8 #include "CellList.hpp"
9 #include "Grid/grid_sm.hpp"
11 #ifndef CELLLIST_TEST_HPP_
12 #define CELLLIST_TEST_HPP_
20 template<
unsigned int dim,
typename T,
typename CellS>
void Test_cell_s()
27 size_t div[dim] = {16,16,16};
33 CellS cl2(box,div,org);
40 for (
size_t i = 0 ; i < CELL_REALLOC * 3 ; i++)
46 BOOST_REQUIRE_EQUAL(cl2.getNelements(cl2.getCell(org)),CELL_REALLOC * 3ul);
47 for (
size_t i = 0 ; i < CELL_REALLOC * 3 ; i++)
49 BOOST_REQUIRE_EQUAL(cl2.get(cl2.getCell(org),i),i);
55 CellS cl1(box,div,org);
71 for (
size_t i = 0 ; i < dim ; i++)
73 offset[i].
get(i) += (1.0 / div[i]) / 8.0;
83 key = key * spacing + offset[0];
89 key = key * spacing + offset[1];
104 while (g_it.isNext())
109 key = key * spacing + offset[2];
111 size_t cell = cl1.getCell(key);
112 size_t n_ele = cl1.getNelements(cell);
114 BOOST_REQUIRE_EQUAL(n_ele,2ul);
115 BOOST_REQUIRE_EQUAL(cl1.get(cell,1) - cl1.get(cell,0),1);
125 while (g_it.isNext())
130 key = key * spacing + offset[0];
132 auto cell = cl1.getCell(key);
144 while (g_it.isNext())
149 key = key * spacing + offset[0];
151 auto cell = cl1.getCell(key);
152 size_t n_ele = cl1.getNelements(cell);
154 BOOST_REQUIRE_EQUAL(n_ele,1ul);
166 while (g_it_s.isNext())
173 key = key * spacing + offset[0];
175 auto NN = cl1.template getNNIterator<NO_CHECK>(cl1.getCell(key));
189 BOOST_REQUIRE_EQUAL(total,(
size_t)openfpm::math::pow(3,dim));
195 BOOST_AUTO_TEST_SUITE( CellList_test )
197 BOOST_AUTO_TEST_CASE( CellDecomposer_use )
203 double pp[3] = {0.5,0.5,0.5};
206 size_t div[3] = {16,16,16};
216 CellDecomposer_sm<3,double> cd(box,div,0);
217 size_t cell = cd.getCell(p);
218 BOOST_REQUIRE_EQUAL(cell,(
size_t)(8*16*16 + 8*16 + 8));
219 auto key = cd.getCellGrid(p);
220 BOOST_REQUIRE_EQUAL(key.
get(0),8);
221 BOOST_REQUIRE_EQUAL(key.
get(1),8);
222 BOOST_REQUIRE_EQUAL(key.
get(2),8);
224 cell = cd.getCell(pp);
225 BOOST_REQUIRE_EQUAL(cell,(
size_t)(8*16*16 + 8*16 + 8));
226 key = cd.getCellGrid(pp);
227 BOOST_REQUIRE_EQUAL(key.
get(0),8);
228 BOOST_REQUIRE_EQUAL(key.
get(1),8);
229 BOOST_REQUIRE_EQUAL(key.
get(2),8);
236 CellDecomposer_sm<3,double> cd(box,div,1);
237 size_t cell = cd.getCell(p);
238 BOOST_REQUIRE_EQUAL(cell,(
size_t)(9*18*18 + 9*18 + 9));
239 auto key = cd.getCellGrid(p);
240 BOOST_REQUIRE_EQUAL(key.
get(0),9);
241 BOOST_REQUIRE_EQUAL(key.
get(1),9);
242 BOOST_REQUIRE_EQUAL(key.
get(2),9);
244 cell = cd.getCell(pp);
245 BOOST_REQUIRE_EQUAL(cell,(
size_t)(9*18*18 + 9*18 + 9));
246 key = cd.getCellGrid(pp);
247 BOOST_REQUIRE_EQUAL(key.
get(0),9);
248 BOOST_REQUIRE_EQUAL(key.
get(1),9);
249 BOOST_REQUIRE_EQUAL(key.
get(2),9);
257 double psht[3] = {1.5,2.5,3.5};
259 CellDecomposer_sm< 3,double,shift<3,double> > cd(box,div,sht,1);
260 size_t cell = cd.getCell(p + sht);
261 BOOST_REQUIRE_EQUAL(cell,(
size_t)(9*18*18 + 9*18 + 9));
262 auto key = cd.getCellGrid(p + sht);
263 BOOST_REQUIRE_EQUAL(key.
get(0),9);
264 BOOST_REQUIRE_EQUAL(key.
get(1),9);
265 BOOST_REQUIRE_EQUAL(key.
get(2),9);
267 cell = cd.getCell(psht);
268 BOOST_REQUIRE_EQUAL(cell,(
size_t)(9*18*18 + 9*18 + 9));
269 key = cd.getCellGrid(psht);
270 BOOST_REQUIRE_EQUAL(key.
get(0),9);
271 BOOST_REQUIRE_EQUAL(key.
get(1),9);
272 BOOST_REQUIRE_EQUAL(key.
get(2),9);
280 BOOST_AUTO_TEST_CASE( CellList_use)
282 std::cout <<
"Test cell list" <<
"\n";
284 Test_cell_s<3,double,CellList<3,double,FAST>>();
288 std::cout <<
"End cell list" <<
"\n";
293 BOOST_AUTO_TEST_CASE( CellDecomposer_get_grid_points )
297 CellDecomposer_sm<3,float> cd;
303 size_t div[] = {10,10,10};
309 cd.setDimensions(box,div,padding);
316 BOOST_REQUIRE_EQUAL(gp.
getLow(0),2+padding);
317 BOOST_REQUIRE_EQUAL(gp.
getLow(1),3+padding);
318 BOOST_REQUIRE_EQUAL(gp.
getLow(2),4+padding);
320 BOOST_REQUIRE_EQUAL(gp.
getHigh(0),5+padding-1);
321 BOOST_REQUIRE_EQUAL(gp.
getHigh(1),5+padding-1);
322 BOOST_REQUIRE_EQUAL(gp.
getHigh(2),6+padding-1);
327 BOOST_REQUIRE_EQUAL(vol,12ul);
336 CellDecomposer_sm<2,float> cd;
342 size_t div[] = {5,5};
348 cd.setDimensions(box,div,padding);
355 BOOST_REQUIRE_EQUAL(gp.
getLow(0),2+padding);
356 BOOST_REQUIRE_EQUAL(gp.
getLow(1),2+padding);
358 BOOST_REQUIRE_EQUAL(gp.
getHigh(0),3+padding);
359 BOOST_REQUIRE_EQUAL(gp.
getHigh(1),3+padding);
364 BOOST_REQUIRE_EQUAL(vol,4ul);
368 BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
grid_key_dx is the key to access any element in the grid
T getHigh(int i) const
get the high interval of the box
This class implement the point shape in an N-dimensional space.
T get(int i) const
Get coordinate.
This class represent an N-dimensional box.
This class is a trick to indicate the compiler a specific specialization pattern. ...
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.