OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
nn_processor_unit_test.hpp
1/*
2 * nn_processor_unit_test.hpp
3 *
4 * Created on: Dec 16, 2015
5 * Author: i-bird
6 */
7
8#ifndef SRC_DECOMPOSITION_NN_PROCESSOR_UNIT_TEST_HPP_
9#define SRC_DECOMPOSITION_NN_PROCESSOR_UNIT_TEST_HPP_
10
11#include "VCluster/VCluster.hpp"
12
13void create_decomposition2x2(openfpm::vector<openfpm::vector<long unsigned int>> & box_nn_processor, openfpm::vector<SpaceBox<2,float>> & sub_domains)
14{
15 Vcluster<> & v_cl = create_vcluster();
16
17 box_nn_processor.add();
18
19 if (v_cl.getProcessUnitID() == 0)
20 {
21 box_nn_processor.get(0).add(1);
22 box_nn_processor.get(0).add(2);
23 box_nn_processor.get(0).add(3);
24
25 sub_domains.add(Box<2,float>({0.0,0.0},{0.5,0.5}));
26 }
27 else if (v_cl.getProcessUnitID() == 1)
28 {
29 box_nn_processor.get(0).add(0);
30 box_nn_processor.get(0).add(2);
31 box_nn_processor.get(0).add(3);
32
33 sub_domains.add(Box<2,float>({0.5,0.0},{1.0,0.5}));
34 }
35 else if (v_cl.getProcessUnitID() == 2)
36 {
37 box_nn_processor.get(0).add(1);
38 box_nn_processor.get(0).add(0);
39 box_nn_processor.get(0).add(3);
40
41 sub_domains.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
42 }
43 else if (v_cl.getProcessUnitID() == 3)
44 {
45 box_nn_processor.get(0).add(1);
46 box_nn_processor.get(0).add(2);
47 box_nn_processor.get(0).add(0);
48
49 sub_domains.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
50 }
51}
52
53BOOST_AUTO_TEST_SUITE( nn_processor_test )
54
55BOOST_AUTO_TEST_CASE( nn_processor_np_test)
56{
57 Vcluster<> & v_cl = create_vcluster();
58
81 if (v_cl.getProcessingUnits() != 4)
82 return;
83
86
87 create_decomposition2x2(box_nn_processor,sub_domains);
88
90 nnp.create(box_nn_processor, sub_domains);
91
92 BOOST_REQUIRE_EQUAL(nnp.getNNProcessors(),3ul);
93
94 if (v_cl.getProcessUnitID() == 0)
95 {
96 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(1),1ul);
97 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(2),1ul);
98 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(3),1ul);
99
100 const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(1);
101 const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(2);
102 const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(3);
103
104 SpaceBox<2,float> b1_a = nsubs1.get(0);
105 SpaceBox<2,float> b2_a = nsubs2.get(0);
106 SpaceBox<2,float> b3_a = nsubs3.get(0);
107
108
109 SpaceBox<2,float> b1_b = Box<2,float>({0.5,0.0},{1.0,0.5});
110 SpaceBox<2,float> b2_b = Box<2,float>({0.0,0.5},{0.5,1.0});
111 SpaceBox<2,float> b3_b = Box<2,float>({0.5,0.5},{1.0,1.0});
112
113 bool ret1 = b1_a == b1_b;
114 bool ret2 = b2_a == b2_b;
115 bool ret3 = b3_a == b3_b;
116
117 BOOST_REQUIRE_EQUAL(ret1,true);
118 BOOST_REQUIRE_EQUAL(ret2,true);
119 BOOST_REQUIRE_EQUAL(ret3,true);
120 }
121 else if (v_cl.getProcessUnitID() == 1)
122 {
123 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(0),1ul);
124 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(2),1ul);
125 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(3),1ul);
126
127 const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(0);
128 const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(2);
129 const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(3);
130
131 SpaceBox<2,float> b1_a = nsubs1.get(0);
132 SpaceBox<2,float> b2_a = nsubs2.get(0);
133 SpaceBox<2,float> b3_a = nsubs3.get(0);
134
135
136 SpaceBox<2,float> b1_b = Box<2,float>({0.0,0.0},{0.5,0.5});
137 SpaceBox<2,float> b2_b = Box<2,float>({0.0,0.5},{0.5,1.0});
138 SpaceBox<2,float> b3_b = Box<2,float>({0.5,0.5},{1.0,1.0});
139
140 bool ret1 = b1_a == b1_b;
141 bool ret2 = b2_a == b2_b;
142 bool ret3 = b3_a == b3_b;
143
144 BOOST_REQUIRE_EQUAL(ret1,true);
145 BOOST_REQUIRE_EQUAL(ret2,true);
146 BOOST_REQUIRE_EQUAL(ret3,true);
147 }
148 else if (v_cl.getProcessUnitID() == 2)
149 {
150 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(1),1ul);
151 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(0),1ul);
152 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(3),1ul);
153
154 const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(1);
155 const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(0);
156 const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(3);
157
158 SpaceBox<2,float> b1_a = nsubs1.get(0);
159 SpaceBox<2,float> b2_a = nsubs2.get(0);
160 SpaceBox<2,float> b3_a = nsubs3.get(0);
161
162 SpaceBox<2,float> b1_b = Box<2,float>({0.5,0.0},{1.0,0.5});
163 SpaceBox<2,float> b2_b = Box<2,float>({0.0,0.0},{0.5,0.5});
164 SpaceBox<2,float> b3_b = Box<2,float>({0.5,0.5},{1.0,1.0});
165
166 bool ret1 = b1_a == b1_b;
167 bool ret2 = b2_a == b2_b;
168 bool ret3 = b3_a == b3_b;
169
170 BOOST_REQUIRE_EQUAL(ret1,true);
171 BOOST_REQUIRE_EQUAL(ret2,true);
172 BOOST_REQUIRE_EQUAL(ret3,true);
173 }
174 else if (v_cl.getProcessUnitID() == 3)
175 {
176 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(0),1ul);
177 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(1),1ul);
178 BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(2),1ul);
179
180 const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(0);
181 const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(1);
182 const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(2);
183
184 SpaceBox<2,float> b1_a = nsubs1.get(0);
185 SpaceBox<2,float> b2_a = nsubs2.get(0);
186 SpaceBox<2,float> b3_a = nsubs3.get(0);
187
188 SpaceBox<2,float> b1_b = Box<2,float>({0.0,0.0},{0.5,0.5});
189 SpaceBox<2,float> b2_b = Box<2,float>({0.5,0.0},{1.0,0.5});
190 SpaceBox<2,float> b3_b = Box<2,float>({0.0,0.5},{0.5,1.0});
191
192 bool ret1 = b1_a == b1_b;
193 bool ret2 = b2_a == b2_b;
194 bool ret3 = b3_a == b3_b;
195
196 BOOST_REQUIRE_EQUAL(ret1,true);
197 BOOST_REQUIRE_EQUAL(ret2,true);
198 BOOST_REQUIRE_EQUAL(ret3,true);
199 }
200}
201
202BOOST_AUTO_TEST_CASE( nn_processor_box_periodic_test)
203{
204 // Vcluster
205 Vcluster<> & v_cl = create_vcluster();
206
229 if (v_cl.getProcessingUnits() != 4)
230 return;
231
232 Box<2,float> domain({0.0,0.0},{1.0,1.0});
233 const size_t bc[2] = {PERIODIC,PERIODIC};
234
235 Ghost<2,float> ghost(0.01);
236
239
240 create_decomposition2x2(box_nn_processor,sub_domains);
241
243
245 nnp.create(box_nn_processor, sub_domains);
246
247 // check that nn_processor contain the correct boxes
248
249 nnp.applyBC(domain,ghost,bc);
250
251 if (v_cl.getProcessUnitID() == 0)
252 {
253 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4ul);
254 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4ul);
255 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4ul);
256
258
259 bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
260 bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
261 bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
262 bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
263
264 bool ret = nnp.getNearSubdomains(1) == bv;
265 BOOST_REQUIRE_EQUAL(ret,true);
266
267 bv.clear();
268
269 bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
270 bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
271 bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
272 bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));
273
274 ret = nnp.getNearSubdomains(2) == bv;
275 BOOST_REQUIRE_EQUAL(ret,true);
276
277 bv.clear();
278
279 bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
280 bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
281 bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
282 bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));
283
284 ret = nnp.getNearSubdomains(3) == bv;
285 BOOST_REQUIRE_EQUAL(ret,true);
286 }
287 else if (v_cl.getProcessUnitID() == 1)
288 {
289 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4ul);
290 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4ul);
291 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4ul);
292
294
295 bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
296 bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
297 bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
298 bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
299
300 bool ret = nnp.getNearSubdomains(0) == bv;
301 BOOST_REQUIRE_EQUAL(ret,true);
302
303 bv.clear();
304
305 bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
306 bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
307 bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
308 bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));
309
310 ret = nnp.getNearSubdomains(2) == bv;
311 BOOST_REQUIRE_EQUAL(ret,true);
312
313 bv.clear();
314
315 bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
316 bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
317 bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
318 bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));
319
320 ret = nnp.getNearSubdomains(3) == bv;
321 BOOST_REQUIRE_EQUAL(ret,true);
322 }
323 else if (v_cl.getProcessUnitID() == 2)
324 {
325 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4ul);
326 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4ul);
327 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4ul);
328
330
331 bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
332 bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
333 bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
334 bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
335
336 bool ret = nnp.getNearSubdomains(0) == bv;
337 BOOST_REQUIRE_EQUAL(ret,true);
338
339 bv.clear();
340
341 bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
342 bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
343 bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
344 bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
345
346 ret = nnp.getNearSubdomains(1) == bv;
347 BOOST_REQUIRE_EQUAL(ret,true);
348
349 bv.clear();
350
351 bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
352 bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
353 bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
354 bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));
355
356 ret = nnp.getNearSubdomains(3) == bv;
357 BOOST_REQUIRE_EQUAL(ret,true);
358 }
359 else if (v_cl.getProcessUnitID() == 3)
360 {
361 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4ul);
362 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4ul);
363 BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4ul);
364
366
367 bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
368 bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
369 bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
370 bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
371
372 bool ret = nnp.getNearSubdomains(0) == bv;
373 BOOST_REQUIRE_EQUAL(ret,true);
374
375 bv.clear();
376
377 bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
378 bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
379 bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
380 bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
381
382 ret = nnp.getNearSubdomains(1) == bv;
383 BOOST_REQUIRE_EQUAL(ret,true);
384
385 bv.clear();
386
387 bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
388 bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
389 bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
390 bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));
391
392 ret = nnp.getNearSubdomains(2) == bv;
393 BOOST_REQUIRE_EQUAL(ret,true);
394 }
395}
396
397BOOST_AUTO_TEST_SUITE_END()
398
399#endif /* SRC_DECOMPOSITION_NN_PROCESSOR_UNIT_TEST_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
This class represent an N-dimensional box.
Definition SpaceBox.hpp:27
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
This class store the adjacent processors and the adjacent sub_domains.
Implementation of 1-D std::vector like structure.