OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
33template<unsigned int dim, typename Cell,int NNc_size, unsigned int impl>
35{
36protected:
37
39 const typename Cell::Mem_type_type::local_index_type * start_id;
40
42 const typename Cell::Mem_type_type::local_index_type * stop_id;
43
45 size_t NNc_id;
46
48 const long int cell;
49
51 size_t cell_id;
52
54 Cell & cl;
55
58
62 __attribute__((always_inline)) inline void selectValid()
63 {
64 while (start_id == stop_id)
65 {
66 NNc_id++;
67
68 // No more Cell
69 if (NNc_id >= NNc_size) return;
70
72
73 start_id = &cl.getStartId(cell_id);
74 stop_id = &cl.getStopId(cell_id);
75 }
76 }
77
78private:
79
80
81public:
82
92 __attribute__((always_inline)) inline CellNNIterator(size_t cell, const NNc_array<dim,NNc_size> &NNc, Cell & cl)
94 {
95 start_id = &cl.getStartId(cell_id);
96 stop_id = &cl.getStopId(cell_id);
97 selectValid();
98 }
99
105 __attribute__((always_inline)) inline bool isNext()
106 {
107 if (NNc_id >= NNc_size)
108 return false;
109 return true;
110 }
111
117 __attribute__((always_inline)) inline CellNNIterator & operator++()
118 {
119 start_id++;
120
121 selectValid();
122
123 return *this;
124 }
125
131 __attribute__((always_inline)) inline const typename Cell::Mem_type_type::local_index_type & get()
132 {
133 return cl.get_lin(start_id);
134 }
135
141 __attribute__((always_inline)) inline const typename Cell::Mem_type_type::local_index_type & get() const
142 {
143 return cl.get_lin(start_id);
144 }
145};
146
147
164template<unsigned int dim, typename Cell, typename vector_pos_type,int NNc_size, unsigned int impl>
165class CellNNIteratorSym : public CellNNIterator<dim,Cell,NNc_size,impl>
166{
168 size_t p;
169
171 const vector_pos_type & v;
172
176 __attribute__((always_inline)) inline void selectValid()
177 {
178 if (this->NNc[this->NNc_id] == 0)
179 {
180 while (this->start_id < this->stop_id)
181 {
182 size_t q = this->cl.get_lin(this->start_id);
183 for (long int i = dim-1 ; i >= 0 ; i--)
184 {
185 if (v.template get<0>(p)[i] < v.template get<0>(q)[i])
186 return;
187 else if (v.template get<0>(p)[i] > v.template get<0>(q)[i])
188 goto next;
189 }
190 if (q >= p) return;
191next:
192 this->start_id++;
193 }
194
196 }
197 else
198 {
200 }
201 }
202
203public:
204
215 __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)
216 :CellNNIterator<dim,Cell,NNc_size,impl>(cell,NNc,cl),p(p),v(v)
217 {
218 selectValid();
219 }
220
221
228 {
229 this->start_id++;
230
231 selectValid();
232
233 return *this;
234 }
235};
236
253template<unsigned int dim, typename Cell, typename vector_pos_type , int NNc_size, unsigned int impl>
254class CellNNIteratorSymMP : public CellNNIterator<dim,Cell,NNc_size,impl>
255{
257 size_t p;
258
260 const vector_pos_type & v_p1;
261
263 const vector_pos_type & v_p2;
264
268 __attribute__((always_inline)) 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;
283next:
284 this->start_id++;
285 }
286
288 }
289 else
290 {
292 }
293 }
294
295public:
296
307 __attribute__((always_inline)) inline CellNNIteratorSymMP(size_t cell,
308 size_t p,
309 const NNc_array<dim,NNc_size> &NNc,
310 Cell & cl,
311 const vector_pos_type & v_p1,
312 const vector_pos_type & v_p2)
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
341template<typename Cell> class CellIterator
342{
344 Cell & cl;
345
347 size_t ele_id;
348
350 const long int cell;
351
352public:
353
360 __attribute__((always_inline)) inline CellIterator(const size_t cell, Cell & cl)
361 :cl(cl),ele_id(0),cell(cell)
362 {
363 }
364
370 __attribute__((always_inline)) inline bool isNext()
371 {
372 return cl.getNelements(cell) > ele_id;
373 }
374
380 __attribute__((always_inline)) inline CellIterator & operator++()
381 {
382 ele_id++;
383
384 return *this;
385 }
386
392 __attribute__((always_inline)) inline typename Cell::value_type & get()
393 {
394 return cl.get(cell,ele_id);
395 }
396
402 __attribute__((always_inline)) 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_ */
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 iterator for the neighborhood of the cell structures.
__attribute__((always_inline)) inline CellNNIteratorSymMP(size_t cell
Cell NN iterator.
__attribute__((always_inline)) inline CellNNIteratorSymMP< dim
take the next element
__attribute__((always_inline)) inline void selectValid()
size_t p
index of the particle p
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.
const vector_pos_type & v
Position of the particle p.
size_t p
index of the particle p
__attribute__((always_inline)) inline CellNNIteratorSym< dim
take the next element
__attribute__((always_inline)) inline void selectValid()
Iterator for the neighborhood of the cell structures.
Cell & cl
Cell list.
__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
__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_id
Actual NNc_id;.
__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.
__attribute__((always_inline)) inline CellNNIterator &operator++()
take the next element
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
__attribute__((always_inline)) inline void selectValid()
Select non-empty cell.