FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
node_functional.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
10#include <kernel/space/node_functional_base.hpp>
11#include <kernel/cubature/dynamic_factory.hpp>
12
13namespace FEAT
14{
15 namespace Space
16 {
17 namespace CroRavRanTur
18 {
19 template<
20 typename Space_,
21 typename Shape_,
22 int codim_,
23 typename DataType_>
25 public NodeFunctionalNull<Space_, DataType_>
26 {
27 public:
28 explicit NodeFunctional(const Space_& space) :
30 {
31 }
32 };
33
39 template<
40 typename Space_,
41 int shape_dim_,
42 typename DataType_>
43 class NodeFunctional<Space_, Shape::Simplex<shape_dim_>, 1, DataType_> :
44 public NodeFunctionalBase<Space_, DataType_>
45 {
46 public:
48 static constexpr int max_assigned_dofs = 1;
49
50 template<typename Function_>
51 struct Value
52 {
54 };
55
56 protected:
57 typedef typename Space_::TrafoType TrafoType;
58 typedef typename Space_::ShapeType ShapeType;
59 typedef typename Shape::FaceTraits<ShapeType, ShapeType::dimension-1>::ShapeType FacetType;
60 typedef typename TrafoType::template Evaluator<FacetType, DataType_>::Type TrafoEvalType;
61 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
62 typedef typename TrafoEvalTraits::DataType DataType;
63 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
64
65 static constexpr int image_dim = TrafoEvalTraits::image_dim;
66
67 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoEvalData;
68
69 TrafoEvalType _trafo_eval;
70 DomainPointType _barycentre;
71
72 public:
73 explicit NodeFunctional(const Space_& space) :
74 BaseClass(space),
75 _trafo_eval(space.get_trafo())
76 {
77 // initialize facet barycentre
78 for(int i(0); i < ShapeType::dimension-1; ++i)
79 _barycentre[i] = DataType_(1) / DataType_(shape_dim_);
80 }
81
82 void prepare(Index cell_index)
83 {
84 BaseClass::prepare(cell_index);
85 _trafo_eval.prepare(cell_index);
86 }
87
88 void finish()
89 {
90 _trafo_eval.finish();
92 }
93
94 int get_num_assigned_dofs() const
95 {
96 return max_assigned_dofs;
97 }
98
99 template<typename NodeData_, typename Function_>
100 void operator()(NodeData_& node_data, const Function_& function) const
101 {
102 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
103
104 // declare our evaluation traits
105 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
106
107 // declare function evaluator
108 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
109
110 // compute trafo data
111 TrafoEvalData trafo_data;
112 _trafo_eval(trafo_data, _barycentre);
113
114 // evaluate function
115 node_data[0] = func_eval.value(trafo_data.img_point);
116 }
117 };
118
124 template<
125 typename Space_,
126 int shape_dim_,
127 typename DataType_>
128 class NodeFunctional<Space_, Shape::Hypercube<shape_dim_>, 1, DataType_> :
129 public NodeFunctionalBase<Space_, DataType_>
130 {
131 public:
133 static constexpr int max_assigned_dofs = 1;
134
135 template<typename Function_>
136 struct Value
137 {
139 };
140
141 protected:
142 typedef typename Space_::TrafoType TrafoType;
143 typedef typename Space_::ShapeType ShapeType;
144 typedef typename Shape::FaceTraits<ShapeType, ShapeType::dimension-1>::ShapeType FacetType;
145 typedef typename TrafoType::template Evaluator<FacetType, DataType_>::Type TrafoEvalType;
146 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
147 typedef typename TrafoEvalTraits::DataType DataType;
148 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
149
150 static constexpr int image_dim = TrafoEvalTraits::image_dim;
151
152 // declare trafo evaluation data
154#if defined(FEAT_COMPILER_PGI) || (defined(FEAT_COMPILER_INTEL) && FEAT_COMPILER_INTEL >= 1800 && FEAT_COMPILER_INTEL < 1900)
155 static constexpr TrafoTags trafo_tags = TrafoTags::img_point | TrafoTags::jac_det;
156 typedef typename TrafoEvalType::template ConfigTraits<trafo_tags>::EvalDataType TrafoEvalData;
157#else
158 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point | TrafoTags::jac_det>::EvalDataType TrafoEvalData;
159#endif
160
162
163 TrafoEvalType _trafo_eval;
164 CubRuleType _cub_rule;
165
166 public:
167 explicit NodeFunctional(const Space_& space) :
168 BaseClass(space),
169 _trafo_eval(space.get_trafo()),
170 _cub_rule(Cubature::ctor_factory, Cubature::DynamicFactory("gauss-legendre:2"))
171 {
172 }
173
174 void prepare(Index cell_index)
175 {
176 BaseClass::prepare(cell_index);
177 _trafo_eval.prepare(cell_index);
178 }
179
180 void finish()
181 {
182 _trafo_eval.finish();
184 }
185
186 int get_num_assigned_dofs() const
187 {
188 return max_assigned_dofs;
189 }
190
191 template<typename NodeData_, typename Function_>
192 void operator()(NodeData_& node_data, const Function_& function) const
193 {
194 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
195
196 // declare our evaluation traits
197 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
198
199 // declare function evaluator
200 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
201
202 typename FuncEvalTraits::ValueType value(DataType_(0));
203 DataType_ mean(DataType_(0));
204 TrafoEvalData trafo_data;
205
206 // integrate over facet
207 for(int i(0); i < _cub_rule.get_num_points(); ++i)
208 {
209 _trafo_eval(trafo_data, _cub_rule.get_point(i));
210 value += (_cub_rule.get_weight(i) * trafo_data.jac_det) * func_eval.value(trafo_data.img_point);
211 mean += _cub_rule.get_weight(i) * trafo_data.jac_det;
212 }
213
214 // set integral mean
215 node_data[0] = (DataType_(1) / mean) * value;
216 }
217 };
218 } // namespace CroRavRanTur
219 } // namespace Space
220} // namespace FEAT
FEAT Kernel base header.
Cubature Rule class template.
Definition: rule.hpp:38
Crouzeix-Raviart / Rannacher-Turek Element Evaluator class template declaration.
Definition: evaluator.hpp:34
TrafoEvalType::template ConfigTraits< TrafoTags::img_point|TrafoTags::jac_det >::EvalDataType TrafoEvalData
Node-functional base class template.
void finish()
Releases the node-functional from the current cell.
void prepare(Index cell_index)
Prepares the node-functional for a given cell.
Null-Node-Functional class template.
int get_num_assigned_dofs() const
Returns the number of assigned dofs on the current cell.
NodeFunctionalBase< Space_, DataType_ > BaseClass
base-class typedef
void operator()(NodeData_ &node_data, const Function_ &function) const
Evaluation operator.
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
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
@ jac_det
specifies whether the trafo should supply jacobian determinants
Face traits tag struct template.
Definition: shape.hpp:106