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  using SubOrdering = TypeTree::ChildForTreePath<Ordering,OrderingTP>;
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  using ChildGridFunctionSpace = TypeTree::ChildForTreePath<GFS,TreePath>;
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  using ChildGridFunctionSpace = TypeTree::ChildForTreePath<GFS,TreePath>;
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 TypeTree::ChildForTreePath<GFS,TreePath>>
380  , public SubSpaceFeatureProvider<GFS,TreePath,typename TypeTree::ChildForTreePath<GFS,TreePath>::ImplementationTag>
381  , public GridFunctionSubSpaceOutputParameters<TypeTree::ChildForTreePath<GFS,TreePath>>
382  {
383 
384  using NodeT = TypeTree::ProxyNode<const TypeTree::ChildForTreePath<GFS,TreePath>>;
385 
386  using FeatureT = SubSpaceFeatureProvider<
387  GFS,
388  TreePath,
389  typename TypeTree::ChildForTreePath<GFS,TreePath>::ImplementationTag
390  >;
391 
392  public:
393 
395  explicit GridFunctionSubSpace(std::shared_ptr<const GFS> gfs_storage)
396  : NodeT(TypeTree::extract_child_storage(*gfs_storage,TreePath()))
397  , FeatureT(*gfs_storage)
398  , _base_gfs(gfs_storage)
399  {
401  }
402 
403  // We can mask out the following constructors if we don't have template aliases,
404  // as we perform the necessary reference <-> shared_ptr conversions in the derived
405  // interface class.
406 
408  explicit GridFunctionSubSpace(const GFS& gfs)
409  : NodeT(TypeTree::extract_child_storage(gfs,TreePath()))
410  , FeatureT(gfs)
411  , _base_gfs(stackobject_to_shared_ptr(gfs))
412  {
414  }
415 
417 
427  template<typename TP>
428  explicit GridFunctionSubSpace(std::shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, typename enable_if<!is_same<TP,TreePath>::value,void*>::type = nullptr)
429  : NodeT(TypeTree::extract_child_storage(gfs_storage->baseGridFunctionSpace(),TreePath()))
430  , FeatureT(gfs_storage->baseGridFunctionSpace())
431  , _base_gfs(gfs_storage->baseGridFunctionSpaceStorage())
432  {
433  setDataSetType(childGridFunctionSpace().dataSetType());
434  }
435 
437 
447  template<typename TP>
448  explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, typename enable_if<!is_same<TP,TreePath>::value,void*>::type = nullptr)
449  : NodeT(TypeTree::extract_child_storage(gfs.baseGridFunctionSpace(),TreePath()))
451  , _base_gfs(gfs.baseGridFunctionSpaceStorage())
452  {
454  }
455 
456  public:
457 
460 
462  using ChildGridFunctionSpace = TypeTree::ChildForTreePath<GFS,TreePath>;
463 
465  typedef typename ChildGridFunctionSpace::Traits Traits;
466 
468  typedef GridFunctionSubSpaceTag<
469  typename ChildGridFunctionSpace::ImplementationTag
471 
473  const BaseGridFunctionSpace& baseGridFunctionSpace() const
474  {
475  return *_base_gfs;
476  }
477 
479  std::shared_ptr<const BaseGridFunctionSpace> baseGridFunctionSpaceStorage() const
480  {
481  return _base_gfs;
482  }
483 
485 
491  {
492  return this->proxiedNode();
493  }
494 
496 
501  std::shared_ptr<const ChildGridFunctionSpace> childGridFunctionSpaceStorage() const
502  {
503  return this->proxiedNodeStorage();
504  }
505 
506  std::string name() const
507  {
508  return childGridFunctionSpace().name();
509  }
510 
511  void name(const std::string& name)
512  {
513  childGridFunctionSpace().name(name);
514  }
515 
516  private:
517 
518  std::shared_ptr<const GFS> _base_gfs;
519 
520  };
521 
522 #ifndef DOXYGEN
523 
524 
526  template<typename GFS, typename TreePath>
527  struct construct_sub_space
528  {
529  typedef GridFunctionSubSpace<
530  GFS,
531  TreePath
532  > type;
533  };
534 
536  template<typename BaseGFS, typename SubGFSTreePath, typename TreePath>
537  struct construct_sub_space<Dune::PDELab::gfs::GridFunctionSubSpace<
538  BaseGFS,
539  SubGFSTreePath
540  >,
541  TreePath
542  >
543  {
544  typedef GridFunctionSubSpace<
545  BaseGFS,
546  typename TypeTree::TreePathConcat<
547  SubGFSTreePath,
548  TreePath
549  >::type
550  > type;
551  };
552 
553 #endif // DOXYGEN
554 
555  } // namespace gfs
556 
557 
558 #if DOXYGEN
559 
561  template<typename GFS, typename TreePath>
563 
564 #else // DOXYGEN
565 
567  template<typename GFS, typename TreePath>
568  using GridFunctionSubSpace = typename gfs::construct_sub_space<GFS,TreePath>::type;
569 
570 #endif // DOXYGEN
571 
573 
574  } // namespace PDELab
575 } // namespace Dune
576 
577 #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:490
void name(const std::string &name)
Definition: subspace.hh:511
GridFunctionSubSpace(const GFS &gfs)
Construct a GridFunctionSubSpace from a root space.
Definition: subspace.hh:408
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:465
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:241
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:395
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:462
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:479
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:473
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:428
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:448
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:506
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:501
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:470
const Traits::ConstraintsType & constraints() const
Returns the constraints engine of this space.
Definition: subspace.hh:262
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:144
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:459
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
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:562