OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
CellDecomposer_unit_tests.hpp
1 /*
2  * CellDecomposer_unit_tests.hpp
3  *
4  * Created on: Feb 12, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLDECOMPOSER_UNIT_TESTS_HPP_
9 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLDECOMPOSER_UNIT_TESTS_HPP_
10 
11 BOOST_AUTO_TEST_SUITE( CellDecomposer_test )
12 
13 BOOST_AUTO_TEST_CASE( CellDecomposer_get_grid_points )
14 {
15  {
16  // Cell decomposer
17  CellDecomposer_sm<3,float> cd;
18 
19  // Box
20  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
21 
22  // Divisions
23  size_t div[] = {10,10,10};
24 
25  // padding
26  size_t padding = 1;
27 
28  // Set the dimensions of the decomposer
29  cd.setDimensions(box,div,padding);
30 
31  Box<3,float> box_small({0.2,0.3,0.4},{0.5,0.5,0.6});
32 
33  // Get the grid points box
34  Box<3,size_t> gp = cd.getGridPoints(box_small);
35 
36  BOOST_REQUIRE_EQUAL(gp.getLow(0),2+padding);
37  BOOST_REQUIRE_EQUAL(gp.getLow(1),3+padding);
38  BOOST_REQUIRE_EQUAL(gp.getLow(2),4+padding);
39 
40  BOOST_REQUIRE_EQUAL(gp.getHigh(0),5+padding-1);
41  BOOST_REQUIRE_EQUAL(gp.getHigh(1),5+padding-1);
42  BOOST_REQUIRE_EQUAL(gp.getHigh(2),6+padding-1);
43 
44  // Get the volume of the box
45  size_t vol = gp.getVolumeKey();
46 
47  BOOST_REQUIRE_EQUAL(vol,12ul);
48  }
49 
51  // 2D test
53 
54  {
55  // Cell decomposer
56  CellDecomposer_sm<2,float> cd;
57 
58  // Box
59  Box<2,float> box({0.0,0.0},{1.0,1.0});
60 
61  // Divisions
62  size_t div[] = {5,5};
63 
64  // padding
65  size_t padding = 1;
66 
67  // Set the dimensions of the decomposer
68  cd.setDimensions(box,div,padding);
69 
70  Box<2,float> box_small({0.4,0.4},{0.8,0.8});
71 
72  // Get the grid points box
73  Box<2,size_t> gp = cd.getGridPoints(box_small);
74 
75  BOOST_REQUIRE_EQUAL(gp.getLow(0),2+padding);
76  BOOST_REQUIRE_EQUAL(gp.getLow(1),2+padding);
77 
78  BOOST_REQUIRE_EQUAL(gp.getHigh(0),3+padding);
79  BOOST_REQUIRE_EQUAL(gp.getHigh(1),3+padding);
80 
81  // Get the volume of the box
82  size_t vol = gp.getVolumeKey();
83 
84  BOOST_REQUIRE_EQUAL(vol,4ul);
85  }
86 }
87 
88 
89 BOOST_AUTO_TEST_CASE( CellDecomposer_use )
90 {
92  //Space where is living the Cell list
93  SpaceBox<3,double> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
94  Point<3,double> p({0.5,0.5,0.5});
95  double pp[3] = {0.5,0.5,0.5};
96 
97  // Number of cell on each dimension
98  size_t div[3] = {16,16,16};
99 
100  // grid info
101  grid_sm<3,void> g_info(div);
102 
103  // Origin
104  Point<3,double> org({0.0,0.0,0.0});
105 
106  // Test Cell decomposer
107  {
108  CellDecomposer_sm<3,double> cd(box,div,0);
109  size_t cell = cd.getCell(p);
110  BOOST_REQUIRE_EQUAL(cell,(size_t)(8*16*16 + 8*16 + 8));
111  auto key = cd.getCellGrid(p);
112  BOOST_REQUIRE_EQUAL(key.get(0),8);
113  BOOST_REQUIRE_EQUAL(key.get(1),8);
114  BOOST_REQUIRE_EQUAL(key.get(2),8);
115 
116  cell = cd.getCell(pp);
117  BOOST_REQUIRE_EQUAL(cell,(size_t)(8*16*16 + 8*16 + 8));
118  key = cd.getCellGrid(pp);
119  BOOST_REQUIRE_EQUAL(key.get(0),8);
120  BOOST_REQUIRE_EQUAL(key.get(1),8);
121  BOOST_REQUIRE_EQUAL(key.get(2),8);
122  }
123 
125 
127  {
128  CellDecomposer_sm<3,double> cd(box,div,1);
129  size_t cell = cd.getCell(p);
130  BOOST_REQUIRE_EQUAL(cell,(size_t)(9*18*18 + 9*18 + 9));
131  auto key = cd.getCellGrid(p);
132  BOOST_REQUIRE_EQUAL(key.get(0),9);
133  BOOST_REQUIRE_EQUAL(key.get(1),9);
134  BOOST_REQUIRE_EQUAL(key.get(2),9);
135 
136  cell = cd.getCell(pp);
137  BOOST_REQUIRE_EQUAL(cell,(size_t)(9*18*18 + 9*18 + 9));
138  key = cd.getCellGrid(pp);
139  BOOST_REQUIRE_EQUAL(key.get(0),9);
140  BOOST_REQUIRE_EQUAL(key.get(1),9);
141  BOOST_REQUIRE_EQUAL(key.get(2),9);
142  }
143 
145 
147  {
148  Point<3,double> sht({1.0,2.0,3.0});
149  Box<3,double> box2 = box;
150  box2+= sht;
151  double psht[3] = {1.5,2.5,3.5};
152 
153  CellDecomposer_sm< 3,double,shift<3,double> > cd(box2,div,1);
154  size_t cell = cd.getCell(p + sht);
155  BOOST_REQUIRE_EQUAL(cell,(size_t)(9*18*18 + 9*18 + 9));
156  auto key = cd.getCellGrid(p + sht);
157  BOOST_REQUIRE_EQUAL(key.get(0),9);
158  BOOST_REQUIRE_EQUAL(key.get(1),9);
159  BOOST_REQUIRE_EQUAL(key.get(2),9);
160 
161  cell = cd.getCell(psht);
162  BOOST_REQUIRE_EQUAL(cell,(size_t)(9*18*18 + 9*18 + 9));
163  key = cd.getCellGrid(psht);
164  BOOST_REQUIRE_EQUAL(key.get(0),9);
165  BOOST_REQUIRE_EQUAL(key.get(1),9);
166  BOOST_REQUIRE_EQUAL(key.get(2),9);
167  }
168 
170 
172  {
173  CellDecomposer_sm<3,double> cd(box,div,1);
174  size_t cell_cor_dom = cd.getCellDom(Point<3,double>({-0.000001,-0.000001,-0.000001}));
175  size_t cell_cor_pad = cd.getCellPad(Point<3,double>({0.000001,0.000001,0.000001}));
176  size_t cell_not_cor_pad1 = cd.getCell(Point<3,double>({-0.000001,-0.000001,-0.000001}));
177  size_t cell_not_cor_pad2 = cd.getCell(Point<3,double>({0.000001,0.000001,0.000001}));
178  BOOST_REQUIRE_EQUAL(cell_cor_pad,0ul);
179  BOOST_REQUIRE_EQUAL(cell_cor_dom,(size_t)(1*18*18 + 1*18 + 1));
180  BOOST_REQUIRE_EQUAL(cell_not_cor_pad1,0ul);
181  BOOST_REQUIRE_EQUAL(cell_not_cor_pad2,(size_t)(1*18*18 + 1*18 + 1));
182  }
183 }
184 
185 #define N_POINTS 1000
186 
187 BOOST_AUTO_TEST_CASE( CellDecomposer_consistent_use )
188 {
189  {
190 
192 
193  // number of divisions in each directions
194  // random engine
195  size_t div[3] = {16,16,16};
196  std::default_random_engine g;
197  std::uniform_real_distribution<double> d(0.0,1.0);
198 
199  SpaceBox<3,double> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
200  Point<3,double> sht({1.1,2.1,3.1});
201  SpaceBox<3,double> box2 = box;
202  box2 += sht;
203 
204  CellDecomposer_sm< 3,double,shift<3,double> > cd(box2,div,1);
205 
206  // Here we create another extended Cell decomposer consistent with the
207  // previous
208 
209  Box<3,size_t> ext({1,2,3},{1,1,1});
210  CellDecomposer_sm< 3,double,shift<3,double> > cd2(cd,ext);
211 
213 
214  // we create 2 grid_sm for the 2 CellDecomposer (used to check the consistency)
215  size_t div_ext[3] = {6+16,6+16,6+16};
216  // The old one has a padding 1 the new padding 3, result is padding 2
217  grid_key_dx<3> key_base(2,2,2);
218 
219  grid_sm<3,void> cd_gr(div);
220  grid_sm<3,void> cd2_gr(div_ext);
221 
222  // we randomly choose N_POINTS points inside box
223 
224  for (size_t i = 0 ; i < N_POINTS ; i++)
225  {
226  Point<3,double> p;
227  p.get(0) = d(g);
228  p.get(1) = d(g);
229  p.get(2) = d(g);
230 
231  p += sht;
232 
233  grid_key_dx<3> key = cd.getCellGrid(p);
234  grid_key_dx<3> key2 = cd2.getCellGrid(p);
235 
236  grid_key_dx<3> key_res = key2 - key_base;
237 
238  BOOST_REQUIRE(key == key_res);
239  }
240 
241  grid_key_dx<3> key = cd.getCellGrid(sht);
242  grid_key_dx<3> key2 = cd2.getCellGrid(sht);
243 
244  grid_key_dx<3> key_res = key2 - key_base;
245 
246  BOOST_REQUIRE(key == key_res);
247 
248  Point<3,double> p({1.0,1.0,1.0});
249  p += sht;
250  key = cd.getCellGrid(p);
251  key2 = cd2.getCellGrid(p);
252 
253  key_res = key2 - key_base;
254 
255  BOOST_REQUIRE(key == key_res);
256 
257  }
258 
259 
260 }
261 
262 BOOST_AUTO_TEST_CASE( CellDecomposer_swap_use )
263 {
264  // number of divisions in each directions
265  // random engine
266  size_t div[3] = {16,16,16};
267 
268  SpaceBox<3,double> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
269 
270  CellDecomposer_sm< 3,double,shift<3,double> > cd1(box,div,1);
271 
272  // another cell Decomposer
273 
274  // number of divisions in each directions
275  // random engine
276  size_t div2[3] = {15,15,15};
277 
278  SpaceBox<3,double> box2({-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f});
279 
280  CellDecomposer_sm< 3,double,shift<3,double> > cd2(box2,div2,2);
281 
282  auto cd1_old = cd1;
283  auto cd2_old = cd2;
284 
285  cd1.swap(cd2);
286 
287  BOOST_REQUIRE(cd2 == cd1_old);
288  BOOST_REQUIRE(cd1 == cd2_old);
289 }
290 
291 BOOST_AUTO_TEST_SUITE_END()
292 
293 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLDECOMPOSER_UNIT_TESTS_HPP_ */
This class represent an N-dimensional box.
Definition: SpaceBox.hpp:26
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:479
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:490
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
const T & get(size_t i) const
Get coordinate.
Definition: Point.hpp:142
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
Declaration grid_sm.
Definition: grid_sm.hpp:71
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.
Definition: Box.hpp:1154