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