OpenFPM  5.2.0
Project that contain the implementation of distributed structures
CellNNIteratorRuntime.hpp
1 /*
2  * CellNNIteratorRuntime.hpp
3  *
4  * Created on: Nov 18, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIME_HPP_
9 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIME_HPP_
10 
11 #include "util/mathutil.hpp"
12 
13 #define FULL openfpm::math::pow(3,dim)
14 #define SYM openfpm::math::pow(3,dim)/2 + 1
15 #define CRS openfpm::math::pow(2,dim)
16 
17 #define RUNTIME -1
18 
31 template<unsigned int dim, typename Cell>
32 class CellNNIterator<dim,Cell,RUNTIME>
33 {
34 protected:
35 
37  const typename Cell::Mem_type_type::loc_index * start_id;
38 
40  const typename Cell::Mem_type_type::loc_index * stop_id;
41 
43  size_t NNc_id;
44 
46  size_t NNc_size;
47 
49  const long int cell;
50 
52  size_t cell_id;
53 
55  Cell & cl;
56 
58  const long int * NNc;
59 
63  __attribute__((always_inline)) inline void selectValid()
64  {
65  while (start_id == stop_id)
66  {
67  NNc_id++;
68 
69  // No more Cell
70  if (NNc_id >= NNc_size) return;
71 
72  cell_id = NNc[NNc_id] + cell;
73 
74  start_id = &cl.getStartId(cell_id);
75  stop_id = &cl.getStopId(cell_id);
76  }
77  }
78 
79 private:
80 
81 
82 public:
83 
94  __attribute__((always_inline)) inline CellNNIterator(size_t cell, const long int * NNc, size_t NNc_size, Cell & cl)
95  :NNc_id(0),NNc_size(NNc_size),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  __attribute__((always_inline)) inline bool isNext()
108  {
109  if (NNc_id >= NNc_size)
110  return false;
111  return true;
112  }
113 
119  __attribute__((always_inline)) inline CellNNIterator & operator++()
120  {
121  start_id++;
122 
123  selectValid();
124 
125  return *this;
126  }
127 
133  __attribute__((always_inline)) inline const typename Cell::Mem_type_type::loc_index & get()
134  {
135  return cl.get_lin(start_id);
136  }
137 };
138 
139 
155 template<unsigned int dim, typename Cell,typename vector_pos_type>
156 class CellNNIteratorSym<dim,Cell,vector_pos_type,RUNTIME> : public CellNNIterator<dim,Cell,RUNTIME>
157 {
159  size_t p;
160 
162  const vector_pos_type & v;
163 
167  __attribute__((always_inline)) inline void selectValid()
168  {
169  if (this->NNc[this->NNc_id] == 0)
170  {
171  while (this->start_id < this->stop_id)
172  {
173  size_t q = this->cl.get_lin(this->start_id);
174  for (long int i = dim-1 ; i >= 0 ; i--)
175  {
176  if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
177  return;
178  else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
179  goto next;
180  }
181  if (q >= p) return;
182 next:
183  this->start_id++;
184  }
185 
187  }
188  else
189  {
191  }
192  }
193 
194 public:
195 
206  __attribute__((always_inline)) inline CellNNIteratorSym(size_t cell,
207  size_t p,
208  const long int * NNc,
209  size_t NNc_size,
210  Cell & cl,
211  const vector_pos_type & v)
212  :CellNNIterator<dim,Cell,RUNTIME>(cell,NNc,NNc_size,cl),p(p),v(v)
213  {
214  if (this->NNc_id >= this->NNc_size)
215  return;
216 
217  selectValid();
218  }
219 
220 
227  {
228  this->start_id++;
229 
230  selectValid();
231 
232  return *this;
233  }
234 };
235 
236 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIME_HPP_ */
Symmetric iterator for the neighborhood of the cell structures.
const vector_pos_type & v
Position of the particle p.
__attribute__((always_inline)) inline CellNNIteratorSym(size_t cell
Cell NN iterator.
__attribute__((always_inline)) inline void selectValid()
__attribute__((always_inline)) inline CellNNIteratorSym< dim
take the next element
Symmetric iterator for the neighborhood of the cell structures.
size_t p
index of the particle p
const vector_pos_type & v
Position of the particle p.
const Cell::Mem_type_type::loc_index * stop_id
stop id to read the end of the cell
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
__attribute__((always_inline)) inline const typename Cell
Get the value of the cell.
const Cell::Mem_type_type::loc_index * start_id
actual element id
__attribute__((always_inline)) inline void selectValid()
Select non-empty cell.
__attribute__((always_inline)) inline bool isNext()
Check if there is the next element.
size_t cell_id
actual cell id = NNc[NNc_id]+cell stored for performance reason
size_t NNc_size
Size of the neighboring cells.
__attribute__((always_inline)) inline CellNNIterator &operator++()
take the next element
__attribute__((always_inline)) inline CellNNIterator(size_t cell
Cell NN iterator.
Iterator for the neighborhood of the cell structures.
const NNc_array< dim, NNc_size > & NNc
NN cell id.
const Cell::Mem_type_type::local_index_type * stop_id
stop id to read the end of the cell
size_t NNc_id
Actual NNc_id;.
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
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
Cell & cl
Cell list.