dune-pdelab  2.0.0
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>
88  class GridFunctionSubSpace;
89 
90  } // namespace gfs
91 
92 
93  // specialized version of LocalFunctionSpace interface class
94  // This class injects SubSpaceLocalFunctionSpaceNode as an intermediate base class
95  // to fix the DOFIndex handling in bind().
96  template <typename BaseGFS, typename SubSpaceTreePath>
97  class LocalFunctionSpace<gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>, AnySpaceTag>
98  : public gfs::SubSpaceLocalFunctionSpaceNode<gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>,
99  typename TypeTree::TransformTree<
100  gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath>,
101  gfs_to_lfs<gfs::GridFunctionSubSpace<
102  BaseGFS,
103  SubSpaceTreePath
104  >
105  >
106  >::Type
107  >
108  {
109 
110  typedef gfs::GridFunctionSubSpace<BaseGFS,SubSpaceTreePath> GFS;
111 
112  typedef gfs::SubSpaceLocalFunctionSpaceNode<
113  GFS,
114  typename TypeTree::TransformTree<
115  GFS,
116  gfs_to_lfs<GFS>
117  >::Type
118  > BaseT;
119 
120  template<typename>
121  friend struct PropagateGlobalStorageVisitor;
122 
123  template<typename>
124  friend struct ClearSizeVisitor;
125 
126  template<typename>
127  friend struct ComputeSizeVisitor;
128 
129  template<typename>
130  friend struct FillIndicesVisitor;
131 
132  public:
133 
134  LocalFunctionSpace(const GFS & gfs)
135  : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
136  {
137  this->_dof_indices = &(this->_dof_index_storage);
138  this->setup(*this);
139  }
140 
141  LocalFunctionSpace(shared_ptr<const GFS> pgfs)
142  : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform_storage(pgfs))
143  {
144  this->_dof_indices = &(this->_dof_index_storage);
145  this->setup(*this);
146  }
147 
149  : BaseT(lfs)
150  {
151  // We need to reset the DOFIndex storage pointers in the new LFS tree,
152  // as they are still pointing to the _dof_index_storage of the
153  // old tree.
154  this->_dof_indices = &(this->_dof_index_storage);
155  this->setup(*this);
156  }
157 
158  };
159 
160  } // namespace PDELab
161 } // namespace Dune
162 
163 #endif // DOXYGEN
164 
165 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_SUBSPACELOCALFUNCTIONSPACE_HH
friend struct ComputeSizeVisitor
Definition: localfunctionspace.hh:732
void setup(NodeType &node)
Definition: localfunctionspace.hh:271
friend struct FillIndicesVisitor
Definition: localfunctionspace.hh:735
shared_ptr< GFS const > pgfs
Definition: localfunctionspace.hh:277
LocalFunctionSpace(const GFS &gfs)
Definition: localfunctionspace.hh:740
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
Traits::DOFIndexContainer * _dof_indices
Definition: localfunctionspace.hh:279
Traits::DOFIndexContainer _dof_index_storage
Definition: localfunctionspace.hh:278
friend struct PropagateGlobalStorageVisitor
Definition: localfunctionspace.hh:726
friend struct ClearSizeVisitor
Definition: localfunctionspace.hh:729
const E & e
Definition: interpolate.hh:172