dune-pdelab  2.5-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 std::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 std::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::EntitySet& entitySet() const
180  {
181  return subSpace().childGridFunctionSpace().entitySet();
182  }
183 
185  const typename Traits::GridViewType& gridView() const
186  {
187  return subSpace().childGridFunctionSpace().gridView();
188  }
189 
191  typename Traits::SizeType globalSize() const
192  {
193  return _ordering.size();
194  }
195 
197 
204  typename Traits::SizeType size() const
205  {
206  return _ordering.size();
207  }
208 
210  typename Traits::SizeType maxLocalSize() const
211  {
212  return _ordering.maxLocalSize();
213  }
214 
216 
217  protected:
218 
219  DefaultSubSpaceFeatures(const GFS& gfs)
220  : _ordering(gfs.orderingStorage())
221  {}
222 
223  private:
224 
225  Ordering _ordering;
226 
227  };
228 
229 
231  template<typename GFS, typename TreePath, typename Tag>
233  {
234 
237 
239  const SubSpace& subSpace() const
240  {
241  return static_cast<const SubSpace&>(*this);
242  }
243 
244  public:
245 
247  using ChildGridFunctionSpace = TypeTree::ChildForTreePath<GFS,TreePath>;
248 
250  typedef typename ChildGridFunctionSpace::Traits Traits;
251 
254 
256  const typename Traits::FiniteElementMap& finiteElementMap() const
257  {
258  return subSpace().childGridFunctionSpace().finiteElementMap();
259  }
260 
262  std::shared_ptr<const typename Traits::FiniteElementMap> finiteElementMapStorage () const
263  {
264  return subSpace().childGridFunctionSpace().finiteElementMapStorage();
265  }
266 
268  const typename Traits::ConstraintsType& constraints() const
269  {
270  return subSpace().childGridFunctionSpace().constraints();
271  }
272 
274  const std::string& name() const
275  {
276  return subSpace().childGridFunctionSpace().name();
277  }
279 
280  };
281 
282 
283 #ifdef DOXYGEN
284 
285 
288  template<typename GFS, typename TreePath, typename Tag>
290  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
291  , public LeafSubSpaceFeatures<GFS,TreePath,Tag>
292  {
293 
294  protected:
295 
296  SubSpaceFeatureProvider(const GFS& gfs)
297  : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs)
298  {}
299 
300  };
301 
302 #else // DOXYGEN
303 
305  template<typename GFS, typename TreePath, typename Tag>
307  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
308  {
309 
310  protected:
311 
312  SubSpaceFeatureProvider(const GFS& gfs)
314  {}
315 
316  };
317 
319  template<typename GFS, typename TreePath>
320  class SubSpaceFeatureProvider<GFS,TreePath,LeafGridFunctionSpaceTag>
321  : public DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
322  , public LeafSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
323  {
324 
325  protected:
326 
327  SubSpaceFeatureProvider(const GFS& gfs)
329  {}
330 
331  };
332 
333 #endif // DOXYGEN
334 
338  {
339  public:
340  void inheritDataSetType(const T & t) {}
341  };
342 
343 #ifndef DOXYGEN
344  template<class T>
347  {
348  public:
349  void inheritDataSetType(const T & t)
350  {
351  setDataSetType(t.dataSetType());
352  }
353  };
354 #endif
355 
356  // ********************************************************************************
357  // GridFunctionSubSpace implementation
358  // ********************************************************************************
359 
361 
383  template<typename GFS, typename TreePath>
385  : public TypeTree::ProxyNode<const TypeTree::ChildForTreePath<GFS,TreePath>>
386  , public SubSpaceFeatureProvider<GFS,TreePath,TypeTree::ImplementationTag<TypeTree::ChildForTreePath<GFS,TreePath>>>
387  , public GridFunctionSubSpaceOutputParameters<TypeTree::ChildForTreePath<GFS,TreePath>>
388  {
389 
390  using NodeT = TypeTree::ProxyNode<const TypeTree::ChildForTreePath<GFS,TreePath>>;
391 
392  using FeatureT = SubSpaceFeatureProvider<
393  GFS,
394  TreePath,
395  TypeTree::ImplementationTag<TypeTree::ChildForTreePath<GFS,TreePath>>
396  >;
397 
398  public:
399 
401  explicit GridFunctionSubSpace(std::shared_ptr<const GFS> gfs_storage)
402  : NodeT(TypeTree::childStorage(*gfs_storage,TreePath()))
403  , FeatureT(*gfs_storage)
404  , _base_gfs(gfs_storage)
405  {
406  this->inheritDataSetType(childGridFunctionSpace());
407  }
408 
409  // We can mask out the following constructors if we don't have template aliases,
410  // as we perform the necessary reference <-> shared_ptr conversions in the derived
411  // interface class.
412 
414  explicit GridFunctionSubSpace(const GFS& gfs)
415  : NodeT(TypeTree::childStorage(gfs,TreePath()))
416  , FeatureT(gfs)
417  , _base_gfs(stackobject_to_shared_ptr(gfs))
418  {
419  this->inheritDataSetType(childGridFunctionSpace());
420  }
421 
423 
433  template<typename TP>
434  explicit GridFunctionSubSpace(std::shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
435  : NodeT(TypeTree::childStorage(gfs_storage->baseGridFunctionSpace(),TreePath()))
436  , FeatureT(gfs_storage->baseGridFunctionSpace())
437  , _base_gfs(gfs_storage->baseGridFunctionSpaceStorage())
438  {
439  setDataSetType(childGridFunctionSpace().dataSetType());
440  }
441 
443 
453  template<typename TP>
454  explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
455  : NodeT(TypeTree::childStorage(gfs.baseGridFunctionSpace(),TreePath()))
456  , FeatureT(gfs.baseGridFunctionSpace())
457  , _base_gfs(gfs.baseGridFunctionSpaceStorage())
458  {
459  this->inheritDataSetType(childGridFunctionSpace());
460  }
461 
462  public:
463 
466 
468  using ChildGridFunctionSpace = TypeTree::ChildForTreePath<GFS,TreePath>;
469 
471  typedef typename ChildGridFunctionSpace::Traits Traits;
472 
474  typedef GridFunctionSubSpaceTag<
475  TypeTree::ImplementationTag<ChildGridFunctionSpace>
477 
479  const BaseGridFunctionSpace& baseGridFunctionSpace() const
480  {
481  return *_base_gfs;
482  }
483 
485  std::shared_ptr<const BaseGridFunctionSpace> baseGridFunctionSpaceStorage() const
486  {
487  return _base_gfs;
488  }
489 
491 
497  {
498  return this->proxiedNode();
499  }
500 
502 
507  std::shared_ptr<const ChildGridFunctionSpace> childGridFunctionSpaceStorage() const
508  {
509  return this->proxiedNodeStorage();
510  }
511 
512  std::string name() const
513  {
514  return childGridFunctionSpace().name();
515  }
516 
517  void name(const std::string& name)
518  {
519  childGridFunctionSpace().name(name);
520  }
521 
522  private:
523 
524  std::shared_ptr<const GFS> _base_gfs;
525 
526  };
527 
528 #ifndef DOXYGEN
529 
530 
532  template<typename GFS, typename TreePath>
533  struct construct_sub_space
534  {
535  typedef GridFunctionSubSpace<
536  GFS,
537  TreePath
538  > type;
539  };
540 
542  template<typename BaseGFS, typename SubGFSTreePath, typename TreePath>
543  struct construct_sub_space<Dune::PDELab::gfs::GridFunctionSubSpace<
544  BaseGFS,
545  SubGFSTreePath
546  >,
547  TreePath
548  >
549  {
550  typedef GridFunctionSubSpace<
551  BaseGFS,
552  typename TypeTree::TreePathConcat<
553  SubGFSTreePath,
554  TreePath
555  >::type
556  > type;
557  };
558 
559 #endif // DOXYGEN
560 
561  } // namespace gfs
562 
563 
564 #if DOXYGEN
565 
567  template<typename GFS, typename TreePath>
569 
570 #else // DOXYGEN
571 
573  template<typename GFS, typename TreePath>
574  using GridFunctionSubSpace = typename gfs::construct_sub_space<GFS,TreePath>::type;
575 
576 #endif // DOXYGEN
577 
579 
580  } // namespace PDELab
581 } // namespace Dune
582 
583 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACE_HH
Definition: gridfunctionspace/tags.hh:35
Traits::SizeType globalSize() const
Returns the global size of the root space.
Definition: subspace.hh:191
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:247
TreePath SubSpacePath
The TreePath from the root of the space hierarchy to this subspace.
Definition: subspace.hh:138
GridFunctionSubSpace(std::shared_ptr< const GFS > gfs_storage)
Construct a GridFunctionSubSpace from the storage object of a root space.
Definition: subspace.hh:401
Traits::SizeType size() const
Returns the global size of the root space.
Definition: subspace.hh:204
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:147
void inheritDataSetType(const T &t)
Definition: subspace.hh:340
GridFunctionSubSpace(const GridFunctionSubSpace< GFS, TP > &gfs, typename std::enable_if<!std::is_same< TP, TreePath >::value, void *>::type=nullptr)
Construct a GridFunctionSubSpace from another GridFunctionSubSpace.
Definition: subspace.hh:454
const std::string & name() const
Returns the name of this space.
Definition: subspace.hh:274
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:24
typename GFS::template ConstraintsContainer< E > Constraintscontainer
Re-exported constraints container from the original GridFunctionSpace.
Definition: subspace.hh:155
GridFunctionSubSpace(const GFS &gfs)
Construct a GridFunctionSubSpace from a root space.
Definition: subspace.hh:414
GridFunctionSubSpaceTag< TypeTree::ImplementationTag< ChildGridFunctionSpace > > ImplementationTag
Our ImplementationTag is derived from the tag of the original GridFunctionSpace.
Definition: subspace.hh:476
void name(const std::string &name)
Definition: subspace.hh:517
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:468
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:144
const BaseGridFunctionSpace & baseGridFunctionSpace() const
Returns the root GridFunctionSpace that this subspace view is based on.
Definition: subspace.hh:479
Definition: gridfunctionspace/tags.hh:238
Support infrastructure to make LocalFunctionSpaces of GridFunctionSubSpace work.
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:485
std::size_t subSpaceDepth() const
Definition: subspace.hh:167
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:49
std::shared_ptr< const typename Traits::FiniteElementMap > finiteElementMapStorage() const
Returns the storage object for the finite element map of this space.
Definition: subspace.hh:262
const Ordering & ordering() const
Returns the ordering associated with this GridFunctionSubSpace.
Definition: subspace.hh:173
DefaultSubSpaceFeatures(const GFS &gfs)
Definition: subspace.hh:219
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:76
std::string name() const
Definition: subspace.hh:512
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
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:465
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:471
Additional features used by leaf subspaces.
Definition: subspace.hh:232
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:250
Traits::SizeType maxLocalSize() const
Returns the maximum number of DOFs per cells in this subspace.
Definition: subspace.hh:210
const Traits::ConstraintsType & constraints() const
Returns the constraints engine of this space.
Definition: subspace.hh:268
ChildGridFunctionSpace::OrderingTag OrderingTag
Re-exported OrderingTag from the original GridFunctionSpace.
Definition: subspace.hh:150
const ChildGridFunctionSpace & childGridFunctionSpace() const
Returns the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:496
Mixin class which inherits from GridFunctionOutputParameters iff T inherits from GridFunctionOutputPa...
Definition: subspace.hh:337
const Traits::EntitySet & entitySet() const
Returns the underlying EntitySet.
Definition: subspace.hh:179
GridFunctionSubSpace(std::shared_ptr< const GridFunctionSubSpace< GFS, TP > > gfs_storage, 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:434
std::shared_ptr< const ChildGridFunctionSpace > childGridFunctionSpaceStorage() const
Returns the storage object of the original GridFunctionSpace that we provide a view for...
Definition: subspace.hh:507
Default features used by every subspace implementation.
Definition: subspace.hh:120
const Traits::GridViewType & gridView() const
Returns the underlying GridView.
Definition: subspace.hh:185
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:124
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:141
const Traits::FiniteElementMap & finiteElementMap() const
Returns the finite element map of this space.
Definition: subspace.hh:256
SubSpaceFeatureProvider(const GFS &gfs)
Definition: subspace.hh:296