FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
evaluator_base.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/trafo/eval_data.hpp>
10
11namespace FEAT
12{
13 namespace Trafo
14 {
16 namespace Intern
17 {
18 template<bool _enable>
19 struct TrafoEvalHelper;
20 } // namespace Intern
22
37 template<
38 typename Trafo_,
39 typename Evaluator_,
40 typename EvalPolicy_>
42 {
43 public:
45 typedef Trafo_ TrafoType;
47 typedef typename TrafoType::ShapeType ShapeType;
48
50 typedef EvalPolicy_ EvalPolicy;
51
53 typedef EvalPolicy_ EvalTraits;
54
56 typedef typename EvalPolicy::DataType DataType;
58 typedef typename EvalPolicy::DomainPointType DomainPointType;
60 typedef typename EvalPolicy::ImagePointType ImagePointType;
62 typedef typename EvalPolicy::JacobianMatrixType JacobianMatrixType;
64 typedef typename EvalPolicy::JacobianInverseType JacobianInverseType;
66 typedef typename EvalPolicy::JacobianDeterminantType JacobianDeterminantType;
68 typedef typename EvalPolicy::HessianTensorType HessianTensorType;
70 typedef typename EvalPolicy::HessianInverseType HessianInverseType;
71
73 static constexpr int domain_dim = EvalPolicy::domain_dim;
75 static constexpr int image_dim = EvalPolicy::image_dim;
76
79
80 // Note:
81 // The following block serves as an element interface documentation and is therefore only
82 // visible to doxygen. The actual functionality has to be supplied by the implementation.
83#ifdef DOXYGEN
84 static constexpr TrafoTags eval_caps = ...;
85#endif // DOXYGEN
86
93 template<TrafoTags cfg_>
95 {
96 static constexpr TrafoTags config =
98 (*(cfg_ & TrafoTags::hess_inv) ?
99 TrafoTags::hess_inv : TrafoTags::none) |
102 TrafoTags::hess_ten : TrafoTags::none) |
104 (*(cfg_ & TrafoTags::jac_det) ?
105 TrafoTags::jac_det : TrafoTags::none) |
108 TrafoTags::jac_inv : TrafoTags::none) |
110 //(*(cfg_ & (TrafoTags::jac_mat | TrafoTags::jac_det | TrafoTags::jac_inv | TrafoTags::hess_inv | TrafoTags::normal)) ?
112 TrafoTags::jac_mat : TrafoTags::none) |
114 (*(cfg_ & TrafoTags::normal) ?
115 TrafoTags::normal : TrafoTags::none) |
117 (*(cfg_ & (TrafoTags::img_point)) ?
118 TrafoTags::img_point : TrafoTags::none) |
121
124 }; // struct ConfigTraits<...>
125
126 protected:
128 Evaluator_& cast()
129 {
130 return static_cast<Evaluator_&>(*this);
131 }
132
133 const Evaluator_& cast() const
134 {
135 return static_cast<const Evaluator_&>(*this);
136 }
138
141
144
146 explicit EvaluatorBase(const TrafoType& trafo) :
147 _trafo(trafo),
148 _cell_index(~Index(0))
149 {
150 }
151
152 public:
156 const TrafoType& get_trafo() const
157 {
158 return _trafo;
159 }
160
165 {
166 return 0;
167 }
168
173 {
174 return get_num_cells();
175 }
176
184 {
185 return _trafo.get_mesh().get_num_entities(domain_dim);
186 }
187
192 {
193 return _cell_index;
194 }
195
202 void prepare(const CellIterator& cell)
203 {
204 // store cell index
205 _cell_index = cell;
206 }
207
211 void finish()
212 {
213 // reset cell index
214 _cell_index = ~Index(0);
215 }
216
228 template<TrafoTags cfg_>
230 {
231 // typedef mumbo-jumbo
232 typedef Trafo::EvalData<EvalTraits, cfg_> TrafoData;
233
234 // Note:
235 // The following static constexpr bool variables are required to
236 // circumvent a compiler bug in GCC 6.1
237
238 // store domain point
239 static constexpr bool want_dom_point = *(TrafoData::config & TrafoTags::dom_point);
240 Intern::TrafoEvalHelper<want_dom_point>::set_dom_point(trafo_data, dom_point);
241 // map image point
242 static constexpr bool want_img_point = *(TrafoData::config & TrafoTags::img_point);
243 Intern::TrafoEvalHelper<want_img_point>::map_img_point(trafo_data, cast());
244 // calculate jacobian matrix
245 static constexpr bool want_jac_mat = *(TrafoData::config & TrafoTags::jac_mat);
246 Intern::TrafoEvalHelper<want_jac_mat>::calc_jac_mat(trafo_data, cast());
247 // calculate inverse jacobian matrix
248 static constexpr bool want_jac_inv = *(TrafoData::config & TrafoTags::jac_inv);
249 Intern::TrafoEvalHelper<want_jac_inv>::calc_jac_inv(trafo_data, cast());
250 // calculate jacobian determinants
251 static constexpr bool want_jac_det = *(TrafoData::config & TrafoTags::jac_det);
252 Intern::TrafoEvalHelper<want_jac_det>::calc_jac_det(trafo_data, cast());
253 // calculate hessian tensor
254 static constexpr bool want_hess_ten = *(TrafoData::config & TrafoTags::hess_ten);
255 Intern::TrafoEvalHelper<want_hess_ten>::calc_hess_ten(trafo_data, cast());
256 // calculate inverse hessian tensor
257 static constexpr bool want_hess_inv = *(TrafoData::config & TrafoTags::hess_inv);
258 Intern::TrafoEvalHelper<want_hess_inv>::calc_hess_inv(trafo_data, cast());
259
260 // note: normal vectors are computed directly by the assembler classes
261 // calculate normal vector
262 //static constexpr bool want_normal = *(TrafoData::config & TrafoTags::normal);
263 //Intern::TrafoEvalHelper<want_normal>::calc_normal(trafo_data, cast());
264 }
265
266 // Note:
267 // The following block serves as an element interface documentation and is therefore only
268 // visible to doxygen. The actual functionality has to be supplied by the implementation.
269#ifdef DOXYGEN
280
291
302
310
330#endif // DOXYGEN
331 }; // class EvaluatorBase<...>
332
334 namespace Intern
335 {
336 template<bool _enable>
337 struct TrafoEvalHelper
338 {
339 template<typename TrafoData_, typename DomPoint_>
340 static void set_dom_point(TrafoData_&, const DomPoint_&) {}
341
342 template<typename TrafoData_, typename Evaluator_>
343 static void map_img_point(TrafoData_&, const Evaluator_&) {}
344
345 template<typename TrafoData_, typename Evaluator_>
346 static void calc_jac_mat(TrafoData_&, const Evaluator_&) {}
347
348 template<typename TrafoData_, typename Evaluator_>
349 static void calc_jac_inv(TrafoData_&, const Evaluator_&) {}
350
351 template<typename TrafoData_, typename Evaluator_>
352 static void calc_jac_det(TrafoData_&, const Evaluator_&) {}
353
354 template<typename TrafoData_, typename Evaluator_>
355 static void calc_hess_ten(TrafoData_&, const Evaluator_&) {}
356
357 template<typename TrafoData_, typename Evaluator_>
358 static void calc_hess_inv(TrafoData_&, const Evaluator_&) {}
359
360 //template<typename TrafoData_, typename Evaluator_>
361 //static void calc_normal(TrafoData_&, const Evaluator_&) {}
362 };
363
364 template<>
365 struct TrafoEvalHelper<true>
366 {
367 template<typename TrafoData_, typename DomPoint_>
368 static void set_dom_point(TrafoData_& trafo_data, const DomPoint_& dom_point)
369 {
370 trafo_data.dom_point = dom_point;
371 }
372
373 template<typename TrafoData_, typename Evaluator_>
374 static void map_img_point(TrafoData_& trafo_data, const Evaluator_& evaluator)
375 {
376 if(!*(Evaluator_::eval_caps & TrafoTags::img_point))
377 XABORTM("trafo evaluator can't compute image point coordinates");
378 evaluator.map_point(trafo_data.img_point, trafo_data.dom_point);
379 }
380
381 template<typename TrafoData_, typename Evaluator_>
382 static void calc_jac_mat(TrafoData_& trafo_data, const Evaluator_& evaluator)
383 {
384 if(!*(Evaluator_::eval_caps & TrafoTags::jac_mat))
385 XABORTM("trafo evaluator can't compute jacobian matrices");
386 // let the evaluator compute the jacobian matrix
387 evaluator.calc_jac_mat(trafo_data.jac_mat, trafo_data.dom_point);
388 }
389
390 template<typename TrafoData_, typename Evaluator_>
391 static void calc_jac_inv(TrafoData_& trafo_data, const Evaluator_&)
392 {
393 if(!*(Evaluator_::eval_caps & TrafoTags::jac_inv))
394 XABORTM("trafo evaluator can't compute jacobian inverse matrices");
395 // invert the jacobian matrix
396 trafo_data.jac_inv.set_inverse(trafo_data.jac_mat);
397 }
398
399 template<typename TrafoData_, typename Evaluator_>
400 static void calc_jac_det(TrafoData_& trafo_data, const Evaluator_&)
401 {
402 if(!*(Evaluator_::eval_caps & TrafoTags::jac_det))
403 XABORTM("trafo evaluator can't compute jacobian determinants");
404 // compute the volume of the jacobian matrix
405 trafo_data.jac_det = trafo_data.jac_mat.vol();
406 }
407
408 template<typename TrafoData_, typename Evaluator_>
409 static void calc_hess_ten(TrafoData_& trafo_data, const Evaluator_& evaluator)
410 {
411 if(!*(Evaluator_::eval_caps & TrafoTags::hess_ten))
412 XABORTM("trafo evaluator can't compute hessian tensors");
413 // let the evaluator compute the hessian tensor
414 evaluator.calc_hess_ten(trafo_data.hess_ten, trafo_data.dom_point);
415 }
416
417 template<typename TrafoData_, typename Evaluator_>
418 static void calc_hess_inv(TrafoData_& trafo_data, const Evaluator_&)
419 {
420 if(!*(Evaluator_::eval_caps & TrafoTags::hess_inv))
421 XABORTM("trafo evaluator can't compute inverse hessian tensors");
422
423 typedef typename TrafoData_::EvalTraits EvalTraits;
424 typedef typename EvalTraits::DataType DataType;
425 typename EvalTraits::HessianTensorType hess_jac;
426
427 // compute inverse
428 hess_jac.format();
429 hess_jac.add_double_mat_mult(trafo_data.hess_ten, trafo_data.jac_inv, trafo_data.jac_inv);
430 trafo_data.hess_inv.format();
431 trafo_data.hess_inv.add_mat_tensor_mult(trafo_data.jac_inv, hess_jac, -DataType(1));
432 }
433
434 /*template<typename TrafoData_, typename Evaluator_>
435 static void calc_normal(TrafoData_& trafo_data, const Evaluator_&)
436 {
437 if(!*(Evaluator_::eval_caps & TrafoTags::normal))
438 XABORTM("trafo evaluator can't compute normal vectors");
439 // compute the normal vector from of the jacobian matrix
440 trafo_data.normal = Tiny::orthogonal(trafo_data.jac_mat);
441 trafo_data.normal.normalize();
442 }*/
443 };
444 } // namespace Intern
446 } // namespace Trafo
447} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
Trafo evaluation data structure.
Definition: eval_data.hpp:33
Trafo Evaluator CRTP base-class template.
EvalPolicy_ EvalTraits
evaluation traits; identical to eval policy
CellIterator end() const
Returns a CellIterator representing the first index past the last cell.
EvalPolicy_ EvalPolicy
evaluation policy
static constexpr int domain_dim
domain dimension
const TrafoType & get_trafo() const
Returns a reference to the trafo object.
EvaluatorBase(const TrafoType &trafo)
constructor
Index get_num_cells() const
Returns the number of cells in the mesh.
void finish()
Finishes the evaluator for the currently active cell.
void calc_jac_mat(JacobianMatrixType &jac_mat, const DomainPointType &dom_point) const
Computes the jacobian matrix for a given domain point.
EvalPolicy::DomainPointType DomainPointType
domain point type
void operator()(Trafo::EvalData< EvalTraits, cfg_ > &trafo_data, const DomainPointType &dom_point) const
Trafo evaluation operator.
void calc_hess_ten(HessianTensorType &hess_ten, const DomainPointType &dom_point) const
Computes the hessian tensor for a given domain point.
EvalPolicy::HessianTensorType HessianTensorType
hessian tensor type
void prepare(const CellIterator &cell)
Prepares the evaluator for a given cell.
EvalPolicy::JacobianMatrixType JacobianMatrixType
jacobian matrix type
static constexpr int image_dim
image dimension
EvalPolicy::JacobianInverseType JacobianInverseType
jacobian inverse matrix type
EvalPolicy::DataType DataType
evaluation data type
TrafoType::ShapeType ShapeType
shape type
DataType width_directed(const ImagePointType &ray) const
Computes and returns the directed mesh width.
const TrafoType & _trafo
trafo reference
Index CellIterator
CellIterator typedef.
EvalPolicy::HessianInverseType HessianInverseType
hessian inverse tensor type
DataType volume() const
Computes and returns the volume of the current cell.
void map_point(ImagePointType &img_point, const DomainPointType &dom_point) const
Maps a domain point from the reference cell to the currently active cell.
EvalPolicy::JacobianDeterminantType JacobianDeterminantType
jacobian determinant type
Index _cell_index
currently active cell index
Index get_cell_index() const
Returns the index of the currently active cell.
CellIterator begin() const
Returns a CellIterator representing the index of the first cell.
EvalPolicy::ImagePointType ImagePointType
image point type
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
TrafoTags
Trafo configuration tags enum.
Definition: eval_tags.hpp:22
@ img_point
specifies whether the trafo should supply image point coordinates
@ hess_inv
specifies whether the trafo should supply inverse hessian tensors
@ dom_point
specifies whether the trafo should supply domain point coordinates
@ hess_ten
specifies whether the trafo should supply hessian tensors
@ jac_inv
specifies whether the trafo should supply inverse jacobian matrices
@ jac_mat
specifies whether the trafo should supply jacobian matrices
@ jac_det
specifies whether the trafo should supply jacobian determinants
Trafo configuration traits class template.
Trafo::EvalData< EvalTraits, config > EvalDataType
evaluation data typedef