preCICE v3.1.2
Loading...
Searching...
No Matches
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
36namespace Integration {
37namespace Serial {
38namespace Whitebox {
39struct TestConfigurationPeano;
40struct TestConfigurationComsol;
41} // namespace Whitebox
42} // namespace Serial
43} // namespace Integration
44
45namespace precice {
46namespace cplscheme {
47class CouplingSchemeConfiguration;
48} // namespace cplscheme
49namespace mesh {
50class Mesh;
51} // namespace mesh
52
53namespace impl {
54
57public:
60
77 std::string_view participantName,
78 std::string_view configurationFileName,
79 int solverProcessIndex,
80 int solverProcessSize,
81 std::optional<void *> communicator);
82
91
93
96
98 void initialize();
99
101 void advance(double computedTimeStepSize);
102
104 void finalize();
105
107
110
112 int getMeshDimensions(std::string_view meshName) const;
113
115 int getDataDimensions(std::string_view meshName, std::string_view dataName) const;
116
118 bool isCouplingOngoing() const;
119
121 bool isTimeWindowComplete() const;
122
124 double getMaxTimeStepSize() const;
125
127
130
132 bool requiresInitialData();
133
136
139
141
145
147 void resetMesh(std::string_view meshName);
148
151
154 std::string_view dataName) const;
155
158 std::string_view meshName,
160
162 int getMeshVertexSize(std::string_view meshName) const;
163
165 void setMeshVertices(
166 std::string_view meshName,
169
171 void setMeshEdge(
172 std::string_view meshName,
173 VertexID first,
174 VertexID second);
175
177 void setMeshEdges(
178 std::string_view meshName,
180
182 void setMeshTriangle(
183 std::string_view meshName,
184 VertexID first,
185 VertexID second,
186 VertexID third);
187
189 void setMeshTriangles(
190 std::string_view meshName,
192
194 void setMeshQuad(
195 std::string_view meshName,
196 VertexID first,
197 VertexID second,
198 VertexID third,
199 VertexID fourth);
200
202 void setMeshQuads(
203 std::string_view meshName,
205
208 std::string_view meshName,
209 VertexID first,
210 VertexID second,
211 VertexID third,
212 VertexID fourth);
213
216 std::string_view meshName,
218
220
223
225 void readData(
226 std::string_view meshName,
227 std::string_view dataName,
229 double relativeReadTime,
230 ::precice::span<double> values) const;
231
233 void writeData(
234 std::string_view meshName,
235 std::string_view dataName,
238
241 std::string_view meshName,
242 std::string_view dataName,
245
247
251
254 ::precice::span<const double> boundingBox) const;
255
258 std::string_view meshName,
260 ::precice::span<double> coordinates) const;
261
263
268 const mesh::Mesh &mesh(const std::string &meshName) const;
269
272 };
273
276
279
282
285
288
289private:
290 mutable logging::Logger _log{"impl::ParticipantImpl"};
291
293
295
297
299
301 int _dimensions = 0;
302
304
307
309
312
314
316 enum struct State {
317 Constructed, // Initial state of Participant
318 Initialized, // Participant.initialize() triggers transition from State::Constructed to State::Initialized; mandatory
319 Finalized // Participant.finalize() triggers transition form State::Initialized to State::Finalized; mandatory
320 };
321
324
326 bool _waitInFinalize = false;
327
329 mutable bool _accessRegionDefined = false;
330
333
336
339
342
351 void configure(std::string_view configurationFileName);
352
359 void configure(const config::Configuration &configuration);
360
362
364 void handleExports();
365
368 const m2n::M2NConfiguration::SharedPointer &m2nConfig);
369
372
374 void computePartitions();
375
377 void computeMappings(std::vector<MappingContext> &contexts, const std::string &mappingType);
378
381
383 void mapWrittenData(std::optional<double> after = std::nullopt);
384
385 // Computes, and performs read mappings of the initial data in initialize
386 void mapInitialReadData();
387
388 // Computes, and performs read mappings
389 void mapReadData();
390
396 void trimReadMappedData(double timeAfterAdvance, bool isTimeWindowComplete, const cplscheme::ImplicitData &fromData);
397
404
411 void resetWrittenData(); //bool isAtWindowEnd, bool isTimeWindowComplete);
412
415 const config::Configuration &config);
416
419
422
424 void syncTimestep(double computedTimeStepSize);
425
427 enum class CloseChannels : bool {
428 All = false,
429 Distributed = true
430 };
431
434
436 void handleDataBeforeAdvance(bool reachedTimeWindowEnd, double timeSteppedTo);
437
439 void handleDataAfterAdvance(bool reachedTimeWindowEnd, bool isTimeWindowComplete, double timeSteppedTo, double timeAfterAdvance, const cplscheme::ImplicitData &receivedData);
440
442 void samplizeWriteData(double time);
443
445 void trimOldDataBefore(double time);
446
448 void trimSendDataAfter(double time);
449
453
456};
457
458} // namespace impl
459} // 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.
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 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.
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.
bool _accessRegionDefined
setMeshAccessRegion may only be called once
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 handleExports()
Exports meshes with data and watch point data.
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)
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
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.
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 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.
std::unique_ptr< profiling::Event > _solverAdvanceEvent
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 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:16
Container and creator for meshes.
Definition Mesh.hpp:39
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:27
Main namespace of the precice library.
int VertexID
Definition Types.hpp:13
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21