preCICE v3.1.1
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
23BOOST_AUTO_TEST_CASE(SendAndReceiveBoundingBox)
24{
25 PRECICE_TEST("A"_on(1_rank), "B"_on(1_rank), Require::Events);
26 auto m2n = context.connectPrimaryRanks("A", "B");
27
28 for (int dim = 2; dim <= 3; dim++) {
30 for (int i = 0; i < dim; i++) {
31 bounds.push_back(i);
32 bounds.push_back(i + 1);
33 }
34 mesh::BoundingBox bb(bounds);
35 auto comm = m2n->getPrimaryRankCommunication();
36
37 if (context.isNamed("A")) {
38 com::sendBoundingBox(*comm, 0, bb);
39 } else {
40 BOOST_TEST(context.isNamed("B"));
41 mesh::BoundingBox bbCompare(dim);
42
43 com::receiveBoundingBox(*comm, 0, bbCompare);
44
45 BOOST_TEST(bb == bbCompare);
46 }
47 }
48}
49
50BOOST_AUTO_TEST_CASE(SendAndReceiveBoundingBoxMap)
51{
52 PRECICE_TEST("A"_on(1_rank), "B"_on(1_rank), Require::Events);
53 auto m2n = context.connectPrimaryRanks("A", "B");
54
55 for (int dim = 2; dim <= 3; dim++) {
57
58 for (Rank rank = 0; rank < 3; rank++) {
60 for (int i = 0; i < dim; i++) {
61 bounds.push_back(rank * i);
62 bounds.push_back(i + 1);
63 }
64 bbm.emplace(rank, mesh::BoundingBox(bounds));
65 }
66
67 auto &comm = *m2n->getPrimaryRankCommunication();
68
69 if (context.isNamed("A")) {
70 com::sendBoundingBoxMap(comm, 0, bbm);
71 } else {
72 BOOST_TEST(context.isNamed("B"));
73
74 mesh::BoundingBox bbCompare(dim);
76
77 for (int i = 0; i < 3; i++) {
78 bbmCompare.emplace(i, bbCompare);
79 }
80
81 com::receiveBoundingBoxMap(comm, 0, bbmCompare);
82
83 for (Rank rank = 0; rank < 3; rank++) {
84 BOOST_TEST(bbm.at(rank) == bbmCompare.at(rank));
85 }
86 }
87 }
88}
89
90BOOST_AUTO_TEST_CASE(BroadcastSendAndReceiveBoundingBoxMap)
91{
92 PRECICE_TEST(""_on(4_ranks).setupIntraComm(), Require::Events);
93
94 // Build BB/BBMap to communicate
95 int dimension = 3;
97 for (Rank rank = 0; rank < 3; rank++) {
99 for (int i = 0; i < dimension; i++) {
100 bounds.push_back(rank * i);
101 bounds.push_back(i + 1);
102 }
103 bbm.emplace(rank, mesh::BoundingBox(bounds));
104 }
105
107
108 if (context.isPrimary()) {
110 } else {
111
112 mesh::BoundingBox bbCompare{dimension};
114
115 for (int i = 0; i < 3; i++) {
116 bbmCompare.emplace(i, bbCompare);
117 }
118 com::broadcastReceiveBoundingBoxMap(comm, bbmCompare);
119 BOOST_TEST((int) bbmCompare.size() == 3);
120 for (Rank rank = 0; rank < 3; rank++) {
121 BOOST_TEST(bbm.at(rank) == bbmCompare.at(rank));
122 }
123 }
124}
125
126BOOST_AUTO_TEST_CASE(SendAndReceiveConnectionMap)
127{
128 PRECICE_TEST("A"_on(1_rank), "B"_on(1_rank), Require::Events);
129 auto m2n = context.connectPrimaryRanks("A", "B");
130
133
134 for (Rank rank = 0; rank < 3; rank++) {
135
136 for (int i = 0; i < 3; i++) {
137 fb.push_back(i + 1);
138 }
139
140 fbm[rank] = fb;
141 fb.clear();
142 }
143
144 auto &comm = *m2n->getPrimaryRankCommunication();
145
146 if (context.isNamed("A")) {
147 com::sendConnectionMap(comm, 0, fbm);
148 } else if (context.isNamed("B")) {
149
150 std::vector<int> fbCompare;
152
153 for (Rank rank = 0; rank < 3; rank++) {
154
155 for (int i = 0; i < 3; i++) {
156 fbCompare.push_back(-1);
157 }
158
159 fbmCompare[rank] = fbCompare;
160 fbCompare.clear();
161 }
162
163 com::receiveConnectionMap(comm, 0, fbmCompare);
164
165 for (Rank rank = 0; rank < 3; rank++) {
166
167 BOOST_TEST(fbm.at(rank) == fbmCompare.at(rank));
168 }
169 }
170}
171
172BOOST_AUTO_TEST_CASE(BroadcastSendAndReceiveConnectionMap)
173{
174 PRECICE_TEST(""_on(4_ranks).setupIntraComm(), Require::Events);
175
178
179 for (Rank rank = 0; rank < 3; rank++) {
180
181 for (int i = 0; i < 3; i++) {
182 fb.push_back(i + 1);
183 }
184
185 fbm[rank] = fb;
186 fb.clear();
187 }
188
190
191 if (context.isPrimary()) {
193 } else {
194
195 std::vector<int> fbCompare;
197
198 for (Rank rank = 0; rank < 3; rank++) {
199 for (int i = 0; i < 3; i++) {
200 fbCompare.push_back(-1);
201 }
202 fbmCompare[rank] = fbCompare;
203 fbCompare.clear();
204 }
205
206 com::broadcastReceiveConnectionMap(comm, fbmCompare);
207
208 for (Rank rank = 0; rank < 3; rank++) {
209
210 BOOST_TEST(fbm.at(rank) == fbmCompare.at(rank));
211 }
212 }
213}
214
216
217BOOST_AUTO_TEST_SUITE_END() // Communication
218
219#endif // not PRECICE_NO_MPI
BOOST_AUTO_TEST_CASE(SendAndReceiveBoundingBox)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
T at(T... args)
An axis-aligned bounding box around a (partition of a) mesh.
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
Main namespace of the precice library.
int Rank
Definition Types.hpp:37
T push_back(T... args)
T size(T... args)