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
9#include <kernel/space/node_functional_base.hpp>
10
11namespace FEAT
12{
13 namespace Space
14 {
15 namespace Discontinuous
16 {
18 namespace Intern
19 {
20 template<typename Shape_>
21 struct Barycentre;
22
23 template<int dim_>
24 struct Barycentre< Shape::Simplex<dim_> >
25 {
26 template<typename T_>
27 static void make(T_& p)
28 {
29 typedef typename T_::DataType DT;
30 for(int i(0); i < dim_; ++i)
31 p[i] = DT(1) / DT(dim_+1);
32 }
33 };
34
35 template<int dim_>
36 struct Barycentre< Shape::Hypercube<dim_> >
37 {
38 template<typename T_>
39 static void make(T_& p)
40 {
41 typedef typename T_::DataType DT;
42 for(int i(0); i < dim_; ++i)
43 p[i] = DT(0);
44 }
45 };
46 } // namespace Intern
48
49 template<
50 typename Space_,
51 int codim_,
52 typename Variant_,
53 typename DataType_,
54 typename Shape_ = typename Space_::ShapeType>
56 public NodeFunctionalNull<Space_, DataType_>
57 {
58 public:
59 explicit NodeFunctional(const Space_& space) :
61 {
62 }
63 };
64
65 template<
66 typename Space_,
67 typename DataType_,
68 typename Shape_>
69 class NodeFunctional<Space_, 0, Variant::StdPolyP<0>, DataType_, Shape_> :
70 public NodeFunctionalBase<Space_, DataType_>
71 {
72 public:
74 static constexpr int max_assigned_dofs = 1;
75
76 template<typename Function_>
77 struct Value
78 {
80 };
81
82 protected:
83 typedef typename Space_::TrafoType TrafoType;
84 typedef typename TrafoType::template Evaluator<Shape_, DataType_>::Type TrafoEvalType;
85 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
86 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
87
88 // declare trafo evaluation data
89 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoEvalData;
90
91 TrafoEvalType _trafo_eval;
92 DomainPointType _dom_point;
93
94 public:
95 explicit NodeFunctional(const Space_& space) :
96 BaseClass(space),
97 _trafo_eval(space.get_trafo())
98 {
99 // set cell midpoint
100 Intern::Barycentre<Shape_>::make(_dom_point);
101 }
102
103 void prepare(Index cell_index)
104 {
105 BaseClass::prepare(cell_index);
106 _trafo_eval.prepare(cell_index);
107 }
108
109 void finish()
110 {
111 _trafo_eval.finish();
113 }
114
115 int get_num_assigned_dofs() const
116 {
117 return max_assigned_dofs;
118 }
119
120 template<typename NodeData_, typename Function_>
121 void operator()(NodeData_& node_data, const Function_& function) const
122 {
123 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
124 static_assert(Function_::can_value, "function cannot compute values");
125
126 // declare our evaluation traits
127 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
128
129 // declare function evaluator
130 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
131
132 // compute trafo data
133 TrafoEvalData trafo_data;
134 _trafo_eval(trafo_data, _dom_point);
135
136 // evaluate function
137 node_data[0] = func_eval.value(trafo_data.img_point);
138 }
139 };
140
141 template<
142 typename Space_,
143 typename DataType_,
144 int shape_dim_>
145 class NodeFunctional<Space_, 0, Variant::StdPolyP<1>, DataType_, Shape::Simplex<shape_dim_> > :
146 public NodeFunctionalBase<Space_, DataType_>
147 {
148 public:
150 static constexpr int max_assigned_dofs = shape_dim_+1;
151
152 template<typename Function_>
153 struct Value
154 {
156 };
157
158 protected:
159 typedef typename Space_::TrafoType TrafoType;
161 typedef typename TrafoType::template Evaluator<ShapeType, DataType_>::Type TrafoEvalType;
162 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
163 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
164
165 // declare trafo evaluation data
166 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoEvalData;
167
168 TrafoEvalType _trafo_eval;
169
170 public:
171 explicit NodeFunctional(const Space_& space) :
172 BaseClass(space),
173 _trafo_eval(space.get_trafo())
174 {
175 }
176
177 void prepare(Index cell_index)
178 {
179 BaseClass::prepare(cell_index);
180 _trafo_eval.prepare(cell_index);
181 }
182
183 void finish()
184 {
185 _trafo_eval.finish();
187 }
188
189 int get_num_assigned_dofs() const
190 {
191 return max_assigned_dofs;
192 }
193
194 template<typename NodeData_, typename Function_>
195 void operator()(NodeData_& node_data, const Function_& function) const
196 {
197 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
198 static_assert(Function_::can_value, "function cannot compute values");
199
200 // declare our evaluation traits
201 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
202
203 // declare function evaluator
204 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
205
206 // compute trafo data
207 TrafoEvalData trafo_data;
208
209 // loop over all nodal points
210 DomainPointType dom_point;
211 for(int i(0); i < max_assigned_dofs; ++i)
212 {
213 // set up domain point
214 for(int j(0); j < shape_dim_; ++j)
215 {
216 dom_point[j] = DataType_(j+1 == i ? 1 : 0);
217 }
218
219 // evaluate trafo
220 _trafo_eval(trafo_data, dom_point);
221
222 // evaluate function
223 node_data[i] = func_eval.value(trafo_data.img_point);
224 }
225 }
226 };
227
228 template<
229 typename Space_,
230 typename DataType_,
231 int shape_dim_>
232 class NodeFunctional<Space_, 0, Variant::StdPolyP<1>, DataType_, Shape::Hypercube<shape_dim_> > :
233 public NodeFunctionalBase<Space_, DataType_>
234 {
235 public:
237 static constexpr int max_assigned_dofs = shape_dim_+1;
238
239 template<typename Function_>
240 struct Value
241 {
243 };
244
245 protected:
246 typedef typename Space_::TrafoType TrafoType;
248 typedef typename TrafoType::template Evaluator<ShapeType, DataType_>::Type TrafoEvalType;
249 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
250 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
251
252 // declare trafo evaluation data
253 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoEvalData;
254
255 TrafoEvalType _trafo_eval;
256
257 public:
258 explicit NodeFunctional(const Space_& space) :
259 BaseClass(space),
260 _trafo_eval(space.get_trafo())
261 {
262 }
263
264 void prepare(Index cell_index)
265 {
266 BaseClass::prepare(cell_index);
267 _trafo_eval.prepare(cell_index);
268 }
269
270 void finish()
271 {
272 _trafo_eval.finish();
274 }
275
276 int get_num_assigned_dofs() const
277 {
278 return max_assigned_dofs;
279 }
280
281 template<typename NodeData_, typename Function_>
282 void operator()(NodeData_& node_data, const Function_& function) const
283 {
284 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
285 static_assert(Function_::can_value, "function cannot compute values");
286
287 // declare our evaluation traits
288 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
289
290 // declare function evaluator
291 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
292
293 // compute trafo data
294 TrafoEvalData trafo_data;
295
296 // evaluate center point
297 DomainPointType dom_point(DataType_(0));
298 _trafo_eval(trafo_data, dom_point);
299 node_data[0] = func_eval.value(trafo_data.img_point);
300
301 // loop over all nodal points
302 for(int i(0); i < shape_dim_; ++i)
303 {
304 // evaluate domain point #1
305 dom_point[i] = DataType_(1);
306 _trafo_eval(trafo_data, dom_point);
307 const auto value_0 = func_eval.value(trafo_data.img_point);
308
309 // evaluate domain point #2
310 dom_point[i] = -DataType_(1);
311 _trafo_eval(trafo_data, dom_point);
312 const auto value_1 = func_eval.value(trafo_data.img_point);
313
314 // scale
315 node_data[i+1] = DataType_(0.5) * (value_0 - value_1);
316
317 // reset domain point
318 dom_point[i] = DataType_(0);
319 }
320 }
321 };
322 } // namespace Discontinuous
323 } // namespace Space
324} // namespace FEAT
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
std::uint64_t Index
Index data type.
@ dom_point
specifies whether the trafo should supply domain point coordinates
Hypercube shape tag struct template.
Definition: shape.hpp:64
Simplex shape tag struct template.
Definition: shape.hpp:44