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.hpp
1 /*
2  * grid_dist_id_iterator_sub.hpp
3  *
4  * Created on: Feb 4, 2015
5  * Author: Pietro Incardona
6  */
7 
8 #ifndef GRID_DIST_ID_ITERATOR_HPP_
9 #define GRID_DIST_ID_ITERATOR_HPP_
10 
11 #define FREE 1
12 #define FIXED 2
13 
14 #include "Grid/grid_dist_key.hpp"
15 #include "VCluster/VCluster.hpp"
16 #include "util/GBoxes.hpp"
17 
18 
28 template<unsigned int dim, typename device_grid, int impl,typename stencil = no_stencil >
30 {
31 
32 };
33 
34 
44 template<unsigned int dim, typename device_grid, typename stencil>
45 class grid_dist_iterator<dim,device_grid,FREE,stencil>
46 {
48  size_t g_c;
49 
52 
55 
58 
61 
66  {
67  // When the grid has size 0 potentially all the other informations are garbage
68  while (g_c < gList.size() && (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false ) )
69  {g_c++;}
70 
71  // get the next grid iterator
72  if (g_c < gList.size())
73  {
74  a_it.reinitialize(gList.get(g_c).getIterator(gdb_ext.get(g_c).Dbox.getKP1(),gdb_ext.get(g_c).Dbox.getKP2()));
75  }
76  }
77 
78  public:
79 
88  :g_c(0),gList(gk),gdb_ext(gdb_ext),stop(stop)
89  {
90  // Initialize the current iterator
91  // with the first grid
92  selectValidGrid();
93  }
94 
106  const grid_key_dx<dim> & stop,
107  const grid_key_dx<dim> (& stencil_pnt)[stencil::nsp])
108  :g_c(0),gList(gk),gdb_ext(gdb_ext),a_it(stencil_pnt),stop(stop)
109  {
110  // Initialize the current iterator
111  // with the first grid
112  selectValidGrid();
113  }
114 
115  // Destructor
117  {
118  }
119 
127  {
128  ++a_it;
129 
130  // check if a_it is at the end
131 
132  if (a_it.isNext() == true)
133  return *this;
134  else
135  {
136  // switch to the new grid
137  g_c++;
138 
139  selectValidGrid();
140  }
141 
142  return *this;
143  }
144 
150  inline bool isNext()
151  {
152  // If there are no other grid stop
153 
154  if (g_c >= gList.size())
155  {return false;}
156 
157  return true;
158  }
159 
166  {
167  return grid_dist_key_dx<dim>(g_c,a_it.get());
168  }
169 
177  inline grid_key_dx<dim> getStop() const
178  {
179  return stop;
180  }
181 
189  inline grid_key_dx<dim> getStart() const
190  {
191  grid_key_dx<dim> start;
192 
193  start.zero();
194 
195  return start;
196  }
197 
206  {
207  return gdb_ext;
208  }
209 
221  {
222  // Get the sub-domain id
223  size_t sub_id = k.getSub();
224 
225  grid_key_dx<dim> k_glob = k.getKey();
226 
227  // shift
228  k_glob = k_glob + gdb_ext.get(sub_id).origin;
229 
230  return k_glob;
231  }
232 
240  template<unsigned int id> inline grid_dist_lin_dx getStencil()
241  {
242  return grid_dist_lin_dx(g_c,a_it.template getStencil<id>());
243  }
244 };
245 
246 
256 template<unsigned int dim, typename device_grid,typename stencil>
257 class grid_dist_iterator<dim,device_grid,FIXED,stencil>
258 {
260  size_t g_c;
261 
264 
267 
270 
275  {
276  // When the grid has size 0 potentially all the other informations are garbage
277  while (g_c < gList.size() && (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false ) ) g_c++;
278 
279  // get the next grid iterator
280  if (g_c < gList.size())
281  {
282  a_it.reinitialize(gList.get(g_c).getIterator(gdb_ext.get(g_c).Dbox.getKP1(),gdb_ext.get(g_c).Dbox.getKP2()));
283  }
284  }
285 
286  public:
287 
296  {
297  g_c = tmp.g_c;
298  gList = tmp.gList;
299  gdb_ext = tmp.gdb_ext;
300  a_it.reinitialize(tmp.a_it);
301 
302  return *this;
303  }
304 
312  :g_c(0),gList(gk),gdb_ext(gdb_ext)
313  {
314  // Initialize the current iterator
315  // with the first grid
316  selectValidGrid();
317  }
318 
319  // Destructor
321  {
322  }
323 
331  {
332  ++a_it;
333 
334  // check if a_it is at the end
335 
336  if (a_it.isNext() == true)
337  return *this;
338  else
339  {
340  // switch to the new grid
341  g_c++;
342  selectValidGrid();
343  }
344 
345  return *this;
346  }
347 
353  bool isNext()
354  {
355  // If there are no other grid stop
356 
357  if (g_c >= gList.size())
358  return false;
359 
360  return true;
361  }
362 
369  {
370  return grid_dist_key_dx<dim>(g_c,a_it.get());
371  }
372 
381  {
382  return gdb_ext;
383  }
384 
396  {
397  // Get the sub-domain id
398  size_t sub_id = k.getSub();
399 
400  grid_key_dx<dim> k_glob = k.getKey();
401 
402  // shift
403  k_glob = k_glob + gdb_ext.get(sub_id).origin;
404 
405  return k_glob;
406  }
407 
415  template<unsigned int id> inline grid_dist_lin_dx getStencil()
416  {
417  return grid_dist_lin_dx(g_c,a_it.template getStencil<id>());
418  }
419 };
420 
421 #endif /* GRID_DIST_ID_ITERATOR_SUB_HPP_ */
const openfpm::vector< GBoxes< device_grid::dims > > & gdb_ext
Extension of each grid: domain and ghost + domain.
grid_key_dx_iterator< dim, stencil > a_it
Actual iterator.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
grid_dist_lin_dx getStencil()
Return the stencil point offset.
grid_dist_lin_dx getStencil()
Return the stencil point offset.
grid_dist_iterator< dim, device_grid, FIXED > & operator++()
Get the next element.
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k)
Convert a g_dist_key_dx into a global key.
grid_key_dx< dim > getStop() const
it return the stop point of the iterator
Grid key for a distributed grid.
grid_key_dx< dim > stop
stop point (is the grid size)
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
grid_dist_iterator(openfpm::vector< device_grid > &gk, const openfpm::vector< GBoxes< device_grid::dims >> &gdb_ext, const grid_key_dx< dim > &stop)
Constructor of the distributed grid iterator.
This structure store the Box that define the domain inside the Ghost + domain box.
Definition: GBoxes.hpp:39
const openfpm::vector< GBoxes< device_grid::dims > > & getGBoxes()
Get the boxes.
const openfpm::vector< device_grid > & gList
List of the grids we are going to iterate.
bool isNext()
Check if there is the next element.
void selectValidGrid()
from g_c increment g_c until you find a valid grid
void zero()
Set to zero the key.
Definition: grid_key.hpp:116
grid_key_dx_iterator_sub< dim, stencil > a_it
Actual iterator.
grid_key_dx< dim > getStart() const
it return the start point of the iterator
grid_dist_iterator(openfpm::vector< device_grid > &gk, const openfpm::vector< GBoxes< device_grid::dims >> &gdb_ext, const grid_key_dx< dim > &stop, const grid_key_dx< dim >(&stencil_pnt)[stencil::nsp])
Constructor of the distributed grid iterator with stencil support.
void selectValidGrid()
from g_c increment g_c until you find a valid grid
openfpm::vector< device_grid > & gList
List of the grids we are going to iterate.
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k)
Convert a g_dist_key_dx into a global key.
const openfpm::vector< GBoxes< device_grid::dims > > & gdb_ext
Extension of each grid: domain and ghost + domain.
grid_dist_iterator(const openfpm::vector< device_grid > &gk, const openfpm::vector< GBoxes< device_grid::dims >> &gdb_ext)
Constructor of the distributed grid iterator.
bool isNext()
Check if there is the next element.
Distributed grid iterator.
grid_dist_iterator< dim, device_grid, FIXED > & operator=(const grid_dist_iterator< dim, device_grid, FIXED > &tmp)
Copy operator=.
size_t getSub() const
Get the local grid.
const openfpm::vector< GBoxes< device_grid::dims > > & getGBoxes()
Get the boxes.
grid_dist_iterator< dim, device_grid, FREE, stencil > & operator++()
Get the next element.
grid_key_dx< dim > getKey() const
Get the key.
Distributed linearized key.