dune-pdelab  2.7-git
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 #include <dune/common/shared_ptr.hh>
10 
11 #include <dune/geometry/referenceelements.hh>
12 
13 #include <dune/localfunctions/common/interfaceswitch.hh>
14 #include <dune/localfunctions/common/localkey.hh>
15 
16 #include <dune/typetree/typetree.hh>
17 
20 
21 namespace Dune {
22  namespace PDELab {
23 
27 
28  namespace Experimental {
29 
30  template<typename LFS>
31  struct LeafLFSMixin
32  : public TypeTree::LeafNode
33  {
34 
35  const auto& finiteElement() const
36  {
37  return static_cast<const LFS*>(this)->tree().finiteElement();
38  }
39 
40  template<typename Tree>
41  struct Traits
42  {
43  using FiniteElement = typename Tree::FiniteElement;
45  };
46  };
47 
48  template<typename GFS, typename TreePath = TypeTree::HybridTreePath<>>
50  : public LeafLFSMixin<LocalFunctionSpace<GFS,TreePath>>
51  {
52 
53  public:
54 
55  using Basis = typename GFS::Basis;
56  using LocalView = typename Basis::LocalView;
57  using Tree = TypeTree::ChildForTreePath<typename LocalView::Tree,TreePath>;
58  using DOFIndex = typename GFS::Ordering::Traits::DOFIndex;
59 
60  template<typename LFS, typename C, typename Tag, bool fast>
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 GFS::Ordering::Traits::DOFIndex;
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().localView())
80  , _tree_path(tree_path)
81  , _tree(TypeTree::child(_local_view.tree(),tree_path))
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 
107  // index: local dof index for the given element
109  {
110  auto refElement = Dune::ReferenceElements<double,Basis::GridView::dimension>::general(_local_view.element().type());
111 
112  auto localKey = _local_view.tree().finiteElement().localCoefficients().localKey(index);
113 
114  const auto& indexSet = _gfs->basis().gridView().indexSet();
115 
116  // get geometry type of subentity
117  auto gt = refElement.type(localKey.subEntity(), localKey.codim());
118 
119  // evaluate consecutive index of subentity
120  auto indexOnEntity = indexSet.subIndex(_local_view.element(),
121  localKey.subEntity(),
122  localKey.codim());
123 
124 
125  DOFIndex result;
126  GFS::Ordering::Traits::DOFIndexAccessor::store(result,gt,indexOnEntity,localKey.index());
127  return result;
128  }
129 
130  // index: local dof index for the given element
132  {
134  result.set({_local_view.index(_tree.localIndex(index))});
135  return result;
136  }
137 
139  const GFS& gridFunctionSpace() const
140  {
141  return *_gfs;
142  }
143 
144  void bind(const typename GFS::Traits::EntitySet::template Codim<0>::Entity& e)
145  {
146  _local_view.bind(e);
147  }
148 
149  const typename Traits::ConstraintsType& constraints() const
150  {
151  return _gfs->constraints();
152  }
153 
154  const Tree& tree() const
155  {
156  return _tree;
157  }
158 
159  private:
160 
161  typename GFS::Ordering::Traits::ContainerIndex containerIndex(const DOFIndex& i) const
162  {
163  return _gfs->ordering().containerIndex(i);
164  }
165 
166  std::shared_ptr<const GFS> _gfs;
167  LocalView _local_view;
168  TreePath _tree_path;
169  const Tree& _tree;
170 
171  };
172 
173  // forward declare GridFunctionSpace
174  template<typename DFBasis, typename V, typename CE=NoConstraints>
175  class GridFunctionSpace;
176 
177 
178  } // namespace Experimental
179 
180 
181  template<typename DFBasis, typename V, typename CE, typename TAG>
182  class LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>,TAG>
183  : public Experimental::LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>>
184  {
185 
187 
188  public:
189 
190  LocalFunctionSpace(std::shared_ptr<const GFS> gfs)
191  : Experimental::LocalFunctionSpace<GFS>(gfs)
192  {}
193 
195  : Experimental::LocalFunctionSpace<GFS>(stackobject_to_shared_ptr(gfs))
196  {}
197 
198  };
199 
200  template<typename DFBasis, typename V, typename CE>
201  class LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>,AnySpaceTag>
202  : public Experimental::LocalFunctionSpace<Experimental::GridFunctionSpace<DFBasis,V,CE>>
203  {
204 
206 
207  public:
208 
209  LocalFunctionSpace(std::shared_ptr<const GFS> gfs)
210  : Experimental::LocalFunctionSpace<GFS>(gfs)
211  {}
212 
214  : Experimental::LocalFunctionSpace<GFS>(stackobject_to_shared_ptr(gfs))
215  {}
216 
217  };
218 
220  } // namespace PDELab
221 } // namespace Dune
222 
223 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLOCALFUNCTIONSPACE_HH
Dune::PDELab::Experimental::LocalFunctionSpace::dofIndex
DOFIndex dofIndex(size_type index) const
Definition: dunefunctionslocalfunctionspace.hh:108
index
std::size_t index
Definition: interpolate.hh:97
Dune::PDELab::Experimental::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE > >::LocalView
typename Basis::LocalView LocalView
Definition: dunefunctionslocalfunctionspace.hh:56
Dune::PDELab::Experimental::LeafLFSMixin::finiteElement
const auto & finiteElement() const
Definition: dunefunctionslocalfunctionspace.hh:35
Dune::PDELab::Experimental::LocalFunctionSpace::Tree
TypeTree::ChildForTreePath< typename LocalView::Tree, TreePath > Tree
Definition: dunefunctionslocalfunctionspace.hh:57
Dune::PDELab::MultiIndex::set
void set(typename ReservedVector< T, n >::value_type index)
Definition: multiindex.hh:152
Dune::PDELab::Experimental::GridFunctionSpace< DFBasis, V, CE >
offset
const std::size_t offset
Definition: localfunctionspace.hh:75
Dune::PDELab::Experimental::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE > >::size_type
std::size_t size_type
Definition: dunefunctionslocalfunctionspace.hh:75
Dune::PDELab::LocalFunctionSpace
Create a local function space from a global function space.
Definition: localfunctionspace.hh:699
Dune::PDELab::Experimental::LocalFunctionSpace::Traits::GridFunctionSpace
GFS GridFunctionSpace
Definition: dunefunctionslocalfunctionspace.hh:67
Dune::PDELab::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE >, AnySpaceTag >::LocalFunctionSpace
LocalFunctionSpace(const GFS &gfs)
Definition: dunefunctionslocalfunctionspace.hh:213
Dune::PDELab::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE >, AnySpaceTag >::LocalFunctionSpace
LocalFunctionSpace(std::shared_ptr< const GFS > gfs)
Definition: dunefunctionslocalfunctionspace.hh:209
Dune::PDELab::Experimental::LocalFunctionSpace
Definition: dunefunctionslocalfunctionspace.hh:49
Dune::PDELab::LFSIndexCacheBase
Definition: lfsindexcache.hh:244
Dune::PDELab::Experimental::LocalFunctionSpace::maxSize
size_type maxSize() const
Definition: dunefunctionslocalfunctionspace.hh:95
Dune::PDELab::AnySpaceTag
Definition: localfunctionspacetags.hh:40
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE >, TAG >::LocalFunctionSpace
LocalFunctionSpace(std::shared_ptr< const GFS > gfs)
Definition: dunefunctionslocalfunctionspace.hh:190
Dune::PDELab::Experimental::LocalFunctionSpace::localIndex
size_type localIndex(size_type index) const
map index in this local function space to root local function space
Definition: dunefunctionslocalfunctionspace.hh:102
tags.hh
e
const Entity & e
Definition: localfunctionspace.hh:121
Dune::PDELab::DOFIndex
A multi-index representing a degree of freedom in a GridFunctionSpace.
Definition: dofindex.hh:147
Dune::PDELab::Experimental::LocalFunctionSpace::gridFunctionSpace
const GFS & gridFunctionSpace() const
Returns the GridFunctionSpace underlying this LocalFunctionSpace.
Definition: dunefunctionslocalfunctionspace.hh:139
Dune::PDELab::Experimental::LocalFunctionSpace::Traits::GridView
typename GFS::Traits::GridView GridView
Definition: dunefunctionslocalfunctionspace.hh:68
Dune::PDELab::Experimental::LocalFunctionSpace::LocalFunctionSpace
LocalFunctionSpace(std::shared_ptr< const GFS > gfs, TreePath tree_path=TreePath(), size_type offset=0)
Definition: dunefunctionslocalfunctionspace.hh:77
Dune::PDELab::Experimental::LocalFunctionSpace::Traits::ConstraintsType
typename GFS::Traits::ConstraintsType ConstraintsType
Definition: dunefunctionslocalfunctionspace.hh:71
Dune::PDELab::Experimental::LocalFunctionSpace::Traits::SizeType
std::size_t SizeType
Definition: dunefunctionslocalfunctionspace.hh:69
Dune::PDELab::GridFunctionSpace
A grid function space.
Definition: gridfunctionspace.hh:178
Dune::PDELab::Experimental::LeafLFSMixin::Traits::FiniteElementType
FiniteElement FiniteElementType
Definition: dunefunctionslocalfunctionspace.hh:44
Dune::PDELab::Experimental::LocalFunctionSpace::subSpaceDepth
size_type subSpaceDepth() const
Definition: dunefunctionslocalfunctionspace.hh:84
Dune::PDELab::Experimental::LocalFunctionSpace::tree
const Tree & tree() const
Definition: dunefunctionslocalfunctionspace.hh:154
Dune::PDELab::Experimental::LocalFunctionSpace::Traits
Definition: dunefunctionslocalfunctionspace.hh:63
Dune::PDELab::Experimental::LocalFunctionSpace::constraints
const Traits::ConstraintsType & constraints() const
Definition: dunefunctionslocalfunctionspace.hh:149
Dune::PDELab::Experimental::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE > >::Basis
typename Experimental::GridFunctionSpace< DFBasis, V, CE > ::Basis Basis
Definition: dunefunctionslocalfunctionspace.hh:55
localvector.hh
Dune::PDELab::Experimental::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE > >::DOFIndex
typename Experimental::GridFunctionSpace< DFBasis, V, CE > ::Ordering::Traits::DOFIndex DOFIndex
Definition: dunefunctionslocalfunctionspace.hh:58
Dune::PDELab::Experimental::LocalFunctionSpace::containerIndex
auto containerIndex(size_type index) const
Definition: dunefunctionslocalfunctionspace.hh:131
Dune::PDELab::Experimental::LeafLFSMixin::Traits
Definition: dunefunctionslocalfunctionspace.hh:41
Dune::PDELab::Experimental::LocalFunctionSpace::Traits::DOFIndex
typename GFS::Ordering::Traits::DOFIndex DOFIndex
Definition: dunefunctionslocalfunctionspace.hh:70
Dune::PDELab::Experimental::LeafLFSMixin::Traits::FiniteElement
typename Tree::FiniteElement FiniteElement
Definition: dunefunctionslocalfunctionspace.hh:43
Dune::PDELab::MultiIndex
A class for representing multi-indices.
Definition: multiindex.hh:27
Dune::PDELab::Experimental::LeafLFSMixin
Definition: dunefunctionslocalfunctionspace.hh:31
Dune::PDELab::Experimental::LocalFunctionSpace::bind
void bind(const typename GFS::Traits::EntitySet::template Codim< 0 >::Entity &e)
Definition: dunefunctionslocalfunctionspace.hh:144
Dune::PDELab::LocalFunctionSpace< Experimental::GridFunctionSpace< DFBasis, V, CE >, TAG >::LocalFunctionSpace
LocalFunctionSpace(const GFS &gfs)
Definition: dunefunctionslocalfunctionspace.hh:194
Dune::PDELab::Experimental::LocalFunctionSpace::size
size_type size() const
get current size
Definition: dunefunctionslocalfunctionspace.hh:90