OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_iterator_dec_skin.hpp
1/*
2 * grid_dist_id_iterator_dec_skin.hpp
3 *
4 * Created on: Jan 4, 2017
5 * Author: i-bird
6 */
7
8#ifndef SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_
9#define SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_
10
11
12#include "grid_dist_id_iterator.hpp"
13#include "Grid/grid_dist_util.hpp"
14#include "grid_dist_id_iterator_util.hpp"
15
23template<typename Decomposition>
24class grid_dist_id_iterator_dec_skin : protected grid_skin_iterator_bc<Decomposition::dims>
25{
27 size_t a_its_p;
28
30 size_t g_c;
31
34
37
39 struct gp_sub
40 {
42 size_t gc;
43
46
54 :gc(gc),it(it)
55 {}
56 };
57
60
62 typename Decomposition::stype spacing[Decomposition::dims];
63
64
69 {
70 if (a_its_p < a_its.size())
71 {
72 g_c = a_its.get(a_its_p).gc;
73
75 }
76 else
77 g_c = gdb_ext.size();
78 }
79
86 {
87 // Construct the sub iterators
88 for (size_t i = 0 ; i < 2*Decomposition::dims; i++)
89 {
90 for (size_t gc = 0 ; gc < gdb_ext.size() ; gc++)
91 {
92 grid_key_dx<Decomposition::dims> start = this->sub_it[i].getStart();
93 grid_key_dx<Decomposition::dims> stop = this->sub_it[i].getStop();
94
97
98 if (compute_subset<Decomposition,false>(gdb_ext,gc,start,stop,start_c,stop_c) == true)
99 {
100 // Convert global coordinate start_c stop_c into local
101 // and calculate the grid sizes
102 size_t sz[Decomposition::dims];
103 for (size_t j = 0 ; j < Decomposition::dims ; j++)
104 {sz[j] = gdb_ext.get(gc).GDbox.getHigh(j) + 1;}
105
107
108 // Non empty sub-set
109 a_its.add(gp_sub(gc,grid_key_dx_iterator_sub<Decomposition::dims>(g_sm,start_c,stop_c)));
110 }
111 }
112 }
113 }
114
115
116 public:
117
118
126 {
127 this->operator=(tmp);
128 }
129
137 {
138 this->operator=(tmp);
139 }
140
154 const size_t (& bc)[Decomposition::dims])
155 :grid_skin_iterator_bc<Decomposition::dims>(g_sm,A,B,bc),a_its_p(0),g_c(0)
156 {
157 // From the decomposition construct gdb_ext
158 create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,g_sm.getSize(),dec.getDomain(),spacing);
159
160 // This iterato only work if A is contained into B
161 if (A.isContained(B) == false)
162 std::cout << __FILE__ << ":" << __LINE__ << ", Error Box A must be contained into box B" << std::endl;
163
164 // construct sub_iterators
166
167 // Initialize the current iterator
168 // with the first grid
170 }
171
174 {
175 }
176
183 {
184 ++a_it;
185
186 // check if a_it is at the end
187
188 if (a_it.isNext() == true)
189 return *this;
190 else
191 {
192 // switch to the new grid
193 a_its_p++;
194
196 }
197
198 return *this;
199 }
200
206 inline bool isNext()
207 {
208 // If there are no other grid stop
209
210 if (a_its_p >= a_its.size())
211 {return false;}
212
213 return true;
214 }
215
223 inline typename Decomposition::stype getSpacing(size_t i)
224 {
225 return spacing[i];
226 }
227
235 {
237
238 // Get the sub-domain id
239 size_t sub_id = k.getSub();
240
241 grid_key_dx<Decomposition::dims> k_glob = k.getKey();
242
243 // shift
244 k_glob = k_glob + gdb_ext.get(sub_id).origin;
245
246 return k_glob;
247 }
248
255 {
257 }
258
267 {
268 a_its_p = tmp.a_its_p;
269 g_c = tmp.g_c;
270 gdb_ext = tmp.gdb_ext;
271 a_its = tmp.a_its;
272
273 for (size_t i = 0 ; i < Decomposition::dims ; i++)
274 spacing[i] = tmp.spacing[i];
275
277
278 return *this;
279 }
280
289 {
290 a_its_p = tmp.a_its_p;
291 g_c = tmp.g_c;
292 gdb_ext = tmp.gdb_ext;
293 a_its = tmp.a_its;
294
295 for (size_t i = 0 ; i < Decomposition::dims ; i++)
296 spacing[i] = tmp.spacing[i];
297
298 a_it.reinitialize(tmp.a_it);
299
300 return *this;
301 }
302};
303
304
305#endif /* SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
This class define the domain decomposition interface.
Given the decomposition it create an iterator.
void construct_sub_it()
construct sub-iterators
bool isNext()
Check if there is the next element.
grid_dist_id_iterator_dec_skin(Decomposition &dec, const grid_sm< Decomposition::dims, void > &g_sm, const Box< Decomposition::dims, size_t > &A, const Box< Decomposition::dims, size_t > &B, const size_t(&bc)[Decomposition::dims])
Constructor of the distributed grid iterator.
openfpm::vector< GBoxes< Decomposition::dims > > gdb_ext
Extension of each grid: domain and ghost + domain.
grid_key_dx< Decomposition::dims > get()
Get the actual global key of the grid.
openfpm::vector< gp_sub > a_its
Actual sub-iterators.
grid_dist_id_iterator_dec_skin(grid_dist_id_iterator_dec_skin< Decomposition > &&tmp)
Copy constructor.
grid_dist_id_iterator_dec_skin< Decomposition > & operator=(grid_dist_id_iterator_dec_skin< Decomposition > &&tmp)
Copy operator=.
Decomposition::stype spacing[Decomposition::dims]
Spacing.
grid_key_dx_iterator_sub< Decomposition::dims > a_it
Internal grid sub-iterator.
grid_dist_id_iterator_dec_skin< Decomposition > & operator=(const grid_dist_id_iterator_dec_skin< Decomposition > &tmp)
Copy operator=.
grid_dist_key_dx< Decomposition::dims > get_int()
Get the actual key.
void selectValidGrid()
from g_c increment g_c until you find a valid grid
size_t a_its_p
a_its element in this moment selected
grid_dist_id_iterator_dec_skin(const grid_dist_id_iterator_dec_skin< Decomposition > &tmp)
Copy constructor.
grid_dist_id_iterator_dec_skin< Decomposition > & operator++()
Get the next element.
Decomposition::stype getSpacing(size_t i)
Get the spacing of the 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.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
grid_key_dx_iterator_sub_bc< dim > sub_it[2 *dim]
Internal iterator for each faces.
Declaration grid_sm.
Definition grid_sm.hpp:167
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition grid_sm.hpp:760
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
size_t gc
from which grid this iterator come from
grid_key_dx_iterator_sub< Decomposition::dims > it
Iterator.
gp_sub(size_t gc, grid_key_dx_iterator_sub< Decomposition::dims > &&it)
constructor