OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
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 
23 template<typename Decomposition>
24 class 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 
74  a_it.reinitialize(a_its.get(a_its_p).it);
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  {
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
169  selectValidGrid();
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 
195  selectValidGrid();
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 
276  a_it.reinitialize(tmp.a_it);
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_ */
openfpm::vector< gp_sub > a_its
Actual sub-iterators.
const grid_key_dx< dim > & getStart() const
Starting point.
openfpm::vector< GBoxes< Decomposition::dims > > gdb_ext
Extension of each grid: domain and ghost + domain.
bool isNext()
Check if there is the next element.
size_t gc
from which grid this iterator come from
grid_key_dx_iterator_sub< Decomposition::dims > a_it
Internal grid sub-iterator.
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.
grid_key_dx_iterator_sub< Decomposition::dims > it
Iterator.
grid_dist_id_iterator_dec_skin< Decomposition > & operator=(grid_dist_id_iterator_dec_skin< Decomposition > &&tmp)
Copy operator=.
Grid key for a distributed grid.
size_t size()
Stub size.
Definition: map_vector.hpp:211
void selectValidGrid()
from g_c increment g_c until you find a valid grid
grid_dist_id_iterator_dec_skin< Decomposition > & operator=(const grid_dist_id_iterator_dec_skin< Decomposition > &tmp)
Copy operator=.
gp_sub(size_t gc, grid_key_dx_iterator_sub< Decomposition::dims > &&it)
constructor
This class define the domain decomposition interface.
size_t a_its_p
a_its element in this moment selected
grid_dist_id_iterator_dec_skin(grid_dist_id_iterator_dec_skin< Decomposition > &&tmp)
Copy constructor.
grid_dist_id_iterator_dec_skin(const grid_dist_id_iterator_dec_skin< Decomposition > &tmp)
Copy constructor.
grid_key_dx_iterator_sub_bc< dim > sub_it[2 *dim]
Internal iterator for each faces.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition: grid_sm.hpp:740
grid_key_dx< Decomposition::dims > get()
Get the actual global key of the grid.
void construct_sub_it()
construct sub-iterators
Decomposition::stype spacing[Decomposition::dims]
Spacing.
This class represent an N-dimensional box.
Definition: Box.hpp:60
const grid_key_dx< dim > & getStop() const
Stop point.
Decomposition::stype getSpacing(size_t i)
Get the spacing of the grid.
Declaration grid_sm.
Definition: grid_sm.hpp:147
void reinitialize(const grid_key_dx_iterator_sub< dim > &g_s_it)
Reinitialize the iterator.
grid_dist_key_dx< Decomposition::dims > get_int()
Get the actual key.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202
bool isNext()
Check if there is the next element.
Given the decomposition it create an iterator.
grid_dist_id_iterator_dec_skin< Decomposition > & operator++()
Get the next element.