OpenFPM_pdata  4.1.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 
32 template<unsigned int dim, typename Cell,unsigned int impl>
33 class CellNNIterator<dim,Cell,RUNTIME,impl>
34 {
35 protected:
36 
38  const typename Cell::Mem_type_type::loc_index * start_id;
39 
41  const typename Cell::Mem_type_type::loc_index * stop_id;
42 
44  size_t NNc_id;
45 
47  size_t NNc_size;
48 
50  const long int cell;
51 
53  size_t cell_id;
54 
56  Cell & cl;
57 
59  const long int * NNc;
60 
64  __attribute__((always_inline)) 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 
95  __attribute__((always_inline)) inline CellNNIterator(size_t cell, const long int * NNc, size_t NNc_size, Cell & cl)
96  :NNc_id(0),NNc_size(NNc_size),cell(cell),cell_id(NNc[NNc_id] + cell),cl(cl),NNc(NNc)
97  {
98  start_id = &cl.getStartId(cell_id);
99  stop_id = &cl.getStopId(cell_id);
100  selectValid();
101  }
102 
108  __attribute__((always_inline)) inline bool isNext()
109  {
110  if (NNc_id >= NNc_size)
111  return false;
112  return true;
113  }
114 
120  __attribute__((always_inline)) inline CellNNIterator & operator++()
121  {
122  start_id++;
123 
124  selectValid();
125 
126  return *this;
127  }
128 
134  __attribute__((always_inline)) inline const typename Cell::Mem_type_type::loc_index & get()
135  {
136  return cl.get_lin(start_id);
137  }
138 };
139 
140 
157 template<unsigned int dim, typename Cell,typename vector_pos_type, unsigned int impl>
158 class CellNNIteratorSym<dim,Cell,vector_pos_type,RUNTIME,impl> : public CellNNIterator<dim,Cell,RUNTIME,impl>
159 {
161  size_t p;
162 
164  const vector_pos_type & v;
165 
169  __attribute__((always_inline)) inline void selectValid()
170  {
171  if (this->NNc[this->NNc_id] == 0)
172  {
173  while (this->start_id < this->stop_id)
174  {
175  size_t q = this->cl.get_lin(this->start_id);
176  for (long int i = dim-1 ; i >= 0 ; i--)
177  {
178  if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
179  return;
180  else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
181  goto next;
182  }
183  if (q >= p) return;
184 next:
185  this->start_id++;
186  }
187 
189  }
190  else
191  {
193  }
194  }
195 
196 public:
197 
208  __attribute__((always_inline)) inline CellNNIteratorSym(size_t cell,
209  size_t p,
210  const long int * NNc,
211  size_t NNc_size,
212  Cell & cl,
213  const vector_pos_type & v)
214  :CellNNIterator<dim,Cell,RUNTIME,impl>(cell,NNc,NNc_size,cl),p(p),v(v)
215  {
216  if (this->NNc_id >= this->NNc_size)
217  return;
218 
219  selectValid();
220  }
221 
222 
228  __attribute__((always_inline)) inline CellNNIteratorSym<dim,Cell,vector_pos_type,RUNTIME,impl> & operator++()
229  {
230  this->start_id++;
231 
232  selectValid();
233 
234  return *this;
235  }
236 };
237 
238 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIME_HPP_ */
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
size_t cell_id
actual cell id = NNc[NNc_id]+cell stored for performance reason
Symmetric iterator for the neighborhood of the cell structures.
const Cell::Mem_type_type::loc_index * stop_id
stop id to read the end of the cell
const Cell::Mem_type_type::loc_index * start_id
actual element id
const Cell::Mem_type_type::local_index_type * start_id
actual element id
Symmetric iterator for the neighborhood of the cell structures.
size_t p
index of the particle p
size_t cell_id
actual cell id = NNc[NNc_id]+cell stored for performance reason
__attribute__((always_inline)) inline const typename Cell
Get the value of the cell.
const NNc_array< dim, NNc_size > & NNc
NN cell id.
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
const vector_pos_type & v
Position of the particle p.
size_t NNc_size
Size of the neighboring cells.
__attribute__((always_inline)) inline void selectValid()
size_t NNc_id
Actual NNc_id;.
__attribute__((always_inline)) inline void selectValid()
Select non-empty cell.
const vector_pos_type & v
Position of the particle p.
__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
Iterator for the neighborhood of the cell structures.
__attribute__((always_inline)) inline void selectValid()
Select non-empty cell.
Cell & cl
Cell list.
__attribute__((always_inline)) inline bool isNext()
Check if there is the next element.