FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
interpolator.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/lafem/dense_vector.hpp>
11#include <kernel/lafem/dense_vector_blocked.hpp>
12
13namespace FEAT
14{
15 namespace Assembly
16 {
18 namespace Intern
19 {
20 template<
21 typename Vector_,
22 typename Function_,
23 typename Space_,
24 int shape_dim_,
25 int max_dofs_ = Space_::template NodeFunctional<shape_dim_, typename Vector_::DataType>::Type::max_assigned_dofs>
26 struct InterpolatorCore
27 {
28 public:
29 static void project(Vector_& vector, const Function_& function, const Space_& space)
30 {
31 typedef typename Vector_::DataType DataType;
32
33 // create a node-functional object
34 typedef typename Space_::template NodeFunctional<shape_dim_, DataType>::Type NodeFunc;
35
36 typedef typename NodeFunc::template Value<Function_>::Type ValueType;
37
38 const Index num_entities = space.get_mesh().get_num_entities(shape_dim_);
39
40 Memory::TypedView<ValueType> vals = vector.elements_view_rw();
41
42 FEAT_PRAGMA_OMP(parallel)
43 {
44 // create node functional
45 NodeFunc node_func(space);
46
47 // create node data; avoid zero-length vectors
48 Tiny::Vector<ValueType, max_dofs_> node_data;
49
50 // define dof assignment
51 typedef typename Space_::template DofAssignment<shape_dim_, DataType>::Type DofAssignType;
52 DofAssignType dof_assign(space);
53
54 // get the vector data array
55 //auto* vals = vector.elements();
56 //XASSERT(vals != nullptr);
57
58 // loop over all entities
59 FEAT_PRAGMA_OMP(for)
60 for(Index i = 0; i < num_entities; ++i)
61 {
62 // evaluate the node functional
63 node_func.prepare(i);
64 node_func(node_data, function);
65 node_func.finish();
66
67 // prepare dof-assignment
68 dof_assign.prepare(i);
69
70 // loop over all assigned DOFs
71 const int num_dofs = dof_assign.get_num_assigned_dofs();
72 for(int j(0); j < num_dofs; ++j)
73 {
74 vals[dof_assign.get_index(j)] += node_data[j];
75 }
76
77 // finish
78 dof_assign.finish();
79 }
80 }
81 } // omp parallel
82 };
83
84 template<typename Vector_, typename Function_, typename Space_, int shape_dim_>
85 struct InterpolatorCore<Vector_, Function_, Space_, shape_dim_, 0>
86 {
87 static void project(Vector_&, const Function_&, const Space_&)
88 {
89 // do nothing
90 }
91 };
92
93 template<typename Space_, int shape_dim_ = Space_::shape_dim>
94 class InterpolatorWrapper
95 {
96 public:
97 template<typename Vector_, typename Function_>
98 static void project(Vector_& vector, const Function_& function, const Space_& space)
99 {
100 // recurse down
101 InterpolatorWrapper<Space_, shape_dim_ - 1>::project(vector, function, space);
102
103 // call interpolator core
104 InterpolatorCore<Vector_, Function_, Space_, shape_dim_>::project(vector, function, space);
105 }
106 };
107
108 template<typename Space_>
109 class InterpolatorWrapper<Space_, 0>
110 {
111 public:
112 template<typename Vector_, typename Function_>
113 static void project(Vector_& vector, const Function_& function, const Space_& space)
114 {
115 // call interpolator core
116 InterpolatorCore<Vector_, Function_, Space_, 0>::project(vector, function, space);
117 }
118 };
119 } // namespace Intern
121
131 {
132 public:
147 template<
148 typename DT_,
149 typename IT_,
150 typename Function_,
151 typename Space_>
152 static void project(
154 const Function_& function,
155 const Space_& space)
156 {
157 typedef typename Space_::TrafoType TrafoType;
158 typedef typename Function_::ImageType ImageType;
159
160 // as a very first step, ensure that the function has the right dimensions
161 static_assert(Function_::domain_dim == TrafoType::world_dim, "invalid function domain dimension");
162 static_assert(ImageType::is_scalar, "only scalar functions can be interpolated to scalar vectors");
163
164 // project function
165 vector = LAFEM::DenseVector<DT_, IT_>(space.get_num_dofs(), DT_(0));
166 Intern::InterpolatorWrapper<Space_>::project(vector, function, space);
167 }
168
183 template<
184 typename DT_,
185 typename IT_,
186 int block_size_,
187 typename Function_,
188 typename Space_>
189 static void project(
191 const Function_& function,
192 const Space_& space)
193 {
194 typedef typename Space_::TrafoType TrafoType;
195 typedef typename Function_::ImageType ImageType;
196
197 // as a very first step, ensure that the function has the right dimensions
198 static_assert(Function_::domain_dim == TrafoType::world_dim, "invalid function domain dimension");
199 static_assert(ImageType::is_vector, "only vector fields can be interpolated to blocked vectors");
200 static_assert(ImageType::image_dim == block_size_, "invalid vector field size");
201
202 // project function
203 vector = LAFEM::DenseVectorBlocked<DT_, IT_, block_size_>(space.get_num_dofs(), DT_(0));
204 Intern::InterpolatorWrapper<Space_>::project(vector, function, space);
205 }
206 }; // class Interpolator
207 } // namespace Assembly
208} // namespace FEAT
Interpolator class template.
static void project(LAFEM::DenseVector< DT_, IT_ > &vector, const Function_ &function, const Space_ &space)
Interpolates a scalar function.
static void project(LAFEM::DenseVectorBlocked< DT_, IT_, block_size_ > &vector, const Function_ &function, const Space_ &space)
Interpolates a vector field.
Blocked Dense data vector class template.
Dense data vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.