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>
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 SizeType = std::size_t;
69  using DOFIndex = typename Basis::MultiIndex;
70  using ConstraintsType = typename GFS::Traits::ConstraintsType;
71 
72  };
73 
74  using size_type = std::size_t;
75 
76  LocalFunctionSpace(std::shared_ptr<const GFS> gfs, TreePath tree_path = TreePath(), size_type offset = 0)
77  : _gfs(gfs)
78  , _local_view(gfs->basis())
79  , _tree_path(tree_path)
80  , _tree(TypeTree::child(_local_view.tree(),tree_path))
81  , _local_index_set(gfs->basis().localIndexSet())
82  {}
83 
85  {
86  return 0;
87  }
88 
90  size_type size () const
91  {
92  return _local_view.size();
93  }
94 
95  size_type maxSize () const
96  {
97  // _dof_indices is always as large as the max local size of the root GFS
98  return _local_view.maxSize();
99  }
100 
103  {
104  return _tree.localIndex(index);
105  }
106 
108  {
109  return _local_index_set.index(_tree.localIndex(index));
110  }
111 
113  const GFS& gridFunctionSpace() const
114  {
115  return *_gfs;
116  }
117 
118  void bind(const typename GFS::Traits::EntitySet::template Codim<0>::Entity& e)
119  {
120  _local_view.bind(e);
121  _local_index_set.bind(_local_view);
122  }
123 
124  const typename Traits::ConstraintsType& constraints() const
125  {
126  return _gfs->constraints();
127  }
128 
129  const Tree& tree() const
130  {
131  return _tree;
132  }
133 
134  private:
135 
136  std::shared_ptr<const GFS> _gfs;
137  LocalView _local_view;
138  TreePath _tree_path;
139  const Tree& _tree;
140  LocalIndexSet _local_index_set;
141 
142  };
143 
144  // forward declare GridFunctionSpace
145  template<typename DFBasis, typename V, typename CE=NoConstraints>
146  class GridFunctionSpace;
147 
148 
149  } // namespace Experimental
150 
151 
152  template<typename DFBasis, typename V, typename CE, typename TAG>
153  class LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>,TAG>
154  : public Experimental::LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>>
155  {
156 
158 
159  public:
160 
161  LocalFunctionSpace(std::shared_ptr<const GFS> gfs)
162  : Experimental::LocalFunctionSpace<GFS>(gfs)
163  {}
164 
165  LocalFunctionSpace(const GFS& gfs)
166  : Experimental::LocalFunctionSpace<GFS>(stackobject_to_shared_ptr(gfs))
167  {}
168 
169  };
170 
171  template<typename DFBasis, typename V, typename CE>
172  class LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>,AnySpaceTag>
173  : public Experimental::LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>>
174  {
175 
177 
178  public:
179 
180  LocalFunctionSpace(std::shared_ptr<const GFS> gfs)
181  : Experimental::LocalFunctionSpace<GFS>(gfs)
182  {}
183 
184  LocalFunctionSpace(const GFS& gfs)
185  : Experimental::LocalFunctionSpace<GFS>(stackobject_to_shared_ptr(gfs))
186  {}
187 
188  };
189 
191  } // namespace PDELab
192 } // namespace Dune
193 
194 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLOCALFUNCTIONSPACE_HH
FiniteElement FiniteElementType
Definition: dunefunctionslocalfunctionspace.hh:43
size_type localIndex(size_type index) const
map index in this local function space to root local function space
Definition: dunefunctionslocalfunctionspace.hh:102
DOFIndex dofIndex(size_type index) const
Definition: dunefunctionslocalfunctionspace.hh:107
Definition: dunefunctionslocalfunctionspace.hh:63
typename Basis::MultiIndex DOFIndex
Definition: dunefunctionslocalfunctionspace.hh:58
A pdelab grid function space implemented by a dune-functions function space basis.
Definition: dunefunctionsgridfunctionspace.hh:37
LocalFunctionSpace(std::shared_ptr< const GFS > gfs)
Definition: dunefunctionslocalfunctionspace.hh:180
A grid function space.
Definition: gridfunctionspace.hh:169
std::size_t SizeType
Definition: dunefunctionslocalfunctionspace.hh:68
LocalFunctionSpace(const GFS &gfs)
Definition: dunefunctionslocalfunctionspace.hh:165
Definition: lfsindexcache.hh:240
typename Basis::MultiIndex DOFIndex
Definition: dunefunctionslocalfunctionspace.hh:69
const Tree & tree() const
Definition: dunefunctionslocalfunctionspace.hh:129
size_type size() const
get current size
Definition: dunefunctionslocalfunctionspace.hh:90
typename Basis::LocalView LocalView
Definition: dunefunctionslocalfunctionspace.hh:55
TypeTree::ChildForTreePath< typename LocalView::Tree, TypeTree::HybridTreePath<> > Tree
Definition: dunefunctionslocalfunctionspace.hh:56
size_type maxSize() const
Definition: dunefunctionslocalfunctionspace.hh:95
const std::size_t offset
Definition: localfunctionspace.hh:74
Definition: dunefunctionslocalfunctionspace.hh:30
typename Experimental::GridFunctionSpace< DFBasis, V, CE > ::Basis Basis
Definition: dunefunctionslocalfunctionspace.hh:54
LocalFunctionSpace(std::shared_ptr< const GFS > gfs)
Definition: dunefunctionslocalfunctionspace.hh:161
Definition: dunefunctionslocalfunctionspace.hh:48
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
const Entity & e
Definition: localfunctionspace.hh:111
typename Tree::FiniteElement FiniteElement
Definition: dunefunctionslocalfunctionspace.hh:42
LocalFunctionSpace(std::shared_ptr< const GFS > gfs, TreePath tree_path=TreePath(), size_type offset=0)
Definition: dunefunctionslocalfunctionspace.hh:76
typename Basis::LocalIndexSet LocalIndexSet
Definition: dunefunctionslocalfunctionspace.hh:57
const auto & finiteElement() const
Definition: dunefunctionslocalfunctionspace.hh:34
LocalFunctionSpace(const GFS &gfs)
Definition: dunefunctionslocalfunctionspace.hh:184
Create a local function space from a global function space.
Definition: localfunctionspace.hh:670
const GFS & gridFunctionSpace() const
Returns the GridFunctionSpace underlying this LocalFunctionSpace.
Definition: dunefunctionslocalfunctionspace.hh:113
size_type subSpaceDepth() const
Definition: dunefunctionslocalfunctionspace.hh:84
typename GFS::Traits::ConstraintsType ConstraintsType
Definition: dunefunctionslocalfunctionspace.hh:70
GFS GridFunctionSpace
Definition: dunefunctionslocalfunctionspace.hh:67
void bind(const typename GFS::Traits::EntitySet::template Codim< 0 >::Entity &e)
Definition: dunefunctionslocalfunctionspace.hh:118
Definition: dunefunctionslocalfunctionspace.hh:40
Definition: localfunctionspacetags.hh:40
const Traits::ConstraintsType & constraints() const
Definition: dunefunctionslocalfunctionspace.hh:124