preCICE v3.1.2
Loading...
Searching...
No Matches
ParticipantState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/range/adaptor/map.hpp>
4#include <cmath>
5#include <memory>
6#include <stddef.h>
7#include <string>
8#include <string_view>
9#include <utility>
10#include <vector>
11
12#include "SharedPointer.hpp"
15#include "io/ExportContext.hpp"
17#include "logging/Logger.hpp"
24#include "utils/IntraComm.hpp"
26
27namespace precice {
28namespace impl {
29struct MeshContext;
30struct MappingContext;
31} // namespace impl
32} // namespace precice
33
34// Forward declaration to friend the boost test struct
35namespace Integration {
36namespace Serial {
37namespace Whitebox {
38struct TestConfigurationPeano;
39struct TestConfigurationComsol;
40} // namespace Whitebox
41} // namespace Serial
42} // namespace Integration
43
44namespace precice {
45namespace utils {
46class ManageUniqueIDs;
47} // namespace utils
48
49namespace impl {
50
52template <typename T>
56 template <typename Other>
57 bool operator<(const MeshDataKey<Other> &other) const
58 {
59 if (mesh < other.mesh) {
60 return true;
61 }
62 if (other.mesh < mesh) {
63 return false;
64 }
65 return data < other.data;
66 }
67};
68
70template <class T>
71MeshDataKey(T, T)->MeshDataKey<T>;
72
75public:
81
89 mesh::PtrMeshConfiguration &meshConfig);
90
91 virtual ~ParticipantState();
92
96 void addWriteData(
97 const mesh::PtrData &data,
98 const mesh::PtrMesh &mesh);
99
101 void addReadData(
102 const mesh::PtrData &data,
103 const mesh::PtrMesh &mesh);
104
106 void addReadMappingContext(const MappingContext &mappingContext);
107
109 void addWriteMappingContext(const MappingContext &mappingContext);
110
112 void addWatchPoint(const PtrWatchPoint &watchPoint);
113
115 void addWatchIntegral(const PtrWatchIntegral &watchIntegral);
116
119
122 {
123 _meshIdManager = std::move(idm);
124 }
125
127 void addAction(action::PtrAction &&action);
128
130 void addExportContext(const io::ExportContext &context);
131
133 void provideMesh(const mesh::PtrMesh &mesh);
134
136 void receiveMesh(const mesh::PtrMesh & mesh,
137 const std::string & fromParticipant,
138 double safetyFactor,
140 const bool allowDirectAccess);
142
145
149
154
162
167
172
177 {
178 return _writeDataContexts | boost::adaptors::map_values;
179 }
180
185 {
186 return _readDataContexts | boost::adaptors::map_values;
187 }
188
190 bool hasData(std::string_view mesh, std::string_view data) const;
191
193 bool isDataUsed(std::string_view mesh, std::string_view data) const;
194
196 bool isDataRead(std::string_view mesh, std::string_view data) const;
197
199 bool isDataWrite(std::string_view mesh, std::string_view data) const;
201
204 /*** Provides direct access to a \ref MeshContext given the \ref meshid
205 * @param[in] meshID the id of the \ref Mesh
206 * @returns a reference to the matching \ref MeshContext
207 * @pre the \ref Mesh with \ref meshID is used by the ParticipantState
208 */
209 const MeshContext &meshContext(std::string_view mesh) const;
210
211 /*** Provides direct access to a \ref MeshContext given the \ref meshid
212 * @param[in] meshID the id of the \ref Mesh
213 * @returns a reference to the matching \ref MeshContext
214 * @pre the \ref Mesh with \ref meshID is used by the ParticipantState
215 */
217
222
227
234
241
243 bool hasMesh(std::string_view mesh) const;
244
246 bool isMeshUsed(std::string_view mesh) const;
247
249 bool isMeshProvided(std::string_view mesh) const;
250
252 bool isMeshReceived(std::string_view mesh) const;
253
258
262 void exportInitial();
263
266 size_t iteration;
267 double time;
269 };
270
273
275
279 const std::string &getName() const;
280
282 bool useIntraComm() const;
283
286
289
292
295
298
301
305
311
312private:
313 mutable logging::Logger _log{"impl::ParticipantState"};
314
316
318
320
323
325
326 template <typename T>
328
329 template <typename T>
331
334
337
340
343
345
347
348 bool _useIntraComm = false;
349
351
352 template <typename ELEMENT_T>
353 bool isDataValid(
354 const std::vector<ELEMENT_T> &data,
355 const ELEMENT_T & newElement) const;
356
358
360
364};
365
366// --------------------------------------------------------- HEADER DEFINITIONS
367
368template <typename ELEMENT_T>
370 const std::vector<ELEMENT_T> &data,
371 const ELEMENT_T & newElement) const
372{
373 for (size_t i = 0; i < data.size(); i++) {
374 if (data[i].name == newElement.name) {
375 return false;
376 }
377 }
378 return true;
379}
380
381} // namespace impl
382} // namespace precice
std::string name
Holds coupling state of one participating solver in coupled simulation.
bool isMeshReceived(std::string_view mesh) const
Is a mesh with this name received by this participant?
std::string hintForMeshData(std::string_view mesh, std::string_view data) const
const std::vector< MeshContext * > & usedMeshContexts() const
bool isDataUsed(std::string_view mesh, std::string_view data) const
Is the data used by this participant?
bool isMeshUsed(std::string_view mesh) const
Is a mesh with this name used by this participant?
std::vector< io::ExportContext > _exportContexts
Export contexts to export meshes, data, and more.
void receiveMesh(const mesh::PtrMesh &mesh, const std::string &fromParticipant, double safetyFactor, partition::ReceivedPartition::GeometricFilter geoFilter, const bool allowDirectAccess)
Adds a mesh to be received by the participant.
MeshMap< MeshContext * > _meshContexts
All mesh contexts involved in a simulation.
bool isDataWrite(std::string_view mesh, std::string_view data) const
Is the participant allowed to write the data?
const ReadDataContext & readDataContext(std::string_view mesh, std::string_view data) const
DataMap< ReadDataContext > _readDataContexts
void addAction(action::PtrAction &&action)
Adds a configured Action to the participant.
std::unique_ptr< utils::ManageUniqueIDs > _meshIdManager
bool isDataRead(std::string_view mesh, std::string_view data) const
Is the participant allowed to read the data?
std::string hintForMesh(std::string_view mesh) const
std::vector< PtrWatchPoint > & watchPoints()
Provided access to all WatchPoints.
std::vector< MeshContext * > _usedMeshContexts
Mesh contexts used by the participant.
const MeshContext & meshContext(std::string_view mesh) const
Mesh queries.
void checkDuplicatedData(std::string_view mesh, std::string_view data)
void addWatchPoint(const PtrWatchPoint &watchPoint)
Adds a configured WatchPoint to the ParticipantState.
std::vector< MappingContext > _readMappingContexts
Read mapping contexts used by the participant.
void addWriteMappingContext(const MappingContext &mappingContext)
Adds a configured write Mapping to the ParticipantState.
ParticipantState(std::string name, mesh::PtrMeshConfiguration &meshConfig)
Constructor.
std::vector< action::PtrAction > _actions
bool isDataValid(const std::vector< ELEMENT_T > &data, const ELEMENT_T &newElement) const
std::vector< action::PtrAction > & actions()
Provided access to all Action.
friend struct Integration::Serial::Whitebox::TestConfigurationPeano
To allow white box tests.
std::vector< PtrWatchIntegral > _watchIntegrals
void setUsePrimaryRank(bool useIntraComm)
Sets weather the participant was configured with a primary tag.
void exportIntermediate(IntermediateExport exp)
Exports timewindows and iterations of meshes and watchpoints.
mesh::PtrMesh findMesh(std::string_view data) const
Returns the mesh associated with ReadDataContext with given data name in _readDataContexts of this Pa...
void addReadMappingContext(const MappingContext &mappingContext)
Adds a configured read Mapping to the ParticipantState.
bool hasMesh(std::string_view mesh) const
Does preCICE know a mesh with this name?
DataMap< WriteDataContext > _writeDataContexts
friend struct Integration::Serial::Whitebox::TestConfigurationComsol
void addWatchIntegral(const PtrWatchIntegral &watchIntegral)
Adds a configured WatchIntegral to the ParticipantState.
std::vector< MappingContext > _writeMappingContexts
Write mapping contexts used by the participant.
bool hasData(std::string_view mesh, std::string_view data) const
Is the dataID know to preCICE?
void addWriteData(const mesh::PtrData &data, const mesh::PtrMesh &mesh)
void addReadData(const mesh::PtrData &data, const mesh::PtrMesh &mesh)
Adds a configured read Data to the ParticipantState.
const std::string & getName() const
std::vector< PtrWatchPoint > _watchPoints
void setMeshIdManager(std::unique_ptr< utils::ManageUniqueIDs > &&idm)
Sets the manager responsible for providing unique IDs to meshes.
bool isDirectAccessAllowed(std::string_view mesh) const
void addExportContext(const io::ExportContext &context)
Adds a configured ExportContext to export meshes and data.
bool useIntraComm() const
Returns true, if the participant uses a primary tag.
bool isMeshProvided(std::string_view mesh) const
Is a mesh with this name provided by this participant?
std::vector< MappingContext > & writeMappingContexts()
Provided access to all write MappingContext.
const std::vector< io::ExportContext > & exportContexts() const
Returns all ExportContext for exporting meshes and data.
std::vector< MappingContext > & readMappingContexts()
Provided access to all read MappingContext.
void provideMesh(const mesh::PtrMesh &mesh)
Adds a mesh to be provided by the participant.
const WriteDataContext & writeDataContext(std::string_view mesh, std::string_view data) const
MeshContext & usedMeshContext(std::string_view name)
void checkDuplicatedUse(std::string_view mesh)
std::vector< PtrWatchIntegral > & watchIntegrals()
Provided access to all WatchIntegrals.
Stores one Data object with related mesh. Context stores data to be read from and potentially provide...
Stores one Data object with related mesh. Context stores data to be written to and potentially provid...
This class provides a lightweight logger.
Definition Logger.hpp:16
GeometricFilter
Defines the type of geometric filter used.
MeshDataKey(T, T) -> MeshDataKey< T >
Deduction guide for two identical parameter types.
Main namespace of the precice library.
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21
Holds a data mapping and related information.
Stores a mesh and related objects and data.
Type that represent a compound key of two values.
bool operator<(const MeshDataKey< Other > &other) const