preCICE v3.1.2
Loading...
Searching...
No Matches
preciceC.cpp
Go to the documentation of this file.
1extern "C" {
2#include "precice/preciceC.h"
3}
4#include <memory>
5#include <string>
7#include "logging/Logger.hpp"
8#include "precice/impl/versions.hpp"
9#include "precice/precice.hpp"
10#include "utils/assertion.hpp"
11
12#ifdef __GNUC__
13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
15#endif
16#ifdef __clang__
17#pragma clang diagnostic push
18#pragma clang diagnostic ignored "-Wdeprecated-declarations"
19#endif
20
22
23static precice::logging::Logger _log("precicec");
24
25static std::string errormsg = "preCICE has not been created properly. Be sure to call \"precicec_createParticipant\" or \"precicec_createParticipant_withCommunicator\" before any other call to preCICE.";
26static std::string errormsgCreate = "preCICE has been created already! Be sure to call either \"precicec_createParticipant\" or \"precicec_createParticipant_withCommunicator\" exactly once.";
27
29 const char *participantName,
30 const char *configFileName,
31 int solverProcessIndex,
32 int solverProcessSize,
33 void * communicator)
34{
36 impl.reset(new precice::Participant(participantName,
37 configFileName,
38 solverProcessIndex,
39 solverProcessSize,
40 communicator));
41}
42
44 const char *participantName,
45 const char *configFileName,
46 int solverProcessIndex,
47 int solverProcessSize)
48{
50 impl.reset(new precice::Participant(participantName,
51 configFileName,
52 solverProcessIndex,
53 solverProcessSize));
54}
55
57{
58 PRECICE_CHECK(impl != nullptr, errormsg);
59 impl->initialize();
60}
61
62void precicec_advance(double computedTimeStepSize)
63{
64 PRECICE_CHECK(impl != nullptr, errormsg);
65 impl->advance(computedTimeStepSize);
66}
67
69{
70 PRECICE_CHECK(impl != nullptr, errormsg);
71 impl->finalize();
72 impl.reset();
73}
74
75int precicec_getMeshDimensions(const char *meshName)
76{
77 PRECICE_CHECK(impl != nullptr, errormsg);
78 return impl->getMeshDimensions(meshName);
79}
80
81int precicec_getDataDimensions(const char *meshName, const char *dataName)
82{
83 PRECICE_CHECK(impl != nullptr, errormsg);
84 return impl->getDataDimensions(meshName, dataName);
85}
86
88{
89 PRECICE_CHECK(impl != nullptr, errormsg);
90 if (impl->isCouplingOngoing()) {
91 return 1;
92 }
93 return 0;
94}
95
97{
98 PRECICE_CHECK(impl != nullptr, errormsg);
99 if (impl->isTimeWindowComplete()) {
100 return 1;
101 }
102 return 0;
103}
104
106{
107 return impl->getMaxTimeStepSize();
108}
109
111{
112 PRECICE_CHECK(impl != nullptr, errormsg);
113 return impl->requiresInitialData() ? 1 : 0;
114}
115
117{
118 PRECICE_CHECK(impl != nullptr, errormsg);
119 return impl->requiresWritingCheckpoint() ? 1 : 0;
120}
121
123{
124 PRECICE_CHECK(impl != nullptr, errormsg);
125 return impl->requiresReadingCheckpoint() ? 1 : 0;
126}
127
129{
130 PRECICE_CHECK(impl != nullptr, errormsg);
131 if (impl->requiresMeshConnectivityFor(meshName)) {
132 return 1;
133 }
134 return 0;
135}
136
138 const char * meshName,
139 const double *position)
140{
141 PRECICE_CHECK(impl != nullptr, errormsg);
142 auto size = static_cast<long unsigned>(impl->getMeshDimensions(meshName));
143 return impl->setMeshVertex(meshName, {position, size});
144}
145
147 const char * meshName,
148 int size,
149 const double *positions,
150 int * ids)
151{
152 PRECICE_CHECK(impl != nullptr, errormsg);
153 auto idsSize = static_cast<long unsigned>(size);
154 auto posSize = static_cast<long unsigned>(impl->getMeshDimensions(meshName) * size);
155 impl->setMeshVertices(meshName, {positions, posSize}, {ids, idsSize});
156}
157
159 const char *meshName)
160{
161 PRECICE_CHECK(impl != nullptr, errormsg);
162 return impl->getMeshVertexSize(meshName);
163}
164
166 const char *meshName,
167 int firstVertexID,
168 int secondVertexID)
169{
170 PRECICE_CHECK(impl != nullptr, errormsg);
171 impl->setMeshEdge(meshName, firstVertexID, secondVertexID);
172}
173
175 const char *meshName,
176 int size,
177 const int * vertices)
178{
179 PRECICE_CHECK(impl != nullptr, errormsg);
180 auto verticesSize = static_cast<long unsigned>(size) * 2;
181 impl->setMeshEdges(meshName, {vertices, verticesSize});
182}
183
185 const char *meshName,
186 int firstVertexID,
187 int secondVertexID,
188 int thirdVertexID)
189{
190 PRECICE_CHECK(impl != nullptr, errormsg);
191 impl->setMeshTriangle(meshName, firstVertexID, secondVertexID, thirdVertexID);
192}
193
195 const char *meshName,
196 int size,
197 const int * vertices)
198{
199 PRECICE_CHECK(impl != nullptr, errormsg);
200 auto verticesSize = static_cast<long unsigned>(size) * 3;
201 impl->setMeshTriangles(meshName, {vertices, verticesSize});
202}
203
205 const char *meshName,
206 int firstVertexID,
207 int secondVertexID,
208 int thirdVertexID,
209 int fourthVertexID)
210{
211 PRECICE_CHECK(impl != nullptr, errormsg);
212 impl->setMeshQuad(meshName, firstVertexID, secondVertexID, thirdVertexID, fourthVertexID);
213}
214
216 const char *meshName,
217 int size,
218 const int * vertices)
219{
220 PRECICE_CHECK(impl != nullptr, errormsg);
221 auto verticesSize = static_cast<long unsigned>(size) * 4;
222 impl->setMeshQuads(meshName, {vertices, verticesSize});
223}
224
226 const char *meshName,
227 int firstVertexID,
228 int secondVertexID,
229 int thirdVertexID,
230 int fourthVertexID)
231{
232 PRECICE_CHECK(impl != nullptr, errormsg);
233 impl->setMeshTetrahedron(meshName, firstVertexID, secondVertexID, thirdVertexID, fourthVertexID);
234}
235
237 const char *meshName,
238 int size,
239 const int * vertices)
240{
241 PRECICE_CHECK(impl != nullptr, errormsg);
242 auto verticesSize = static_cast<long unsigned>(size) * 4;
243 impl->setMeshTetrahedra(meshName, {vertices, verticesSize});
244}
245
247 const char * meshName,
248 const char * dataName,
249 int size,
250 const int * valueIndices,
251 const double *values)
252{
253 PRECICE_CHECK(impl != nullptr, errormsg);
254 auto dataSize = size * impl->getDataDimensions(meshName, dataName);
255 impl->writeData(meshName, dataName, {valueIndices, static_cast<unsigned long>(size)}, {values, static_cast<unsigned long>(dataSize)});
256}
257
259 const char *meshName,
260 const char *dataName,
261 int size,
262 const int * valueIndices,
263 double relativeReadTime,
264 double * values)
265{
266 PRECICE_CHECK(impl != nullptr, errormsg);
267 auto dataSize = size * impl->getDataDimensions(meshName, dataName);
268 impl->readData(meshName, dataName, {valueIndices, static_cast<unsigned long>(size)}, relativeReadTime, {values, static_cast<unsigned long>(dataSize)});
269}
270
271int precicec_requiresGradientDataFor(const char *meshName,
272 const char *dataName)
273{
274 PRECICE_CHECK(impl != nullptr, errormsg);
275 if (impl->requiresGradientDataFor(meshName, dataName)) {
276 return 1;
277 }
278 return 0;
279}
280
282 const char * meshName,
283 const char * dataName,
284 int size,
285 const int * valueIndices,
286 const double *gradients)
287{
288 PRECICE_CHECK(impl != nullptr, errormsg);
289 auto gradientComponents = impl->getDataDimensions(meshName, dataName) * impl->getMeshDimensions(meshName);
290 auto gradientSize = size * gradientComponents;
291 impl->writeGradientData(meshName, dataName, {valueIndices, static_cast<unsigned long>(size)}, {gradients, static_cast<unsigned long>(gradientSize)});
292}
293
295{
296 return precice::versionInformation;
297}
298
300 const char * meshName,
301 const double *boundingBox)
302{
303 auto bbSize = static_cast<long unsigned>(impl->getMeshDimensions(meshName)) * 2;
304 impl->setMeshAccessRegion(meshName, {boundingBox, bbSize});
305}
306
308 const char *meshName,
309 const int size,
310 int * ids,
311 double * coordinates)
312{
313 auto coordinatesSize = static_cast<long unsigned>(impl->getMeshDimensions(meshName) * size);
314 impl->getMeshVertexIDsAndCoordinates(meshName, {ids, static_cast<unsigned long>(size)}, {coordinates, coordinatesSize});
315}
316
317#ifdef __GNUC__
318#pragma GCC diagnostic pop
319#endif
320#ifdef __clang__
321#pragma clang diagnostic pop
322#endif
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
Main Application Programming Interface of preCICE. Include using #include <precice/precice....
This class provides a lightweight logger.
Definition Logger.hpp:16
double precicec_getMaxTimeStepSize()
Returns maximum allowed time step size.
Definition preciceC.cpp:105
static precice::logging::Logger _log("precicec")
void precicec_setMeshTriangles(const char *meshName, int size, const int *vertices)
Sets multiple mesh triangles from vertex IDs.
Definition preciceC.cpp:194
void precicec_setMeshTetrahedra(const char *meshName, int size, const int *vertices)
Sets multiple mesh tetrahedra from vertex IDs.
Definition preciceC.cpp:236
int precicec_requiresReadingCheckpoint()
Definition preciceC.cpp:122
int precicec_isTimeWindowComplete()
Returns true (->1), if the coupling time window is completed.
Definition preciceC.cpp:96
static std::string errormsgCreate
Definition preciceC.cpp:26
void precicec_writeData(const char *meshName, const char *dataName, int size, const int *valueIndices, const double *values)
Writes vector data values given as block.
Definition preciceC.cpp:246
void precicec_readData(const char *meshName, const char *dataName, int size, const int *valueIndices, double relativeReadTime, double *values)
Reads vector data values given as block.
Definition preciceC.cpp:258
int precicec_getDataDimensions(const char *meshName, const char *dataName)
Returns the spatial dimensionality of the given data on the given mesh.
Definition preciceC.cpp:81
void precicec_setMeshEdge(const char *meshName, int firstVertexID, int secondVertexID)
Sets mesh edge from vertex IDs.
Definition preciceC.cpp:165
void precicec_createParticipant(const char *participantName, const char *configFileName, int solverProcessIndex, int solverProcessSize)
Creates the coupling interface and configures it.
Definition preciceC.cpp:43
void precicec_setMeshQuad(const char *meshName, int firstVertexID, int secondVertexID, int thirdVertexID, int fourthVertexID)
Sets surface mesh quadrangle from vertex IDs.
Definition preciceC.cpp:204
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21
int precicec_getMeshDimensions(const char *meshName)
Returns the spatial dimensionality of the given mesh.
Definition preciceC.cpp:75
void precicec_initialize()
Initiates the coupling to the coupling supervisor and initializes coupling data.
Definition preciceC.cpp:56
static std::string errormsg
Definition preciceC.cpp:25
void precicec_setMeshEdges(const char *meshName, int size, const int *vertices)
Sets multiple mesh edge from vertex IDs.
Definition preciceC.cpp:174
int precicec_requiresInitialData()
Definition preciceC.cpp:110
int precicec_isCouplingOngoing()
Returns true (->1), if the coupled simulation is ongoing.
Definition preciceC.cpp:87
int precicec_getMeshVertexSize(const char *meshName)
Returns the number of vertices of a mesh.
Definition preciceC.cpp:158
void precicec_writeGradientData(const char *meshName, const char *dataName, int size, const int *valueIndices, const double *gradients)
Writes vector gradient data to a mesh.
Definition preciceC.cpp:281
void precicec_setMeshAccessRegion(const char *meshName, const double *boundingBox)
See precice::Participant::setMeshAccessRegion().
Definition preciceC.cpp:299
void precicec_setMeshTriangle(const char *meshName, int firstVertexID, int secondVertexID, int thirdVertexID)
Sets a triangle from vertex IDs. Creates missing edges.
Definition preciceC.cpp:184
int precicec_setMeshVertex(const char *meshName, const double *position)
Creates a mesh vertex.
Definition preciceC.cpp:137
void precicec_finalize()
Finalizes the coupling to the coupling supervisor.
Definition preciceC.cpp:68
int precicec_requiresMeshConnectivityFor(const char *meshName)
Checks if the given mesh requires connectivity.
Definition preciceC.cpp:128
void precicec_setMeshVertices(const char *meshName, int size, const double *positions, int *ids)
Creates multiple mesh vertices.
Definition preciceC.cpp:146
void precicec_advance(double computedTimeStepSize)
Exchanges data between solver and coupling supervisor.
Definition preciceC.cpp:62
void precicec_createParticipant_withCommunicator(const char *participantName, const char *configFileName, int solverProcessIndex, int solverProcessSize, void *communicator)
Definition preciceC.cpp:28
void precicec_setMeshQuads(const char *meshName, int size, const int *vertices)
Sets multiple mesh quads from vertex IDs.
Definition preciceC.cpp:215
int precicec_requiresGradientDataFor(const char *meshName, const char *dataName)
Checks if the given data set requires gradient data. We check if the data object has been initialized...
Definition preciceC.cpp:271
void precicec_getMeshVertexIDsAndCoordinates(const char *meshName, const int size, int *ids, double *coordinates)
See precice::Participant::getMeshVertexIDsAndCoordinates().
Definition preciceC.cpp:307
int precicec_requiresWritingCheckpoint()
Definition preciceC.cpp:116
void precicec_setMeshTetrahedron(const char *meshName, int firstVertexID, int secondVertexID, int thirdVertexID, int fourthVertexID)
Sets mesh tetrahedron from vertex IDs.
Definition preciceC.cpp:225
const char * precicec_getVersionInformation()
Returns information on the version of preCICE.
Definition preciceC.cpp:294
C language bindings to main Application Programming Interface of preCICE.