8 #ifndef OPENFPM_DATA_SRC_GRID_GRID_BASE_IMPLEMENTATION_HPP_
9 #define OPENFPM_DATA_SRC_GRID_GRID_BASE_IMPLEMENTATION_HPP_
11 #include "grid_base_impl_layout.hpp"
12 #include "copy_grid_fast.hpp"
25 template<
unsigned int dim,
typename T,
typename S,
typename layout_,
template<
typename>
class layout_base >
37 static constexpr
unsigned int dims = dim;
67 inline void check_init()
const
71 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" you must call SetMemory before access the grid\n";
72 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
83 for (
long int i = 0 ; i < dim ; i++)
87 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << v1.
get(i) <<
" >= " <<
getGrid().
size(i) <<
"\n";
88 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
90 else if (v1.
get(i) < 0)
92 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << v1.
get(i) <<
" is negative " <<
"\n";
93 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
103 inline void check_bound(
size_t v1)
const
107 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " << v1<<
" >= " <<
getGrid().
size() <<
"\n";
108 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
122 for (
size_t i = 0 ; i < dim ; i++)
126 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" >= " << g.
getGrid().
size(i) <<
"\n";
127 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
129 else if (key2.
get(i) < 0)
131 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" is negative " <<
"\n";
132 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
149 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " << key2 <<
" >= " <<
getGrid().
size() <<
"\n";
150 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
159 #include "grid_pack_unpack.ipp"
180 check_new(
this,8,GRID_EVENT,1);
206 check_new(
this,8,GRID_EVENT,1);
222 check_new(
this,8,GRID_EVENT,1);
246 check_new(
this,8,GRID_EVENT,1);
264 check_new(
this,8,GRID_EVENT,1);
332 grid_new.set(it.
get(),*
this,it.
get());
418 if (
data_.mem_r == NULL)
421 return data_.mem_r->get_pointer();
437 if (
data_.mem_r == NULL)
440 return data_.mem_r->get_pointer();
450 template <
unsigned int p,
typename r_type=decltype(mem_get<p,layout_base<T>,layout,gr
id_sm<dim,T>,gr
id_key_dx<dim>>::get(data_,g1,gr
id_key_dx<dim>()))>
inline r_type
get(
const grid_key_dx<dim> & v1)
469 template <
unsigned int p,
typename r_type=decltype(mem_get<p,layout_base<T>,layout,gr
id_sm<dim,T>,gr
id_key_dx<dim>>::get(data_,g1,gr
id_key_dx<dim>()))>
489 template <
unsigned int p,
typename r_type=decltype(mem_get<p,layout_base<T>,layout,gr
id_sm<dim,T>,gr
id_key_dx<dim>>::get_lin(data_,g1,0))>
490 inline r_type
get(
const size_t lin_id)
509 template <
unsigned int p,
typename r_type=decltype(mem_get<p,layout_base<T>,layout,gr
id_sm<dim,T>,gr
id_key_dx<dim>>::get_lin(data_,g1,0))>
inline const r_type
get(
size_t lin_id)
const
674 for (
size_t i = 0 ; i < dim ; i++)
697 this->
swap(grid_new);
713 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" remove work only on dimension == 1 " <<
"\n";
720 data_.move(&this->
template get<0>());
795 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
817 this->
get_o(dx) = obj;
853 inline void set(
const size_t key1,
961 template<
unsigned int Np>
1003 return check_whoami(
this,8);
void swap(grid_base_impl< dim, T, S, layout, layout_base > &&grid)
It move the allocated object from one grid to another.
grid_key_dx< dim > access_key
Access key.
grid_sm< dim, T > g1
This is a structure that store all information related to the grid and how indexes are linearized...
void * getPointer()
Return a plain pointer to the internal data.
grid_key_dx is the key to access any element in the grid
void set(grid_key_dx< dim > dx, const encapc< 1, T, Memory > &obj)
set an element of the grid
memory_traits_lin< typename T::type >::type memory_lin
Definition of the layout.
T value_type
The object type the grid is storing.
grid_base_impl() THROW
Default constructor.
size_t size() const
Return the size of the grid.
r_type get(const grid_key_dx< dim > &v1)
Get the reference of the selected element.
void resize(const size_t(&sz)[dim])
Resize the space.
bool operator==(const grid_base_impl< dim, T, S, layout, layout_base > &g)
Compare two grids.
bool is_mem_init
Is the memory initialized.
encapc< dim, T, layout > get_o(const grid_key_dx< dim > &v1)
Get the of the selected element as a boost::fusion::vector.
~grid_base_impl() THROW
Destructor.
grid_key_dx_iterator_sub< dim > getSubIterator(grid_key_dx< dim > &start, grid_key_dx< dim > &stop) const
Return a sub-grid iterator.
layout data_
Memory layout specification + memory chunk pointer.
encapc< dim, T, layout > get_o(size_t v1)
Get the of the selected element as a boost::fusion::vector.
void set(const size_t key1, const grid_base_impl< dim, T, S, layout, layout_base > &g, const size_t key2)
Set an element of the grid from another element of another grid.
this class is a functor for "for_each" algorithm
T::type T_type
boost::vector that describe the data type
grid_key_dx_iterator_sub< dim > getSubIterator(size_t m)
Return a sub-grid iterator.
mem_id get(size_t i) const
Get the i index.
void set(const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, S, layout, layout_base > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
void set(const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, Mem, layout, layout_base > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
grid_base_impl(const size_t &sz) THROW
create a grid of size sz on each direction
const encapc< dim, T, layout > get_o(size_t v1) const
Get the of the selected element as a boost::fusion::vector.
const grid_sm< dim, T > & getGrid() const
Return the internal grid information.
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
grid_base_impl< dim, T, S, layout, layout_base > & operator=(grid_base_impl< dim, T, S, layout, layout_base > &&g)
It copy a grid.
layout_ layout_type
memory layout
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
const grid_key_dx< dim > & get() const
Get the actual key.
grid_base_impl(const grid_base_impl &g) THROW
create a grid from another grid
void fill(unsigned char fl)
Fill the memory with the selected byte.
size_t size() const
return the size of the grid
void setMemory()
Create the object that provide memory.
bool isNext()
Check if there is the next element.
long int who()
It return the id of structure in the allocation list.
grid_base_impl(const size_t(&sz)[dim]) THROW
Constructor.
This class is a trick to indicate the compiler a specific specialization pattern. ...
grid_base_impl< dim, T, S, layout, layout_base > & operator=(const grid_base_impl< dim, T, S, layout, layout_base > &g)
It copy a grid.
const encapc< dim, T, layout > get_o(const grid_key_dx< dim > &v1) const
Get the of the selected element as a boost::fusion::vector.
grid_key_dx_iterator_sub< dim > getIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
Return a grid iterator over all points included between start and stop point.
void swap(grid_base_impl< dim, T, S, layout, layout_base > &grid)
It move the allocated object from one grid to another.
int yes_i_am_grid
it define that it is a grid
const void * getPointer() const
Return a plain pointer to the internal data.
This class is a container for the memory interface like HeapMemory CudaMemory.
void setMemory(S &m)
Get the object that provide memory.
static constexpr unsigned int dims
expose the dimansionality as a static const
void set(grid_key_dx< dim > dx, const T &obj)
set an element of the grid
grid_key_dx_iterator< dim > getIterator() const
Return a grid iterator.
layout_ layout
memory layout
grid_key_dx_iterator_sub< N > getSubIterator(grid_key_dx< N > &start, grid_key_dx< N > &stop) const
Return a sub-grid iterator.
encapc< dim, T, layout > container
Object container for T, it is the return type of get_o it return a object type trough.
grid_base_impl< dim, T, S, layout, layout_base > duplicate() const THROW
create a duplicated version of the grid
grid_key_dx_iterator< dim, stencil_offset_compute< dim, Np > > getIteratorStencil(const grid_key_dx< dim >(&stencil_pnt)[Np]) const
Return a grid iterator.
bool isExternal
The memory allocator is not internally created.
Implementation of a N-dimensional grid.