preCICE v3.1.2
Loading...
Searching...
No Matches
GatherScatterCommunicationTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <memory>
5#include <vector>
8#include "m2n/M2N.hpp"
9#include "mesh/Mesh.hpp"
12#include "testing/Testing.hpp"
13
15
16using namespace precice;
17using namespace m2n;
18
19BOOST_AUTO_TEST_CASE(GatherScatterTest)
20{
21 PRECICE_TEST("Part1"_on(1_rank), "Part2"_on(3_ranks).setupIntraComm(), Require::Events);
22 auto m2n = context.connectPrimaryRanks("Part1", "Part2");
23
24 int dimensions = 2;
25 int numberOfVertices = 6;
26 int valueDimension = 1;
27 Eigen::VectorXd offset = Eigen::VectorXd::Zero(dimensions);
28
29 if (context.isNamed("Part1")) {
30 mesh::PtrMesh pMesh(new mesh::Mesh("Mesh", dimensions, testing::nextMeshID()));
31 m2n->createDistributedCommunication(pMesh);
32
33 pMesh->setGlobalNumberOfVertices(numberOfVertices);
34 pMesh->setVertexDistribution({{0, {0, 1, 2, 3, 4, 5}}});
35
36 m2n->acceptSecondaryRanksConnection("Part1", "Part2");
37 Eigen::VectorXd values = Eigen::VectorXd::Zero(numberOfVertices);
38 values << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0;
39 m2n->send(values, pMesh->getID(), valueDimension);
40 m2n->receive(values, pMesh->getID(), valueDimension);
41 BOOST_TEST(values(0) == 2.0);
42 BOOST_TEST(values(1) == 4.0);
43 BOOST_TEST(values(2) == 6.0);
44 BOOST_TEST(values(3) == 16.0);
45 BOOST_TEST(values(4) == 10.0);
46 BOOST_TEST(values(5) == 12.0);
47
48 } else {
49 BOOST_TEST(context.isNamed("Part2"));
50 mesh::PtrMesh pMesh(new mesh::Mesh("Mesh", dimensions, testing::nextMeshID()));
51 m2n->createDistributedCommunication(pMesh);
52 m2n->requestSecondaryRanksConnection("Part1", "Part2");
53
54 if (context.isPrimary()) {
55 pMesh->setGlobalNumberOfVertices(numberOfVertices);
56 pMesh->setVertexDistribution({{0, {0, 1, 3}}, {2, {2, 3, 4, 5}}});
57
58 Eigen::Vector3d values(0.0, 0.0, 0.0);
59 m2n->receive(values, pMesh->getID(), valueDimension);
60 BOOST_TEST(values(0) == 1.0);
61 BOOST_TEST(values(1) == 2.0);
62 BOOST_TEST(values(2) == 4.0);
63 values = values * 2;
64 m2n->send(values, pMesh->getID(), valueDimension);
65 } else if (context.isRank(1)) { // Secondary rank1
66 Eigen::VectorXd values;
67 m2n->receive({}, pMesh->getID(), valueDimension);
68 m2n->send(values, pMesh->getID(), valueDimension);
69 } else {
70 BOOST_TEST(context.isRank(2));
71 Eigen::Vector4d values(0.0, 0.0, 0.0, 0.0);
72 m2n->receive(values, pMesh->getID(), valueDimension);
73 BOOST_TEST(values(0) == 3.0);
74 BOOST_TEST(values(1) == 4.0);
75 BOOST_TEST(values(2) == 5.0);
76 BOOST_TEST(values(3) == 6.0);
77 values = values * 2;
78 m2n->send(values, pMesh->getID(), valueDimension);
79 }
80 }
81}
82
84
85#endif // PRECICE_NO_MPI
BOOST_AUTO_TEST_CASE(GatherScatterTest)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Container and creator for meshes.
Definition Mesh.hpp:39
Main namespace of the precice library.