1#ifndef DUNE_FEM_SPACE_LOCALFINITEELEMENT_INTERPOLATION_HH
2#define DUNE_FEM_SPACE_LOCALFINITEELEMENT_INTERPOLATION_HH
12#include <dune/fem/misc/threads/threadsafevalue.hh>
14#include <dune/fem/function/common/localcontribution.hh>
15#include <dune/fem/space/basisfunctionset/transformed.hh>
16#include <dune/fem/space/basisfunctionset/vectorial.hh>
17#include <dune/fem/space/combinedspace/interpolation.hh>
18#include <dune/fem/space/common/localinterpolation.hh>
30 template<
class LocalFunction,
class BasisFunctionSet >
31 struct LocalFunctionWrapper
41 LocalFunctionWrapper (
const LocalFunction &lf,
const BasisFunctionSet &bset ) : lf_( lf ) {}
44 void evaluate (
const Arg &x,
typename Traits::RangeType &y )
const
49 typename Traits::RangeType operator()(
const Arg &x)
const
51 typename Traits::RangeType y;
57 const LocalFunction &lf_;
61 template<
class LocalFunction,
class Entity,
class ShapeFunctionSet,
class Transformation >
62 struct LocalFunctionWrapper< LocalFunction, TransformedBasisFunctionSet< Entity, ShapeFunctionSet, Transformation > >
64 typedef TransformedBasisFunctionSet< Entity, ShapeFunctionSet, Transformation > BasisFunctionSetType;
74 LocalFunctionWrapper (
const LocalFunction &lf,
const BasisFunctionSetType &bset )
75 : lf_( lf ), bset_( bset )
81 void evaluate (
const Arg &x,
typename Traits::RangeType &y )
const
83 typename Traits::RangeType help;
84 lf_.evaluate( x, help );
88 typename Transformation::InverseTransformationType transf( bset_.geometry(), x );
89 y = transf.apply( help );
92 typename Traits::RangeType operator() (
const Arg &x )
const
94 typename Traits::RangeType y;
100 const LocalFunction &lf_;
101 const BasisFunctionSetType &bset_;
110 template<
class Space,
class LocalInterpolation,
bool scalarSFS >
111 class LocalFiniteElementInterpolation;
116 template<
class Space,
class LocalInterpolation >
117 class LocalFiniteElementInterpolation<Space,LocalInterpolation,false>
119 typedef LocalFiniteElementInterpolation< Space, LocalInterpolation,false > ThisType;
122 typedef typename Space::BasisFunctionSetType BasisFunctionSetType;
123 typedef LocalInterpolation LocalInterpolationType;
132 typedef std::size_t size_type;
134 template<
class LocalFunction >
135 using LocalFunctionWrapper = Impl::LocalFunctionWrapper< LocalFunction, BasisFunctionSetType >;
138 LocalFiniteElementInterpolation()
139 : basisFunctionSet_()
140 , localInterpolation_()
144 explicit LocalFiniteElementInterpolation (
const BasisFunctionSetType &basisFunctionSet,
145 const LocalInterpolationType &localInterpolation = LocalInterpolationType() )
146 : basisFunctionSet_( basisFunctionSet ),
147 localInterpolation_( localInterpolation )
150 ThisType& operator=(
const ThisType& other )
152 basisFunctionSet_ = other.basisFunctionSet_;
153 localInterpolation_.emplace( other.localInterpolation() );
162 template<
class LocalFunction,
class Dof >
163 void operator() (
const LocalFunction &localFunction, std::vector< Dof > &localDofVector )
const
165 LocalFunctionWrapper< LocalFunction > wrapper( localFunction, basisFunctionSet_ );
166 localInterpolation().interpolate( wrapper, localDofVector );
169 template<
class LocalFunction,
class Dof,
class Allocator >
172 (*this)(localFunction,localDofVector.container() );
175 template<
class LocalFunction,
class DofVector >
176 void operator() (
const LocalFunction &localFunction, DofVector &localDofVector )
const
178 LocalFunctionWrapper< LocalFunction > wrapper( localFunction, basisFunctionSet_ );
179 localInterpolation().interpolate( wrapper, localDofVector );
182 template<
class LocalFunction,
class DiscreteFunction,
template<
class >
class Assembly >
183 void operator() (
const LocalFunction &localFunction, LocalContribution< DiscreteFunction, Assembly > &localContribution )
const
185 (*this)(localFunction,localContribution.localDofVector());
188 BasisFunctionSetType basisFunctionSet ()
const {
return basisFunctionSet_; }
189 const LocalInterpolationType &localInterpolation ()
const
191 assert( localInterpolation_.has_value() );
192 return *localInterpolation_;
196 BasisFunctionSetType basisFunctionSet_;
197 std::optional< LocalInterpolationType > localInterpolation_;
202 template <
int dimRange>
203 struct RangeConverter
205 RangeConverter ( std::size_t
range ) : range_(
range ) {}
208 FieldVector< T, 1 > operator() (
const FieldVector< T, dimRange > &in )
const
213 template<
class T,
int j >
214 FieldMatrix< T, 1, j > operator() (
const FieldMatrix< T, dimRange, j > &in )
const
217 FieldMatrix<T,1,j> ret;
225 template <
class DofVector,
class DofAlignment>
226 struct SubDofVectorWrapper
227 :
public SubDofVector< DofVector, DofAlignment >
229 typedef SubDofVector< DofVector, DofAlignment > BaseType;
231 SubDofVectorWrapper( DofVector& dofs,
int coordinate,
const DofAlignment &dofAlignment )
232 : BaseType( dofs, coordinate, dofAlignment )
237 void resize(
const unsigned int) {}
245 template<
class Space,
class LocalInterpolation >
246 class LocalFiniteElementInterpolation<Space,LocalInterpolation,true>
248 typedef LocalFiniteElementInterpolation< Space, LocalInterpolation,true > ThisType;
251 typedef typename Space::BasisFunctionSetType BasisFunctionSetType;
252 typedef LocalInterpolation LocalInterpolationType;
261 static const int dimR = Space::FunctionSpaceType::dimRange;
263 typedef std::size_t size_type;
265 typedef VerticalDofAlignment< BasisFunctionSetType, RangeType> DofAlignmentType;
268 LocalFiniteElementInterpolation ()
269 : basisFunctionSet_(),
270 localInterpolation_(),
274 explicit LocalFiniteElementInterpolation (
const BasisFunctionSetType &basisFunctionSet,
275 const LocalInterpolationType &localInterpolation = LocalInterpolationType() )
276 : basisFunctionSet_( basisFunctionSet ),
277 localInterpolation_( localInterpolation ),
278 dofAlignment_( basisFunctionSet_ )
281 LocalFiniteElementInterpolation (
const ThisType& other )
282 : basisFunctionSet_( other.basisFunctionSet_ ),
283 localInterpolation_( other.localInterpolation_ ),
284 dofAlignment_( basisFunctionSet_ )
287 ThisType& operator=(
const ThisType& other )
289 basisFunctionSet_ = other.basisFunctionSet_;
290 localInterpolation_.emplace( other.localInterpolation() );
299 template<
class LocalFunction,
class Vector>
300 void operator() (
const LocalFunction &localFunction, Vector &localDofVector )
const
304 std::fill(localDofVector.begin(),localDofVector.end(),0);
305 for( std::size_t i = 0; i < dimR; ++i )
307 Impl::SubDofVectorWrapper< Vector, DofAlignmentType > subLdv( localDofVector, i, dofAlignment_ );
309 localFunctionConverter( localFunction, Impl::RangeConverter<dimR>(i) ),
310 subLdv, PriorityTag<42>()
315 template<
class LocalFunction,
class Dof,
class Allocator >
318 (*this)(localFunction,localDofVector.container() );
321 template<
class LocalFunction,
class DiscreteFunction,
template<
class >
class Assembly >
322 void operator() (
const LocalFunction &localFunction, LocalContribution< DiscreteFunction, Assembly > &localContribution )
const
324 (*this)(localFunction,localContribution.localDofVector());
327 BasisFunctionSetType basisFunctionSet ()
const {
return basisFunctionSet_; }
328 const LocalInterpolationType &localInterpolation ()
const
330 assert( localInterpolation_.has_value() );
331 return *localInterpolation_;
335 template<
class LocalFunction,
class Vector>
336 auto operator() (
const LocalFunction &localFunction, Vector &localDofVector, PriorityTag<1> )
const
338 std::declval<LocalInterpolationType>().interpolate(
339 localFunction, localDofVector)) >
341 localInterpolation().interpolate( localFunction, localDofVector );
343 template<
class LocalFunction,
class Vector>
344 void operator() (
const LocalFunction &localFunction, Vector &localDofVector, PriorityTag<0> )
const
346 std::vector<typename Vector::value_type> tmp(basisFunctionSet_.size());
347 localInterpolation().interpolate( localFunction, tmp);
348 for (
unsigned int i=0;i<tmp.size();++i)
349 localDofVector[i] = tmp[i];
351 BasisFunctionSetType basisFunctionSet_;
352 std::optional< LocalInterpolationType > localInterpolation_;
353 DofAlignmentType dofAlignment_;
356 template <
class DiscreteFunctionSpace >
357 class LocalFEInterpolationWrapper
358 :
public LocalInterpolationWrapper< DiscreteFunctionSpace >
360 typedef LocalInterpolationWrapper< DiscreteFunctionSpace > BaseType;
362 using BaseType :: interpolation_;
363 typedef std::vector< typename DiscreteFunctionSpace::RangeFieldType >
364 TemporarayDofVectorType;
367 using BaseType::interpolation;
373 using BaseType :: bind;
374 using BaseType :: unbind;
376 template<
class LocalFunction,
class Dof >
377 void operator() (
const LocalFunction &localFunction, std::vector< Dof > &localDofVector )
const
380 interpolation()( localFunction, localDofVector );
383 template<
class LocalFunction,
class Dof,
class Allocator >
387 (*this)(localFunction, localDofVector.container() );
391 template<
class LocalFunction,
class DiscreteFunction,
template<
class >
class Assembly >
392 void operator() (
const LocalFunction &localFunction, LocalContribution< DiscreteFunction, Assembly > &localContribution )
const
395 (*this)(localFunction, localContribution.localDofVector());
399 template<
class LocalFunction,
class LocalDofVector >
400 void operator () (
const LocalFunction &localFunction, LocalDofVector &dofs )
const
402 const int size = dofs.size();
403 TemporarayDofVectorType& tmpDofs = *tmpDofs_;
404 tmpDofs.resize(
size );
405 (*this)(localFunction, tmpDofs );
408 for(
int i=0; i<
size; ++i )
410 dofs[ i ] = tmpDofs[ i ];
Construct a vector with a dynamic size.
Definition: dynvector.hh:59
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
@ dimRange
dimension of range vector space
Definition: functionspaceinterface.hh:48
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
A vector valued function space.
Definition: functionspace.hh:60
FunctionSpaceType::DomainType DomainType
type of domain vectors, i.e., type of coordinates
Definition: localfunction.hh:108
FunctionSpaceType::RangeType RangeType
type of range vectors, i.e., type of function values
Definition: localfunction.hh:110
Implements a vector constructed from a given type representing a field and a compile-time given size.
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
free standing function for setting up a range based for loop over an integer range for (auto i: range...
Definition: rangeutilities.hh:288
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75