Loading [MathJax]/extensions/tex2jax.js

DUNE PDELab (unstable)

subspace.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#ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACE_HH
4#define DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACE_HH
5
11#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
12#include <dune/pdelab/gridfunctionspace/powergridfunctionspace.hh>
13#include <dune/pdelab/gridfunctionspace/compositegridfunctionspace.hh>
15#include <dune/pdelab/ordering/subordering.hh>
16
17namespace Dune {
18 namespace PDELab {
19
20 namespace gfs {
21
22 // forward declaration for use in build_dof_index_type specialization and
23 // in feature mixins.
24 template<typename GFS, typename TreePath>
26
27 } // namespace gfs
28
29#ifndef DOXYGEN
30
31 // Specialization of DOFIndex type deduction TMP - the DOFIndex
32 // of a subspace must be large enough to contain DOFIndex values
33 // for the complete tree rooted in the base space.
34 template<typename GFS, typename TP>
35 struct build_dof_index_type<gfs::GridFunctionSubSpace<GFS,TP> >
36 {
37 typedef typename GFS::Ordering::Traits::DOFIndex type;
38 };
39
40#endif // DOXYGEN
41
45
46
48 namespace gfs {
49
50 namespace {
51
52 template<typename Ordering, typename GFS, typename GFSTP, typename OrderingTP>
53 constexpr auto create_ordering_treepath_for_sub_gfs(
54 const Ordering& ordering, const GFS& gfs, GFSTP gfs_tp, OrderingTP ordering_tp)
55 {
56 using namespace Dune::TypeTree;
57
58 if constexpr (gfs_tp.size() == 0)
59 {
60 return ordering_tp;
61 }
62 else
63 {
64 // Get the ordering at the current subtree position.
66
67 // 1. Only descend in the GFS tree if the current ordering child consumes a tree index entry.
68 // 2. Insert either GFS child index or synthesized child index (always 0) in the ordering treepath.
69 // 3. Keep (synthesized ordering node) or drop (ordering with associated GFS) first entry of GFS TreePath.
71 {
72 // we now know that SubGFS = GFS;
73 auto subordering_tp = push_back(OrderingTP(), front(GFSTP()));
74 auto subgfs_tp = pop_front(GFSTP());
75
76 // Recurse into child trees.
77 return create_ordering_treepath_for_sub_gfs(
78 ordering, gfs, subgfs_tp, subordering_tp);
79 }
80 else
81 {
82 // using SubGFS = typename GFS::template Child<TypeTree::front(GFSTP())>::type;
83 auto subordering_tp = push_back(OrderingTP(), Indices::_0);
84 auto subgfs_tp = gfs_tp;
85
86 // Recurse into child trees.
87 return create_ordering_treepath_for_sub_gfs(
88 ordering, gfs.child(front(gfs_tp)), subgfs_tp, subordering_tp);
89 }
90 }
91 }
92
93 // ********************************************************************************
94 // Helper TMPs
95 // ********************************************************************************
96
98
102 template<typename Ordering, typename GFS, typename GFSTP, typename OrderingTP = TypeTree::StaticTreePath<> >
103 struct find_ordering_treepath_for_sub_gfs
104 {
105 using type = decltype(
106 create_ordering_treepath_for_sub_gfs(
107 std::declval<Ordering>(),
108 std::declval<GFS>(),
109 GFSTP(),
110 OrderingTP())
111 );
112 };
113
114 } // anonymous namespace
115
116
117
118
119 // *****************************************************************************************
120 // Feature provider mixins
121 // *****************************************************************************************
122
124 template<typename GFS, typename TreePath, typename Tag>
126 {
127
130
132 const SubSpace& subSpace() const
133 {
134 return static_cast<const SubSpace&>(*this);
135 }
136
137 public:
138
141
143 typedef TreePath SubSpacePath;
144
147
150
152 typedef typename ChildGridFunctionSpace::Traits Traits;
153
155 typedef typename ChildGridFunctionSpace::OrderingTag OrderingTag;
156
157
159 template<typename E>
160 using Constraintscontainer = typename GFS::template ConstraintsContainer<E>;
161
163 typedef SubOrdering<
164 typename GFS::Ordering,
165 typename find_ordering_treepath_for_sub_gfs<
166 typename GFS::Ordering,
167 GFS,
168 TreePath
169 >::type
171
172 std::size_t subSpaceDepth() const
173 {
174 return SubSpacePath().size();
175 }
176
178 const Ordering& ordering() const
179 {
180 return _ordering;
181 }
182
184 const typename Traits::EntitySet& entitySet() const
185 {
186 return subSpace().childGridFunctionSpace().entitySet();
187 }
188
190 const typename Traits::GridViewType& gridView() const
191 {
192 return subSpace().childGridFunctionSpace().gridView();
193 }
194
196 typename Traits::SizeType globalSize() const
197 {
198 return _ordering.size();
199 }
200
202
209 typename Traits::SizeType size() const
210 {
211 return _ordering.size();
212 }
213
215 typename Traits::SizeType maxLocalSize() const
216 {
217 return _ordering.maxLocalSize();
218 }
219
221
222 protected:
223
224 DefaultSubSpaceFeatures(const GFS& gfs, TreePath tree_path)
225 : _ordering(gfs.orderingStorage(), create_ordering_treepath_for_sub_gfs(gfs.ordering(), gfs, tree_path, TypeTree::treePath()))
226 {}
227
228 DefaultSubSpaceFeatures(const GFS& gfs)
229 : DefaultSubSpaceFeatures(gfs, TreePath())
230 {}
231
232 private:
233
234 Ordering _ordering;
235
236 };
237
238
240 template<typename GFS, typename TreePath, typename Tag>
242 {
243
246
248 const SubSpace& subSpace() const
249 {
250 return static_cast<const SubSpace&>(*this);
251 }
252
253 public:
254
257
259 typedef typename ChildGridFunctionSpace::Traits Traits;
260
263
265 const typename Traits::FiniteElementMap& finiteElementMap() const
266 {
267 return subSpace().childGridFunctionSpace().finiteElementMap();
268 }
269
271 std::shared_ptr<const typename Traits::FiniteElementMap> finiteElementMapStorage () const
272 {
273 return subSpace().childGridFunctionSpace().finiteElementMapStorage();
274 }
275
277 const typename Traits::ConstraintsType& constraints() const
278 {
279 return subSpace().childGridFunctionSpace().constraints();
280 }
281
283 const std::string& name() const
284 {
285 return subSpace().childGridFunctionSpace().name();
286 }
288
289 };
290
291
292#ifdef DOXYGEN
293
294
297 template<typename GFS, typename TreePath, typename Tag>
299 : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
300 , public LeafSubSpaceFeatures<GFS,TreePath,Tag>
301 {
302
303 protected:
304
305 SubSpaceFeatureProvider(const GFS& gfs, TreePath tree_path)
307 {}
308
309 };
310
311#else // DOXYGEN
312
314 template<typename GFS, typename TreePath, typename Tag>
316 : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
317 {
318
319 protected:
320
321 SubSpaceFeatureProvider(const GFS& gfs, TreePath tree_path)
322 : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs,tree_path)
323 {}
324
325 };
326
328 template<typename GFS, typename TreePath>
329 class SubSpaceFeatureProvider<GFS,TreePath,LeafGridFunctionSpaceTag>
330 : public DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
331 , public LeafSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
332 {
333
334 protected:
335
336 SubSpaceFeatureProvider(const GFS& gfs, TreePath tree_path)
337 : DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>(gfs, tree_path)
338 {}
339
340 };
341
342#endif // DOXYGEN
343
345 template<class T, bool Enable = std::is_base_of<GridFunctionOutputParameters, T>::value>
347 {
348 public:
349 void inheritDataSetType(const T & t) {}
350 };
351
352#ifndef DOXYGEN
353 template<class T>
356 {
357 public:
358 void inheritDataSetType(const T & t)
359 {
360 setDataSetType(t.dataSetType());
361 }
362 };
363#endif
364
365 // ********************************************************************************
366 // GridFunctionSubSpace implementation
367 // ********************************************************************************
368
370
392 template<typename GFS, typename TreePath>
394 : public TypeTree::ProxyNode<const TypeTree::ChildForTreePath<GFS,TreePath>>
395 , public SubSpaceFeatureProvider<GFS,TreePath,TypeTree::ImplementationTag<TypeTree::ChildForTreePath<GFS,TreePath>>>
396 , public GridFunctionSubSpaceOutputParameters<TypeTree::ChildForTreePath<GFS,TreePath>>
397 {
398
400
402 GFS,
403 TreePath,
405 >;
406
407 public:
408
410 explicit GridFunctionSubSpace(std::shared_ptr<const GFS> gfs_storage, TreePath tree_path)
411 : NodeT(TypeTree::childStorage(*gfs_storage,tree_path))
412 , FeatureT(*gfs_storage, tree_path)
413 , _base_gfs(gfs_storage)
414 {
415 this->inheritDataSetType(childGridFunctionSpace());
416 }
417
419 explicit GridFunctionSubSpace(std::shared_ptr<const GFS> gfs_storage)
420 : GridFunctionSubSpace(gfs_storage, TreePath())
421 {}
422
423 // We can mask out the following constructors if we don't have template aliases,
424 // as we perform the necessary reference <-> shared_ptr conversions in the derived
425 // interface class.
426
428 explicit GridFunctionSubSpace(const GFS& gfs, TreePath tree_path)
429 : NodeT(TypeTree::childStorage(gfs,tree_path))
430 , FeatureT(gfs,tree_path)
431 , _base_gfs(stackobject_to_shared_ptr(gfs))
432 {
433 this->inheritDataSetType(childGridFunctionSpace());
434 }
435
436 explicit GridFunctionSubSpace(const GFS& gfs)
437 : GridFunctionSubSpace(gfs, TreePath())
438 {}
439
441
451 template<typename TP>
452 explicit GridFunctionSubSpace(std::shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, TreePath tree_path, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
453 : NodeT(TypeTree::childStorage(gfs_storage->baseGridFunctionSpace(),tree_path))
454 , FeatureT(gfs_storage->baseGridFunctionSpace(), tree_path)
455 , _base_gfs(gfs_storage->baseGridFunctionSpaceStorage())
456 {
457 setDataSetType(childGridFunctionSpace().dataSetType());
458 }
459
460 template<typename TP>
461 explicit GridFunctionSubSpace(std::shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
462 : GridFunctionSubSpace(gfs_storage, TreePath())
463 {}
464
466
476 template<typename TP>
477 explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, TreePath tree_path, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
478 : NodeT(TypeTree::childStorage(gfs.baseGridFunctionSpace(),tree_path))
479 , FeatureT(gfs.baseGridFunctionSpace(), tree_path)
480 , _base_gfs(gfs.baseGridFunctionSpaceStorage())
481 {
482 this->inheritDataSetType(childGridFunctionSpace());
483 }
484
485 template<typename TP>
486 explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
487 : GridFunctionSubSpace(gfs, TreePath())
488 {}
489
490 public:
491
494
497
499 typedef typename ChildGridFunctionSpace::Traits Traits;
500
502 typedef GridFunctionSubSpaceTag<
505
508 {
509 return *_base_gfs;
510 }
511
513 std::shared_ptr<const BaseGridFunctionSpace> baseGridFunctionSpaceStorage() const
514 {
515 return _base_gfs;
516 }
517
519
525 {
526 return this->proxiedNode();
527 }
528
530
535 std::shared_ptr<const ChildGridFunctionSpace> childGridFunctionSpaceStorage() const
536 {
537 return this->proxiedNodeStorage();
538 }
539
540 std::string name() const
541 {
542 return childGridFunctionSpace().name();
543 }
544
545 void name(const std::string& name)
546 {
547 childGridFunctionSpace().name(name);
548 }
549
550 private:
551
552 std::shared_ptr<const GFS> _base_gfs;
553
554 };
555
556#ifndef DOXYGEN
557
558
560 template<typename GFS, typename TreePath>
561 struct construct_sub_space
562 {
563 typedef GridFunctionSubSpace<
564 GFS,
565 TreePath
566 > type;
567 };
568
570 template<typename BaseGFS, typename SubGFSTreePath, typename TreePath>
571 struct construct_sub_space<Dune::PDELab::gfs::GridFunctionSubSpace<
572 BaseGFS,
573 SubGFSTreePath
574 >,
575 TreePath
576 >
577 {
578 using SubSpaceTreePath = decltype(TypeTree::join(SubGFSTreePath(), TreePath()));
579 typedef GridFunctionSubSpace<
580 BaseGFS,SubSpaceTreePath> type;
581 };
582
583#endif // DOXYGEN
584
585 } // namespace gfs
586
587
588#if DOXYGEN
589
591 template<typename GFS, typename TreePath>
593
594#else // DOXYGEN
595
597 template<typename GFS, typename TreePath>
598 using GridFunctionSubSpace = typename gfs::construct_sub_space<GFS,TreePath>::type;
599
600#endif // DOXYGEN
601
603
604 } // namespace PDELab
605} // namespace Dune
606
607#endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACE_HH
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:126
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:50
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:75
Traits::SizeType maxLocalSize() const
Returns the maximum per-entity size of the TargetOrdering.
Definition: subordering.hh:195
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:178
Default features used by every subspace implementation.
Definition: subspace.hh:126
const Traits::GridViewType & gridView() const
Returns the underlying GridView.
Definition: subspace.hh:190
typename GFS::template ConstraintsContainer< E > Constraintscontainer
Re-exported constraints container from the original GridFunctionSpace.
Definition: subspace.hh:160
const Traits::EntitySet & entitySet() const
Returns the underlying EntitySet.
Definition: subspace.hh:184
Traits::SizeType size() const
Returns the global size of the root space.
Definition: subspace.hh:209
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:152
const Ordering & ordering() const
Returns the ordering associated with this GridFunctionSubSpace.
Definition: subspace.hh:178
Traits::SizeType maxLocalSize() const
Returns the maximum number of DOFs per cells in this subspace.
Definition: subspace.hh:215
Traits::SizeType globalSize() const
Returns the global size of the root space.
Definition: subspace.hh:196
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:149
ChildGridFunctionSpace::OrderingTag OrderingTag
Re-exported OrderingTag from the original GridFunctionSpace.
Definition: subspace.hh:155
TreePath SubSpacePath
The TreePath from the root of the space hierarchy to this subspace.
Definition: subspace.hh:143
SubOrdering< typename GFS::Ordering, typename find_ordering_treepath_for_sub_gfs< typename GFS::Ordering, GFS, TreePath >::type > Ordering
The ordering used by this GridFunctionSubSpace.
Definition: subspace.hh:170
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:146
Mixin class which inherits from GridFunctionOutputParameters iff T inherits from GridFunctionOutputPa...
Definition: subspace.hh:347
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:397
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:496
std::shared_ptr< const BaseGridFunctionSpace > baseGridFunctionSpaceStorage() const
Returns the storage object of the root GridFunctionSpace that this subspace view is based on.
Definition: subspace.hh:513
const BaseGridFunctionSpace & baseGridFunctionSpace() const
Returns the root GridFunctionSpace that this subspace view is based on.
Definition: subspace.hh:507
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:493
const ChildGridFunctionSpace & childGridFunctionSpace() const
Returns the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:524
GridFunctionSubSpaceTag< TypeTree::ImplementationTag< ChildGridFunctionSpace > > ImplementationTag
Our ImplementationTag is derived from the tag of the original GridFunctionSpace.
Definition: subspace.hh:504
GridFunctionSubSpace(const GFS &gfs, TreePath tree_path)
Construct a GridFunctionSubSpace from a root space.
Definition: subspace.hh:428
GridFunctionSubSpace(std::shared_ptr< const GFS > gfs_storage, TreePath tree_path)
Construct a GridFunctionSubSpace from the storage object of a root space.
Definition: subspace.hh:410
std::shared_ptr< const ChildGridFunctionSpace > childGridFunctionSpaceStorage() const
Returns the storage object of the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:535
GridFunctionSubSpace(std::shared_ptr< const GFS > gfs_storage)
Construct a GridFunctionSubSpace from the storage object of a root space.
Definition: subspace.hh:419
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:499
GridFunctionSubSpace(std::shared_ptr< const GridFunctionSubSpace< GFS, TP > > gfs_storage, TreePath tree_path, typename std::enable_if<!std::is_same< TP, TreePath >::value, void * >::type=nullptr)
Construct a GridFunctionSubSpace from the storage of another GridFunctionSubSpace.
Definition: subspace.hh:452
GridFunctionSubSpace(const GridFunctionSubSpace< GFS, TP > &gfs, TreePath tree_path, typename std::enable_if<!std::is_same< TP, TreePath >::value, void * >::type=nullptr)
Construct a GridFunctionSubSpace from another GridFunctionSubSpace.
Definition: subspace.hh:477
Additional features used by leaf subspaces.
Definition: subspace.hh:242
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:259
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:256
const Traits::FiniteElementMap & finiteElementMap() const
Returns the finite element map of this space.
Definition: subspace.hh:265
std::shared_ptr< const typename Traits::FiniteElementMap > finiteElementMapStorage() const
Returns the storage object for the finite element map of this space.
Definition: subspace.hh:271
const Traits::ConstraintsType & constraints() const
Returns the constraints engine of this space.
Definition: subspace.hh:277
const std::string & name() const
Returns the name of this space.
Definition: subspace.hh:283
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:255
std::enable_if< enabled, const TypeTree::ChildForTreePath< GFS, TreePath > & >::type proxiedNode()
Returns the proxied node.
Definition: proxynode.hh:306
std::enable_if< enabled, std::shared_ptr< const TypeTree::ChildForTreePath< GFS, TreePath > > >::type proxiedNodeStorage()
Returns the storage of the proxied node.
Definition: proxynode.hh:320
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:52
gfs::GridFunctionSubSpace< GFS, TreePath > GridFunctionSubSpace
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:592
typename std::decay_t< T >::ImplementationTag ImplementationTag
Returns the implementation tag of the given Node.
Definition: nodeinterface.hh:74
constexpr auto pop_front(const HybridTreePath< T... > &tp)
Removes first index on a HybridTreePath.
Definition: treepath.hh:527
constexpr auto join(const HybridTreePath< Head... > &head, const Other &... tail)
Join two tree paths into one.
Definition: treepath.hh:509
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:323
typename impl::_ChildForTreePath< Node, TreePath >::type ChildForTreePath
Template alias for the type of a child node given by a TreePath or a HybridTreePath type.
Definition: childextraction.hh:251
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
constexpr std::integer_sequence< T, II..., T(IN)> push_back(std::integer_sequence< T, II... >, std::integral_constant< T, IN >={})
Append an index IN to the back of the sequence.
Definition: integersequence.hh:69
constexpr std::integral_constant< T, I0 > front(std::integer_sequence< T, I0, II... >)
Return the first entry of the sequence.
Definition: integersequence.hh:39
This file implements several utilities related to std::shared_ptr.
Support infrastructure to make LocalFunctionSpaces of GridFunctionSubSpace work.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 14, 22:45, 2025)