DUNE PDELab (2.7)

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 
17 namespace 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 
53 
54  // ********************************************************************************
55  // Helper TMPs
56  // ********************************************************************************
57 
59 
63  template<typename Ordering, typename GFS, typename GFSTP, typename OrderingTP = TypeTree::StaticTreePath<> >
64  struct find_ordering_treepath_for_sub_gfs
65  {
66 
67  // Get the ordering at the current subtree position.
69 
70  // Only descend in the GFS tree if the current ordering child consumes a tree index entry.
71  typedef typename std::conditional<
73  typename GFS::template Child<TypeTree::TreePathFront<GFSTP>::value>::type,
74  GFS
75  >::type SubGFS;
76 
77  // Insert either GFS child index or synthesized child index (always 0) in the ordering treepath.
78  typedef typename TypeTree::TreePathPushBack<
79  OrderingTP,
80  (SubOrdering::consume_tree_index ? TypeTree::TreePathFront<GFSTP>::value : 0)
81  >::type SubOrderingTP;
82 
83  // Keep (synthesized ordering node) or drop (ordering with associated GFS) first entry of GFS TreePath.
84  typedef typename std::conditional<
86  typename TypeTree::TreePathPopFront<GFSTP>::type,
87  GFSTP
88  >::type SubGFSTP;
89 
90  // Recurse into child trees.
91  typedef typename find_ordering_treepath_for_sub_gfs<
92  Ordering,
93  SubGFS,
94  SubGFSTP,
95  SubOrderingTP
96  >::type type;
97 
98  };
99 
101  template<typename Ordering, typename GFS, typename OrderingTP>
102  struct find_ordering_treepath_for_sub_gfs<Ordering,GFS,TypeTree::StaticTreePath<>,OrderingTP>
103  {
104 
105  // We have found the correct ordering TreePath, so let's return it.
106  typedef OrderingTP type;
107 
108  };
109 
110  } // anonymous namespace
111 
112 
113 
114 
115  // *****************************************************************************************
116  // Feature provider mixins
117  // *****************************************************************************************
118 
120  template<typename GFS, typename TreePath, typename Tag>
122  {
123 
126 
128  const SubSpace& subSpace() const
129  {
130  return static_cast<const SubSpace&>(*this);
131  }
132 
133  public:
134 
137 
139  typedef TreePath SubSpacePath;
140 
143 
146 
148  typedef typename ChildGridFunctionSpace::Traits Traits;
149 
151  typedef typename ChildGridFunctionSpace::OrderingTag OrderingTag;
152 
153 
155  template<typename E>
156  using Constraintscontainer = typename GFS::template ConstraintsContainer<E>;
157 
159  typedef SubOrdering<
160  typename GFS::Ordering,
161  typename find_ordering_treepath_for_sub_gfs<
162  typename GFS::Ordering,
163  GFS,
164  TreePath
165  >::type
167 
168  std::size_t subSpaceDepth() const
169  {
170  return TypeTree::TreePathSize<SubSpacePath>::value;
171  }
172 
174  const Ordering& ordering() const
175  {
176  return _ordering;
177  }
178 
180  const typename Traits::EntitySet& entitySet() const
181  {
182  return subSpace().childGridFunctionSpace().entitySet();
183  }
184 
186  const typename Traits::GridViewType& gridView() const
187  {
188  return subSpace().childGridFunctionSpace().gridView();
189  }
190 
192  typename Traits::SizeType globalSize() const
193  {
194  return _ordering.size();
195  }
196 
198 
205  typename Traits::SizeType size() const
206  {
207  return _ordering.size();
208  }
209 
211  typename Traits::SizeType maxLocalSize() const
212  {
213  return _ordering.maxLocalSize();
214  }
215 
217 
218  protected:
219 
220  DefaultSubSpaceFeatures(const GFS& gfs)
221  : _ordering(gfs.orderingStorage())
222  {}
223 
224  private:
225 
226  Ordering _ordering;
227 
228  };
229 
230 
232  template<typename GFS, typename TreePath, typename Tag>
234  {
235 
238 
240  const SubSpace& subSpace() const
241  {
242  return static_cast<const SubSpace&>(*this);
243  }
244 
245  public:
246 
249 
251  typedef typename ChildGridFunctionSpace::Traits Traits;
252 
255 
257  const typename Traits::FiniteElementMap& finiteElementMap() const
258  {
259  return subSpace().childGridFunctionSpace().finiteElementMap();
260  }
261 
263  std::shared_ptr<const typename Traits::FiniteElementMap> finiteElementMapStorage () const
264  {
265  return subSpace().childGridFunctionSpace().finiteElementMapStorage();
266  }
267 
269  const typename Traits::ConstraintsType& constraints() const
270  {
271  return subSpace().childGridFunctionSpace().constraints();
272  }
273 
275  const std::string& name() const
276  {
277  return subSpace().childGridFunctionSpace().name();
278  }
280 
281  };
282 
283 
284 #ifdef DOXYGEN
285 
286 
289  template<typename GFS, typename TreePath, typename Tag>
291  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
292  , public LeafSubSpaceFeatures<GFS,TreePath,Tag>
293  {
294 
295  protected:
296 
297  SubSpaceFeatureProvider(const GFS& gfs)
299  {}
300 
301  };
302 
303 #else // DOXYGEN
304 
306  template<typename GFS, typename TreePath, typename Tag>
308  : public DefaultSubSpaceFeatures<GFS,TreePath,Tag>
309  {
310 
311  protected:
312 
313  SubSpaceFeatureProvider(const GFS& gfs)
314  : DefaultSubSpaceFeatures<GFS,TreePath,Tag>(gfs)
315  {}
316 
317  };
318 
320  template<typename GFS, typename TreePath>
321  class SubSpaceFeatureProvider<GFS,TreePath,LeafGridFunctionSpaceTag>
322  : public DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
323  , public LeafSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>
324  {
325 
326  protected:
327 
328  SubSpaceFeatureProvider(const GFS& gfs)
329  : DefaultSubSpaceFeatures<GFS,TreePath,LeafGridFunctionSpaceTag>(gfs)
330  {}
331 
332  };
333 
334 #endif // DOXYGEN
335 
337  template<class T, bool Enable = std::is_base_of<GridFunctionOutputParameters, T>::value>
339  {
340  public:
341  void inheritDataSetType(const T & t) {}
342  };
343 
344 #ifndef DOXYGEN
345  template<class T>
348  {
349  public:
350  void inheritDataSetType(const T & t)
351  {
352  setDataSetType(t.dataSetType());
353  }
354  };
355 #endif
356 
357  // ********************************************************************************
358  // GridFunctionSubSpace implementation
359  // ********************************************************************************
360 
362 
384  template<typename GFS, typename TreePath>
386  : public TypeTree::ProxyNode<const TypeTree::ChildForTreePath<GFS,TreePath>>
387  , public SubSpaceFeatureProvider<GFS,TreePath,TypeTree::ImplementationTag<TypeTree::ChildForTreePath<GFS,TreePath>>>
388  , public GridFunctionSubSpaceOutputParameters<TypeTree::ChildForTreePath<GFS,TreePath>>
389  {
390 
392 
394  GFS,
395  TreePath,
397  >;
398 
399  public:
400 
402  explicit GridFunctionSubSpace(std::shared_ptr<const GFS> gfs_storage)
403  : NodeT(TypeTree::childStorage(*gfs_storage,TreePath()))
404  , FeatureT(*gfs_storage)
405  , _base_gfs(gfs_storage)
406  {
407  this->inheritDataSetType(childGridFunctionSpace());
408  }
409 
410  // We can mask out the following constructors if we don't have template aliases,
411  // as we perform the necessary reference <-> shared_ptr conversions in the derived
412  // interface class.
413 
415  explicit GridFunctionSubSpace(const GFS& gfs)
416  : NodeT(TypeTree::childStorage(gfs,TreePath()))
417  , FeatureT(gfs)
418  , _base_gfs(stackobject_to_shared_ptr(gfs))
419  {
420  this->inheritDataSetType(childGridFunctionSpace());
421  }
422 
424 
434  template<typename TP>
435  explicit GridFunctionSubSpace(std::shared_ptr<const GridFunctionSubSpace<GFS,TP> > gfs_storage, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
436  : NodeT(TypeTree::childStorage(gfs_storage->baseGridFunctionSpace(),TreePath()))
437  , FeatureT(gfs_storage->baseGridFunctionSpace())
438  , _base_gfs(gfs_storage->baseGridFunctionSpaceStorage())
439  {
440  setDataSetType(childGridFunctionSpace().dataSetType());
441  }
442 
444 
454  template<typename TP>
455  explicit GridFunctionSubSpace(const GridFunctionSubSpace<GFS,TP>& gfs, typename std::enable_if<!std::is_same<TP,TreePath>::value,void*>::type = nullptr)
456  : NodeT(TypeTree::childStorage(gfs.baseGridFunctionSpace(),TreePath()))
458  , _base_gfs(gfs.baseGridFunctionSpaceStorage())
459  {
460  this->inheritDataSetType(childGridFunctionSpace());
461  }
462 
463  public:
464 
467 
470 
472  typedef typename ChildGridFunctionSpace::Traits Traits;
473 
475  typedef GridFunctionSubSpaceTag<
478 
481  {
482  return *_base_gfs;
483  }
484 
486  std::shared_ptr<const BaseGridFunctionSpace> baseGridFunctionSpaceStorage() const
487  {
488  return _base_gfs;
489  }
490 
492 
498  {
499  return this->proxiedNode();
500  }
501 
503 
508  std::shared_ptr<const ChildGridFunctionSpace> childGridFunctionSpaceStorage() const
509  {
510  return this->proxiedNodeStorage();
511  }
512 
513  std::string name() const
514  {
515  return childGridFunctionSpace().name();
516  }
517 
518  void name(const std::string& name)
519  {
520  childGridFunctionSpace().name(name);
521  }
522 
523  private:
524 
525  std::shared_ptr<const GFS> _base_gfs;
526 
527  };
528 
529 #ifndef DOXYGEN
530 
531 
533  template<typename GFS, typename TreePath>
534  struct construct_sub_space
535  {
536  typedef GridFunctionSubSpace<
537  GFS,
538  TreePath
539  > type;
540  };
541 
543  template<typename BaseGFS, typename SubGFSTreePath, typename TreePath>
544  struct construct_sub_space<Dune::PDELab::gfs::GridFunctionSubSpace<
545  BaseGFS,
546  SubGFSTreePath
547  >,
548  TreePath
549  >
550  {
551  typedef GridFunctionSubSpace<
552  BaseGFS,
553  typename TypeTree::TreePathConcat<
554  SubGFSTreePath,
555  TreePath
556  >::type
557  > type;
558  };
559 
560 #endif // DOXYGEN
561 
562  } // namespace gfs
563 
564 
565 #if DOXYGEN
566 
568  template<typename GFS, typename TreePath>
570 
571 #else // DOXYGEN
572 
574  template<typename GFS, typename TreePath>
575  using GridFunctionSubSpace = typename gfs::construct_sub_space<GFS,TreePath>::type;
576 
577 #endif // DOXYGEN
578 
580 
581  } // namespace PDELab
582 } // namespace Dune
583 
584 #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:191
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:179
Default features used by every subspace implementation.
Definition: subspace.hh:122
typename GFS::template ConstraintsContainer< E > Constraintscontainer
Re-exported constraints container from the original GridFunctionSpace.
Definition: subspace.hh:156
const Traits::EntitySet & entitySet() const
Returns the underlying EntitySet.
Definition: subspace.hh:180
const Ordering & ordering() const
Returns the ordering associated with this GridFunctionSubSpace.
Definition: subspace.hh:174
Traits::SizeType size() const
Returns the global size of the root space.
Definition: subspace.hh:205
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:148
const Traits::GridViewType & gridView() const
Returns the underlying GridView.
Definition: subspace.hh:186
Traits::SizeType maxLocalSize() const
Returns the maximum number of DOFs per cells in this subspace.
Definition: subspace.hh:211
Traits::SizeType globalSize() const
Returns the global size of the root space.
Definition: subspace.hh:192
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:145
ChildGridFunctionSpace::OrderingTag OrderingTag
Re-exported OrderingTag from the original GridFunctionSpace.
Definition: subspace.hh:151
TreePath SubSpacePath
The TreePath from the root of the space hierarchy to this subspace.
Definition: subspace.hh:139
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:166
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:142
Mixin class which inherits from GridFunctionOutputParameters iff T inherits from GridFunctionOutputPa...
Definition: subspace.hh:339
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:389
const ChildGridFunctionSpace & childGridFunctionSpace() const
Returns the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:497
GFS BaseGridFunctionSpace
The base GridFunctionSpace that this GridFunctionSubSpace is based on.
Definition: subspace.hh:466
GridFunctionSubSpaceTag< TypeTree::ImplementationTag< ChildGridFunctionSpace > > ImplementationTag
Our ImplementationTag is derived from the tag of the original GridFunctionSpace.
Definition: subspace.hh:477
GridFunctionSubSpace(const GFS &gfs)
Construct a GridFunctionSubSpace from a root space.
Definition: subspace.hh:415
const BaseGridFunctionSpace & baseGridFunctionSpace() const
Returns the root GridFunctionSpace that this subspace view is based on.
Definition: subspace.hh:480
GridFunctionSubSpace(std::shared_ptr< const GFS > gfs_storage)
Construct a GridFunctionSubSpace from the storage object of a root space.
Definition: subspace.hh:402
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:486
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:435
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:472
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:455
std::shared_ptr< const ChildGridFunctionSpace > childGridFunctionSpaceStorage() const
Returns the storage object of the original GridFunctionSpace that we provide a view for.
Definition: subspace.hh:508
Additional features used by leaf subspaces.
Definition: subspace.hh:234
ChildGridFunctionSpace::Traits Traits
Re-exported Traits from the original GridFunctionSpace.
Definition: subspace.hh:251
const Traits::FiniteElementMap & finiteElementMap() const
Returns the finite element map of this space.
Definition: subspace.hh:257
TypeTree::ChildForTreePath< GFS, TreePath > ChildGridFunctionSpace
The type of the original GridFunctionSpace that is the root of this GridFunctionSpace.
Definition: subspace.hh:248
const std::string & name() const
Returns the name of this space.
Definition: subspace.hh:275
const Traits::ConstraintsType & constraints() const
Returns the constraints engine of this space.
Definition: subspace.hh:269
std::shared_ptr< const typename Traits::FiniteElementMap > finiteElementMapStorage() const
Returns the storage object for the finite element map of this space.
Definition: subspace.hh:263
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:258
std::enable_if< enabled, const TypeTree::ChildForTreePath< GFS, TreePath > & >::type proxiedNode()
Returns the proxied node.
Definition: proxynode.hh:298
std::enable_if< enabled, std::shared_ptr< const TypeTree::ChildForTreePath< GFS, TreePath > > >::type proxiedNodeStorage()
Returns the storage of the proxied node.
Definition: proxynode.hh:312
gfs::GridFunctionSubSpace< GFS, TreePath > GridFunctionSubSpace
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:569
typename std::decay_t< T >::ImplementationTag ImplementationTag
Returns the implementation tag of the given Node.
Definition: nodeinterface.hh:66
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:303
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Support infrastructure to make LocalFunctionSpaces of GridFunctionSubSpace work.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)