dune-pdelab  2.4-dev
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  // Specialization of DOFIndex type deduction TMP - the DOFIndex
31  // of a subspace must be large enough to contain DOFIndex values
32  // for the complete tree rooted in the base space.
33  template<typename GFS, typename TP>
34  struct build_dof_index_type<gfs::GridFunctionSubSpace<GFS,TP> >
35  {
36  typedef typename GFS::Ordering::Traits::DOFIndex type;
37  };
38 
39 #endif // DOXYGEN
40 
44 
45 
47  namespace gfs {
48 
49  namespace {
50 
51 
52 
53  // ********************************************************************************
54  // Helper TMPs
55  // ********************************************************************************
56 
58 
62  template<typename Ordering, typename GFS, typename GFSTP, typename OrderingTP = TypeTree::TreePath<> >
63  struct find_ordering_treepath_for_sub_gfs
64  {
65 
66  // Get the ordering at the current subtree position.
67  typedef typename TypeTree::extract_child_type<Ordering,OrderingTP>::type SubOrdering;
68 
69  // Only descend in the GFS tree if the current ordering child consumes a tree index entry.
70  typedef typename conditional<
72  typename GFS::template Child<TypeTree::TreePathFront<GFSTP>::value>::type,
73  GFS
74  >::type SubGFS;
75 
76  // Insert either GFS child index or synthesized child index (always 0) in the ordering treepath.
77  typedef typename TypeTree::TreePathPushBack<
78  OrderingTP,
79  (SubOrdering::consume_tree_index ? TypeTree::TreePathFront<GFSTP>::value : 0)
80  >::type SubOrderingTP;
81 
82  // Keep (synthesized ordering node) or drop (ordering with associated GFS) first entry of GFS TreePath.
83  typedef typename conditional<
85  typename TypeTree::TreePathPopFront<GFSTP>::type,
86  GFSTP
87  >::type SubGFSTP;
88 
89  // Recurse into child trees.
90  typedef typename find_ordering_treepath_for_sub_gfs<
91  Ordering,
92  SubGFS,
93  SubGFSTP,
94  SubOrderingTP
95  >::type type;
96 
97  };
98 
100  template<typename Ordering, typename GFS, typename OrderingTP>
101  struct find_ordering_treepath_for_sub_gfs<Ordering,GFS,TypeTree::TreePath<>,OrderingTP>
102  {
103 
104  // We have found the correct ordering TreePath, so let's return it.
105  typedef OrderingTP type;
106 
107  };
108 
109  } // anonymous namespace
110 
111 
112 
113 
114  // *****************************************************************************************
115  // Feature provider mixins
116  // *****************************************************************************************
117 
119  template<typename GFS, typename TreePath, typename Tag>
121  {
122 
125 
127  const SubSpace& subSpace() const
128  {
129  return static_cast<const SubSpace&>(*this);
130  }
131 
132  public:
133 
136 
138  typedef TreePath SubSpacePath;
139 
142 
144  typedef typename TypeTree::extract_child_type<GFS,TreePath>::type ChildGridFunctionSpace;
145 
147  typedef typename ChildGridFunctionSpace::Traits Traits;
148 
150  typedef typename ChildGridFunctionSpace::OrderingTag OrderingTag;
151 
152 
154  template<typename E>
155  using Constraintscontainer = typename GFS::template ConstraintsContainer<E>;
156 
158  typedef SubOrdering<
159  typename GFS::Ordering,
160  typename find_ordering_treepath_for_sub_gfs<
161  typename GFS::Ordering,
162  GFS,
163  TreePath
164  >::type
166 
167  std::size_t subSpaceDepth() const
168  {
170  }
171 
173  const Ordering& ordering() const
174  {
175  return _ordering;
176  }
177 
179  const typename Traits::GridViewType& gridView() const
180  {
181  return subSpace().childGridFunctionSpace().gridView();
182  }
183 
185  typename Traits::SizeType globalSize() const
186  {
187  return _ordering.size();
188  }
189 
191 
198  typename Traits::SizeType size() const
199  {
200  return _ordering.size();
201  }
202 
204  typename Traits::SizeType maxLocalSize() const
205  {
206  return _ordering.maxLocalSize();
207  }
208 
210 
211  protected:
212 
213  DefaultSubSpaceFeatures(const GFS& gfs)
214  : _ordering(gfs.orderingStorage())
215  {}
216 
217  private:
218 
219  Ordering _ordering;
220 
221  };
222 
223 
225  template<typename GFS, typename TreePath, typename Tag>
227  {
228 
231 
233  const SubSpace& subSpace() const
234  {
235  return static_cast<const SubSpace&>(*this);
236  }
237 
238  public:
239 
241  typedef typename TypeTree::extract_child_type<GFS,TreePath>::type ChildGridFunctionSpace;
242 
244  typedef typename ChildGridFunctionSpace::Traits Traits;
245 
248 
250  const typename Traits::FiniteElementMap& finiteElementMap() const
251  {
252  return subSpace().childGridFunctionSpace().finiteElementMap();
253  }
254 
256  std::shared_ptr<const typename Traits::FiniteElementMap> finiteElementMapStorage () const
257  {
258  return subSpace().childGridFunctionSpace().finiteElementMapStorage();
259  }
260 
262  const typename Traits::ConstraintsType& constraints() const
263  {
264  return subSpace().childGridFunctionSpace().constraints();
265  }
266 
268  const std::string& name() const
269  {
270  return subSpace().childGridFunctionSpace().name();
271  }
273 
274  };
275 
276 
277 #ifdef DOXYGEN
278 
279 
282  template<typename GFS, typename TreePath, typename Tag>
284  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
285  , public LeafSubSpaceFeatures<GFS,TreePath,Tag>
286  {
287 
288  protected:
289 
290  SubSpaceFeatureProvider(const GFS& gfs)
291  : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs)
292  {}
293 
294  };
295 
296 #else // DOXYGEN
297 
299  template<typename GFS, typename TreePath, typename Tag>
300  class SubSpaceFeatureProvider
301  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
302  {
303 
304  protected:
305 
306  SubSpaceFeatureProvider(const GFS& gfs)
307  : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs)
308  {}
309 
310  };
311 
313  template<typename GFS, typename TreePath>
314  class SubSpaceFeatureProvider<GFS,TreePath,LeafGridFunctionSpaceTag>
315  : public DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
316  , public LeafSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
317  {
318 
319  protected:
320 
321  SubSpaceFeatureProvider(const GFS& gfs)
322  : DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>(gfs)
323  {}
324 
325  };
326 
327 #endif // DOXYGEN
328 
332  {
333  public:
334  void inheritDataSetType(const T & t) {}
335  };
336 
337 #ifndef DOXYGEN
338  template<class T>
339  class GridFunctionSubSpaceOutputParameters<T,true> :
341  {
342  public:
343  void inheritDataSetType(const T & t)
344  {
345  setDataSetType(t.dataSetType());
346  }
347  };
348 #endif
349 
350  // ********************************************************************************
351  // GridFunctionSubSpace implementation
352  // ********************************************************************************
353 
355 
377  template<typename GFS, typename TreePath>
379  : public TypeTree::ProxyNode<const typename TypeTree::extract_child_type<GFS,TreePath>::type>
380  , public SubSpaceFeatureProvider<GFS,TreePath,typename TypeTree::extract_child_type<
381  GFS,
382  TreePath
383  >::type::ImplementationTag
384  >
385  , public GridFunctionSubSpaceOutputParameters<typename TypeTree::extract_child_type<GFS,TreePath>::type>
386  {
387 
388  typedef TypeTree::ProxyNode<
389  const typename TypeTree::extract_child_type<
390  GFS,
391  TreePath
392  >::type
393  > NodeT;
394 
395  typedef SubSpaceFeatureProvider<
396  GFS,
397  TreePath,
398  typename TypeTree::extract_child_type<
399  GFS,
400  TreePath
401  >::type::ImplementationTag
402  > FeatureT;
403 
404  public:
405 
407  explicit GridFunctionSubSpace(std::shared_ptr<const GFS> gfs_storage)
408  : NodeT(TypeTree::extract_child_storage(*gfs_storage,TreePath()))
409  , FeatureT(*gfs_storage)
410  , _base_gfs(gfs_storage)
411  {
413  }
414 
415  // We can mask out the following constructors if we don't have template aliases,
416  // as we perform the necessary reference <-> shared_ptr conversions in the derived
417  // interface class.
418 
420  explicit GridFunctionSubSpace(const GFS& gfs)
421  : NodeT(TypeTree::extract_child_storage(gfs,TreePath()))
422  , FeatureT(gfs)
423  , _base_gfs(stackobject_to_shared_ptr(gfs))
424  {
426  }
427 
429 
439  template<typename TP>
440  explicit GridFunctionSubSpace(std::shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, typename enable_if<!is_same<TP,TreePath>::value,void*>::type = nullptr)
441  : NodeT(TypeTree::extract_child_storage(gfs_storage->baseGridFunctionSpace(),TreePath()))
442  , FeatureT(gfs_storage->baseGridFunctionSpace())
443  , _base_gfs(gfs_storage->baseGridFunctionSpaceStorage())
444  {
445  setDataSetType(childGridFunctionSpace().dataSetType());
446  }
447 
449 
459  template<typename TP>
460  explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, typename enable_if<!is_same<TP,TreePath>::value,void*>::type = nullptr)
461  : NodeT(TypeTree::extract_child_storage(gfs.baseGridFunctionSpace(),TreePath()))
462  , FeatureT(gfs.baseGridFunctionSpace())
463  , _base_gfs(gfs.baseGridFunctionSpaceStorage())
464  {
466  }
467 
468  public:
469 
472 
474  typedef typename TypeTree::extract_child_type<GFS,TreePath>::type ChildGridFunctionSpace;
475 
477  typedef typename ChildGridFunctionSpace::Traits Traits;
478 
480  typedef GridFunctionSubSpaceTag<
481  typename ChildGridFunctionSpace::ImplementationTag
483 
485  const BaseGridFunctionSpace& baseGridFunctionSpace() const
486  {
487  return *_base_gfs;
488  }
489 
491  std::shared_ptr<const BaseGridFunctionSpace> baseGridFunctionSpaceStorage() const
492  {
493  return _base_gfs;
494  }
495 
497 
502  const ChildGridFunctionSpace& childGridFunctionSpace() const
503  {
504  return this->proxiedNode();
505  }
506 
508 
513  std::shared_ptr<const ChildGridFunctionSpace> childGridFunctionSpaceStorage() const
514  {
515  return this->proxiedNodeStorage();
516  }
517 
518  std::string name() const
519  {
520  return childGridFunctionSpace().name();
521  }
522 
523  void name(const std::string& name)
524  {
525  childGridFunctionSpace().name(name);
526  }
527 
528  private:
529 
530  std::shared_ptr<const GFS> _base_gfs;
531 
532  };
533 
534 #ifndef DOXYGEN
535 
536 
538  template<typename GFS, typename TreePath>
539  struct construct_sub_space
540  {
541  typedef GridFunctionSubSpace<
542  GFS,
543  TreePath
544  > type;
545  };
546 
548  template<typename BaseGFS, typename SubGFSTreePath, typename TreePath>
549  struct construct_sub_space<Dune::PDELab::gfs::GridFunctionSubSpace<
550  BaseGFS,
551  SubGFSTreePath
552  >,
553  TreePath
554  >
555  {
556  typedef GridFunctionSubSpace<
557  BaseGFS,
558  typename TypeTree::TreePathConcat<
559  SubGFSTreePath,
560  TreePath
561  >::type
562  > type;
563  };
564 
565 #endif // DOXYGEN
566 
567  } // namespace gfs
568 
569 
570 #if DOXYGEN
571 
573  template<typename GFS, typename TreePath>
575 
576 #else // DOXYGEN
577 
579  template<typename GFS, typename TreePath>
580  using GridFunctionSubSpace = typename gfs::construct_sub_space<GFS,TreePath>::type;
581 
582 #endif // DOXYGEN
583 
585 
586  } // namespace PDELab
587 } // namespace Dune
588 
589 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACE_HH
Default features used by every subspace implementation.
Definition: subspace.hh:120
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:244
ChildGridFunctionSpace::OrderingTag OrderingTag
Re-exported OrderingTag from the original GridFunctionSpace.
Definition: subspace.hh:150
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:188
Definition: gridfunctionspace/tags.hh:35
const std::string & name() const
Returns the name of this space.
Definition: subspace.hh:268
_build_dof_index_type< GFS, typename GFS::OrderingTag >::type type
Definition: gridfunctionspace/tags.hh:311
const ChildGridFunctionSpace & childGridFunctionSpace() const
Returns the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:502
void name(const std::string &name)
Definition: subspace.hh:523
GridFunctionSubSpace(const GFS &gfs)
Construct a GridFunctionSubSpace from a root space.
Definition: subspace.hh:420
Traits::SizeType maxLocalSize() const
Returns the maximum number of DOFs per cells in this subspace.
Definition: subspace.hh:204
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:477
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:50
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:24
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:141
GridFunctionSubSpace(std::shared_ptr< const GFS > gfs_storage)
Construct a GridFunctionSubSpace from the storage object of a root space.
Definition: subspace.hh:407
Traits::SizeType size() const
Returns the global size of the root space.
Definition: subspace.hh:198
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:123
Additional features used by leaf subspaces.
Definition: subspace.hh:226
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:78
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:491
TypeTree::extract_child_type< GFS, TreePath >::type ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:474
std::size_t subSpaceDepth() const
Definition: subspace.hh:167
const BaseGridFunctionSpace & baseGridFunctionSpace() const
Returns the root GridFunctionSpace that this subspace view is based on.
Definition: subspace.hh:485
TypeTree::extract_child_type< GFS, TreePath >::type ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:144
GridFunctionSubSpace(std::shared_ptr< const GridFunctionSubSpace< GFS, TP > > gfs_storage, typename enable_if<!is_same< TP, TreePath >::value, void * >::type=nullptr)
Construct a GridFunctionSubSpace from the storage of another GridFunctionSubSpace.
Definition: subspace.hh:440
Mixin class which inherits from GridFunctionOutputParameters iff T inherits from GridFunctionOutputPa...
Definition: subspace.hh:331
Traits::SizeType maxLocalSize() const
Returns the maximum per-entity size of the TargetOrdering.
Definition: subordering.hh:200
const Ordering & ordering() const
Returns the ordering associated with this GridFunctionSubSpace.
Definition: subspace.hh:173
GridFunctionSubSpace(const GridFunctionSubSpace< GFS, TP > &gfs, typename enable_if<!is_same< TP, TreePath >::value, void * >::type=nullptr)
Construct a GridFunctionSubSpace from another GridFunctionSubSpace.
Definition: subspace.hh:460
std::shared_ptr< const typename Traits::FiniteElementMap > finiteElementMapStorage() const
Returns the storage object for the finite element map of this space.
Definition: subspace.hh:256
Definition: adaptivity.hh:27
typename GFS::template ConstraintsContainer< E > Constraintscontainer
Re-exported constraints container from the original GridFunctionSpace.
Definition: subspace.hh:155
void inheritDataSetType(const T &t)
Definition: subspace.hh:334
std::string name() const
Definition: subspace.hh:518
DefaultSubSpaceFeatures(const GFS &gfs)
Definition: subspace.hh:213
Definition: gridfunctionspace/tags.hh:309
std::shared_ptr< const ChildGridFunctionSpace > childGridFunctionSpaceStorage() const
Returns the storage object of the original GridFunctionSpace that we provide a view for...
Definition: subspace.hh:513
Support infrastructure to make LocalFunctionSpaces of GridFunctionSubSpace work.
GridFunctionSubSpaceTag< typename ChildGridFunctionSpace::ImplementationTag > ImplementationTag
Our ImplementationTag is derived from the tag of the original GridFunctionSpace.
Definition: subspace.hh:482
const Traits::ConstraintsType & constraints() const
Returns the constraints engine of this space.
Definition: subspace.hh:262
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:471
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:165
TreePath SubSpacePath
The TreePath from the root of the space hierarchy to this subspace.
Definition: subspace.hh:138
const Traits::GridViewType & gridView() const
Returns the underlying GridView.
Definition: subspace.hh:179
const Traits::FiniteElementMap & finiteElementMap() const
Returns the finite element map of this space.
Definition: subspace.hh:250
Traits::SizeType globalSize() const
Returns the global size of the root space.
Definition: subspace.hh:185
SubSpaceFeatureProvider(const GFS &gfs)
Definition: subspace.hh:290
TypeTree::extract_child_type< GFS, TreePath >::type ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:241
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:147
gfs::GridFunctionSubSpace< GFS, TreePath > GridFunctionSubSpace
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:574