OpenFPM  5.2.0
Project that contain the implementation of distributed structures
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 
32 template<unsigned int dim, typename Cell,int NNc_size>
34 {
35 protected:
36 
38  const typename Cell::Mem_type_type::local_index_type * start_id;
39 
41  const typename Cell::Mem_type_type::local_index_type * stop_id;
42 
44  size_t NNc_id;
45 
47  const long int cell;
48 
50  size_t cell_id;
51 
53  Cell & cl;
54 
57 
61  __attribute__((always_inline)) inline void selectValid()
62  {
63  while (start_id == stop_id)
64  {
65  NNc_id++;
66 
67  // No more Cell
68  if (NNc_id >= NNc_size) return;
69 
70  cell_id = NNc[NNc_id] + cell;
71 
72  start_id = &cl.getStartId(cell_id);
73  stop_id = &cl.getStopId(cell_id);
74  }
75  }
76 
77 private:
78 
79 
80 public:
81 
91  __attribute__((always_inline)) inline CellNNIterator(size_t cell, const NNc_array<dim,NNc_size> &NNc, Cell & cl)
93  {
94  start_id = &cl.getStartId(cell_id);
95  stop_id = &cl.getStopId(cell_id);
96  selectValid();
97  }
98 
104  __attribute__((always_inline)) inline bool isNext()
105  {
106  if (NNc_id >= NNc_size)
107  return false;
108  return true;
109  }
110 
116  __attribute__((always_inline)) inline CellNNIterator & operator++()
117  {
118  start_id++;
119 
120  selectValid();
121 
122  return *this;
123  }
124 
130  __attribute__((always_inline)) inline const typename Cell::Mem_type_type::local_index_type & get()
131  {
132  return cl.get_lin(start_id);
133  }
134 
140  __attribute__((always_inline)) inline const typename Cell::Mem_type_type::local_index_type & get() const
141  {
142  return cl.get_lin(start_id);
143  }
144 };
145 
146 
162 template<unsigned int dim, typename Cell, typename vector_pos_type,int NNc_size>
164 {
166  size_t p;
167 
169  const vector_pos_type & v;
170 
172  const typename Cell::Mem_type_type::local_index_type * start_id;
173 
175  const typename Cell::Mem_type_type::local_index_type * stop_id;
176 
178  size_t NNc_id;
179 
181  const long int cell;
182 
184  size_t cell_id;
185 
187  Cell & cl;
188 
191 
195  __attribute__((always_inline)) inline void IterateOwnCell()
196  {
197  while (start_id < stop_id)
198  {
199 
200  size_t q = cl.get_lin(start_id);
201 
202  for (long int i = dim-1 ; i >= 0 ; i--)
203  {
204  if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
205  return;
206  else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
207  goto next;
208  }
209 
210  if (q >= p)
211  return;
212 next:
213  start_id++;
214  }
215  }
216 
217 
221  __attribute__((always_inline)) inline void selectValid()
222  {
223  if (NNc[NNc_id] == 0)
224  IterateOwnCell();
225 
226  while (start_id == stop_id)
227  {
228  // No more Cell
229  if (++NNc_id >= NNc_size) return;
230 
231  cell_id = NNc[NNc_id] + cell;
232 
233  if (NNc[NNc_id] == 0)
234  {
235  start_id = &(cl.getStartId(cell_id));
236  stop_id = &(cl.getStopId(cell_id));
237  IterateOwnCell();
238 
239  } else if (NNc[NNc_id] < 0) {
240  start_id = &(cl.getGhostId(cell_id));
241  stop_id = &(cl.getStopId(cell_id));
242  } else {
243  start_id = &(cl.getStartId(cell_id));
244  stop_id = &(cl.getStopId(cell_id));
245  }
246  }
247  }
248 
249 public:
250  __attribute__((always_inline)) inline const typename Cell::Mem_type_type::local_index_type & get()
251  {
252  return cl.get_lin(start_id);
253  }
254 
260  __attribute__((always_inline)) inline const typename Cell::Mem_type_type::local_index_type & get() const
261  {
262  return cl.get_lin(start_id);
263  }
264 
265 
276  __attribute__((always_inline)) inline CellNNIteratorSymLocal(size_t cell, size_t p,
277  const NNc_array<dim,NNc_size> &NNc, Cell & cl,
278  const vector_pos_type & v)
279  : NNc_id(0),cell(cell),
280  cell_id(NNc[NNc_id] + cell),
281  cl(cl),NNc(NNc),
282  p(p),v(v)
283  {
284  if (NNc[NNc_id] < 0) {
285  start_id = &(cl.getGhostId(cell_id));
286  stop_id = &(cl.getStopId(cell_id));
287  } else {
288  start_id = &(cl.getStartId(cell_id));
289  stop_id = &(cl.getStopId(cell_id));
290  }
291 
292  selectValid();
293  }
294 
301  {
302  start_id++;
303 
304  selectValid();
305 
306  return *this;
307  }
308 
314  __attribute__((always_inline)) inline bool isNext()
315  {
316  if (NNc_id >= NNc_size)
317  return false;
318  return true;
319  }
320 };
321 
337 template<unsigned int dim, typename Cell, typename vector_pos_type,int NNc_size>
338 class CellNNIteratorSym : public CellNNIterator<dim,Cell,NNc_size>
339 {
341  size_t p;
342 
344  const vector_pos_type & v;
345 
349  __attribute__((always_inline)) inline void selectValid()
350  {
351  if (this->NNc[this->NNc_id] == 0)
352  {
353  while (this->start_id < this->stop_id)
354  {
355  size_t q = this->cl.get_lin(this->start_id);
356  for (long int i = dim-1 ; i >= 0 ; i--)
357  {
358  if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
359  return;
360  else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
361  goto next;
362  }
363  if (q >= p) return;
364 next:
365  this->start_id++;
366  }
367 
369  }
370  else
371  {
373  }
374  }
375 
376 public:
377 
388  __attribute__((always_inline)) inline CellNNIteratorSym(size_t cell, size_t p, const NNc_array<dim,NNc_size> &NNc, Cell & cl, const vector_pos_type & v)
389  :CellNNIterator<dim,Cell,NNc_size>(cell,NNc,cl),p(p),v(v)
390  {
391  selectValid();
392  }
393 
394 
401  {
402  this->start_id++;
403 
404  selectValid();
405 
406  return *this;
407  }
408 };
409 
425 template<unsigned int dim, typename Cell, typename vector_pos_type , int NNc_size>
426 class CellNNIteratorSymMP : public CellNNIterator<dim,Cell,NNc_size>
427 {
429  size_t p;
430 
432  const vector_pos_type & v_p1;
433 
435  const vector_pos_type & v_p2;
436 
440  __attribute__((always_inline)) inline void selectValid()
441  {
442  if (this->NNc[this->NNc_id] == 0)
443  {
444  while (this->start_id < this->stop_id)
445  {
446  size_t q = this->cl.get_lin(this->start_id);
447  for (long int i = dim-1 ; i >= 0 ; i--)
448  {
449  if (v_p1.template get<0>(p)[i] < v_p2.template get<0>(q)[i])
450  return;
451  else if (v_p1.template get<0>(p)[i] > v_p2.template get<0>(q)[i])
452  goto next;
453  }
454  if (q >= p) return;
455 next:
456  this->start_id++;
457  }
458 
460  }
461  else
462  {
464  }
465  }
466 
467 public:
468 
479  __attribute__((always_inline)) inline CellNNIteratorSymMP(size_t cell,
480  size_t p,
481  const NNc_array<dim,NNc_size> &NNc,
482  Cell & cl,
483  const vector_pos_type & v_p1,
484  const vector_pos_type & v_p2)
485  :CellNNIterator<dim,Cell,NNc_size>(cell,NNc,cl),p(p),v_p1(v_p1),v_p2(v_p2)
486  {
487  selectValid();
488  }
489 
490 
497  {
498  this->start_id++;
499 
500  selectValid();
501 
502  return *this;
503  }
504 };
505 
513 template<typename Cell> class CellIterator
514 {
516  Cell & cl;
517 
519  size_t ele_id;
520 
522  const long int cell;
523 
524 public:
525 
532  __attribute__((always_inline)) inline CellIterator(const size_t cell, Cell & cl)
533  :cl(cl),ele_id(0),cell(cell)
534  {
535  }
536 
542  __attribute__((always_inline)) inline bool isNext()
543  {
544  return cl.getNelements(cell) > ele_id;
545  }
546 
552  __attribute__((always_inline)) inline CellIterator & operator++()
553  {
554  ele_id++;
555 
556  return *this;
557  }
558 
564  __attribute__((always_inline)) inline typename Cell::value_type & get()
565  {
566  return cl.get(cell,ele_id);
567  }
568 
574  __attribute__((always_inline)) inline const typename Cell::value_type & get() const
575  {
576  return cl.get(cell,ele_id);
577  }
578 };
579 
580 #include "NN/CellList/CellNNIteratorRuntime.hpp"
581 
582 #endif /* CELLNNITERATOR_FULL_HPP_ */
it iterate through the elements of a cell
Cell & cl
Cell list.
__attribute__((always_inline)) inline bool isNext()
Check if there is the next element.
__attribute__((always_inline)) inline CellIterator(const size_t cell
Cell iterator.
__attribute__((always_inline)) inline CellIterator &operator++()
take the next neoghborhood particle
const long int cell
selected cell
__attribute__((always_inline)) inline typename Cell
Get the value of the cell.
size_t ele_id
actual element id inside the cell
Symmetric local iterator for the neighborhood of the cell structures.
const Cell::Mem_type_type::local_index_type * start_id
actual element id
size_t cell_id
actual cell id = NNc[NNc_id]+cell stored for performance reason
__attribute__((always_inline)) inline void selectValid()
size_t p
index of the particle p
__attribute__((always_inline)) inline void IterateOwnCell()
__attribute__((always_inline)) inline const typename Cell
Get the value of the cell.
const Cell::Mem_type_type::local_index_type * stop_id
stop id to read the end of the cell
const vector_pos_type & v
Position of the particle p.
__attribute__((always_inline)) inline bool isNext()
Check if there is the next element.
size_t NNc_id
Actual NNc_id;.
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
const NNc_array< dim, NNc_size > & NNc
NN cell id.
__attribute__((always_inline)) inline CellNNIteratorSymLocal< dim
take the next element
Symmetric iterator for the neighborhood of the cell structures.
size_t p
index of the particle p
__attribute__((always_inline)) inline CellNNIteratorSymMP< dim
take the next element
__attribute__((always_inline)) inline void selectValid()
__attribute__((always_inline)) inline CellNNIteratorSymMP(size_t cell
Cell NN iterator.
const vector_pos_type & v_p1
Phase vector for particle p.
const vector_pos_type & v_p2
Phase vector for particle q.
Symmetric iterator for the neighborhood of the cell structures.
__attribute__((always_inline)) inline CellNNIteratorSym(size_t cell
Cell NN iterator.
size_t p
index of the particle p
__attribute__((always_inline)) inline CellNNIteratorSym< dim
take the next element
const vector_pos_type & v
Position of the particle p.
__attribute__((always_inline)) inline void selectValid()
Iterator for the neighborhood of the cell structures.
const NNc_array< dim, NNc_size > & NNc
NN cell id.
__attribute__((always_inline)) inline CellNNIterator &operator++()
take the next element
const Cell::Mem_type_type::local_index_type * stop_id
stop id to read the end of the cell
__attribute__((always_inline)) inline void selectValid()
Select non-empty cell.
size_t NNc_id
Actual NNc_id;.
__attribute__((always_inline)) inline const typename Cell
Get the value of the cell.
const Cell::Mem_type_type::local_index_type * start_id
actual element id
size_t cell_id
actual cell id = NNc[NNc_id]+cell stored for performance reason
__attribute__((always_inline)) inline bool isNext()
Check if there is the next element.
__attribute__((always_inline)) inline CellNNIterator(size_t cell
Cell NN iterator.
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
Cell & cl
Cell list.