11 #include "Vector/map_vector.hpp"
12 #include "CellDecomposer.hpp"
13 #include "Space/SpaceBox.hpp"
14 #include "util/mathutil.hpp"
15 #include "CellNNIterator.hpp"
16 #include "Space/Shape/HyperCube.hpp"
17 #include "CellListNNIteratorRadius.hpp"
18 #include <unordered_map>
20 #include "CellListIterator.hpp"
21 #include "ParticleIt_Cells.hpp"
22 #include "ParticleItCRS_Cells.hpp"
23 #include "util/common.hpp"
25 #include "NN/Mem_type/MemFast.hpp"
26 #include "NN/Mem_type/MemBalanced.hpp"
27 #include "NN/Mem_type/MemMemoryWise.hpp"
28 #include "NN/CellList/NNc_array.hpp"
31 template<
typename key,
typename val>
36 #ifdef HAVE_LIBQUADMATH
38 #include <boost/multiprecision/float128.hpp>
42 template<
typename val>
50 #define CELL_REALLOC 16ul
52 #define STARTING_NSLOT 16
66 typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
67 typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
75 for (
size_t i = 0 ; i < dim ; i++)
82 for (
size_t i = 0; i < dim; i++)
85 size_t middle = gs.LinId(src_);
88 while (gr_sub3.isNext())
90 auto dst = gr_sub3.get();
93 if ((
long int)middle > gs.LinId(dst))
101 for (
size_t i = 0 ; i < dim; i++)
106 dst.set_d(i,dst.get(i) + 1);
132 typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
133 typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
141 for (
size_t i = 0 ; i < dim ; i++)
148 for (
size_t i = 0; i < dim; i++)
151 size_t middle = gs.LinId(src_);
154 while (gr_sub3.isNext())
156 auto dst = gr_sub3.get();
158 if ((
long int)middle > gs.LinId(dst))
183 typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
184 typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
192 for (
size_t i = 0 ; i < dim ; i++)
199 for (
size_t i = 0; i < dim; i++)
203 while (gr_sub3.isNext())
205 auto dst = gr_sub3.get();
268 template<
unsigned int dim,
typename T,
typename Mem_type,
typename transform = no_transform<dim,T>,
typename base=openfpm::vector<
size_t>>
269 class CellList :
public CellDecomposer_sm<dim,T,transform>,
public Mem_type
338 size_t n_cell_mid[dim];
343 for (
size_t i = 0 ; i < dim ; i++)
345 n_cell[i] = 2*(std::ceil(r_cut / spacing.
get(i)))+1;
346 n_cell_mid[i] = n_cell[i] / 2;
356 for (
size_t i = 0 ; i < dim ; i++)
357 key.set_d(i,
key.get(i) - n_cell_mid[i]);
368 Mem_type::init_to_zero(slot,tot_n_cell);
377 void setCellDecomposer(CellDecomposer_sm<dim,T,transform> & cd,
const CellDecomposer_sm<dim,T,transform> & cd_sm,
const Box<dim,T> & dom_box,
size_t pad)
const
381 for (
size_t i = 0 ; i < dim ; i++)
382 bc[i] = NON_PERIODIC;
389 for (
size_t i = 0 ; i < dim ; i++)
392 div_big[i] = cd_sm.getDiv()[i] - 2*cd_sm.getPadding(i);
395 cd.setDimensions(cd_sm.getDomain(),div_big,div, pad, bx.
getP1());
418 return CellDecomposer_sm<dim,T,transform>::getGrid();
434 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)
437 for (
size_t i = 0 ; i < dim ; i++) {bc[i] = NON_PERIODIC;}
441 setCellDecomposer(*
this,cd_sm,dom_box,pad);
443 size_t div_w_pad[dim];
446 for (
size_t i = 0 ; i < dim ; i++)
449 tot_cell *= div_w_pad[i];
468 void Initialize(
const Box<dim,T> & box,
const size_t (&div)[dim],
const size_t pad = 1,
size_t slot=STARTING_NSLOT)
489 CellDecomposer_sm<dim,T,transform>::setDimensions(box,div, mat, pad);
490 Mem_type::set_slot(slot);
501 :Mem_type(STARTING_NSLOT)
506 :Mem_type(STARTING_NSLOT)
513 :Mem_type(STARTING_NSLOT)
529 :Mem_type(slot),CellDecomposer_sm<dim,T,transform>(box,div,mat,box.getP1(),pad)
543 CellList(
Box<dim,T> & box,
const size_t (&div)[dim],
const size_t pad = 1,
size_t slot=STARTING_NSLOT)
544 :Mem_type(slot),
n_dec(0)
574 CellList(CellDecomposer_sm<dim,T,transform> & cd_sm,
const Box<dim,T> & box,
const size_t pad = 1,
size_t slot=STARTING_NSLOT)
575 :Mem_type(slot),
n_dec(0)
596 std::copy(&cell.NNc_full[0],&cell.NNc_full[openfpm::math::pow(3,dim)],&
NNc_full[0]);
597 std::copy(&cell.NNc_sym[0],&cell.NNc_sym[openfpm::math::pow(3,dim)/2+1],&
NNc_sym[0]);
599 Mem_type::swap(static_cast<Mem_type &&>(cell));
601 static_cast<CellDecomposer_sm<dim,T,transform> &
>(*this).swap(cell);
621 Mem_type::operator=(static_cast<const Mem_type &>(cell));
623 static_cast<CellDecomposer_sm<dim,T,transform> &
>(*this) =
static_cast<const CellDecomposer_sm<dim,T,transform> &
>(cell);
651 inline void addCell(
size_t cell_id,
typename base::value_type ele)
653 Mem_type::addCell(cell_id,ele);
662 inline void add(
const T (& pos)[dim],
typename base::value_type ele)
665 size_t cell_id = this->getCell(pos);
667 Mem_type::add(cell_id,ele);
679 size_t cell_id = this->getCell(pos);
681 Mem_type::add(cell_id,ele);
693 inline void addDom(
const T (& pos)[dim],
typename base::value_type ele)
697 size_t cell_id = this->getCellDom(pos);
716 size_t cell_id = this->getCellDom(pos);
731 inline void addPad(
const T (& pos)[dim],
typename base::value_type ele)
735 size_t cell_id = this->getCellPad(pos);
754 size_t cell_id = this->getCell(pos);
767 inline void remove(
size_t cell,
size_t ele)
769 Mem_type::remove(cell,ele);
781 return Mem_type::getNelements(cell_id);
794 inline auto get(
size_t cell,
size_t ele) -> decltype(this->Mem_type::get(cell,ele))
796 return Mem_type::get(cell,ele);
809 inline auto get(
size_t cell,
size_t ele)
const -> decltype(this->Mem_type::get(cell,ele))
811 return Mem_type::get(cell,ele);
824 Mem_type::swap(static_cast<Mem_type &>(cl));
826 static_cast<CellDecomposer_sm<dim,T,transform> &
>(*this) =
static_cast<const CellDecomposer_sm<dim,T,transform> &
>(cl);
912 template<
unsigned int impl>
918 {std::cerr << __FILE__ <<
":" << __LINE__ <<
" Warning when you try to get a symmetric neighborhood iterator, you must construct the Cell-list in a symmetric way" << std::endl;}
921 CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,base>,SYM,impl> cln(cell,p,
NNc_sym,*
this,v);
947 template<
unsigned int impl>
953 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Warning when you try to get a symmetric neighborhood iterator, you must construct the Cell-list in a symmetric way" << std::endl;
956 CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform,base>,SYM,impl> cln(cell,p,
NNc_sym,*
this,v_p1,v_p2);
979 return CellDecomposer_sm<dim,T,transform>::getPadding(i);
990 return CellDecomposer_sm<dim,T,transform>::getPadding();
1008 inline const typename Mem_type::loc_index &
getStartId(
typename Mem_type::loc_index cell_id)
const
1010 return Mem_type::getStartId(cell_id);
1020 inline const typename Mem_type::loc_index &
getStopId(
typename Mem_type::loc_index cell_id)
const
1022 return Mem_type::getStopId(cell_id);
1032 inline const typename Mem_type::loc_index &
get_lin(
const typename Mem_type::loc_index * part_id)
const
1034 return Mem_type::get_lin(part_id);
1073 this->n_dec =
n_dec;
1097 template<
unsigned int dim,
typename St>
static inline void cl_param_calculate(
Box<dim, St> & pbox,
size_t (&div)[dim], St r_cut,
const Ghost<dim, St> & enlarge)
1105 for (
size_t i = 0; i < dim; i++)
1107 div[i] =
static_cast<size_t>((pbox.
getP2().get(i) - pbox.
getP1().get(i)) / r_cut);
1122 template<
unsigned int dim,
typename St>
static
1123 inline void cl_param_calculateSym(
const Box<dim,St> & dom,
1131 for (
size_t i = 0 ; i < dim ; i++)
1137 for (
size_t i = 0 ; i < dim ; i++)
1139 size_t tmp = std::ceil(fabs(g.
getLow(i)) / r_cut);
1140 pad = (pad > tmp)?pad:tmp;
1142 tmp = std::ceil(fabs(g.
getHigh(i)) / r_cut);
1143 pad = (pad > tmp)?pad:tmp;
1146 cd_sm.setDimensions(dom,div,pad);
1159 template<
unsigned int dim,
typename St>
1160 static inline void cl_param_calculateSym(
const Box<dim,St> & dom,
1167 for (
size_t i = 0 ; i < dim ; i++)
1174 cd_sm.setDimensions(dom,div,pad);
ParticleIt_Cells< dim, CellList< dim, T, Mem_fast<>, transform, base > > getDomainIterator(openfpm::vector< size_t > &dom_cells)
Get an iterator over particles following the cell structure.
void add(const T(&pos)[dim], typename base::value_type ele)
Add an element in the cell list.
This class represent an N-dimensional box.
NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)> NNc_full
The array contain the neighborhood of the cell-id in case of asymmetric interaction.
const Mem_type::loc_index & getStartId(typename Mem_type::loc_index cell_id) const
Return the starting point of the cell p.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Mem_type Mem_type_type
Type of internal memory structure.
size_t get_gm()
return the ghost marker
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
CellList(Box< dim, T > &box, const size_t(&div)[dim], Matrix< dim, T > mat, const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor.
CellNNIteratorSymMP< dim, CellList< dim, T, Mem_type, transform, base >,(unsigned int) SYM, impl > getNNIteratorSymMP(size_t cell, size_t p, const openfpm::vector< Point< dim, T >> &v_p1, const openfpm::vector< Point< dim, T >> &v_p2)
Get the symmetric Neighborhood iterator.
const Mem_type::loc_index & get_lin(const typename Mem_type::loc_index *part_id) const
Return the neighborhood id.
const Mem_type::loc_index & getStopId(typename Mem_type::loc_index cell_id) const
Return the end point of the cell p.
size_t getNelements(const size_t cell_id) const
Return the number of elements in the cell.
size_t get_ndec() const
Set the n_dec number.
void magnify(T mg)
Magnify the box.
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)
CellNNIteratorSym< dim, CellList< dim, T, Mem_type, transform, base >,(unsigned int) SYM, impl > getNNIteratorSym(size_t cell, size_t p, const openfpm::vector< Point< dim, T >> &v)
Get the symmetric Neighborhood iterator.
T getHigh(int i) const
get the high interval of the box
void addPad(const Point< dim, T > &pos, typename base::value_type ele)
Add an element in the cell list forcing to be in the padding cells.
void setHigh(int i, T val)
set the high interval of the box
CellList()
Default Constructor.
This class implement the point shape in an N-dimensional space.
Symmetric iterator for the neighborhood of the cell structures.
Point< dim, T > getP1() const
Get the point p1.
const NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)/2+1 > & getNNc_sym() const
Get the symmetric neighborhood.
Symmetric iterator for the neighborhood of the cell structures.
void Initialize(const SpaceBox< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
void set_size(const size_t(&sz)[dim])
Set the size in each.
void swap(CellList< dim, T, Mem_type, transform, base > &cl)
Swap the memory.
mem_id get(size_t i) const
Get the i index.
CellNNIteratorRadius< dim, CellList< dim, T, Mem_type, transform, base >, impl > getNNIteratorRadius(size_t cell, T r_cut)
Get the symmetric Neighborhood iterator.
CellList(const CellList< dim, T, Mem_type, transform, base > &cell)
Copy constructor.
void InitializeStructures(const size_t(&div)[dim], size_t tot_n_cell, size_t slot=STARTING_NSLOT)
Initialize the structures of the data structure.
CellIterator< CellList< dim, T, Mem_type, transform, base > > getCellIterator(size_t cell)
Get the Cell iterator.
size_t(& getPadding())[dim]
Return the number of padding cells of the Cell decomposer as an array.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
T stype
Type of the coordinate space (double float)
size_t getPadding(size_t i) const
Return the number of padding cells of the Cell decomposer.
const grid_key_dx< dim > & get() const
Get the actual key.
This class implement an NxN (dense) matrix.
const T & get(size_t i) const
Get coordinate.
it iterate through the elements of a cell
CellList(CellList< dim, T, Mem_type, transform, base > &&cell)
Copy constructor.
void init_sym()
Initialize the NNc array with symmetric neighborhood cells indexes.
bool isNext()
Check if there is the next element.
CellList(Box< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor.
void addPad(const T(&pos)[dim], typename base::value_type ele)
Add an element in the cell list forcing to be in the padding cells.
This class represent an N-dimensional box.
wrap_unordered_map< T, openfpm::vector< long int > > rcache
Caching of r_cutoff radius.
This class is a trick to indicate the compiler a specific specialization pattern. ...
void set_ndec(size_t n_dec)
Set the n_dec number.
CellList(SpaceBox< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor.
void clear()
Clear the cell list.
void Initialize(const Box< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
void addDom(const Point< dim, T > &pos, typename base::value_type ele)
Add an element in the cell list forcing to be in the domain cells.
void addDom(const T(&pos)[dim], typename base::value_type ele)
Add an element in the cell list forcing to be in the domain cells.
NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)/2+1 > NNc_sym
The array contain the neighborhood of the cell-id in case of symmetric interaction.
const grid_sm< dim, void > & getGrid()
Return the underlying grid information of the cell list.
This iterator iterate across the particles of a Cell-list following the Cell structure.
void swap(NNc_array< dim, size, thr > &nnc)
swap NNc_array
void set_gm(size_t g_m)
Set the ghost marker.
void addCell(size_t cell_id, typename base::value_type ele)
Add to the cell.
CellNNIterator< dim, CellList< dim, T, Mem_type, transform, base >,(int) FULL, impl > getNNIterator(size_t cell)
Get the Neighborhood iterator.
void init_full()
Initialize the NNc array with full neighborhood cells indexes.
bool from_cd
True if has been initialized from CellDecomposer.
void set_d(size_t i, mem_id id)
Set the i index.
CellList< dim, T, Mem_type, transform, base > & operator=(CellList< dim, T, Mem_type, transform, base > &&cell)
Constructor from a temporal object.
CellList< dim, T, Mem_type, transform, base > & operator=(const CellList< dim, T, Mem_type, transform, base > &cell)
Constructor from a temporal object.
Iterator for the neighborhood of the cell structures with free radius.
Wrapper of the unordered map.
Implementation of 1-D std::vector like structure.
base::value_type value_type
Object type that the structure store.
Class for FAST cell list implementation.
CellList(CellDecomposer_sm< dim, T, transform > &cd_sm, const Box< dim, T > &box, const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor from a cell decomposer.
Iterator for the neighborhood of the cell structures.
Point< dim, T > getP2() const
Get the point p2.
void add(const Point< dim, T > &pos, typename base::value_type ele)
Add an element in the cell list.
void NNcalc(T r_cut, openfpm::vector< long int > &NNcell)