48 auto &context =
meshContext(action->getMesh()->getName());
49 context.require(action->getMeshRequirement());
50 _actions.push_back(std::move(action));
78 context->provideMesh =
true;
87 const bool allowDirectAccess)
96 context->receiveMeshFrom = fromParticipant;
97 context->safetyFactor = safetyFactor;
98 context->provideMesh =
false;
99 context->geoFilter = geoFilter;
100 context->allowDirectAccess = allowDirectAccess;
181 [data](
const auto &mckv) {
182 const auto &meshData = mckv.second->mesh->data();
183 return std::any_of(meshData.begin(), meshData.end(), [data](const auto &dptr) {
184 return dptr->getName() == data;
191 const auto &meshData = meshContext(mesh).mesh->data();
192 const auto match =
std::find_if(meshData.begin(), meshData.end(), [data](
auto &dptr) { return dptr->getName() == data; });
193 return match != meshData.end();
198 return _readDataContexts.count(
MeshDataKey{mesh, data}) > 0;
203 return _writeDataContexts.count(
MeshDataKey{mesh, data}) > 0;
210 auto pos = _meshContexts.find(mesh);
217 auto pos = _meshContexts.find(mesh);
224 return _usedMeshContexts;
229 return _usedMeshContexts;
234 auto pos =
std::find_if(_usedMeshContexts.begin(), _usedMeshContexts.end(),
236 return context->mesh->getName() == mesh;
244 auto pos =
std::find_if(_usedMeshContexts.begin(), _usedMeshContexts.end(),
246 return context->mesh->getName() == mesh;
254 return _meshContexts.count(mesh) > 0;
260 _usedMeshContexts.begin(), _usedMeshContexts.end(),
262 return mcptr->mesh->getName() == mesh;
269 return usedMeshContext(mesh).provideMesh;
275 return !usedMeshContext(mesh).provideMesh;
281 return meshContext(mesh).allowDirectAccess;
288 return _readMappingContexts;
293 return _writeMappingContexts;
306void ParticipantState::addExportContext(
309 _exportContexts.
push_back(exportContext);
314 return _exportContexts;
324 return _watchIntegrals;
327bool ParticipantState::useIntraComm()
const
329 return _useIntraComm;
337void ParticipantState::exportInitial()
340 if (context.everyNTimeWindows < 1) {
344 for (
const MeshContext *meshContext : usedMeshContexts()) {
345 auto &mesh = *meshContext->mesh;
346 PRECICE_DEBUG(
"Exporting initial mesh {} to location \"{}\"", mesh.getName(), context.location);
347 context.exporter->doExport(fmt::format(
"{}-{}.init", mesh.getName(), getName()), context.location, mesh);
355 if (exp.complete && (context.everyNTimeWindows > 0) && (exp.timewindow % context.everyNTimeWindows == 0)) {
356 for (
const MeshContext *meshContext : usedMeshContexts()) {
357 auto &mesh = *meshContext->mesh;
358 PRECICE_DEBUG(
"Exporting mesh {} for timewindow {} to location \"{}\"", mesh.getName(), exp.timewindow, context.location);
359 context.exporter->doExport(fmt::format(
"{}-{}.dt{}", mesh.getName(), getName(), exp.timewindow), context.location, mesh);
363 if (context.everyIteration) {
364 for (
const MeshContext *meshContext : usedMeshContexts()) {
365 auto &mesh = *meshContext->mesh;
366 PRECICE_DEBUG(
"Exporting mesh {} for iteration {} to location \"{}\"", meshContext->mesh->getName(), exp.iteration, context.location);
368 context.exporter->doExport(fmt::format(
"{}-{}.it{}", mesh.getName(), getName(), exp.iteration), context.location, mesh);
376 watchPoint->exportPointData(exp.time);
380 watchIntegral->exportIntegralData(exp.time);
390 "Mesh \"{} cannot be used twice by participant {}. "
391 "Please remove one of the provide/receive-mesh nodes with name=\"{}\"./>",
397 PRECICE_CHECK(!isDataWrite(mesh, data) && !isDataRead(mesh, data),
398 "ParticipantState \"{}\" can read/write data \"{}\" from/to mesh \"{}\" only once. "
399 "Please remove any duplicate instances of write-data/read-data nodes.",
408 if (_meshContexts.size() == 1) {
409 return " This participant only knows mesh \"" + _meshContexts.begin()->first +
"\".";
413 if (matches.front().distance < 3) {
414 return " Did you mean mesh \"" + matches.front().name +
"\"?";
416 return fmt::format(
" Available meshes are: {}", fmt::join(_meshContexts | boost::adaptors::map_keys,
", "));
428 for (
const auto &[_, mc] : _meshContexts) {
429 if (mc->mesh->hasDataName(data)) {
430 return " Did you mean the data of mesh \"" + mc->mesh->getName() +
"\"?";
435 auto localData = meshContext(mesh).mesh->availableData();
437 if (localData.size() == 1) {
438 return " This mesh only knows data \"" + localData.
front() +
"\".";
443 if (matches.front().distance < 3) {
444 return " Did you mean data \"" + matches.front().name +
"\"?";
447 return fmt::format(
" Available data are: {}", fmt::join(localData,
", "));
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_CHECK(check,...)
#define PRECICE_ASSERT(...)
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.
virtual ~ParticipantState()
MeshMap< MeshContext * > _meshContexts
All mesh contexts involved in a simulation.
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::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
std::vector< PtrWatchIntegral > _watchIntegrals
void setUsePrimaryRank(bool useIntraComm)
Sets weather the participant was configured with a primary tag.
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.
DataMap< WriteDataContext > _writeDataContexts
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.
std::vector< PtrWatchPoint > _watchPoints
bool useIntraComm() const
Returns true, if the participant uses a primary tag.
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
void checkDuplicatedUse(std::string_view mesh)
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...
GeometricFilter
Defines the type of geometric filter used.
std::vector< StringMatch > computeMatches(std::string_view given, const Container &expected)
Holds a data mapping and related information.
Stores a mesh and related objects and data.
mesh::PtrMesh mesh
Mesh holding the geometry data structure.
Type that represent a compound key of two values.