OpenFPM  5.2.0
Project that contain the implementation of distributed structures
VerletListM.hpp
1 /*
2  * VerletListM.hpp
3  *
4  * Created on: Oct 15, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLISTM_HPP_
9 #define OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLISTM_HPP_
10 
11 #include "NN/VerletList/VerletNNIteratorM.hpp"
12 #include "VerletList.hpp"
13 
14 
22 template<unsigned int dim,
23  typename T,
24  unsigned int sh_byte ,
25  typename CellListImpl=CellListM<dim,T,sh_byte>,
26  typename transform = shift<dim,T>,
27  typename vector_pos_type = openfpm::vector<Point<dim,T>>,
28  typename VerletBase=VerletList<dim,T,VL_NON_SYMMETRIC,Mem_fast<>,transform, vector_pos_type> >
29 class VerletListM : public VerletBase
30 {
31 
33  typedef boost::high_bit_mask_t<sh_byte> mask_high;
34 
36  typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
37 
50  inline void create(
51  const vector_pos_type & pos,
53  size_t pp,
54  T r_cut,
55  size_t ghostMarker,
56  CellListImpl & cl,
57  size_t opt)
58  {
59  if (opt == VL_CRS_SYMMETRIC)
60  {
63  createCRSSymmetric(pos,pos2,dom_c,anom_c,pp,r_cut,ghostMarker,cl,opt);
64  }
65  else if (opt == VL_SYMMETRIC)
66  {
67  createSymmetric(pos,pos2,pp,r_cut,ghostMarker,cl,opt);
68  }
69  else
70  {
71  createNonSymmetric(pos,pos2,pp,r_cut,ghostMarker,cl,opt);
72  }
73  }
74 
89  inline void createCRSSymmetric(
90  const vector_pos_type & pos,
92  const openfpm::vector<size_t> & dom,
93  const openfpm::vector<subsub_lin<dim>> & anom,
94  size_t pp,
95  T r_cut,
96  size_t ghostMarker,
97  CellListImpl & cli,
98  size_t opt)
99  {
100  size_t end = pos.size();
101 
102  this->init_to_zero(this->slot,end);
103 
104  // square of the cutting radius
105  T r_cut2 = r_cut * r_cut;
106 
107  auto it = ParticleItCRS_Cells<dim,CellListImpl,vector_pos_type>(cli,dom,anom,cli.getNNc_sym());
108  // iterate the particles
109  while (it.isNext())
110  {
111  size_t i = it.get();
112  Point<dim,T> xp = pos.template get<0>(i);
113 
114  // Get the neighborhood of the particle
115  auto NN = it.getNNIteratorCSRM(pos,pos2);
116 
117  while (NN.isNext())
118  {
119  size_t nnp = NN.getP();
120  size_t v = NN.getV();
121  size_t nnp_a = NN.get();
122 
123  Point<dim,T> xq = pos2.get(v).pos.template get<0>(nnp);
124 
125  if (xp.distance2(xq) < r_cut2)
126  this->addPart(i,nnp_a);
127 
128  // Next particle
129  ++NN;
130  }
131 
132  ++it;
133  }
134  }
135 
148  inline void createSymmetric(
149  const vector_pos_type & pos,
151  size_t pp,
152  T r_cut,
153  size_t ghostMarker,
154  CellListImpl & cli,
155  size_t opt)
156  {
157  size_t end = ghostMarker;
158  this->init_to_zero(this->slot,end);
159 
160  // square of the cutting radius
161  T r_cut2 = r_cut * r_cut;
162 
163  // iterate the particles
164  auto it = pos.getIteratorTo(end);
165  while (it.isNext())
166  {
167  size_t i = it.get();
168  Point<dim,T> xp = pos.template get<0>(i);
169 
170  // Get the neighborhood of the particle
171  auto NN = cli.getNNIteratorBoxSym(cli.getCell(xp),pp,i,pos,pos2);
172 
173  while (NN.isNext())
174  {
175  size_t nnp = NN.getP();
176  size_t v = NN.getV();
177  size_t nnp_a = NN.get();
178 
179  Point<dim,T> xq = pos2.get(v).pos.template get<0>(nnp);
180 
181  if (xp.distance2(xq) < r_cut2)
182  this->addPart(i,nnp_a);
183 
184  // Next particle
185  ++NN;
186  }
187 
188  ++it;
189  }
190  }
191 
204  inline void createNonSymmetric(
205  const vector_pos_type & pos,
207  size_t pp,
208  T r_cut,
209  size_t ghostMarker,
210  CellListImpl & cli,
211  size_t opt)
212  {
213  size_t end = ghostMarker;
214 
215  this->init_to_zero(this->slot,end);
216 
217  // square of the cutting radius
218  T r_cut2 = r_cut * r_cut;
219 
220  // iterate the particles
221  auto it = pos.getIteratorTo(end);
222  while (it.isNext())
223  {
224  size_t i = it.get();
225  Point<dim,T> xp = pos.template get<0>(i);
226 
227  // Get the neighborhood of the particle
228  auto NN = cli.getNNIteratorBox(cli.getCell(xp));
229 
230  while (NN.isNext())
231  {
232  size_t nnp = NN.getP();
233  size_t v = NN.getV();
234  size_t nnp_a = NN.get();
235 
236  Point<dim,T> xq = pos2.get(v).pos.template get<0>(nnp);
237 
238  if (xp.distance2(xq) < r_cut2)
239  this->addPart(i,nnp_a);
240 
241  // Next particle
242  ++NN;
243  }
244 
245  ++it;
246  }
247  }
248 
249 public:
250 
264  void Initialize(CellListImpl & cli, size_t pp,
265  T r_cut, const vector_pos_type & pos,
266  const openfpm::vector<struct pos_v<vector_pos_type>> & pos2, size_t ghostMarker,
267  size_t opt = VL_NON_SYMMETRIC)
268  {
269 // this->cl_n.resize(ghostMarker);
270 // this->cl_base.resize(ghostMarker*this->slot);
271 
272  Point<dim,T> spacing = cli.getCellBox().getP2();
273 
274  // Create with radius or not
275  bool wr = true;
276 
277  for (size_t i = 0 ; i < dim ; i++)
278  {wr &= r_cut <= spacing.get(i);}
279 
280  if (wr == true || opt == VL_SYMMETRIC)
281  {
282  create(pos,pos2,pp,r_cut,ghostMarker,cli,opt);
283  }
284  else
285  {
286  std::cerr << __FILE__ << ":" << __LINE__ << " error iterator with radius is not implemented yet " << std::endl;
287  }
288  }
289 
300  inline size_t getP(size_t part, size_t ele) const
301  {
302  return VerletBase::get(part,ele) & mask_low::sig_bits_fast;
303  }
304 
315  inline size_t getV(size_t part, size_t ele) const
316  {
317  return (VerletBase::get(part,ele)) >> (sizeof(size_t)*8-sh_byte);
318  }
319 
330  {
332 
333  return vln;
334  }
335 };
336 
337 
338 #endif /* OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLISTM_HPP_ */
VerletListM::Initialize
void Initialize(CellListImpl &cli, size_t pp, T r_cut, const vector_pos_type &pos, const openfpm::vector< struct pos_v< vector_pos_type >> &pos2, size_t ghostMarker, size_t opt=VL_NON_SYMMETRIC)
Definition: VerletListM.hpp:264
VerletListM::createSymmetric
void createSymmetric(const vector_pos_type &pos, const openfpm::vector< pos_v< vector_pos_type >> &pos2, size_t pp, T r_cut, size_t ghostMarker, CellListImpl &cli, size_t opt)
Create the Symmetric Verlet list from a given cell-list.
Definition: VerletListM.hpp:148
Point::distance2
T distance2(const Point< dim, T > &q) const
It calculate the square distance between 2 points.
Definition: Point.hpp:284
pos_v
Structure that contain a reference to a vector of particles.
Definition: CellList_util.hpp:20
VerletListM
Class for Verlet list implementation with Multiphase.
Definition: VerletListM.hpp:29
VerletListM::mask_high
boost::high_bit_mask_t< sh_byte > mask_high
Mask to get the high bits of a number.
Definition: VerletListM.hpp:33
VerletListM::createCRSSymmetric
void createCRSSymmetric(const vector_pos_type &pos, const openfpm::vector< pos_v< vector_pos_type >> &pos2, const openfpm::vector< size_t > &dom, const openfpm::vector< subsub_lin< dim >> &anom, size_t pp, T r_cut, size_t ghostMarker, CellListImpl &cli, size_t opt)
Create the CRS Symmetric Verlet list from a given cell-list.
Definition: VerletListM.hpp:89
ele
Definition: vector_performance_test.cu:159
ParticleItCRS_Cells
This iterator iterate across the particles of a Cell-list following the Cell structure.
Definition: ParticleItCRS_Cells.hpp:52
Point::get
__device__ const __host__ T & get(unsigned int i) const
Get coordinate.
Definition: Point.hpp:172
openfpm::vector
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:203
VerletListM::mask_low
boost::low_bits_mask_t< sizeof(size_t) *8-sh_byte > mask_low
Mask to get the low bits of a number.
Definition: VerletListM.hpp:36
VerletListM::createNonSymmetric
void createNonSymmetric(const vector_pos_type &pos, const openfpm::vector< pos_v< vector_pos_type >> &pos2, size_t pp, T r_cut, size_t ghostMarker, CellListImpl &cli, size_t opt)
Create the Non-symmetric Verlet list from a given cell-list.
Definition: VerletListM.hpp:204
VerletListM::getNNIterator
VerletNNIteratorM< dim, VerletListM< dim, T, sh_byte, CellListImpl, transform, vector_pos_type, VerletBase >, sh_byte > getNNIterator(size_t part_id)
Get the Neighborhood iterator.
Definition: VerletListM.hpp:329
VerletListM::getV
size_t getV(size_t part, size_t ele) const
Get the element vector in the cell.
Definition: VerletListM.hpp:315
CellListM
Class for Multi-Phase cell-list.
Definition: CellListM.hpp:51
VerletListM::create
void create(const vector_pos_type &pos, const openfpm::vector< pos_v< vector_pos_type >> &pos2, size_t pp, T r_cut, size_t ghostMarker, CellListImpl &cl, size_t opt)
Create the Verlet list from a given cell-list.
Definition: VerletListM.hpp:50
subsub_lin
Linearized version of subsub.
Definition: ParticleItCRS_Cells.hpp:36
VerletListM::getP
size_t getP(size_t part, size_t ele) const
Get the element-id in the cell.
Definition: VerletListM.hpp:300
VerletNNIteratorM
Iterator for the neighborhood of the cell structures.
Definition: VerletNNIteratorM.hpp:24
shift
Definition: CellDecomposer.hpp:27
VerletList
Class for Verlet list implementation.
Definition: VerletList.hpp:268
Point
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27