34#ifndef Foam_GenericExpression_H
35#define Foam_GenericExpression_H
54 static constexpr bool is_leaf =
false;
60 return static_cast<E const&
>(*this).evaluate();
68#undef EXPRESSION_FUNCTION1
69#define EXPRESSION_FUNCTION1(BaseClass, Func, BaseFunc, OpFunc) \
70template<typename E1> \
73 public BaseClass<OpFunc<E1>> \
75 typename std::conditional<E1::is_leaf, const E1&, const E1>::type u_; \
78 static constexpr bool is_leaf = false; \
85 auto evaluate() const \
87 return BaseFunc(u_.evaluate()); \
90template<typename E1> \
93 const BaseClass<E1>& u \
96 return OpFunc<E1>(static_cast<const E1&>(u)); \
100#undef EXPRESSION_FUNCTION2
101#define EXPRESSION_FUNCTION2(BaseClass, Func, BaseFunc, OpFunc) \
102template<typename E1, typename E2> \
105 public BaseClass<OpFunc<E1, E2>> \
107 typename std::conditional<E1::is_leaf, const E1&, const E1>::type u_; \
108 typename std::conditional<E2::is_leaf, const E2&, const E2>::type v_; \
111 static constexpr bool is_leaf = false; \
113 OpFunc(const E1& u, const E2& v) \
117 auto evaluate() const \
119 return BaseFunc(u_.evaluate(), v_.evaluate()); \
122template<typename E1, typename E2> \
125 const BaseClass<E1>& u, \
126 const BaseClass<E2>& v \
129 return OpFunc<E1, E2> \
131 static_cast<const E1&>(u), \
132 static_cast<const E2&>(v) \
137#undef EXPRESSION_OPERATOR
138#define EXPRESSION_OPERATOR(BaseClass, Op, BaseOp, OpFunc) \
139template<typename E1, typename E2> \
148 typename std::conditional<E1::is_leaf, const E1&, const E1>::type u_; \
149 typename std::conditional<E2::is_leaf, const E2&, const E2>::type v_; \
152 static constexpr bool is_leaf = false; \
154 OpFunc(const E1& u, const E2& v) \
158 auto evaluate() const \
160 return u_.evaluate() BaseOp v_.evaluate(); \
163template<typename E1, typename E2> \
167 BaseClass<E1> const& u, \
168 BaseClass<E2> const& v \
171 return OpFunc<E1, E2> \
173 static_cast<const E1&>(u), \
174 static_cast<const E2&>(v) \
188 typename std::conditional<E1::is_leaf, const E1&, const E1>::type u_;
191 static constexpr bool is_leaf =
false;
200 return -u_.evaluate();
204g_negate<E1>
operator-
206 const GenericExpression<E1>& u
225#undef EXPRESSION_FUNCTION1
232#undef EXPRESSION_FUNCTION2
240#undef EXPRESSION_OPERATOR
#define EXPRESSION_OPERATOR(BaseClass, Op, BaseOp, OpFunc)
#define EXPRESSION_FUNCTION2(BaseClass, Func, BaseFunc, OpFunc)
#define EXPRESSION_FUNCTION1(BaseClass, Func, BaseFunc, OpFunc)
static constexpr bool is_leaf
g_add(const E1 &u, const E2 &v)
g_and(const E1 &u, const E2 &v)
g_bitand(const E1 &u, const E2 &v)
g_bitor(const E1 &u, const E2 &v)
g_divide(const E1 &u, const E2 &v)
g_multiply(const E1 &u, const E2 &v)
static constexpr bool is_leaf
g_or(const E1 &u, const E2 &v)
g_subtract(const E1 &u, const E2 &v)
g_xor(const E1 &u, const E2 &v)
A namespace for expression templates.
g_pow2< E1 > pow2(const GenericExpression< E1 > &u)
g_sqrt< E1 > sqrt(const GenericExpression< E1 > &u)
g_sqr< E1 > sqr(const GenericExpression< E1 > &u)
g_pow4< E1 > pow4(const GenericExpression< E1 > &u)
g_symm< E1 > symm(const GenericExpression< E1 > &u)
g_pow3< E1 > pow3(const GenericExpression< E1 > &u)
g_magSqr< E1 > magSqr(const GenericExpression< E1 > &u)
dimensionedSymmTensor sqr(const dimensionedVector &dv)