OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_iterator_dec.hpp
1/*
2 * grid_dist_id_iterator_dec.hpp
3 *
4 * Created on: Jan 27, 2016
5 * Author: i-bird
6 */
7
8#ifndef SRC_GRID_GRID_DIST_ID_ITERATOR_DEC_HPP_
9#define SRC_GRID_GRID_DIST_ID_ITERATOR_DEC_HPP_
10
11#include "grid_dist_id_iterator.hpp"
12#include "Grid/grid_dist_util.hpp"
13#include "grid_dist_id_iterator_util.hpp"
14
22template<typename Decomposition, bool ghost_or_domain = false>
24{
26 size_t g_c;
27
30
33
36
39
41 typename Decomposition::stype spacing[Decomposition::dims];
42
45
50 {
51 // start and stop for the subset grid
54
55 // When the grid has size 0 potentially all the other informations are garbage
56 while (g_c < gdb_ext.size() &&
57 (gdb_ext.get(g_c).Dbox.isValid() == false || compute_subset<Decomposition,ghost_or_domain>(gdb_ext,g_c,start,stop,start_c,stop_c) == false ))
58 {g_c++;}
59
60 // get the next grid iterator
61 if (g_c < gdb_ext.size())
62 {
63 // Calculate the resolution of the local grid
64 size_t sz[Decomposition::dims];
65 for (size_t i = 0 ; i < Decomposition::dims ; i++)
66 sz[i] = gdb_ext.get(g_c).GDbox.getP2()[i] + 1;
67
70 }
71 }
72
79 {
81 }
82
83 public:
84
93 {
94 g_c = tmp.g_c;
95 gdb_ext = tmp.gdb_ext;
97
98 start = tmp.start;
99 stop = tmp.stop;
100
101 domain = tmp.domain;
102
103 return *this;
104 }
105
112 {
113 this->operator=(tmp);
114 }
115
122 grid_dist_id_iterator_dec(Decomposition & dec, const size_t (& sz)[Decomposition::dims])
123 :g_c(0)
124 {
125 domain = dec.getDomain();
126
127 // Initialize start and stop
128 start.zero();
129 for (size_t i = 0 ; i < Decomposition::dims ; i++)
130 stop.set_d(i,sz[i]-1);
131
132 // From the decomposition construct gdb_ext
133 create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,sz,dec.getDomain(),spacing);
134
135 // Initialize the current iterator
136 // with the first grid
138 }
139
149 :g_c(0),start(start),stop(stop)
150 {
151 domain = dec.getDomain();
152
153 // From the decomposition construct gdb_ext
154 create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,sz,dec.getDomain(),spacing);
155
156 // Initialize the current iterator
157 // with the first grid
159 }
160
161 // Destructor
163 {
164 }
165
171 inline bool isNextGrid()
172 {
173 return g_c < gdb_ext.size();
174 }
175
180 inline size_t getGridId()
181 {
182 return g_c;
183 }
184
189 inline void nextGrid()
190 {
191 g_c++;
193 }
194
201 {
203
204 auto start = a_it.getStart();
205 auto stop = a_it.getStop();
206
207 for (int i = 0 ; i < Decomposition::dims ; i++)
208 {
209 bx.setHigh(i,stop.get(i));
210 bx.setLow(i,start.get(i));
211 }
212
213 return bx;
214 }
215
223 {
224 ++a_it;
225
226 // check if a_it is at the end
227
228 if (a_it.isNext() == true)
229 {return *this;}
230 else
231 {
232 // switch to the new grid
233 g_c++;
234
236 }
237
238 return *this;
239 }
240
246 inline bool isNext()
247 {
248 // If there are no other grid stop
249
250 if (g_c >= gdb_ext.size())
251 return false;
252
253 return true;
254 }
255
261 inline typename Decomposition::stype getSpacing(size_t i)
262 {
263 return spacing[i];
264 }
265
273 {
275
276 // Get the sub-domain id
277 size_t sub_id = k.getSub();
278
279 grid_key_dx<Decomposition::dims> k_glob = k.getKey();
280
281 // shift
282 k_glob = k_glob + gdb_ext.get(sub_id).origin;
283
284 return k_glob;
285 }
286
293 {
295 auto key = this->get();
296
297 for (int i = 0 ; i < Decomposition::dims ; i++)
298 {
299 p.get(i) = spacing[i] * key.get(i) + domain.getLow(i);
300 }
301
302 return p;
303 }
304
314 {
315 return get_int();
316 }
317
324 {
325 return start;
326 }
327
334 {
335 return stop;
336 }
337};
338
339
340#endif /* SRC_GRID_GRID_DIST_ID_ITERATOR_DEC_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__ 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
This class define the domain decomposition interface.
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
Given the decomposition it create an iterator.
grid_dist_id_iterator_dec< Decomposition > & operator=(const grid_dist_id_iterator_dec< Decomposition > &tmp)
Copy operator=.
Box< Decomposition::dims, typename Decomposition::stype > domain
Domain.
grid_dist_key_dx< Decomposition::dims > get_int()
Get the actual key.
grid_key_dx< Decomposition::dims > start
start key
size_t getGridId()
Return the index of the grid in which we are iterating.
openfpm::vector< GBoxes< Decomposition::dims > > gdb_ext
Extension of each grid: domain and ghost + domain.
void selectValidGrid()
from g_c increment g_c until you find a valid grid
grid_dist_id_iterator_dec(Decomposition &dec, const size_t(&sz)[Decomposition::dims], grid_key_dx< Decomposition::dims > start, grid_key_dx< Decomposition::dims > stop)
Constructor of the distributed grid iterator.
grid_key_dx< Decomposition::dims > getStart()
Get the starting point of the sub-grid we are iterating.
grid_key_dx< Decomposition::dims > get()
Get the actual global key of the grid.
grid_key_dx< Decomposition::dims > getStop()
Get the starting point of the sub-grid we are iterating.
Box< Decomposition::dims, size_t > getGridBox()
Return the actual pointed grid.
Point< Decomposition::dims, typename Decomposition::stype > getPoint()
Return the point coordinates.
bool isNextGrid()
Return true if we point to a valid grid.
grid_key_dx_iterator_sub< Decomposition::dims > a_it
Actual iterator.
Decomposition::stype spacing[Decomposition::dims]
Spacing.
grid_dist_id_iterator_dec(Decomposition &dec, const size_t(&sz)[Decomposition::dims])
Constructor of the distributed grid iterator.
Decomposition::stype getSpacing(size_t i)
Get the spacing of the grid.
grid_key_dx< Decomposition::dims > stop
stop key
grid_dist_id_iterator_dec< Decomposition, ghost_or_domain > & operator++()
Get the next element.
grid_dist_id_iterator_dec(const grid_dist_id_iterator_dec< Decomposition > &tmp)
Copy constructor.
bool isNext()
Check if there is the next element.
grid_dist_key_dx< Decomposition::dims > get_dist()
Get the actual grid key for a distributed grid.
Grid key for a distributed grid.
Declaration grid_key_dx_iterator_sub.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
bool isNext()
Check if there is the next element.
void reinitialize(const grid_key_dx_iterator_sub< dim > &g_s_it)
Reinitialize the iterator.
const grid_key_dx< dim > & getStart() const
Starting point.
const grid_key_dx< dim > & getStop() const
Stop point.
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
Declaration grid_sm.
Definition grid_sm.hpp:167
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.