12 #ifndef MFEM_TEMPLATE_COEFFICIENT
13 #define MFEM_TEMPLATE_COEFFICIENT
15 #include "../config/tconfig.hpp"
16 #include "../linalg/ttensor.hpp"
17 #include "../linalg/tlayout.hpp"
18 #include "../linalg/vector.hpp"
37 template <
typename complex_t =
double>
50 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
51 inline MFEM_ALWAYS_INLINE
52 void Eval(
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
const
54 TAssign<AssignOp::Set>(l, c,
value);
65 template <
typename Func,
typename complex_t =
double>
75 template <
int dim,
bool dummy>
struct Dim;
76 template <
bool dummy>
struct Dim<1,dummy>
78 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
79 static inline MFEM_ALWAYS_INLINE
80 void Eval(Func &
F,
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
82 const int qpts = T_result_t::x_type::layout_type::dim_1;
83 const int ne = T_result_t::x_type::layout_type::dim_3;
84 for (
int k = 0; k < ne; k++)
86 for (
int i = 0; i < qpts; i++)
88 c[l.ind(i,k)] = F.Eval1D(T.x(i,0,k));
93 template <
bool dummy>
struct Dim<2,dummy>
95 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
96 static inline MFEM_ALWAYS_INLINE
97 void Eval(Func &
F,
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
99 const int qpts = T_result_t::x_type::layout_type::dim_1;
100 const int ne = T_result_t::x_type::layout_type::dim_3;
101 for (
int k = 0; k < ne; k++)
103 for (
int i = 0; i < qpts; i++)
105 c[l.ind(i,k)] = F.Eval2D(T.x(i,0,k), T.x(i,1,k));
110 template <
bool dummy>
struct Dim<3,dummy>
112 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
113 static inline MFEM_ALWAYS_INLINE
114 void Eval(Func &
F,
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
116 const int qpts = T_result_t::x_type::layout_type::dim_1;
117 const int ne = T_result_t::x_type::layout_type::dim_3;
118 for (
int k = 0; k < ne; k++)
120 for (
int i = 0; i < qpts; i++)
122 c[l.ind(i,k)] = F.Eval3D(T.x(i,0,k), T.x(i,1,k), T.x(i,2,k));
135 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
136 inline MFEM_ALWAYS_INLINE
137 void Eval(
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
139 const int qpts = T_result_t::x_type::layout_type::dim_1;
140 const int sdim = T_result_t::x_type::layout_type::dim_2;
141 const int ne = T_result_t::x_type::layout_type::dim_3;
142 MFEM_STATIC_ASSERT(c_layout_t::rank == 2 && c_layout_t::dim_1 == qpts &&
143 c_layout_t::dim_2 == ne,
"invalid c_layout_t");
152 template <
typename complex_t =
double>
165 : constants(constants) { }
168 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
169 inline MFEM_ALWAYS_INLINE
170 void Eval(
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
172 const int ne = T_result_t::ne;
173 for (
int i = 0; i < ne; i++)
175 TAssign<AssignOp::Set>(l.ind2(i), c,
constants(T.attrib[i]-1));
181 template <
typename FieldEval>
197 inline MFEM_ALWAYS_INLINE
204 inline MFEM_ALWAYS_INLINE
209 :
fieldEval(tfes, shapeEval, vec_layout, data, NULL)
213 inline MFEM_ALWAYS_INLINE
220 inline MFEM_ALWAYS_INLINE
222 :
fieldEval(*func.FESpace(), func.GetData(), NULL)
227 template <
typename T_result_t,
typename c_layout_t,
typename c_data_t>
228 inline MFEM_ALWAYS_INLINE
229 void Eval(
const T_result_t &T,
const c_layout_t &l, c_data_t &c)
231 const int ne = T_result_t::ne;
232 const int vdim = FieldEval::vdim;
233 const int qpts = FieldEval::qpts;
234 MFEM_STATIC_ASSERT(c_layout_t::rank == 2,
"tensor rank must be 2");
235 MFEM_STATIC_ASSERT(c_layout_t::dim_1 == qpts,
"incompatible quadrature");
236 MFEM_STATIC_ASSERT(c_layout_t::dim_2 == ne,
"");
237 MFEM_STATIC_ASSERT(vdim == 1,
"vdim != 1 is not supported");
239 fieldEval.GetValues(T.first_elem_idx, l.template split_2<1,ne>(), c);
246 template <
typename IR,
typename coeff_t,
int NE>
249 static const int qpts = IR::qpts;
250 static const int ne = NE;
253 template <
bool is_const,
bool dummy>
struct Aux;
256 template <
bool dummy>
struct Aux<true,dummy>
258 typedef struct { } result_t;
261 inline MFEM_ALWAYS_INLINE
Aux(
const IR &int_rule,
const coeff_t &c)
263 c.Eval(
true, cw.layout, cw);
264 int_rule.ApplyWeights(cw);
267 template <
typename T_result_t>
268 inline MFEM_ALWAYS_INLINE
269 void Eval(
const T_result_t &F, result_t &res) { }
271 inline MFEM_ALWAYS_INLINE
278 template <
bool dummy>
struct Aux<false,dummy>
281 #ifdef MFEM_TEMPLATE_INTRULE_COEFF_PRECOMP
288 #ifdef MFEM_TEMPLATE_INTRULE_COEFF_PRECOMP
289 inline MFEM_ALWAYS_INLINE
Aux(
const IR &int_rule,
const coeff_t &c)
292 int_rule.template AssignWeights<AssignOp::Set>(w.layout, w);
295 inline MFEM_ALWAYS_INLINE
Aux(
const IR &int_rule,
const coeff_t &c)
296 : int_rule(int_rule), c(c) { }
298 template <
typename T_result_t>
299 inline MFEM_ALWAYS_INLINE
302 c.Eval(F, res.
layout, res);
303 #ifdef MFEM_TEMPLATE_INTRULE_COEFF_PRECOMP
304 for (
int i = 0; i <
ne; i++)
306 TAssign<AssignOp::Mult>(res.
layout.
ind2(i), res,
310 int_rule.template AssignWeights<AssignOp::Mult>(res.
layout, res);
314 inline MFEM_ALWAYS_INLINE
326 #endif // MFEM_TEMPLATE_COEFFICIENT
TMatrix< qpts, ne, complex_type > result_t
static const bool uses_Jacobians
TFunctionCoefficient(Func &F_)
Class for grid function - Vector with associated FE space.
FieldEval::FESpace_type FESpace_type
static const layout_type layout
static const bool uses_coordinates
MFEM_ALWAYS_INLINE Aux(const IR &int_rule, const coeff_t &c)
static MFEM_ALWAYS_INLINE void Eval(Func &F, const T_result_t &T, const c_layout_t &l, c_data_t &c)
MFEM_ALWAYS_INLINE TGridFunctionCoefficient(const GridFunction &func)
FieldEval::complex_type complex_type
static const bool uses_attributes
static const bool uses_element_idxs
FieldEval::ShapeEval_type ShapeEval_type
static const bool uses_element_idxs
static const bool uses_coordinates
static const bool is_const
MFEM_ALWAYS_INLINE void Eval(const T_result_t &T, const c_layout_t &l, c_data_t &c)
coeff_t::complex_type complex_type
static MFEM_ALWAYS_INLINE void Eval(Func &F, const T_result_t &T, const c_layout_t &l, c_data_t &c)
MFEM_ALWAYS_INLINE TGridFunctionCoefficient(const FESpace_type &tfes, const ShapeEval_type &shapeEval, const VecLayout_type &vec_layout, const complex_type *data)
MFEM_ALWAYS_INLINE Aux(const IR &int_rule, const coeff_t &c)
Aux< coeff_t::is_const, true > Type
TPiecewiseConstCoefficient(const Vector &constants)
Note: in the input array index i corresponds to mesh attribute i+1.
MFEM_ALWAYS_INLINE void Eval(const T_result_t &F, result_t &res)
static StridedLayout1D< N1 *N2,(S1< S2)?S1:S2 > merge_12()
static const bool is_const
TConstantCoefficient(complex_t val)
MFEM_ALWAYS_INLINE void Eval(const T_result_t &T, const c_layout_t &l, c_data_t &c) const
FieldEval::VecLayout_type VecLayout_type
MFEM_ALWAYS_INLINE void Eval(const T_result_t &F, result_t &res)
TMatrix< qpts, 1, complex_type > cw
static MFEM_ALWAYS_INLINE void Eval(Func &F, const T_result_t &T, const c_layout_t &l, c_data_t &c)
static OffsetStridedLayout1D< N1, S1 > ind2(int i2)
TMatrix< qpts, 1, typename IR::real_type > w
MFEM_ALWAYS_INLINE void Eval(const T_result_t &T, const c_layout_t &l, c_data_t &c)
MFEM_ALWAYS_INLINE TGridFunctionCoefficient(const FieldEval &fE, const complex_type *data)
static const bool uses_attributes
MFEM_ALWAYS_INLINE TGridFunctionCoefficient(const FiniteElementSpace &fes, const complex_type *data)
MFEM_ALWAYS_INLINE void Eval(const T_result_t &T, const c_layout_t &l, c_data_t &c)