DUNE-FEM (unstable)

restrictprolongtuple.hh
1#ifndef DUNE_FEM_SPACE_COMMON_RESTRICTPROLONGTUPLE_HH
2#define DUNE_FEM_SPACE_COMMON_RESTRICTPROLONGTUPLE_HH
3
4#include <tuple>
5#include <utility>
6
7#include <dune/fem/common/forloop.hh>
9
10#include <dune/fem/space/common/restrictprolonginterface.hh>
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
18 // Internal forward declaration
19 // ----------------------------
20
21 template< class... RestrictProlongInterfaces >
23 template< class... DiscreteFunctions >
25
26
27
28 // RestrictProlongTuple
29 // --------------------
30
44 template< class Head, class... Tail >
45 class RestrictProlongTuple< Head, Tail... >
46 : public Dune::Fem::RestrictProlongInterface< RestrictProlongTraits< RestrictProlongTuple< Head, Tail... >, typename Head::DomainFieldType > >
47 {
48 typedef Dune::Fem::RestrictProlongInterface< RestrictProlongTraits< RestrictProlongTuple< Head, Tail... >, typename Head::DomainFieldType > > BaseType;
49
50 template< int i > struct AddToList;
51 template< int i > struct AddToLoadBalancer;
52 template< int i > struct ProlongLocal;
53 template< int i > struct RestrictLocal;
54 template< int i > struct SetFatherChildWeight;
55 template< int i > struct Initialize;
56 template< int i > struct Finalize;
57
58 public:
60 typedef typename BaseType::DomainFieldType DomainFieldType;
61
66 explicit RestrictProlongTuple ( Head &&head, Tail &&... tail )
67 : tuple_( std::forward< Head >( head ), std::forward< Tail >( tail )... )
68 {}
69
70 explicit RestrictProlongTuple ( std::tuple< Head, Tail... > &&tuple )
71 : tuple_( tuple )
72 {}
73
81 void initialize ()
82 {
83 Dune::Fem::ForLoop< Initialize, 0, sizeof...( Tail ) >::apply( tuple_ );
84 }
85
87 void finalize ()
88 {
89 Dune::Fem::ForLoop< Finalize, 0, sizeof...( Tail ) >::apply( tuple_ );
90 }
91
93 void setFatherChildWeight ( const DomainFieldType &weight ) const
94 {
95 Dune::Fem::ForLoop< SetFatherChildWeight, 0, sizeof...( Tail ) >::apply( weight, tuple_ );
96 }
97
99 template< class Entity >
100 void restrictLocal ( const Entity &father, const Entity &child, bool initialize ) const
101 {
102 Dune::Fem::ForLoop< RestrictLocal, 0, sizeof...( Tail ) >::apply( father, child, initialize, tuple_ );
103 }
104
106 template< class Entity, class LocalGeometry >
107 void restrictLocal ( const Entity &father, const Entity &child,
108 const LocalGeometry &geometryInFather, bool initialize ) const
109 {
110 Dune::Fem::ForLoop< RestrictLocal, 0, sizeof...( Tail ) >::apply( father, child, geometryInFather, initialize, tuple_ );
111 }
112
113 template< class Entity >
114 void restrictFinalize ( const Entity &father ) const
115 {
116 }
117
119 template< class Entity >
120 void prolongLocal ( const Entity &father, const Entity &child, bool initialize ) const
121 {
122 Dune::Fem::ForLoop< ProlongLocal, 0, sizeof...( Tail ) >::apply( father, child, initialize, tuple_ );
123 }
124
126 template< class Entity, class LocalGeometry >
127 void prolongLocal ( const Entity &father, const Entity &child,
128 const LocalGeometry &geometryInFather, bool initialize ) const
129 {
130 Dune::Fem::ForLoop< ProlongLocal, 0, sizeof...( Tail ) >::apply( father, child, geometryInFather, initialize, tuple_ );
131 }
132
134 template< class Communicator, class Operation >
135 void addToList ( Communicator &comm, const Operation& op )
136 {
137 Dune::Fem::ForLoop< AddToList, 0, sizeof...( Tail ) >::apply( comm, tuple_, op );
138 }
139
141 template< class Communicator >
142 void addToList ( Communicator &comm )
143 {
144 Dune::Fem::ForLoop< AddToList, 0, sizeof...( Tail ) >::apply( comm, tuple_ );
145 }
146
148 template< class LoadBalancer >
149 void addToLoadBalancer ( LoadBalancer &loadBalancer )
150 {
151 Dune::Fem::ForLoop< AddToLoadBalancer, 0, sizeof...( Tail ) >::apply( loadBalancer, tuple_ );
152 }
153
156 private:
157 std::tuple< Head, Tail... > tuple_;
158 };
159
160
161
162 // RestrictProlongTuple< Head, Tail... >::AddToList
163 // ------------------------------------------------
164
165 template< class Head, class... Tail >
166 template< int i >
167 struct RestrictProlongTuple< Head, Tail... >::AddToList
168 {
169 template< class Communicator, class Operation >
170 static void apply ( Communicator &comm, std::tuple< Head, Tail... > &tuple, const Operation& op )
171 {
172 std::get< i >( tuple ).addToList( comm, op );
173 }
174
175 template< class Communicator >
176 static void apply ( Communicator &comm, std::tuple< Head, Tail... > &tuple )
177 {
178 std::get< i >( tuple ).addToList( comm );
179 }
180 };
181
182
183
184 // RestrictProlongTuple< Head, Tail... >::AddToLoadBalancer
185 // --------------------------------------------------------
186
187 template< class Head, class... Tail >
188 template< int i >
189 struct RestrictProlongTuple< Head, Tail... >::AddToLoadBalancer
190 {
191 template< class LoadBalancer >
192 static void apply ( LoadBalancer &loadBalancer, std::tuple< Head, Tail... > &tuple )
193 {
194 std::get< i >( tuple ).addToLoadBalancer( loadBalancer );
195 }
196 };
197
198
199
200 // RestrictProlongTuple< Head, Tail... >::ProlongLocal
201 // ---------------------------------------------------
202
203 template< class Head, class... Tail >
204 template< int i >
205 struct RestrictProlongTuple< Head, Tail... >::ProlongLocal
206 {
207 template< class Entity >
208 static void apply ( const Entity &father, const Entity &child, bool initialize,
209 const std::tuple< Head, Tail... > &tuple )
210 {
211 std::get< i >( tuple ).prolongLocal( father, child, initialize );
212 }
213
214 template< class Entity, class LocalGeometry >
215 static void apply ( const Entity &father, const Entity &child, const LocalGeometry &geometryInFather, bool initialize,
216 const std::tuple< Head, Tail... > &tuple )
217 {
218 std::get< i >( tuple ).prolongLocal( father, child, geometryInFather, initialize );
219 }
220 };
221
222
223
224 // RestrictProlongTuple< Head, Tail... >::RestrictLocal
225 // ----------------------------------------------------
226
227 template< class Head, class... Tail >
228 template< int i >
229 struct RestrictProlongTuple< Head, Tail... >::RestrictLocal
230 {
231 template< class Entity >
232 static void apply ( const Entity &father, const Entity &child, bool initialize,
233 const std::tuple< Head, Tail... > &tuple )
234 {
235 std::get< i >( tuple ).restrictLocal( father, child, initialize );
236 }
237
238 template< class Entity, class LocalGeometry >
239 static void apply ( const Entity &father, const Entity &child, const LocalGeometry &geometryInFather, bool initialize,
240 const std::tuple< Head, Tail... > &tuple )
241 {
242 std::get< i >( tuple ).restrictLocal( father, child, geometryInFather, initialize );
243 }
244 };
245
246
247
248 // RestrictProlongTuple< Head, Tail... >::SetFatherChildWeight
249 // -----------------------------------------------------------
250
251 template< class Head, class... Tail >
252 template< int i >
253 struct RestrictProlongTuple< Head, Tail... >::SetFatherChildWeight
254 {
255 static void apply ( const DomainFieldType &weight, const std::tuple< Head, Tail... > &tuple )
256 {
257 std::get< i >( tuple ).setFatherChildWeight( weight );
258 }
259 };
260
261
262 // RestrictProlongTuple< Head, Tail... >::Initialize
263 // -------------------------------------------------
264
265 template< class Head, class... Tail >
266 template< int i >
267 struct RestrictProlongTuple< Head, Tail... >::Initialize
268 {
269 static void apply ( std::tuple< Head, Tail... > &tuple )
270 {
271 std::get< i >( tuple ).initialize();
272 }
273 };
274
275
276 // RestrictProlongTuple< Head, Tail... >::Finalize
277 // -----------------------------------------------
278
279 template< class Head, class... Tail >
280 template< int i >
281 struct RestrictProlongTuple< Head, Tail... >::Finalize
282 {
283 static void apply ( std::tuple< Head, Tail... > &tuple )
284 {
285 std::get< i >( tuple ).finalize();
286 }
287 };
288
289
290
291 // RestrictProlongDefaultTuple
292 // ---------------------------
293
302 template< class... DiscreteFunctions >
304 : public RestrictProlongTuple< RestrictProlongDefault< DiscreteFunctions >... >
305 {
307
308 template< class DiscreteFunction >
309 struct Operation
310 {
311 typedef typename std::decay< DiscreteFunction >::type DiscreteFunctionType;
313
314 static Type apply ( DiscreteFunctionType &discreteFunction )
315 {
316 return Type( discreteFunction );
317 }
318 };
319
320 public:
321 explicit RestrictProlongDefaultTuple ( DiscreteFunctions &... discreteFunctions )
322 : BaseType( RestrictProlongDefault< DiscreteFunctions >( discreteFunctions )... )
323 {}
324
325 explicit RestrictProlongDefaultTuple ( std::tuple< DiscreteFunctions &... > tuple )
326 : BaseType( Dune::transformTuple< Operation >( tuple ) )
327 {}
328 };
329
330 // RestrictProlongDefaultTraits
331 template<class... DiscreteFunctions>
332 struct RestrictProlongDefaultTraits
333 {
334 typedef RestrictProlongDefaultTuple<DiscreteFunctions...> Type;
335 };
336
337 template<class... DiscreteFunctions>
338 struct RestrictProlongDefaultTraits<std::tuple<DiscreteFunctions&...> >
339 {
340 typedef RestrictProlongDefaultTuple<DiscreteFunctions...> Type;
341 };
342
345 } // namespace Fem
346
347} // namespace Dune
348
349#endif // #ifndef DUNE_FEM_SPACE_COMMON_RESTRICTPROLONGTUPLE_HH
conveniently set up a tuple of Dune::Fem::RestrictProlongDefault restriction/prolongation objects cre...
Definition: restrictprolongtuple.hh:305
This is a wrapper for the default implemented restriction/prolongation operator, which only takes a d...
Definition: restrictprolonginterface.hh:207
Interface class defining the local behaviour of the restrict/prolong operation (using BN)
Definition: restrictprolonginterface.hh:40
combine a variadic number of Dune::Fem::RestrictProlongInterface instances into a single object again...
Definition: restrictprolongtuple.hh:22
forward declaration
Definition: discretefunction.hh:51
Contains utility classes which can be used with std::tuple.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integer_sequence< T, II... > tail(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the tail sequence.
Definition: integersequence.hh:58
constexpr std::integral_constant< T, I0 > head(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the single head element.
Definition: integersequence.hh:53
STL namespace.
Traits class for derivation from RestrictProlongInterface.
Definition: restrictprolonginterface.hh:155
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)