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"
16 #define NON_PERIODIC 0
38 static bool valid(
size_t v_id,
size_t sz)
61 static bool valid(
size_t v_id,
size_t sz)
69 template<
unsigned int N,
typename T>
class grid_sm;
80 template<
unsigned int N,
typename T>
124 for(
size_t i = 0 ; i < N ; i++)
152 for (
size_t i = 1 ; i < N ; i++)
179 for (
size_t i = 1 ; i < N ; i++)
259 for (
size_t i = 0 ; i < N ; i++)
268 inline size_t totalSize(
const size_t (&
sz)[N])
272 for (
size_t i = 0 ; i < N ; i++)
282 inline size_t totalSize(
const std::vector<size_t> &
sz)
288 for(
size_t i = 0 ; i < N ; i++)
293 return totalSize(sz_a);
337 for (
size_t i = 1 ; i < sz.size() && N > 1 ; i++)
354 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
360 if (bc[0] == NON_PERIODIC)
362 if (check::valid(gk.
k[0] + sum_id[0],sz[0]) ==
false)
365 lid = gk.
k[0] + sum_id[0];
369 lid = openfpm::math::positive_modulo(gk.
k[0] + sum_id[0],sz[0]);
372 for (mem_id i = 1 ; i < N ; i++)
376 if (bc[i] == NON_PERIODIC)
378 if (check::valid(gk.
k[i] + sum_id[i],sz[i]) ==
false)
381 lid += (gk.
k[i] + sum_id[i]) *
sz_s[i-1];
385 lid += (openfpm::math::positive_modulo(gk.
k[i] + sum_id[i],sz[i])) *
sz_s[i-1];
404 for (mem_id i = 1 ; i < N ; i++)
406 lid += k[i] *
sz_s[i-1];
421 inline mem_id
LinId(
const size_t (& k)[N])
const
424 for (mem_id i = 1 ; i < N ; i++)
426 lid += k[i] *
sz_s[i-1];
443 mem_id lid = gk.
k[0];
444 for (mem_id i = 1 ; i < N ; i++)
446 lid += gk.
k[i] *
sz_s[i-1];
457 template<
typename a,
typename ...lT>
inline mem_id
Lin(a v,lT...t)
const
460 if (
sizeof...(t)+1 > N)
462 std::cerr <<
"Error incorrect grid cannot linearize more index than its dimensionality" <<
"\n";
466 return v*
sz_s[
sizeof...(t)-1] +
Lin(t...);
470 template<
typename a>
inline mem_id
Lin(a v)
const
489 for (mem_id i = 0 ; i < N ; i++)
491 gk.
set_d(i,
id % sz[i]);
511 mem_id lid = gk.k[0];
512 for (mem_id i = 1 ; i < dim ; i++)
514 lid += gk.k[i] *
sz_s[i-1];
530 inline mem_id
LinId(mem_id *
id)
const
534 for (mem_id i = 1 ; i < N ; i++)
536 lid +=
id[i] *
sz_s[i-1];
568 for (
size_t i = 0 ; i < N ; i++)
587 for (
size_t i = 0 ; i < N ; i++)
589 if (sz[i] != g.
sz[i])
601 for (
size_t i = 0 ; i < N ; i++)
633 inline size_t size_s(
unsigned int i)
const
647 inline size_t size(
unsigned int i)
const
659 std::vector<size_t> vect_sz;
661 for (
int i = 0 ; i < N ; i++)
663 vect_sz.push_back(sz[i]);
707 for (
size_t i = 0 ; i < N ; i++)
720 template <
unsigned int,
typename>
friend class grid_sm;
761 for(
unsigned int i = 0 ; i < dim ; i++)
787 template<
typename a,
typename ...T>
void set(a v, T...t)
836 template<
typename a,
typename ...T>
void invert_assign(a v)
890 for (
size_t i = 0 ; i < dim ; i++)
913 for ( ; i < dim-1 ; i++)
915 size_t id = gk.
get(i);
934 for (
unsigned int s = 0 ; s <= i+1 ; s++)
936 gk.
set_d(i+1-s,
id+1+s);
963 if (gk.
get(dim-1) <
static_cast<mem_id
>(sz-dim+1))
grid_sm(std::vector< size_t > &sz)
Construct a grid of a specified size.
grid_sm()
Default constructor.
mem_id k[dim]
structure that store all the index
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.
grid_key_dx is the key to access any element in 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 mulLin(size_t a, size_t b)
It multiplicate two number and return the result.
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.
void Initialize(std::vector< size_t > &sz)
Initialize the basic structure.
static bool valid(size_t v_id, size_t sz)
Check is performed.
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.
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.
void setDimensions(std::vector< size_t > &dims)
Reset the dimension of the grid.
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
bool isLinearizeLinear()
Is linearize additive.
This class is a trick to indicate the compiler a specific specialization pattern. ...
grid_sm(std::vector< size_t > &&sz)
Construct a grid of a specified size.
Iterator_g_const & operator++()
Get the next element.
mem_id LinId(const grid_key_dx< N > &gk) const
Linearization of the grid_key_dx.
class that store the information of the grid like number of point on each direction and define the in...
grid_key_d is the key to access any element in the grid
size_t size(unsigned int i) const
Class to check if the edge can be created or not.
std::vector< size_t > getVectorSize()
Return the size of the grid as an std::vector.
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)
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 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.