dune-pdelab 2.7-git
Loading...
Searching...
No Matches
decorator.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_ORDERING_DECORATOR_HH
5#define DUNE_PDELAB_ORDERING_DECORATOR_HH
6
7#include <array>
8
9#include <dune/typetree/typetree.hh>
10
14
15namespace Dune {
16 namespace PDELab {
17
20
21 namespace ordering {
22
23#ifndef DOXYGEN
24
25 // Forward declaration for is_decorated specialization
26 template<typename D, typename U>
27 struct decorated_ordering_tag;
28
29 namespace impl {
30
31 struct is_decorated
32 {};
33
34 template<typename DecoratedOrderingTag, std::size_t level>
35 struct basetag_access_provider
36 {};
37
38 // provide access to the base tag for disambiguation of member
39 // accesses in case those are overloaded by a decorator.
40 template<typename D, typename U>
41 struct basetag_access_provider<decorated_ordering_tag<D,U>,0>
42 : public is_decorated
43 {
44 typedef U BaseTag;
45
46 const BaseTag& baseTag() const
47 {
48 return static_cast<decorated_ordering_tag<D,U>& >(*this);
49 }
50
51 BaseTag& baseTag()
52 {
53 return static_cast<decorated_ordering_tag<D,U>& >(*this);
54 }
55
56 };
57
58 template<typename T, T v>
59 struct lazy_constant
60 {
61 typedef std::integral_constant<T,v> type;
62 };
63
64 template<typename D>
65 struct lazy_level
66 {
67 typedef std::integral_constant<std::size_t,D::level> type;
68 };
69
70 template<typename D>
71 struct decoration_level
72 : public std::conditional<
73 std::is_base_of<is_decorated, D>::value,
74 lazy_level<D>,
75 lazy_constant<std::size_t,0>
76 >::type::type
77 {};
78
79 } // namespace impl
80
81#endif // DOXYGEN
82
83 template<typename D, typename U>
85 : U
86 , impl::basetag_access_provider<decorated_ordering_tag<D,U>,impl::decoration_level<U>::value>
87 {
88
89 typedef D Decorator;
90 typedef U Undecorated;
91
92 static const std::size_t level = impl::decoration_level<U>::value + 1;
93
95 {}
96
98 : Undecorated(u)
99 {}
100
102 : Undecorated(std::move(u))
103 {}
104
105 };
106
107
108 namespace {
109
110 // recursive helper for undecorated_ordering that traverses down the Ordering tree level times
111
112 // end of recursion
113 template<typename Ordering>
114 const Ordering& _unwind_decorators(const Ordering& ordering, std::integral_constant<std::size_t,0>)
115 {
116 return ordering;
117 }
118
119 // recursive implementation - this uses decltype to avoid implementing a separate meta function
120 // for calculating the return type
121 template<typename Ordering, std::size_t level>
122 auto _unwind_decorators(const Ordering& ordering, std::integral_constant<std::size_t,level>)
123 -> decltype(
124 _unwind_decorators(
125 ordering.template child<0>(),
126 std::integral_constant<std::size_t,level-1>()
127 )
128 )
129 {
130 return _unwind_decorators(
131 ordering.template child<0>(),
132 std::integral_constant<std::size_t,level-1>()
133 );
134 }
135
136 }
137
138
140
143 template<typename GFS>
144 auto undecorated_ordering(const GFS& gfs)
145 -> decltype(
146 _unwind_decorators(
147 gfs.ordering(),
148 impl::decoration_level<typename GFS::OrderingTag>()
149 )
150 )
151 {
152 return _unwind_decorators(
153 gfs.ordering(),
154 impl::decoration_level<typename GFS::OrderingTag>()
155 );
156 }
157
158
159 template<typename GFS,typename Transformation,typename Undecorated,typename GlueTag, typename Tag>
161 : public TypeTree::meta_function
162 {
163 typedef decltype(
164 register_gfs_to_decorator_descriptor(
165 TypeTree::declptr<GFS>(), // the source GridFunctionSpace
166 TypeTree::declptr<Transformation>(), // the full transformation descriptor
167 TypeTree::declptr<Undecorated>(), // the type of the undecorated Ordering to be wrapped in the decorator
168 TypeTree::declptr<GlueTag>(), // the decorated_ordering_tag for the current decoration nesting level
169 TypeTree::declptr<Tag>() // the decorator tag
170 )
172 };
173
174
175 template<typename GFS, typename Transformation, typename OrderingTag>
177 {
178
179 static const bool recursive = false;
180
181 typedef typename leaf_gfs_to_ordering_descriptor<
182 GFS,
183 Transformation,
184 typename OrderingTag::Undecorated
186
187 typedef typename undecorated_descriptor::transformed_type undecorated_type;
188
189 typedef typename gfs_to_decorator_descriptor<
190 GFS,
191 Transformation,
193 OrderingTag,
194 typename OrderingTag::Decorator
196
197 typedef typename decorator_descriptor::transformed_type transformed_type;
198 typedef typename decorator_descriptor::transformed_storage_type transformed_storage_type;
199
200 static transformed_type transform(const GFS& gfs, const Transformation& t)
201 {
202 return decorator_descriptor::transform(gfs,t,std::make_shared<undecorated_type>(undecorated_descriptor::transform(gfs,t)));
203 }
204
205 static transformed_storage_type transform(std::shared_ptr<const GFS>& gfs_pointer, const Transformation& t)
206 {
207 return decorator_descriptor::transform(gfs_pointer,t,undecorated_descriptor::transform(gfs_pointer,t));
208 }
209
210 };
211
212 template<typename GFS, typename Transformation, typename D, typename U>
213 leaf_gfs_to_decorated<GFS,Transformation,decorated_ordering_tag<D,U> >
215
216
217 template<typename GFS, typename Transformation, typename OrderingTag>
219 {
220
221 static const bool recursive = true;
222
223 template<typename TC>
224 struct result
225 {
226
227 typedef typename power_gfs_to_ordering_descriptor<
228 GFS,
229 Transformation,
230 typename OrderingTag::Undecorated
232
233 typedef typename undecorated_descriptor::template result<TC>::type undecorated_type;
234 typedef typename gfs_to_decorator_descriptor<
235 GFS,
236 Transformation,
238 OrderingTag,
239 typename OrderingTag::Decorator
241
242 typedef typename decorator_descriptor::transformed_type type;
243 typedef typename decorator_descriptor::transformed_storage_type storage_type;
244
245 };
246
247 template<typename TC>
248 static typename result<TC>::type transform(const GFS& gfs, const Transformation& t, const std::array<std::shared_ptr<TC>,TypeTree::StaticDegree<GFS>::value>& children)
249 {
251 }
252
253 template<typename TC>
254 static typename result<TC>::storage_type transform_storage(std::shared_ptr<const GFS> gfs_pointer, const Transformation& t, const std::array<std::shared_ptr<TC>,TypeTree::StaticDegree<GFS>::value>& children)
255 {
257 }
258
259 };
260
261
262 template<typename GFS, typename Transformation, typename OrderingTag>
264 {
265
266 static const bool recursive = false;
267
268 typedef typename power_gfs_to_ordering_descriptor<
269 GFS,
270 Transformation,
271 typename OrderingTag::Undecorated
273
274 typedef typename undecorated_descriptor::transformed_type undecorated_type;
275
276 typedef typename gfs_to_decorator_descriptor<
277 GFS,
278 Transformation,
280 OrderingTag,
281 typename OrderingTag::Decorator
283
284 typedef typename decorator_descriptor::transformed_type transformed_type;
285 typedef typename decorator_descriptor::transformed_storage_type transformed_storage_type;
286
287 static transformed_type transform(const GFS& gfs, const Transformation& t)
288 {
289 return decorator_descriptor::transform(gfs,t,std::make_shared<undecorated_type>(undecorated_descriptor::transform(gfs,t)));
290 }
291
292 static transformed_storage_type transform_storage(std::shared_ptr<const GFS>& gfs_pointer, const Transformation& t)
293 {
294 return decorator_descriptor::transform_storage(gfs_pointer,t,undecorated_descriptor::transform_storage(gfs_pointer,t));
295 }
296
297 };
298
299
300 template<typename GFS, typename Transformation, typename OrderingTag>
302 : public std::conditional<
303 power_gfs_to_ordering_descriptor<
304 GFS,
305 Transformation,
306 typename OrderingTag::Undecorated
307 >::type::recursive,
308 recursive_power_gfs_to_decorated<
309 GFS,
310 Transformation,
311 OrderingTag
312 >,
313 nonrecursive_power_gfs_to_decorated<
314 GFS,
315 Transformation,
316 OrderingTag>
317 >::type
318 {};
319
320 template<typename GFS, typename Transformation, typename D, typename U>
322 GFS,
323 Transformation,
325 >
327
328
329
330
331
332
333 template<typename GFS, typename Transformation, typename OrderingTag>
335 {
336
337 static const bool recursive = true;
338
339 template<typename... TC>
340 struct result
341 {
342
343 typedef typename composite_gfs_to_ordering_descriptor<
344 GFS,
345 Transformation,
346 typename OrderingTag::Undecorated
348
349 typedef typename undecorated_descriptor::template result<TC...>::type undecorated_type;
350 typedef typename gfs_to_decorator_descriptor<
351 GFS,
352 Transformation,
354 OrderingTag,
355 typename OrderingTag::Decorator
357
358 typedef typename decorator_descriptor::transformed_type type;
359 typedef typename decorator_descriptor::transformed_storage_type storage_type;
360
361 };
362
363 template<typename... TC>
364 static typename result<TC...>::type transform(const GFS& gfs, const Transformation& t, std::shared_ptr<TC>... children)
365 {
367 }
368
369 template<typename... TC>
370 static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const GFS> gfs_pointer, const Transformation& t, std::shared_ptr<TC>... children)
371 {
373 }
374
375 };
376
377
378 template<typename GFS, typename Transformation, typename OrderingTag>
380 {
381
382 static const bool recursive = false;
383
384 typedef typename composite_gfs_to_ordering_descriptor<
385 GFS,
386 Transformation,
387 typename OrderingTag::Undecorated
389
390 typedef typename undecorated_descriptor::transformed_type undecorated_type;
391
392 typedef typename gfs_to_decorator_descriptor<
393 GFS,
394 Transformation,
396 OrderingTag,
397 typename OrderingTag::Decorator
399
400 typedef typename decorator_descriptor::transformed_type transformed_type;
401 typedef typename decorator_descriptor::transformed_storage_type transformed_storage_type;
402
403 static transformed_type transform(const GFS& gfs, const Transformation& t)
404 {
405 return decorator_descriptor::transform(gfs,t,std::make_shared<undecorated_type>(undecorated_descriptor::transform(gfs,t)));
406 }
407
408 static transformed_storage_type transform_storage(std::shared_ptr<const GFS>& gfs_pointer, const Transformation& t)
409 {
410 return decorator_descriptor::transform_storage(gfs_pointer,t,undecorated_descriptor::transform(gfs_pointer,t));
411 }
412
413 };
414
415
416 template<typename GFS, typename Transformation, typename OrderingTag>
418 : public std::conditional<
419 composite_gfs_to_ordering_descriptor<
420 GFS,
421 Transformation,
422 typename OrderingTag::Undecorated
423 >::type::recursive,
424 recursive_composite_gfs_to_decorated<
425 GFS,
426 Transformation,
427 OrderingTag
428 >,
429 nonrecursive_composite_gfs_to_decorated<
430 GFS,
431 Transformation,
432 OrderingTag>
433 >::type
434 {};
435
436
437 template<typename GFS, typename Transformation, typename D, typename U>
440
441 } // namespace ordering
442
444
445 } // namespace PDELab
446} // namespace Dune
447
448#endif // DUNE_PDELAB_ORDERING_DECORATOR_HH
STL namespace.
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
composite_gfs_to_decorated< GFS, Transformation, decorated_ordering_tag< D, U > > register_composite_gfs_to_ordering_descriptor(GFS *, Transformation *, decorated_ordering_tag< D, U > *)
power_gfs_to_decorated< GFS, Transformation, decorated_ordering_tag< D, U > > register_power_gfs_to_ordering_descriptor(GFS *, Transformation *, decorated_ordering_tag< D, U > *)
leaf_gfs_to_decorated< GFS, Transformation, decorated_ordering_tag< D, U > > register_leaf_gfs_to_ordering_descriptor(GFS *, Transformation *, decorated_ordering_tag< D, U > *)
auto undecorated_ordering(const GFS &gfs) -> decltype(_unwind_decorators(gfs.ordering(), impl::decoration_level< typename GFS::OrderingTag >()))
Unwinds the stack of decorators on top of the base ordering of gfs and returns the base ordering.
Definition: decorator.hh:144
decorated_ordering_tag()
Definition: decorator.hh:94
U Undecorated
Definition: decorator.hh:90
static const std::size_t level
Definition: decorator.hh:92
D Decorator
Definition: decorator.hh:89
decorated_ordering_tag(Undecorated &&u)
Definition: decorator.hh:101
decorated_ordering_tag(const Undecorated &u)
Definition: decorator.hh:97
decltype(register_gfs_to_decorator_descriptor(TypeTree::declptr< GFS >(),//the source GridFunctionSpace TypeTree::declptr< Transformation >(),//the full transformation descriptor TypeTree::declptr< Undecorated >(),//the type of the undecorated Ordering to be wrapped in the decorator TypeTree::declptr< GlueTag >(),//the decorated_ordering_tag for the current decoration nesting level TypeTree::declptr< Tag >()//the decorator tag)) type
Definition: decorator.hh:171
decorator_descriptor::transformed_storage_type transformed_storage_type
Definition: decorator.hh:198
static transformed_storage_type transform(std::shared_ptr< const GFS > &gfs_pointer, const Transformation &t)
Definition: decorator.hh:205
undecorated_descriptor::transformed_type undecorated_type
Definition: decorator.hh:187
decorator_descriptor::transformed_type transformed_type
Definition: decorator.hh:197
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: decorator.hh:200
static const bool recursive
Definition: decorator.hh:179
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typenameOrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:195
leaf_gfs_to_ordering_descriptor< GFS, Transformation, typenameOrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:185
static const bool recursive
Definition: decorator.hh:221
static result< TC >::type transform(const GFS &gfs, const Transformation &t, const std::array< std::shared_ptr< TC >, TypeTree::StaticDegree< GFS >::value > &children)
Definition: decorator.hh:248
static result< TC >::storage_type transform_storage(std::shared_ptr< const GFS > gfs_pointer, const Transformation &t, const std::array< std::shared_ptr< TC >, TypeTree::StaticDegree< GFS >::value > &children)
Definition: decorator.hh:254
decorator_descriptor::transformed_type type
Definition: decorator.hh:242
undecorated_descriptor::template result< TC >::type undecorated_type
Definition: decorator.hh:233
decorator_descriptor::transformed_storage_type storage_type
Definition: decorator.hh:243
power_gfs_to_ordering_descriptor< GFS, Transformation, typenameOrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:231
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typenameOrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:240
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typenameOrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:282
undecorated_descriptor::transformed_type undecorated_type
Definition: decorator.hh:274
decorator_descriptor::transformed_type transformed_type
Definition: decorator.hh:284
static const bool recursive
Definition: decorator.hh:266
decorator_descriptor::transformed_storage_type transformed_storage_type
Definition: decorator.hh:285
static transformed_storage_type transform_storage(std::shared_ptr< const GFS > &gfs_pointer, const Transformation &t)
Definition: decorator.hh:292
power_gfs_to_ordering_descriptor< GFS, Transformation, typenameOrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:272
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: decorator.hh:287
static const bool recursive
Definition: decorator.hh:337
static result< TC... >::storage_type transform_storage(std::shared_ptr< const GFS > gfs_pointer, const Transformation &t, std::shared_ptr< TC >... children)
Definition: decorator.hh:370
static result< TC... >::type transform(const GFS &gfs, const Transformation &t, std::shared_ptr< TC >... children)
Definition: decorator.hh:364
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typenameOrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:356
composite_gfs_to_ordering_descriptor< GFS, Transformation, typenameOrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:347
decorator_descriptor::transformed_storage_type storage_type
Definition: decorator.hh:359
undecorated_descriptor::template result< TC... >::type undecorated_type
Definition: decorator.hh:349
decorator_descriptor::transformed_type type
Definition: decorator.hh:358
undecorated_descriptor::transformed_type undecorated_type
Definition: decorator.hh:390
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: decorator.hh:403
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typenameOrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:398
composite_gfs_to_ordering_descriptor< GFS, Transformation, typenameOrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:388
static const bool recursive
Definition: decorator.hh:382
decorator_descriptor::transformed_type transformed_type
Definition: decorator.hh:400
decorator_descriptor::transformed_storage_type transformed_storage_type
Definition: decorator.hh:401
static transformed_storage_type transform_storage(std::shared_ptr< const GFS > &gfs_pointer, const Transformation &t)
Definition: decorator.hh:408