OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_key_dx_iterator_hilbert.hpp
1/*
2 * grid_key_dx_iterator_hilbert.hpp
3 *
4 * Created on: Feb 24, 2016
5 * Author: yaroslav
6 */
7
8#ifndef OPENFPM_DATA_SRC_GRID_GRID_KEY_DX_ITERATOR_HILBERT_HPP_
9#define OPENFPM_DATA_SRC_GRID_GRID_KEY_DX_ITERATOR_HILBERT_HPP_
10
11extern "C"
12{
13#include "hilbertKey.h"
14}
15
16
17/*
18 *
19 * Grid key class iterator, iterate through the grid elements following an
20 * hilbert space filling curve
21 *
22 * \param dim dimensionality of the grid
23 *
24 * ### Grid iterator declaration and usage
25 * \snippet grid_unit_tests.hpp Grid iterator test usage
26 *
27 */
28
29template<unsigned int dim>
31{
32#ifdef SE_CLASS1
35 bool initialized = false;
36#endif
37
39 uint64_t hkey = 0;
40
42 size_t m;
43
46
47protected:
48
51
52public:
53
63 :m(m)
64 {
65 // create from m the correct grid_sm
66
67 size_t dims[dim];
68
69 //Set the 2^m value to the each elements of dims[]
70 for (size_t i = 0 ; i < dim ; i++)
71 dims[i] = 1 << m;
72
73 //Set grid_sm dimensions
74 grid_base.setDimensions(dims);
75
76 reset();
77
78#ifdef SE_CLASS1
79 initialized = true;
80#endif
81 }
82
90 {
91 //An integer to handle errors
92 int err;
93
94 hkey++;
95
96 //Array to handle output
97 uint64_t nextCoord[dim];
98
99 //Get the coordinates of the next cell
100 getIntCoordFromHKey(nextCoord, m, dim, hkey, &err);
101
102 //Set the new coordinates
103 for (size_t i = 0; i < dim; i++)
104 gk.set_d(i, nextCoord[i]);
105
106 return *this;
107 }
108
117 bool isNext()
118 {
119 if ( hkey < (size_t)1 << (m*dim))
120 {
122
123 return true;
124 }
125
127 return false;
128 }
129
138 {
139 return gk;
140 }
141
142
146 void reset()
147 {
149 for (size_t i = 0 ; i < dim ; i++)
150 gk.set_d(i,0);
151 }
152};
153
154
155#endif /* OPENFPM_DATA_SRC_GRID_GRID_KEY_DX_ITERATOR_HILBERT_HPP_ */
grid_key_dx< dim > gk
Actual position in the grid.
grid_key_dx_iterator_hilbert< dim > & operator++()
Get the next element.
grid_key_dx_iterator_hilbert(int32_t m)
Constructor.
size_t m
Order of a hilbert curve.
const grid_key_dx< dim > & get()
Get the actual key.
grid_sm< dim, void > grid_base
Size of the hilbert grid in each dimension.
bool isNext()
Check if there is the next element.
void reset()
Reset the iterator (it restart from the beginning)
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
Declaration grid_sm.
Definition grid_sm.hpp:167