FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
analytic_projector.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/assembly/base.hpp>
10#include <kernel/analytic/function.hpp>
11#include <kernel/cubature/dynamic_factory.hpp>
12#include <kernel/trafo/base.hpp>
13
14namespace FEAT
15{
16 namespace Assembly
17 {
26 {
27 public:
40 template<typename VectorOut_, typename Function_, typename Trafo_>
41 static void project(VectorOut_& vector, const Function_& function, const Trafo_& trafo)
42 {
43 // our mesh and shape types
44 typedef Trafo_ TrafoType;
45 typedef typename TrafoType::MeshType MeshType;
46
47 // get our data and value types
48 typedef typename VectorOut_::DataType DataType;
49
50 // get the mesh
51 const MeshType& mesh(trafo.get_mesh());
52
53 // fetch the vertex set
54 typedef typename MeshType::VertexSetType VertexSetType;
55 const VertexSetType& vtx(mesh.get_vertex_set());
56
57 // fetch the cell count
58 const Index num_verts(mesh.get_num_entities(0));
59
60 // create a clear output vector
61 vector = VectorOut_(num_verts, DataType(0));
62
63 // define the evaluation traits
65
66 // create a function evaluator
67 typename Function_::template Evaluator<EvalTraits> func_eval(function);
68
69 // loop over all cells of the mesh
70 for(Index i(0); i < num_verts; ++i)
71 {
72 // compute and store function value
73 vector(i, func_eval.value(vtx[i]));
74
75 // continue with next vertex
76 }
77 }
78 }; // class AnalyticVertexProjector<...>
79
89 {
90 private:
92 static constexpr TrafoTags trafo_config = TrafoTags::img_point | TrafoTags::jac_det;
94
95 public:
108 template<
109 typename VectorOut_,
110 typename Function_,
111 typename Trafo_>
112 static void project(
113 VectorOut_& vector,
114 const Function_& function,
115 const Trafo_& trafo)
116 {
117 Cubature::DynamicFactory cubature_factory("barycentre");
118 project(vector, function, trafo, cubature_factory);
119 }
120
136 template<
137 typename VectorOut_,
138 typename Function_,
139 typename Trafo_,
140 typename CubatureFactory_>
141 static void project(
142 VectorOut_& vector,
143 const Function_& function,
144 const Trafo_& trafo,
145 const CubatureFactory_& cubature_factory)
146 {
147 // our mesh and shape types
148 typedef Trafo_ TrafoType;
149 typedef typename TrafoType::MeshType MeshType;
150 typedef typename MeshType::ShapeType ShapeType;
151
152 // our shape dimension
153 static constexpr int shape_dim = ShapeType::dimension;
154
155 // get our data and value types
156 typedef typename VectorOut_::DataType DataType;
157
158 // create our cubature rule
160 cubature_rule(Cubature::ctor_factory, cubature_factory);
161
162 // get our mesh
163 const MeshType& mesh(trafo.get_mesh());
164
165 // fetch the cell count
166 const Index num_cells(mesh.get_num_entities(shape_dim));
167
168 // create a clear output vector
169 vector = VectorOut_(num_cells, DataType(0));
170
171 // create a trafo evaluator
172 typedef typename TrafoType::template Evaluator<ShapeType, DataType>::Type TrafoEvaluator;
173 typedef typename TrafoEvaluator::template ConfigTraits<trafo_config> TrafoConfigTraits;
174 typename TrafoConfigTraits::EvalDataType trafo_data;
175
176 // create a trafo evaluator
177 TrafoEvaluator trafo_eval(trafo);
178
179 // define the evaluation traits
180 typedef Analytic::EvalTraits<DataType, Function_> FuncEvalTraits;
181 typedef typename FuncEvalTraits::ValueType ValueType;
182
183 // create a function evaluator
184 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
185
186 // loop over all cells of the mesh
187 for(Index cell(0); cell < num_cells; ++cell)
188 {
189 // prepare trafo evaluator
190 trafo_eval.prepare(cell);
191
192 ValueType value(DataType(0));
193 DataType area(DataType(0));
194
195 // loop over all quadrature points and integrate
196 for(int k(0); k < cubature_rule.get_num_points(); ++k)
197 {
198 // compute trafo data
199 trafo_eval(trafo_data, cubature_rule.get_point(k));
200
201 // compute function value
202 ValueType val = func_eval.value(trafo_data.img_point);
203
204 // compute weight
205 DataType weight(trafo_data.jac_det * cubature_rule.get_weight(k));
206
207 // update cell area
208 area += weight;
209
210 // update cell value
211 value += weight * val;
212
213 // continue with next vertex
214 }
215
216 // set contribution
217 vector(cell, (DataType(1) / area) * value);
218
219 // finish trafo evaluator
220 trafo_eval.finish();
221
222 // continue with next cell
223 }
224 }
225 }; // class AnalyticCellProjector<...>
226 } // namespace Assembly
227} // namespace FEAT
Analytic cell projector class.
static void project(VectorOut_ &vector, const Function_ &function, const Trafo_ &trafo, const CubatureFactory_ &cubature_factory)
Projects an analytic function into the cells.
static void project(VectorOut_ &vector, const Function_ &function, const Trafo_ &trafo)
Projects an analytic function into the cells using the barycentre cubature rule.
Analytic vertex projector class.
static void project(VectorOut_ &vector, const Function_ &function, const Trafo_ &trafo)
Projects an analytic function into the vertices.
Cubature Rule class template.
Definition: rule.hpp:38
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