OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
CellNNIterator.hpp
1 /*
2  * CellNNIterator.hpp
3  *
4  * Created on: Mar 26, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef CELLNNITERATOR_FULL_HPP_
9 #define CELLNNITERATOR_FULL_HPP_
10 
11 #include "util/mathutil.hpp"
12 #include "NN/CellList/NNc_array.hpp"
13 
14 #define FULL openfpm::math::pow(3,dim)
15 #define SYM openfpm::math::pow(3,dim)/2 + 1
16 #define CRS openfpm::math::pow(2,dim)
17 
18 #define NO_CHECK 1
19 #define SAFE 2
20 
35 template<unsigned int dim, typename Cell,int NNc_size, unsigned int impl>
37 {
38 protected:
39 
41  const typename Cell::Mem_type_type::loc_index * start_id;
42 
44  const typename Cell::Mem_type_type::loc_index * stop_id;
45 
47  size_t NNc_id;
48 
50  const long int cell;
51 
53  size_t cell_id;
54 
56  Cell & cl;
57 
60 
64  inline void selectValid()
65  {
66  while (start_id == stop_id)
67  {
68  NNc_id++;
69 
70  // No more Cell
71  if (NNc_id >= NNc_size) return;
72 
73  cell_id = NNc[NNc_id] + cell;
74 
75  start_id = &cl.getStartId(cell_id);
76  stop_id = &cl.getStopId(cell_id);
77  }
78  }
79 
80 private:
81 
82 
83 public:
84 
94  inline CellNNIterator(size_t cell, const NNc_array<dim,NNc_size> &NNc, Cell & cl)
95  :NNc_id(0),cell(cell),cell_id(NNc[NNc_id] + cell),cl(cl),NNc(NNc)
96  {
97  start_id = &cl.getStartId(cell_id);
98  stop_id = &cl.getStopId(cell_id);
99  selectValid();
100  }
101 
107  inline bool isNext()
108  {
109  if (NNc_id >= NNc_size)
110  return false;
111  return true;
112  }
113 
120  {
121  start_id++;
122 
123  selectValid();
124 
125  return *this;
126  }
127 
133  inline const typename Cell::Mem_type_type::loc_index & get()
134  {
135  return cl.get_lin(start_id);
136  }
137 
143  inline const typename Cell::Mem_type_type::loc_index & get() const
144  {
145  return cl.get_lin(start_id);
146  }
147 };
148 
149 
166 template<unsigned int dim, typename Cell,int NNc_size, unsigned int impl> class CellNNIteratorSym : public CellNNIterator<dim,Cell,NNc_size,impl>
167 {
169  size_t p;
170 
173 
177  inline void selectValid()
178  {
179  if (this->NNc[this->NNc_id] == 0)
180  {
181  while (this->start_id < this->stop_id)
182  {
183  size_t q = this->cl.get_lin(this->start_id);
184  for (long int i = dim-1 ; i >= 0 ; i--)
185  {
186  if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
187  return;
188  else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
189  goto next;
190  }
191  if (q >= p) return;
192 next:
193  this->start_id++;
194  }
195 
197  }
198  else
199  {
201  }
202  }
203 
204 public:
205 
217  :CellNNIterator<dim,Cell,NNc_size,impl>(cell,NNc,cl),p(p),v(v)
218  {
219  selectValid();
220  }
221 
222 
229  {
230  this->start_id++;
231 
232  selectValid();
233 
234  return *this;
235  }
236 };
237 
254 template<unsigned int dim, typename Cell,int NNc_size, unsigned int impl> class CellNNIteratorSymMP : public CellNNIterator<dim,Cell,NNc_size,impl>
255 {
257  size_t p;
258 
261 
264 
268  inline void selectValid()
269  {
270  if (this->NNc[this->NNc_id] == 0)
271  {
272  while (this->start_id < this->stop_id)
273  {
274  size_t q = this->cl.get_lin(this->start_id);
275  for (long int i = dim-1 ; i >= 0 ; i--)
276  {
277  if (v_p1.template get<0>(p)[i] < v_p2.template get<0>(q)[i])
278  return;
279  else if (v_p1.template get<0>(p)[i] > v_p2.template get<0>(q)[i])
280  goto next;
281  }
282  if (q >= p) return;
283 next:
284  this->start_id++;
285  }
286 
288  }
289  else
290  {
292  }
293  }
294 
295 public:
296 
307  inline CellNNIteratorSymMP(size_t cell,
308  size_t p,
310  Cell & cl,
313  :CellNNIterator<dim,Cell,NNc_size,impl>(cell,NNc,cl),p(p),v_p1(v_p1),v_p2(v_p2)
314  {
315  selectValid();
316  }
317 
318 
325  {
326  this->start_id++;
327 
328  selectValid();
329 
330  return *this;
331  }
332 };
333 
341 template<typename Cell> class CellIterator
342 {
344  Cell & cl;
345 
347  size_t ele_id;
348 
350  const long int cell;
351 
352 public:
353 
360  inline CellIterator(const size_t cell, Cell & cl)
361  :cl(cl),ele_id(0),cell(cell)
362  {
363  }
364 
370  inline bool isNext()
371  {
372  return cl.getNelements(cell) > ele_id;
373  }
374 
381  {
382  ele_id++;
383 
384  return *this;
385  }
386 
392  inline typename Cell::value_type & get()
393  {
394  return cl.get(cell,ele_id);
395  }
396 
402  inline const typename Cell::value_type & get() const
403  {
404  return cl.get(cell,ele_id);
405  }
406 };
407 
408 #include "CellNNIteratorRuntime.hpp"
409 
410 #endif /* CELLNNITERATOR_FULL_HPP_ */
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
CellNNIteratorSymMP(size_t cell, size_t p, const NNc_array< dim, NNc_size > &NNc, Cell &cl, const openfpm::vector< Point< dim, typename Cell::stype >> &v_p1, const openfpm::vector< Point< dim, typename Cell::stype >> &v_p2)
Cell NN iterator.
CellNNIteratorSymMP< dim, Cell, NNc_size, impl > & operator++()
take the next element
const Cell::Mem_type_type::loc_index * stop_id
stop id to read the end of the cell
CellNNIterator & operator++()
take the next element
bool isNext()
Check if there is the next element.
const openfpm::vector< Point< dim, typename Cell::stype > > & v_p1
Phase vector for particle p.
size_t ele_id
actual element id inside the cell
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
CellIterator(const size_t cell, Cell &cl)
Cell iterator.
Symmetric iterator for the neighborhood of the cell structures.
Symmetric iterator for the neighborhood of the cell structures.
size_t p
index of the particle p
CellIterator & operator++()
take the next neoghborhood particle
const NNc_array< dim, NNc_size > & NNc
NN cell id.
size_t cell_id
actual cell id = NNc[NNc_id]+cell stored for performance reason
Cell & cl
Cell list.
const openfpm::vector< Point< dim, typename Cell::stype > > & v
Position of the particle p.
it iterate through the elements of a cell
size_t NNc_id
Actual NNc_id;.
bool isNext()
Check if there is the next element.
size_t p
index of the particle p
CellNNIteratorSym< dim, Cell, NNc_size, impl > & operator++()
take the next element
const Cell::Mem_type_type::loc_index * start_id
actual element id
const long int cell
selected cell
CellNNIterator(size_t cell, const NNc_array< dim, NNc_size > &NNc, Cell &cl)
Cell NN iterator.
void selectValid()
Select non-empty cell.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
Iterator for the neighborhood of the cell structures.
Cell & cl
Cell list.
const openfpm::vector< Point< dim, typename Cell::stype > > & v_p2
Phase vector for particle q.
CellNNIteratorSym(size_t cell, size_t p, const NNc_array< dim, NNc_size > &NNc, Cell &cl, const openfpm::vector< Point< dim, typename Cell::stype >> &v)
Cell NN iterator.