Loading [MathJax]/extensions/tex2jax.js

DUNE-FEM (unstable)

interpolation.hh
1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
3
4#include <tuple>
5#include <utility>
6
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>
12
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19
20 // PowerSpaceInterpolation
21 // ------------------
22
23 template< class Space, int N >
24 class PowerSpaceInterpolation
25 {
26 typedef PowerSpaceInterpolation< Space, N > ThisType;
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 {
52 typedef SubDofVector< DofVector, DofAlignment > BaseType;
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 >
105 class TupleSpaceInterpolation
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
134 static_assert( Std::are_all_same< typename Spaces::EntityType ... >::value,
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 /*
140 TupleSpaceInterpolation ( std::tuple< const Spaces & ... > tuple, const EntityType &entity )
141 : interpolation_( interpolationTuple( tuple, entity ) ),
142 basisFunctionSet_( basisFunctionSetTuple( tuple, entity ) )
143 {}
144 */
145
146 TupleSpaceInterpolation ( const Spaces & ... spaces, const EntityType &entity )
147 : interpolation_( std::make_tuple( spaces.localInterpolation( entity ) ... ) ),
148 basisFunctionSet_( std::make_tuple( spaces.basisFunctionSet( entity ) ... ) )
149 {}
150
151 template< class LocalFunction, class LocalDofVector >
152 void operator() ( const LocalFunction &lf, LocalDofVector &ldv ) const
153 {
154 Fem::ForLoop< Apply, 0, setSize >::apply( interpolation_, basisFunctionSet_, lf, ldv );
155 }
156
157 void unbind() {}
158
159 protected:
160 InterpolationTupleType interpolation_;
161 BasisFunctionSetType basisFunctionSet_;
162 };
163
164
165 // specialization of TupleSpaceInterpolation::Apply for SpaceProduct
166 template< class CombineOp, class ... Spaces >
167 template< int i >
168 struct TupleSpaceInterpolation< CombineOp, Spaces ... >::ProductApply
169 {
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;
173
174 struct RangeConverter
175 {
176 template< class T >
177 FieldVector< T, thisDimRange > operator() ( const FieldVector< T, dimRange > &in ) const
178 {
179 FieldVector< T, thisDimRange > ret;
180 apply( in, ret );
181 return ret;
182 }
183
184 template< class T, int j >
185 FieldMatrix< T, thisDimRange, j > operator() ( const FieldMatrix< T, dimRange, j > &in ) const
186 {
187 FieldMatrix< T, thisDimRange, j > ret;
188 apply( in, ret );
189 return ret;
190 }
191
192 protected:
193 template< class In, class Out >
194 void apply ( const In &in, Out &out ) const
195 {
196 for( std::size_t j = 0; j < thisDimRange; ++j )
197 out[ j ] = in[ j + rangeOffset ];
198 }
199 };
200
201 template< class Tuple, class LocalFunction, class LocalDofVector >
202 static void apply ( const Tuple &tuple, const BasisFunctionSetType &basisSet, const LocalFunction &lv, LocalDofVector &ldv )
203 {
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 );
207 }
208 };
209
210
211 template< class CombineOp, class ... Spaces >
212 template< int i >
213 struct TupleSpaceInterpolation< CombineOp, Spaces ... >::SummationApply
214 {
215 template< class Tuple, class LocalFunction, class LocalDofVector >
216 static void apply ( const Tuple &tuple, const BasisFunctionSetType &basisSet, const LocalFunction &lv, LocalDofVector &ldv )
217 {
218 SubVector< LocalDofVector, OffsetSubMapper >
219 subLdv( ldv, OffsetSubMapper( basisSet.template subBasisFunctionSet< i >().size(), basisSet.offset( i ) ) );
220 std::get< i >( tuple ) ( lv, subLdv );
221 }
222 };
223
224 } // namespace Fem
225
226} // namespace Dune
227
228#endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_INTERPOLATION_HH
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
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 28, 22:35, 2025)