dune-pdelab  2.0.0
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 
15 
16 namespace Dune {
17  namespace PDELab {
18 
19  namespace gfs {
20 
21  // forward declaration for use in build_dof_index_type specialization and
22  // in feature mixins.
23  template<typename GFS, typename TreePath>
25 
26  } // namespace gfs
27 
28 #ifndef DOXYGEN
29 
30 #if HAVE_TEMPLATE_ALIASES
31 
32  // Specialization of DOFIndex type deduction TMP - the DOFIndex
33  // of a subspace must be large enough to contain DOFIndex values
34  // for the complete tree rooted in the base space.
35  template<typename GFS, typename TP>
36  struct build_dof_index_type<gfs::GridFunctionSubSpace<GFS,TP> >
37  {
38  typedef typename GFS::Ordering::Traits::DOFIndex type;
39  };
40 
41 #else // HAVE_TEMPLATE_ALIASES
42 
43  // without template aliases, the visible type of GridFunctionSubSpace is directly
44  // contained in the PDELab namespace, so we have to forward declare and specialize
45  // build_dof_index_type for the interface class as well.
46 
47  // forward declaration
48  template<typename GFS, typename TreePath>
50 
51  // Specialization of DOFIndex type deduction TMP - the DOFIndex
52  // of a subspace must be large enough to contain DOFIndex values
53  // for the complete tree rooted in the base space.
54  template<typename GFS, typename TP>
56  {
57  typedef typename GFS::Ordering::Traits::DOFIndex type;
58  };
59 
60 #endif // HAVE_TEMPLATE_ALIASES
61 
62 #endif // DOXYGEN
63 
67 
68 
70  namespace gfs {
71 
72  namespace {
73 
74 
75 
76  // ********************************************************************************
77  // Helper TMPs
78  // ********************************************************************************
79 
81 
85  template<typename Ordering, typename GFS, typename GFSTP, typename OrderingTP = TypeTree::TreePath<> >
86  struct find_ordering_treepath_for_sub_gfs
87  {
88 
89  // Get the ordering at the current subtree position.
90  typedef typename TypeTree::extract_child_type<Ordering,OrderingTP>::type SubOrdering;
91 
92  // Only descend in the GFS tree if the current ordering child consumes a tree index entry.
93  typedef typename conditional<
95  typename GFS::template Child<TypeTree::TreePathFront<GFSTP>::value>::type,
96  GFS
97  >::type SubGFS;
98 
99  // Insert either GFS child index or synthesized child index (always 0) in the ordering treepath.
100  typedef typename TypeTree::TreePathPushBack<
101  OrderingTP,
103  >::type SubOrderingTP;
104 
105  // Keep (synthesized ordering node) or drop (ordering with associated GFS) first entry of GFS TreePath.
106  typedef typename conditional<
108  typename TypeTree::TreePathPopFront<GFSTP>::type,
109  GFSTP
110  >::type SubGFSTP;
111 
112  // Recurse into child trees.
113  typedef typename find_ordering_treepath_for_sub_gfs<
114  Ordering,
115  SubGFS,
116  SubGFSTP,
117  SubOrderingTP
118  >::type type;
119 
120  };
121 
123  template<typename Ordering, typename GFS, typename OrderingTP>
124  struct find_ordering_treepath_for_sub_gfs<Ordering,GFS,TypeTree::TreePath<>,OrderingTP>
125  {
126 
127  // We have found the correct ordering TreePath, so let's return it.
128  typedef OrderingTP type;
129 
130  };
131 
132  } // anonymous namespace
133 
134 
135 
136 
137  // *****************************************************************************************
138  // Feature provider mixins
139  // *****************************************************************************************
140 
142  template<typename GFS, typename TreePath, typename Tag>
144  {
145 
148 
150  const SubSpace& subSpace() const
151  {
152  return static_cast<const SubSpace&>(*this);
153  }
154 
155  public:
156 
159 
161  typedef TreePath SubSpacePath;
162 
165 
167  typedef typename TypeTree::extract_child_type<GFS,TreePath>::type ChildGridFunctionSpace;
168 
170  typedef typename ChildGridFunctionSpace::Traits Traits;
171 
173  typedef typename ChildGridFunctionSpace::OrderingTag OrderingTag;
174 
175 
176 #if HAVE_TEMPLATE_ALIASES
177 
179  template<typename E>
180  using Constraintscontainer = typename GFS::template ConstraintsContainer<E>;
181 
182 #else // HAVE_TEMPLATE_ALIASES
183 
185  template<typename E>
187  : public GFS::template ConstraintsContainer<E>
188  {};
189 
190 #endif // HAVE_TEMPLATE_ALIASES
191 
193  typedef SubOrdering<
194  typename GFS::Ordering,
195  typename find_ordering_treepath_for_sub_gfs<
196  typename GFS::Ordering,
197  GFS,
198  TreePath
199  >::type
201 
202  std::size_t subSpaceDepth() const
203  {
205  }
206 
208  const Ordering& ordering() const
209  {
210  return _ordering;
211  }
212 
214  const typename Traits::GridViewType& gridView() const
215  {
216  return subSpace().childGridFunctionSpace().gridView();
217  }
218 
220  typename Traits::SizeType globalSize() const
221  {
222  return _ordering.size();
223  }
224 
226 
233  typename Traits::SizeType size() const
234  {
235  return _ordering.size();
236  }
237 
239  typename Traits::SizeType maxLocalSize() const
240  {
241  return _ordering.maxLocalSize();
242  }
243 
245 
246  protected:
247 
248  DefaultSubSpaceFeatures(const GFS& gfs)
249  : _ordering(gfs.orderingStorage())
250  {}
251 
252  private:
253 
254  Ordering _ordering;
255 
256  };
257 
258 
260  template<typename GFS, typename TreePath, typename Tag>
262  {
263 
266 
268  const SubSpace& subSpace() const
269  {
270  return static_cast<const SubSpace&>(*this);
271  }
272 
273  public:
274 
276  typedef typename TypeTree::extract_child_type<GFS,TreePath>::type ChildGridFunctionSpace;
277 
279  typedef typename ChildGridFunctionSpace::Traits Traits;
280 
283 
285  const typename Traits::FiniteElementMap& finiteElementMap() const
286  {
287  return subSpace().childGridFunctionSpace().finiteElementMap();
288  }
289 
291  shared_ptr<const typename Traits::FiniteElementMap> finiteElementMapStorage () const
292  {
293  return subSpace().childGridFunctionSpace().finiteElementMapStorage();
294  }
295 
297  const typename Traits::ConstraintsType& constraints() const
298  {
299  return subSpace().childGridFunctionSpace().constraints();
300  }
301 
303  const std::string& name() const
304  {
305  return subSpace().childGridFunctionSpace().name();
306  }
308 
309  };
310 
311 
312 #ifdef DOXYGEN
313 
314 
317  template<typename GFS, typename TreePath, typename Tag>
319  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
320  , public LeafSubSpaceFeatures<GFS,TreePath,Tag>
321  {
322 
323  protected:
324 
325  SubSpaceFeatureProvider(const GFS& gfs)
326  : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs)
327  {}
328 
329  };
330 
331 #else // DOXYGEN
332 
334  template<typename GFS, typename TreePath, typename Tag>
335  class SubSpaceFeatureProvider
336  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
337  {
338 
339  protected:
340 
341  SubSpaceFeatureProvider(const GFS& gfs)
342  : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs)
343  {}
344 
345  };
346 
348  template<typename GFS, typename TreePath>
349  class SubSpaceFeatureProvider<GFS,TreePath,LeafGridFunctionSpaceTag>
350  : public DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
351  , public LeafSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
352  {
353 
354  protected:
355 
356  SubSpaceFeatureProvider(const GFS& gfs)
357  : DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>(gfs)
358  {}
359 
360  };
361 
362 #endif // DOXYGEN
363 
364 
365 
366  // ********************************************************************************
367  // GridFunctionSubSpace implementation
368  // ********************************************************************************
369 
371 
393  template<typename GFS, typename TreePath>
394  class GridFunctionSubSpace
395  : public TypeTree::ProxyNode<const typename TypeTree::extract_child_type<GFS,TreePath>::type>
396  , public SubSpaceFeatureProvider<GFS,TreePath,typename TypeTree::extract_child_type<
397  GFS,
398  TreePath
399  >::type::ImplementationTag
400  >
401  {
402 
403  typedef TypeTree::ProxyNode<
404  const typename TypeTree::extract_child_type<
405  GFS,
406  TreePath
407  >::type
408  > NodeT;
409 
410  typedef SubSpaceFeatureProvider<
411  GFS,
412  TreePath,
413  typename TypeTree::extract_child_type<
414  GFS,
415  TreePath
416  >::type::ImplementationTag
417  > FeatureT;
418 
419 #if HAVE_TEMPLATE_ALIASES
420  public:
421 #else
422  protected:
423 #endif
424  // If we don't have template aliases, force the user to use the wrapper class
425  // by making the constructors protected.
426 
427 
429  explicit GridFunctionSubSpace(shared_ptr<const GFS> gfs_storage)
430  : NodeT(TypeTree::extract_child_storage(*gfs_storage,TreePath()))
431  , FeatureT(*gfs_storage)
432  , _base_gfs(gfs_storage)
433  {}
434 
435 #if HAVE_TEMPLATE_ALIASES
436 
437  // We can mask out the following constructors if we don't have template aliases,
438  // as we perform the necessary reference <-> shared_ptr conversions in the derived
439  // interface class.
440 
442  explicit GridFunctionSubSpace(const GFS& gfs)
443  : NodeT(TypeTree::extract_child_storage(gfs,TreePath()))
444  , FeatureT(gfs)
445  , _base_gfs(stackobject_to_shared_ptr(gfs))
446  {}
447 
449 
459  template<typename TP>
460  explicit GridFunctionSubSpace(shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, typename enable_if<!is_same<TP,TreePath>::value,void*>::type = nullptr)
461  : NodeT(TypeTree::extract_child_storage(gfs_storage->baseGridFunctionSpace(),TreePath()))
462  , FeatureT(gfs_storage->baseGridFunctionSpace())
463  , _base_gfs(gfs_storage->baseGridFunctionSpaceStorage())
464  {}
465 
466 #endif // HAVE_TEMPLATE_ALIASES
467 
469 
479  template<typename TP>
480  explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, typename enable_if<!is_same<TP,TreePath>::value,void*>::type = nullptr)
481  : NodeT(TypeTree::extract_child_storage(gfs.baseGridFunctionSpace(),TreePath()))
483  , _base_gfs(gfs.baseGridFunctionSpaceStorage())
484  {}
485 
486  public:
487 
490 
492  typedef typename TypeTree::extract_child_type<GFS,TreePath>::type ChildGridFunctionSpace;
493 
495  typedef typename ChildGridFunctionSpace::Traits Traits;
496 
498  typedef GridFunctionSubSpaceTag<
499  typename ChildGridFunctionSpace::ImplementationTag
501 
504  {
505  return *_base_gfs;
506  }
507 
509  shared_ptr<const BaseGridFunctionSpace> baseGridFunctionSpaceStorage() const
510  {
511  return _base_gfs;
512  }
513 
515 
521  {
522  return this->proxiedNode();
523  }
524 
526 
531  shared_ptr<const ChildGridFunctionSpace> childGridFunctionSpaceStorage() const
532  {
533  return this->proxiedNodeStorage();
534  }
535 
536  private:
537 
538  shared_ptr<const GFS> _base_gfs;
539 
540  };
541 
542 #if HAVE_TEMPLATE_ALIASES && !DOXYGEN
543 
544 
546  template<typename GFS, typename TreePath>
547  struct construct_sub_space
548  {
549  typedef GridFunctionSubSpace<
550  GFS,
551  TreePath
552  > type;
553  };
554 
556  template<typename BaseGFS, typename SubGFSTreePath, typename TreePath>
557  struct construct_sub_space<Dune::PDELab::gfs::GridFunctionSubSpace<
558  BaseGFS,
559  SubGFSTreePath
560  >,
561  TreePath
562  >
563  {
564  typedef GridFunctionSubSpace<
565  BaseGFS,
566  typename TypeTree::TreePathConcat<
567  SubGFSTreePath,
568  TreePath
569  >::type
570  > type;
571  };
572 
573 #endif // HAVE_TEMPLATE_ALIASES && !DOXYGEN
574 
575  } // namespace gfs
576 
577 
578 #if HAVE_TEMPLATE_ALIASES
579 
580 #if DOXYGEN
581 
583  template<typename GFS, typename TreePath>
584  using GridFunctionSubSpace = gfs::GridFunctionSubSpace<GFS,TreePath>;
585 
586 #else // DOXYGEN
587 
589  template<typename GFS, typename TreePath>
590  using GridFunctionSubSpace = typename gfs::construct_sub_space<GFS,TreePath>::type;
591 
592 #endif // DOXYGEN
593 
594 #else // HAVE_TEMPLATE_ALIASES
595 
596 
598 
602  template<typename GFS, typename TreePath>
604  : public gfs::GridFunctionSubSpace<GFS,TreePath>
605  {
606 
608  GFS,
609  TreePath
610  > BaseT;
611 
612  public:
613 
614  explicit GridFunctionSubSpace(shared_ptr<const GFS> gfs_storage)
615  : BaseT(gfs_storage)
616  {}
617 
618  explicit GridFunctionSubSpace(const GFS& gfs)
619  : BaseT(stackobject_to_shared_ptr(gfs))
620  {}
621 
622  };
623 
624 
625 #ifndef DOXYGEN
626 
628 
632  template<typename BaseGFS, typename SubSpaceTreePath, typename TreePath>
633  class GridFunctionSubSpace<GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>,TreePath>
634  : public gfs::GridFunctionSubSpace<typename GridFunctionSubSpace<
635  BaseGFS,
636  SubSpaceTreePath
637  >::BaseGridFunctionSpace,
638  typename TypeTree::TreePathConcat<
639  SubSpaceTreePath,
640  TreePath
641  >::type
642  >
643  {
644 
645  typedef gfs::GridFunctionSubSpace<
646  typename GridFunctionSubSpace<
647  BaseGFS,
648  SubSpaceTreePath
650  typename TypeTree::TreePathConcat<
651  SubSpaceTreePath,
652  TreePath
653  >::type
654  > BaseT;
655 
656  typedef GridFunctionSubSpace<BaseGFS,SubSpaceTreePath> SubSpace;
657 
658  public:
659 
660  explicit GridFunctionSubSpace(shared_ptr<const SubSpace> gfs_storage)
661  : BaseT(gfs_storage->baseGridFunctionSpaceStorage())
662  {}
663 
664  explicit GridFunctionSubSpace(const SubSpace& gfs)
665  : BaseT(gfs.baseGridFunctionSpaceStorage())
666  {}
667 
668  };
669 
670 #endif // DOXYGEN
671 
672 #endif // HAVE_TEMPLATE_ALIASES
673 
675 
676  } // namespace PDELab
677 } // namespace Dune
678 
679 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACE_HH
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:279
shared_ptr< const BaseGridFunctionSpace > baseGridFunctionSpaceStorage() const
Returns the storage object of the root GridFunctionSpace that this subspace view is based on...
Definition: subspace.hh:509
Additional features used by leaf subspaces.
Definition: subspace.hh:261
GridFunctionSubSpace(const GridFunctionSubSpace< GFS, TP > &gfs, typename enable_if<!is_same< TP, TreePath >::value, void * >::type=nullptr)
Construct a GridFunctionSubSpace another GridFunctionSubSpace.
Definition: subspace.hh:480
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:603
Default features used by every subspace implementation.
Definition: subspace.hh:143
ChildGridFunctionSpace::OrderingTag OrderingTag
Re-exported OrderingTag from the original GridFunctionSpace.
Definition: subspace.hh:173
Definition: gridfunctionspace/tags.hh:309
const std::string & name() const
Returns the name of this space.
Definition: subspace.hh:303
const ChildGridFunctionSpace & childGridFunctionSpace() const
Returns the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:520
GridFunctionSubSpaceTag< typename ChildGridFunctionSpace::ImplementationTag > ImplementationTag
Our ImplementationTag is derived from the tag of the original GridFunctionSpace.
Definition: subspace.hh:500
Traits::SizeType maxLocalSize() const
Returns the maximum number of DOFs per cells in this subspace.
Definition: subspace.hh:239
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:50
TypeTree::extract_child_type< GFS, TreePath >::type ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:492
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:489
_build_dof_index_type< GFS, typename GFS::OrderingTag >::type type
Definition: gridfunctionspace/tags.hh:311
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:164
Traits::SizeType size() const
Returns the global size of the root space.
Definition: subspace.hh:233
shared_ptr< const ChildGridFunctionSpace > childGridFunctionSpaceStorage() const
Returns the storage object of the original GridFunctionSpace that we provide a view for...
Definition: subspace.hh:531
std::size_t subSpaceDepth() const
Definition: subspace.hh:202
TypeTree::extract_child_type< GFS, TreePath >::type ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:167
GridFunctionSubSpace(const GFS &gfs)
Definition: subspace.hh:618
const Ordering & ordering() const
Returns the ordering associated with this GridFunctionSubSpace.
Definition: subspace.hh:208
const Traits::FiniteElementMap & finiteElementMap() const
Returns the finite element map of this space.
Definition: subspace.hh:285
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:188
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
const Traits::ConstraintsType & constraints() const
Returns the constraints engine of this space.
Definition: subspace.hh:297
DefaultSubSpaceFeatures(const GFS &gfs)
Definition: subspace.hh:248
GridFunctionSubSpace(shared_ptr< const GFS > gfs_storage)
Definition: subspace.hh:614
SubSpaceFeatureProvider(const GFS &gfs)
Definition: subspace.hh:325
const BaseGridFunctionSpace & baseGridFunctionSpace() const
Returns the root GridFunctionSpace that this subspace view is based on.
Definition: subspace.hh:503
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:495
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:200
Definition: gridfunctionspace/tags.hh:31
TreePath SubSpacePath
The TreePath from the root of the space hierarchy to this subspace.
Definition: subspace.hh:161
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:24
GridFunctionSubSpace(shared_ptr< const GFS > gfs_storage)
Construct a GridFunctionSubSpace from the storage object of a root space.
Definition: subspace.hh:429
TypeTree::extract_child_type< GFS, TreePath >::type ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:276
Re-exported constraints container from the original GridFunctionSpace.
Definition: subspace.hh:186
shared_ptr< const typename Traits::FiniteElementMap > finiteElementMapStorage() const
Returns the storage object for the finite element map of this space.
Definition: subspace.hh:291
Support infrastructure to make LocalFunctionSpaces of GridFunctionSubSpace work.
const Traits::GridViewType & gridView() const
Returns the underlying GridView.
Definition: subspace.hh:214
Traits::SizeType globalSize() const
Returns the global size of the root space.
Definition: subspace.hh:220
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:78
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:170
Traits::SizeType maxLocalSize() const
Returns the maximum per-entity size of the TargetOrdering.
Definition: subordering.hh:200