preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticipantImpl.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <map>
5#include <set>
6#include <string>
7#include <string_view>
8#include <vector>
9
10#include "action/Action.hpp"
11#include "boost/noncopyable.hpp"
12#include "com/Communication.hpp"
15#include "logging/Logger.hpp"
16#include "m2n/BoundM2N.hpp"
22#include "utils/MultiLock.hpp"
23
24namespace precice {
25
26namespace profiling {
27class Event;
28}
29
30namespace config {
31class Configuration;
32}
33} // namespace precice
34
35// Forward declaration to friend the boost test struct
36
38struct TestConfigurationPeano;
39struct TestConfigurationComsol;
40} // namespace Integration::Serial::Whitebox
41
42namespace precice {
43namespace cplscheme {
44class CouplingSchemeConfiguration;
45} // namespace cplscheme
46namespace mesh {
47class Mesh;
48} // namespace mesh
49
50namespace impl {
51
54public:
57
74 std::string_view participantName,
75 std::string_view configurationFileName,
76 int solverProcessIndex,
77 int solverProcessSize,
78 std::optional<void *> communicator);
79
88
90
93
95 void initialize();
96
98 void advance(double computedTimeStepSize);
99
101 void finalize();
102
104
107
109 int getMeshDimensions(std::string_view meshName) const;
110
112 int getDataDimensions(std::string_view meshName, std::string_view dataName) const;
113
115 bool isCouplingOngoing() const;
116
118 bool isTimeWindowComplete() const;
119
121 double getMaxTimeStepSize() const;
122
124
127
129 bool requiresInitialData();
130
133
136
138
142
144 void resetMesh(std::string_view meshName);
145
148
151 std::string_view dataName) const;
152
155 std::string_view meshName,
157
159 int getMeshVertexSize(std::string_view meshName) const;
160
162 void setMeshVertices(
163 std::string_view meshName,
166
168 void setMeshEdge(
169 std::string_view meshName,
170 VertexID first,
171 VertexID second);
172
174 void setMeshEdges(
175 std::string_view meshName,
177
179 void setMeshTriangle(
180 std::string_view meshName,
181 VertexID first,
182 VertexID second,
183 VertexID third);
184
186 void setMeshTriangles(
187 std::string_view meshName,
189
191 void setMeshQuad(
192 std::string_view meshName,
193 VertexID first,
194 VertexID second,
195 VertexID third,
196 VertexID fourth);
197
199 void setMeshQuads(
200 std::string_view meshName,
202
205 std::string_view meshName,
206 VertexID first,
207 VertexID second,
208 VertexID third,
209 VertexID fourth);
210
213 std::string_view meshName,
215
217
220
222 void readData(
223 std::string_view meshName,
224 std::string_view dataName,
226 double relativeReadTime,
227 ::precice::span<double> values) const;
228
230 void mapAndReadData(
231 std::string_view meshName,
232 std::string_view dataName,
234 double relativeReadTime,
235 ::precice::span<double> values) const;
236
238 void writeAndMapData(
239 std::string_view meshName,
240 std::string_view dataName,
243
245 void writeData(
246 std::string_view meshName,
247 std::string_view dataName,
250
253 std::string_view meshName,
254 std::string_view dataName,
257
259
263
266 ::precice::span<const double> boundingBox) const;
267
270 std::string_view meshName,
272 ::precice::span<double> coordinates) const;
273
275
279
282
285
287
292 const mesh::Mesh &mesh(const std::string &meshName) const;
293
296 };
297
300
303
306
309
312
313private:
314 mutable logging::Logger _log{"impl::ParticipantImpl"};
315
317
319
321
323
325 int _dimensions = 0;
326
328
331
333
336
338
340 enum struct State {
341 Constructed, // Initial state of Participant
342 Initialized, // Participant.initialize() triggers transition from State::Constructed to State::Initialized; mandatory
343 Finalized // Participant.finalize() triggers transition form State::Initialized to State::Finalized; mandatory
344 };
345
348
350 bool _allowsRemeshing = false;
351
353 bool _waitInFinalize = false;
354
357
360
363
366
369
378 void configure(std::string_view configurationFileName);
379
386 void configure(const config::Configuration &configuration);
387
389
390 enum struct ExportTiming : bool {
391 Advance = false,
392 Initial = true
393 };
394
397 void handleExports(ExportTiming timing);
398
401 const m2n::M2NConfiguration::SharedPointer &m2nConfig);
402
405
407 void computePartitions();
408
410 void computeMappings(std::vector<MappingContext> &contexts, const std::string &mappingType);
411
414
417
418 // Computes, and performs read mappings of the initial data in initialize
419 void mapInitialReadData();
420
421 // Computes, and performs read mappings
422 void mapReadData();
423
429 void trimReadMappedData(double timeAfterAdvance, bool isTimeWindowComplete, const cplscheme::ImplicitData &fromData);
430
437
444 void resetWrittenData(); // bool isAtWindowEnd, bool isTimeWindowComplete);
445
448 const config::Configuration &config);
449
452
455
457 void syncTimestep(double computedTimeStepSize);
458
460 enum class CloseChannels : bool {
461 All = false,
462 Distributed = true
463 };
464
467
469 void handleDataBeforeAdvance(bool reachedTimeWindowEnd, double timeSteppedTo);
470
472 void handleDataAfterAdvance(bool reachedTimeWindowEnd, bool isTimeWindowComplete, double timeSteppedTo, double timeAfterAdvance, const cplscheme::ImplicitData &receivedData);
473
475 void samplizeWriteData(double time);
476
478 void trimOldDataBefore(double time);
479
481 void trimSendDataAfter(double time);
482
485
490
492 void clearStamplesOfChangedMeshes(MeshChanges totalMeshChanges);
493
500 bool reinitHandshake(bool requestReinit) const;
501
503 void reinitialize();
504
506 void setupCommunication();
507
509 void setupWatcher();
510
515
519
522
524};
525
526} // namespace impl
527} // namespace precice
Main class for preCICE XML configuration tree.
Implementation of Participant. See also pimpl ideom (https://en.cppreference.com/w/cpp/language/pimpl...
CloseChannels
Which channels to close in closeCommunicationChannels()
std::map< std::string, int > _meshIDs
mesh name to mesh ID mapping.
void writeGradientData(std::string_view meshName, std::string_view dataName, ::precice::span< const VertexID > vertices, ::precice::span< const double > gradients)
Writes vector gradient data to a mesh.
int getMeshVertexSize(std::string_view meshName) const
Returns the number of vertices of a mesh.
utils::MultiLock< std::string > _meshLock
void setMeshQuad(std::string_view meshName, VertexID first, VertexID second, VertexID third, VertexID fourth)
Sets a planar surface mesh quadrangle from vertex IDs.
void setMeshTetrahedra(std::string_view meshName, ::precice::span< const VertexID > vertices)
Sets multiple mesh tetrahedra from vertex IDs.
bool requiresGradientDataFor(std::string_view meshName, std::string_view dataName) const
Checks if the given data set requires gradient data. We check if the data object has been initialized...
int getDataDimensions(std::string_view meshName, std::string_view dataName) const
Returns the spatial dimensionality of the given data on the given mesh.
impl::PtrParticipant determineAccessingParticipant(const config::Configuration &config)
Determines participant accessing this interface from the configuration.
MeshChanges getTotalMeshChanges() const
void advanceCouplingScheme()
Advances the coupling schemes.
void computePartitions()
Communicate meshes and create partitions.
void setMeshEdge(std::string_view meshName, VertexID first, VertexID second)
Sets a mesh edge from vertex IDs.
std::vector< impl::PtrParticipant > _participants
Holds information about solvers participating in the coupled simulation.
bool requiresMeshConnectivityFor(std::string_view meshName) const
Checks if the given mesh requires connectivity.
void setMeshTriangles(std::string_view meshName, ::precice::span< const VertexID > vertices)
Sets multiple mesh triangles from vertex IDs.
int _executedReadMappings
Counts the amount of samples mapped in read mappings executed in the latest advance.
void clearStamplesOfChangedMeshes(MeshChanges totalMeshChanges)
Clears stample of changed meshes to make them consistent after the reinitialization.
void performDataActions(const std::set< action::Action::Timing > &timings)
Performs all data actions with given timing.
ParticipantImpl & operator=(ParticipantImpl &&)=delete
Disable move assignment.
void setMeshTriangle(std::string_view meshName, VertexID first, VertexID second, VertexID third)
Sets mesh triangle from vertex IDs.
void configurePartitions(const m2n::M2NConfiguration::SharedPointer &m2nConfig)
Determines participants providing meshes to other participants.
double getMaxTimeStepSize() const
Get the maximum allowed time step size of the current window.
cplscheme::PtrCouplingScheme _couplingScheme
long int _numberAdvanceCalls
Counts calls to advance for plotting.
bool _allowsExperimental
Are experimental API calls allowed?
void handleDataBeforeAdvance(bool reachedTimeWindowEnd, double timeSteppedTo)
Completes everything data-related between adding time to and advancing the coupling scheme.
ParticipantImpl(ParticipantImpl &&)=delete
Disable move construction.
void setMeshTetrahedron(std::string_view meshName, VertexID first, VertexID second, VertexID third, VertexID fourth)
Set tetrahedron in 3D mesh from vertex ID.
void handleDataAfterAdvance(bool reachedTimeWindowEnd, bool isTimeWindowComplete, double timeSteppedTo, double timeAfterAdvance, const cplscheme::ImplicitData &receivedData)
Completes everything data-related after advancing the coupling scheme.
void samplizeWriteData(double time)
Creates a Stample at the given time for each write Data and zeros the buffers.
void setMeshQuads(std::string_view meshName, ::precice::span< const VertexID > vertices)
Sets multiple mesh quads from vertex IDs.
void getMeshVertexIDsAndCoordinates(std::string_view meshName, ::precice::span< VertexID > ids, ::precice::span< double > coordinates) const
getMeshVertexIDsAndCoordinates Iterates over the region of interest defined by bounding boxes and rea...
State
Represents the various states a Participant can be in.
void closeCommunicationChannels(CloseChannels cc)
Syncs the primary ranks of all connected participants.
bool reinitHandshake(bool requestReinit) const
void trimSendDataAfter(double time)
Discards send (currently write) data of a participant after a given time when another iteration is re...
std::unique_ptr< profiling::Event > _solverInitEvent
ParticipantImpl(std::string_view participantName, std::string_view configurationFileName, int solverProcessIndex, int solverProcessSize, std::optional< void * > communicator)
Generic constructor for ParticipantImpl.
void advance(double computedTimeStepSize)
Advances preCICE after the solver has computed one time step.
void setMeshAccessRegion(std::string_view meshName, ::precice::span< const double > boundingBox) const
setMeshAccessRegion Define a region of interest on a received mesh (<receive-mesh ....
ParticipantImpl & operator=(ParticipantImpl const &)=delete
Disable assignment construction.
void writeData(std::string_view meshName, std::string_view dataName, ::precice::span< const VertexID > vertices, ::precice::span< const double > values)
Writes data to a mesh.
std::vector< profiling::Event > _userEvents
void handleExports(ExportTiming timing)
bool isCouplingOngoing() const
Checks if the coupled simulation is still ongoing.
State _state
The current State of the Participant.
void configure(const config::Configuration &configuration)
Configures the coupling interface with a prepared configuration.
void mapInitialWrittenData()
Computes, and performs write mappings of the initial data in initialize.
void setMeshVertices(std::string_view meshName, ::precice::span< const double > positions, ::precice::span< VertexID > ids)
Creates multiple mesh vertices.
ParticipantImpl(ParticipantImpl const &)=delete
Disable copy construction.
friend struct Integration::Serial::Whitebox::TestConfigurationPeano
To allow white box tests.
void resetMesh(std::string_view meshName)
Removes all vertices and connectivity information from the mesh.
MappedSamples mappedSamples() const
Returns the amount of mapped read and write samples in the last call to advance.
void finalize()
Finalizes preCICE.
int _dimensions
Spatial dimensions of problem.
int _executedWriteMappings
Counts the amount of samples mapped in write mappings executed in the latest advance.
void configureM2Ns(const m2n::M2NConfiguration::SharedPointer &config)
void trimReadMappedData(double timeAfterAdvance, bool isTimeWindowComplete, const cplscheme::ImplicitData &fromData)
Removes samples in mapped to data connected to received data via a mapping.
std::map< std::string, m2n::BoundM2N > _m2ns
void reinitialize()
Reinitializes preCICE.
void setupWatcher()
Setup mesh watcher such as WatchPoints.
bool isTimeWindowComplete() const
Checks if the current coupling window is completed.
friend struct Integration::Serial::Whitebox::TestConfigurationComsol
void setMeshEdges(std::string_view meshName, ::precice::span< const VertexID > vertices)
Sets multiple mesh edges from vertex IDs.
std::string _configHash
The hash of the configuration file used to configure this participant.
void setupCommunication()
Connect participants including repartitioning.
bool _allowsRemeshing
Are experimental remeshing API calls allowed?
VertexID setMeshVertex(std::string_view meshName, ::precice::span< const double > position)
Creates a mesh vertex.
void syncTimestep(double computedTimeStepSize)
Syncs the time step size between all ranks (all time steps sizes should be the same!...
void readData(std::string_view meshName, std::string_view dataName, ::precice::span< const VertexID > vertices, double relativeReadTime, ::precice::span< double > values) const
Reads data values from a mesh. Values correspond to a given point in time relative to the beginning o...
const mesh::Mesh & mesh(const std::string &meshName) const
Allows to access a registered mesh.
void compareBoundingBoxes()
Communicate bounding boxes and look for overlaps.
bool _waitInFinalize
Are participants waiting for each other in finalize?
void startProfilingSection(std::string_view eventName)
void initializeIntraCommunication()
Initializes intra-participant communication.
void resetWrittenData()
Resets written data.
void trimOldDataBefore(double time)
Discards data before the given time for all meshes and data known by this participant.
void mapAndReadData(std::string_view meshName, std::string_view dataName, ::precice::span< const double > coordinates, double relativeReadTime, ::precice::span< double > values) const
Reads data values from a mesh using a just-in-time data mapping. Values correspond to a given point i...
std::unique_ptr< profiling::Event > _solverAdvanceEvent
bool requiresUserDefinedAccessRegion(std::string_view meshName) const
void configure(std::string_view configurationFileName)
Configures the coupling interface from the given xml file.
void mapWrittenData(std::optional< double > after=std::nullopt)
Computes, and performs suitable write mappings either entirely or after given time.
void initialize()
Fully initializes preCICE and coupling data.
void writeAndMapData(std::string_view meshName, std::string_view dataName, ::precice::span< const double > coordinates, ::precice::span< const double > values)
Writes data values to a mesh using a just-in-time mapping (experimental).
void computeMappings(std::vector< MappingContext > &contexts, const std::string &mappingType)
Helper for mapWrittenData and mapReadData.
int getMeshDimensions(std::string_view meshName) const
Returns the spatial dimensionality of the given mesh.
This class provides a lightweight logger.
Definition Logger.hpp:17
Container and creator for meshes.
Definition Mesh.hpp:38
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
Class handling multiple locks allowing global lock and unlock operations.
Definition MultiLock.hpp:26
T make_unique(T... args)
Main namespace of the precice library.
int VertexID
Definition Types.hpp:13
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21