8 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_TEST_HPP_
9 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_TEST_HPP_
11 #include "NN/CellList/CellListIterator.hpp"
12 #include "NN/CellList/ParticleItCRS_Cells.hpp"
21 template<
unsigned int dim,
typename CellList>
void FillCellList(
size_t k,
CellList & NN)
26 for (
size_t i = 0; i < k; i++)
28 for (
size_t j = 0; j < dim; j++)
30 pos[j] = rand()/double(RAND_MAX);
36 BOOST_AUTO_TEST_SUITE( celllist_and_iterator_tests )
38 BOOST_AUTO_TEST_CASE( celllist_lin_and_iterator_test )
44 size_t div[dim] = {4,5,6};
53 for (
size_t i = 0; i < dim; i++)
68 for (
size_t i = 0; i < k*0.9; i++)
70 for (
size_t j = 0; j < dim; j++)
72 pos[j] = rand()/double(RAND_MAX);
82 while (it_cl.isNext())
84 auto p_key = it_cl.
get();
95 BOOST_AUTO_TEST_CASE( celllist_hilb_and_iterator_test )
97 std::string c2 = std::string(
"test_data/NN_hilb_keys");
101 const size_t dim = 3;
103 size_t div[dim] = {4,5,6};
112 for (
size_t i = 0; i < dim; i++)
121 NN.
setOpt(CL_NON_SYMMETRIC | CL_HILBERT_CELL_KEYS);
125 FillCellList<dim>((
size_t)k*0.9,NN);
133 while (it_cl.isNext())
135 auto p_key = it_cl.
get();
151 for (
size_t i = 0; i < keys_old.
size(); i++)
153 size_t a1 = keys_old.get(i);
156 BOOST_REQUIRE_EQUAL(a1,a2);
159 size_t s1 = keys_old.
size();
162 BOOST_REQUIRE_EQUAL(s1,s2);
165 BOOST_AUTO_TEST_CASE( ParticleItCRS_Cells_iterator )
169 const size_t dim = 3;
171 size_t div[dim] = {4,5,6};
172 size_t div_p[dim] = {6,7,8};
183 for (
size_t i = 0; i < dim; i++)
194 FillCellList<dim>(k,NN);
211 dom.add(gs.LinId(key));
219 ParticleItCRS_Cells<dim,CellList<dim,float,Mem_fast<>,
shift<dim,float>,
vector_type>,
vector_type> it_cl(NN,dom,anom,NN.
getNNc_sym());
223 while (it_cl.isNext())
229 BOOST_REQUIRE_EQUAL(count,k);
239 for (
size_t i = 0; i < k; i++)
241 pos[0] = 0.999*rand()/double(RAND_MAX) + 0.0001;
242 pos[1] = 0.999*rand()/double(RAND_MAX) + 0.0001;
243 pos[2] = 0.999*rand()/double(RAND_MAX) + 0.0001;
250 bool alternate =
false;
257 auto key = it2.get();
259 if (alternate ==
false)
261 dom.add(gs.LinId(key));
267 anom.last().subsub = gs.LinId(key);
276 ParticleItCRS_Cells<dim,CellList<dim,float,Mem_fast<>,
shift<dim,float>,
vector_type>,
vector_type> it_cl2(NN,dom,anom,NN.
getNNc_sym());
280 while (it_cl2.isNext())
286 BOOST_REQUIRE_EQUAL(count,k);
289 BOOST_AUTO_TEST_CASE( ParticleIt_Cells_NN_iterator )
293 const size_t dim = 3;
295 size_t div[dim] = {4,5,6};
296 size_t div_p[dim] = {6,7,8};
305 for (
size_t i = 0; i < dim; i++)
320 for (
size_t i = 0 ; i < dim ; i++)
322 spacing[i] = box.
getHigh(i) / div[i];
323 middle[i] = spacing[i]/2;
336 p.get(0) = key.get(0)*spacing[0] + middle[0];
337 p.get(1) = key.get(1)*spacing[1] + middle[1];
338 p.get(2) = key.get(2)*spacing[2] + middle[2];
357 bool alternate =
false;
360 auto key = it2.get();
362 if (alternate ==
false)
364 dom.add(gs.LinId(key));
370 anom.last().subsub = gs.LinId(key);
372 for(
size_t j = 0 ; j < openfpm::math::pow(3,dim)/2+1 ; j++)
373 {anom.last().NN_subsub.add(NN.
getNNc_sym()[j]);}
384 ParticleItCRS_Cells<dim,CellList<dim,float,Mem_fast<>,
shift<dim,float>,
vector_type>,
vector_type> it_cl(NN,dom,anom,NN.
getNNc_sym());
388 while (it_cl.isNext())
390 auto NN_it = it_cl.getNNIteratorCSR(vp);
394 while (NN_it.isNext())
401 BOOST_REQUIRE_EQUAL(size_NN,14ul);
407 BOOST_REQUIRE_EQUAL(count,(div[0]-2)*(div[1]-2)*(div[2]-2));
410 BOOST_AUTO_TEST_CASE( ParticleIt_Cells_iterator )
414 const size_t dim = 3;
416 size_t div[dim] = {4,5,6};
417 size_t div_p[dim] = {6,7,8};
428 for (
size_t i = 0; i < dim; i++)
439 FillCellList<dim>(k,NN);
454 dom.add(gs.LinId(key));
464 while (it_cl.isNext())
466 auto i = it_cl.get();
472 BOOST_REQUIRE_EQUAL(count,290ul);
475 BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
__device__ __host__ T getHigh(int i) const
get the high interval of the box
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Class for FAST cell list implementation.
const openfpm::vector< size_t > & getCellSFCKeys()
Get the space filling curve object.
void setGhostMarker(size_t ghostMarker)
Set the ghost marker.
__attribute__((always_inline)) inline const typename Mem_type size_t getGhostMarker() const
Return the starting point of the cell p.
const NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)/2+1 > & getNNc_sym() const
Get the symmetric neighborhood.
CellParticleIterator getCellParticleIterator()
return the celllist iterator (across cells)
void add(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list.
void clear()
Clear the cell list.
size_t getPadding(size_t i) const
Return the number of padding cells of the Cell decomposer.
void setOpt(size_t opt)
Sets the option flags that control the cell list.
void Initialize(CellDecomposer_sm< dim, T, transform > &cd_sm, const Box< dim, T > &dom_box, const size_t pad=1, size_t slot=STARTING_NSLOT)
This iterator iterate across the particles of a Cell-list following the Cell structure.
size_t get()
Get the real particle id.
This iterator iterate across the particles of a Cell-list following the Cell structure.
grid_key_dx is the key to access any element in the grid