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 Argyris
16 {
17 template<
18 typename Space_,
19 int dim_,
20 typename DataType_>
22 public NodeFunctionalNull<Space_, DataType_>
23 {
24 public:
25 explicit NodeFunctional(const Space_& space) :
27 {
28 }
29 };
30
31 template<
32 typename Space_,
33 typename DataType_>
34 class NodeFunctional<Space_, 0, DataType_> :
35 public NodeFunctionalBase<Space_, DataType_>
36 {
37 public:
39 static constexpr int max_assigned_dofs = 6;
40
41 template<typename Function_>
42 struct Value
43 {
45 };
46
47 protected:
48 typedef typename Space_::TrafoType TrafoType;
49 typedef typename Space_::ShapeType ShapeType;
50 typedef typename TrafoType::template Evaluator<Shape::Vertex, DataType_>::Type TrafoEvalType;
51 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
52 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
53
54 // declare trafo evaluation data
55 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoEvalData;
56
57 TrafoEvalType _trafo_eval;
58
59 public:
60 explicit NodeFunctional(const Space_& space) :
61 BaseClass(space),
62 _trafo_eval(space.get_trafo())
63 {
64 }
65
66 void prepare(Index cell_index)
67 {
68 BaseClass::prepare(cell_index);
69 _trafo_eval.prepare(cell_index);
70 }
71
72 void finish()
73 {
74 _trafo_eval.finish();
76 }
77
78 int get_num_assigned_dofs() const
79 {
80 return max_assigned_dofs;
81 }
82
83 template<typename NodeData_, typename Function_>
84 void operator()(NodeData_& node_data, const Function_& function) const
85 {
86 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
87 static_assert(Function_::can_value, "function cannot compute values");
88 static_assert(Function_::can_grad, "function cannot compute gradients");
89 static_assert(Function_::can_hess, "function cannot compute hessians");
90
91 // declare our evaluation traits
92 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
93
94 // declare function evaluator
95 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
96
97 // compute trafo data
98 DomainPointType dom_point(DataType_(0));
99 TrafoEvalData trafo_data;
100 _trafo_eval(trafo_data, dom_point);
101
102 // evaluate function
103 const auto func_value = func_eval.value(trafo_data.img_point);
104 const auto func_grad = func_eval.gradient(trafo_data.img_point);
105 const auto func_hess = func_eval.hessian(trafo_data.img_point);
106
107 // set node functional values
108 node_data[0] = func_value;
109 node_data[1] = func_grad[0];
110 node_data[2] = func_grad[1];
111 node_data[3] = func_hess[0][0];
112 node_data[4] = func_hess[1][1];
113 node_data[5] = func_hess[0][1];
114 }
115 };
116
117 template<
118 typename Space_,
119 typename DataType_>
120 class NodeFunctional<Space_, 1, DataType_> :
121 public NodeFunctionalBase<Space_, DataType_>
122 {
123 public:
125 static constexpr int max_assigned_dofs = 1;
126
127 template<typename Function_>
128 struct Value
129 {
131 };
132
133 protected:
134 typedef typename Space_::TrafoType TrafoType;
135 typedef typename Space_::ShapeType ShapeType;
136 typedef typename TrafoType::template Evaluator<Shape::Simplex<1>, DataType_>::Type TrafoEvalType;
137 typedef typename TrafoEvalType::EvalTraits TrafoEvalTraits;
138 typedef typename TrafoEvalTraits::DataType DataType;
139 typedef typename TrafoEvalTraits::DomainPointType DomainPointType;
140
141 // declare trafo evaluation data
143#if defined(FEAT_COMPILER_PGI) || (defined(FEAT_COMPILER_INTEL) && FEAT_COMPILER_INTEL >= 1800 && FEAT_COMPILER_INTEL < 1900)
144 static constexpr TrafoTags trafo_tags = TrafoTags::img_point|TrafoTags::jac_mat;
145 typedef typename TrafoEvalType::template ConfigTraits<trafo_tags>::EvalDataType TrafoEvalData;
146#else
147 typedef typename TrafoEvalType::template ConfigTraits<TrafoTags::img_point|TrafoTags::jac_mat>::EvalDataType TrafoEvalData;
148#endif
149
150 TrafoEvalType _trafo_eval;
151
152 public:
153 explicit NodeFunctional(const Space_& space) :
154 BaseClass(space),
155 _trafo_eval(space.get_trafo())
156 {
157 }
158
159 void prepare(Index cell_index)
160 {
161 BaseClass::prepare(cell_index);
162 _trafo_eval.prepare(cell_index);
163 }
164
165 void finish()
166 {
167 _trafo_eval.finish();
169 }
170
171 int get_num_assigned_dofs() const
172 {
173 return max_assigned_dofs;
174 }
175
176 template<typename NodeData_, typename Function_>
177 void operator()(NodeData_& node_data, const Function_& function) const
178 {
179 static_assert(std::is_base_of<Analytic::Function, Function_>::value, "invalid function object");
180 static_assert(Function_::can_grad, "function cannot compute gradients");
181
182 // declare our evaluation traits
183 typedef Analytic::EvalTraits<DataType_, Function_> FuncEvalTraits;
184
185 // declare function evaluator
186 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
187
188 DomainPointType dom_point(DataType_(0.5));
189 TrafoEvalData trafo_data;
190
191 _trafo_eval(trafo_data, dom_point);
192
193 // compute edge normal
194 DataType_ dnx = +trafo_data.jac_mat(1,0);
195 DataType_ dny = -trafo_data.jac_mat(0,0);
196 DataType_ dnl = DataType_(1) / Math::sqrt(dnx*dnx + dny*dny);
197 dnx *= dnl;
198 dny *= dnl;
199
200 // evaluate function gradient
201 const auto func_grad = func_eval.gradient(trafo_data.img_point);
202
203 // set edge normal derivative
204 node_data[0] = dnx * func_grad[0] + dny * func_grad[1];
205 }
206 };
207 } // namespace Argyris
208 } // namespace Space
209} // namespace FEAT
Argyris Element Evaluator class template declaration.
Definition: evaluator.hpp:28
TrafoEvalType::template ConfigTraits< TrafoTags::img_point|TrafoTags::jac_mat >::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.
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
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
@ dom_point
specifies whether the trafo should supply domain point coordinates
@ jac_mat
specifies whether the trafo should supply jacobian matrices