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#include <kernel/util/memory_arbiter.hpp>
14
15namespace FEAT
16{
17 namespace Assembly
18 {
27 {
28 public:
41 template<typename VectorOut_, typename Function_, typename Trafo_>
42 static void project(VectorOut_& vector, const Function_& function, const Trafo_& trafo)
43 {
44 // our mesh and shape types
45 typedef Trafo_ TrafoType;
46 typedef typename TrafoType::MeshType MeshType;
47
48 // get our data and value types
49 typedef typename VectorOut_::DataType DataType;
50 typedef typename VectorOut_::ValueType ValueType;
51
52 // get the mesh
53 const MeshType& mesh(trafo.get_mesh());
54
55 // fetch the vertex set
56 typedef typename MeshType::VertexSetType VertexSetType;
57 const VertexSetType& vtx(mesh.get_vertex_set());
58
59 // fetch the cell count
60 const Index num_verts(mesh.get_num_entities(0));
61
62 // create a clear output vector
63 vector = VectorOut_(num_verts, DataType(0));
64
65 // define the evaluation traits
67
68 // create a function evaluator
69 typename Function_::template Evaluator<EvalTraits> func_eval(function);
70
71 // get a view for the vector
72 Memory::TypedView<ValueType> vec_view(vector.elements_view_w());
73
74 // loop over all cells of the mesh
75 for(Index i(0); i < num_verts; ++i)
76 {
77 // compute and store function value
78 vec_view[i] = func_eval.value(vtx[i]);
79
80 // continue with next vertex
81 }
82 }
83 }; // class AnalyticVertexProjector<...>
84
94 {
95 private:
97 static constexpr TrafoTags trafo_config = TrafoTags::img_point | TrafoTags::jac_det;
99
100 public:
113 template<
114 typename VectorOut_,
115 typename Function_,
116 typename Trafo_>
117 static void project(
118 VectorOut_& vector,
119 const Function_& function,
120 const Trafo_& trafo)
121 {
122 Cubature::DynamicFactory cubature_factory("barycentre");
123 project(vector, function, trafo, cubature_factory);
124 }
125
141 template<
142 typename VectorOut_,
143 typename Function_,
144 typename Trafo_,
145 typename CubatureFactory_>
146 static void project(
147 VectorOut_& vector,
148 const Function_& function,
149 const Trafo_& trafo,
150 const CubatureFactory_& cubature_factory)
151 {
152 // our mesh and shape types
153 typedef Trafo_ TrafoType;
154 typedef typename TrafoType::MeshType MeshType;
155 typedef typename MeshType::ShapeType ShapeType;
156
157 // our shape dimension
158 static constexpr int shape_dim = ShapeType::dimension;
159
160 // get our data and value types
161 typedef typename VectorOut_::DataType DataType;
162
163 // create our cubature rule
165 cubature_rule(Cubature::ctor_factory, cubature_factory);
166
167 // get our mesh
168 const MeshType& mesh(trafo.get_mesh());
169
170 // fetch the cell count
171 const Index num_cells(mesh.get_num_entities(shape_dim));
172
173 // create a clear output vector
174 vector = VectorOut_(num_cells, DataType(0));
175
176 // create a trafo evaluator
177 typedef typename TrafoType::template Evaluator<ShapeType, DataType>::Type TrafoEvaluator;
178 typedef typename TrafoEvaluator::template ConfigTraits<trafo_config> TrafoConfigTraits;
179 typename TrafoConfigTraits::EvalDataType trafo_data;
180
181 // create a trafo evaluator
182 TrafoEvaluator trafo_eval(trafo);
183
184 // define the evaluation traits
185 typedef Analytic::EvalTraits<DataType, Function_> FuncEvalTraits;
186 typedef typename FuncEvalTraits::ValueType ValueType;
187
188 // create a function evaluator
189 typename Function_::template Evaluator<FuncEvalTraits> func_eval(function);
190
191 // get a view for the vector
192 Memory::TypedView<ValueType> vec_view(vector.elements_view_w());
193
194 // loop over all cells of the mesh
195 for(Index cell(0); cell < num_cells; ++cell)
196 {
197 // prepare trafo evaluator
198 trafo_eval.prepare(cell);
199
200 ValueType value(DataType(0));
201 DataType area(DataType(0));
202
203 // loop over all quadrature points and integrate
204 for(int k(0); k < cubature_rule.get_num_points(); ++k)
205 {
206 // compute trafo data
207 trafo_eval(trafo_data, cubature_rule.get_point(k));
208
209 // compute function value
210 ValueType val = func_eval.value(trafo_data.img_point);
211
212 // compute weight
213 DataType weight(trafo_data.jac_det * cubature_rule.get_weight(k));
214
215 // update cell area
216 area += weight;
217
218 // update cell value
219 value += weight * val;
220
221 // continue with next vertex
222 }
223
224 // set contribution
225 vec_view[cell] = (DataType(1) / area) * value;
226
227 // finish trafo evaluator
228 trafo_eval.finish();
229
230 // continue with next cell
231 }
232 }
233 }; // class AnalyticCellProjector<...>
234 } // namespace Assembly
235} // 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
Typed memory view class.
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