OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_key_dx_iterator.hpp
1/*
2 * grid_key_dx_iterator.hpp
3 *
4 * Created on: Dec 15, 2015
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_HPP_
9#define OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_HPP_
10
11#include "Grid/grid_sm.hpp"
12#include "stencil_type.hpp"
13
27template<unsigned int dim, typename stencil=no_stencil, typename linearizer = grid_sm<dim,void>>
29{
30#ifdef SE_CLASS1
31 // Actual status of the iterator, when the iterator is not initialized cannot be used
32 // and reinitialize must be called
33 bool initialized = false;
34#endif
35
37 linearizer grid_base;
38
47 inline size_t get_gk(size_t i) const
48 {
49 return gk.get(i);
50 }
51
52protected:
53
56
59 stencil stl_code;
60
61public:
62
70 {
71#ifdef SE_CLASS1
72 initialized = false;
73#endif
74 }
75
81 : grid_base(g_it.grid_base)
82 {
84
85 for (size_t i = 0 ; i < dim ; i++)
86 {
87 gk.set_d(i,g_it.get_gk(i));
88 }
89
90 stl_code = g_it.stl_code;
91
92#ifdef SE_CLASS1
93 initialized = true;
94#endif
95 }
96
103 template<typename grid_lin>
104 grid_key_dx_iterator(const grid_lin & g,
105 const grid_key_dx<dim> (& stencil_pnt)[stencil::nsp])
106 :grid_base(g)
107 {
108 reset();
109
110 grid_key_dx<dim> zero;
111 for (size_t i = 0 ; i < dim ; i++) {zero.set_d(i,0);}
112
113 // calculate the offsets for the stencil code
114 stl_code.calc_offsets(g,zero,stencil_pnt);
115
116#ifdef SE_CLASS1
117 initialized = true;
118#endif
119 }
120
128 grid_key_dx_iterator(const grid_key_dx<dim> (& stencil_pnt)[stencil::nsp])
129 {
130 // calculate the offsets for the stencil code
131 stl_code.set_stencil(stencil_pnt);
132 }
133
138 grid_key_dx_iterator(const linearizer & g)
139 : grid_base(g)
140 {
141 reset();
142
143#ifdef SE_CLASS1
144 initialized = true;
145#endif
146 }
147
156 {
157 grid_base = key_it.grid_base;
158
160
161 for (size_t i = 0 ; i < dim ; i++)
162 {gk.set_d(i,key_it.get_gk(i));}
163
164 return *this;
165 }
166
174 {
176
177 size_t id = gk.get(0);
178 gk.set_d(0,id+1);
179
180 stl_code.increment();
181
183
184 size_t i = 0;
185 for ( ; i < dim-1 ; i++)
186 {
187 /* coverity[dead_error_begin] */
188 size_t id = gk.get(i);
189 if (id >= grid_base.size(i))
190 {
191 // ! overflow, increment the next index
192
193 size_t idr = gk.get(i);
194 gk.set_d(i,0);
195 id = gk.get(i+1);
196 gk.set_d(i+1,id+1);
197
198 stl_code.adjust_offset(i,idr,grid_base);
199 }
200 else
201 {
202 break;
203 }
204 }
205
206 return *this;
207 }
208
217 inline void set(int d, size_t sz)
218 {
219 // set the counter dim to sz
220
221 gk.set_d(d,sz);
222 }
223
231 template<unsigned int id> inline size_t getStencil() const
232 {
233 return stl_code.template getStencil<id>();
234 }
235
244 inline bool isNext()
245 {
246 if (gk.get(dim-1) < (long int)grid_base.size(dim-1))
247 {
249
250 return true;
251 }
252
254 return false;
255 }
256
264 inline const grid_key_dx<dim> & get() const
265 {
266 return gk;
267 }
268
275 {
276 grid_base = key.getGridInfo();
277 reset();
278 }
279
285 inline const linearizer & getGridInfo() const
286 {
287 return grid_base;
288 }
289
293 inline void reset()
294 {
295 // Initialize to 0 the index
296
297 for (size_t i = 0 ; i < dim ; i++)
298 {gk.set_d(i,0);}
299
300 // here we check if grid have a size equal to zero or negative
301 // in this case the grid has no points
302
303 for (size_t i = 0 ; i < dim ; i++)
304 {
305 // If the size of the grid is zero in any dimension set the iterator
306 // to the end point
307 if (grid_base.size(i) == 0)
308 gk.set_d(dim-1,grid_base.size(dim-1));
309 }
310 }
311
318 {
319 // calculate the offsets for the stencil code
320 stl_code.calc_offsets(grid_base,start_p);
321 }
322
329 {
330 grid_key_dx<dim> zero;
331 zero.zero();
332 return zero;
333 }
334
335
341 {
342 grid_key_dx<dim> stop;
343
344 for (size_t i = 0 ; i < dim ; i++)
345 {
346 stop.set_d(i,grid_base.size(i) - 1);
347 }
348
349 return stop;
350 }
351
357 inline size_t getVolume()
358 {
360 }
361
362
363};
364
365
366#endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_HPP_ */
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.
Definition Box.hpp:1351
grid_key_dx_iterator(const grid_key_dx< dim >(&stencil_pnt)[stencil::nsp])
Constructor.
grid_key_dx_iterator< dim, stencil, linearizer > & operator++()
Get the next element.
grid_key_dx_iterator()
Default constructor.
void reinitialize(const grid_key_dx_iterator< dim > &key)
Reinitialize the grid_key_dx_iterator.
linearizer grid_base
information of the grid where this iterator iterate
grid_key_dx< dim > getStart()
Return the starting point of the iteration.
const grid_key_dx< dim > & get() const
Get the actual key.
void set(int d, size_t sz)
Set the dimension.
grid_key_dx_iterator(const linearizer &g)
Constructor require a grid_sm<dim,T>
size_t get_gk(size_t i) const
return the index i of the gk key
grid_key_dx< dim > gk
Actual key.
void reset()
Reset the iterator (it restart from the beginning)
grid_key_dx_iterator(const grid_key_dx_iterator< dim > &g_it)
Constructor from a grid_key_dx_iterator<dim>
grid_key_dx_iterator(const grid_lin &g, const grid_key_dx< dim >(&stencil_pnt)[stencil::nsp])
Constructor require a grid_sm<dim,T>
size_t getStencil() const
Get the actual position.
void calc_stencil_offset(const grid_key_dx< dim > &start_p)
Calculate the stencil offset.
bool isNext()
Check if there is the next element.
grid_key_dx_iterator< dim > operator=(const grid_key_dx_iterator< dim > &key_it)
Constructor from another grid_key_dx_iterator.
size_t getVolume()
Get the volume spanned by this sub-grid iterator.
const linearizer & getGridInfo() const
Get the information about the grid.
grid_key_dx< dim > getStop()
Return the stop point of the iteration.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
void zero()
Set to zero the key.
Definition grid_key.hpp:170
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition grid_key.hpp:516
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503