8 #ifndef OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_FUNCTIONS_HPP_
9 #define OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_FUNCTIONS_HPP_
17 #define CREATE_VDIST_ARG_FUNC(fun_base,fun_name,OP_ID) \
20 template <typename exp1>\
21 class vector_dist_expression_op<exp1,void,OP_ID>\
27 vector_dist_expression_op(const exp1 & o1)\
31 inline void init() const\
36 template<typename r_type=typename std::remove_reference<decltype(fun_base(o1.value(vect_dist_key_dx(0))))>::type > inline r_type value(const vect_dist_key_dx & key) const\
38 return fun_base(o1.value(key));\
43 template<typename exp1, typename exp2_, unsigned int op1>\
44 inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2_,op1>,void,OP_ID>\
45 fun_name(const vector_dist_expression_op<exp1,exp2_,op1> & va)\
47 vector_dist_expression_op<vector_dist_expression_op<exp1,exp2_,op1>,void,OP_ID> exp_sum(va);\
53 template<unsigned int prp1, typename v1>\
54 inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,void,OP_ID>\
55 fun_name(const vector_dist_expression<prp1,v1> & va)\
57 vector_dist_expression_op<vector_dist_expression<prp1,v1>,void,OP_ID> exp_sum(va);\
63 CREATE_VDIST_ARG_FUNC(norm,norm,VECT_NORM)
64 CREATE_VDIST_ARG_FUNC(norm2,norm2,VECT_NORM2)
65 CREATE_VDIST_ARG_FUNC(abs,abs,POINT_ABS)
66 CREATE_VDIST_ARG_FUNC(exp,exp,POINT_EXP)
67 CREATE_VDIST_ARG_FUNC(exp2,exp2,POINT_EXP2)
68 CREATE_VDIST_ARG_FUNC(expm1,expm1,POINT_EXPM1)
69 CREATE_VDIST_ARG_FUNC(log,log,POINT_LOG)
70 CREATE_VDIST_ARG_FUNC(log10,log10,POINT_LOG10)
71 CREATE_VDIST_ARG_FUNC(log2,log2,POINT_LOG2)
72 CREATE_VDIST_ARG_FUNC(log1p,log1p,POINT_LOG1P)
73 CREATE_VDIST_ARG_FUNC(sqrt,sqrt,POINT_SQRT)
74 CREATE_VDIST_ARG_FUNC(cbrt,cbrt,POINT_CBRT)
75 CREATE_VDIST_ARG_FUNC(sin,sin,POINT_SIN)
76 CREATE_VDIST_ARG_FUNC(cos,cos,POINT_COS)
77 CREATE_VDIST_ARG_FUNC(tan,tan,POINT_TAN)
78 CREATE_VDIST_ARG_FUNC(asin,asin,POINT_ASIN)
79 CREATE_VDIST_ARG_FUNC(acos,acos,POINT_ACOS)
80 CREATE_VDIST_ARG_FUNC(atan,atan,POINT_ATAN)
81 CREATE_VDIST_ARG_FUNC(sinh,sinh,POINT_SINH)
82 CREATE_VDIST_ARG_FUNC(cosh,cosh,POINT_COSH)
83 CREATE_VDIST_ARG_FUNC(tanh,tanh,POINT_TANH)
84 CREATE_VDIST_ARG_FUNC(asinh,asinh,POINT_ASINH)
85 CREATE_VDIST_ARG_FUNC(acosh,acosh,POINT_ACOSH)
86 CREATE_VDIST_ARG_FUNC(atanh,atanh,POINT_ATANH)
87 CREATE_VDIST_ARG_FUNC(erf,erf,POINT_ERF)
88 CREATE_VDIST_ARG_FUNC(erfc,erfc,POINT_ERFC)
89 CREATE_VDIST_ARG_FUNC(tgamma,tgamma,POINT_TGAMMA)
90 CREATE_VDIST_ARG_FUNC(lgamma,lgamma,POINT_LGAMMA)
91 CREATE_VDIST_ARG_FUNC(ceil,ceil,POINT_CEIL)
92 CREATE_VDIST_ARG_FUNC(floor,floor,POINT_FLOOR)
93 CREATE_VDIST_ARG_FUNC(trunc,trunc,POINT_TRUNC)
94 CREATE_VDIST_ARG_FUNC(round,round,POINT_ROUND)
95 CREATE_VDIST_ARG_FUNC(nearbyint,nearbyint,POINT_NEARBYINT)
96 CREATE_VDIST_ARG_FUNC(rint,rint,POINT_RINT)
105 #define CREATE_VDIST_ARG2_FUNC(fun_base,fun_name,OP_ID) \
108 template <typename exp1,typename exp2>\
109 class vector_dist_expression_op<exp1,exp2,OP_ID>\
116 vector_dist_expression_op(const exp1 & o1, const exp2 & o2)\
120 inline void init() const\
126 template<typename r_type=typename std::remove_reference<decltype(fun_base(o1.value(vect_dist_key_dx(0)),o2.value(vect_dist_key_dx(0)) ))>::type > inline r_type value(const vect_dist_key_dx & key) const\
128 return fun_base(o1.value(key),o2.value(key));\
133 template<unsigned int p1, unsigned int p2, typename v1, typename v2>\
134 inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,OP_ID>\
135 fun_name(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)\
137 vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,OP_ID> exp_sum(va,vb);\
142 template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>\
143 inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,OP_ID>\
144 fun_name(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<prp1,v1> & vb)\
146 vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,OP_ID> exp_sum(va,vb);\
151 template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>\
152 inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,OP_ID>\
153 fun_name(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)\
155 vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,OP_ID> exp_sum(va,vb);\
160 template<typename exp1 , typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>\
161 inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,OP_ID>\
162 fun_name(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)\
164 vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,OP_ID> exp_sum(va,vb);\
169 template<unsigned int prp1 , typename v1>\
170 inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,OP_ID>\
171 fun_name(const vector_dist_expression<prp1,v1> & va, double d)\
173 vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,OP_ID> exp_sum(va,vector_dist_expression<0,double>(d));\
178 template<unsigned int prp1 , typename v1>\
179 inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,OP_ID>\
180 fun_name(double d, const vector_dist_expression<prp1,v1> & vb)\
182 vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,OP_ID> exp_sum(vector_dist_expression<0,double>(d),vb);\
187 template<typename exp1 , typename exp2, unsigned int op1>\
188 inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,OP_ID>\
189 fun_name(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)\
191 vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,OP_ID> exp_sum(va,vector_dist_expression<0,double>(d));\
196 template<typename exp1 , typename exp2, unsigned int op1>\
197 inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression_op<exp1,exp2,op1>,OP_ID>\
198 fun_name(double d, const vector_dist_expression_op<exp1,exp2,op1> & va)\
200 vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,OP_ID> exp_sum(vector_dist_expression<0,double>(d),va);\
205 CREATE_VDIST_ARG2_FUNC(pmul,pmul,VECT_PMUL)
227 mutable typename std::remove_reference<rtype>::type
val;
230 const vector_type &
vd;
236 :o1(o1),val(0),vd(vd)
253 val += o1.value(
key);
260 inline typename std::remove_reference<rtype>::type
get()
274 template<
typename exp1,
typename exp2_,
unsigned int op1,
typename vector_type>
278 vector_dist_expression_op<vector_dist_expression_op<exp1,exp2_,op1>,vector_type,VECT_SUM_REDUCE> exp_sum(va,vd);
284 template<
unsigned int prp1,
typename v1,
typename vector_type>
288 vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_type,VECT_SUM_REDUCE> exp_sum(va,vd);
299 template <
typename T,
typename P>
auto distance(T exp1,
P exp2) -> decltype(norm(exp1 - exp2))
301 return norm(exp1 - exp2);
vector_dist_expression_op(const exp1 &o1, const vector_type &vd)
constructor from an epxression exp1 and a vector vd
std::remove_reference< rtype >::type val
return type of the calculated value (without reference)
const exp1 o1
expression on which apply the reduction
Grid key for a distributed grid.
void init() const
sum reduction require initialization where we calculate the reduction
apply_kernel_rtype< decltype(o1.value(vect_dist_key_dx()))>::rtype rtype
return type of this expression
const vector_type & vd
vector on which we apply the reduction expression
Unknown operation specialization.
Main class that encapsulate a vector properties operand to be used for expressions construction...
This class is a trick to indicate the compiler a specific specialization pattern. ...
r_type value(const vect_dist_key_dx &key) const
it return the result of the expression (precalculated before)
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
auto distance(T exp1, P exp2) -> decltype(norm(exp1-exp2))
General distance formula.
It give the return type of the expression if applicable.
Test structure used for several test.