OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_amr_unit_tests.cpp
1/*
2 * grid_dist_amr_dist_unit_tests.cpp
3 *
4 * Created on: Sep 21, 2017
5 * Author: i-bird
6 */
7
8
9#define BOOST_TEST_DYN_LINK
10
11#include <boost/test/unit_test.hpp>
12#include "grid_dist_amr.hpp"
13
14BOOST_AUTO_TEST_SUITE( grid_dist_amr_test )
15
16
23template<typename grid_amr>
24void Test3D_amr_create_levels(grid_amr & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
25{
26 size_t g_sz[3] = {coars_g,coars_g,coars_g};
27
28 size_t tot_c = (coars_g - 1)*(coars_g - 1)*(coars_g - 1);
29 size_t correct_result = 0;
30 size_t correct_result_cell = 0;
31 size_t fact = 1;
32
33 for (size_t i = 0 ; i < n_lvl ; i++)
34 {
35 correct_result += coars_g*coars_g*coars_g;
36 correct_result_cell += tot_c*fact;
37 coars_g = 2*(coars_g - 1) + 1;
38 fact *= 8;
39 }
40
41 amr_g.initLevels(n_lvl,g_sz);
42
43
44 for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
45 {
46 // Fill the AMR with something
47
48 size_t count = 0;
49
50 auto it = amr_g.getGridIterator(i);
51
52 while (it.isNext())
53 {
54 auto key = it.get_dist();
55 auto akey = amr_g.getAMRKey(i,key);
56
57 amr_g.template insert<0>(akey) = 3.0;
58
59 amr_g.template insert<1>(akey)[0] = 3.0;
60 amr_g.template insert<1>(akey)[1] = 3.0;
61 amr_g.template insert<1>(akey)[2] = 3.0;
62
63 amr_g.template insert<2>(akey)[0] = 3;
64 amr_g.template insert<2>(akey)[1] = 3;
65 amr_g.template insert<2>(akey)[2] = 3;
66
67 count++;
68
69 ++it;
70 }
71 }
72
73 // Iterate across all the levels initialized
74 auto it = amr_g.getDomainIterator();
75
76 size_t count = 0;
77
78 while (it.isNext())
79 {
80 count++;
81
82 ++it;
83 }
84
85 Vcluster<> & v_cl = create_vcluster();
86
87 v_cl.sum(count);
88 v_cl.execute();
89
90 BOOST_REQUIRE_EQUAL(count,correct_result);
91
92 auto itc = amr_g.getDomainIteratorCells();
93
94 size_t count_c = 0;
95
96 while (itc.isNext())
97 {
98 count_c++;
99
100 ++itc;
101 }
102
103 v_cl.sum(count_c);
104 v_cl.execute();
105
106 auto it_level = amr_g.getDomainIteratorCells(3);
107
108 while (it_level.isNext())
109 {
110 auto key = it_level.get();
111
112 amr_g.template get<0>(3,key);
113
114 ++it_level;
115 }
116
117 BOOST_REQUIRE_EQUAL(count_c,correct_result_cell);
118}
119
120
121
122template<unsigned int dim>
123inline bool gr_is_inside(const grid_key_dx<dim> & key, const size_t (& sz)[dim])
124{
125 for (size_t i = 0 ; i < dim ; i++)
126 {
127 if (key.get(i) >= (long int)sz[i] || key.get(i) < 0)
128 {
129 return false;
130 }
131 }
132
133 return true;
134}
135
136template <typename grid>
137void Test3D_amr_child_parent_get_no_periodic(grid & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
138{
139 const int x = 0;
140 const int y = 1;
141 const int z = 2;
142
143 size_t g_sz[3] = {coars_g,coars_g,coars_g};
144
145 size_t tot = coars_g*coars_g*coars_g;
146 size_t correct_result = 0;
147 size_t fact = 1;
148
149 for (size_t i = 0 ; i < n_lvl ; i++)
150 {
151 correct_result += tot*fact;
152 fact *= 8;
153 }
154
155 amr_g.initLevels(n_lvl,g_sz);
156
158
159 for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
160 {
161 // Fill the AMR with something
162
163 size_t count = 0;
164
165 auto it = amr_g.getGridIterator(i);
166
167 while (it.isNext())
168 {
169 auto key = it.get_dist();
170 auto akey = amr_g.getAMRKey(i,key);
171
172 amr_g.template insert<0>(akey) = 3.0;
173
174 count++;
175
176 ++it;
177 }
178 }
179
181
182 std::string test = amr_g.getSpacing(0).toString();
183
184 // Iterate across all the levels initialized
185 auto it = amr_g.getDomainIterator();
186
187 while (it.isNext())
188 {
189 auto key = it.get();
190 auto gkey = it.getGKey();
191
192 amr_g.template insert<0>(key) = gkey.get(0);
193 amr_g.template insert<1>(key) = gkey.get(1);
194 amr_g.template insert<2>(key) = gkey.get(2);
195 amr_g.template insert<3>(key)[0] = gkey.get(0);
196 amr_g.template insert<3>(key)[1] = gkey.get(1);
197 amr_g.template insert<3>(key)[2] = gkey.get(2);
198 amr_g.template insert<3>(key)[3] = gkey.get(0);
199
200 ++it;
201 }
202
203 amr_g.template ghost_get<0,1,2,3>();
204
205 // now we check that move space work
206
207 auto it2 = amr_g.getDomainIterator();
208
209 bool match = true;
210 while (it2.isNext())
211 {
212 auto key = it2.get();
213 auto gkey = it2.getGKey();
214
215 auto key_px = key.moveSpace(x,1);
216 auto key_gpx = amr_g.getGKey(key_px);
217
218 auto key_mx = key.moveSpace(x,-1);
219 auto key_gmx = amr_g.getGKey(key_mx);
220
221 auto key_py = key.moveSpace(y,1);
222 auto key_gpy = amr_g.getGKey(key_py);
223
224 auto key_my = key.moveSpace(y,-1);
225 auto key_gmy = amr_g.getGKey(key_my);
226
227 auto key_pz = key.moveSpace(z,1);
228 auto key_gpz = amr_g.getGKey(key_pz);
229
230 auto key_mz = key.moveSpace(z,-1);
231 auto key_gmz = amr_g.getGKey(key_mz);
232
233 if (gr_is_inside(key_gpx,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
234 {
235 match &= amr_g.template get<0>(key_px) == gkey.get(0) + 1;
236 match &= amr_g.template get<1>(key_px) == gkey.get(1);
237 match &= amr_g.template get<2>(key_px) == gkey.get(2);
238
239 match &= amr_g.template get<3>(key_px)[0] == gkey.get(0) + 1;
240 match &= amr_g.template get<3>(key_px)[1] == gkey.get(1);
241 match &= amr_g.template get<3>(key_px)[2] == gkey.get(2);
242 match &= amr_g.template get<3>(key_px)[3] == gkey.get(0) + 1;
243 }
244
245 if (gr_is_inside(key_gmx,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
246 {
247 match &= amr_g.template get<0>(key_mx) == gkey.get(0) - 1;
248 match &= amr_g.template get<1>(key_mx) == gkey.get(1);
249 match &= amr_g.template get<2>(key_mx) == gkey.get(2);
250
251 match &= amr_g.template get<3>(key_mx)[0] == gkey.get(0) - 1;
252 match &= amr_g.template get<3>(key_mx)[1] == gkey.get(1);
253 match &= amr_g.template get<3>(key_mx)[2] == gkey.get(2);
254 match &= amr_g.template get<3>(key_mx)[3] == gkey.get(0) - 1;
255 }
256
257 if (gr_is_inside(key_gpy,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
258 {
259 match &= amr_g.template get<0>(key_py) == gkey.get(0);
260 match &= amr_g.template get<1>(key_py) == gkey.get(1) + 1;
261 match &= amr_g.template get<2>(key_py) == gkey.get(2);
262
263 match &= amr_g.template get<3>(key_py)[0] == gkey.get(0);
264 match &= amr_g.template get<3>(key_py)[1] == gkey.get(1) + 1;
265 match &= amr_g.template get<3>(key_py)[2] == gkey.get(2);
266 match &= amr_g.template get<3>(key_py)[3] == gkey.get(0);
267 }
268
269 if (gr_is_inside(key_gmy,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
270 {
271 match &= amr_g.template get<0>(key_my) == gkey.get(0);
272 match &= amr_g.template get<1>(key_my) == gkey.get(1) - 1;
273 match &= amr_g.template get<2>(key_my) == gkey.get(2);
274
275 match &= amr_g.template get<3>(key_my)[0] == gkey.get(0);
276 match &= amr_g.template get<3>(key_my)[1] == gkey.get(1) - 1;
277 match &= amr_g.template get<3>(key_my)[2] == gkey.get(2);
278 match &= amr_g.template get<3>(key_my)[3] == gkey.get(0);
279 }
280
281 if (gr_is_inside(key_gpz,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
282 {
283 match &= amr_g.template get<0>(key_pz) == gkey.get(0);
284 match &= amr_g.template get<1>(key_pz) == gkey.get(1);
285 match &= amr_g.template get<2>(key_pz) == gkey.get(2) + 1;
286
287 match &= amr_g.template get<3>(key_pz)[0] == gkey.get(0);
288 match &= amr_g.template get<3>(key_pz)[1] == gkey.get(1);
289 match &= amr_g.template get<3>(key_pz)[2] == gkey.get(2) + 1;
290 match &= amr_g.template get<3>(key_pz)[3] == gkey.get(0);
291 }
292
293 if (gr_is_inside(key_gmz,amr_g.getGridInfoVoid(it2.getLvl()).getSize()) == true)
294 {
295 match &= amr_g.template get<0>(key_mz) == gkey.get(0);
296 match &= amr_g.template get<1>(key_mz) == gkey.get(1);
297 match &= amr_g.template get<2>(key_mz) == gkey.get(2) - 1;
298
299 match &= amr_g.template get<3>(key_mz)[0] == gkey.get(0);
300 match &= amr_g.template get<3>(key_mz)[1] == gkey.get(1);
301 match &= amr_g.template get<3>(key_mz)[2] == gkey.get(2) - 1;
302 match &= amr_g.template get<3>(key_mz)[3] == gkey.get(0);
303 }
304
305
306 // Test to go to all the levels down
307
308 size_t lvl = it2.getLvl();
309
310 if (lvl < amr_g.getNLvl() - 1)
311 {
312 auto key_l1 = key;
313 amr_g.moveLvlDw(key_l1);
314 auto key_gl1 = amr_g.getGKey(key_l1);
315
316 for (size_t s = 0 ; s < 3 ; s++)
317 {
318 match &= key_gl1.get(s) >> 1 == gkey.get(s);
319 match &= amr_g.template get<0>(key_l1) == key_gl1.get(0);
320 match &= amr_g.template get<1>(key_l1) == key_gl1.get(1);
321 match &= amr_g.template get<2>(key_l1) == key_gl1.get(2);
322 }
323 }
324
325 if (lvl != 0)
326 {
327 auto key_l1 = key;
328 amr_g.moveLvlUp(key_l1);
329 auto key_gl1 = amr_g.getGKey(key_l1);
330
331 for (size_t s = 0 ; s < 3 ; s++)
332 {
333 match &= gkey.get(s) >> 1 == key_gl1.get(s);
334
335 match &= amr_g.template get<0>(key_l1) == key_gl1.get(0);
336 match &= amr_g.template get<1>(key_l1) == key_gl1.get(1);
337 match &= amr_g.template get<2>(key_l1) == key_gl1.get(2);
338 }
339 }
340
341 ++it2;
342 }
343
344 BOOST_REQUIRE_EQUAL(match,true);
345}
346
347
348template <typename grid>
349void Test3D_amr_child_parent_get_periodic(grid & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
350{
351 const int x = 0;
352 const int y = 1;
353 const int z = 2;
354
355 size_t g_sz[3] = {coars_g,coars_g,coars_g};
356
357 size_t tot = coars_g*coars_g*coars_g;
358 size_t correct_result = 0;
359 size_t fact = 1;
360
361 for (size_t i = 0 ; i < n_lvl ; i++)
362 {
363 correct_result += tot*fact;
364 fact *= 8;
365 }
366
367 amr_g.initLevels(n_lvl,g_sz);
368
370
371 for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
372 {
373 // Fill the AMR with something
374
375 size_t count = 0;
376
377 auto it = amr_g.getGridIterator(i);
378
379 while (it.isNext())
380 {
381 auto key = it.get_dist();
382 auto akey = amr_g.getAMRKey(i,key);
383
384 amr_g.template insert<0>(akey) = 3.0;
385
386 count++;
387
388 ++it;
389 }
390 }
391
393
394 std::string test = amr_g.getSpacing(0).toString();
395
396 // Iterate across all the levels initialized
397 auto it = amr_g.getDomainIterator();
398
399 while (it.isNext())
400 {
401 auto key = it.get();
402 auto gkey = it.getGKey();
403
404 amr_g.template insert<0>(key) = gkey.get(0);
405 amr_g.template insert<1>(key) = gkey.get(1);
406 amr_g.template insert<2>(key) = gkey.get(2);
407
408 ++it;
409 }
410
411 amr_g.template ghost_get<0,1,2>();
412
413 // now we check that move space work
414
415 auto it2 = amr_g.getDomainIterator();
416
417 bool match = true;
418 while (it2.isNext())
419 {
420 auto key = it2.get();
421 auto gkey = it2.getGKey();
422
423 auto key_px = key.moveSpace(x,1);
424 auto key_mx = key.moveSpace(x,-1);
425 auto key_py = key.moveSpace(y,1);
426 auto key_my = key.moveSpace(y,-1);
427 auto key_pz = key.moveSpace(z,1);
428 auto key_mz = key.moveSpace(z,-1);
429
430 match &= amr_g.template get<0>(key_px) == openfpm::math::positive_modulo(gkey.get(0) + 1,amr_g.getGridInfoVoid(it2.getLvl()).size(0));
431 match &= amr_g.template get<1>(key_px) == gkey.get(1);
432 match &= amr_g.template get<2>(key_px) == gkey.get(2);
433
434 match &= amr_g.template get<0>(key_mx) == openfpm::math::positive_modulo(gkey.get(0) - 1,amr_g.getGridInfoVoid(it2.getLvl()).size(0));
435 match &= amr_g.template get<1>(key_mx) == gkey.get(1);
436 match &= amr_g.template get<2>(key_mx) == gkey.get(2);
437
438 match &= amr_g.template get<0>(key_py) == gkey.get(0);
439 match &= amr_g.template get<1>(key_py) == openfpm::math::positive_modulo(gkey.get(1) + 1,amr_g.getGridInfoVoid(it2.getLvl()).size(1));
440 match &= amr_g.template get<2>(key_py) == gkey.get(2);
441
442 match &= amr_g.template get<0>(key_my) == gkey.get(0);
443 match &= amr_g.template get<1>(key_my) == openfpm::math::positive_modulo(gkey.get(1) - 1,amr_g.getGridInfoVoid(it2.getLvl()).size(1));
444 match &= amr_g.template get<2>(key_my) == gkey.get(2);
445
446 match &= amr_g.template get<0>(key_pz) == gkey.get(0);
447 match &= amr_g.template get<1>(key_pz) == gkey.get(1);
448 match &= amr_g.template get<2>(key_pz) == openfpm::math::positive_modulo(gkey.get(2) + 1,amr_g.getGridInfoVoid(it2.getLvl()).size(2));
449
450 match &= amr_g.template get<0>(key_mz) == gkey.get(0);
451 match &= amr_g.template get<1>(key_mz) == gkey.get(1);
452 match &= amr_g.template get<2>(key_mz) == openfpm::math::positive_modulo(gkey.get(2) - 1,amr_g.getGridInfoVoid(it2.getLvl()).size(2));
453
454 // Test to go to all the levels down
455
456 size_t lvl = it2.getLvl();
457
458 if (lvl < amr_g.getNLvl() - 1)
459 {
460 auto key_l1 = key;
461 amr_g.moveLvlDw(key_l1);
462 auto key_gl1 = amr_g.getGKey(key_l1);
463
464 for (size_t s = 0 ; s < 3 ; s++)
465 {
466 match &= key_gl1.get(s) >> 1 == gkey.get(s);
467 match &= amr_g.template get<0>(key_l1) == key_gl1.get(0);
468 match &= amr_g.template get<1>(key_l1) == key_gl1.get(1);
469 match &= amr_g.template get<2>(key_l1) == key_gl1.get(2);
470 }
471 }
472
473 if (lvl != 0)
474 {
475 auto key_l1 = key;
476 amr_g.moveLvlUp(key_l1);
477 auto key_gl1 = amr_g.getGKey(key_l1);
478
479 for (size_t s = 0 ; s < 3 ; s++)
480 {
481 match &= gkey.get(s) >> 1 == key_gl1.get(s);
482
483 match &= amr_g.template get<0>(key_l1) == key_gl1.get(0);
484 match &= amr_g.template get<1>(key_l1) == key_gl1.get(1);
485 match &= amr_g.template get<2>(key_l1) == key_gl1.get(2);
486 }
487 }
488
489 ++it2;
490 }
491
492 BOOST_REQUIRE_EQUAL(match,true);
493}
494
495template <typename grid>
496void Test3D_amr_ghost_it(grid & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
497{
498 size_t g_sz[3] = {coars_g,coars_g,coars_g};
499
500 size_t tot = coars_g*coars_g*coars_g;
501 size_t correct_result = 0;
502 size_t fact = 1;
503
504 for (size_t i = 0 ; i < n_lvl ; i++)
505 {
506 correct_result += tot*fact;
507 fact *= 8;
508 }
509
510 amr_g.initLevels(n_lvl,g_sz);
511
513
514 for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
515 {
516 // Fill the AMR with something
517
518 size_t count = 0;
519
520 auto it = amr_g.getGridGhostIterator(i);
521
522 while (it.isNext())
523 {
524 auto key = it.get_dist();
525 auto gkey = it.get();
526 auto akey = amr_g.getAMRKey(i,key);
527
528 amr_g.template insert<0>(akey) = gkey.get(0);
529 amr_g.template insert<1>(akey) = gkey.get(1);
530 amr_g.template insert<2>(akey) = gkey.get(2);
531
532 if (gkey.get(0) == -1 || gkey.get(0) == (long int)amr_g.getGridInfoVoid(i).size(0) ||
533 gkey.get(1) == -1 || gkey.get(1) == (long int)amr_g.getGridInfoVoid(i).size(1) ||
534 gkey.get(2) == -1 || gkey.get(2) == (long int)amr_g.getGridInfoVoid(i).size(2))
535 {count++;}
536
537 ++it;
538 }
539
540 size_t tot = (amr_g.getGridInfoVoid(i).size(0) + 2)*
541 (amr_g.getGridInfoVoid(i).size(1) + 2)*
542 (amr_g.getGridInfoVoid(i).size(2) + 2) - amr_g.getGridInfoVoid(i).size();
543
544 auto & v_cl = create_vcluster();
545
546 if (v_cl.size() == 1)
547 {
548 v_cl.sum(count);
549 v_cl.execute();
550
551 BOOST_REQUIRE_EQUAL(tot,count);
552 }
553
554 bool match = true;
555 auto it2 = amr_g.getDomainIterator(i);
556
557 while (it2.isNext())
558 {
559 auto key = it2.get();
560
561 // move -x
562
563 auto key_m1 = key.move(0,-1);
564 auto key_gm1 = it2.getGKey(key_m1);
565 match &= amr_g.template get<0>(i,key_m1) == key_gm1.get(0);
566
567 // move +x
568
569 auto key_p1 = key.move(0,1);
570 auto key_gp1 = it2.getGKey(key_p1);
571 match &= amr_g.template get<0>(i,key_p1) == key_gp1.get(0);
572
573 // move -y
574
575 key_m1 = key.move(1,-1);
576 key_gm1 = it2.getGKey(key_m1);
577 match &= amr_g.template get<1>(i,key_m1) == key_gm1.get(1);
578
579 // move +y
580
581 key_p1 = key.move(1,1);
582 key_gp1 = it2.getGKey(key_p1);
583 match &= amr_g.template get<1>(i,key_p1) == key_gp1.get(1);
584
585 // move -z
586
587 key_m1 = key.move(2,-1);
588 key_gm1 = it2.getGKey(key_m1);
589 match &= amr_g.template get<2>(i,key_m1) == key_gm1.get(2);
590
591 // move +z
592
593 key_p1 = key.move(2,1);
594 key_gp1 = it2.getGKey(key_p1);
595 match &= amr_g.template get<2>(i,key_p1) == key_gp1.get(2);
596
597 ++it2;
598 }
599
600 BOOST_REQUIRE_EQUAL(match,true);
601 }
602}
603
604
605
606template <typename grid>
607void Test3D_amr_domain_ghost_it(grid & amr_g, Box<3,float> & domain, size_t coars_g, size_t n_lvl)
608{
609 size_t g_sz[3] = {coars_g,coars_g,coars_g};
610
611 size_t tot = coars_g*coars_g*coars_g;
612 size_t correct_result = 0;
613 size_t fact = 1;
614
615 for (size_t i = 0 ; i < n_lvl ; i++)
616 {
617 correct_result += tot*fact;
618 fact *= 8;
619 }
620
621 amr_g.initLevels(n_lvl,g_sz);
622
623 size_t total_all_level = 0;
624
626
627 for (size_t i = 0 ; i < amr_g.getNLvl() ; i++)
628 {
629 // Fill the AMR with something
630
631 size_t count = 0;
632
633 auto it = amr_g.getGridGhostIterator(i);
634
635 while (it.isNext())
636 {
637 auto key = it.get_dist();
638 auto gkey = it.get();
639 auto akey = amr_g.getAMRKey(i,key);
640
641 amr_g.template insert<0>(akey) = gkey.get(0);
642 amr_g.template insert<1>(akey) = gkey.get(1);
643 amr_g.template insert<2>(akey) = gkey.get(2);
644
645 count++;
646
647 ++it;
648 }
649
650 size_t tot = (amr_g.getGridInfoVoid(i).size(0) + 2)*
651 (amr_g.getGridInfoVoid(i).size(1) + 2)*
652 (amr_g.getGridInfoVoid(i).size(2) + 2);
653
654 auto & v_cl = create_vcluster();
655
656 if (v_cl.size() == 1)
657 {
658 v_cl.sum(count);
659 v_cl.execute();
660
661 BOOST_REQUIRE_EQUAL(tot,count);
662 }
663
664 size_t amr_cnt = 0;
665 bool match = true;
666 auto it2 = amr_g.getDomainGhostIterator(i);
667
668 while (it2.isNext())
669 {
670 auto key = it2.get();
671 auto key_g = it2.getGKey(key);
672 match &= amr_g.template get<0>(i,key) == key_g.get(0);
673
674 total_all_level++;
675 amr_cnt++;
676
677 ++it2;
678 }
679
680 BOOST_REQUIRE_EQUAL(amr_cnt,count);
681 BOOST_REQUIRE_EQUAL(match,true);
682 }
683
684 // test the total iterator
685
686 size_t gtot_count = 0;
687 auto tot_it = amr_g.getDomainGhostIterator();
688
689 while (tot_it.isNext())
690 {
691 gtot_count++;
692
693 ++tot_it;
694 }
695
696 BOOST_REQUIRE_EQUAL(gtot_count,total_all_level);
697}
698
699template<typename grid_amr>
700void Test3D_ghost_put(grid_amr & g_dist_amr, long int k)
701{
702 size_t sz[3] = {(size_t)k,(size_t)k,(size_t)k};
703
704 g_dist_amr.initLevels(4,sz);
705
706 // Grid sm
707 grid_sm<3,void> info(sz);
708
709 size_t count = 0;
710
711 for (size_t i = 0 ; i < g_dist_amr.getNLvl() ; i++)
712 {
713 auto dom = g_dist_amr.getGridIterator(i);
714
715 while (dom.isNext())
716 {
717 auto key = dom.get_dist();
718
719 g_dist_amr.template insert<0>(i,key) = -6.0;
720
721 // Count the points
722 count++;
723
724 ++dom;
725 }
726 }
727
728 // Set to zero the full grid
729
730 {
731 auto dom = g_dist_amr.getDomainIterator();
732
733 while (dom.isNext())
734 {
735 auto key = dom.get();
736
737 g_dist_amr.template insert<0>(key.moveSpace(0,1)) += 1.0;
738 g_dist_amr.template insert<0>(key.moveSpace(0,-1)) += 1.0;
739 g_dist_amr.template insert<0>(key.moveSpace(1,1)) += 1.0;
740 g_dist_amr.template insert<0>(key.moveSpace(1,-1)) += 1.0;
741 g_dist_amr.template insert<0>(key.moveSpace(2,1)) += 1.0;
742 g_dist_amr.template insert<0>(key.moveSpace(2,-1)) += 1.0;
743
744 ++dom;
745 }
746 }
747
748 bool correct = true;
749
750 // Domain + Ghost iterator
751 auto dom_gi = g_dist_amr.getDomainIterator();
752
753 while (dom_gi.isNext())
754 {
755 auto key = dom_gi.get();
756
757 correct &= (g_dist_amr.template get<0>(key) == 0);
758
759 ++dom_gi;
760 }
761
762 g_dist_amr.template ghost_put<add_,0>();
763
764 if (count != 0)
765 {BOOST_REQUIRE_EQUAL(correct, false);}
766
767 // sync the ghosts
768 g_dist_amr.template ghost_get<0>();
769
770 correct = true;
771
772 // Domain + Ghost iterator
773 auto dom_gi2 = g_dist_amr.getDomainIterator();
774
775 while (dom_gi2.isNext())
776 {
777 auto key = dom_gi2.get();
778
779 correct &= (g_dist_amr.template get<0>(key) == 0);
780
781 ++dom_gi2;
782 }
783
784 BOOST_REQUIRE_EQUAL(correct, true);
785}
786
787
788
789
790BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_nop )
791{
792 // Domain
793 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
794
795 long int k = 16*16*16*create_vcluster().getProcessingUnits();
796 k = std::pow(k, 1/3.);
797
800
801 Test3D_amr_child_parent_get_no_periodic(amr_g,domain3,k,4);
802}
803
804BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_p )
805{
806 // Domain
807 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
808
809 long int k = 16*16*16*create_vcluster().getProcessingUnits();
810 k = std::pow(k, 1/3.);
811
812 periodicity<3> bc = {PERIODIC,PERIODIC,PERIODIC};
813
816
817 Test3D_amr_child_parent_get_periodic(amr_g,domain3,k,4);
818}
819
820BOOST_AUTO_TEST_CASE( grid_dist_amr_test )
821{
822 // Domain
823 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
824
825 long int k = 16*16*16*create_vcluster().getProcessingUnits();
826 k = std::pow(k, 1/3.);
827
830
831 Test3D_amr_create_levels(amr_g,domain3,k,4);
832
834
835 Test3D_amr_create_levels(amr_g2,domain3,k,4);
836}
837
838BOOST_AUTO_TEST_CASE( grid_dist_amr_ghost_it_test )
839{
840 // Domain
841 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
842
843 long int k = 16*16*16*create_vcluster().getProcessingUnits();
844 k = std::pow(k, 1/3.);
845
848
849 Test3D_amr_ghost_it(amr_g,domain3,k,4);
850
852
853 Test3D_amr_ghost_it(amr_g2,domain3,k,4);
854
855 for (size_t i = 0 ; i < amr_g2.getNLvl() ; i++)
856 {BOOST_REQUIRE(amr_g2.size_inserted(i) != 0ul);}
857
858 amr_g2.clear();
859
860 for (size_t i = 0 ; i < amr_g2.getNLvl() ; i++)
861 {BOOST_REQUIRE_EQUAL(amr_g2.size_inserted(i),0ul);}
862}
863
864BOOST_AUTO_TEST_CASE( grid_dist_amr_domain_ghost_it_test )
865{
866 // Domain
867 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
868
869 long int k = 16*16*16*create_vcluster().getProcessingUnits();
870 k = std::pow(k, 1/3.);
871
874
875 Test3D_amr_domain_ghost_it(amr_g,domain3,k,4);
876
878
879 Test3D_amr_domain_ghost_it(amr_g2,domain3,k,4);
880
881 for (size_t i = 0 ; i < amr_g2.getNLvl() ; i++)
882 {BOOST_REQUIRE(amr_g2.size_inserted(i) != 0ul);}
883
884 amr_g2.clear();
885
886 for (size_t i = 0 ; i < amr_g2.getNLvl() ; i++)
887 {BOOST_REQUIRE_EQUAL(amr_g2.size_inserted(i),0ul);}
888}
889
890BOOST_AUTO_TEST_CASE( grid_dist_amr_get_child_test_low_res )
891{
892 // Domain
893 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
894
895 long int k = 2;
896
899
900 Test3D_amr_child_parent_get_no_periodic(amr_g,domain3,k,4);
901
903
904 Test3D_amr_child_parent_get_no_periodic(amr_g2,domain3,k,4);
905}
906
907BOOST_AUTO_TEST_CASE( grid_dist_amr_test_background_value )
908{
909 // Domain
910 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
911
913
915
916 size_t g_sz[3] = {4,4,4};
917
918 amr_g2.initLevels(4,g_sz);
919
921 bck.get<0>() = -57;
922 bck.get<1>() = -90;
923 bck.get<2>() = -123;
924
925 amr_g2.setBackgroundValue(bck);
926
927 // Get a non existent point to check that
928 // the background value work
929
930 grid_dist_key_dx<3> key(0,grid_key_dx<3>({0,0,0}));
931 long int bck0 = amr_g2.get<0>(2,key);
932 BOOST_REQUIRE_EQUAL(bck0,-57);
933 long int bck1 = amr_g2.get<1>(2,key);
934 BOOST_REQUIRE_EQUAL(bck1,-90);
935 long int bck2 = amr_g2.get<2>(2,key);
936 BOOST_REQUIRE_EQUAL(bck2,-123);
937
938 // Now we insert that point and we check the subsequent point
939 amr_g2.insert<0>(2,key) = 5;
940
941 grid_dist_key_dx<3> key2(0,grid_key_dx<3>({1,0,0}));
942 bck0 = amr_g2.get<0>(2,key2);
943 BOOST_REQUIRE_EQUAL(bck0,-57);
944 bck1 = amr_g2.get<1>(2,key2);
945 BOOST_REQUIRE_EQUAL(bck1,-90);
946 bck2 = amr_g2.get<2>(2,key2);
947 BOOST_REQUIRE_EQUAL(bck2,-123);
948
949 auto & g_dist_lvl2 = amr_g2.getDistGrid(2);
950 g_dist_lvl2.get_loc_grid(0).internal_clear_cache();
951
952 bck0 = amr_g2.get<0>(2,key2);
953 BOOST_REQUIRE_EQUAL(bck0,-57);
954 bck1 = amr_g2.get<1>(2,key2);
955 BOOST_REQUIRE_EQUAL(bck1,-90);
956 bck2 = amr_g2.get<2>(2,key2);
957 BOOST_REQUIRE_EQUAL(bck2,-123);
958
959}
960
961BOOST_AUTO_TEST_CASE( grid_dist_amr_get_domain_ghost_check )
962{
963 // Test grid periodic
964
965 Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
966
967 Vcluster<> & v_cl = create_vcluster();
968
969 if ( v_cl.getProcessingUnits() > 32 )
970 {return;}
971
972 long int k = 13;
973
974 BOOST_TEST_CHECKPOINT( "Testing grid periodic k<=" << k );
975
976 // Ghost
978
979 // periodicity
980 periodicity<3> pr = {{PERIODIC,PERIODIC,PERIODIC}};
981
982 // Distributed grid with id decomposition
984
985 Test3D_ghost_put(g_dist,k);
986
987 // Distributed grid with id decomposition
989
990 Test3D_ghost_put(sg_dist,k);
991}
992
993BOOST_AUTO_TEST_CASE( grid_dist_amr_ghost_put_create )
994{
995 // Test grid periodic
996
997 Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
998
999 Vcluster<> & v_cl = create_vcluster();
1000
1001 if ( v_cl.getProcessingUnits() > 32 )
1002 {return;}
1003
1004 long int k = 13;
1005
1006 BOOST_TEST_CHECKPOINT( "Testing grid periodic k<=" << k );
1007
1008 // Ghost
1009 Ghost<3,long int> g(1);
1010
1011 // periodicity
1012 periodicity<3> pr = {{PERIODIC,PERIODIC,PERIODIC}};
1013
1014 // Distributed grid with id decomposition
1016
1017 Test3D_ghost_put(g_dist,k);
1018
1019 // Distributed grid with id decomposition
1021
1022 Test3D_ghost_put(sg_dist,k);
1023}
1024
1025BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Definition Box.hpp:61
void execute()
Execute all the requests.
size_t size()
Get the total number of processors.
void sum(T &num)
Sum the numbers across all processors and get the result.
Implementation of VCluster class.
Definition VCluster.hpp:59
Grid key for a distributed grid.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503
Declaration grid_sm.
Definition grid_sm.hpp:167
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
__device__ __host__ boost::mpl::at< type, boost::mpl::int_< i > >::type & get()
get the properties i
Boundary conditions.
Definition common.hpp:22