1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
7#include <dune/fem/common/forloop.hh>
8#include <dune/fem/function/localfunction/converter.hh>
9#include <dune/fem/space/basisfunctionset/tuple.hh>
10#include <dune/fem/space/basisfunctionset/vectorial.hh>
11#include <dune/fem/storage/subvector.hh>
23 template<
class Space,
int N >
24 class PowerSpaceInterpolation
26 typedef PowerSpaceInterpolation< Space, N > ThisType;
30 RangeConverter ( std::size_t
range ) : range_(
range ) {}
38 template<
class T,
int j >
39 FieldMatrix< T, 1, j > operator() (
const FieldMatrix< T, N, j > &in )
const
48 template <
class DofVector,
class DofAlignment>
49 struct SubDofVectorWrapper
50 :
public SubDofVector< DofVector, DofAlignment >
52 typedef SubDofVector< DofVector, DofAlignment > BaseType;
54 SubDofVectorWrapper( DofVector& dofs,
int coordinate,
const DofAlignment &dofAlignment )
55 : BaseType( dofs, coordinate, dofAlignment )
63 typedef typename Space::BasisFunctionSetType::DofAlignmentType DofAlignmentType;
66 typedef typename Space::EntityType EntityType;
68 PowerSpaceInterpolation (
const Space &space,
const EntityType &entity )
69 : interpolation_( space.containedSpace().localInterpolation( entity ) ),
70 dofAlignment_( space.basisFunctionSet( entity ).dofAlignment() )
73 template<
class LocalFunction,
class LocalDofVector >
74 void operator () (
const LocalFunction &lv, LocalDofVector &ldv )
const
79 template<
class LocalFunction,
class LocalDofVector >
80 void apply (
const LocalFunction &lv, LocalDofVector &ldv )
const
85 for( std::size_t i = 0; i < N; ++i )
87 SubDofVectorWrapper< LocalDofVector, DofAlignmentType > subLdv( ldv, i, dofAlignment_ );
88 interpolation_( localFunctionConverter( lv, RangeConverter( i ) ), subLdv );
93 typename Space::ContainedDiscreteFunctionSpaceType::InterpolationImplType interpolation_;
94 DofAlignmentType dofAlignment_;
104 template<
class CombineOp ,
class ... Spaces >
105 class TupleSpaceInterpolation
107 typedef TupleSpaceInterpolation< CombineOp, Spaces ... > ThisType;
108 typedef std::tuple<
typename Spaces::InterpolationImplType ... > InterpolationTupleType;
110 static const int setSize =
sizeof ... ( Spaces ) -1;
116 struct SummationApply;
118 template<
int,
class CombOp >
121 template<
int counter >
122 struct ApplyBase< counter, TupleSpaceProduct > :
public ProductApply< counter >{};
124 template<
int counter >
125 struct ApplyBase< counter, TupleSpaceSummation > :
public SummationApply< counter >{};
127 template <
int counter >
128 struct Apply :
public ApplyBase< counter, CombineOp > {};
130 typedef TupleBasisFunctionSet< CombineOp,
typename Spaces::BasisFunctionSetType ... > BasisFunctionSetType;
134 static_assert( Std::are_all_same<
typename Spaces::EntityType ... >::value,
135 "TupleSpaceInterpolation requires Spaces defined over the same grid" );
137 typedef typename std::tuple_element< 0, std::tuple< Spaces ... > >::type::EntityType EntityType;
146 TupleSpaceInterpolation (
const Spaces & ... spaces,
const EntityType &entity )
147 : interpolation_(
std::make_tuple( spaces.localInterpolation( entity ) ... ) ),
148 basisFunctionSet_(
std::make_tuple( spaces.basisFunctionSet( entity ) ... ) )
151 template<
class LocalFunction,
class LocalDofVector >
152 void operator() (
const LocalFunction &lf, LocalDofVector &ldv )
const
154 Fem::ForLoop< Apply, 0, setSize >::apply( interpolation_, basisFunctionSet_, lf, ldv );
160 InterpolationTupleType interpolation_;
161 BasisFunctionSetType basisFunctionSet_;
166 template<
class CombineOp,
class ... Spaces >
168 struct TupleSpaceInterpolation< CombineOp, Spaces ... >::ProductApply
170 static const int rangeOffset = BasisFunctionSetType::RangeIndices::template offset< i >();
171 static const int thisDimRange = BasisFunctionSetType::template SubBasisFunctionSet< i >::type::FunctionSpaceType::dimRange;
172 static const int dimRange = BasisFunctionSetType::FunctionSpaceType::dimRange;
174 struct RangeConverter
177 FieldVector< T, thisDimRange > operator() (
const FieldVector< T, dimRange > &in )
const
179 FieldVector< T, thisDimRange > ret;
184 template<
class T,
int j >
185 FieldMatrix< T, thisDimRange, j > operator() (
const FieldMatrix< T, dimRange, j > &in )
const
187 FieldMatrix< T, thisDimRange, j > ret;
193 template<
class In,
class Out >
194 void apply (
const In &in, Out &out )
const
196 for( std::size_t j = 0; j < thisDimRange; ++j )
197 out[ j ] = in[ j + rangeOffset ];
201 template<
class Tuple,
class LocalFunction,
class LocalDofVector >
202 static void apply (
const Tuple &tuple,
const BasisFunctionSetType &basisSet,
const LocalFunction &lv, LocalDofVector &ldv )
204 SubVector< LocalDofVector, OffsetSubMapper >
205 subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
206 std::get< i >( tuple ) ( localFunctionConverter( lv, RangeConverter() ), subLdv );
211 template<
class CombineOp,
class ... Spaces >
213 struct TupleSpaceInterpolation< CombineOp, Spaces ... >::SummationApply
215 template<
class Tuple,
class LocalFunction,
class LocalDofVector >
216 static void apply (
const Tuple &tuple,
const BasisFunctionSetType &basisSet,
const LocalFunction &lv, LocalDofVector &ldv )
218 SubVector< LocalDofVector, OffsetSubMapper >
219 subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
220 std::get< i >( tuple ) ( lv, subLdv );
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