9#include "CellListM.hpp"
10#include "Grid/grid_sm.hpp"
12#ifndef CELLLIST_TEST_HPP_
13#define CELLLIST_TEST_HPP_
21template<
unsigned int dim,
typename T,
typename CellS>
void Test_cell_s(
SpaceBox<dim,T> & box)
28 size_t div[dim] = {16,16,16};
41 for (
size_t i = 0 ; i < CELL_REALLOC * 3 ; i++)
47 BOOST_REQUIRE_EQUAL(cl2.getNelements(cl2.getCell(org)),CELL_REALLOC * 3ul);
48 for (
size_t i = 0 ; i < CELL_REALLOC * 3 ; i++)
50 BOOST_REQUIRE_EQUAL(cl2.get(cl2.getCell(org),i),i);
72 for (
size_t i = 0 ; i < dim ; i++)
74 offset[i].
get(i) += (1.0 / div[i]) / 8.0;
85 key = pmul(key,spacing) + offset[0] + box.
getP1();
92 key = pmul(key,spacing) + offset[1] + box.
getP1();
108 while (g_it.isNext())
113 key = pmul(key,spacing) + offset[2] + box.
getP1();
115 size_t cell = cl1.getCell(key);
116 size_t n_ele = cl1.getNelements(cell);
118 BOOST_REQUIRE_EQUAL(n_ele,2ul);
119 BOOST_REQUIRE_EQUAL((
long int)(cl1.get(cell,1) - cl1.get(cell,0)),1);
129 while (g_it.isNext())
134 key = pmul(key,spacing) + offset[0] + box.
getP1();
136 auto cell = cl1.getCell(key);
148 while (g_it.isNext())
153 key = pmul(key,spacing) + offset[0] + box.
getP1();
155 auto cell = cl1.getCell(key);
156 size_t n_ele = cl1.getNelements(cell);
158 BOOST_REQUIRE_EQUAL(n_ele,1ul);
171 while (g_it_s.isNext())
176 key = pmul(key,spacing) + offset[0] + box.
getP1();
178 auto NN = cl1.template getNNIterator<NO_CHECK>(cl1.getCell(key));
192 BOOST_REQUIRE_EQUAL(total,(
size_t)openfpm::math::pow(3,dim));
199 id = cl1.get(cl1.getCell(key),0);
200 auto NNSym = cl1.template getNNIteratorSym<NO_CHECK>(cl1.getCell(key),
id,pos);
203 while(NNSym.isNext())
212 BOOST_REQUIRE_EQUAL(total,(
size_t)openfpm::math::pow(3,dim) / 2 + 1);
227template<
unsigned int dim,
typename T,
typename CellS>
void Test_cell_sM(
SpaceBox<dim,T> & box)
233 size_t div[dim] = {16,16,16};
260 for (
size_t i = 0 ; i < dim ; i++)
262 offset[i].
get(i) += (1.0 / div[i]) / 8.0;
274 while (g_it.isNext())
279 key = pmul(key,spacing) + offset[0] + box.
getP1();
286 key = pmul(key,spacing) + offset[1] + box.
getP1();
300 while (g_it.isNext())
305 key = pmul(key,spacing) + offset[2] + box.
getP1();
307 size_t cell = cl1.getCell(key);
308 size_t n_ele = cl1.getNelements(cell);
310 size_t p1 = cl1.getP(cell,1);
311 size_t p2 = cl1.getP(cell,0);
313 size_t v1 = cl1.getV(cell,1);
314 size_t v2 = cl1.getV(cell,0);
316 BOOST_REQUIRE_EQUAL(n_ele,2ul);
317 BOOST_REQUIRE_EQUAL((
long int)(p1 - p2),0);
318 BOOST_REQUIRE_EQUAL((
long int)(v1 - v2),1);
325template<
typename CellList>
void Test_CellDecomposer_consistent()
329 size_t div[2] = {36,36};
331 CellDecomposer_sm<2,float,shift<2,float>> cd(bx,div,1);
333 Box<2,float> bx_sub({-1.0/5.0,-1.0/5.0},{1.0/5.0,1.0/5.0});
335 size_t bc[2] = {NON_PERIODIC,NON_PERIODIC};
337 Box<2,long int> bx_int = cd.convertDomainSpaceIntoGridUnits(bx_sub,bc);
339 BOOST_REQUIRE_EQUAL(bx_int.
getLow(0),8);
340 BOOST_REQUIRE_EQUAL(bx_int.
getLow(1),8);
342 BOOST_REQUIRE_EQUAL(bx_int.
getHigh(0),28);
343 BOOST_REQUIRE_EQUAL(bx_int.
getHigh(1),28);
345 cd.convertCellUnitsIntoDomainSpace(bx_sub);
347 BOOST_REQUIRE_EQUAL(bx_sub.getLow(0),-1.0f/5.0f);
348 BOOST_REQUIRE_EQUAL(bx_sub.getLow(1),-1.0f/5.0f);
350 BOOST_REQUIRE_EQUAL(bx_sub.getHigh(0),1.0f/5.0f);
351 BOOST_REQUIRE_EQUAL(bx_sub.getHigh(1),1.0f/5.0f);
359template<
unsigned int dim,
typename T,
typename CellS>
void Test_NN_iterator_radius(
SpaceBox<dim,T> & box)
368 for (
size_t i = 0 ; i < dim ; i++)
381 CellS cl1(box,div,2);
382 CellS cl2(box,div2,3);
386 cl2.setRadius( radius );
392 for (
size_t j = 0 ; j < 10000 ; j++)
396 for (
size_t i = 0 ; i < dim ; i++)
398 vrp.template get<0>(j)[i] = ((float)rand() / (float)RAND_MAX)*(box.
getHigh(i) - box.
getLow(i)) + box.
getLow(i);
402 auto g_it = vrp.getIterator();
404 while (g_it.isNext())
408 size_t debug = cl1.getCell(xp);
410 cl1.add(xp,g_it.get());
411 cl2.add(xp,g_it.get());
419 auto g_it2 = vrp.getIterator();
421 size_t number_of_nn = 0;
422 size_t number_of_nn2 = 0;
424 while (g_it2.isNext())
434 auto NNit = cl1.getNNIterator(cl1.getCell(xp));
436 while (NNit.isNext())
445 if (r.norm() <= radius)
454 auto NN2it = cl2.getNNIteratorRadius(cl2.getCell(xp));
456 while (NN2it.isNext())
458 auto q = NN2it.get();
463 if (r.norm() <= radius)
476 match &= ids1.
size() == ids2.
size();
478 for (
size_t i = 0 ; i < ids1.
size() ; i++)
479 {match &= ids1.get(i) == ids2.get(i);}
487 BOOST_REQUIRE_EQUAL(match,
true);
488 BOOST_REQUIRE(number_of_nn2 < number_of_nn);
491BOOST_AUTO_TEST_SUITE( CellList_test )
493BOOST_AUTO_TEST_CASE ( NN_radius_check )
499 std::cout <<
"Test cell list radius" <<
"\n";
501 Test_NN_iterator_radius<2,float,CellList<2,float,Mem_fast<>,
shift<2,float>>>(box1);
502 Test_NN_iterator_radius<3,float,CellList<3,float,Mem_fast<>,
shift<3,float>>>(box2);
503 Test_NN_iterator_radius<3,float,CellList<3,float,Mem_fast<>,
shift<3,float>>>(box3);
505 std::cout <<
"End cell list" <<
"\n";
508BOOST_AUTO_TEST_CASE( CellList_use)
510 std::cout <<
"Test cell list" <<
"\n";
514 Test_cell_s<3,double,CellList<3,double,Mem_fast<>>>(box);
515 Test_cell_s<3,double,CellList<3,double,Mem_fast<>,
shift<3,double>> >(box2);
516 Test_cell_sM<3,double,CellListM<3,double,8>>(box);
517 Test_cell_sM<3,double,CellListM<3,double,8>>(box2);
520 Test_cell_s<3,double,CellList<3,double,Mem_bal<>>>(box);
521 Test_cell_s<3,double,CellList<3,double,Mem_mw<>>>(box);
523 std::cout <<
"End cell list" <<
"\n";
528BOOST_AUTO_TEST_CASE( CellList_consistent )
530 Test_CellDecomposer_consistent<CellList<2,float,Mem_fast<>,
shift<2,float>>>();
533BOOST_AUTO_TEST_CASE( CellList_NNc_csr_calc )
539 BOOST_REQUIRE_EQUAL(cNN.
size(),14ul);
587BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Point< dim, T > getP2() const
Get the point p2.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Point< dim, T > getP1() const
Get the point p1.
Class for FAST cell list implementation.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This class represent an N-dimensional box.
Declaration grid_key_dx_iterator_sub.
grid_key_dx is the key to access any element in the grid
Implementation of 1-D std::vector like structure.
Structure that contain a reference to a vector of particles.