dune-functions  2.5-dev
pq1nodalbasis.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_PQ1NODALBASIS_HH
4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PQ1NODALBASIS_HH
5 
6 #include <array>
7 #include <dune/common/exceptions.hh>
8 
9 #include <dune/localfunctions/lagrange/pqkfactory.hh>
10 
11 #include <dune/typetree/leafnode.hh>
12 
16 
17 
18 namespace Dune {
19 namespace Functions {
20 
21 // *****************************************************************************
22 // This is the reusable part of the basis. It contains
23 //
24 // PQ1NodeFactory
25 // PQ1NodeIndexSet
26 // PQ1Node
27 //
28 // The factory allows to create the others and is the owner of possible shared
29 // state. These three components do _not_ depend on the global basis or index
30 // set and can be used without a global basis.
31 // *****************************************************************************
32 
33 template<typename GV, typename TP>
34 class PQ1Node;
35 
36 template<typename GV, class MI, class TP>
38 
39 template<typename GV, class MI>
41 
53 template<typename GV, class MI>
54 class PQ1NodeFactory
55 {
56  static const int dim = GV::dimension;
57 
58 public:
59 
61  using GridView = GV;
62 
64  using size_type = std::size_t;
65 
67  template<class TP>
69 
71  template<class TP>
73 
75  using MultiIndex = MI;
76 
78  using SizePrefix = Dune::ReservedVector<size_type, 2>;
79 
81  PQ1NodeFactory(const GridView& gv) :
82  gridView_(gv)
83  {}
84 
87  {}
88 
90  const GridView& gridView() const
91  {
92  return gridView_;
93  }
94 
96  void update (const GridView& gv)
97  {
98  gridView_ = gv;
99  }
100 
111  template<class TP>
112  Node<TP> node(const TP& tp) const
113  {
114  return Node<TP>{tp};
115  }
116 
126  template<class TP>
128  {
129  return IndexSet<TP>{*this};
130  }
131 
133  size_type size() const
134  {
135  return (size_type)(gridView_.size(dim));
136  }
137 
139  size_type size(const SizePrefix prefix) const
140  {
141  if (prefix.size() == 0)
142  return size();
143  if (prefix.size() == 1)
144  return 0;
145  DUNE_THROW(RangeError, "Method size() can only be called for prefixes of length up to one");
146  }
147 
150  {
151  return size();
152  }
153 
156  {
158  }
159 
160 protected:
162 };
163 
164 
165 
166 template<typename GV, typename TP>
167 class PQ1Node :
168  public LeafBasisNode<std::size_t, TP>
169 {
170  static const int dim = GV::dimension;
171  static const int maxSize = StaticPower<2,GV::dimension>::power;
172 
173  using Base = LeafBasisNode<std::size_t,TP>;
174  using FiniteElementCache = typename Dune::PQkLocalFiniteElementCache<typename GV::ctype, double, dim, 1>;
175 
176 public:
177 
178  using size_type = std::size_t;
179  using TreePath = TP;
180  using Element = typename GV::template Codim<0>::Entity;
181  using FiniteElement = typename FiniteElementCache::FiniteElementType;
182 
183  PQ1Node(const TreePath& treePath) :
184  Base(treePath),
185  finiteElement_(nullptr),
186  element_(nullptr)
187  {}
188 
190  const Element& element() const
191  {
192  return *element_;
193  }
194 
200  {
201  return *finiteElement_;
202  }
203 
205  void bind(const Element& e)
206  {
207  element_ = &e;
208  finiteElement_ = &(cache_.get(element_->type()));
209  this->setSize(finiteElement_->size());
210  }
211 
212 protected:
213 
214  FiniteElementCache cache_;
217 };
218 
219 
220 
221 template<typename GV, class MI, class TP>
222 class PQ1NodeIndexSet
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 NodeFactory::template Node<TP>;
236 
237  PQ1NodeIndexSet(const NodeFactory& nodeFactory) :
238  nodeFactory_(&nodeFactory)
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 
267  {
268  Dune::LocalKey localKey = node_->finiteElement().localCoefficients().localKey(i);
269  const auto& gridIndexSet = nodeFactory_->gridView().indexSet();
270  const auto& element = node_->element();
271 
272  return {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),dim)) }};
273  }
274 
275 protected:
277 
278  const Node* node_;
279 };
280 
281 
282 
292 template<typename GV>
294 
295 } // end namespace Functions
296 } // end namespace Dune
297 
298 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PQ1NODALBASIS_HH
Definition: pq1nodalbasis.hh:37
typename GV::template Codim< 0 >::Entity Element
Definition: pq1nodalbasis.hh:180
size_type size() const
Same as size(prefix) with empty prefix.
Definition: pq1nodalbasis.hh:133
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: pq1nodalbasis.hh:75
std::size_t size_type
Definition: nodes.hh:127
IndexSet< TP > indexSet() const
Create tree node index set with given root tree path.
Definition: pq1nodalbasis.hh:127
std::size_t size_type
Definition: pq1nodalbasis.hh:228
Node< TP > node(const TP &tp) const
Create tree node with given root tree path.
Definition: pq1nodalbasis.hh:112
GridView gridView_
Definition: pq1nodalbasis.hh:161
const Element * element_
Definition: pq1nodalbasis.hh:216
typename FiniteElementCache::FiniteElementType FiniteElement
Definition: pq1nodalbasis.hh:181
Dune::ReservedVector< size_type, 2 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: pq1nodalbasis.hh:78
Global basis for given node factory.
Definition: defaultglobalbasis.hh:42
std::size_t size_type
Type used for indices and size information.
Definition: pq1nodalbasis.hh:64
void initializeIndices()
Initialize the global indices.
Definition: pq1nodalbasis.hh:86
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: pq1nodalbasis.hh:231
void bind(const Element &e)
Bind to element.
Definition: pq1nodalbasis.hh:205
Definition: polynomial.hh:7
Definition: nodes.hh:189
PQ1Node(const TreePath &treePath)
Definition: pq1nodalbasis.hh:183
FiniteElementCache cache_
Definition: pq1nodalbasis.hh:214
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: pq1nodalbasis.hh:149
size_type size() const
Size of subtree rooted in this node (element-local)
Definition: pq1nodalbasis.hh:260
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: pq1nodalbasis.hh:96
Definition: pq1nodalbasis.hh:34
GV GridView
The grid view that the FE basis is defined on.
Definition: pq1nodalbasis.hh:61
typename NodeFactory::template Node< TP > Node
Definition: pq1nodalbasis.hh:235
const Element & element() const
Return current element, throw if unbound.
Definition: pq1nodalbasis.hh:190
const NodeFactory * nodeFactory_
Definition: pq1nodalbasis.hh:276
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: pq1nodalbasis.hh:139
MultiIndex index(size_type i) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis...
Definition: pq1nodalbasis.hh:266
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: pq1nodalbasis.hh:90
TP TreePath
Definition: nodes.hh:126
PQ1NodeFactory(const GridView &gv)
Constructor for a given grid view object.
Definition: pq1nodalbasis.hh:81
void unbind()
Unbind the view.
Definition: pq1nodalbasis.hh:253
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: pq1nodalbasis.hh:155
void bind(const Node &node)
Bind the view to a grid element.
Definition: pq1nodalbasis.hh:246
const Node * node_
Definition: pq1nodalbasis.hh:278
Imp::PowerNodeFactoryBuilder< k, IndexMergingStrategy, SubFactoryTag > power(SubFactoryTag &&tag, const IndexMergingStrategy &ims)
Create a factory builder that can build a PowerNodeFactory.
Definition: powerbasis.hh:424
const FiniteElement * finiteElement_
Definition: pq1nodalbasis.hh:215
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition: pq1nodalbasis.hh:199
Factory for a first order PQ-lagrange basis.
Definition: pq1nodalbasis.hh:40
PQ1NodeIndexSet(const NodeFactory &nodeFactory)
Definition: pq1nodalbasis.hh:237