5 #include <boost/shared_array.hpp>
7 #include <initializer_list>
9 #include "memory/memory.hpp"
10 #include "Space/Shape/Box.hpp"
11 #include "grid_key.hpp"
13 #include "util/mathutil.hpp"
14 #include "iterators/stencil_type.hpp"
17 #define NON_PERIODIC 0
39 static bool valid(
size_t v_id,
size_t sz)
64 static bool valid(
size_t v_id,
size_t sz)
71 template<
unsigned int N,
typename T>
class grid_sm;
77 template<
unsigned int dim,
typename stencil=no_stencil,
typename warn=pr
int_warning_on_adjustment<dim>>
class grid_key_dx_iterator_sub;
86 template<
unsigned int N,
typename T>
120 for (
size_t i = 1 ; i < N ; i++)
151 for (
size_t i = 1 ; i < N ; i++)
179 for (
size_t i = 1 ; i < N ; i++)
215 for (
size_t i = 0 ; i < N ; i++)
245 for (
size_t i = 0 ; i < N ; i++)
264 for (
size_t i = 0 ; i < N ; i++)
273 inline size_t totalSize(
const size_t sz)
277 for (
size_t i = 0 ; i < N ; i++)
287 inline size_t totalSize(
const size_t (& sz)[N])
291 for (
size_t i = 0 ; i < N ; i++)
337 template<
typename check=NoCheck>
inline mem_id
LinId(
const grid_key_dx<N> & gk,
const char sum_id[N])
const
343 if (check::valid(gk.
get(0) + sum_id[0],sz[0]) ==
false)
346 lid = gk.
get(0) + sum_id[0];
349 for (mem_id i = 1 ; i < N ; i++)
353 if (check::valid(gk.
get(i) + sum_id[i],sz[i]) ==
false)
356 lid += (gk.
get(i) + sum_id[i]) *
sz_s[i-1];
372 template<
typename check=NoCheck>
inline mem_id
LinId(
const grid_key_dx<N> & gk,
const char sum_id[N],
const size_t (&bc)[N])
const
378 if (bc[0] == NON_PERIODIC)
380 if (check::valid(gk.
get(0) + sum_id[0],sz[0]) ==
false)
383 lid = gk.
get(0) + sum_id[0];
387 lid = openfpm::math::positive_modulo(gk.
get(0) + sum_id[0],sz[0]);
390 for (mem_id i = 1 ; i < N ; i++)
395 if (bc[i] == NON_PERIODIC)
397 if (check::valid(gk.
get(i) + sum_id[i],sz[i]) ==
false)
400 lid += (gk.
get(i) + sum_id[i]) *
sz_s[i-1];
404 lid += (openfpm::math::positive_modulo(gk.
get(i) + sum_id[i],sz[i])) *
sz_s[i-1];
422 for (mem_id i = 1 ; i < N ; i++)
424 lid += k[i] *
sz_s[i-1];
439 inline mem_id
LinId(
const size_t (& k)[N])
const
442 for (mem_id i = 1 ; i < N ; i++)
445 lid += k[i] *
sz_s[i-1];
463 for (mem_id i = 1 ; i < N ; i++)
477 template<
typename a,
typename ...lT>
inline mem_id
Lin(a v,lT...t)
const
480 if (
sizeof...(t)+1 > N)
482 std::cerr <<
"Error incorrect grid cannot linearize more index than its dimensionality" <<
"\n";
486 return v*
sz_s[
sizeof...(t)-1] +
Lin(t...);
490 template<
typename a>
inline mem_id
Lin(a v)
const
509 for (mem_id i = 0 ; i < N ; i++)
511 gk.
set_d(i,
id % sz[i]);
531 mem_id
lid = gk.k[0];
532 for (mem_id i = 1 ; i < dim ; i++)
534 lid += gk.k[i] *
sz_s[i-1];
550 inline mem_id
LinId(mem_id *
id)
const
554 for (mem_id i = 1 ; i < N ; i++)
556 lid +=
id[i] *
sz_s[i-1];
588 for (
size_t i = 0 ; i < N ; i++)
607 for (
size_t i = 0 ; i < N ; i++)
609 if (sz[i] != g.
sz[i])
621 for (
size_t i = 0 ; i < N ; i++)
653 inline size_t size_s(
unsigned int i)
const
667 inline size_t size(
unsigned int i)
const
710 for (
size_t i = 0 ; i < N ; i++)
729 std::stringstream str;
731 for (
size_t i = 0 ; i < N ; i++)
732 str <<
"sz[" << i <<
"]=" <<
size(i) <<
" ";
738 template <
unsigned int,
typename>
friend class grid_sm;
779 for(
unsigned int i = 0 ; i < dim ; i++)
805 template<
typename a,
typename ...T>
void set(a v, T...t)
854 template<
typename a,
typename ...T>
void invert_assign(a v)
908 for (
size_t i = 0 ; i < dim ; i++)
931 for ( ; i < dim-1 ; i++)
933 size_t id = gk.
get(i);
952 for (
unsigned int s = 0 ; s <= i+1 ; s++)
954 gk.
set_d(i+1-s,
id+1+s);
981 if (gk.
get(dim-1) <
static_cast<mem_id
>(sz-dim+1))
Declaration print_warning_on_adjustment.
grid_sm()
Default constructor.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
size_t sz_s[N]
size of the grid on each stride (used for linearization)
mem_id Lin(a v) const
Linearize a set of index.
Iterator_g_const(size_t n, size_t sz)
Constructor.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
grid_key_dx is the key to access any element in the grid
const Box< N, size_t > getBoxKey() const
Return the box enclosing the grid.
void set_d(size_t i, mem_id id)
Set the i index.
grid_key_dx_r(size_t dim)
constructor
size_t size_s(unsigned int i) const
void set(a v, T...t)
set the grid key from a list of numbers
mem_id LinIdPtr(size_t *k) const
Linearization of the set of indexes.
size_t size() const
Return the size of the grid.
Emulate grid_key_dx with runtime dimensionality.
size_t size_tot
total number of the elements in the grid
const Box< N, size_t > & getBox() const
Return the box enclosing the grid.
Box< N, size_t > box
Box enclosing the grid.
T getHigh(int i) const
get the high interval of the box
static bool valid(size_t v_id, size_t sz)
Check if vertex exist.
void setHigh(int i, T val)
set the high interval of the box
mem_id LinId(const grid_key_d< dim, p > &gk) const
Linearization of the grid_key_d.
grid_key_dx_r(grid_key_dx_r &key)
constructor from another key
size_t sz[N]
size of the grid
bool operator==(const grid_sm< N, T > &g)
Check if the two grid_sm are the same.
bool operator!=(const grid_sm< N, T > &g)
Check if the two grid_sm are the same.
grid_key_dx< N > InvLinId(mem_id id) const
Construct.
mem_id LinId(const size_t(&k)[N]) const
Linearization of the grid_key_dx.
void invert_assign(a v, T...t)
Recursively invert the assignment.
mem_id get(size_t i) const
Get the i index.
void Initialize()
Initialize the basic structure.
grid_sm(const size_t &sz)
Construct a grid of a specified size.
static bool valid(size_t v_id, size_t sz)
No check is performed.
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
grid_sm(const grid_sm< N, S > &g)
construct a grid from another grid
grid_sm< N, T > & operator=(const grid_sm< N, T > &g)
Copy the grid from another grid.
size_t sz
size of the grid (the grid is assumed a square so equal on each dimension)
size_t getDim()
Get the dimensionality of the iterator.
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
void Initialize(const size_t(&sz)[N])
Initialize the basic structure.
mem_id Lin(a v, lT...t) const
linearize an arbitrary set of index
void setLow(int i, T val)
set the low interval of the box
This class is a trick to indicate the compiler a specific specialization pattern. ...
Iterator_g_const & operator++()
Get the next element.
mem_id LinId(const grid_key_dx< N > &gk) const
Linearization of the grid_key_dx.
grid_key_d is the key to access any element in the grid
Declaration grid_key_dx_iterator_sub.
size_t size(unsigned int i) const
Class to check if the edge can be created or not.
bool isNext()
Check if there is the next element.
mem_id LinId(mem_id *id) const
Linearization of an array of mem_id (long int)
std::string toString() const
Produce a string from the object.
void set_d(size_t i, mem_id id)
Set the i index.
mem_id * k
structure that store all the index
grid_key_dx_iterator_sub< N > getSubIterator(grid_key_dx< N > &start, grid_key_dx< N > &stop) const
Return a sub-grid iterator.
Class to check if the edge can be created or not.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N], const size_t(&bc)[N]) const
Linearization of the grid_key_dx with a specified shift.
void Initialize(const size_t sz)
Initialize the basic structure.
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
size_t getDim()
Get the dimensionality of the key.
grid_sm(const size_t(&sz)[N])
Construct a grid of a specified size.