OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
SparseGrid_iterator.hpp
1/*
2 * SparseGrid_iterator.hpp
3 *
4 * Created on: Oct 24, 2017
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_SPARSEGRID_SPARSEGRID_ITERATOR_HPP_
9#define OPENFPM_DATA_SRC_SPARSEGRID_SPARSEGRID_ITERATOR_HPP_
10
17{
19 size_t chunk;
20
22 size_t lin_id;
23
24public:
25
26 inline grid_key_sparse_lin_dx(size_t chunk, size_t lin_id)
28 {
29
30 }
31
37 inline size_t getChunk() const
38 {
39 return chunk;
40 }
41
47 inline size_t getPos() const
48 {
49 return lin_id;
50 }
51};
52
53
58template<unsigned int n_ele>
59inline void fill_mask(short unsigned int (& mask_it)[n_ele],
60 const unsigned char (& mask)[n_ele],
61 int & mask_nele)
62{
63 mask_nele = 0;
64
65 for (size_t i = 0 ; i < n_ele ; i++)
66 {
67 if (mask[i] & 1)
68 {
69 mask_it[mask_nele] = i;
70 mask_nele++;
71 }
72 }
73}
74
79template<unsigned int dim, unsigned int n_ele>
80inline void fill_mask_box(short unsigned int (& mask_it)[n_ele],
81 const unsigned char (& mask)[n_ele],
82 size_t & mask_nele,
83 Box<dim,size_t> & bx,
84 const grid_key_dx<dim> (& loc_grid)[n_ele])
85{
86 mask_nele = 0;
87
88 for (size_t i = 0 ; i < n_ele ; i++)
89 {
90 size_t id = i;
91
92 bool is_inside = true;
93 // we check the point is inside inte
94 for (size_t j = 0 ; j < dim ; j++)
95 {
96 if (loc_grid[id].get(j) < (long int)bx.getLow(j) ||
97 loc_grid[id].get(j) > (long int)bx.getHigh(j))
98 {
99 is_inside = false;
100
101 break;
102 }
103 }
104
105 if (is_inside == true && (mask[i] & 1))
106 {
107 mask_it[mask_nele] = id;
108 mask_nele++;
109 }
110 }
111}
112
119template<unsigned int n_ele>
121{
123 unsigned char mask[n_ele];
124};
125
126
133template<unsigned int dim>
135{
138
140 int nele;
141};
142
147template<unsigned dim, unsigned int n_ele>
149{
150 const static int cnk_pos = 0;
151 const static int cnk_nele = 1;
152 const static int cnk_mask = 2;
153
156
159
161 const grid_key_dx<dim> (* lin_id_pos)[n_ele];
162
164 size_t chunk_id;
165
167 size_t mask_nele;
168
171
174
177
180
182 size_t sz_cnk[dim];
183
185 short unsigned int mask_it[n_ele];
186
192 {
193 mask_it_pnt = 0;
194 mask_nele = 0;
195
196 while (mask_nele == 0 && chunk_id < header_inf->size())
197 {
198 auto & mask = header_mask->get(chunk_id).mask;
199
200 Box<dim,size_t> cnk_box;
201
202 for (size_t i = 0 ; i < dim ; i++)
203 {
204 cnk_box.setLow(i,header_inf->get(chunk_id).pos.get(i));
205 cnk_box.setHigh(i,header_inf->get(chunk_id).pos.get(i) + sz_cnk[i] - 1);
206 }
207
208 Box<dim,size_t> inte;
209
210 if (bx.Intersect(cnk_box,inte) == true)
211 {
212 inte -= header_inf->get(chunk_id).pos.toPoint();
213 fill_mask_box<dim,n_ele>(mask_it,mask,mask_nele,inte,*lin_id_pos);
214 }
215 else
216 {mask_nele = 0;}
217
218 chunk_id = (mask_nele == 0)?chunk_id + 1:chunk_id;
219
220 }
221 }
222
223public:
224
232
235 const grid_key_dx<dim> (& lin_id_pos)[n_ele],
236 const grid_key_dx<dim> & start,
237 const grid_key_dx<dim> & stop,
238 const size_t (& sz_cnk)[dim])
241 {
242 for (size_t i = 0 ; i < dim ; i++)
243 {
244 this->sz_cnk[i] = sz_cnk[i];
245
246 bx.setLow(i,start.get(i));
247 bx.setHigh(i,stop.get(i));
248 }
249
251 }
252
262 {
263 header_inf = g_s_it.header_inf;
264 header_mask = g_s_it.header_mask;
265 lin_id_pos = g_s_it.lin_id_pos;
266 chunk_id = g_s_it.chunk_id;
267 mask_nele = g_s_it.mask_nele;
268 mask_it_pnt = g_s_it.mask_it_pnt;
269 start = g_s_it.start;
270 stop = g_s_it.stop;
271 bx = g_s_it.bx;
272 for (size_t i = 0 ; i < dim ; i++)
273 {sz_cnk[i] = g_s_it.sz_cnk[i];}
274
275 memcpy(mask_it,g_s_it.mask_it,sizeof(short unsigned int)*n_ele);
276 }
277
279 {
280 mask_it_pnt++;
281
283 {
284 return *this;
285 }
286
287 chunk_id++;
288 mask_it_pnt = 0;
289
290 if (chunk_id < header_inf->size())
291 {
293 }
294
295 return *this;
296 }
297
298
304 inline grid_key_dx<dim> get() const
305 {
306 grid_key_dx<dim> k_pos;
307
308 size_t lin_id = mask_it[mask_it_pnt];
309
310 for (size_t i = 0 ; i < dim ; i++)
311 {
312 k_pos.set_d(i,(*lin_id_pos)[lin_id].get(i) + header_inf->get(chunk_id).pos.get(i));
313 }
314
315 return k_pos;
316 }
317
326 {
328 }
329
335 bool isNext()
336 {
337 return chunk_id < header_inf->size();
338 }
339
346 {
347 return start;
348 }
349
355 const grid_key_dx<dim> & getStop() const
356 {
357 return stop;
358 }
359
366 {return header_inf;}
367
374 {return header_mask;}
375
382 {return lin_id_pos;}
383
389 size_t private_get_chunk_id() const
390 {return chunk_id;}
391
398 {return mask_nele;}
399
400
407 {return mask_it_pnt;}
408
414 const short unsigned int (& private_get_mask_it() const) [n_ele]
415 {
416 return mask_it;
417 }
418};
419
424template<unsigned dim, unsigned int n_ele>
426{
429
432
434 const grid_key_dx<dim> (* lin_id_pos)[n_ele];
435
437 size_t chunk_id;
438
441
444
446 short unsigned int mask_it[n_ele];
447
453 {
454 mask_nele = 0;
455 mask_it_pnt = 0;
456
457 while (mask_nele == 0 && chunk_id < header_inf->size())
458 {
459 auto & mask = header_mask->get(chunk_id).mask;
460
461 fill_mask<n_ele>(mask_it,mask,mask_nele);
462
463 chunk_id = (mask_nele == 0)?chunk_id + 1:chunk_id;
464
465 }
466 }
467
468public:
469
477
480 const grid_key_dx<dim> (* lin_id_pos)[n_ele])
482 {
484 }
485
486 inline grid_key_sparse_dx_iterator<dim,n_ele> & operator++()
487 {
488 mask_it_pnt++;
489
491 {
492 return *this;
493 }
494
495 chunk_id++;
496 mask_it_pnt = 0;
497
498 if (chunk_id < header_inf->size())
499 {
501 }
502
503 return *this;
504 }
505
515 {
516 header_mask = g_s_it.header_mask;
517 header_inf = g_s_it.header_inf;
518 lin_id_pos = g_s_it.lin_id_pos;
519 chunk_id = g_s_it.chunk_id;
520 mask_nele = g_s_it.mask_nele;
521 mask_it_pnt = g_s_it.mask_it_pnt;
522
523 memcpy(mask_it,g_s_it.mask_it,sizeof(short unsigned int)*n_ele);
524 }
525
535 {
539 chunk_id = 0;
540
542 }
543
552 {
554 }
555
561 inline grid_key_dx<dim> get() const
562 {
563 grid_key_dx<dim> k_pos;
564
565 size_t lin_id = mask_it[mask_it_pnt];
566
567 for (size_t i = 0 ; i < dim ; i++)
568 {
569 k_pos.set_d(i,(*lin_id_pos)[lin_id].get(i) + header_inf->get(chunk_id).pos.get(i));
570 }
571
572 return k_pos;
573 }
574
580 bool isNext()
581 {
582 return chunk_id < header_inf->size();
583 }
584};
585
586#endif /* OPENFPM_DATA_SRC_SPARSEGRID_SPARSEGRID_ITERATOR_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
__device__ __host__ bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
Definition Box.hpp:95
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__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
Grid key sparse iterator on a sub-part of the domain.
const grid_key_dx< dim > & getStop() const
Return the stop point for the iteration.
const grid_key_dx< dim > & getStart() const
Return the starting point for the iteration.
size_t private_get_mask_it_pnt() const
Return the private member mask_it_pnt.
grid_key_sparse_dx_iterator_sub()
Default constructor.
size_t chunk_id
point to the actual chunk
Box< dim, size_t > bx
Sub-grid box.
const openfpm::vector< mheader< n_ele > > * header_mask
It store the information of each chunk mask.
const grid_key_dx< dim >(* private_get_lin_id_pos() const)[n_ele]
Return the private member lin_id_pos.
const grid_key_dx< dim >(* lin_id_pos)[n_ele]
linearized id to position in coordinates conversion
const short unsigned int(& private_get_mask_it() const)[n_ele]
Return the private member mask_it.
size_t private_get_mask_nele() const
Return the private member mask_nele.
size_t mask_it_pnt
Actual point in mask it.
grid_key_dx< dim > start
Starting point.
const openfpm::vector< cheader< dim > > * private_get_header_inf() const
Return the private member header.
const openfpm::vector< cheader< dim > > * header_inf
it store the information of each chunk
grid_key_sparse_lin_dx getKeyF()
Return the actual point linearized.
size_t mask_nele
Number of points in mask_it.
bool isNext()
Return true if there is a next grid point.
const openfpm::vector< mheader< n_ele > > * private_get_header_mask() const
Return the private member header.
size_t private_get_chunk_id() const
Return the private member chunk_id.
grid_key_dx< dim > get() const
Return the position of the actual point in coordinates.
void reinitialize(const grid_key_sparse_dx_iterator_sub< dim, n_ele > &g_s_it)
Reinitialize the iterator.
void SelectValidAndFill_mask_it()
Everytime we move to a new chunk we calculate on which indexes we have to iterate.
short unsigned int mask_it[n_ele]
set of index in the chunk on which we have to iterate
grid_key_dx< dim > stop
Stop point.
Grid key sparse iterator.
grid_key_sparse_lin_dx getKeyF()
Return the actual point.
const grid_key_dx< dim >(* lin_id_pos)[n_ele]
linearized id to position in coordinates conversion
bool isNext()
Return true if there is a next grid point.
const openfpm::vector< mheader< n_ele > > * header_mask
It store the information of each chunk.
size_t mask_it_pnt
Actual point in mask it.
grid_key_sparse_dx_iterator()
Default constructor.
size_t chunk_id
point to the actual chunk
grid_key_dx< dim > get() const
Return the position of the actual point in coordinates.
void SelectValidAndFill_mask_it()
Everytime we move to a new chunk we calculate on which indexes we have to iterate.
void reinitialize(const grid_key_sparse_dx_iterator_sub< dim, n_ele > &g_s_it)
Reinitialize the iterator.
int mask_nele
Number of points in mask_it.
short unsigned int mask_it[n_ele]
set of index in the chunk on which we have to iterate
const openfpm::vector< cheader< dim > > * header_inf
It store the information of each chunk.
void reinitialize(const grid_key_sparse_dx_iterator< dim, n_ele > &g_s_it)
Reinitialize the iterator.
It store the position in space of the sparse grid.
size_t getPos() const
Return the linearized position in the chunk.
size_t getChunk() const
Return the chunk id.
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
This structure contain the information of a chunk.
int nele
how many elements in the chunk are set
grid_key_dx< dim > pos
where is located the chunk
This structure contain the information of a chunk.
unsigned char mask[n_ele]
which elements in the chunks are set