DUNE PDELab (2.8)

decorator.hh
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
11#include <dune/pdelab/common/typetraits.hh>
12#include <dune/pdelab/ordering/utility.hh>
13#include <dune/pdelab/ordering/orderingbase.hh>
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>
84 struct decorated_ordering_tag
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
94 decorated_ordering_tag()
95 {}
96
97 decorated_ordering_tag(const Undecorated& u)
98 : Undecorated(u)
99 {}
100
101 decorated_ordering_tag(Undecorated&& u)
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>
160 struct gfs_to_decorator_descriptor
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 )
171 ) type;
172 };
173
174
175 template<typename GFS, typename Transformation, typename OrderingTag>
176 struct leaf_gfs_to_decorated
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
185 >::type undecorated_descriptor;
186
187 typedef typename undecorated_descriptor::transformed_type undecorated_type;
188
189 typedef typename gfs_to_decorator_descriptor<
190 GFS,
191 Transformation,
192 undecorated_type,
193 OrderingTag,
194 typename OrderingTag::Decorator
195 >::type decorator_descriptor;
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> >
214 register_leaf_gfs_to_ordering_descriptor(GFS*,Transformation*,decorated_ordering_tag<D,U>*);
215
216
217 template<typename GFS, typename Transformation, typename OrderingTag>
218 struct recursive_power_gfs_to_decorated
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
231 >::type undecorated_descriptor;
232
233 typedef typename undecorated_descriptor::template result<TC>::type undecorated_type;
234 typedef typename gfs_to_decorator_descriptor<
235 GFS,
236 Transformation,
237 undecorated_type,
238 OrderingTag,
239 typename OrderingTag::Decorator
240 >::type decorator_descriptor;
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 {
250 return result<TC>::decorator_descriptor::transform(gfs,t,std::make_shared<typename result<TC>::undecorated_type>(result<TC>::undecorated_descriptor::transform(gfs,t,children)));
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 {
256 return result<TC>::decorator_descriptor::transform(gfs_pointer,t,result<TC>::undecorated_descriptor::transform_storage(gfs_pointer,t,children));
257 }
258
259 };
260
261
262 template<typename GFS, typename Transformation, typename OrderingTag>
263 struct nonrecursive_power_gfs_to_decorated
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
272 >::type undecorated_descriptor;
273
274 typedef typename undecorated_descriptor::transformed_type undecorated_type;
275
276 typedef typename gfs_to_decorator_descriptor<
277 GFS,
278 Transformation,
279 undecorated_type,
280 OrderingTag,
281 typename OrderingTag::Decorator
282 >::type decorator_descriptor;
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>
301 struct power_gfs_to_decorated
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>
321 power_gfs_to_decorated<
322 GFS,
323 Transformation,
324 decorated_ordering_tag<D,U>
325 >
326 register_power_gfs_to_ordering_descriptor(GFS*,Transformation*,decorated_ordering_tag<D,U>*);
327
328
329
330
331
332
333 template<typename GFS, typename Transformation, typename OrderingTag>
334 struct recursive_composite_gfs_to_decorated
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
347 >::type undecorated_descriptor;
348
349 typedef typename undecorated_descriptor::template result<TC...>::type undecorated_type;
350 typedef typename gfs_to_decorator_descriptor<
351 GFS,
352 Transformation,
353 undecorated_type,
354 OrderingTag,
355 typename OrderingTag::Decorator
356 >::type decorator_descriptor;
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 {
366 return result<TC...>::decorator_descriptor::transform(gfs,t,std::make_shared<typename result<TC...>::undecorated_type>(result<TC...>::undecorated_descriptor::transform(gfs,t,children...)));
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 {
372 return result<TC...>::decorator_descriptor::transform_storage(gfs_pointer,t,result<TC...>::undecorated_descriptor::transform(gfs_pointer,t,children...));
373 }
374
375 };
376
377
378 template<typename GFS, typename Transformation, typename OrderingTag>
379 struct nonrecursive_composite_gfs_to_decorated
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
388 >::type undecorated_descriptor;
389
390 typedef typename undecorated_descriptor::transformed_type undecorated_type;
391
392 typedef typename gfs_to_decorator_descriptor<
393 GFS,
394 Transformation,
395 undecorated_type,
396 OrderingTag,
397 typename OrderingTag::Decorator
398 >::type decorator_descriptor;
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>
417 struct composite_gfs_to_decorated
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>
438 composite_gfs_to_decorated<GFS,Transformation,decorated_ordering_tag<D,U> >
439 register_composite_gfs_to_ordering_descriptor(GFS*,Transformation*,decorated_ordering_tag<D,U>*);
440
441 } // namespace ordering
442
444
445 } // namespace PDELab
446} // namespace Dune
447
448#endif // DUNE_PDELAB_ORDERING_DECORATOR_HH
Dune namespace.
Definition: alignedallocator.hh:11
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)