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 DiscreteFunction,
template<
class >
class Assembly >
176 void operator() (
const LocalFunction &localFunction, LocalContribution< DiscreteFunction, Assembly > &localContribution )
const
178 (*this)(localFunction,localContribution.localDofVector());
181 BasisFunctionSetType basisFunctionSet ()
const {
return basisFunctionSet_; }
182 const LocalInterpolationType &localInterpolation ()
const
184 assert( localInterpolation_.has_value() );
185 return *localInterpolation_;
189 BasisFunctionSetType basisFunctionSet_;
190 std::optional< LocalInterpolationType > localInterpolation_;
195 template <
int dimRange>
196 struct RangeConverter
198 RangeConverter ( std::size_t
range ) : range_(
range ) {}
201 FieldVector< T, 1 > operator() (
const FieldVector< T, dimRange > &in )
const
206 template<
class T,
int j >
207 FieldMatrix< T, 1, j > operator() (
const FieldMatrix< T, dimRange, j > &in )
const
210 FieldMatrix<T,1,j> ret;
218 template <
class DofVector,
class DofAlignment>
219 struct SubDofVectorWrapper
220 :
public SubDofVector< DofVector, DofAlignment >
222 typedef SubDofVector< DofVector, DofAlignment > BaseType;
224 SubDofVectorWrapper( DofVector& dofs,
int coordinate,
const DofAlignment &dofAlignment )
225 : BaseType( dofs, coordinate, dofAlignment )
230 void resize(
const unsigned int) {}
238 template<
class Space,
class LocalInterpolation >
239 class LocalFiniteElementInterpolation<Space,LocalInterpolation,true>
241 typedef LocalFiniteElementInterpolation< Space, LocalInterpolation,true > ThisType;
244 typedef typename Space::BasisFunctionSetType BasisFunctionSetType;
245 typedef LocalInterpolation LocalInterpolationType;
254 static const int dimR = Space::FunctionSpaceType::dimRange;
256 typedef std::size_t size_type;
258 typedef VerticalDofAlignment< BasisFunctionSetType, RangeType> DofAlignmentType;
261 LocalFiniteElementInterpolation ()
262 : basisFunctionSet_(),
263 localInterpolation_(),
267 explicit LocalFiniteElementInterpolation (
const BasisFunctionSetType &basisFunctionSet,
268 const LocalInterpolationType &localInterpolation = LocalInterpolationType() )
269 : basisFunctionSet_( basisFunctionSet ),
270 localInterpolation_( localInterpolation ),
271 dofAlignment_( basisFunctionSet_ )
274 LocalFiniteElementInterpolation (
const ThisType& other )
275 : basisFunctionSet_( other.basisFunctionSet_ ),
276 localInterpolation_( other.localInterpolation_ ),
277 dofAlignment_( basisFunctionSet_ )
280 ThisType& operator=(
const ThisType& other )
282 basisFunctionSet_ = other.basisFunctionSet_;
283 localInterpolation_.emplace( other.localInterpolation() );
292 template<
class LocalFunction,
class Vector>
293 void operator() (
const LocalFunction &localFunction, Vector &localDofVector )
const
297 std::fill(localDofVector.begin(),localDofVector.end(),0);
298 for( std::size_t i = 0; i < dimR; ++i )
300 Impl::SubDofVectorWrapper< Vector, DofAlignmentType > subLdv( localDofVector, i, dofAlignment_ );
302 localFunctionConverter( localFunction, Impl::RangeConverter<dimR>(i) ),
303 subLdv, PriorityTag<42>()
308 template<
class LocalFunction,
class Dof,
class Allocator >
311 (*this)(localFunction,localDofVector.container() );
314 template<
class LocalFunction,
class DiscreteFunction,
template<
class >
class Assembly >
315 void operator() (
const LocalFunction &localFunction, LocalContribution< DiscreteFunction, Assembly > &localContribution )
const
317 (*this)(localFunction,localContribution.localDofVector());
320 BasisFunctionSetType basisFunctionSet ()
const {
return basisFunctionSet_; }
321 const LocalInterpolationType &localInterpolation ()
const
323 assert( localInterpolation_.has_value() );
324 return *localInterpolation_;
328 template<
class LocalFunction,
class Vector>
329 auto operator() (
const LocalFunction &localFunction, Vector &localDofVector, PriorityTag<1> )
const
331 std::declval<LocalInterpolationType>().interpolate(
332 localFunction, localDofVector)) >
334 localInterpolation().interpolate( localFunction, localDofVector );
336 template<
class LocalFunction,
class Vector>
337 void operator() (
const LocalFunction &localFunction, Vector &localDofVector, PriorityTag<0> )
const
339 std::vector<typename Vector::value_type> tmp(basisFunctionSet_.size());
340 localInterpolation().interpolate( localFunction, tmp);
341 for (
unsigned int i=0;i<tmp.size();++i)
342 localDofVector[i] = tmp[i];
344 BasisFunctionSetType basisFunctionSet_;
345 std::optional< LocalInterpolationType > localInterpolation_;
346 DofAlignmentType dofAlignment_;
349 template <
class DiscreteFunctionSpace >
350 class LocalFEInterpolationWrapper
351 :
public LocalInterpolationWrapper< DiscreteFunctionSpace >
353 typedef LocalInterpolationWrapper< DiscreteFunctionSpace > BaseType;
355 using BaseType :: interpolation_;
356 typedef std::vector< typename DiscreteFunctionSpace::RangeFieldType >
357 TemporarayDofVectorType;
360 using BaseType::interpolation;
366 using BaseType :: bind;
367 using BaseType :: unbind;
369 template<
class LocalFunction,
class Dof >
370 void operator() (
const LocalFunction &localFunction, std::vector< Dof > &localDofVector )
const
373 interpolation()( localFunction, localDofVector );
376 template<
class LocalFunction,
class Dof,
class Allocator >
380 (*this)(localFunction, localDofVector.container() );
384 template<
class LocalFunction,
class DiscreteFunction,
template<
class >
class Assembly >
385 void operator() (
const LocalFunction &localFunction, LocalContribution< DiscreteFunction, Assembly > &localContribution )
const
388 (*this)(localFunction, localContribution.localDofVector());
392 template<
class LocalFunction,
class LocalDofVector >
393 void operator () (
const LocalFunction &localFunction, LocalDofVector &dofs )
const
395 const int size = dofs.size();
396 TemporarayDofVectorType& tmpDofs = *tmpDofs_;
397 tmpDofs.resize(
size );
398 (*this)(localFunction, tmpDofs );
401 for(
int i=0; i<
size; ++i )
403 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:294
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