8 #ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SUB_HPP_
9 #define OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SUB_HPP_
17 template <
unsigned int dim>
21 inline static void pw1(
size_t i,
const grid_key_dx<dim> & gk_start) {std::cerr <<
"Warning: " << __FILE__ <<
":" << __LINE__ <<
" start with index smaller than zero x[" << i <<
"]=" << gk_start.
get(i) <<
"\n";}
22 inline static void pw2(
size_t i,
const grid_key_dx<dim> & gk_start) {std::cerr <<
"Warning: " << __FILE__ <<
":" << __LINE__ <<
" Cropping start point x[" << i <<
"]=" << gk_start.
get(i) <<
" to x[" << i <<
"]=0 \n" ;}
23 inline static void pw3() {std::cerr <<
"Warning: " << __FILE__ <<
":" << __LINE__ <<
" stop with smaller index than start \n";}
24 inline static void pw4(
size_t i,
const grid_key_dx<dim> & gk_stop,
const grid_sm<dim,void> & grid_base) {std::cerr <<
"Warning: " << __FILE__ <<
":" << __LINE__ <<
" stop index bigger than cell domain x[" << i <<
"]=" << gk_stop.
get(i) <<
" >= " << grid_base.
size(i) <<
"\n";}
25 inline static void pw5() {std::cerr <<
"Warning grid_key_dx_iterator_sub: " << __FILE__ <<
":" << __LINE__ <<
" the starting point is not smaller or equal than than the stop point in all the coordinates" <<
"\n";}
35 template <
unsigned int dim>
41 inline static void pw3() {}
43 inline static void pw5() {}
60 template<
unsigned int dim,
typename warn>
64 bool initialized =
false;
83 for (
size_t i = 0 ; i < dim ; i++)
86 if (gk_start.
get(i) < 0)
89 warn::pw1(i,gk_start);
91 if (gk_start.
get(i) < gk_stop.
get(i))
94 warn::pw2(i,gk_start);
104 gk_start.
set_d(dim-1,gk_stop.
get(dim-1)+1);
110 if (gk_stop.
get(i) >= (
long int)grid_base.
size(i))
113 warn::pw4(i,gk_stop,grid_base);
116 if (gk_start.
get(i) < (
long int)grid_base.
size(i))
121 gk_start.
set_d(dim-1,gk_stop.
get(dim-1)+1);
128 for (
unsigned int i = 0 ; i < dim ; i++)
130 this->gk.set_d(i,gk_start.
get(i));
183 for (
unsigned int i = 0 ; i < dim ; i++)
185 if (gk_start.
get(i) > gk_stop.
get(i))
212 for (
unsigned int i = 0 ; i < dim ; i++)
240 for (
unsigned int i = 0 ; i < dim ; i++)
242 if (start[i] > stop[i])
263 if (initialized ==
false)
264 {std::cerr <<
"Error: " << __FILE__ << __LINE__ <<
" using unitialized iterator" <<
"\n";}
269 size_t id = this->gk.get(0);
270 this->gk.set_d(0,
id+1);
275 for ( ; i < dim-1 ; i++)
277 size_t id = this->gk.get(i);
278 if ((
long int)
id > gk_stop.
get(i))
282 this->gk.set_d(i,gk_start.
get(i));
283 id = this->gk.get(i+1);
284 this->gk.set_d(i+1,
id+1);
306 if (initialized ==
false)
307 {std::cerr <<
"Error: " << __FILE__ << __LINE__ <<
" using unitialized iterator" <<
"\n";}
310 if (this->gk.get(dim-1) <= gk_stop.
get(dim-1))
327 if (initialized ==
false)
328 {std::cerr <<
"Error: " << __FILE__ << __LINE__ <<
" using unitialized iterator" <<
"\n";}
357 for (
unsigned int i = 0 ; i < dim ; i++)
359 if (gk_start.
get(i) > gk_stop.
get(i))
388 for (
size_t i = 0 ; i < dim ; i++)
389 {this->gk.set_d(i,gk_start.
get(i));}
419 template<
typename warn>
grid_key_dx_iterator_sub(const grid_sm< dim, T > &g, const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop)
Constructor require a grid grid<dim,T>
void reinitialize(const grid_key_dx_iterator_sub< dim, warn > &g_s_it)
Reinitialize the iterator.
mem_id k[dim]
structure that store all the index
void reinitialize(const grid_key_dx_iterator< dim > &key)
Reinitialize the grid_key_dx_iterator.
grid_key_dx is the key to access any element in the grid
size_t size() const
Return the size of the grid.
grid_key_dx_iterator< dim > & operator++()
Get the next element.
void Initialize()
Initialize gk.
bool isNext()
Check if there is the next element.
const grid_sm< dim, void > & getGridInfo()
Return the grid information related to this grid.
grid_key_dx_iterator_sub(const grid_sm< dim, T > &g, const size_t(&start)[dim], const size_t(&stop)[dim])
Constructor require a grid grid<dim,T>
mem_id get(size_t i) const
Get the i index.
grid_key_dx< dim > gk_stop
stop point
grid_key_dx_iterator_sub(const grid_sm< dim, T > &g, const size_t m)
Constructor require a grid grid<dim,T>
grid_sm< dim, void > grid_base
grid base where we are iterating
void reset()
Reset the iterator (it restart from the beginning)
grid_key_dx< dim > gk_start
start point
const grid_key_dx< dim > & get()
Get the actual key.
grid_key_dx_iterator_sub(const grid_key_dx_iterator_sub< dim > &g_s_it)
Constructor from another grid_key_dx_iterator_sub.
void set(a v, T...t)
set the grid key from a list of numbers
void set_d(size_t i, mem_id id)
Set the i index.
T getVolumeKey() const
Get the volume spanned by the Box P1 and P2 interpreted as grid key.
size_t getVolume()
Get the volume spanned by this sub-grid iterator.
grid_key_dx_iterator_sub()
Default constructor.