| 1 | /* |
| 2 | * amr_base_unit_test.cpp |
| 3 | * |
| 4 | * Created on: Oct 5, 2017 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | #define BOOST_TEST_DYN_LINK |
| 8 | #include <boost/test/unit_test.hpp> |
| 9 | |
| 10 | #include "Grid/grid_dist_id.hpp" |
| 11 | #include "Point_test.hpp" |
| 12 | #include "Grid/tests/grid_dist_id_util_tests.hpp" |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE( amr_grid_dist_id_test ) |
| 15 | |
| 16 | |
| 17 | BOOST_AUTO_TEST_CASE( grid_dist_id_amr ) |
| 18 | { |
| 19 | // Domain |
| 20 | Box<2,float> domain2({0.0,0.0},{1.0,1.0}); |
| 21 | |
| 22 | size_t sz[2] = {100,100}; |
| 23 | |
| 24 | // Ghost |
| 25 | Ghost<2,long int> g(1); |
| 26 | |
| 27 | // periodicity |
| 28 | periodicity<2> pr = {{PERIODIC,PERIODIC}}; |
| 29 | |
| 30 | openfpm::vector<Box<2,long int>> C_draw; |
| 31 | C_draw.add(Box<2,long int>({20,20},{50,24})); |
| 32 | C_draw.add(Box<2,long int>({51,20},{60,24})); |
| 33 | C_draw.add(Box<2,long int>({61,20},{70,24})); |
| 34 | C_draw.add(Box<2,long int>({20,25},{24,66})); |
| 35 | C_draw.add(Box<2,long int>({15,67},{49,85})); |
| 36 | C_draw.add(Box<2,long int>({50,76},{70,81})); |
| 37 | C_draw.add(Box<2,long int>({30,25},{34,37})); |
| 38 | C_draw.add(Box<2,long int>({50,66},{70,70})); |
| 39 | |
| 40 | size_t volume_key = 0; |
| 41 | for (size_t i = 0 ; i < C_draw.size() ; i++) |
| 42 | { |
| 43 | volume_key += Box<2,long int>(C_draw.get(i)).getVolumeKey(); |
| 44 | } |
| 45 | |
| 46 | // Distributed grid with id decomposition |
| 47 | grid_dist_id<2,float,Point_test<float>> g_dist(sz,domain2,g,pr,C_draw); |
| 48 | |
| 49 | // fill with gkey |
| 50 | |
| 51 | auto git = g_dist.getDomainIterator(); |
| 52 | grid_sm<2,void> gs(sz); |
| 53 | |
| 54 | size_t count = 0; |
| 55 | |
| 56 | while (git.isNext()) |
| 57 | { |
| 58 | auto key = git.get(); |
| 59 | auto gkey = git.getGKey(key); |
| 60 | |
| 61 | g_dist.template get<0>(key) = gs.LinId(gkey); |
| 62 | |
| 63 | count++; |
| 64 | |
| 65 | ++git; |
| 66 | } |
| 67 | |
| 68 | Vcluster<> & vcl = create_vcluster(); |
| 69 | |
| 70 | vcl.sum(count); |
| 71 | vcl.execute(); |
| 72 | |
| 73 | BOOST_REQUIRE_EQUAL(count,volume_key); |
| 74 | |
| 75 | g_dist.ghost_get<0>(); |
| 76 | |
| 77 | // Check it is correct |
| 78 | |
| 79 | bool check = true; |
| 80 | size_t check_count = 0; |
| 81 | |
| 82 | auto git2 = g_dist.getDomainGhostIterator(); |
| 83 | while (git2.isNext()) |
| 84 | { |
| 85 | auto key = git2.get(); |
| 86 | auto gkey = git2.getGKey(key); |
| 87 | |
| 88 | float value = g_dist.template get<0>(key); |
| 89 | |
| 90 | // check if the point is inside or outside the domain |
| 91 | |
| 92 | for (size_t k = 0; k < C_draw.size() ; k++) |
| 93 | { |
| 94 | if (Box<2,long int>(C_draw.get(k)).isInside(gkey.toPoint()) == true) |
| 95 | { |
| 96 | check &= value == gs.LinId(gkey); |
| 97 | |
| 98 | // get the gdb_ext |
| 99 | auto & gdb_ext = g_dist.getLocalGridsInfo(); |
| 100 | |
| 101 | for (size_t s = 0 ; s < gdb_ext.size() ; s++) |
| 102 | { |
| 103 | Box<2,long int> bx = gdb_ext.get(s).Dbox; |
| 104 | bx += gdb_ext.get(s).origin; |
| 105 | if (bx.isInside(gkey.toPoint())) |
| 106 | { |
| 107 | check_count++; |
| 108 | break; |
| 109 | } |
| 110 | } |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | ++git2; |
| 116 | } |
| 117 | |
| 118 | vcl.sum(check_count); |
| 119 | vcl.execute(); |
| 120 | |
| 121 | BOOST_REQUIRE_EQUAL(check,true); |
| 122 | BOOST_REQUIRE(check_count >= volume_key); |
| 123 | } |
| 124 | |
| 125 | BOOST_AUTO_TEST_CASE( amr_grid_dist_id_iterator_test_use_2D) |
| 126 | { |
| 127 | // Domain |
| 128 | Box<2,float> domain({0.0,0.0},{1.0,1.0}); |
| 129 | |
| 130 | #ifdef TEST_COVERAGE_MODE |
| 131 | long int k = 256*256*create_vcluster().getProcessingUnits(); |
| 132 | #else |
| 133 | long int k = 1024*1024*create_vcluster().getProcessingUnits(); |
| 134 | #endif |
| 135 | k = std::pow(k, 1/2.); |
| 136 | |
| 137 | long int big_step = k / 30; |
| 138 | big_step = (big_step == 0)?1:big_step; |
| 139 | long int small_step = 21; |
| 140 | |
| 141 | print_test( "AMR Testing 2D full grid k<=" ,k); |
| 142 | |
| 143 | // 2D test |
| 144 | for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) |
| 145 | { |
| 146 | BOOST_TEST_CHECKPOINT( "AMR Testing 2D full grid k=" << k ); |
| 147 | |
| 148 | //! [Create and access a distributed grid] |
| 149 | |
| 150 | // grid size |
| 151 | size_t sz[2]; |
| 152 | sz[0] = k; |
| 153 | sz[1] = k; |
| 154 | |
| 155 | // periodicity |
| 156 | periodicity<2> pr = {{PERIODIC,PERIODIC}}; |
| 157 | |
| 158 | // Ghost |
| 159 | Ghost<2,long int> g(1); |
| 160 | |
| 161 | openfpm::vector<Box<2,long int>> bx_def; |
| 162 | bx_def.add(Box<2,long int>({0,0},{k-1,k-1})); |
| 163 | |
| 164 | // Distributed grid with id decomposition |
| 165 | grid_dist_id<2, float, aggregate<double>> g_dist(sz,domain,g,pr,bx_def); |
| 166 | |
| 167 | Test2D_core(g_dist,sz,k); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | BOOST_AUTO_TEST_SUITE_END() |
| 172 | |