OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
grid_key_expression.hpp
1 #ifndef GRID_KEY_EXPRESSION
2 #define GRID_KEY_EXPRESSION
3 
4 #include "util/common.hpp"
5 
6 template<unsigned int dim, typename index_type = long int> class grid_key_dx;
7 template<int dim, typename exp1, typename exp2> class grid_key_dx_sum;
8 template<int dim, typename exp1, typename exp2> class grid_key_dx_sub;
9 
10 
21 template<unsigned int dim, typename exp>
23 {
24 public:
25 
26  __device__ __host__ mem_id value(int i) const
27  {
28  return static_cast<const exp &>(*this).value(i);
29  }
30 
31  /* \brief subtract this expression with another expression
32  *
33  * \param key to subtract
34  *
35  * \return a grid_key_dx_expression that encapsulate the expression
36  *
37  */
38  template<typename index_type>
40  {
42 
43  return exp_sum;
44  }
45 
46  /* \brief subtract this expression a grid key
47  *
48  * \param key to subtract
49  *
50  * \return a grid_key_dx_expression that encapsulate the expression
51  *
52  */
53  template <typename T>
55  {
57 
58  return exp_sum;
59  }
60 
61  /* \brief subtract this expression with another expression
62  *
63  * \param key to subtract
64  *
65  * \return a grid_key_dx_expression that encapsulate the expression
66  *
67  */
68  template<typename index_type>
70  {
72 
73  return exp_sum;
74  }
75 
76  /* \brief subtract this expression a grid key
77  *
78  * \param key to subtract
79  *
80  * \return a grid_key_dx_expression that encapsulate the expression
81  *
82  */
83  template <typename T>
85  {
87 
88  return exp_sum;
89  }
90 };
91 
92 
100 template<int dim, typename exp1, typename exp2>
101 class grid_key_dx_sum : public grid_key_dx_expression<dim,grid_key_dx_sum<dim,exp1,exp2>>
102 {
103  const exp1 & e1;
104  const exp2 & e2;
105 
106 public:
107 
108  __device__ __host__ grid_key_dx_sum(const exp1 & ex1, const exp2 & ex2)
109  :e1(ex1),e2(ex2)
110  {}
111 
112  __device__ __host__ mem_id value(int i) const
113  {
114  return e1.value(i) + e2.value(i);
115  }
116 };
117 
125 template<int dim, typename exp1, typename exp2>
126 class grid_key_dx_sub : public grid_key_dx_expression<dim,grid_key_dx_sub<dim,exp1,exp2>>
127 {
128  const exp1 & e1;
129  const exp2 & e2;
130 
131 public:
132 
133  __device__ __host__ grid_key_dx_sub(const exp1 & ex1, const exp2 & ex2)
134  :e1(ex1),e2(ex2)
135  {}
136 
137  __device__ __host__ mem_id value(int i) const
138  {
139  return e1.value(i) - e2.value(i);
140  }
141 };
142 
143 #endif
Main class that encapsulate a sub expression.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
Expression template for grid_key_dx.
Main class that encapsulate a sum expression.