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 Q1TBNP
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::Hypercube<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 // declare trafo evaluation data
68 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point | TrafoTags::jac_det>::EvalDataType TrafoEvalData;
69
71
72 TrafoEvalType _trafo_eval;
73 CubRuleType _cub_rule;
74
75 public:
76 explicit NodeFunctional(const Space_& space) :
77 BaseClass(space),
78 _trafo_eval(space.get_trafo()),
79 _cub_rule(Cubature::ctor_factory, Cubature::DynamicFactory("gauss-legendre:2"))
80 {
81 }
82
83 void prepare(Index cell_index)
84 {
85 BaseClass::prepare(cell_index);
86 _trafo_eval.prepare(cell_index);
87 }
88
89 void finish()
90 {
91 _trafo_eval.finish();
93 }
94
95 int get_num_assigned_dofs() const
96 {
97 return max_assigned_dofs;
98 }
99
100 template<typename NodeData_, typename Function_>
101 void operator()(NodeData_& node_data, const Function_& function) const
102 {
103 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
104
105 // declare our evaluation traits
106 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
107
108 // declare function evaluator
109 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
110
111 typename FuncEvalTraits::ValueType value(DataType_(0));
112 DataType_ mean(DataType_(0));
113 TrafoEvalData trafo_data;
114
115 // integrate over facet
116 for(int i(0); i < _cub_rule.get_num_points(); ++i)
117 {
118 _trafo_eval(trafo_data, _cub_rule.get_point(i));
119 value += (_cub_rule.get_weight(i) * trafo_data.jac_det) * func_eval.value(trafo_data.img_point);
120 mean += _cub_rule.get_weight(i) * trafo_data.jac_det;
121 }
122
123 // set integral mean
124 node_data[0] = (DataType_(1) / mean) * value;
125 }
126 };
127
133 template<
134 typename Space_,
135 typename DataType_>
136 class NodeFunctional<Space_, Shape::Hypercube<2>, 0, DataType_> :
137 public NodeFunctionalBase<Space_, DataType_>
138 {
139 public:
141 static constexpr int max_assigned_dofs = 1;
142
143 template<typename Function_>
144 struct Value
145 {
147 };
148
149 protected:
150 typedef typename Space_::TrafoType TrafoType;
151 typedef typename Space_::ShapeType ShapeType;
152 typedef typename TrafoType::template Evaluator<ShapeType, DataType_>::Type TrafoEvalType;
153 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
154 typedef typename TrafoEvalTraits::DataType DataType;
155 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
156 typedef typename TrafoEvalTraits::ImagePointType ImagePointType;
157 typedef typename TrafoEvalTraits::JacobianInverseType JacobianInverseType;
158
159 static constexpr int image_dim = TrafoEvalTraits::image_dim;
160
161 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point | TrafoTags::jac_det>::EvalDataType TrafoEvalData;
162 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point | TrafoTags::jac_inv>::EvalDataType InvLinTrafoData;
163
165
166 TrafoEvalType _trafo_eval;
167 CubRuleType _cub_rule;
168
169 JacobianInverseType _inv_lin_mat;
170 ImagePointType _inv_lin_vec;
171
172 public:
173 explicit NodeFunctional(const Space_& space) :
174 BaseClass(space),
175 _trafo_eval(space.get_trafo()),
176 _cub_rule(Cubature::ctor_factory, Cubature::DynamicFactory("gauss-legendre:2"))
177 {
178 }
179
180 void prepare(Index cell_index)
181 {
182 BaseClass::prepare(cell_index);
183 _trafo_eval.prepare(cell_index);
184
185 DomainPointType dom_point(DataType(0));
186 InvLinTrafoData trafo_data;
187 _trafo_eval(trafo_data, dom_point);
188 _inv_lin_mat = trafo_data.jac_inv;
189 _inv_lin_vec = trafo_data.img_point;
190 }
191
192 void finish()
193 {
194 _trafo_eval.finish();
196 }
197
198 int get_num_assigned_dofs() const
199 {
200 return max_assigned_dofs;
201 }
202
203 template<typename NodeData_, typename Function_>
204 void operator()(NodeData_& node_data, const Function_& function) const
205 {
206 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
207
208 // declare our evaluation traits
209 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
210
211 // declare function evaluator
212 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
213
214 typename FuncEvalTraits::ValueType value(DataType_(0));
215 DataType_ mean(DataType_(0));
216 TrafoEvalData trafo_data;
217 DomainPointType dom_point;
218
219 // integrate over facet
220 for(int i(0); i < _cub_rule.get_num_points(); ++i)
221 {
222 _trafo_eval(trafo_data, _cub_rule.get_point(i));
223 dom_point.set_mat_vec_mult(_inv_lin_mat, trafo_data.img_point - _inv_lin_vec);
224 value += (_cub_rule.get_weight(i) * trafo_data.jac_det) * func_eval.value(trafo_data.img_point) * dom_point[0] * dom_point[1];
225 mean += _cub_rule.get_weight(i) * trafo_data.jac_det;
226 }
227
228 // set integral mean
229 node_data[0] = (DataType_(1) / mean) * value;
230 }
231 };
232
238 template<
239 typename Space_,
240 typename DataType_>
241 class NodeFunctional<Space_, Shape::Hypercube<3>, 0, DataType_> :
242 public NodeFunctionalBase<Space_, DataType_>
243 {
244 public:
246 static constexpr int max_assigned_dofs = 3;
247
248 template<typename Function_>
249 struct Value
250 {
252 };
253
254 protected:
255 typedef typename Space_::TrafoType TrafoType;
256 typedef typename Space_::ShapeType ShapeType;
257 typedef typename TrafoType::template Evaluator<ShapeType, DataType_>::Type TrafoEvalType;
258 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
259 typedef typename TrafoEvalTraits::DataType DataType;
260 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
261 typedef typename TrafoEvalTraits::ImagePointType ImagePointType;
262 typedef typename TrafoEvalTraits::JacobianInverseType JacobianInverseType;
263
264 static constexpr int image_dim = TrafoEvalTraits::image_dim;
265
266 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point | TrafoTags::jac_det>::EvalDataType TrafoEvalData;
267 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point | TrafoTags::jac_inv>::EvalDataType InvLinTrafoData;
268
270
271 TrafoEvalType _trafo_eval;
272 CubRuleType _cub_rule;
273
274 JacobianInverseType _inv_lin_mat;
275 ImagePointType _inv_lin_vec;
276
277 public:
278 explicit NodeFunctional(const Space_& space) :
279 BaseClass(space),
280 _trafo_eval(space.get_trafo()),
281 _cub_rule(Cubature::ctor_factory, Cubature::DynamicFactory("gauss-legendre:2"))
282 {
283 }
284
285 void prepare(Index cell_index)
286 {
287 BaseClass::prepare(cell_index);
288 _trafo_eval.prepare(cell_index);
289
290 DomainPointType dom_point(DataType(0));
291 InvLinTrafoData trafo_data;
292 _trafo_eval(trafo_data, dom_point);
293 _inv_lin_mat = trafo_data.jac_inv;
294 _inv_lin_vec = trafo_data.img_point;
295 }
296
297 void finish()
298 {
299 _trafo_eval.finish();
301 }
302
303 int get_num_assigned_dofs() const
304 {
305 return max_assigned_dofs;
306 }
307
308 template<typename NodeData_, typename Function_>
309 void operator()(NodeData_& node_data, const Function_& function) const
310 {
311 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
312
313 // declare our evaluation traits
314 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
315
316 // declare function evaluator
317 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
318
319 Tiny::Vector<typename FuncEvalTraits::ValueType, 3> vals;
320 vals.format();
321 DataType_ mean(DataType_(0));
322 TrafoEvalData trafo_data;
323 DomainPointType dom_point;
324
325 // integrate over facet
326 for(int i(0); i < _cub_rule.get_num_points(); ++i)
327 {
328 _trafo_eval(trafo_data, _cub_rule.get_point(i));
329 dom_point.set_mat_vec_mult(_inv_lin_mat, trafo_data.img_point - _inv_lin_vec);
330 typename FuncEvalTraits::ValueType fv = (_cub_rule.get_weight(i) * trafo_data.jac_det) * func_eval.value(trafo_data.img_point);
331 vals[0] += fv * (dom_point[0] * dom_point[1]);
332 vals[1] += fv * (dom_point[1] * dom_point[2]);
333 vals[2] += fv * (dom_point[2] * dom_point[0]);
334 mean += _cub_rule.get_weight(i) * trafo_data.jac_det;
335 }
336
337 // set integral mean
338 node_data[0] = (DataType_(1) / mean) * vals[0];
339 node_data[1] = (DataType_(1) / mean) * vals[1];
340 node_data[2] = (DataType_(1) / mean) * vals[2];
341 }
342 };
343 } // namespace Q1TBNP
344 } // namespace Space
345} // namespace FEAT
FEAT Kernel base header.
Cubature Rule class template.
Definition: rule.hpp:38
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.
Q1TBNP Element Evaluator class template declaration.
Definition: evaluator.hpp:34
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
@ dom_point
specifies whether the trafo should supply domain point coordinates
Face traits tag struct template.
Definition: shape.hpp:106