dune-functions  2.6-dev
rannacherturekbasis.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_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
5 
6 #include <dune/common/exceptions.hh>
7 
8 #include <dune/localfunctions/rannacherturek.hh>
9 
10 #include <dune/typetree/leafnode.hh>
11 
15 
16 
17 namespace Dune {
18 namespace Functions {
19 
20 // *****************************************************************************
21 // This is the reusable part of the basis. It contains
22 //
23 // RannacherTurekPreBasis
24 // RannacherTurekNodeIndexSet
25 // RannacherTurekNode
26 //
27 // The pre-basis allows to create the others and is the owner of possible shared
28 // state. These three components do _not_ depend on the global basis or index
29 // set and can be used without a global basis.
30 // *****************************************************************************
31 
32 template<typename GV, typename TP>
34 
35 template<typename GV, class MI, class TP>
37 
38 template<typename GV, class MI>
40 
54 template<typename GV, class MI>
56 {
57  static const int dim = GV::dimension;
58 
59 public:
60 
62  using GridView = GV;
63 
65  using size_type = std::size_t;
66 
68  template<class TP>
70 
72  template<class TP>
74 
76  using MultiIndex = MI;
77 
79  using SizePrefix = Dune::ReservedVector<size_type, 1>;
80 
83  gridView_(gv)
84  {}
85 
88  {}
89 
91  const GridView& gridView() const
92  {
93  return gridView_;
94  }
95 
97  void update (const GridView& gv)
98  {
99  gridView_ = gv;
100  }
101 
112  template<class TP>
113  Node<TP> node(const TP& tp) const
114  {
115  return Node<TP>{tp};
116  }
117 
127  template<class TP>
129  {
130  return IndexSet<TP>{*this};
131  }
132 
134  size_type size() const
135  {
136  return (size_type)(gridView_.size(1));
137  }
138 
140  size_type size(const SizePrefix prefix) const
141  {
142  assert(prefix.size() == 0 || prefix.size() == 1);
143  return (prefix.size() == 0) ? size() : 0;
144  }
145 
148  {
149  return size();
150  }
151 
154  {
155  return 2*GV::dimension;
156  }
157 
158 protected:
160 };
161 
162 
163 
164 template<typename GV, typename TP>
165 class RannacherTurekNode :
166  public LeafBasisNode<std::size_t, TP>
167 {
168  static const int dim = GV::dimension;
169  static const int maxSize = 2*dim;
170 
171  using Base = LeafBasisNode<std::size_t,TP>;
172 
173 public:
174 
175  using size_type = std::size_t;
176  using TreePath = TP;
177  using Element = typename GV::template Codim<0>::Entity;
178  using FiniteElement = RannacherTurekLocalFiniteElement<typename GV::ctype, double, dim>;
179 
180  RannacherTurekNode(const TreePath& treePath) :
181  Base(treePath),
182  finiteElement_(),
183  element_(nullptr)
184  {}
185 
187  const Element& element() const
188  {
189  return *element_;
190  }
191 
197  {
198  return finiteElement_;
199  }
200 
202  void bind(const Element& e)
203  {
204  element_ = &e;
205 #ifndef NDEBUG
206  if (e.type() != finiteElement_.type())
207  DUNE_THROW(Dune::Exception,
208  "Rannacher-Turek elements do not exist for elements of type " << e.type());
209 #endif
210  this->setSize(finiteElement_.size());
211  }
212 
213 protected:
214 
217 };
218 
219 
220 
221 template<typename GV, class MI, class TP>
223 {
224  enum {dim = GV::dimension};
225 
226 public:
227 
228  using size_type = std::size_t;
229 
231  using MultiIndex = MI;
232 
234 
235  using Node = typename PreBasis::template Node<TP>;
236 
238  preBasis_(&preBasis)
239  {}
240 
246  void bind(const Node& node)
247  {
248  node_ = &node;
249  }
250 
253  void unbind()
254  {
255  node_ = nullptr;
256  }
257 
260  size_type size() const
261  {
262  return (size_type)(node_->finiteElement().size());
263  }
264 
266  template<typename It>
267  It indices(It it) const
268  {
269  for (size_type i = 0, end = size() ; i < end ; ++i, ++it)
270  {
271  Dune::LocalKey localKey = node_->finiteElement().localCoefficients().localKey(i);
272  const auto& gridIndexSet = preBasis_->gridView().indexSet();
273  const auto& element = node_->element();
274 
275  *it = {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),1)) }};
276  }
277  return it;
278  }
279 
280 protected:
282 
283  const Node* node_;
284 };
285 
286 
287 
288 namespace BasisBuilder {
289 
290 namespace Imp {
291 
292 template<class Dummy=void>
293 class RannacherTurekPreBasisFactory
294 {
295 public:
296  static const std::size_t requiredMultiIndexSize = 1;
297 
298  template<class MultiIndex, class GridView>
299  auto makePreBasis(const GridView& gridView) const
300  {
302  }
303 
304 };
305 
306 } // end namespace BasisBuilder::Imp
307 
308 
309 
315 template<class Dummy=void>
317 {
318  return Imp::RannacherTurekPreBasisFactory<void>();
319 }
320 
321 } // end namespace BasisBuilder
322 
323 
324 
325 
326 
338 template<typename GV>
340 
341 } // end namespace Functions
342 } // end namespace Dune
343 
344 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PQ1NODALBASIS_HH
typename GV::template Codim< 0 >::Entity Element
Definition: rannacherturekbasis.hh:177
Node< TP > node(const TP &tp) const
Create tree node with given root tree path.
Definition: rannacherturekbasis.hh:113
TP TreePath
Definition: nodes.hh:126
Definition: rannacherturekbasis.hh:33
std::size_t size_type
Definition: nodes.hh:127
size_type size() const
Same as size(prefix) with empty prefix.
Definition: rannacherturekbasis.hh:134
Pre-basis for a Rannacher-Turek basis.
Definition: rannacherturekbasis.hh:39
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: rannacherturekbasis.hh:91
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: rannacherturekbasis.hh:231
const Node * node_
Definition: rannacherturekbasis.hh:283
const FiniteElement finiteElement_
Definition: rannacherturekbasis.hh:215
IndexSet< TP > indexSet() const
Create tree node index set with given root tree path.
Definition: rannacherturekbasis.hh:128
Dune::ReservedVector< size_type, 1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: rannacherturekbasis.hh:79
RannacherTurekLocalFiniteElement< typename GV::ctype, double, dim > FiniteElement
Definition: rannacherturekbasis.hh:178
std::size_t size_type
Definition: rannacherturekbasis.hh:228
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: rannacherturekbasis.hh:76
void bind(const Node &node)
Bind the view to a grid element.
Definition: rannacherturekbasis.hh:246
Definition: rannacherturekbasis.hh:36
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:42
Definition: nodes.hh:189
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: rannacherturekbasis.hh:147
RannacherTurekPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: rannacherturekbasis.hh:82
const PreBasis * preBasis_
Definition: rannacherturekbasis.hh:281
std::size_t size_type
Type used for indices and size information.
Definition: rannacherturekbasis.hh:65
auto rannacherTurek()
Create a pre-basis factory that can create a Rannacher-Turek pre-basis.
Definition: rannacherturekbasis.hh:316
const Element & element() const
Return current element, throw if unbound.
Definition: rannacherturekbasis.hh:187
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: rannacherturekbasis.hh:153
It indices(It it) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis...
Definition: rannacherturekbasis.hh:267
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition: rannacherturekbasis.hh:196
Definition: polynomial.hh:7
GridView gridView_
Definition: rannacherturekbasis.hh:159
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: rannacherturekbasis.hh:140
RannacherTurekNode(const TreePath &treePath)
Definition: rannacherturekbasis.hh:180
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: rannacherturekbasis.hh:97
size_type size() const
Size of subtree rooted in this node (element-local)
Definition: rannacherturekbasis.hh:260
GV GridView
The grid view that the FE basis is defined on.
Definition: rannacherturekbasis.hh:62
void bind(const Element &e)
Bind to element.
Definition: rannacherturekbasis.hh:202
typename PreBasis::template Node< TP > Node
Definition: rannacherturekbasis.hh:235
void initializeIndices()
Initialize the global indices.
Definition: rannacherturekbasis.hh:87
RannacherTurekNodeIndexSet(const PreBasis &preBasis)
Definition: rannacherturekbasis.hh:237
const Element * element_
Definition: rannacherturekbasis.hh:216
void unbind()
Unbind the view.
Definition: rannacherturekbasis.hh:253