OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
21template<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
46template<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
70template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
71struct 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
77template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
78struct 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
84template<typename T, typename T_ker, typename type_prp ,template<typename> class layout_base>
85struct 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
107template<unsigned int dim, typename S, typename Memory>
109{
112
115
117 typedef typename S::value_type obj_type;
118
120 typedef typename S::value_type::type ov_seq;
121
124
136
137
138#ifdef SE_CLASS1
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
170template<typename T>
172{
173 typedef T& type;
174};
175
180enum 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_ */
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
this class is a functor for "for_each" algorithm
grid_key_dx< dim > & key
size to allocate
S::value_type obj_type
type of the object we have to set
void operator()(T &t) const
It call the copy function for each property.
S & grid_dst
grid where we have to store the data
S::value_type::type ov_seq
type of the object boost::sequence
copy_cpu_encap(grid_key_dx< dim > &key, S &grid_dst, const encapc< 1, obj_type, Memory > &obj)
constructor
const encapc< 1, obj_type, Memory > & obj
object we have to store
Metafunction take T and return a reference.
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition meta_copy.hpp:60
this class is a functor for "for_each" algorithm
void operator()(T &t)
It call the copy function for each property.