dune-fem  2.8-git
combinedspace/interpolation.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
2 #define DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
3 
4 #include <tuple>
5 #include <utility>
6 
12 
13 
14 namespace Dune
15 {
16 
17  namespace Fem
18  {
19 
20  // PowerSpaceInterpolation
21  // ------------------
22 
23  template< class Space, int N >
25  {
27 
28  struct RangeConverter
29  {
30  RangeConverter ( std::size_t range ) : range_( range ) {}
31 
32  template< class T >
33  FieldVector< T, 1 > operator() ( const FieldVector< T, N > &in ) const
34  {
35  return in[ range_ ];
36  }
37 
38  template< class T, int j >
39  FieldMatrix< T, 1, j > operator() ( const FieldMatrix< T, N, j > &in ) const
40  {
41  return in[ range_ ];
42  }
43 
44  protected:
45  std::size_t range_;
46  };
47 
48  template <class DofVector, class DofAlignment>
49  struct SubDofVectorWrapper
50  : public SubDofVector< DofVector, DofAlignment >
51  {
53 
54  SubDofVectorWrapper( DofVector& dofs, int coordinate, const DofAlignment &dofAlignment )
55  : BaseType( dofs, coordinate, dofAlignment )
56  {}
57 
59  void clear() {}
60  };
61 
62  // Note: BasisFunctionSetType is VectorialBasisFunctionSet
63  typedef typename Space::BasisFunctionSetType::DofAlignmentType DofAlignmentType;
64 
65  public:
66  typedef typename Space::EntityType EntityType;
67 
68  PowerSpaceInterpolation ( const Space &space, const EntityType &entity )
69  : interpolation_( space.containedSpace().localInterpolation( entity ) ),
70  dofAlignment_( space.basisFunctionSet( entity ).dofAlignment() )
71  {}
72 
73  template< class LocalFunction, class LocalDofVector >
74  void operator () ( const LocalFunction &lv, LocalDofVector &ldv ) const
75  {
76  apply( lv, ldv );
77  }
78 
79  template< class LocalFunction, class LocalDofVector >
80  void apply ( const LocalFunction &lv, LocalDofVector &ldv ) const
81  {
82  // clear dofs before something is adedd
83  ldv.clear();
84 
85  for( std::size_t i = 0; i < N; ++i )
86  {
87  SubDofVectorWrapper< LocalDofVector, DofAlignmentType > subLdv( ldv, i, dofAlignment_ );
88  interpolation_( localFunctionConverter( lv, RangeConverter( i ) ), subLdv );
89  }
90  }
91 
92  protected:
93  typename Space::ContainedDiscreteFunctionSpaceType::InterpolationImplType interpolation_;
94  DofAlignmentType dofAlignment_;
95  };
96 
97 
98  // TupleSpaceInterpolation
99  // -----------------------
100  // CombineOp describes the way in which the spaces have been combined, i.e.
101  // Product: V = V_1 x V_2 x ...
102  // Summation: V = V_1 + V_2 + ...
103 
104  template< class CombineOp , class ... Spaces >
106  {
107  typedef TupleSpaceInterpolation< CombineOp, Spaces ... > ThisType;
108  typedef std::tuple< typename Spaces::InterpolationImplType ... > InterpolationTupleType;
109 
110  static const int setSize = sizeof ... ( Spaces ) -1;
111 
112  template< int >
113  struct ProductApply;
114 
115  template< int >
116  struct SummationApply;
117 
118  template< int, class CombOp >
119  struct ApplyBase;
120 
121  template< int counter >
122  struct ApplyBase< counter, TupleSpaceProduct > : public ProductApply< counter >{};
123 
124  template< int counter >
125  struct ApplyBase< counter, TupleSpaceSummation > : public SummationApply< counter >{};
126 
127  template < int counter >
128  struct Apply : public ApplyBase< counter, CombineOp > {};
129 
130  typedef TupleBasisFunctionSet< CombineOp, typename Spaces::BasisFunctionSetType ... > BasisFunctionSetType;
131 
132  public:
133 
135  "TupleSpaceInterpolation requires Spaces defined over the same grid" );
136 
137  typedef typename std::tuple_element< 0, std::tuple< Spaces ... > >::type::EntityType EntityType;
138 
139  TupleSpaceInterpolation ( std::tuple< const Spaces & ... > tuple, const EntityType &entity )
140  : interpolation_( interpolationTuple( tuple, entity ) ),
141  basisFunctionSet_( basisFunctionSetTuple( tuple, entity ) )
142  {}
143 
144  TupleSpaceInterpolation ( const Spaces & ... spaces, const EntityType &entity )
145  : interpolation_( std::make_tuple( spaces.localInterpolation( entity ) ... ) ),
146  basisFunctionSet_( std::make_tuple( spaces.basisFunctionSet( entity ) ... ) )
147  {}
148 
149  template< class LocalFunction, class LocalDofVector >
150  void operator() ( const LocalFunction &lf, LocalDofVector &ldv ) const
151  {
153  }
154 
155  void unbind() {}
156 
157  protected:
158  InterpolationTupleType interpolation_;
160  };
161 
162 
163  // specialization of TupleSpaceInterpolation::Apply for SpaceProduct
164  template< class CombineOp, class ... Spaces >
165  template< int i >
166  struct TupleSpaceInterpolation< CombineOp, Spaces ... >::ProductApply
167  {
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;
171 
173  {
174  template< class T >
175  FieldVector< T, thisDimRange > operator() ( const FieldVector< T, dimRange > &in ) const
176  {
177  FieldVector< T, thisDimRange > ret;
178  apply( in, ret );
179  return ret;
180  }
181 
182  template< class T, int j >
183  FieldMatrix< T, thisDimRange, j > operator() ( const FieldMatrix< T, dimRange, j > &in ) const
184  {
185  FieldMatrix< T, thisDimRange, j > ret;
186  apply( in, ret );
187  return ret;
188  }
189 
190  protected:
191  template< class In, class Out >
192  void apply ( const In &in, Out &out ) const
193  {
194  for( std::size_t j = 0; j < thisDimRange; ++j )
195  out[ j ] = in[ j + rangeOffset ];
196  }
197  };
198 
199  template< class Tuple, class LocalFunction, class LocalDofVector >
200  static void apply ( const Tuple &tuple, const BasisFunctionSetType &basisSet, const LocalFunction &lv, LocalDofVector &ldv )
201  {
203  subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
204  std::get< i >( tuple ) ( localFunctionConverter( lv, RangeConverter() ), subLdv );
205  }
206  };
207 
208 
209  template< class CombineOp, class ... Spaces >
210  template< int i >
211  struct TupleSpaceInterpolation< CombineOp, Spaces ... >::SummationApply
212  {
213  template< class Tuple, class LocalFunction, class LocalDofVector >
214  static void apply ( const Tuple &tuple, const BasisFunctionSetType &basisSet, const LocalFunction &lv, LocalDofVector &ldv )
215  {
216  SubVector< LocalDofVector, OffsetSubMapper >
217  subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
218  std::get< i >( tuple ) ( lv, subLdv );
219  }
220  };
221 
222  } // namespace Fem
223 
224 } // namespace Dune
225 
226 #endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
Definition: bindguard.hh:11
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
LocalFunctionConverter< HostLocalFunction, Converter, __InstationaryFunction::HoldCopy > localFunctionConverter(HostLocalFunction hostLocalFunction, const Converter &converter=Converter())
Definition: converter.hh:199
IteratorRange< typename DF::DofIteratorType > dofs(DF &df)
Iterates over all DOFs.
Definition: rangegenerators.hh:76
static DUNE_PRIVATE void apply(Args &&... args)
Definition: forloop.hh:23
Definition: utility.hh:147
interface for local functions
Definition: localfunction.hh:77
Definition: space/basisfunctionset/tuple.hh:34
Definition: space/basisfunctionset/tuple.hh:35
Definition: space/basisfunctionset/tuple.hh:39
std::size_t offset(int i) const
return offset of the i-th subbasisfunctionSet in the whole set
Definition: space/basisfunctionset/tuple.hh:418
std::size_t size() const
return size of basis function set
Definition: space/basisfunctionset/tuple.hh:256
Interface documentation for Dof alignment classes used in VectorialBasisFunctionSet.
Definition: basisfunctionset/vectorial.hh:34
Extract Sub dof vector for single coordinate.
Definition: basisfunctionset/vectorial.hh:179
Definition: combinedspace/interpolation.hh:25
void apply(const LocalFunction &lv, LocalDofVector &ldv) const
Definition: combinedspace/interpolation.hh:80
Space::EntityType EntityType
Definition: combinedspace/interpolation.hh:66
void operator()(const LocalFunction &lv, LocalDofVector &ldv) const
Definition: combinedspace/interpolation.hh:74
DofAlignmentType dofAlignment_
Definition: combinedspace/interpolation.hh:94
Space::ContainedDiscreteFunctionSpaceType::InterpolationImplType interpolation_
Definition: combinedspace/interpolation.hh:93
PowerSpaceInterpolation(const Space &space, const EntityType &entity)
Definition: combinedspace/interpolation.hh:68
Definition: combinedspace/interpolation.hh:106
void unbind()
Definition: combinedspace/interpolation.hh:155
InterpolationTupleType interpolation_
Definition: combinedspace/interpolation.hh:158
TupleSpaceInterpolation(std::tuple< const Spaces &... > tuple, const EntityType &entity)
Definition: combinedspace/interpolation.hh:139
std::tuple_element< 0, std::tuple< Spaces ... > >::type::EntityType EntityType
Definition: combinedspace/interpolation.hh:135
void operator()(const LocalFunction &lf, LocalDofVector &ldv) const
Definition: combinedspace/interpolation.hh:150
TupleSpaceInterpolation(const Spaces &... spaces, const EntityType &entity)
Definition: combinedspace/interpolation.hh:144
BasisFunctionSetType basisFunctionSet_
Definition: combinedspace/interpolation.hh:159
Definition: combinedspace/interpolation.hh:173
void apply(const In &in, Out &out) const
Definition: combinedspace/interpolation.hh:192
An implementation of DenseVector to extract a portion, not necessarly contiguos, of a vector.
Definition: subvector.hh:161
Index mapper which simply adds an offset to the index.
Definition: subvector.hh:83