OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 NO_CHECK 1
18 #define SAFE 2
19 
20 #define RUNTIME -1
21 
35 template<unsigned int dim, typename Cell,unsigned int impl>
36 class CellNNIterator<dim,Cell,RUNTIME,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  size_t NNc_size;
51 
53  const long int cell;
54 
56  size_t cell_id;
57 
59  Cell & cl;
60 
62  const long int * NNc;
63 
67  inline void selectValid()
68  {
69  while (start_id == stop_id)
70  {
71  NNc_id++;
72 
73  // No more Cell
74  if (NNc_id >= NNc_size) return;
75 
76  cell_id = NNc[NNc_id] + cell;
77 
78  start_id = &cl.getStartId(cell_id);
79  stop_id = &cl.getStopId(cell_id);
80  }
81  }
82 
83 private:
84 
85 
86 public:
87 
98  inline CellNNIterator(size_t cell, const long int * NNc, size_t NNc_size, Cell & cl)
99  :NNc_id(0),NNc_size(NNc_size),cell(cell),cell_id(NNc[NNc_id] + cell),cl(cl),NNc(NNc)
100  {
101  start_id = &cl.getStartId(cell_id);
102  stop_id = &cl.getStopId(cell_id);
103  selectValid();
104  }
105 
111  inline bool isNext()
112  {
113  if (NNc_id >= NNc_size)
114  return false;
115  return true;
116  }
117 
124  {
125  start_id++;
126 
127  selectValid();
128 
129  return *this;
130  }
131 
137  inline const typename Cell::Mem_type_type::loc_index & get()
138  {
139  return cl.get_lin(start_id);
140  }
141 };
142 
143 
160 template<unsigned int dim, typename Cell,unsigned int impl>
161 class CellNNIteratorSym<dim,Cell,RUNTIME,impl> : public CellNNIterator<dim,Cell,RUNTIME,impl>
162 {
164  size_t p;
165 
168 
172  inline void selectValid()
173  {
174  if (this->NNc[this->NNc_id] == 0)
175  {
176  while (this->start_id < this->stop_id)
177  {
178  size_t q = this->cl.get_lin(this->start_id);
179  for (long int i = dim-1 ; i >= 0 ; i--)
180  {
181  if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
182  return;
183  else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
184  goto next;
185  }
186  if (q >= p) return;
187 next:
188  this->start_id++;
189  }
190 
192  }
193  else
194  {
196  }
197  }
198 
199 public:
200 
211  inline CellNNIteratorSym(size_t cell,
212  size_t p,
213  const long int * NNc,
214  size_t NNc_size,
215  Cell & cl,
217  :CellNNIterator<dim,Cell,RUNTIME,impl>(cell,NNc,NNc_size,cl),p(p),v(v)
218  {
219  if (this->NNc_id >= this->NNc_size)
220  return;
221 
222  selectValid();
223  }
224 
225 
232  {
233  this->start_id++;
234 
235  selectValid();
236 
237  return *this;
238  }
239 };
240 
241 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIME_HPP_ */
CellNNIteratorSym(size_t cell, size_t p, const long int *NNc, size_t NNc_size, Cell &cl, const openfpm::vector< Point< dim, typename Cell::stype >> &v)
Cell NN iterator.
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
const Cell::Mem_type_type::loc_index * stop_id
stop id to read the end of the cell
const openfpm::vector< Point< dim, typename Cell::stype > > & v
Position of the particle p.
bool isNext()
Check if there is the next element.
const Cell::Mem_type_type::loc_index * stop_id
stop id to read the end of the cell
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
CellNNIteratorSym< dim, Cell, RUNTIME, impl > & operator++()
take the next element
const Cell::Mem_type_type::loc_index * start_id
actual element id
Symmetric iterator for the neighborhood of the cell structures.
CellNNIterator(size_t cell, const long int *NNc, size_t NNc_size, Cell &cl)
Cell NN iterator.
size_t p
index of the particle p
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
const openfpm::vector< Point< dim, typename Cell::stype > > & v
Position of the particle p.
const long int cell
Center cell, or cell for witch we are searching the NN-cell.
size_t NNc_size
Size of the neighboring cells.
size_t NNc_id
Actual NNc_id;.
Symmetric iterator for the neighborhood of the cell structures.
const Cell::Mem_type_type::loc_index * start_id
actual element id
CellNNIterator & operator++()
take the next element
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.