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.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 
22 template<typename Decomposition>
24 {
26  size_t g_c;
27 
30 
33 
36 
39 
41  typename Decomposition::stype spacing[Decomposition::dims];
42 
43 
48  {
49  // start and stop for the subset grid
52 
53  // When the grid has size 0 potentially all the other informations are garbage
54  while (g_c < gdb_ext.size() &&
55  (gdb_ext.get(g_c).Dbox.isValid() == false || compute_subset<Decomposition>(gdb_ext,g_c,start,stop,start_c,stop_c) == false ))
56  {g_c++;}
57 
58  // get the next grid iterator
59  if (g_c < gdb_ext.size())
60  {
61  // Calculate the resolution of the local grid
62  size_t sz[Decomposition::dims];
63  for (size_t i = 0 ; i < Decomposition::dims ; i++)
64  sz[i] = gdb_ext.get(g_c).GDbox.getP2()[i] + 1;
65 
68  }
69  }
70 
77  {
79  }
80 
81  public:
82 
91  {
92  g_c = tmp.g_c;
93  gdb_ext = tmp.gdb_ext;
94  a_it.reinitialize(tmp.a_it);
95 
96  start = tmp.start;
97  stop = tmp.stop;
98 
99  return *this;
100  }
101 
108  {
109  this->operator=(tmp);
110  }
111 
118  grid_dist_id_iterator_dec(Decomposition & dec, const size_t (& sz)[Decomposition::dims])
119  :g_c(0)
120  {
121  // Initialize start and stop
122  start.zero();
123  for (size_t i = 0 ; i < Decomposition::dims ; i++)
124  stop.set_d(i,sz[i]-1);
125 
126  // From the decomposition construct gdb_ext
127  create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,sz,dec.getDomain(),spacing);
128 
129  // Initialize the current iterator
130  // with the first grid
131  selectValidGrid();
132  }
133 
143  :g_c(0),start(start),stop(stop)
144  {
145  // From the decomposition construct gdb_ext
146  create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,sz,dec.getDomain(),spacing);
147 
148  // Initialize the current iterator
149  // with the first grid
150  selectValidGrid();
151  }
152 
153  // Destructor
155  {
156  }
157 
165  {
166  ++a_it;
167 
168  // check if a_it is at the end
169 
170  if (a_it.isNext() == true)
171  {return *this;}
172  else
173  {
174  // switch to the new grid
175  g_c++;
176 
177  selectValidGrid();
178  }
179 
180  return *this;
181  }
182 
188  inline bool isNext()
189  {
190  // If there are no other grid stop
191 
192  if (g_c >= gdb_ext.size())
193  return false;
194 
195  return true;
196  }
197 
203  inline typename Decomposition::stype getSpacing(size_t i)
204  {
205  return spacing[i];
206  }
207 
215  {
217 
218  // Get the sub-domain id
219  size_t sub_id = k.getSub();
220 
222 
223  // shift
224  k_glob = k_glob + gdb_ext.get(sub_id).origin;
225 
226  return k_glob;
227  }
228 
238  {
239  return get_int();
240  }
241 
248  {
249  return start;
250  }
251 
258  {
259  return stop;
260  }
261 };
262 
263 
264 #endif /* SRC_GRID_GRID_DIST_ID_ITERATOR_DEC_HPP_ */
grid_dist_id_iterator_dec< Decomposition > & operator=(const grid_dist_id_iterator_dec< Decomposition > &tmp)
Copy operator=.
Decomposition::stype spacing[Decomposition::dims]
Spacing.
grid_dist_id_iterator_dec(const grid_dist_id_iterator_dec< Decomposition > &tmp)
Copy constructor.
grid_dist_id_iterator_dec(Decomposition &dec, const size_t(&sz)[Decomposition::dims])
Constructor of the distributed grid iterator.
Given the decomposition it create an iterator.
grid_dist_key_dx< Decomposition::dims > get_int()
Get the actual key.
size_t size()
Stub size.
Definition: map_vector.hpp:70
grid_dist_key_dx< Decomposition::dims > get_dist()
Get the actual grid key for a distributed grid.
Grid key for a distributed 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 > start
start key
bool isNext()
Check if there is the next element.
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
This class define the domain decomposition interface.
Decomposition::stype getSpacing(size_t i)
Get the spacing of the grid.
grid_dist_id_iterator_dec< Decomposition > & operator++()
Get the next element.
openfpm::vector< GBoxes< Decomposition::dims > > gdb_ext
Extension of each grid: domain and ghost + domain.
grid_key_dx< Decomposition::dims > getStart()
Get the starting point of the sub-grid we are iterating.
void zero()
Set to zero the key.
Definition: grid_key.hpp:116
grid_key_dx< Decomposition::dims > stop
stop key
grid_key_dx_iterator_sub< Decomposition::dims > a_it
Actual iterator.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
grid_key_dx< Decomposition::dims > getStop()
Get the starting point of the sub-grid we are iterating.
Declaration grid_sm.
Definition: grid_sm.hpp:71
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_key.hpp:407
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
bool isNext()
Check if there is the next element.
void selectValidGrid()
from g_c increment g_c until you find a valid grid
size_t getSub() const
Get the local grid.
void reinitialize(const grid_key_dx_iterator_sub< dim > &g_s_it)
Reinitialize the iterator.
grid_key_dx< dim > getKey() const
Get the key.