preCICE v3.2.0
Loading...
Searching...
No Matches
CommunicateBoundingBoxTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2#include <map>
3#include <memory>
4#include <vector>
5
6#include "com/Extra.hpp"
8#include "m2n/M2N.hpp"
10#include "mesh/Mesh.hpp"
13#include "testing/Testing.hpp"
14#include "utils/IntraComm.hpp"
15
16using namespace precice;
17using namespace precice::com;
18
19BOOST_AUTO_TEST_SUITE(CommunicationTests)
20
21BOOST_AUTO_TEST_SUITE(CommunicateBoundingBoxTests)
22
23PRECICE_TEST_SETUP("A"_on(1_rank), "B"_on(1_rank), Require::Events)
24BOOST_AUTO_TEST_CASE(SendAndReceiveBoundingBox)
25{
27 auto m2n = context.connectPrimaryRanks("A", "B");
28
29 for (int dim = 2; dim <= 3; dim++) {
31 for (int i = 0; i < dim; i++) {
32 bounds.push_back(i);
33 bounds.push_back(i + 1);
34 }
35 mesh::BoundingBox bb(bounds);
36 auto comm = m2n->getPrimaryRankCommunication();
37
38 if (context.isNamed("A")) {
39 com::sendBoundingBox(*comm, 0, bb);
40 } else {
41 BOOST_TEST(context.isNamed("B"));
42 mesh::BoundingBox bbCompare(dim);
43
44 com::receiveBoundingBox(*comm, 0, bbCompare);
45
46 BOOST_TEST(bb == bbCompare);
47 }
48 }
49}
50
51PRECICE_TEST_SETUP("A"_on(1_rank), "B"_on(1_rank), Require::Events)
52BOOST_AUTO_TEST_CASE(SendAndReceiveBoundingBoxMap)
53{
55 auto m2n = context.connectPrimaryRanks("A", "B");
56
57 for (int dim = 2; dim <= 3; dim++) {
59
60 for (Rank rank = 0; rank < 3; rank++) {
62 for (int i = 0; i < dim; i++) {
63 bounds.push_back(rank * i);
64 bounds.push_back(i + 1);
65 }
66 bbm.emplace(rank, mesh::BoundingBox(bounds));
67 }
68
69 auto &comm = *m2n->getPrimaryRankCommunication();
70
71 if (context.isNamed("A")) {
72 com::sendBoundingBoxMap(comm, 0, bbm);
73 } else {
74 BOOST_TEST(context.isNamed("B"));
75
76 mesh::BoundingBox bbCompare(dim);
78
79 for (int i = 0; i < 3; i++) {
80 bbmCompare.emplace(i, bbCompare);
81 }
82
83 com::receiveBoundingBoxMap(comm, 0, bbmCompare);
84
85 for (Rank rank = 0; rank < 3; rank++) {
86 BOOST_TEST(bbm.at(rank) == bbmCompare.at(rank));
87 }
88 }
89 }
90}
91
92PRECICE_TEST_SETUP(""_on(4_ranks).setupIntraComm(), Require::Events)
93BOOST_AUTO_TEST_CASE(BroadcastSendAndReceiveBoundingBoxMap)
94{
96
97 // Build BB/BBMap to communicate
98 int dimension = 3;
100 for (Rank rank = 0; rank < 3; rank++) {
101 std::vector<double> bounds;
102 for (int i = 0; i < dimension; i++) {
103 bounds.push_back(rank * i);
104 bounds.push_back(i + 1);
105 }
106 bbm.emplace(rank, mesh::BoundingBox(bounds));
107 }
108
110
111 if (context.isPrimary()) {
113 } else {
114
115 mesh::BoundingBox bbCompare{dimension};
117
118 for (int i = 0; i < 3; i++) {
119 bbmCompare.emplace(i, bbCompare);
120 }
121 com::broadcastReceiveBoundingBoxMap(comm, bbmCompare);
122 BOOST_TEST((int) bbmCompare.size() == 3);
123 for (Rank rank = 0; rank < 3; rank++) {
124 BOOST_TEST(bbm.at(rank) == bbmCompare.at(rank));
125 }
126 }
127}
128
129PRECICE_TEST_SETUP("A"_on(1_rank), "B"_on(1_rank), Require::Events)
130BOOST_AUTO_TEST_CASE(SendAndReceiveConnectionMap)
131{
132 PRECICE_TEST();
133 auto m2n = context.connectPrimaryRanks("A", "B");
134
137
138 for (Rank rank = 0; rank < 3; rank++) {
139
140 for (int i = 0; i < 3; i++) {
141 fb.push_back(i + 1);
142 }
143
144 fbm[rank] = fb;
145 fb.clear();
146 }
147
148 auto &comm = *m2n->getPrimaryRankCommunication();
149
150 if (context.isNamed("A")) {
151 com::sendConnectionMap(comm, 0, fbm);
152 } else if (context.isNamed("B")) {
153
154 std::vector<int> fbCompare;
156
157 for (Rank rank = 0; rank < 3; rank++) {
158
159 for (int i = 0; i < 3; i++) {
160 fbCompare.push_back(-1);
161 }
162
163 fbmCompare[rank] = fbCompare;
164 fbCompare.clear();
165 }
166
167 com::receiveConnectionMap(comm, 0, fbmCompare);
168
169 for (Rank rank = 0; rank < 3; rank++) {
170
171 BOOST_TEST(fbm.at(rank) == fbmCompare.at(rank));
172 }
173 }
174}
175
176PRECICE_TEST_SETUP(""_on(4_ranks).setupIntraComm(), Require::Events)
177BOOST_AUTO_TEST_CASE(BroadcastSendAndReceiveConnectionMap)
178{
179 PRECICE_TEST();
180
183
184 for (Rank rank = 0; rank < 3; rank++) {
185
186 for (int i = 0; i < 3; i++) {
187 fb.push_back(i + 1);
188 }
189
190 fbm[rank] = fb;
191 fb.clear();
192 }
193
195
196 if (context.isPrimary()) {
198 } else {
199
200 std::vector<int> fbCompare;
202
203 for (Rank rank = 0; rank < 3; rank++) {
204 for (int i = 0; i < 3; i++) {
205 fbCompare.push_back(-1);
206 }
207 fbmCompare[rank] = fbCompare;
208 fbCompare.clear();
209 }
210
211 com::broadcastReceiveConnectionMap(comm, fbmCompare);
212
213 for (Rank rank = 0; rank < 3; rank++) {
214
215 BOOST_TEST(fbm.at(rank) == fbmCompare.at(rank));
216 }
217 }
218}
219
221
222BOOST_AUTO_TEST_SUITE_END() // Communication
223
224#endif // not 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)
An axis-aligned bounding box around a (partition of a) mesh.
std::map< int, BoundingBox > BoundingBoxMap
Definition Mesh.hpp:45
static com::PtrCommunication & getCommunication()
Intra-participant communication.
Definition IntraComm.hpp:31
T clear(T... args)
T emplace(T... args)
contains the data communication abstraction layer.
void receiveBoundingBoxMap(Communication &communication, int rankSender, mesh::Mesh::BoundingBoxMap &bbm)
Definition Extra.cpp:63
void broadcastReceiveBoundingBoxMap(Communication &communication, mesh::Mesh::BoundingBoxMap &bbm)
Definition Extra.cpp:73
void sendBoundingBox(Communication &communication, int rankReceiver, const mesh::BoundingBox &bb)
Definition Extra.cpp:48
void sendConnectionMap(Communication &communication, int rankReceiver, const mesh::Mesh::ConnectionMap &cm)
Definition Extra.cpp:28
void receiveConnectionMap(Communication &communication, int rankSender, mesh::Mesh::ConnectionMap &cm)
Definition Extra.cpp:33
void broadcastSendConnectionMap(Communication &communication, const mesh::Mesh::ConnectionMap &cm)
Definition Extra.cpp:38
void broadcastSendBoundingBoxMap(Communication &communication, const mesh::Mesh::BoundingBoxMap &bbm)
Definition Extra.cpp:68
void sendBoundingBoxMap(Communication &communication, int rankReceiver, const mesh::Mesh::BoundingBoxMap &bbm)
Definition Extra.cpp:58
void broadcastReceiveConnectionMap(Communication &communication, mesh::Mesh::ConnectionMap &cm)
Definition Extra.cpp:43
void receiveBoundingBox(Communication &communication, int rankSender, mesh::BoundingBox &bb)
Definition Extra.cpp:53
contains the logic of the parallel communication between participants.
Definition BoundM2N.cpp:12
@ Events
Require to initialize Event.
Main namespace of the precice library.
int Rank
Definition Types.hpp:37
T push_back(T... args)
T size(T... args)