preCICE v3.1.1
Loading...
Searching...
No Matches
ParallelTests.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <memory>
6#include <mpi.h>
7#include <string>
8#include <vector>
9
10#include "com/Communication.hpp"
11#include "com/SharedPointer.hpp"
12#include "logging/LogMacros.hpp"
13#include "math/constants.hpp"
14#include "math/geometry.hpp"
15#include "mesh/Mesh.hpp"
21#include "testing/Testing.hpp"
22#include "utils/IntraComm.hpp"
23#include "utils/Parallel.hpp"
24
25using namespace precice;
27
37
38BOOST_AUTO_TEST_SUITE(PreciceTests)
39BOOST_FIXTURE_TEST_SUITE(Parallel, ParallelTestFixture)
40
41// Simple case of A <==> B <==> C
42void multiCouplingThreeSolversParallelControl(const std::string configFile, const TestContext &context)
43{
44 Eigen::Vector2d coordOneA{0.0, 0.0};
45 Eigen::Vector2d coordOneB{1.0, 0.0};
46
47 double valueA1 = 1.0;
48 double valueA2 = 1.5;
49 double valueB1 = 2.0;
50 double valueB2 = 2.5;
51 double valueC1 = 3.0;
52 double valueC2 = 3.5;
53
54 if (context.isNamed("SolverA")) {
55 Participant cplInterface("SolverA", configFile, context.rank, context.size);
56 auto meshName = "MeshA";
57 auto dataABID = "DataAB";
58 auto dataBAID = "DataBA";
59
60 if (context.isPrimary()) {
61 int vertex1 = cplInterface.setMeshVertex(meshName, coordOneA);
62
63 cplInterface.initialize();
64 double maxDt = cplInterface.getMaxTimeStepSize();
65 double valueRead;
66
67 BOOST_TEST(cplInterface.isCouplingOngoing());
68 while (cplInterface.isCouplingOngoing()) {
69 cplInterface.writeData(meshName, dataABID, {&vertex1, 1}, {&valueA1, 1});
70 if (cplInterface.requiresWritingCheckpoint()) {
71 }
72
73 cplInterface.advance(maxDt);
74
75 if (cplInterface.requiresReadingCheckpoint()) {
76 }
77
78 maxDt = cplInterface.getMaxTimeStepSize();
79 cplInterface.readData(meshName, dataBAID, {&vertex1, 1}, maxDt, {&valueRead, 1});
80 }
81
82 BOOST_TEST(valueRead == valueB1);
83
84 cplInterface.finalize();
85
86 } else {
87 int vertex2 = cplInterface.setMeshVertex(meshName, coordOneB);
88
89 cplInterface.initialize();
90 double maxDt = cplInterface.getMaxTimeStepSize();
91 double valueRead;
92
93 BOOST_TEST(cplInterface.isCouplingOngoing());
94 while (cplInterface.isCouplingOngoing()) {
95 cplInterface.writeData(meshName, dataABID, {&vertex2, 1}, {&valueA2, 1});
96 if (cplInterface.requiresWritingCheckpoint()) {
97 }
98
99 cplInterface.advance(maxDt);
100
101 if (cplInterface.requiresReadingCheckpoint()) {
102 }
103
104 maxDt = cplInterface.getMaxTimeStepSize();
105 cplInterface.readData(meshName, dataBAID, {&vertex2, 1}, maxDt, {&valueRead, 1});
106 }
107
108 BOOST_TEST(valueRead == valueB2);
109
110 cplInterface.finalize();
111 }
112
113 } else if (context.isNamed("SolverB")) {
114 Participant cplInterface("SolverB", configFile, 0, 1);
115 auto meshName1 = "MeshB1";
116 auto meshName2 = "MeshB2";
117 int vertex1 = cplInterface.setMeshVertex(meshName1, coordOneA);
118 int vertex2 = cplInterface.setMeshVertex(meshName1, coordOneB);
119 int vertex3 = cplInterface.setMeshVertex(meshName2, coordOneA);
120 int vertex4 = cplInterface.setMeshVertex(meshName2, coordOneB);
121
122 auto dataABID = "DataAB"; // meshName1
123 auto dataBAID = "DataBA"; // meshName1
124 auto dataCBID = "DataCB"; // meshName2;
125 auto dataBCID = "DataBC"; // meshName2;
126
127 cplInterface.initialize();
128 double maxDt = cplInterface.getMaxTimeStepSize();
129 double valueReadA1, valueReadA2, valueReadC1, valueReadC2;
130
131 BOOST_TEST(cplInterface.isCouplingOngoing());
132 while (cplInterface.isCouplingOngoing()) {
133 cplInterface.writeData(meshName1, dataBAID, {&vertex1, 1}, {&valueB1, 1});
134 cplInterface.writeData(meshName1, dataBAID, {&vertex2, 1}, {&valueB2, 1});
135 cplInterface.writeData(meshName2, dataBCID, {&vertex3, 1}, {&valueB1, 1});
136 cplInterface.writeData(meshName2, dataBCID, {&vertex4, 1}, {&valueB2, 1});
137 if (cplInterface.requiresWritingCheckpoint()) {
138 }
139
140 cplInterface.advance(maxDt);
141
142 if (cplInterface.requiresReadingCheckpoint()) {
143 }
144
145 maxDt = cplInterface.getMaxTimeStepSize();
146 cplInterface.readData(meshName1, dataABID, {&vertex1, 1}, maxDt, {&valueReadA1, 1});
147 cplInterface.readData(meshName1, dataABID, {&vertex2, 1}, maxDt, {&valueReadA2, 1});
148 cplInterface.readData(meshName2, dataCBID, {&vertex1, 1}, maxDt, {&valueReadC1, 1});
149 cplInterface.readData(meshName2, dataCBID, {&vertex2, 1}, maxDt, {&valueReadC2, 1});
150 }
151
152 BOOST_TEST(valueReadA1 == valueA1);
153 BOOST_TEST(valueReadA2 == valueA2);
154 BOOST_TEST(valueReadC1 == valueC1);
155 BOOST_TEST(valueReadC2 == valueC2);
156
157 cplInterface.finalize();
158
159 } else {
160 Participant cplInterface("SolverC", configFile, 0, 1);
161 auto meshName = "MeshC";
162 int vertex1 = cplInterface.setMeshVertex(meshName, coordOneA);
163 int vertex2 = cplInterface.setMeshVertex(meshName, coordOneB);
164 auto dataCBID = "DataCB";
165 auto dataBCID = "DataBC";
166
167 cplInterface.initialize();
168 double maxDt = cplInterface.getMaxTimeStepSize();
169 double valueRead1, valueRead2;
170
171 BOOST_TEST(cplInterface.isCouplingOngoing());
172 while (cplInterface.isCouplingOngoing()) {
173
174 cplInterface.writeData(meshName, dataCBID, {&vertex1, 1}, {&valueC1, 1});
175 cplInterface.writeData(meshName, dataCBID, {&vertex2, 1}, {&valueC2, 1});
176 if (cplInterface.requiresWritingCheckpoint()) {
177 }
178
179 cplInterface.advance(maxDt);
180
181 if (cplInterface.requiresReadingCheckpoint()) {
182 }
183
184 maxDt = cplInterface.getMaxTimeStepSize();
185 cplInterface.readData(meshName, dataBCID, {&vertex1, 1}, maxDt, {&valueRead1, 1});
186 cplInterface.readData(meshName, dataBCID, {&vertex2, 1}, maxDt, {&valueRead2, 1});
187 }
188
189 BOOST_TEST(valueRead1 == valueB1);
190 BOOST_TEST(valueRead2 == valueB2);
191
192 cplInterface.finalize();
193 }
194}
195
196// BOOST_AUTO_TEST_CASE(MultiCouplingThreeSolversParallelCentral1)
197// {
198// PRECICE_TEST("SolverA"_on(2_ranks), "SolverB"_on(1_rank), "SolverC"_on(1_rank));
199// const std::string configFile = _pathToTests + "multi-coupling-three-solver-1.xml";
200// multiCouplingThreeSolversParallelControl(configFile, context);
201// }
202
203// BOOST_AUTO_TEST_CASE(MultiCouplingThreeSolversParallelCentral2)
204// {
205// PRECICE_TEST("SolverA"_on(2_ranks), "SolverB"_on(1_rank), "SolverC"_on(1_rank));
206// const std::string configFile = _pathToTests + "multi-coupling-three-solver-2.xml";
207// multiCouplingThreeSolversParallelControl(configFile, context);
208// }
209
210// BOOST_AUTO_TEST_CASE(MultiCouplingThreeSolversParallelCentral3)
211// {
212// PRECICE_TEST("SolverA"_on(2_ranks), "SolverB"_on(1_rank), "SolverC"_on(1_rank));
213// const std::string configFile = _pathToTests + "multi-coupling-three-solver-3.xml";
214// multiCouplingThreeSolversParallelControl(configFile, context);
215// }
216
219#endif // PRECICE_NO_MPI
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
void multiCouplingThreeSolversParallelControl(const std::string configFile, const TestContext &context)
Main Application Programming Interface of preCICE. Include using #include <precice/precice....
bool isCouplingOngoing() const
Checks if the coupled simulation is still ongoing.
VertexID setMeshVertex(::precice::string_view meshName, ::precice::span< const double > position)
Creates a mesh vertex.
void finalize()
Finalizes preCICE.
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.
double getMaxTimeStepSize() const
Get the maximum allowed time step size of the current window.
void advance(double computedTimeStepSize)
Advances preCICE after the solver has computed one time step.
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...
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:31
Main namespace of the precice library.
STL namespace.
struct giving access to the impl of a befriended class or struct
Definition Testing.hpp:37