DUNE PDELab (2.7)

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
13#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
14#include <dune/pdelab/gridfunctionspace/localfunctionspace.hh>
15
16namespace Dune {
17 namespace PDELab {
18
19 namespace gfs {
20
21 // ********************************************************************************
22 // utility functions for copying a tree path to an iterator range in reverse order
23 // ********************************************************************************
24
25 template<typename It>
26 void extract_tree_path_elements(TypeTree::StaticTreePath<>, It it)
27 {
28 // end of recursion
29 }
30
31 template<typename TP, typename It>
32 void extract_tree_path_elements(TP, It it)
33 {
34 *it = TypeTree::TreePathBack<TP>::value;
35 extract_tree_path_elements(typename TypeTree::TreePathPopBack<TP>::type(),++it);
36 }
37
38 // ********************************************************************************
39 // intermediate base class for LocalFunctionSpaces of GridFunctionSubSpace
40 // ********************************************************************************
41
42 // This class works for subspaces of any kind of underlying space (leaf, Power, Composite)
43 // thanks to the magic of perfect forwarding
44 template<typename GFS, typename LFS>
45 class SubSpaceLocalFunctionSpaceNode
46 : public LFS
47 {
48
49 public:
50
51 typedef typename LFS::Traits Traits;
52
53 template<typename... T>
54 SubSpaceLocalFunctionSpaceNode(T&&... t)
55 : LFS(std::forward<T>(t)...)
56 {
57 extract_tree_path_elements(typename GFS::SubSpacePath(),_tree_path.begin());
58 }
59
60 // modify bind to fill up the DOFIndices with our subspace path
61 template<typename E>
62 void bind(const E& e)
63 {
64 LFS::bind(e);
65 for (auto di= this->_dof_index_storage.begin(), end=this->_dof_index_storage.end();
66 di!=end; ++di)
67 complete_dof_index(*di);
68 }
69
70 std::size_t subSpaceDepth() const
71 {
72 return this->gridFunctionSpace().subSpaceDepth();
73 }
74
75 private:
76
78 void complete_dof_index(typename Traits::DOFIndex& di) const
79 {
80 std::copy(_tree_path.begin(),_tree_path.end(),std::back_inserter(di.treeIndex()));
81 }
82
83 std::array<std::size_t,TypeTree::TreePathSize<typename GFS::SubSpacePath>::value> _tree_path;
84
85 };
86
87 // forward declaration for use in LocalFunctionSpace specialization.
88 template<typename GFS, typename TreePath>
90
91 } // namespace gfs
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,bool>
127 friend struct ComputeSizeVisitor;
128
129 template<typename,bool>
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(std::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
148 LocalFunctionSpace(const LocalFunctionSpace & lfs)
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
gfs::GridFunctionSubSpace< GFS, TreePath > GridFunctionSubSpace
Non-nesting implementation of GridFunctionSubSpace.
Definition: subspace.hh:569
Dune namespace.
Definition: alignedallocator.hh:14
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)