dune-pdelab  2.5-dev
dunefunctionslocalfunctionspace.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_DUNEFUNCTIONSLOCALFUNCTIONSPACE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLOCALFUNCTIONSPACE_HH
5 
6 #include<vector>
7 
8 #include <dune/common/stdstreams.hh>
9 
10 #include <dune/geometry/referenceelements.hh>
11 
12 #include <dune/localfunctions/common/interfaceswitch.hh>
13 #include <dune/localfunctions/common/localkey.hh>
14 
15 #include <dune/typetree/typetree.hh>
16 
19 
20 namespace Dune {
21  namespace PDELab {
22 
26 
27  namespace Experimental {
28 
29  template<typename LFS>
30  struct LeafLFSMixin
31  : public TypeTree::LeafNode
32  {
33 
34  const auto& finiteElement() const
35  {
36  return static_cast<const LFS*>(this)->tree().finiteElement();
37  }
38 
39  template<typename Tree>
40  struct Traits
41  {
42  using FiniteElement = typename Tree::FiniteElement;
44  };
45  };
46 
47  template<typename GFS, typename TreePath = TypeTree::HybridTreePath<>>
49  : public LeafLFSMixin<LocalFunctionSpace<GFS,TreePath>>
50  {
51 
52  public:
53 
54  using Basis = typename GFS::Basis;
55  using LocalView = typename Basis::LocalView;
56  using Tree = TypeTree::ChildForTreePath<typename LocalView::Tree,TreePath>;
57  using LocalIndexSet = typename Basis::LocalIndexSet;
58  using DOFIndex = typename Basis::MultiIndex;
59 
60  template<typename LFS, typename C, typename Tag, bool fast>
61  friend class LFSIndexCacheBase;
62 
63  struct Traits
64  : public LeafLFSMixin<LocalFunctionSpace<GFS,TreePath>>::template Traits<Tree>
65  {
66 
67  using GridFunctionSpace = GFS;
68  using GridView = typename GFS::Traits::GridView;
69  using SizeType = std::size_t;
70  using DOFIndex = typename Basis::MultiIndex;
71  using ConstraintsType = typename GFS::Traits::ConstraintsType;
72 
73  };
74 
75  using size_type = std::size_t;
76 
77  LocalFunctionSpace(std::shared_ptr<const GFS> gfs, TreePath tree_path = TreePath(), size_type offset = 0)
78  : _gfs(gfs)
79  , _local_view(gfs->basis())
80  , _tree_path(tree_path)
81  , _tree(TypeTree::child(_local_view.tree(),tree_path))
82  , _local_index_set(gfs->basis().localIndexSet())
83  {}
84 
86  {
87  return 0;
88  }
89 
91  size_type size () const
92  {
93  return _local_view.size();
94  }
95 
96  size_type maxSize () const
97  {
98  // _dof_indices is always as large as the max local size of the root GFS
99  return _local_view.maxSize();
100  }
101 
104  {
105  return _tree.localIndex(index);
106  }
107 
109  {
110  return _local_index_set.index(_tree.localIndex(index));
111  }
112 
114  const GFS& gridFunctionSpace() const
115  {
116  return *_gfs;
117  }
118 
119  void bind(const typename GFS::Traits::EntitySet::template Codim<0>::Entity& e)
120  {
121  _local_view.bind(e);
122  _local_index_set.bind(_local_view);
123  }
124 
125  const typename Traits::ConstraintsType& constraints() const
126  {
127  return _gfs->constraints();
128  }
129 
130  const Tree& tree() const
131  {
132  return _tree;
133  }
134 
135  private:
136 
137  std::shared_ptr<const GFS> _gfs;
138  LocalView _local_view;
139  TreePath _tree_path;
140  const Tree& _tree;
141  LocalIndexSet _local_index_set;
142 
143  };
144 
145  // forward declare GridFunctionSpace
146  template<typename DFBasis, typename V, typename CE=NoConstraints>
147  class GridFunctionSpace;
148 
149 
150  } // namespace Experimental
151 
152 
153  template<typename DFBasis, typename V, typename CE, typename TAG>
154  class LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>,TAG>
155  : public Experimental::LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>>
156  {
157 
159 
160  public:
161 
162  LocalFunctionSpace(std::shared_ptr<const GFS> gfs)
163  : Experimental::LocalFunctionSpace<GFS>(gfs)
164  {}
165 
166  LocalFunctionSpace(const GFS& gfs)
167  : Experimental::LocalFunctionSpace<GFS>(stackobject_to_shared_ptr(gfs))
168  {}
169 
170  };
171 
172  template<typename DFBasis, typename V, typename CE>
173  class LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>,AnySpaceTag>
174  : public Experimental::LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>>
175  {
176 
178 
179  public:
180 
181  LocalFunctionSpace(std::shared_ptr<const GFS> gfs)
182  : Experimental::LocalFunctionSpace<GFS>(gfs)
183  {}
184 
185  LocalFunctionSpace(const GFS& gfs)
186  : Experimental::LocalFunctionSpace<GFS>(stackobject_to_shared_ptr(gfs))
187  {}
188 
189  };
190 
192  } // namespace PDELab
193 } // namespace Dune
194 
195 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLOCALFUNCTIONSPACE_HH
const Entity & e
Definition: localfunctionspace.hh:120
A grid function space.
Definition: gridfunctionspace.hh:166
FiniteElement FiniteElementType
Definition: dunefunctionslocalfunctionspace.hh:43
const GFS & gridFunctionSpace() const
Returns the GridFunctionSpace underlying this LocalFunctionSpace.
Definition: dunefunctionslocalfunctionspace.hh:114
Definition: localfunctionspacetags.hh:40
A pdelab grid function space implemented by a dune-functions function space basis.
Definition: dunefunctionsgridfunctionspace.hh:53
LocalFunctionSpace(std::shared_ptr< const GFS > gfs)
Definition: dunefunctionslocalfunctionspace.hh:162
const Tree & tree() const
Definition: dunefunctionslocalfunctionspace.hh:130
typename Experimental::GridFunctionSpace< DFBasis, V, CE > ::Basis Basis
Definition: dunefunctionslocalfunctionspace.hh:54
LocalFunctionSpace(const GFS &gfs)
Definition: dunefunctionslocalfunctionspace.hh:166
std::size_t SizeType
Definition: dunefunctionslocalfunctionspace.hh:69
const auto & finiteElement() const
Definition: dunefunctionslocalfunctionspace.hh:34
typename GFS::Traits::GridView GridView
Definition: dunefunctionslocalfunctionspace.hh:68
LocalFunctionSpace(std::shared_ptr< const GFS > gfs, TreePath tree_path=TreePath(), size_type offset=0)
Definition: dunefunctionslocalfunctionspace.hh:77
const std::size_t offset
Definition: localfunctionspace.hh:74
typename Basis::LocalView LocalView
Definition: dunefunctionslocalfunctionspace.hh:55
typename Tree::FiniteElement FiniteElement
Definition: dunefunctionslocalfunctionspace.hh:42
typename Basis::MultiIndex DOFIndex
Definition: dunefunctionslocalfunctionspace.hh:70
size_type maxSize() const
Definition: dunefunctionslocalfunctionspace.hh:96
typename Basis::MultiIndex DOFIndex
Definition: dunefunctionslocalfunctionspace.hh:58
size_type size() const
get current size
Definition: dunefunctionslocalfunctionspace.hh:91
GFS GridFunctionSpace
Definition: dunefunctionslocalfunctionspace.hh:67
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
LocalFunctionSpace(std::shared_ptr< const GFS > gfs)
Definition: dunefunctionslocalfunctionspace.hh:181
Definition: dunefunctionslocalfunctionspace.hh:48
DOFIndex dofIndex(size_type index) const
Definition: dunefunctionslocalfunctionspace.hh:108
typename Basis::LocalIndexSet LocalIndexSet
Definition: dunefunctionslocalfunctionspace.hh:57
TypeTree::ChildForTreePath< typename LocalView::Tree, TypeTree::HybridTreePath<> > Tree
Definition: dunefunctionslocalfunctionspace.hh:56
typename GFS::Traits::ConstraintsType ConstraintsType
Definition: dunefunctionslocalfunctionspace.hh:71
void bind(const typename GFS::Traits::EntitySet::template Codim< 0 >::Entity &e)
Definition: dunefunctionslocalfunctionspace.hh:119
Definition: lfsindexcache.hh:244
size_type localIndex(size_type index) const
map index in this local function space to root local function space
Definition: dunefunctionslocalfunctionspace.hh:103
const Traits::ConstraintsType & constraints() const
Definition: dunefunctionslocalfunctionspace.hh:125
Definition: dunefunctionslocalfunctionspace.hh:40
Create a local function space from a global function space.
Definition: localfunctionspace.hh:698
LocalFunctionSpace(const GFS &gfs)
Definition: dunefunctionslocalfunctionspace.hh:185
std::size_t index
Definition: interpolate.hh:118
size_type subSpaceDepth() const
Definition: dunefunctionslocalfunctionspace.hh:85
Definition: dunefunctionslocalfunctionspace.hh:63
Definition: dunefunctionslocalfunctionspace.hh:30