OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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>(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 
121  {
123  }
124 
125  public:
126 
127 
135  {
136  this->operator=(tmp);
137  }
138 
146  {
147  this->operator=(tmp);
148  }
149 
163  const size_t (& bc)[Decomposition::dims])
164  :grid_skin_iterator_bc<Decomposition::dims>(g_sm,A,B,bc),a_its_p(0),g_c(0)
165  {
166  // From the decomposition construct gdb_ext
167  create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,g_sm.getSize(),dec.getDomain(),spacing);
168 
169  // This iterato only work if A is contained into B
170  if (A.isContained(B) == false)
171  std::cout << __FILE__ << ":" << __LINE__ << ", Error Box A must be contained into box B" << std::endl;
172 
173  // construct sub_iterators
175 
176  // Initialize the current iterator
177  // with the first grid
178  selectValidGrid();
179  }
180 
183  {
184  }
185 
192  {
193  ++a_it;
194 
195  // check if a_it is at the end
196 
197  if (a_it.isNext() == true)
198  return *this;
199  else
200  {
201  // switch to the new grid
202  a_its_p++;
203 
204  selectValidGrid();
205  }
206 
207  return *this;
208  }
209 
215  inline bool isNext()
216  {
217  // If there are no other grid stop
218 
219  if (g_c >= gdb_ext.size())
220  return false;
221 
222  return true;
223  }
224 
232  inline typename Decomposition::stype getSpacing(size_t i)
233  {
234  return spacing[i];
235  }
236 
244  {
246 
247  // Get the sub-domain id
248  size_t sub_id = k.getSub();
249 
251 
252  // shift
253  k_glob = k_glob + gdb_ext.get(sub_id).origin;
254 
255  if (k_glob.get(0) > 11)
256  {
257  int debug = 0;
258  debug++;
259  }
260 
261  return k_glob;
262  }
263 
272  {
273  a_its_p = tmp.a_its_p;
274  g_c = tmp.g_c;
275  gdb_ext = tmp.gdb_ext;
276  a_its = tmp.a_its;
277 
278  for (size_t i = 0 ; i < Decomposition::dims ; i++)
279  spacing[i] = tmp.spacing[i];
280 
281  a_it.reinitialize(tmp.a_it);
282 
283  return *this;
284  }
285 
294  {
295  a_its_p = tmp.a_its_p;
296  g_c = tmp.g_c;
297  gdb_ext = tmp.gdb_ext;
298  a_its = tmp.a_its;
299 
300  for (size_t i = 0 ; i < Decomposition::dims ; i++)
301  spacing[i] = tmp.spacing[i];
302 
303  a_it.reinitialize(tmp.a_it);
304 
305  return *this;
306  }
307 };
308 
309 
310 #endif /* SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_ */
openfpm::vector< gp_sub > a_its
Actual sub-iterators.
openfpm::vector< GBoxes< Decomposition::dims > > gdb_ext
Extension of each grid: domain and ghost + domain.
size_t gc
from which grid this iterator come from
grid_key_dx_iterator_sub< Decomposition::dims > a_it
Internal grid sub-iterator.
const grid_key_dx< dim > & getStop() const
Stop point.
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=.
size_t size()
Stub size.
Definition: map_vector.hpp:70
Grid key for a distributed grid.
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=.
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
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.
bool isContained(const Box< dim, T > &b) const
Check if the box is contained.
Definition: Box.hpp:863
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition: grid_sm.hpp:677
void construct_sub_it()
construct sub-iterators
Decomposition::stype spacing[Decomposition::dims]
Spacing.
This class represent an N-dimensional box.
Definition: Box.hpp:56
grid_key_dx< dim > get() const
Return the actual grid key iterator.
Decomposition::stype getSpacing(size_t i)
Get the spacing of the grid.
Declaration grid_sm.
Definition: grid_sm.hpp:71
grid_dist_key_dx< Decomposition::dims > get_int()
Get the actual key.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
bool isNext()
Check if there is the next element.
bool isNext()
Check if there is the next element.
const grid_key_dx< dim > & getStart() const
Starting point.
Given the decomposition it create an iterator.
size_t getSub() const
Get the local grid.
void reinitialize(const grid_key_dx_iterator_sub< dim > &g_s_it)
Reinitialize the iterator.
grid_dist_id_iterator_dec_skin< Decomposition > & operator++()
Get the next element.
grid_key_dx< dim > getKey() const
Get the key.