OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
grid_common.hpp
1 /*
2  * grid_common.hpp
3  *
4  * Created on: Oct 31, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_GRID_COMMON_HPP_
9 #define OPENFPM_DATA_SRC_GRID_GRID_COMMON_HPP_
10 
11 #include <type_traits>
12 #include "util/tokernel_transformation.hpp"
13 
21 template<typename aggrT_src, typename local_grids_type>
23 {
24  aggrT_src & bck;
25 
26  local_grids_type & loc_grid;
27 
28  inline setBackground_impl(aggrT_src & bck, local_grids_type & loc_grid)
29  :bck(bck),loc_grid(loc_grid)
30  {};
31 
33  template<typename T>
34  inline void operator()(T& t)
35  {
36  for (size_t i = 0 ; i < loc_grid.size() ; i++)
37  {
38  loc_grid.get(i).template setBackgroundValue<T::value>(bck.template get<T::value>());
39  }
40  }
41 };
42 
44 
45 
46 template<typename T, typename T_ker, typename type_prp, template<typename> class layout_base , int is_vector>
48 {
49  template<typename mem_type, typename obj_type> static void destruct(mem_type * mem, obj_type & obj)
50  {
51  size_t sz = mem->size() / sizeof(type_prp);
52  // The type of device and the type on host does not match (in general)
53  // So we have to convert before transfer
54 
55  mem_type tmp;
56 
57  tmp.allocate(mem->size());
58 
59  mem->deviceToHost(tmp);
60  T_ker * ptr = static_cast<T_ker *>(tmp.getPointer());
61 
62  for(size_t i = 0 ; i < sz ; i++)
63  {
64  ptr->~T_ker();
65  ++ptr;
66  }
67  }
68 };
69 
70 template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
71 struct call_recursive_destructor_if_vector<T,T_ker,type_prp,layout_base,0>
72 {
73  template<typename mem_type,typename obj_type> static void destruct(mem_type * mem, obj_type & obj)
74  {}
75 };
76 
77 template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
78 struct call_recursive_destructor_if_vector<T,T_ker,type_prp,layout_base,3>
79 {
80  template<typename mem_type,typename obj_type> static void destruct(mem_type * mem, obj_type & obj)
81  {}
82 };
83 
84 template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
85 struct call_recursive_destructor_if_vector<T,T_ker,type_prp,layout_base,4>
86 {
87  template<typename mem_type,typename obj_type> static void destruct(mem_type * mem, obj_type & obj)
88  {}
89 };
90 
92 
107 template<unsigned int dim, typename S, typename Memory>
109 {
112 
114  S & grid_dst;
115 
117  typedef typename S::value_type obj_type;
118 
120  typedef typename S::value_type::type ov_seq;
121 
124 
135  :key(key),grid_dst(grid_dst),obj(obj){};
136 
137 
138 #ifdef SE_CLASS1
139 
147  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object";};
148 #endif
149 
151  template<typename T>
152  inline void operator()(T& t) const
153  {
154  // Remove the reference from the type to copy
155  typedef typename boost::remove_reference<decltype(grid_dst.template get<T::value>(key))>::type copy_rtype;
156 
157  meta_copy<copy_rtype>::meta_copy_(obj.template get<T::value>(),grid_dst.template get<T::value>(key));
158  }
159 };
160 
161 
170 template<typename T>
172 {
173  typedef T& type;
174 };
175 
180 enum rem_copy_opt
181 {
182  NONE_OPT = 0,
183  PHASE1 = 0,
184  PHASE2 = 1,
185  PHASE3 = 2,
186  // This option indicate that the geometrical structure of the sparse-grid has not changed
187  KEEP_GEOMETRY = 4,
188 };
189 
190 #endif /* OPENFPM_DATA_SRC_GRID_GRID_COMMON_HPP_ */
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition: meta_copy.hpp:60
void operator()(T &t) const
It call the copy function for each property.
S::value_type obj_type
type of the object we have to set
const encapc< 1, obj_type, Memory > & obj
object we have to store
this class is a functor for "for_each" algorithm
Metafunction take T and return a reference.
copy_cpu_encap(grid_key_dx< dim > &key, S &grid_dst, const encapc< 1, obj_type, Memory > &obj)
constructor
this class is a functor for "for_each" algorithm
Definition: grid_common.hpp:22
void operator()(T &t)
It call the copy function for each property.
Definition: grid_common.hpp:34
grid_key_dx< dim > & key
size to allocate
S & grid_dst
grid where we have to store the data
S::value_type::type ov_seq
type of the object boost::sequence