preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Participant.cpp
Go to the documentation of this file.
1#include <optional>
2#include <string_view>
3
7#include "precice/impl/versions.hpp"
8
9namespace precice {
10
11namespace {
13{
14 // The given string_view may contain null chars.
15 // We trim to the first null char here.
16 std::string_view s{sv.data(), sv.size()};
17 auto trim_pos = s.find('\0');
18 if (trim_pos != s.npos) {
19 s.remove_suffix(s.size() - trim_pos);
20 }
21 return s;
22}
23} // namespace
24
26 ::precice::string_view participantName,
27 ::precice::string_view configurationFileName,
28 int solverProcessIndex,
29 int solverProcessSize)
30 : _impl(new impl::ParticipantImpl(toSV(participantName), toSV(configurationFileName), solverProcessIndex, solverProcessSize, std::nullopt))
31{
32}
33
35 ::precice::string_view participantName,
36 ::precice::string_view configurationFileName,
37 int solverProcessIndex,
38 int solverProcessSize,
39 void *communicator)
40 : _impl(new impl::ParticipantImpl(toSV(participantName), toSV(configurationFileName), solverProcessIndex, solverProcessSize, {communicator}))
41{
42}
43
45
47{
48 _impl->initialize();
49}
50
52 double computedTimeStepSize)
53{
54 _impl->advance(computedTimeStepSize);
55}
56
58{
59 return _impl->finalize();
60}
61
63{
64 return _impl->getMeshDimensions(toSV(meshName));
65}
66
68{
69 return _impl->getDataDimensions(toSV(meshName), toSV(dataName));
70}
71
73{
74 return _impl->isCouplingOngoing();
75}
76
78{
79 return _impl->isTimeWindowComplete();
80}
81
83{
84 return _impl->getMaxTimeStepSize();
85}
86
88{
89 return _impl->requiresInitialData();
90}
91
93{
94 return _impl->requiresReadingCheckpoint();
95}
96
98{
99 return _impl->requiresWritingCheckpoint();
100}
101
103{
104 return _impl->requiresMeshConnectivityFor(toSV(meshName));
105}
106
108{
109 return _impl->resetMesh(toSV(meshName));
110}
111
113 ::precice::string_view dataName) const
114{
115 return _impl->requiresGradientDataFor(toSV(meshName), toSV(dataName));
116}
117
119 ::precice::string_view meshName,
121{
122 return _impl->setMeshVertex(toSV(meshName), coordinates);
123}
124
126 ::precice::string_view meshName) const
127{
128 return _impl->getMeshVertexSize(toSV(meshName));
129}
130
132 ::precice::string_view meshName,
135{
136 _impl->setMeshVertices(toSV(meshName), coordinates, ids);
137}
138
140 ::precice::string_view meshName,
141 VertexID first,
142 VertexID second)
143{
144 _impl->setMeshEdge(toSV(meshName), first, second);
145}
146
148 ::precice::string_view meshName,
150{
151 _impl->setMeshEdges(toSV(meshName), ids);
152}
153
155 ::precice::string_view meshName,
156 VertexID first,
157 VertexID second,
158 VertexID third)
159{
160 _impl->setMeshTriangle(toSV(meshName), first, second, third);
161}
162
164 ::precice::string_view meshName,
166{
167 _impl->setMeshTriangles(toSV(meshName), ids);
168}
169
171 ::precice::string_view meshName,
172 VertexID first,
173 VertexID second,
174 VertexID third,
175 VertexID fourth)
176{
177 _impl->setMeshQuad(toSV(meshName), first, second, third, fourth);
178}
179
181 ::precice::string_view meshName,
183{
184 _impl->setMeshQuads(toSV(meshName), ids);
185}
186
188 ::precice::string_view meshName,
189 VertexID first,
190 VertexID second,
191 VertexID third,
192 VertexID fourth)
193{
194 _impl->setMeshTetrahedron(toSV(meshName), first, second, third, fourth);
195}
196
198 ::precice::string_view meshName,
200{
201 _impl->setMeshTetrahedra(toSV(meshName), ids);
202}
203
205 ::precice::string_view meshName,
206 ::precice::string_view dataName,
209{
210 _impl->writeData(toSV(meshName), toSV(dataName), ids, values);
211}
212
214 ::precice::string_view meshName,
215 ::precice::string_view dataName,
217 double relativeReadTime,
218 ::precice::span<double> values) const
219{
220 _impl->readData(toSV(meshName), toSV(dataName), ids, relativeReadTime, values);
221}
222
224 ::precice::string_view meshName,
225 ::precice::string_view dataName,
227 double relativeReadTime,
228 ::precice::span<double> values) const
229{
230 _impl->mapAndReadData(toSV(meshName), toSV(dataName), coordinates, relativeReadTime, values);
231}
232
234 ::precice::string_view meshName,
235 ::precice::string_view dataName,
238{
239 _impl->writeAndMapData(toSV(meshName), toSV(dataName), coordinates, values);
240}
241
243 ::precice::span<const double> boundingBox) const
244{
245 _impl->setMeshAccessRegion(toSV(meshName), boundingBox);
246}
247
250 ::precice::span<double> coordinates) const
251{
252 _impl->getMeshVertexIDsAndCoordinates(toSV(meshName), ids, coordinates);
253}
254
256 ::precice::string_view meshName,
257 ::precice::string_view dataName,
260{
261 _impl->writeGradientData(toSV(meshName), toSV(dataName), ids, gradients);
262}
263
265{
266 _impl->startProfilingSection(toSV(sectionName));
267}
268
270{
271 _impl->stopLastProfilingSection();
272}
273
274} // namespace precice
int getMeshVertexSize(::precice::string_view meshName) const
Returns the number of vertices of a mesh.
void setMeshAccessRegion(::precice::string_view meshName, ::precice::span< const double > boundingBox) const
setMeshAccessRegion Define a region of interest on a received mesh (<receive-mesh ....
void setMeshQuads(::precice::string_view meshName, ::precice::span< const VertexID > ids)
Sets multiple mesh quads from vertex IDs.
int getDataDimensions(::precice::string_view meshName, ::precice::string_view dataName) const
Returns the spatial dimensionality of the given data on the given mesh.
Participant(::precice::string_view participantName, ::precice::string_view configurationFileName, int solverProcessIndex, int solverProcessSize)
Constructs a Participant for the given participant.
bool isCouplingOngoing() const
Checks if the coupled simulation is still ongoing.
void getMeshVertexIDsAndCoordinates(::precice::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...
VertexID setMeshVertex(::precice::string_view meshName, ::precice::span< const double > position)
Creates a mesh vertex.
void finalize()
Finalizes preCICE.
void setMeshTetrahedra(::precice::string_view meshName, ::precice::span< const VertexID > ids)
Sets multiple mesh tetrahedra from vertex IDs.
void initialize()
Fully initializes preCICE and coupling data.
void writeData(::precice::string_view meshName, ::precice::string_view dataName, ::precice::span< const VertexID > ids, ::precice::span< const double > values)
Writes data to a mesh.
void setMeshTriangle(::precice::string_view meshName, VertexID first, VertexID second, VertexID third)
Sets mesh triangle from vertex IDs.
std::unique_ptr< impl::ParticipantImpl > _impl
Pointer to implementation of Participant.
void setMeshVertices(::precice::string_view meshName, ::precice::span< const double > coordinates, ::precice::span< VertexID > ids)
Creates multiple mesh vertices.
void writeGradientData(::precice::string_view meshName, ::precice::string_view dataName, ::precice::span< const VertexID > ids, ::precice::span< const double > gradients)
Writes vector gradient data to a mesh.
double getMaxTimeStepSize() const
Get the maximum allowed time step size of the current window.
bool requiresGradientDataFor(::precice::string_view meshName, ::precice::string_view dataName) const
Checks if the given data set requires gradient data. We check if the data object has been initialized...
bool requiresMeshConnectivityFor(::precice::string_view meshName) const
Checks if the given mesh requires connectivity.
void advance(double computedTimeStepSize)
Advances preCICE after the solver has computed one time step.
void startProfilingSection(::precice::string_view sectionName)
int getMeshDimensions(::precice::string_view meshName) const
Returns the spatial dimensionality of the given mesh.
void mapAndReadData(::precice::string_view meshName, ::precice::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...
void setMeshTriangles(::precice::string_view meshName, ::precice::span< const VertexID > ids)
Sets multiple mesh triangles from vertex IDs.
void setMeshEdges(::precice::string_view meshName, ::precice::span< const VertexID > ids)
Sets multiple mesh edges from vertex IDs.
void readData(::precice::string_view meshName, ::precice::string_view dataName, ::precice::span< const VertexID > ids, 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...
void setMeshEdge(::precice::string_view meshName, VertexID first, VertexID second)
Sets a mesh edge from vertex IDs.
void resetMesh(::precice::string_view meshName)
Removes all vertices and connectivity information from the mesh.
bool isTimeWindowComplete() const
Checks if the current coupling window is completed.
void setMeshTetrahedron(::precice::string_view meshName, VertexID first, VertexID second, VertexID third, VertexID fourth)
Set tetrahedron in 3D mesh from vertex ID.
void setMeshQuad(::precice::string_view meshName, VertexID first, VertexID second, VertexID third, VertexID fourth)
Sets a planar surface mesh quadrangle from vertex IDs.
void writeAndMapData(::precice::string_view meshName, ::precice::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).
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
constexpr pointer data() const noexcept
Definition span.hpp:500
constexpr size_type size() const noexcept
Definition span.hpp:469
Main namespace of the precice library.
int VertexID
Definition Types.hpp:13
STL namespace.