preCICE v3.3.1
Loading...
Searching...
No Matches
ParticipantImpl.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <deque>
5#include <map>
6#include <set>
7#include <string>
8#include <string_view>
9#include <vector>
10
11#include "action/Action.hpp"
12#include "boost/noncopyable.hpp"
13#include "com/Communication.hpp"
16#include "logging/Logger.hpp"
17#include "m2n/BoundM2N.hpp"
23#include "profiling/Event.hpp"
24#include "utils/MultiLock.hpp"
25
26namespace precice::config {
27class Configuration;
28} // namespace precice::config
29
30// Forward declaration to friend the boost test struct
31
33struct TestConfigurationPeano;
34struct TestConfigurationComsol;
35} // namespace Integration::Serial::Whitebox
36
37namespace precice {
38namespace cplscheme {
39class CouplingSchemeConfiguration;
40} // namespace cplscheme
41namespace mesh {
42class Mesh;
43} // namespace mesh
44
45namespace impl {
46
49public:
52
69 std::string_view participantName,
70 std::string_view configurationFileName,
71 int solverProcessIndex,
72 int solverProcessSize,
73 std::optional<void *> communicator);
74
83
85
88
90 void initialize();
91
93 void advance(double computedTimeStepSize);
94
96 void finalize();
97
99
102
104 int getMeshDimensions(std::string_view meshName) const;
105
107 int getDataDimensions(std::string_view meshName, std::string_view dataName) const;
108
110 bool isCouplingOngoing() const;
111
113 bool isTimeWindowComplete() const;
114
116 double getMaxTimeStepSize() const;
117
119
122
124 bool requiresInitialData();
125
128
131
133
137
139 void resetMesh(std::string_view meshName);
140
143
146 std::string_view dataName) const;
147
150 std::string_view meshName,
152
154 int getMeshVertexSize(std::string_view meshName) const;
155
157 void setMeshVertices(
158 std::string_view meshName,
161
163 void setMeshEdge(
164 std::string_view meshName,
165 VertexID first,
166 VertexID second);
167
169 void setMeshEdges(
170 std::string_view meshName,
172
174 void setMeshTriangle(
175 std::string_view meshName,
176 VertexID first,
177 VertexID second,
178 VertexID third);
179
181 void setMeshTriangles(
182 std::string_view meshName,
184
186 void setMeshQuad(
187 std::string_view meshName,
188 VertexID first,
189 VertexID second,
190 VertexID third,
191 VertexID fourth);
192
194 void setMeshQuads(
195 std::string_view meshName,
197
200 std::string_view meshName,
201 VertexID first,
202 VertexID second,
203 VertexID third,
204 VertexID fourth);
205
208 std::string_view meshName,
210
212
215
217 void readData(
218 std::string_view meshName,
219 std::string_view dataName,
221 double relativeReadTime,
222 ::precice::span<double> values) const;
223
225 void mapAndReadData(
226 std::string_view meshName,
227 std::string_view dataName,
229 double relativeReadTime,
230 ::precice::span<double> values) const;
231
233 void writeAndMapData(
234 std::string_view meshName,
235 std::string_view dataName,
238
240 void writeData(
241 std::string_view meshName,
242 std::string_view dataName,
245
248 std::string_view meshName,
249 std::string_view dataName,
252
254
258
261 ::precice::span<const double> boundingBox) const;
262
265 std::string_view meshName,
267 ::precice::span<double> coordinates) const;
268
270
274
277
280
282
287 const mesh::Mesh &mesh(const std::string &meshName) const;
288
291 };
292
295
298
301
304
307
308private:
309 mutable logging::Logger _log{"impl::ParticipantImpl"};
310
312
314
316
318
320 int _dimensions = 0;
321
323
326
328
331
333
335 enum struct State {
336 Constructed, // Initial state of Participant
337 Initialized, // Participant.initialize() triggers transition from State::Constructed to State::Initialized; mandatory
338 Finalized // Participant.finalize() triggers transition form State::Initialized to State::Finalized; mandatory
339 };
340
343
345 bool _allowsRemeshing = false;
346
348 bool _waitInFinalize = false;
349
352
355
358
361
364
373 void configure(std::string_view configurationFileName);
374
381 void configure(const config::Configuration &configuration);
382
383 enum struct ExportTiming : bool {
384 Advance = false,
385 Initial = true
386 };
387
390 void handleExports(ExportTiming timing);
391
394
396 void computePartitions();
397
399 void computeMappings(std::vector<MappingContext> &contexts, const std::string &mappingType);
400
403
405 void mapWrittenData(std::optional<double> after = std::nullopt);
406
407 // Computes, and performs read mappings of the initial data in initialize
408 void mapInitialReadData();
409
410 // Computes, and performs read mappings
411 void mapReadData();
412
418 void trimReadMappedData(double timeAfterAdvance, bool isTimeWindowComplete, const cplscheme::ImplicitData &fromData);
419
426
433 void resetWrittenData(); // bool isAtWindowEnd, bool isTimeWindowComplete);
434
438
441
444
446 void syncTimestep(double computedTimeStepSize);
447
449 enum class CloseChannels : bool {
450 All = false,
452 };
453
456
458 void handleDataBeforeAdvance(bool reachedTimeWindowEnd, double timeSteppedTo);
459
461 void handleDataAfterAdvance(bool reachedTimeWindowEnd, bool isTimeWindowComplete, double timeSteppedTo, double timeAfterAdvance, const cplscheme::ImplicitData &receivedData);
462
464 void samplizeWriteData(double time);
465
467 void trimOldDataBefore(double time);
468
470 void trimSendDataAfter(double time);
471
474
479
481 void clearStamplesOfChangedMeshes(MeshChanges totalMeshChanges);
482
489 bool reinitHandshake(bool requestReinit) const;
490
492 void reinitialize();
493
495 void setupCommunication();
496
498 void setupWatcher();
499
504
508
511
513};
514
515} // namespace impl
516} // namespace precice
Main class for preCICE XML configuration tree.
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
std::deque< profiling::Event > _userEvents
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.
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.
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)
std::vector< int > MeshChanges
How many ranks have changed each used 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 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
std::shared_ptr< CouplingScheme > PtrCouplingScheme
std::shared_ptr< ParticipantState > PtrParticipant
provides Mesh, Data and primitives.
contains the time interpolation logic.
Definition Sample.hpp:8
Main namespace of the precice library.
int VertexID
Definition Types.hpp:13