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