OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 
24 template<unsigned int dim, typename T, typename CellListImpl, typename PartIt, int type>
25 struct NNTypeM
26 {
38  static inline auto get(const PartIt & it,
39  const openfpm::vector<Point<dim,T>> & pos,
41  Point<dim,T> & xp,
42  size_t pp,
43  size_t p,
44  CellListImpl & cl,
45  T r_cut) -> decltype(cl.template getNNIterator<NO_CHECK>(0))
46  {
47  return cl.template getNNIterator<NO_CHECK>(cl.getCell(xp));
48  }
49 };
50 
61 template<unsigned int dim, typename T, typename CellListImpl, typename PartIt>
62 struct NNTypeM<dim,T,CellListImpl,PartIt,VL_CRS_SYMMETRIC>
63 {
76  static inline auto get(const PartIt & it,
77  const openfpm::vector<Point<dim,T>> & pos,
79  Point<dim,T> & xp,
80  size_t pp,
81  size_t p,
82  CellListImpl & cl,
83  T r_cut) -> decltype(it.getNNIteratorCSRM(pos,v))
84  {
85  return it.getNNIteratorCSRM(pos,v);
86  }
87 };
88 
99 template<unsigned int dim, typename T, typename CellListImpl, typename PartIt>
100 struct NNTypeM<dim,T,CellListImpl,PartIt,VL_SYMMETRIC>
101 {
113  static inline auto get(const PartIt & it,
114  const openfpm::vector<Point<dim,T>> & pos,
115  const openfpm::vector<pos_v<dim,T>> & v,
116  Point<dim,T> & xp,
117  size_t pp,
118  size_t p,
119  CellListImpl & cl,
120  T r_cut) -> decltype(cl.template getNNIteratorSym<NO_CHECK>(0,0,0,openfpm::vector<Point<dim,T>>(),openfpm::vector<pos_v<dim,T>>()))
121  {
122  return cl.template getNNIteratorSym<NO_CHECK>(cl.getCell(xp),pp,p,pos,v);
123  }
124 };
125 
126 
127 
135 template<unsigned int dim,
136  typename T,
137  unsigned int sh_byte ,
138  typename CellListImpl=CellListM<dim,T,sh_byte>,
139  typename transform = shift<dim,T>,
140  typename VerletBase=VerletList<dim,T,Mem_fast<>,transform, size_t> >
141 class VerletListM : public VerletBase
142 {
143 
145  typedef boost::high_bit_mask_t<sh_byte> mask_high;
146 
148  typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
149 
162  inline void create(const openfpm::vector<Point<dim,T>> & pos,
163  const openfpm::vector<pos_v<dim,T>> & pos2 ,
164  const openfpm::vector<size_t> & dom,
165  const openfpm::vector<subsub_lin<dim>> & anom,
166  size_t pp,
167  T r_cut,
168  size_t g_m,
169  CellListImpl & cl,
170  size_t opt)
171  {
172  if (opt == VL_CRS_SYMMETRIC)
173  {
174  create_<CellNNIteratorSymM<dim,CellListImpl,sh_byte,RUNTIME,NO_CHECK>,VL_CRS_SYMMETRIC>(pos,pos2,dom,anom,pp,r_cut,g_m,cl,opt);
175  }
176  else if (opt == VL_SYMMETRIC)
177  {
178  create_<decltype(cl.template getNNIteratorSym<NO_CHECK>(0,0,0,pos,pos2)),VL_SYMMETRIC>(pos,pos2,dom,anom,pp,r_cut,g_m,cl,opt);
179  }
180  else
181  {
182  create_<decltype(cl.template getNNIterator<NO_CHECK>(0)),VL_NON_SYMMETRIC>(pos,pos2,dom,anom,pp,r_cut,g_m,cl,opt);
183  }
184  }
185 
200  template<typename NN_type, int type> inline void create_(const openfpm::vector<Point<dim,T>> & pos,
201  const openfpm::vector<pos_v<dim,T>> & pos2 ,
202  const openfpm::vector<size_t> & dom,
203  const openfpm::vector<subsub_lin<dim>> & anom,
204  size_t pp,
205  T r_cut,
206  size_t g_m,
207  CellListImpl & cli,
208  size_t opt)
209  {
210  size_t end;
211 
212  auto it = PartItNN<type,dim,openfpm::vector<Point<dim,T>>,CellListImpl>::get(pos,dom,anom,cli,g_m,end);
213 
214 /* this->cl_n.resize(end);
215  this->cl_base.resize(end*this->slot);
216  this->cl_n.fill(0);*/
217 
218  this->init_to_zero(this->slot,end);
219 
220  // square of the cutting radius
221  T r_cut2 = r_cut * r_cut;
222 
223  // iterate the particles
224  while (it.isNext())
225  {
226  size_t i = it.get();
227  Point<dim,T> xp = pos.template get<0>(i);
228 
229  // Get the neighborhood of the particle
230  NN_type NN = NNTypeM<dim,T,CellListImpl,decltype(it),type>::get(it,pos,pos2,xp,pp,i,cli,r_cut);
231 
232  while (NN.isNext())
233  {
234  size_t nnp = NN.getP();
235  size_t v = NN.getV();
236  size_t nnp_a = NN.get();
237 
238  Point<dim,T> xq = pos2.get(v).pos.template get<0>(nnp);
239 
240  if (xp.distance2(xq) < r_cut2)
241  this->addPart(i,nnp_a);
242 
243  // Next particle
244  ++NN;
245  }
246 
247  ++it;
248  }
249  }
250 
251 public:
252 
266  void Initialize(CellListImpl & cli, size_t pp, T r_cut, const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<struct pos_v<dim,T>> & pos2, size_t g_m, size_t opt = VL_NON_SYMMETRIC)
267  {
268 // this->cl_n.resize(g_m);
269 // this->cl_base.resize(g_m*this->slot);
270 
271  Point<dim,T> spacing = cli.getCellBox().getP2();
272 
273  // Create with radius or not
274  bool wr = true;
275 
276  for (size_t i = 0 ; i < dim ; i++)
277  {wr &= r_cut <= spacing.get(i);}
278 
279  if (wr == true || opt == VL_SYMMETRIC)
280  {
283 
284  create(pos,pos2,dom_c,anom_c,pp,r_cut,g_m,cli,opt);
285  }
286  else
287  {
288  std::cerr << __FILE__ << ":" << __LINE__ << " error iterator with radius is not implemented yet " << std::endl;
289  }
290  }
291 
302  inline size_t getP(size_t part, size_t ele) const
303  {
304  return VerletBase::get(part,ele) & mask_low::sig_bits_fast;
305  }
306 
317  inline size_t getV(size_t part, size_t ele) const
318  {
319  return (VerletBase::get(part,ele)) >> (sizeof(size_t)*8-sh_byte);
320  }
321 
331  template<unsigned int impl=NO_CHECK> inline VerletNNIteratorM<dim,VerletListM<dim,T,sh_byte,CellListImpl,transform,VerletBase>,sh_byte> getNNIterator(size_t part_id)
332  {
334 
335  return vln;
336  }
337 };
338 
339 
340 #endif /* OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLISTM_HPP_ */
Get the neighborhood iterator based on type.
Definition: VerletListM.hpp:25
Iterator for the neighborhood of the cell structures.
size_t getP(size_t part, size_t ele) const
Get the element-id in the cell.
Class for Verlet list implementation.
void create(const openfpm::vector< Point< dim, T >> &pos, const openfpm::vector< pos_v< dim, T >> &pos2, const openfpm::vector< size_t > &dom, const openfpm::vector< subsub_lin< dim >> &anom, size_t pp, T r_cut, size_t g_m, CellListImpl &cl, size_t opt)
Create the Verlet list from a given cell-list.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Structure that contain a reference to a vector of particles.
static auto get(const PartIt &it, const openfpm::vector< Point< dim, T >> &pos, const openfpm::vector< pos_v< dim, T >> &v, Point< dim, T > &xp, size_t pp, size_t p, CellListImpl &cl, T r_cut) -> decltype(cl.template getNNIterator< NO_CHECK >(0))
Get the neighborhood.
Definition: VerletListM.hpp:38
size_t getV(size_t part, size_t ele) const
Get the element vector in the cell.
Class for Verlet list implementation with Multiphase.
Class for Multi-Phase cell-list.
Definition: CellListM.hpp:53
const T & get(size_t i) const
Get coordinate.
Definition: Point.hpp:142
In general different NN scheme like full symmetric or CRS require different iterators over particles ...
boost::low_bits_mask_t< sizeof(size_t)*8-sh_byte > mask_low
Mask to get the low bits of a number.
void Initialize(CellListImpl &cli, size_t pp, T r_cut, const openfpm::vector< Point< dim, T >> &pos, const openfpm::vector< struct pos_v< dim, T >> &pos2, size_t g_m, size_t opt=VL_NON_SYMMETRIC)
void create_(const openfpm::vector< Point< dim, T >> &pos, const openfpm::vector< pos_v< dim, T >> &pos2, const openfpm::vector< size_t > &dom, const openfpm::vector< subsub_lin< dim >> &anom, size_t pp, T r_cut, size_t g_m, CellListImpl &cli, size_t opt)
Create the Verlet list from a given cell-list.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
Linearized version of subsub.
VerletNNIteratorM< dim, VerletListM< dim, T, sh_byte, CellListImpl, transform, VerletBase >, sh_byte > getNNIterator(size_t part_id)
Get the Neighborhood iterator.
boost::high_bit_mask_t< sh_byte > mask_high
Mask to get the high bits of a number.