preCICE v3.3.0
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::impl {
28struct MeshContext;
29struct MappingContext;
30} // namespace precice::impl
31
32// Forward declaration to friend the boost test struct
33
35struct TestConfigurationPeano;
36struct TestConfigurationComsol;
37} // namespace Integration::Serial::Whitebox
38
39namespace precice {
40namespace utils {
41class ManageUniqueIDs;
42} // namespace utils
43
44namespace impl {
45
47template <typename T>
51 template <typename Other>
52 bool operator<(const MeshDataKey<Other> &other) const
53 {
54 if (mesh < other.mesh) {
55 return true;
56 }
57 if (other.mesh < mesh) {
58 return false;
59 }
60 return data < other.data;
61 }
62};
63
65template <class T>
67
70public:
76
83 std::string name,
84 mesh::PtrMeshConfiguration &meshConfig);
85
86 virtual ~ParticipantState();
87
91 void addWriteData(
92 const mesh::PtrData &data,
93 const mesh::PtrMesh &mesh);
94
96 void addReadData(
97 const mesh::PtrData &data,
98 const mesh::PtrMesh &mesh);
99
101 void addReadMappingContext(const MappingContext &mappingContext);
102
104 void addWriteMappingContext(const MappingContext &mappingContext);
105
107 void addWatchPoint(const PtrWatchPoint &watchPoint);
108
110 void addWatchIntegral(const PtrWatchIntegral &watchIntegral);
111
114
117
119 void addExportContext(const io::ExportContext &context);
120
122 void provideMesh(const mesh::PtrMesh &mesh);
123
125 void receiveMesh(const mesh::PtrMesh &mesh,
126 const std::string &fromParticipant,
127 double safetyFactor,
129 const bool allowDirectAccess);
131
134
138
143
151
156
161
166 {
167 return _writeDataContexts | boost::adaptors::map_values;
168 }
169
174 {
175 return _readDataContexts | boost::adaptors::map_values;
176 }
177
180
183
186
190
193 /*** Provides direct access to a \ref MeshContext given the \ref meshid
194 * @param[in] meshID the id of the \ref Mesh
195 * @returns a reference to the matching \ref MeshContext
196 * @pre the \ref Mesh with \ref meshID is used by the ParticipantState
197 */
199
200 /*** Provides direct access to a \ref MeshContext given the \ref meshid
201 * @param[in] meshID the id of the \ref Mesh
202 * @returns a reference to the matching \ref MeshContext
203 * @pre the \ref Mesh with \ref meshID is used by the ParticipantState
204 */
206
211
216
223
230
232 bool hasMesh(std::string_view mesh) const;
233
235 bool isMeshUsed(std::string_view mesh) const;
236
239
242
247
250
253
256
260 void exportInitial();
261
264 size_t iteration;
265 double time;
267 bool final;
268 };
269
272
274
278 const std::string &getName() const;
279
281 bool useIntraComm() const;
282
284 bool hasReadMappings() const;
285
287 bool hasWriteMappings() const;
288
291
294
297
300
303
306
309
311 bool hasExports() const;
313
319
320private:
321 mutable logging::Logger _log{"impl::ParticipantState"};
322
324
326
328
331
333
334 template <typename T>
336
337 template <typename T>
339
342
345
348
351
353
355
356 bool _useIntraComm = false;
357
358 template <typename ELEMENT_T>
359 bool isDataValid(
360 const std::vector<ELEMENT_T> &data,
361 const ELEMENT_T &newElement) const;
362
364
366
370};
371
372// --------------------------------------------------------- HEADER DEFINITIONS
373
374template <typename ELEMENT_T>
376 const std::vector<ELEMENT_T> &data,
377 const ELEMENT_T &newElement) const
378{
379 for (size_t i = 0; i < data.size(); i++) {
380 if (data[i].name == newElement.name) {
381 return false;
382 }
383 }
384 return true;
385}
386
387} // namespace impl
388} // namespace precice
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.
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.
std::map< std::string, T, std::less<> > MeshMap
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
bool hasExports() const
Returns true, if the participant has any exports enabled.
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
bool hasWriteMappings() const
Returns true, if the participant has at least one write mapping.
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 configureOutputMeshContext(std::string_view toMesh, impl::MappingContext &mappingContext, mapping::Mapping::MeshRequirement requirement)
Configures the mesh context with connectivity requirements and adds it to the mappingcontext.
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
std::map< MeshDataKey< std::string >, T, std::less<> > DataMap
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?
void configureInputMeshContext(std::string_view fromMesh, impl::MappingContext &mappingContext, mapping::Mapping::MeshRequirement requirement)
Configures the mesh context with connectivity requirements and adds it to the mappingcontext.
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.
bool hasReadMappings() const
Returns true, if the participant has at least one read mapping.
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 initializeMappingDataCache(std::string_view mappingType)
Initializes the MappingDataCache in the DataContext after having computed the mappings.
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:17
MeshRequirement
Specifies requirements for the input and output meshes of a mapping.
Definition Mapping.hpp:46
GeometricFilter
Defines the type of geometric filter used.
Manages a set of unique IDs.
contains actions to modify exchanged data.
Definition Action.hpp:6
std::unique_ptr< Action > PtrAction
std::shared_ptr< WatchPoint > PtrWatchPoint
MeshDataKey(T, T) -> MeshDataKey< T >
Deduction guide for two identical parameter types.
std::shared_ptr< WatchIntegral > PtrWatchIntegral
provides Mesh, Data and primitives.
std::shared_ptr< Data > PtrData
std::shared_ptr< Mesh > PtrMesh
std::shared_ptr< MeshConfiguration > PtrMeshConfiguration
contains precice-related utilities.
Main namespace of the precice library.
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