-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPde_Expression_Templates.h
More file actions
199 lines (171 loc) · 5.39 KB
/
Pde_Expression_Templates.h
File metadata and controls
199 lines (171 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//
// Created by simonepanzeri on 26/11/2021.
//
#ifndef DEV_FDAPDE_PDE_EXPRESSION_TEMPLATES_H
#define DEV_FDAPDE_PDE_EXPRESSION_TEMPLATES_H
#include "Finite_Element.h"
//Forward declarations!
template <UInt ORDER, UInt mydim, UInt ndim>
class FiniteElement;
enum class PDEParameterOptions;
template<PDEParameterOptions OPTION>
class Diffusion;
struct Stiff {
template<UInt ORDER, UInt mydim, UInt ndim>
Real operator() (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return fe_.stiff_impl(iq, i, j);
}
};
struct Grad {
template<UInt ORDER, UInt mydim, UInt ndim>
Real operator() (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return fe_.grad_impl(iq, i, j);
}
};
struct Mass {
template<UInt ORDER, UInt mydim, UInt ndim>
Real operator() (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return fe_.mass_impl(iq, i, j);
}
};
template<typename A>
class EOExpr{
//! "A" is a generic type
A a_;
public:
//! A constructor.
/*!
* \param object is a constant reference to a generic operator.
*/
EOExpr(const A& a) : a_(a) {}
template<UInt ORDER, UInt mydim, UInt ndim>
Real operator() (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return a_(fe_, iq, i, j);
}
};
template<>
class EOExpr<Stiff>{
//! "A" is a generic type
Stiff a_;
public:
//! A constructor.
/*!
* \param object is a constant reference to a generic operator.
*/
EOExpr(const Stiff& a) : a_(a) {}
template<PDEParameterOptions OPTION>
EOExpr<const Diffusion<OPTION>&> operator[] (const Diffusion<OPTION>& K){
typedef EOExpr<const Diffusion<OPTION>&> ExprT;
return ExprT(K);
}
template<UInt ORDER, UInt mydim, UInt ndim>
Real operator() (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return a_(fe_, iq, i, j);
}
};
//composition of two wrappers (operator)
//composition of two wrappers (operator)
template<typename A, typename B, typename Op>
class EOBinOp{
//! "A" is a generic type.
/*!
* Stores the first operand.
*/
A a_;
//! "B" is a generic type.
/*!
* Stores the second operand.
*/
B b_;
public:
//! A constructor.
/*!
* \param a is a constant reference to a generic type.
* \param b is a constant reference to a generic type.
*/
EOBinOp(const A& a ,const B& b) : a_(a), b_(b) {}
//! A definition of operator () taking two arguments.
/*!
* \param i is an unsigned int
* \param j is an unsigned int
* applies the generic operation defined by the type Op to the two generic objects a_, b_;
* returns a type P variable
*/
template<UInt ORDER,UInt mydim,UInt ndim>
Real operator () (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return Op::apply(a_(fe_, iq, i, j), b_(fe_, iq, i, j));
}
};
template<class B, class Op>
class EOBinOp<Real, B, Op>{
Real M_a;
B M_b;
public:
EOBinOp(Real a, const B& b) : M_a(a), M_b(b) {};
template<UInt ORDER, UInt mydim, UInt ndim>
Real operator () (const FiniteElement<ORDER,mydim,ndim>& fe_, UInt iq, UInt i, UInt j) const {
return Op::apply(M_a, M_b(fe_, iq, i, j));
}
};
//wrappers addition
//! A ETWAdd class: Expression Template Wrapper Addition
/*!
* Class that defines Addition operation, following:
* "Expression Templates Implementation of Continuous and DIscontinous Galerkin Methods"
* D.A. Di Pietro, A. Veneziani
*/
struct EOAdd{
//! A static inline method taking two arguments.
/*!
*The actual addition operation
* \param a is of P type, first addend
* \param b is of P type, second addend
*/
template<class T, class V>
static auto apply(const T& a, const V& b) -> decltype(a+b) {
return a+b;
}
};
//multiplication by real scalar
//! A ETWMult class: Expression Template Wrapper Multiplication.
/*!
* Class that defines Multiplication operation, following:
* "Expression Templates Implementation of Continuous and DIscontinous Galerkin Methods"
* D.A. Di Pietro, A. Veneziani
*/
struct EOMult{
//! A static inline method taking two arguments.
/*!
* The actual multiplication operation.
* \param a is of P type, first operand
* \param b is a Real, second operand
*/
template<class T>
static auto apply(Real a, const T &b) -> decltype(a*b) {
return a*b;
}
};
//operator +
//! Overloading of operator +.
/*!
* Following:
* "Expression Templates Implementation of Continuous and DIscontinous Galerkin Methods"
* D.A. Di Pietro, A. Veneziani
* Takes two arguments:
* \param a is const reference ETWrapper<P, A>
* \param b is const reference ETWrapper<P, A>
* \return a ETWrapper<P,ETWBinOp<P, ETWrapper<P,A>, ETWrapper<P, B>, ETWAdd<P> > which is resolved at compile time.
*/
template<typename A, typename B>
EOExpr<EOBinOp<EOExpr<A>, EOExpr<B>, EOAdd> >
operator + (const EOExpr<A>& a, const EOExpr<B>& b){
typedef EOBinOp<EOExpr<A>, EOExpr<B>, EOAdd > ExprT;
return EOExpr<ExprT> (ExprT(a,b));
}
template<typename B>
EOExpr<EOBinOp<Real, EOExpr<B>, EOMult> >
operator * (Real a, const EOExpr<B>& b){
typedef EOBinOp<Real, EOExpr<B>, EOMult> ExprT;
return EOExpr<ExprT> (ExprT(a,b));
}
#endif //DEV_FDAPDE_PDE_EXPRESSION_TEMPLATES_H