1 #ifndef OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLIST_HPP_
2 #define OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLIST_HPP_
4 #include "Vector/map_vector.hpp"
6 #include "VerletNNIterator.hpp"
7 #include "NN/CellList/CellList.hpp"
8 #include "NN/CellList/CellList_util.hpp"
9 #include "NN/Mem_type/MemFast.hpp"
10 #include "NN/Mem_type/MemBalanced.hpp"
11 #include "NN/Mem_type/MemMemoryWise.hpp"
15 constexpr
int VL_NON_SYMMETRIC = 1;
16 constexpr
int VL_SYMMETRIC = 2;
17 constexpr
int VL_CRS_SYMMETRIC = 4;
18 constexpr
int VL_ADAPTIVE_RCUT = 8;
19 constexpr
int VL_NMAX_NEIGHBOR = 16;
20 constexpr
int VL_SKIP_REF_PART = 32;
22 constexpr
int VERLET_STARTING_NSLOT = 128;
25 typedef size_t local_index_;
27 typedef unsigned int local_index_;
39 template<
bool isNMax,
bool skipRefPart>
60 template<
typename NeighborIter_type,
typename VerletList_type,
typename vPos_type,
unsigned int dim,
typename T>
61 inline void operator() (
62 VerletList_type& verletList,
63 NeighborIter_type & it,
64 const vPos_type & pos,
66 T r_cut,
size_t neighborMaxNum)
68 T r_cut2 = r_cut * r_cut;
77 verletList.addPart(p,q);
103 template<
typename NeighborIter_type,
typename VerletList_type,
typename vPos_type,
unsigned int dim,
typename T>
104 inline void operator() (
105 VerletList_type& verletList,
106 NeighborIter_type & it,
107 const vPos_type & pos,
109 T r_cut,
size_t neighborMaxNum)
111 T r_cut2 = r_cut * r_cut;
119 if (xp.
distance2(xq) < r_cut2 && p != q) {
120 verletList.addPart(p,q);
145 template<
typename NeighborIter_type,
typename VerletList_type,
typename vPos_type,
unsigned int dim,
typename T>
146 inline void operator() (
147 VerletList_type& verletList,
148 NeighborIter_type & it,
149 const vPos_type & pos,
151 T r_cut,
size_t neighborMaxNum)
156 bool operator<(
const ReorderType &other)
const {
return this->dist < other.dist; }
168 ReorderType qReorder;
171 neighborList.add(qReorder);
178 for(
size_t i = 0; i < neighborList.
size(); ++i) {
179 if (i < neighborMaxNum)
180 verletList.addPart(p, neighborList.get(i).id);
204 template<
typename NeighborIter_type,
typename VerletList_type,
typename vPos_type,
unsigned int dim,
typename T>
205 inline void operator() (
206 VerletList_type& verletList,
207 NeighborIter_type & it,
208 const vPos_type & pos,
210 T r_cut,
size_t neighborMaxNum)
215 bool operator<(
const ReorderType &other)
const {
return this->dist < other.dist; }
227 ReorderType qReorder;
230 neighborList.add(qReorder);
237 for(
size_t i = 0; i < neighborList.
size(); ++i) {
238 if (i < neighborMaxNum && p != neighborList.get(i).id)
239 verletList.addPart(p, neighborList.get(i).id);
261 template<
unsigned int dim,
263 unsigned int opt = VL_NON_SYMMETRIC,
273 typename Mem_type::local_index_type
slot;
311 if (opt & VL_SYMMETRIC || opt & VL_CRS_SYMMETRIC)
316 cellList.fill(vPos, vPropStub, ghostMarker);
332 const vPos_type & pos,
338 size_t end = pos.size();
340 Mem_type::init_to_zero(
slot,end);
347 typename Mem_type::local_index_type p = it.get();
353 auto NN = it.getNNIteratorCSR(pos);
371 const vPos_type & pos,
376 size_t end = ghostMarker;
378 Mem_type::init_to_zero(
slot,end);
382 auto it = pos.getIteratorTo(end);
385 typename Mem_type::local_index_type p = it.get();
407 const vPos_type & pos,
412 size_t end = ghostMarker;
414 Mem_type::init_to_zero(
slot,end);
417 auto it = pos.getIteratorTo(end);
420 typename Mem_type::local_index_type p = it.get();
442 template <
typename domainIterator_type>
444 domainIterator_type& it,
445 const vPos_type & pos,
450 fillNonSymmetricIterator<domainIterator_type>(it, pos, pos, r_cut, ghostMarker,
cellList);
465 template <
typename domainIterator_type,
typename vPos_type2>
467 domainIterator_type& it,
468 const vPos_type2 & domainPos,
469 const vPos_type & supportPos,
474 size_t end = ghostMarker;
476 Mem_type::init_to_zero(
slot,end);
480 typename Mem_type::local_index_type p = it.get();
505 const vPos_type & pos,
510 std::cerr << __FILE__ <<
":" << __LINE__
511 <<
" ERROR: when constructing adaptive cut-off Verlet list, pos.size() != rCuts.size(), ["
512 <<
rCuts.
size() <<
"!=" << pos.size() <<
"]" << std::endl;
513 std::runtime_error(
"Runtime adaptive cut-off Verlet list error");
521 for (
size_t i = 0; i <
rCuts.
size(); ++i)
522 if (
rCuts.get(i) > rCutMax)
523 rCutMax =
rCuts.get(i);
538 Mem_type::init_to_zero(
slot,ghostMarker);
541 auto it = pos.getIteratorTo(ghostMarker);
544 typename Mem_type::local_index_type p = it.get();
567 template <
typename domainIterator_type,
typename vPos_type2>
569 domainIterator_type& it,
570 const vPos_type2 & domainPos,
571 const vPos_type & supportPos,
577 std::cerr << __FILE__ <<
":" << __LINE__
578 <<
" ERROR: when constructing adaptive cut-off Verlet list, pos.size_local() != rCuts.size(), ["
579 <<
rCuts.
size() <<
"!=" << domainPos.size_local() <<
"]" << std::endl;
580 std::runtime_error(
"Runtime adaptive cut-off Verlet list error");
583 size_t end = ghostMarker;
585 Mem_type::init_to_zero(
slot,end);
590 typename Mem_type::local_index_type p = it.get();
595 auto NN = supportPos.getIteratorTo(supportPos.size_local());
596 T r_cut =
rCuts.get(p);
614 const vPos_type & pos,
619 size_t end = ghostMarker;
621 Mem_type::init_to_zero(
slot,end);
624 auto it = pos.getIteratorTo(end);
627 typename Mem_type::local_index_type p = it.get();
651 return Mem_type::size();
662 Mem_type::addCell(p,q);
674 for (
size_t i = 0; i < buffer.
size(); i++)
676 Mem_type::addCell(p,buffer.get(i));
724 template <
typename domainIterator_type>
728 domainIterator_type& it,
729 const vPos_type& pos,
750 template <
typename domainIterator_type>
754 domainIterator_type& it,
755 const vPos_type& domainPos,
756 const vPos_type& supportPos,
790 CellDecomposer_sm<dim,T,shift<dim,T>> cd_sm;
793 cl_param_calculateSym<dim,T>(box,cd_sm,ghostSize,r_cut,pad);
829 CellDecomposer_sm<dim,T,shift<dim,T>> cd_sm;
832 cl_param_calculateSym<dim,T>(box,cd_sm,ghostSize,r_cut,pad);
851 size_t & ghostMarker)
855 if (opt & VL_SYMMETRIC)
874 size_t & ghostMarker,
884 :Mem_type(VERLET_STARTING_NSLOT),
slot(VERLET_STARTING_NSLOT),
n_dec(0)
889 :Mem_type(VERLET_STARTING_NSLOT),
slot(VERLET_STARTING_NSLOT)
896 :Mem_type(VERLET_STARTING_NSLOT),
slot(VERLET_STARTING_NSLOT),
n_dec(0)
912 :
slot(VERLET_STARTING_NSLOT),CellDecomposer_sm<dim,T,transform>(box,div,mat,box.getP1(),pad)
977 Mem_type::operator=(vl);
997 Mem_type::operator=(vl);
1016 return Mem_type::getNelements(p);
1027 inline size_t get(
size_t p,
size_t q)
const
1029 return Mem_type::get(p,q);
1042 size_t vl_slot_tmp = vl.
slot;
1048 size_t n_dec_tmp = vl.
n_dec;
1085 inline const typename Mem_type::local_index_type &
1088 return Mem_type::getStartId(p);
1098 inline const typename Mem_type::local_index_type &
1101 return Mem_type::getStopId(p);
1111 inline const typename Mem_type::local_index_type &
1112 get_lin(
const typename Mem_type::local_index_type * p)
1114 return Mem_type::get_lin(p);
1134 this->n_dec =
n_dec;
1211 return rCuts.get(p);
1218 void clear(
typename Mem_type::local_index_type p)
This class represent an N-dimensional box.
Class for FAST cell list implementation.
This class implement an NxN (dense) matrix.
This iterator iterate across the particles of a Cell-list following the Cell structure.
This class implement the point shape in an N-dimensional space.
__device__ __host__ T distance(const Point< dim, T > &q) const
It calculate the distance between 2 points.
T distance2(const Point< dim, T > &q) const
It calculate the square distance between 2 points.
Class for Verlet list implementation.
void initCl(CellListImpl &cellList, const vPos_type &vPos, size_t ghostMarker)
Fill the cell-list with data.
openfpm::vector< typename Mem_type::local_index_type > domainParticlesCRS
Domain particles.
VerletList(Box< dim, T > &box, T r_cut, Matrix< dim, T > mat, const size_t pad=1, size_t slot=STARTING_NSLOT)
Verlet-list constructor.
void updateCrs(vPos_type &pos, T r_cut, size_t &ghostMarker, const openfpm::vector< size_t > &dom_c, const openfpm::vector< subsub_lin< dim >> &anom_c)
update the Verlet list
openfpm::vector< typename Mem_type::local_index_type > & getParticleSeq()
Return the domain particle sequence.
void InitializeNonSymmAdaptive(const Box< dim, T > &box, openfpm::vector< T > &rCuts, const vPos_type &pos, size_t ghostMarker)
Initialize non-symmetric adaptive r-cut Verlet list from a list of cut-off radii.
void InitializeSym(const Box< dim, T > &box, const Box< dim, T > &dom, const Ghost< dim, T > &ghostSize, T r_cut, vPos_type &pos, size_t ghostMarker)
Initialize the symmetric Verlet-list.
void fillNonSymmetricIterator(domainIterator_type &it, const vPos_type2 &domainPos, const vPos_type &supportPos, T r_cut, size_t ghostMarker, CellListImpl &cellList)
Fill Non-symmetric Verlet list from a given cell-list.
Mem_type::local_index_type slot
Number of slot for each particle. Or maximum number of particles for each particle.
VerletNNIterator< dim, VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > > getNNIterator(size_t p)
Get the Neighborhood iterator.
void set_ndec(size_t n_dec)
Set the n_dec number.
const Mem_type::local_index_type & get_lin(const typename Mem_type::local_index_type *p)
Return the neighborhood id.
CellListImpl cellList
Internal cell-list.
VerletList(Box< dim, T > &box, T r_cut, vPos_type &pos, size_t ghostMarker, size_t slot=VERLET_STARTING_NSLOT)
Verlet-list constructor.
void swap(VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > &vl)
Swap the memory.
size_t getNNPart(size_t p) const
Return the number of neighborhood particles for the particle id.
VerletList(Box< dim, T > &box, Box< dim, T > &dom, T r_cut, vPos_type &pos, size_t ghostMarker, size_t slot=VERLET_STARTING_NSLOT)
Cell list constructor.
CellListImpl & getInternalCellList()
Get the internal cell-list used to construct the Verlet-list.
void update(const Box< dim, T > &dom, T r_cut, vPos_type &pos, size_t &ghostMarker)
update the Verlet list
openfpm::vector< T > rCuts
Cut-off radius vector.
VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > & operator=(const VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > &vl)
Copy a verlet list.
Mem_type Mem_type_type
type for the local index
void fillNonSymmetricRadius(const vPos_type &pos, T r_cut, size_t ghostMarker, CellListImpl &cellList)
Fill Non-symmetric Verlet list from a given cell-list (Radius)
void setNeighborMaxNum(size_t neighborMaxNum)
Sets the max number of neighbors per particle. Only with opt | VL_NMAX_NEIGHBOR.
VerletList(const VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > &cell)
Copy constructor.
void Initialize(CellListImpl &cellList, T r_cut, domainIterator_type &it, const vPos_type &domainPos, const vPos_type &supportPos, size_t ghostMarker)
const Mem_type::local_index_type & getStart(typename Mem_type::local_index_type p)
Return the starting point of the neighborhood for the particle p.
void fillNonSymmetricIterator(domainIterator_type &it, const vPos_type &pos, T r_cut, size_t ghostMarker, CellListImpl &cellList)
Fill Non-symmetric Verlet list from a given cell-list.
void initializeCrs(const Box< dim, T > &box, const Box< dim, T > &dom, const Ghost< dim, T > &ghostSize, T r_cut, vPos_type &pos, size_t ghostMarker)
Initialize the symmetric Verlet-list CRS scheme.
VerletList()
Default Constructor.
size_t size()
Return for how many particles has been constructed this verlet list.
void replaceNeighbParts(size_t p, const openfpm::vector< size_t > &buffer)
Replace the neighborhood particles for the particle id p with the given buffer.
VerletList(VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > &&cell)
Copy constructor.
void clear()
Clear the cell list.
void clear(typename Mem_type::local_index_type p)
Clear support of one particle in the verlet list.
size_t getNeighborMaxNum() const
Returns the max number of neighbors per particle. Only with opt | VL_NMAX_NEIGHBOR.
VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > & operator=(VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > &&vl)
Copy the verlet list.
size_t neighborMaxNum
Max number of Nieghbors. Only with opt |= VL_NMAX_NEIGHBOR.
void Initialize(CellListImpl &cellList, T r_cut, domainIterator_type &it, const vPos_type &pos, size_t ghostMarker)
void fillNonSymmAdaptiveIterator(domainIterator_type &it, const vPos_type2 &domainPos, const vPos_type &supportPos, openfpm::vector< T > &rCuts, size_t ghostMarker)
Fill non-symmetric adaptive r-cut Verlet list from a list of cut-off radii.
void Initialize(const Box< dim, T > &box, T r_cut, vPos_type &pos, size_t ghostMarker)
size_t get_ndec()
Set the n_dec number.
T getRCuts(size_t p)
Return the cut-off radii for individual particles.
size_t n_dec
decomposition counter
size_t value_type
Object type that the structure store.
void fillNonSymmetric(const vPos_type &pos, T r_cut, size_t ghostMarker, CellListImpl &cellList)
Fill Non-symmetric Verlet list from a given cell-list.
void fillSymmetric(const vPos_type &pos, T r_cut, size_t ghostMarker, CellListImpl &cellList)
Fill Symmetric Verlet list from a given cell-list.
void addPart(size_t p, size_t q)
Add a neighborhood particle to a particle.
size_t getOpt() const
Returns the option flag template parameter opt that controls the Verlet list.
void fillCRSSymmetric(const vPos_type &pos, T r_cut, size_t ghostMarker, const openfpm::vector< size_t > &dom, const openfpm::vector< subsub_lin< dim >> &anom)
Fill CRS Symmetric Verlet list from a given cell-list.
size_t get(size_t p, size_t q) const
Get the neighborhood element q for the particle p.
const Mem_type::local_index_type & getStop(typename Mem_type::local_index_type p)
Return the end point of the neighborhood for the particle p.
T getRCut()
Return the cut-off radius of the Verlet list.
Iterator for the neighborhood of the cell structures.
Implementation of 1-D std::vector like structure.
Linearized version of subsub.