preCICE v3.2.0
Loading...
Searching...
No Matches
ProvidedPartitionTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2#include <Eigen/Core>
3#include <algorithm>
4#include <deque>
5#include <map>
6#include <memory>
7#include <string>
8#include <vector>
9
10#include "com/Communication.hpp"
11#include "com/Extra.hpp"
12#include "com/SharedPointer.hpp"
13#include "m2n/M2N.hpp"
14#include "mapping/Mapping.hpp"
17#include "math/constants.hpp"
18#include "mesh/BoundingBox.hpp"
19#include "mesh/Data.hpp"
20#include "mesh/Mesh.hpp"
26#include "testing/Testing.hpp"
27#include "utils/assertion.hpp"
28
29namespace precice::mesh {
30class Edge;
31class Vertex;
32} // namespace precice::mesh
33
34using namespace precice;
35using namespace partition;
37
38BOOST_AUTO_TEST_SUITE(PartitionTests)
39BOOST_AUTO_TEST_SUITE(ProvidedPartitionTests)
40
41PRECICE_TEST_SETUP("NASTIN"_on(1_rank), "SOLIDZ"_on(3_ranks).setupIntraComm(), Require::Events)
42BOOST_AUTO_TEST_CASE(TestGatherAndCommunicate2D)
43{
45 auto m2n = context.connectPrimaryRanks("NASTIN", "SOLIDZ");
46
47 int dimensions = 2;
48
49 if (context.isNamed("NASTIN")) { // NASTIN
50 mesh::PtrMesh pSolidzMesh(new mesh::Mesh("SolidzMesh", dimensions, testing::nextMeshID()));
51
52 double safetyFactor = 0.1;
53
54 ReceivedPartition part(pSolidzMesh, ReceivedPartition::ON_SECONDARY_RANKS, safetyFactor);
55 part.addM2N(m2n);
56 part.communicate();
57
58 BOOST_TEST(pSolidzMesh->nVertices() == 6);
59 BOOST_TEST(pSolidzMesh->edges().size() == 4);
60
61 for (int i = 0; i < 6; i++) {
62 BOOST_TEST(pSolidzMesh->vertex(i).getGlobalIndex() == i);
63 }
64 } else { // SOLIDZ
65 mesh::PtrMesh pSolidzMesh(new mesh::Mesh("SolidzMesh", dimensions, testing::nextMeshID()));
66
67 if (context.isPrimary()) { // Primary
68 Eigen::VectorXd position(dimensions);
69 position << 0.0, 0.0;
70 mesh::Vertex &v1 = pSolidzMesh->createVertex(position);
71 position << 0.0, 1.5;
72 mesh::Vertex &v2 = pSolidzMesh->createVertex(position);
73 pSolidzMesh->createEdge(v1, v2);
74 } else if (context.isRank(1)) { // SecondaryRank1
75 } else if (context.isRank(2)) { // Secondary rank 2
76 Eigen::VectorXd position(dimensions);
77 position << 0.0, 3.5;
78 mesh::Vertex &v3 = pSolidzMesh->createVertex(position);
79 position << 0.0, 4.5;
80 mesh::Vertex &v4 = pSolidzMesh->createVertex(position);
81 position << 0.0, 5.5;
82 mesh::Vertex &v5 = pSolidzMesh->createVertex(position);
83 position << 0.0, 7.0;
84 mesh::Vertex &v6 = pSolidzMesh->createVertex(position);
85 pSolidzMesh->createEdge(v3, v4);
86 pSolidzMesh->createEdge(v4, v5);
87 pSolidzMesh->createEdge(v5, v6);
88 }
89 pSolidzMesh->computeBoundingBox();
90
91 ProvidedPartition part(pSolidzMesh);
92 part.addM2N(m2n);
93 part.communicate();
94 part.compute();
95
96 BOOST_REQUIRE(pSolidzMesh->getVertexOffsets().size() == 3);
97 if (context.isPrimary()) {
98 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(0) == 2);
99 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(1) == 2);
100 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(2) == 6);
101 } else if (context.isRank(1)) { // SecondaryRank1
102 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(0) == 2);
103 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(1) == 2);
104 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(2) == 6);
105 } else {
106 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(0) == 2);
107 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(1) == 2);
108 BOOST_TEST(pSolidzMesh->getVertexOffsets().at(2) == 6);
109 }
110 }
111}
112
113PRECICE_TEST_SETUP("NASTIN"_on(1_rank), "SOLIDZ"_on(3_ranks).setupIntraComm(), Require::Events)
114BOOST_AUTO_TEST_CASE(TestGatherAndCommunicate3D)
115{
116 PRECICE_TEST();
117 auto m2n = context.connectPrimaryRanks("NASTIN", "SOLIDZ");
118
119 int dimensions = 3;
120
121 if (context.isNamed("NASTIN")) { // NASTIN
122 mesh::PtrMesh pSolidzMesh(new mesh::Mesh("SolidzMesh", dimensions, testing::nextMeshID()));
123
124 double safetyFactor = 0.1;
125
126 ReceivedPartition part(pSolidzMesh, ReceivedPartition::ON_SECONDARY_RANKS, safetyFactor);
127 part.addM2N(m2n);
128 part.communicate();
129
130 BOOST_TEST(pSolidzMesh->nVertices() == 6);
131 BOOST_TEST(pSolidzMesh->edges().size() == 6);
132 BOOST_TEST(pSolidzMesh->triangles().size() == 2);
133
134 for (int i = 0; i < 6; i++) {
135 BOOST_TEST(pSolidzMesh->vertex(i).getGlobalIndex() == i);
136 }
137 } else { // SOLIDZ
138 mesh::PtrMesh pSolidzMesh(new mesh::Mesh("SolidzMesh", dimensions, testing::nextMeshID()));
139
140 if (context.isPrimary()) { // Primary
141 Eigen::VectorXd position(dimensions);
142 position << 0.0, 0.0, 0.0;
143 mesh::Vertex &v1 = pSolidzMesh->createVertex(position);
144 position << 0.0, 1.5, 1.0;
145 mesh::Vertex &v2 = pSolidzMesh->createVertex(position);
146 pSolidzMesh->createEdge(v1, v2);
147 } else if (context.isRank(1)) { // SecondaryRank1
148 } else if (context.isRank(2)) { // Secondary rank 2
149 Eigen::VectorXd position(dimensions);
150 position << 0.0, 3.5, 0.1;
151 mesh::Vertex &v3 = pSolidzMesh->createVertex(position);
152 position << 0.0, 4.5, 0.2;
153 mesh::Vertex &v4 = pSolidzMesh->createVertex(position);
154 position << 0.0, 5.5, 0.8;
155 mesh::Vertex &v5 = pSolidzMesh->createVertex(position);
156 position << 0.0, 7.0, 0.4;
157 mesh::Vertex &v6 = pSolidzMesh->createVertex(position);
158 mesh::Edge &e1 = pSolidzMesh->createEdge(v3, v4);
159 mesh::Edge &e2 = pSolidzMesh->createEdge(v4, v5);
160 mesh::Edge &e3 = pSolidzMesh->createEdge(v5, v3);
161 mesh::Edge &e4 = pSolidzMesh->createEdge(v3, v6);
162 mesh::Edge &e5 = pSolidzMesh->createEdge(v6, v5);
163
164 pSolidzMesh->createTriangle(e1, e2, e3);
165 pSolidzMesh->createTriangle(e4, e5, e3);
166 }
167 pSolidzMesh->computeBoundingBox();
168
169 ProvidedPartition part(pSolidzMesh);
170 part.addM2N(m2n);
171 part.communicate();
172 part.compute();
173
174 BOOST_TEST(pSolidzMesh->getGlobalNumberOfVertices() == 6);
175 const auto &vertices = pSolidzMesh->vertices();
176 const auto &vertexOffsets = pSolidzMesh->getVertexOffsets();
177 const auto &vertexDistribution = pSolidzMesh->getVertexDistribution();
178
179 if (context.isPrimary()) {
180 BOOST_REQUIRE(vertexOffsets.size() == 3);
181 BOOST_TEST(vertexOffsets.at(0) == 2);
182 BOOST_TEST(vertexOffsets.at(1) == 2);
183 BOOST_TEST(vertexOffsets.at(2) == 6);
184
185 BOOST_REQUIRE(vertices.size() == 2);
186 BOOST_TEST(vertices.at(0).getGlobalIndex() == 0);
187 BOOST_TEST(vertices.at(1).getGlobalIndex() == 1);
188 BOOST_TEST(vertices.at(0).isOwner() == true);
189 BOOST_TEST(vertices.at(1).isOwner() == true);
190
191 BOOST_REQUIRE((vertexDistribution.size()) == 3);
192 BOOST_TEST(vertexDistribution.at(0).size() == 2);
193 BOOST_TEST(vertexDistribution.at(1).size() == 0);
194 BOOST_TEST(vertexDistribution.at(2).size() == 4);
195 BOOST_TEST(vertexDistribution.at(0).at(0) == 0);
196 BOOST_TEST(vertexDistribution.at(0).at(1) == 1);
197 BOOST_TEST(vertexDistribution.at(2).at(0) == 2);
198 BOOST_TEST(vertexDistribution.at(2).at(1) == 3);
199 BOOST_TEST(vertexDistribution.at(2).at(2) == 4);
200 BOOST_TEST(vertexDistribution.at(2).at(3) == 5);
201 } else if (context.isRank(1)) { // SecondaryRank1
202 BOOST_REQUIRE(vertexOffsets.size() == 3);
203 BOOST_TEST(vertexOffsets.at(0) == 2);
204 BOOST_TEST(vertexOffsets.at(1) == 2);
205 BOOST_TEST(vertexOffsets.at(2) == 6);
206 } else if (context.isRank(2)) { // Secondary rank 2
207 BOOST_REQUIRE(vertexOffsets.size() == 3);
208 BOOST_TEST(vertexOffsets.at(0) == 2);
209 BOOST_TEST(vertexOffsets.at(1) == 2);
210 BOOST_TEST(vertexOffsets.at(2) == 6);
211
212 BOOST_REQUIRE(vertices.size() == 4);
213 BOOST_TEST(vertices.at(0).getGlobalIndex() == 2);
214 BOOST_TEST(vertices.at(1).getGlobalIndex() == 3);
215 BOOST_TEST(vertices.at(2).getGlobalIndex() == 4);
216 BOOST_TEST(vertices.at(3).getGlobalIndex() == 5);
217 BOOST_TEST(vertices.at(0).isOwner() == true);
218 BOOST_TEST(vertices.at(1).isOwner() == true);
219 BOOST_TEST(vertices.at(2).isOwner() == true);
220 BOOST_TEST(vertices.at(3).isOwner() == true);
221 }
222 }
223}
224
225PRECICE_TEST_SETUP("NASTIN"_on(4_ranks).setupIntraComm(), Require::Events)
226BOOST_AUTO_TEST_CASE(TestOnlyDistribution2D)
227{
228 PRECICE_TEST();
229 // Create mesh object
230 std::string meshName("MyMesh");
231 int dim = 2;
232 mesh::PtrMesh pMesh(new mesh::Mesh(meshName, dim, testing::nextMeshID()));
233
234 if (context.isPrimary()) { // Primary
235 Eigen::VectorXd position(dim);
236 position << 0.0, 0.0;
237 pMesh->createVertex(position);
238 position << 1.0, 0.0;
239 pMesh->createVertex(position);
240 } else if (context.isRank(1)) { // SecondaryRank1
241 Eigen::VectorXd position(dim);
242 position << 2.0, 0.0;
243 pMesh->createVertex(position);
244 } else if (context.isRank(2)) { // Secondary rank 2
245 } else if (context.isRank(3)) { // Secondary rank 3
246 Eigen::VectorXd position(dim);
247 position << 3.0, 0.0;
248 pMesh->createVertex(position);
249 position << 4.0, 0.0;
250 pMesh->createVertex(position);
251 }
252 pMesh->computeBoundingBox();
253
254 ProvidedPartition part(pMesh);
255 part.communicate();
256 part.compute();
257
258 BOOST_TEST_CONTEXT(*pMesh)
259 {
260 if (context.isPrimary()) { // Primary
261 BOOST_TEST(pMesh->getGlobalNumberOfVertices() == 5);
262 BOOST_TEST_REQUIRE(pMesh->getVertexOffsets().size() == 4);
263 BOOST_TEST(pMesh->getVertexOffsets().at(0) == 2);
264 BOOST_TEST(pMesh->getVertexOffsets().at(1) == 3);
265 BOOST_TEST(pMesh->getVertexOffsets().at(2) == 3);
266 BOOST_TEST(pMesh->getVertexOffsets().at(3) == 5);
267 BOOST_TEST(pMesh->vertex(0).getGlobalIndex() == 0);
268 BOOST_TEST(pMesh->vertex(1).getGlobalIndex() == 1);
269 BOOST_TEST(pMesh->vertex(0).isOwner() == true);
270 BOOST_TEST(pMesh->vertex(1).isOwner() == true);
271 } else if (context.isRank(1)) { // SecondaryRank1
272 BOOST_TEST(pMesh->getGlobalNumberOfVertices() == 5);
273 BOOST_TEST_REQUIRE(pMesh->getVertexOffsets().size() == 4);
274 BOOST_TEST(pMesh->getVertexOffsets().at(0) == 2);
275 BOOST_TEST(pMesh->getVertexOffsets().at(1) == 3);
276 BOOST_TEST(pMesh->getVertexOffsets().at(2) == 3);
277 BOOST_TEST(pMesh->getVertexOffsets().at(3) == 5);
278 BOOST_TEST(pMesh->vertex(0).getGlobalIndex() == 2);
279 BOOST_TEST(pMesh->vertex(0).isOwner() == true);
280 } else if (context.isRank(2)) { // Secondary rank 2
281 BOOST_TEST(pMesh->getGlobalNumberOfVertices() == 5);
282 BOOST_TEST_REQUIRE(pMesh->getVertexOffsets().size() == 4);
283 BOOST_TEST(pMesh->getVertexOffsets().at(0) == 2);
284 BOOST_TEST(pMesh->getVertexOffsets().at(1) == 3);
285 BOOST_TEST(pMesh->getVertexOffsets().at(2) == 3);
286 BOOST_TEST(pMesh->getVertexOffsets().at(3) == 5);
287 } else if (context.isRank(3)) { // Secondary rank 3
288 BOOST_TEST(pMesh->getGlobalNumberOfVertices() == 5);
289 BOOST_TEST_REQUIRE(pMesh->getVertexOffsets().size() == 4);
290 BOOST_TEST(pMesh->getVertexOffsets().at(0) == 2);
291 BOOST_TEST(pMesh->getVertexOffsets().at(1) == 3);
292 BOOST_TEST(pMesh->getVertexOffsets().at(2) == 3);
293 BOOST_TEST(pMesh->getVertexOffsets().at(3) == 5);
294 BOOST_TEST(pMesh->vertex(0).getGlobalIndex() == 3);
295 BOOST_TEST(pMesh->vertex(1).getGlobalIndex() == 4);
296 BOOST_TEST(pMesh->vertex(0).isOwner() == true);
297 BOOST_TEST(pMesh->vertex(1).isOwner() == true);
298 }
299 }
300}
301
302PRECICE_TEST_SETUP("SOLIDZ"_on(3_ranks).setupIntraComm(), "NASTIN"_on(1_rank), Require::Events)
303BOOST_AUTO_TEST_CASE(TestCompareBoundingBoxes2D)
304{
305 PRECICE_TEST();
307 options.useOnlyPrimaryCom = false;
308 options.useTwoLevelInit = true;
309 auto m2n = context.connectPrimaryRanks("NASTIN", "SOLIDZ", options);
310
311 int dimensions = 2;
312
313 if (context.isNamed("SOLIDZ")) { // SOLIDZ
314
315 mesh::PtrMesh pSolidzMesh(new mesh::Mesh("SolidzMesh", dimensions, testing::nextMeshID()));
316
317 if (context.isPrimary()) { // Primary
318 Eigen::VectorXd position(dimensions);
319 position << -1.0, 0.0;
320 mesh::Vertex &v0 = pSolidzMesh->createVertex(position);
321 position << 1.0, 2.0;
322 mesh::Vertex &v1 = pSolidzMesh->createVertex(position);
323 position << 5.0, 3.0;
324 mesh::Vertex &v2 = pSolidzMesh->createVertex(position);
325 pSolidzMesh->createEdge(v0, v1);
326 pSolidzMesh->createEdge(v1, v2);
327 }
328
329 else if (context.isRank(1)) { // SecondaryRank1
330 Eigen::VectorXd position(dimensions);
331 position << 1.0, 3.5;
332 mesh::Vertex &v3 = pSolidzMesh->createVertex(position);
333 position << 0.0, 4.5;
334 mesh::Vertex &v4 = pSolidzMesh->createVertex(position);
335 pSolidzMesh->createEdge(v3, v4);
336 } else if (context.isRank(2)) { // Secondary rank 2
337 Eigen::VectorXd position(dimensions);
338 position << 2.5, 5.5;
339 mesh::Vertex &v5 = pSolidzMesh->createVertex(position);
340 position << 4.5, 7.0;
341 mesh::Vertex &v6 = pSolidzMesh->createVertex(position);
342 pSolidzMesh->createEdge(v5, v6);
343 }
344 pSolidzMesh->computeBoundingBox();
345
346 ProvidedPartition part(pSolidzMesh);
347 part.addM2N(m2n);
349
350 if (context.isPrimary()) { // Primary
351 BOOST_TEST(pSolidzMesh->getConnectedRanks().size() == 2);
352 BOOST_TEST(pSolidzMesh->getConnectedRanks().at(0) == 1);
353 BOOST_TEST(pSolidzMesh->getConnectedRanks().at(1) == 2);
354 } else if (context.isRank(1)) { // SecondaryRank1
355 BOOST_TEST(pSolidzMesh->getConnectedRanks().size() == 2);
356 BOOST_TEST(pSolidzMesh->getConnectedRanks().at(0) == 0);
357 BOOST_TEST(pSolidzMesh->getConnectedRanks().at(1) == 2);
358 } else if (context.isRank(2)) { // Secondary rank 2
359 BOOST_TEST(pSolidzMesh->getConnectedRanks().size() == 2);
360 BOOST_TEST(pSolidzMesh->getConnectedRanks().at(0) == 0);
361 BOOST_TEST(pSolidzMesh->getConnectedRanks().at(1) == 1);
362 }
363
364 } else { // NASTIN
365 BOOST_TEST(context.isNamed("NASTIN"));
366
367 mesh::Mesh::BoundingBoxMap receivedGlobalBB;
368 mesh::BoundingBox localBB{dimensions};
369
371 compareBB.emplace(0, mesh::BoundingBox({-1, 5, 0, 3}));
372 compareBB.emplace(1, mesh::BoundingBox({0, 1, 3.5, 4.5}));
373 compareBB.emplace(2, mesh::BoundingBox({2.5, 4.5, 5.5, 7.0}));
374
375 // we receive other participants communicator size
376 int receivedFeedbackSize = 3;
377 m2n->getPrimaryRankCommunication()->receive(receivedFeedbackSize, 0);
378
379 for (int i = 0; i < receivedFeedbackSize; i++) {
380 receivedGlobalBB.emplace(i, localBB);
381 }
382
383 // we receive global bounding box from other participant!
384 com::receiveBoundingBoxMap(*m2n->getPrimaryRankCommunication(), 0, receivedGlobalBB);
385 // check whether we have received the correct com size
386 BOOST_TEST(receivedFeedbackSize == 3);
387
388 // check the validity of received global bounding box (globalBB)
389 BOOST_TEST(receivedGlobalBB.at(0) == compareBB.at(0));
390 BOOST_TEST(receivedGlobalBB.at(1) == compareBB.at(1));
391 BOOST_TEST(receivedGlobalBB.at(2) == compareBB.at(2));
392
393 std::vector<int> connectedRanks = {0, 1, 2};
394 m2n->getPrimaryRankCommunication()->sendRange(connectedRanks, 0);
395
396 // construct connection map
397 std::map<int, std::vector<int>> connectionMap;
398 connectionMap[0].push_back(1);
399 connectionMap[0].push_back(2);
400 connectionMap[1].push_back(0);
401 connectionMap[1].push_back(2);
402 connectionMap[2].push_back(0);
403 connectionMap[2].push_back(1);
404
405 com::sendConnectionMap(*m2n->getPrimaryRankCommunication(), 0, connectionMap);
406 }
407}
408
409PRECICE_TEST_SETUP("SOLIDZ"_on(3_ranks).setupIntraComm(), "NASTIN"_on(1_rank), Require::Events)
410BOOST_AUTO_TEST_CASE(TestSendBoundingBoxes3D)
411{
412 PRECICE_TEST();
414 options.useOnlyPrimaryCom = false;
415 options.useTwoLevelInit = true;
416 auto m2n = context.connectPrimaryRanks("NASTIN", "SOLIDZ", options);
417
418 int dimensions = 3;
419
420 if (context.isNamed("SOLIDZ")) { // SOLIDZ
421
422 mesh::PtrMesh pSolidzMesh(new mesh::Mesh("SolidzMesh", dimensions, testing::nextMeshID()));
423
424 if (context.isPrimary()) { // Primary
425 Eigen::VectorXd position(dimensions);
426 position << -1.0, 0.0, -1.0;
427 mesh::Vertex &v0 = pSolidzMesh->createVertex(position);
428 position << 1.0, 2.0, 1.0;
429 mesh::Vertex &v1 = pSolidzMesh->createVertex(position);
430 position << 5.0, 3.0, 5.0;
431 mesh::Vertex &v2 = pSolidzMesh->createVertex(position);
432 pSolidzMesh->createEdge(v0, v1);
433 pSolidzMesh->createEdge(v1, v2);
434 }
435
436 else if (context.isRank(1)) { // SecondaryRank1
437 Eigen::VectorXd position(dimensions);
438 position << 1.0, 3.5, 1.0;
439 mesh::Vertex &v3 = pSolidzMesh->createVertex(position);
440 position << 0.0, 4.5, 0.0;
441 mesh::Vertex &v4 = pSolidzMesh->createVertex(position);
442 pSolidzMesh->createEdge(v3, v4);
443 } else if (context.isRank(2)) { // Secondary rank 2
444 Eigen::VectorXd position(dimensions);
445 position << 2.5, 5.5, 2.5;
446 mesh::Vertex &v5 = pSolidzMesh->createVertex(position);
447 position << 4.5, 7.0, 4.5;
448 mesh::Vertex &v6 = pSolidzMesh->createVertex(position);
449 pSolidzMesh->createEdge(v5, v6);
450 }
451 pSolidzMesh->computeBoundingBox();
452
453 ProvidedPartition part(pSolidzMesh);
454 part.addM2N(m2n);
455 part.compareBoundingBoxes();
456
457 } else { // NASTIN
458 BOOST_TEST(context.isNamed("NASTIN"));
459
460 mesh::Mesh::BoundingBoxMap receivedGlobalBB;
461 mesh::BoundingBox localBB{dimensions};
462
464 compareBB.emplace(0, mesh::BoundingBox({-1, 5, 0, 3, -1, 5}));
465 compareBB.emplace(1, mesh::BoundingBox({0, 1, 3.5, 4.5, 0, 1}));
466 compareBB.emplace(2, mesh::BoundingBox({2.5, 4.5, 5.5, 7.0, 2.5, 4.5}));
467
468 // we receive other participants communicator size
469 int remoteParComSize = 3;
470 m2n->getPrimaryRankCommunication()->receive(remoteParComSize, 0);
471
472 for (int i = 0; i < remoteParComSize; i++) {
473 receivedGlobalBB.emplace(i, localBB);
474 }
475
476 // we receive global bounding box from other participant!
477 com::receiveBoundingBoxMap(*m2n->getPrimaryRankCommunication(), 0, receivedGlobalBB);
478
479 // check whether we have received the correct com size
480 BOOST_TEST(remoteParComSize == 3);
481
482 // check the validity of received global bounding box (globalBB)
483 BOOST_TEST(receivedGlobalBB.at(0) == compareBB.at(0));
484 BOOST_TEST(receivedGlobalBB.at(1) == compareBB.at(1));
485 BOOST_TEST(receivedGlobalBB.at(2) == compareBB.at(2));
486
487 // send empty dummy list of connected ranks as feedback
488 std::vector<int> connectedRanksList;
489 m2n->getPrimaryRankCommunication()->sendRange(connectedRanksList, 0);
490 }
491}
492
493PRECICE_TEST_SETUP("Solid"_on(2_ranks).setupIntraComm(), "Fluid"_on(2_ranks).setupIntraComm(), Require::Events)
494BOOST_AUTO_TEST_CASE(TestCommunicateLocalMeshPartitions)
495{
496 PRECICE_TEST();
497 // mesh creation
498 int dimensions = 2;
499 double safetyFactor = 0.1;
500 mesh::PtrMesh mesh(new mesh::Mesh("mesh", dimensions, testing::nextMeshID()));
501
503 options.useOnlyPrimaryCom = false;
504 options.useTwoLevelInit = true;
506 auto m2n = context.connectPrimaryRanks("Fluid", "Solid", options);
507
508 if (context.isNamed("Solid")) {
509 if (context.isPrimary()) {
510 Eigen::VectorXd position(dimensions);
511 position << 0.5, 0.0;
512 mesh::Vertex &v1 = mesh->createVertex(position);
513 position << 1.5, 0.0;
514 mesh::Vertex &v2 = mesh->createVertex(position);
515 position << 2.0, 1.0;
516 mesh::Vertex &v3 = mesh->createVertex(position);
517 position << 0.5, 1.0;
518 mesh::Vertex &v4 = mesh->createVertex(position);
519 mesh->createEdge(v1, v2);
520 mesh->createEdge(v2, v3);
521 mesh->createEdge(v3, v4);
522 mesh->createEdge(v4, v1);
523
524 mesh->setConnectedRanks({0});
525
526 } else {
527 Eigen::VectorXd position(dimensions);
528 position << 2.5, 0.0;
529 mesh::Vertex &v1 = mesh->createVertex(position);
530 position << 3.5, 0.0;
531 mesh::Vertex &v2 = mesh->createVertex(position);
532 position << 3.5, 1.0;
533 mesh::Vertex &v3 = mesh->createVertex(position);
534 position << 2.0, 1.0;
535 mesh::Vertex &v4 = mesh->createVertex(position);
536 mesh->createEdge(v1, v2);
537 mesh->createEdge(v2, v3);
538 mesh->createEdge(v3, v4);
539 mesh->createEdge(v4, v1);
540
541 mesh->setConnectedRanks({1});
542 }
543 } else {
544 BOOST_TEST(context.isNamed("Fluid"));
545 if (context.isPrimary()) {
546 mesh->setConnectedRanks({0});
547 } else {
548 mesh->setConnectedRanks({1});
549 }
550 }
551 mesh->computeBoundingBox();
552
553 if (context.isNamed("Solid")) {
554 m2n->createDistributedCommunication(mesh);
556 m2n->acceptSecondaryRanksPreConnection("SolidSecondaryRanks", "FluidSecondaryRanks");
557 part.addM2N(m2n);
558 part.communicate();
559 } else {
560 m2n->createDistributedCommunication(mesh);
562 m2n->requestSecondaryRanksPreConnection("SolidSecondaryRanks", "FluidSecondaryRanks");
563 part.addM2N(m2n);
564
565 part.communicate();
566
567 BOOST_TEST(mesh->nVertices() == 4);
568
569 if (context.isPrimary()) {
570 BOOST_TEST(mesh->vertex(0).coord(0) == 0.5);
571 BOOST_TEST(mesh->vertex(0).coord(1) == 0.0);
572 BOOST_TEST(mesh->vertex(1).coord(0) == 1.5);
573 BOOST_TEST(mesh->vertex(1).coord(1) == 0.0);
574 BOOST_TEST(mesh->vertex(2).coord(0) == 2.0);
575 BOOST_TEST(mesh->vertex(2).coord(1) == 1.0);
576 BOOST_TEST(mesh->vertex(3).coord(0) == 0.5);
577 BOOST_TEST(mesh->vertex(3).coord(1) == 1.0);
578 } else {
579 BOOST_TEST(mesh->vertex(0).coord(0) == 2.5);
580 BOOST_TEST(mesh->vertex(0).coord(1) == 0.0);
581 BOOST_TEST(mesh->vertex(1).coord(0) == 3.5);
582 BOOST_TEST(mesh->vertex(1).coord(1) == 0.0);
583 BOOST_TEST(mesh->vertex(2).coord(0) == 3.5);
584 BOOST_TEST(mesh->vertex(2).coord(1) == 1.0);
585 BOOST_TEST(mesh->vertex(3).coord(0) == 2.0);
586 BOOST_TEST(mesh->vertex(3).coord(1) == 1.0);
587 }
588 }
589}
590
591PRECICE_TEST_SETUP("Solid"_on(2_ranks).setupIntraComm(), "Fluid"_on(2_ranks).setupIntraComm(), Require::Events)
592BOOST_AUTO_TEST_CASE(TestTwoLevelRepartitioning2D)
593{
594 PRECICE_TEST();
595 // mesh creation
596 int dimensions = 2;
597 double safetyFactor = 0;
598 mesh::PtrMesh mesh(new mesh::Mesh("mesh", dimensions, testing::nextMeshID()));
599 mesh::PtrMesh receivedMesh(new mesh::Mesh("mesh", dimensions, testing::nextMeshID()));
600
602 options.useOnlyPrimaryCom = false;
603 options.useTwoLevelInit = true;
605 auto m2n = context.connectPrimaryRanks("Fluid", "Solid", options);
606
607 if (context.isNamed("Solid")) {
608 if (context.isPrimary()) {
609 Eigen::VectorXd position(dimensions);
610 position << -2.0, 0.0;
611 mesh->createVertex(position);
612 position << -1.0, 0.0;
613 mesh->createVertex(position);
614 position << 0.0, 1.0;
615 mesh->createVertex(position);
616 position << -1.0, 1.0;
617 mesh->createVertex(position);
618 position << -2.0, 1.0;
619 mesh->createVertex(position);
620 position << -2.0, 2.0;
621 mesh->createVertex(position);
622 position << -1.0, 2.0;
623 mesh->createVertex(position);
624 position << 0.0, 2.0;
625 mesh->createVertex(position);
626 } else {
627 Eigen::VectorXd position(dimensions);
628 position << -0.5, 0.0;
629 mesh->createVertex(position);
630 position << 1.0, 0.0;
631 mesh->createVertex(position);
632 position << 2.0, 0.0;
633 mesh->createVertex(position);
634 position << 2.0, 1.0;
635 mesh->createVertex(position);
636 position << 1.0, 1.0;
637 mesh->createVertex(position);
638 position << 1.0, 2.0;
639 mesh->createVertex(position);
640 position << 2.0, 2.0;
641 mesh->createVertex(position);
642 }
643 } else {
644 BOOST_TEST(context.isNamed("Fluid"));
645 if (context.isPrimary()) {
646 Eigen::VectorXd position(dimensions);
647 position << 0.0, 0.0;
648 mesh->createVertex(position);
649 position << 0.0, -1.0;
650 mesh->createVertex(position);
651 position << -1.0, 0.0;
652 mesh->createVertex(position);
653 position << -1.0, -1.0;
654 mesh->createVertex(position);
655 position << -2.0, -0.0;
656 mesh->createVertex(position);
657 position << -2.0, -1.0;
658 mesh->createVertex(position);
659 } else {
660 Eigen::VectorXd position(dimensions);
661 position << 0.0, 0.0;
662 mesh->createVertex(position);
663 position << 1.0, 0.0;
664 mesh->createVertex(position);
665 position << 0.0, -1.0;
666 mesh->createVertex(position);
667 position << 1.0, -1.0;
668 mesh->createVertex(position);
669 position << 2.0, 0.0;
670 mesh->createVertex(position);
671 position << 2.0, -1.0;
672 mesh->createVertex(position);
673 }
674 }
675 mesh->computeBoundingBox();
676
677 if (context.isNamed("Solid")) {
678 m2n->createDistributedCommunication(mesh);
680 part.addM2N(m2n);
681
682 part.compareBoundingBoxes();
683
684 if (context.isPrimary()) {
685 BOOST_TEST(mesh->getConnectedRanks().size() == 2);
686 BOOST_TEST(mesh->getConnectedRanks().at(0) == 0);
687 BOOST_TEST(mesh->getConnectedRanks().at(1) == 1);
688 } else {
689 BOOST_TEST(mesh->getConnectedRanks().size() == 2);
690 BOOST_TEST(mesh->getConnectedRanks().at(0) == 0);
691 BOOST_TEST(mesh->getConnectedRanks().at(1) == 1);
692 }
693
694 m2n->acceptSecondaryRanksPreConnection("FluidSecondaryRanks", "SolidSecondaryRanks");
695
696 part.communicate();
697 part.compute();
698
699 if (context.isPrimary()) {
700 BOOST_TEST(mesh->getCommunicationMap().at(0).at(0) == 0);
701 BOOST_TEST(mesh->getCommunicationMap().at(0).at(1) == 1);
702 } else {
703 BOOST_TEST(mesh->getCommunicationMap().at(0).at(0) == 0);
704 BOOST_TEST(mesh->getCommunicationMap().at(1).at(0) == 1);
705 BOOST_TEST(mesh->getCommunicationMap().at(1).at(1) == 2);
706 }
707 } else {
708 m2n->createDistributedCommunication(receivedMesh);
711 boundingFromMapping->setMeshes(receivedMesh, mesh);
712 boundingToMapping->setMeshes(mesh, receivedMesh);
713
714 ReceivedPartition part(receivedMesh, ReceivedPartition::ON_SECONDARY_RANKS, safetyFactor);
715
716 part.addM2N(m2n);
717
718 part.addFromMapping(boundingFromMapping);
719 part.addToMapping(boundingToMapping);
720
721 part.compareBoundingBoxes();
722
723 m2n->requestSecondaryRanksPreConnection("FluidSecondaryRanks", "SolidSecondaryRanks");
724
725 part.communicate();
726 part.compute();
727 }
728}
729
730PRECICE_TEST_SETUP("Solid"_on(2_ranks).setupIntraComm(), "Fluid"_on(2_ranks).setupIntraComm(), Require::Events)
731BOOST_AUTO_TEST_CASE(TestTwoLevelRepartitioning3D)
732{
733 PRECICE_TEST();
734
735 // mesh creation
736 int dimensions = 3;
737 double safetyFactor = 0.0;
738 mesh::PtrMesh mesh(new mesh::Mesh("mesh", dimensions, testing::nextMeshID()));
739 mesh::PtrMesh receivedMesh(new mesh::Mesh("mesh", dimensions, testing::nextMeshID()));
740
741 // create the communicator for m2n mesh and communication map exchange
743 options.useOnlyPrimaryCom = false;
744 options.useTwoLevelInit = true;
746 auto m2n = context.connectPrimaryRanks("Fluid", "Solid", options);
747
748 if (context.isNamed("Solid")) {
749 if (context.isPrimary()) {
750 Eigen::VectorXd position(dimensions);
751 position << -2.0, 0.0, 0.0;
752 mesh->createVertex(position);
753 position << -1.0, 0.0, 0.0;
754 mesh->createVertex(position);
755 position << 0.0, 1.0, 1.0;
756 mesh->createVertex(position);
757 position << -1.0, 1.0, 1.0;
758 mesh->createVertex(position);
759 position << -2.0, 1.0, 1.0;
760 mesh->createVertex(position);
761 } else {
762 Eigen::VectorXd position(dimensions);
763 position << -0.5, 0.0, 0.0;
764 mesh->createVertex(position);
765 position << 1.0, 0.0, 0.0;
766 mesh->createVertex(position);
767 position << 2.0, 0.0, 0.0;
768 mesh->createVertex(position);
769 position << 2.0, 1.0, 1.0;
770 mesh->createVertex(position);
771 position << 1.0, 1.0, 1.0;
772 mesh->createVertex(position);
773 }
774 } else {
775 if (context.isPrimary()) {
776 Eigen::VectorXd position(dimensions);
777 position << 0.0, 0.0, 0.0;
778 mesh->createVertex(position);
779 position << 0.0, -1.0, 1.0;
780 mesh->createVertex(position);
781 position << -1.0, 0.0, 0.0;
782 mesh->createVertex(position);
783 position << -1.0, -1.0, 1.0;
784 mesh->createVertex(position);
785 position << -2.0, -0.0, 0.0;
786 mesh->createVertex(position);
787 position << -2.0, -1.0, 1.0;
788 mesh->createVertex(position);
789 } else {
790 Eigen::VectorXd position(dimensions);
791 position << 0.0, 0.0, 0.0;
792 mesh->createVertex(position);
793 position << 1.0, 0.0, 0.0;
794 mesh->createVertex(position);
795 position << 0.0, -1.0, 1.0;
796 mesh->createVertex(position);
797 position << 1.0, -1.0, 1.0;
798 mesh->createVertex(position);
799 position << 2.0, 0.0, 0.0;
800 mesh->createVertex(position);
801 position << 2.0, -1.0, 0.0;
802 mesh->createVertex(position);
803 }
804 }
805 mesh->computeBoundingBox();
806
807 if (context.isNamed("Solid")) {
808 m2n->createDistributedCommunication(mesh);
810 part.addM2N(m2n);
811
812 part.compareBoundingBoxes();
813
814 if (context.isPrimary()) {
815 BOOST_TEST(mesh->getConnectedRanks().size() == 2);
816 BOOST_TEST(mesh->getConnectedRanks().at(0) == 0);
817 BOOST_TEST(mesh->getConnectedRanks().at(1) == 1);
818 } else {
819 BOOST_TEST(mesh->getConnectedRanks().size() == 2);
820 BOOST_TEST(mesh->getConnectedRanks().at(0) == 0);
821 BOOST_TEST(mesh->getConnectedRanks().at(1) == 1);
822 }
823
824 m2n->acceptSecondaryRanksPreConnection("FluidSecondaryRanks", "SolidSecondaryRanks");
825
826 part.communicate();
827 part.compute();
828
829 if (context.isPrimary()) {
830 BOOST_TEST(mesh->getCommunicationMap().at(0).at(0) == 0);
831 BOOST_TEST(mesh->getCommunicationMap().at(0).at(1) == 1);
832 } else {
833 BOOST_TEST(mesh->getCommunicationMap().at(0).at(0) == 0);
834 BOOST_TEST(mesh->getCommunicationMap().at(1).at(0) == 1);
835 BOOST_TEST(mesh->getCommunicationMap().at(1).at(1) == 2);
836 }
837 } else {
838 m2n->createDistributedCommunication(receivedMesh);
841 boundingFromMapping->setMeshes(receivedMesh, mesh);
842 boundingToMapping->setMeshes(mesh, receivedMesh);
843
844 ReceivedPartition part(receivedMesh, ReceivedPartition::ON_SECONDARY_RANKS, safetyFactor);
845 part.addM2N(m2n);
846
847 part.addFromMapping(boundingFromMapping);
848 part.addToMapping(boundingToMapping);
849
850 part.compareBoundingBoxes();
851
852 m2n->requestSecondaryRanksPreConnection("FluidSecondaryRanks", "SolidSecondaryRanks");
853
854 part.communicate();
855 part.compute();
856 }
857}
858
861
862#endif // PRECICE_NO_MPI
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
T at(T... args)
Mapping using nearest neighboring vertices.
An axis-aligned bounding box around a (partition of a) mesh.
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:15
Container and creator for meshes.
Definition Mesh.hpp:38
std::map< int, BoundingBox > BoundingBoxMap
Definition Mesh.hpp:45
Vertex of a mesh.
Definition Vertex.hpp:16
void addM2N(m2n::PtrM2N m2n)
Definition Partition.hpp:56
A partition that is provided by the participant.
void compute() override
All distribution data structures are set up.
void communicate() override
The mesh is gathered and sent to another participant (if required)
void compareBoundingBoxes() override
Intersections between bounding boxes around each rank are computed.
A partition that is computed from a mesh received from another participant.
@ ON_SECONDARY_RANKS
Filter after communication on all secondary ranks.
void communicate() override
The mesh is communicated between both primary ranks (if required)
T emplace(T... args)
void receiveBoundingBoxMap(Communication &communication, int rankSender, mesh::Mesh::BoundingBoxMap &bbm)
Definition Extra.cpp:63
void sendConnectionMap(Communication &communication, int rankReceiver, const mesh::Mesh::ConnectionMap &cm)
Definition Extra.cpp:28
contains the logic of the parallel communication between participants.
Definition BoundM2N.cpp:12
std::shared_ptr< Mapping > PtrMapping
provides Mesh, Data and primitives.
std::shared_ptr< Mesh > PtrMesh
contains the partitioning of distributed meshes.
Definition Partition.cpp:5
@ Events
Require to initialize Event.
Main namespace of the precice library.