dune-pdelab  2.4.1
subspacelocalfunctionspace.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_SUBSPACELOCALFUNCTIONSPACE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACELOCALFUNCTIONSPACE_HH
5 
10 // nothing in here is of interest to our users
11 #ifndef DOXYGEN
12 
14 
15 namespace Dune {
16  namespace PDELab {
17 
18  namespace gfs {
19 
20  // ********************************************************************************
21  // utility functions for copying a tree path to an iterator range in reverse order
22  // ********************************************************************************
23 
24  template<typename It>
25  void extract_tree_path_elements(TypeTree::TreePath<>, It it)
26  {
27  // end of recursion
28  }
29 
30  template<typename TP, typename It>
31  void extract_tree_path_elements(TP, It it)
32  {
34  extract_tree_path_elements(typename TypeTree::TreePathPopBack<TP>::type(),++it);
35  }
36 
37  // ********************************************************************************
38  // intermediate base class for LocalFunctionSpaces of GridFunctionSubSpace
39  // ********************************************************************************
40 
41  // This class works for subspaces of any kind of underlying space (leaf, Power, Composite)
42  // thanks to the magic of perfect forwarding
43  template<typename GFS, typename LFS>
44  class SubSpaceLocalFunctionSpaceNode
45  : public LFS
46  {
47 
48  public:
49 
50  typedef typename LFS::Traits Traits;
51 
52  template<typename... T>
53  SubSpaceLocalFunctionSpaceNode(T&&... t)
54  : LFS(std::forward<T>(t)...)
55  {
56  extract_tree_path_elements(typename GFS::SubSpacePath(),_tree_path.begin());
57  }
58 
59  // modify bind to fill up the DOFIndices with our subspace path
60  template<typename E>
61  void bind(const E& e)
62  {
63  LFS::bind(e);
64  for (auto di= this->_dof_index_storage.begin(), end=this->_dof_index_storage.end();
65  di!=end; ++di)
66  complete_dof_index(*di);
67  }
68 
69  std::size_t subSpaceDepth() const
70  {
71  return this->gridFunctionSpace().subSpaceDepth();
72  }
73 
74  private:
75 
77  void complete_dof_index(typename Traits::DOFIndex& di) const
78  {
79  std::copy(_tree_path.begin(),_tree_path.end(),std::back_inserter(di.treeIndex()));
80  }
81 
83 
84  };
85 
86  // forward declaration for use in LocalFunctionSpace specialization.
87  template<typename GFS, typename TreePath>
89 
90  } // namespace gfs
91 
92  // specialized version of LocalFunctionSpace interface class
93  // This class injects SubSpaceLocalFunctionSpaceNode as an intermediate base class
94  // to fix the DOFIndex handling in bind().
95  template <typename BaseGFS, typename SubSpaceTreePath>
96  class LocalFunctionSpace<gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>, AnySpaceTag>
97  : public gfs::SubSpaceLocalFunctionSpaceNode<gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>,
98  typename TypeTree::TransformTree<
99  gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>,
100  gfs_to_lfs<gfs::GridFunctionSubSpace<
101  BaseGFS,
102  SubSpaceTreePath
103  >
104  >
105  >::Type
106  >
107  {
108 
109  typedef gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath> GFS;
110 
111  typedef gfs::SubSpaceLocalFunctionSpaceNode<
112  GFS,
113  typename TypeTree::TransformTree<
114  GFS,
115  gfs_to_lfs<GFS>
116  >::Type
117  > BaseT;
118 
119  template<typename>
120  friend struct PropagateGlobalStorageVisitor;
121 
122  template<typename>
123  friend struct ClearSizeVisitor;
124 
125  template<typename>
126  friend struct ComputeSizeVisitor;
127 
128  template<typename>
129  friend struct FillIndicesVisitor;
130 
131  public:
132 
133  LocalFunctionSpace(const GFS & gfs)
134  : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
135  {
136  this->_dof_indices = &(this->_dof_index_storage);
137  this->setup(*this);
138  }
139 
140  LocalFunctionSpace(std::shared_ptr<const GFS> pgfs)
141  : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform_storage(pgfs))
142  {
143  this->_dof_indices = &(this->_dof_index_storage);
144  this->setup(*this);
145  }
146 
147  LocalFunctionSpace(const LocalFunctionSpace & lfs)
148  : BaseT(lfs)
149  {
150  // We need to reset the DOFIndex storage pointers in the new LFS tree,
151  // as they are still pointing to the _dof_index_storage of the
152  // old tree.
153  this->_dof_indices = &(this->_dof_index_storage);
154  this->setup(*this);
155  }
156 
157  };
158 
159  } // namespace PDELab
160 } // namespace Dune
161 
162 #endif // DOXYGEN
163 
164 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACELOCALFUNCTIONSPACE_HH
STL namespace.
gfs::GridFunctionSubSpace< GFS, TreePath > GridFunctionSubSpace
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:568
static const unsigned int value
Definition: gridfunctionspace/tags.hh:177
Definition: adaptivity.hh:27
const Entity & e
Definition: localfunctionspace.hh:111