preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
19PRECICE_TEST_SETUP("Part1"_on(1_rank), "Part2"_on(3_ranks).setupIntraComm(), Require::Events)
20BOOST_AUTO_TEST_CASE(GatherScatterTest)
21{
23 auto m2n = context.connectPrimaryRanks("Part1", "Part2");
24
25 int dimensions = 2;
26 int numberOfVertices = 6;
27 int valueDimension = 1;
28 Eigen::VectorXd offset = Eigen::VectorXd::Zero(dimensions);
29
30 if (context.isNamed("Part1")) {
31 mesh::PtrMesh pMesh(new mesh::Mesh("Mesh", dimensions, testing::nextMeshID()));
32 m2n->createDistributedCommunication(pMesh);
33
34 pMesh->setGlobalNumberOfVertices(numberOfVertices);
35 pMesh->setVertexDistribution({{0, {0, 1, 2, 3, 4, 5}}});
36
37 m2n->acceptSecondaryRanksConnection("Part1", "Part2");
38 Eigen::VectorXd values = Eigen::VectorXd::Zero(numberOfVertices);
39 values << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0;
40 m2n->send(values, pMesh->getID(), valueDimension);
41 m2n->receive(values, pMesh->getID(), valueDimension);
42 BOOST_TEST(values(0) == 2.0);
43 BOOST_TEST(values(1) == 4.0);
44 BOOST_TEST(values(2) == 6.0);
45 BOOST_TEST(values(3) == 16.0);
46 BOOST_TEST(values(4) == 10.0);
47 BOOST_TEST(values(5) == 12.0);
48
49 } else {
50 BOOST_TEST(context.isNamed("Part2"));
51 mesh::PtrMesh pMesh(new mesh::Mesh("Mesh", dimensions, testing::nextMeshID()));
52 m2n->createDistributedCommunication(pMesh);
53 m2n->requestSecondaryRanksConnection("Part1", "Part2");
54
55 if (context.isPrimary()) {
56 pMesh->setGlobalNumberOfVertices(numberOfVertices);
57 pMesh->setVertexDistribution({{0, {0, 1, 3}}, {2, {2, 3, 4, 5}}});
58
59 Eigen::Vector3d values(0.0, 0.0, 0.0);
60 m2n->receive(values, pMesh->getID(), valueDimension);
61 BOOST_TEST(values(0) == 1.0);
62 BOOST_TEST(values(1) == 2.0);
63 BOOST_TEST(values(2) == 4.0);
64 values = values * 2;
65 m2n->send(values, pMesh->getID(), valueDimension);
66 } else if (context.isRank(1)) { // Secondary rank1
67 Eigen::VectorXd values;
68 m2n->receive({}, pMesh->getID(), valueDimension);
69 m2n->send(values, pMesh->getID(), valueDimension);
70 } else {
71 BOOST_TEST(context.isRank(2));
72 Eigen::Vector4d values(0.0, 0.0, 0.0, 0.0);
73 m2n->receive(values, pMesh->getID(), valueDimension);
74 BOOST_TEST(values(0) == 3.0);
75 BOOST_TEST(values(1) == 4.0);
76 BOOST_TEST(values(2) == 5.0);
77 BOOST_TEST(values(3) == 6.0);
78 values = values * 2;
79 m2n->send(values, pMesh->getID(), valueDimension);
80 }
81 }
82}
83
85
86#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
Container and creator for meshes.
Definition Mesh.hpp:38
Main namespace of the precice library.