dune-functions  2.7.1
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>
33 class RannacherTurekNode;
34 
35 template<typename GV, class MI>
36 class RannacherTurekNodeIndexSet;
37 
38 template<typename GV, class MI>
39 class RannacherTurekPreBasis;
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 
69 
72 
74  using MultiIndex = MI;
75 
77  using SizePrefix = Dune::ReservedVector<size_type, 1>;
78 
81  gridView_(gv)
82  {}
83 
86  {}
87 
89  const GridView& gridView() const
90  {
91  return gridView_;
92  }
93 
95  void update (const GridView& gv)
96  {
97  gridView_ = gv;
98  }
99 
103  Node makeNode() const
104  {
105  return Node{};
106  }
107 
115  {
116  return IndexSet{*this};
117  }
118 
120  size_type size() const
121  {
122  return (size_type)(gridView_.size(1));
123  }
124 
126  size_type size(const SizePrefix prefix) const
127  {
128  assert(prefix.size() == 0 || prefix.size() == 1);
129  return (prefix.size() == 0) ? size() : 0;
130  }
131 
134  {
135  return size();
136  }
137 
140  {
141  return 2*GV::dimension;
142  }
143 
144 protected:
146 };
147 
148 
149 
150 template<typename GV>
152  public LeafBasisNode
153 {
154  static const int dim = GV::dimension;
155  static const int maxSize = 2*dim;
156 
157 public:
158 
159  using size_type = std::size_t;
160  using Element = typename GV::template Codim<0>::Entity;
161  using FiniteElement = RannacherTurekLocalFiniteElement<typename GV::ctype, double, dim>;
162 
164  finiteElement_(),
165  element_(nullptr)
166  {}
167 
169  const Element& element() const
170  {
171  return *element_;
172  }
173 
179  {
180  return finiteElement_;
181  }
182 
184  void bind(const Element& e)
185  {
186  element_ = &e;
187 #ifndef NDEBUG
188  if (e.type() != finiteElement_.type())
189  DUNE_THROW(Dune::Exception,
190  "Rannacher-Turek elements do not exist for elements of type " << e.type());
191 #endif
192  this->setSize(finiteElement_.size());
193  }
194 
195 protected:
196 
199 };
200 
201 
202 
203 template<typename GV, class MI>
205 {
206  enum {dim = GV::dimension};
207 
208 public:
209 
210  using size_type = std::size_t;
211 
213  using MultiIndex = MI;
214 
216 
218 
220  preBasis_(&preBasis)
221  {}
222 
228  void bind(const Node& node)
229  {
230  node_ = &node;
231  }
232 
235  void unbind()
236  {
237  node_ = nullptr;
238  }
239 
242  size_type size() const
243  {
244  return (size_type)(node_->finiteElement().size());
245  }
246 
248  template<typename It>
249  It indices(It it) const
250  {
251  for (size_type i = 0, end = size() ; i < end ; ++i, ++it)
252  {
253  Dune::LocalKey localKey = node_->finiteElement().localCoefficients().localKey(i);
254  const auto& gridIndexSet = preBasis_->gridView().indexSet();
255  const auto& element = node_->element();
256 
257  *it = {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),1)) }};
258  }
259  return it;
260  }
261 
262 protected:
264 
265  const Node* node_;
266 };
267 
268 
269 
270 namespace BasisFactory {
271 
272 namespace Imp {
273 
274 template<class Dummy=void>
275 class RannacherTurekPreBasisFactory
276 {
277 public:
278  static const std::size_t requiredMultiIndexSize = 1;
279 
280  template<class MultiIndex, class GridView>
281  auto makePreBasis(const GridView& gridView) const
282  {
284  }
285 
286 };
287 
288 } // end namespace BasisFactory::Imp
289 
290 
291 
297 template<class Dummy=void>
299 {
300  return Imp::RannacherTurekPreBasisFactory<void>();
301 }
302 
303 } // end namespace BasisFactory
304 
305 
306 
307 
319 template<typename GV>
321 
322 } // end namespace Functions
323 } // end namespace Dune
324 
325 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
auto rannacherTurek()
Create a pre-basis factory that can create a Rannacher-Turek pre-basis.
Definition: rannacherturekbasis.hh:298
Definition: polynomial.hh:10
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:47
std::size_t size_type
Definition: nodes.hh:125
void setSize(const size_type size)
Definition: nodes.hh:160
Definition: nodes.hh:182
Definition: rannacherturekbasis.hh:153
void bind(const Element &e)
Bind to element.
Definition: rannacherturekbasis.hh:184
RannacherTurekLocalFiniteElement< typename GV::ctype, double, dim > FiniteElement
Definition: rannacherturekbasis.hh:161
const Element & element() const
Return current element, throw if unbound.
Definition: rannacherturekbasis.hh:169
const FiniteElement finiteElement_
Definition: rannacherturekbasis.hh:197
typename GV::template Codim< 0 >::Entity Element
Definition: rannacherturekbasis.hh:160
RannacherTurekNode()
Definition: rannacherturekbasis.hh:163
const Element * element_
Definition: rannacherturekbasis.hh:198
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition: rannacherturekbasis.hh:178
Definition: rannacherturekbasis.hh:205
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:249
const PreBasis * preBasis_
Definition: rannacherturekbasis.hh:263
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: rannacherturekbasis.hh:213
size_type size() const
Size of subtree rooted in this node (element-local)
Definition: rannacherturekbasis.hh:242
std::size_t size_type
Definition: rannacherturekbasis.hh:210
void bind(const Node &node)
Bind the view to a grid element.
Definition: rannacherturekbasis.hh:228
const Node * node_
Definition: rannacherturekbasis.hh:265
void unbind()
Unbind the view.
Definition: rannacherturekbasis.hh:235
RannacherTurekNodeIndexSet(const PreBasis &preBasis)
Definition: rannacherturekbasis.hh:219
Pre-basis for a Rannacher-Turek basis.
Definition: rannacherturekbasis.hh:56
Dune::ReservedVector< size_type, 1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: rannacherturekbasis.hh:77
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: rannacherturekbasis.hh:139
IndexSet makeIndexSet() const
Create tree node index set.
Definition: rannacherturekbasis.hh:114
std::size_t size_type
Type used for indices and size information.
Definition: rannacherturekbasis.hh:65
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: rannacherturekbasis.hh:89
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: rannacherturekbasis.hh:133
GV GridView
The grid view that the FE basis is defined on.
Definition: rannacherturekbasis.hh:62
size_type size() const
Same as size(prefix) with empty prefix.
Definition: rannacherturekbasis.hh:120
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: rannacherturekbasis.hh:74
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: rannacherturekbasis.hh:126
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: rannacherturekbasis.hh:95
Node makeNode() const
Create tree node.
Definition: rannacherturekbasis.hh:103
GridView gridView_
Definition: rannacherturekbasis.hh:145
void initializeIndices()
Initialize the global indices.
Definition: rannacherturekbasis.hh:85
RannacherTurekPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: rannacherturekbasis.hh:80