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;
139 TupleSpaceInterpolation ( std::tuple< const Spaces & ... > tuple,
const EntityType &entity )
140 : interpolation_( interpolationTuple( tuple, entity ) ),
141 basisFunctionSet_( basisFunctionSetTuple( tuple, entity ) )
144 TupleSpaceInterpolation (
const Spaces & ... spaces,
const EntityType &entity )
145 : interpolation_(
std::make_tuple( spaces.localInterpolation( entity ) ... ) ),
146 basisFunctionSet_(
std::make_tuple( spaces.basisFunctionSet( entity ) ... ) )
149 template<
class LocalFunction,
class LocalDofVector >
150 void operator() (
const LocalFunction &lf, LocalDofVector &ldv )
const
152 Fem::ForLoop< Apply, 0, setSize >::apply( interpolation_, basisFunctionSet_, lf, ldv );
158 InterpolationTupleType interpolation_;
159 BasisFunctionSetType basisFunctionSet_;
164 template<
class CombineOp,
class ... Spaces >
166 struct TupleSpaceInterpolation< CombineOp, Spaces ... >::ProductApply
168 static const int rangeOffset = BasisFunctionSetType::RangeIndices::template offset< i >();
169 static const int thisDimRange = BasisFunctionSetType::template SubBasisFunctionSet< i >::type::FunctionSpaceType::dimRange;
170 static const int dimRange = BasisFunctionSetType::FunctionSpaceType::dimRange;
172 struct RangeConverter
175 FieldVector< T, thisDimRange > operator() (
const FieldVector< T, dimRange > &in )
const
177 FieldVector< T, thisDimRange > ret;
182 template<
class T,
int j >
183 FieldMatrix< T, thisDimRange, j > operator() (
const FieldMatrix< T, dimRange, j > &in )
const
185 FieldMatrix< T, thisDimRange, j > ret;
191 template<
class In,
class Out >
192 void apply (
const In &in, Out &out )
const
194 for( std::size_t j = 0; j < thisDimRange; ++j )
195 out[ j ] = in[ j + rangeOffset ];
199 template<
class Tuple,
class LocalFunction,
class LocalDofVector >
200 static void apply (
const Tuple &tuple,
const BasisFunctionSetType &basisSet,
const LocalFunction &lv, LocalDofVector &ldv )
202 SubVector< LocalDofVector, OffsetSubMapper >
203 subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
204 std::get< i >( tuple ) ( localFunctionConverter( lv, RangeConverter() ), subLdv );
209 template<
class CombineOp,
class ... Spaces >
211 struct TupleSpaceInterpolation< CombineOp, Spaces ... >::SummationApply
213 template<
class Tuple,
class LocalFunction,
class LocalDofVector >
214 static void apply (
const Tuple &tuple,
const BasisFunctionSetType &basisSet,
const LocalFunction &lv, LocalDofVector &ldv )
216 SubVector< LocalDofVector, OffsetSubMapper >
217 subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
218 std::get< i >( tuple ) ( lv, subLdv );
Dune namespace.
Definition: alignedallocator.hh:13