14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
17#include "Amr/grid_dist_amr.hpp"
18#include "Point_test.hpp"
19#include "Grid/tests/grid_dist_id_util_tests.hpp"
23 template<
typename gr
id_type,
typename ite_type>
26 GRID_ID_3_GLOBAL(itg);
28 __shared__
bool is_block_empty;
30 if (threadIdx.x == 0 && threadIdx.y == 0 && threadIdx.z == 0)
31 {is_block_empty =
true;}
37 bool out =
grid.getInsertBlockOffset(itg,key,blk,offset);
39 auto blockId =
grid.getBlockLinId(blk);
41 const float x = keyg.get(0)*spacing - center.
get(0);
42 const float y = keyg.get(1)*spacing - center.
get(1);
43 const float z = keyg.get(2)*spacing - center.
get(2);
45 float radius = sqrt((
float) (x*x + y*y + z*z));
47 bool is_active = radius < 0.4 && radius > 0.3;
49 if (is_active ==
true)
50 {is_block_empty =
false;}
54 if (is_block_empty ==
false)
56 auto ec =
grid.insertBlock(blockId);
58 if ( is_active ==
true)
60 ec.template get<0>()[offset] = x+y+z;
61 ec.template get<grid_type::pMask>()[offset] = 1;
67 grid.flush_block_insert();
73BOOST_AUTO_TEST_SUITE( amr_grid_dist_id_test )
76BOOST_AUTO_TEST_CASE( grid_dist_id_amr_gpu )
83 sgrid_dist_amr_gpu<3,float,aggregate<float>> amr_g(domain3,g);
85 size_t g_sz[3] = {4,4,4};
89 amr_g.initLevels(n_lvl,g_sz);
91 for (
size_t i = 0 ; i < amr_g.getNLvl() ; i++)
97 auto it = amr_g.getGridIteratorGPU(i);
98 it.setGPUInsertBuffer(1);
103 amr_g.getDistGrid(i).template flush<smax_<0>>(FLUSH_ON_DEVICE);
105 amr_g.getDistGrid(i).template deviceToHost<0>();
107 auto it2 = amr_g.getDistGrid(i).getDomainIterator();
111 auto key = it2.get();
112 auto keyg = it2.getGKey(key);
119 auto & v_cl = create_vcluster();
127 BOOST_REQUIRE_EQUAL(count,0);
130 BOOST_REQUIRE_EQUAL(count,30);
133 BOOST_REQUIRE_EQUAL(count,282);
136 BOOST_REQUIRE_EQUAL(count,2192);
139 BOOST_REQUIRE_EQUAL(count,16890);
142 BOOST_REQUIRE_EQUAL(count,136992);
194BOOST_AUTO_TEST_CASE( grid_dist_id_amr_gpu_link_test )
200 auto & v_cl = create_vcluster();
206 sgrid_dist_amr_gpu<2,float,aggregate<float>> amr_g(domain,g);
208 size_t g_sz[2] = {17,17};
212 amr_g.initLevels(n_lvl,g_sz);
220 auto it = amr_g.getGridIterator(0,start,start);
221 auto it2 = amr_g.getGridIterator(1,start_lvl_dw,stop_lvl_dw);
222 auto it3 = amr_g.getGridIterator(2,start_lvl_dw2,stop_lvl_dw2);
225 auto & lvl_0 = amr_g.getDistGrid(0);
226 auto & lvl_1 = amr_g.getDistGrid(1);
227 auto & lvl_2 = amr_g.getDistGrid(2);
233 auto key = it.get_dist();
235 lvl_0.template insertFlush<0>(key) = 1.0;
242 auto key = it2.get_dist();
244 lvl_1.template insertFlush<0>(key) = 2.0;
251 auto key = it3.get_dist();
253 lvl_2.template insertFlush<0>(key) = 3.0;
258 amr_g.hostToDevice<0>();
260 amr_g.construct_level_connections();
264 auto & lvl_zero_d = amr_g.getDistGrid(0);
265 auto & lvl_one_d = amr_g.getDistGrid(1);
266 auto & lvl_two_d = amr_g.getDistGrid(2);
270 for (
int i = 0 ; i < lvl_zero_d.getN_loc_grid() ; i++)
274 auto & lvl_zero = lvl_zero_d.get_loc_grid(i);
275 auto & lvl_one = lvl_one_d.get_loc_grid(i);
276 auto & lvl_two = lvl_two_d.get_loc_grid(i);
278 auto & offs_dw_link = lvl_zero.getDownLinksOffsets();
279 auto & dw_links = lvl_zero.getDownLinks();
281 BOOST_REQUIRE_EQUAL(offs_dw_link.size(),1);
282 BOOST_REQUIRE_EQUAL(dw_links.size(),4);
284 auto & indexL0 = lvl_zero.private_get_blockMap().getIndexBuffer();
285 auto & indexL1 = lvl_one.private_get_blockMap().getIndexBuffer();
286 auto & indexL2 = lvl_two.private_get_blockMap().getIndexBuffer();
288 auto & dataL0 = lvl_zero.private_get_blockMap().getDataBuffer();
289 auto & dataL1 = lvl_one.private_get_blockMap().getDataBuffer();
290 auto & dataL2 = lvl_two.private_get_blockMap().getDataBuffer();
292 dw_links.template deviceToHost<0,1>();
294 BOOST_REQUIRE_EQUAL(dataL1.template get<0>(dw_links.template get<0>(0))[dw_links.template get<1>(0)],2);
295 BOOST_REQUIRE_EQUAL(dataL1.template get<0>(dw_links.template get<0>(1))[dw_links.template get<1>(1)],2);
296 BOOST_REQUIRE_EQUAL(dataL1.template get<0>(dw_links.template get<0>(2))[dw_links.template get<1>(2)],2);
297 BOOST_REQUIRE_EQUAL(dataL1.template get<0>(dw_links.template get<0>(3))[dw_links.template get<1>(3)],2);
299 auto & offs_dw_link_1 = lvl_one.getDownLinksOffsets();
300 auto & dw_links_1 = lvl_one.getDownLinks();
302 BOOST_REQUIRE_EQUAL(offs_dw_link_1.size(),12);
303 BOOST_REQUIRE_EQUAL(dw_links_1.size(),9);
305 dw_links_1.template deviceToHost<0,1>();
307 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(0))[dw_links_1.template get<1>(0)],3);
308 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(1))[dw_links_1.template get<1>(1)],3);
309 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(2))[dw_links_1.template get<1>(2)],3);
310 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(3))[dw_links_1.template get<1>(3)],3);
311 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(4))[dw_links_1.template get<1>(4)],3);
312 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(5))[dw_links_1.template get<1>(5)],3);
313 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(6))[dw_links_1.template get<1>(6)],3);
314 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(7))[dw_links_1.template get<1>(7)],3);
315 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(8))[dw_links_1.template get<1>(8)],3);
323BOOST_AUTO_TEST_CASE( grid_dist_id_amr_gpu_link_test_more_dense )
329 auto & v_cl = create_vcluster();
335 sgrid_dist_amr_gpu<2,float,aggregate<float>> amr_g(domain,g);
337 size_t g_sz[2] = {17,17};
341 amr_g.initLevels(n_lvl,g_sz);
350 auto it = amr_g.getGridIterator(0,start,stop);
351 auto it2 = amr_g.getGridIterator(1,start_lvl_dw,stop_lvl_dw);
352 auto it3 = amr_g.getGridIterator(2,start_lvl_dw2,stop_lvl_dw2);
354 auto & lvl_0 = amr_g.getDistGrid(0);
355 auto & lvl_1 = amr_g.getDistGrid(1);
356 auto & lvl_2 = amr_g.getDistGrid(2);
362 auto key = it.get_dist();
364 lvl_0.template insertFlush<0>(key) = 1.0;
371 auto key = it2.get_dist();
373 lvl_1.template insertFlush<0>(key) = 2.0;
380 auto key = it3.get_dist();
382 lvl_2.template insertFlush<0>(key) = 3.0;
387 amr_g.hostToDevice<0>();
388 amr_g.ghost_get<0>(RUN_ON_DEVICE);
390 amr_g.ghost_get<0>(RUN_ON_DEVICE);
391 amr_g.construct_level_connections();
392 amr_g.deviceToHost<0>();
393 amr_g.write(
"TESTOUT");
397 auto & lvl_zero_d = amr_g.getDistGrid(0);
398 auto & lvl_one_d = amr_g.getDistGrid(1);
399 auto & lvl_two_d = amr_g.getDistGrid(2);
403 size_t tot_dw_offs_12 = 0;
404 size_t tot_dw_lk_12 = 0;
406 size_t tot_dw_offs_23 = 0;
407 size_t tot_dw_lk_23 = 0;
409 size_t tot_up_offs_12 = 0;
410 size_t tot_up_lk_12 = 0;
412 size_t tot_up_offs_23 = 0;
413 size_t tot_up_lk_23 = 0;
415 for (
int i = 0 ; i < lvl_zero_d.getN_loc_grid() ; i++)
419 auto & lvl_zero = lvl_zero_d.get_loc_grid(i);
420 auto & lvl_one = lvl_one_d.get_loc_grid(i);
421 auto & lvl_two = lvl_two_d.get_loc_grid(i);
423 auto & offs_dw_link = lvl_zero.getDownLinksOffsets();
424 auto & dw_links = lvl_zero.getDownLinks();
426 auto & offs_up_link = lvl_one.getUpLinksOffsets();
427 auto & up_links = lvl_one.getUpLinks();
429 tot_dw_offs_12 += offs_dw_link.size();
430 tot_dw_lk_12 += dw_links.size();
432 tot_up_offs_12 += offs_up_link.size();
433 tot_up_lk_12 += up_links.size();
435 auto & indexL0 = lvl_zero.private_get_blockMap().getIndexBuffer();
436 auto & indexL1 = lvl_one.private_get_blockMap().getIndexBuffer();
437 auto & indexL2 = lvl_two.private_get_blockMap().getIndexBuffer();
439 auto & dataL0 = lvl_zero.private_get_blockMap().getDataBuffer();
440 auto & dataL1 = lvl_one.private_get_blockMap().getDataBuffer();
441 auto & dataL2 = lvl_two.private_get_blockMap().getDataBuffer();
443 dw_links.template deviceToHost<0,1>();
444 up_links.template deviceToHost<0,1>();
446 for (
int i = 0 ; i < dw_links.size(); i++)
448 BOOST_REQUIRE_EQUAL(dataL1.template get<0>(dw_links.template get<0>(i))[dw_links.template get<1>(i)],2);
451 for (
int i = 0 ; i < up_links.size(); i++)
453 BOOST_REQUIRE_EQUAL(dataL0.template get<0>(up_links.template get<0>(i))[up_links.template get<1>(i)],1);
456 auto & offs_dw_link_1 = lvl_one.getDownLinksOffsets();
457 auto & dw_links_1 = lvl_one.getDownLinks();
459 auto & offs_up_link_1 = lvl_two.getUpLinksOffsets();
460 auto & up_links_1 = lvl_two.getUpLinks();
462 tot_dw_offs_23 += offs_dw_link_1.size();
463 tot_dw_lk_23 += dw_links_1.size();
465 tot_up_offs_23 += offs_up_link_1.size();
466 tot_up_lk_23 += up_links_1.size();
468 dw_links_1.template deviceToHost<0,1>();
469 up_links_1.template deviceToHost<0,1>();
471 for (
int i = 0 ; i < dw_links_1.size(); i++)
473 BOOST_REQUIRE_EQUAL(dataL2.template get<0>(dw_links_1.template get<0>(i))[dw_links_1.template get<1>(i)],3);
476 for (
int i = 0 ; i < up_links_1.size(); i++)
478 BOOST_REQUIRE_EQUAL(dataL1.template get<0>(up_links_1.template get<0>(i))[up_links_1.template get<1>(i)],2);
482 v_cl.sum(tot_dw_offs_12);
483 v_cl.sum(tot_dw_lk_12);
485 v_cl.sum(tot_dw_offs_23);
486 v_cl.sum(tot_dw_lk_23);
488 v_cl.sum(tot_up_offs_12);
489 v_cl.sum(tot_up_lk_12);
491 v_cl.sum(tot_up_offs_23);
492 v_cl.sum(tot_up_lk_23);
496 BOOST_REQUIRE_EQUAL(tot_dw_offs_12,56);
497 BOOST_REQUIRE_EQUAL(tot_dw_lk_12,56*4);
499 BOOST_REQUIRE_EQUAL(tot_dw_offs_23,116);
500 BOOST_REQUIRE_EQUAL(tot_dw_lk_23,116*4);
502 BOOST_REQUIRE_EQUAL(tot_up_offs_12,116);
503 BOOST_REQUIRE_EQUAL(tot_up_lk_12,116);
505 BOOST_REQUIRE_EQUAL(tot_up_offs_23,236);
506 BOOST_REQUIRE_EQUAL(tot_up_lk_23,236);
513BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This is a distributed grid.
grid_key_dx is the key to access any element in the grid