FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
fe_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
10#include <kernel/lafem/dense_vector.hpp>
11#include <kernel/lafem/dense_vector_blocked.hpp>
12#include <kernel/space/lagrange1/element.hpp>
13#include <kernel/space/lagrange2/element.hpp>
14#include <kernel/util/math.hpp>
15
16namespace FEAT
17{
18 namespace Assembly
19 {
20
37 template<typename ToSpace_, typename FromSpace_>
39 {
40 };
41
57 template<typename Trafo_, int shape_dim_ = Trafo_::MeshType::shape_dim>
59 {
64
84 template<typename DataType_, typename ValueType_>
85 static void recurse(Memory::TypedView<ValueType_>& vtc, const Memory::TypedView<ValueType_>& vfc, const ToSpace& to_space)
86 {
87 const auto& mesh = to_space.get_trafo().get_mesh();
88
89 // We use this to identify the vertex DoF at our shape
90 const auto& from_vertex_at_shape_idx = mesh.template get_index_set<shape_dim_, 0>();
91
92 // This is for mapping to the correct Lagrange2 DoF
93 typename ToSpace::template DofAssignment<shape_dim_, DataType_>::Type to_dof_assignment(to_space);
94
95 for(Index k(0); k < mesh.get_num_entities(shape_dim_); ++k)
96 {
97 to_dof_assignment.prepare(k);
98
99 // There is only one Lagrange2 DoF at each entity, but this is easier to understand for future reference
100 for(int j(0); j < to_dof_assignment.get_num_assigned_dofs(); ++j)
101 {
102 ValueType_ tmp(0);
103
104 for(int i(0); i < from_vertex_at_shape_idx.get_num_indices(); ++i)
105 {
106 tmp += vfc(from_vertex_at_shape_idx(k,i));
107 }
108
109 // Linear interpolation
110 tmp *= ( DataType_(1)/DataType_(from_vertex_at_shape_idx.get_num_indices()) );
111
112 // Emplacement operator
113 vtc[to_dof_assignment.get_index(j)] = tmp;
114 }
115 }
116
117 // recurse down
118 Lagrange1To2DofAtEntity<Trafo_, shape_dim_-1>::template recurse<DataType_>( vtc, vfc, to_space);
119 }
120 };
121
129 template<typename Trafo_>
130 struct Lagrange1To2DofAtEntity<Trafo_, 0>
131 {
134
154 //template<typename Vector_>
155 //static void recurse(Vector_& to_coeffs, const Vector_& from_coeffs, const ToSpace& to_space)
156 template<typename DataType_, typename ValueType_>
157 static void recurse(Memory::TypedView<ValueType_>& vtc, const Memory::TypedView<ValueType_>& vfc, const ToSpace& to_space)
158 {
159 const auto& mesh = to_space.get_trafo().get_mesh();
160 for(Index i(0); i < mesh.get_num_entities(0); ++i)
161 {
162 vtc[i] = vfc(i);
163 }
164 }
165 };
166
175 template<typename Trafo_>
176 struct FEInterpolator<Space::Lagrange2::Element<Trafo_>, Space::Lagrange1::Element<Trafo_>>
177 {
179 typedef Trafo_ TrafoType;
184
207 template<typename DataType_, typename IT_>
209 const LAFEM::DenseVector<DataType_, IT_>& from_coeffs,
210 const ToSpace& to_space,
211 const FromSpace& DOXY(from_space))
212 {
213 const Memory::TypedView<DataType_> vfc(from_coeffs.elements_view_r());
214 Memory::TypedView<DataType_> vtc(to_coeffs.elements_view_w());
215 Lagrange1To2DofAtEntity<TrafoType>::template recurse<DataType_>(vtc, vfc, to_space);
216 }
217
240 template<typename DataType_, typename IT_, int blocksize_>
243 const ToSpace& to_space,
244 const FromSpace& DOXY(from_space))
245 {
246 typedef Tiny::Vector<DataType_, blocksize_> ValueType;
247 const Memory::TypedView<ValueType> vfc(from_coeffs.elements_view_r());
248 Memory::TypedView<ValueType> vtc(to_coeffs.elements_view_w());
249 Lagrange1To2DofAtEntity<TrafoType>::template recurse<DataType_>(vtc, vfc, to_space);
250 }
251 }; //FEInterpolator Lagrange1 to Lagrange2
252
261 template<typename Trafo_>
262 struct FEInterpolator<Space::Lagrange1::Element<Trafo_>, Space::Lagrange2::Element<Trafo_>>
263 {
265 typedef Trafo_ TrafoType;
270
293 template<typename DataType_, typename IT_>
295 const LAFEM::DenseVector<DataType_, IT_>& from_coeffs,
296 const ToSpace& DOXY(to_space),
297 const FromSpace& DOXY(from_space))
298 {
299 const Memory::TypedView<DataType_> vfc(from_coeffs.elements_view_r());
300 Memory::TypedView<DataType_> vtc(to_coeffs.elements_view_w());
301 //sanity check for the vector sizes
302 XASSERTM(to_coeffs.size() < from_coeffs.size(), "Coefficient vectors do not match!\n To_coeffs size is ");
303 //due to the two level ordering of Lagrange1 and Lagrange2 elements it is always sufficient to just truncate our vector
304 for(Index i(0); i < to_coeffs.size(); ++i)
305 {
306 vtc[i] = vfc(i);
307 }
308 //And we are done
309 }
310
333 template<typename DataType_, typename IT_, int blocksize_>
336 const ToSpace& DOXY(to_space),
337 const FromSpace& DOXY(from_space))
338 {
339 const Memory::TypedView<Tiny::Vector<DataType_, blocksize_>> vfc(from_coeffs.elements_view_r());
340 Memory::TypedView<Tiny::Vector<DataType_, blocksize_>> vtc(to_coeffs.elements_view_w());
341 //sanity check for the vector sizes
342 XASSERTM(to_coeffs.size() < from_coeffs.size(), "Coefficient vectors do not match!\n To_coeffs size is ");
343 //due to the two level ordering of Lagrange1 and Lagrange2 elements it is always sufficient to only truncate our vector
344 for(Index i(0); i < to_coeffs.size(); ++i)
345 {
346 vtc[i] = vfc(i);
347 }
348 //And we are done
349 }
350
351 }; //FEInterpolator Lagrange2 to Lagrange1
352
361 template<typename Space_>
362 struct FEInterpolator<Space_, Space_>
363 {
364 typedef Space_ ToSpace;
365
366 typedef Space_ FromSpace;
367
392 template<typename Vector_>
393 static void interpolate(Vector_& to_coeffs,
394 const Vector_& from_coeffs,
395 const ToSpace& DOXY(to_space),
396 const FromSpace& DOXY(from_space))
397 {
398 to_coeffs.copy(from_coeffs, true);
399 }
400
401 }; //FEInterpolator same space
402
403 } // namespace Assembly
404} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Blocked Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Typed memory view class.
TrafoType & get_trafo()
Returns a reference to the trafo.
Standard Lagrange-1 Finite-Element space class template.
Definition: element.hpp:39
Standard Lagrange-2 Finite-Element space class template.
Definition: element.hpp:39
Tiny Vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
static void interpolate(LAFEM::DenseVectorBlocked< DataType_, IT_, blocksize_ > &to_coeffs, const LAFEM::DenseVectorBlocked< DataType_, IT_, blocksize_ > &from_coeffs, const ToSpace &to_space, const FromSpace &from_space)
Interpolates a vector Lagrange1 to Lagrange2 FE function.
static void interpolate(LAFEM::DenseVector< DataType_, IT_ > &to_coeffs, const LAFEM::DenseVector< DataType_, IT_ > &from_coeffs, const ToSpace &to_space, const FromSpace &from_space)
Interpolates a scalar Lagrange1 to Lagrange2 FE function.
static void interpolate(LAFEM::DenseVector< DataType_, IT_ > &to_coeffs, const LAFEM::DenseVector< DataType_, IT_ > &from_coeffs, const ToSpace &to_space, const FromSpace &from_space)
Interpolates a scalar Lagrange1 to Lagrange2 FE function.
static void interpolate(LAFEM::DenseVectorBlocked< DataType_, IT_, blocksize_ > &to_coeffs, const LAFEM::DenseVectorBlocked< DataType_, IT_, blocksize_ > &from_coeffs, const ToSpace &to_space, const FromSpace &from_space)
Interpolates a vector valued Lagrange1 to Lagrange2 FE function.
static void interpolate(Vector_ &to_coeffs, const Vector_ &from_coeffs, const ToSpace &to_space, const FromSpace &from_space)
Interpolates a scalar/vector FE function on the same space by just copying the vector.
Interpolation operator between two finite element spaces.
static void recurse(Memory::TypedView< ValueType_ > &vtc, const Memory::TypedView< ValueType_ > &vfc, const ToSpace &to_space)
Evaluates the node functionals for shape dimension 0.
Helper class that recurses through shape dimensions and evaluates Lagrange2 DoF based on Lagrange1 Do...
static void recurse(Memory::TypedView< ValueType_ > &vtc, const Memory::TypedView< ValueType_ > &vfc, const ToSpace &to_space)
Evaluates the node functionals from shape_dim_ on down to shape dimension 0.
Space::Lagrange2::Element< Trafo_ > ToSpace
We map to Lagrange2.
Space::Lagrange1::Element< Trafo_ > FromSpace
We map from Lagrange1.