3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PQKNODALBASIS_HH 4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PQKNODALBASIS_HH 7 #include <dune/common/exceptions.hh> 9 #include <dune/localfunctions/lagrange/pqkfactory.hh> 11 #include <dune/typetree/leafnode.hh> 35 template<
typename GV,
int k,
typename TP>
38 template<
typename GV,
int k,
class MI,
class TP>
41 template<
typename GV,
int k,
class MI>
58 template<
typename GV,
int k,
class MI>
61 static const int dim = GV::dimension;
73 template<
typename,
int,
class,
class>
78 k == 0 ? (dim == 0 ? 1 : 0) : 1;
80 k == 0 ? (dim == 1 ? 1 : 0) : k-1;
82 k == 0 ? (dim == 2 ? 1 : 0) : (k-1)*(k-2)/2;
84 k == 0 ? (dim == 2 ? 1 : 0) : (k-1)*(k-1);
85 const static size_type dofsPerTetrahedron =
86 k == 0 ? (dim == 3 ? 1 : 0) : (k-3)*(k-2)*(k-1)/6;
88 k == 0 ? (dim == 3 ? 1 : 0) : (k-1)*(k-1)*(k-2)/2;
89 const static size_type dofsPerHexahedron =
90 k == 0 ? (dim == 3 ? 1 : 0) : (k-1)*(k-1)*(k-1);
92 k == 0 ? (dim == 3 ? 1 : 0) : (k-2)*(k-1)*(2*k-3)/6;
205 DUNE_THROW(Dune::NotImplemented,
"No size method for " << dim <<
"d grids available yet!");
211 assert(prefix.size() == 0 || prefix.size() == 1);
212 return (prefix.size() == 0) ?
size() : 0;
243 template<
typename GV,
int k,
typename TP>
247 static const int dim = GV::dimension;
251 using FiniteElementCache =
typename Dune::PQkLocalFiniteElementCache<typename GV::ctype, double, dim, k>;
257 using Element =
typename GV::template Codim<0>::Entity;
262 finiteElement_(nullptr),
278 return *finiteElement_;
285 finiteElement_ = &(cache_.get(element_->type()));
286 this->setSize(finiteElement_->size());
298 template<
typename GV,
int k,
class MI,
class TP>
301 enum {dim = GV::dimension};
315 preBasis_(&preBasis),
340 assert(node_ !=
nullptr);
341 return node_->finiteElement().size();
345 template<
typename It>
348 assert(node_ !=
nullptr);
349 for (
size_type i = 0, end = node_->finiteElement().size() ; i < end ; ++it, ++i)
351 Dune::LocalKey localKey = node_->finiteElement().localCoefficients().localKey(i);
352 const auto& gridIndexSet = preBasis_->gridView().indexSet();
353 const auto& element = node_->element();
356 auto dofDim = dim - localKey.codim();
359 *it = {{ (
size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),dim)) }};
367 *it = {{ preBasis_->edgeOffset_
368 + preBasis_->dofsPerEdge * ((
size_type)gridIndexSet.subIndex(element,0,0))
369 + localKey.index() }};
374 const auto refElement
375 = Dune::referenceElement<double,dim>(element.type());
379 auto v0 = (
size_type)gridIndexSet.subIndex(element,refElement.subEntity(localKey.subEntity(),localKey.codim(),0,dim),dim);
380 auto v1 = (
size_type)gridIndexSet.subIndex(element,refElement.subEntity(localKey.subEntity(),localKey.codim(),1,dim),dim);
381 bool flip = (v0 > v1);
383 ? preBasis_->edgeOffset_
384 + preBasis_->dofsPerEdge*((
size_type)gridIndexSet.subIndex(element,localKey.subEntity(),localKey.codim()))
385 + (preBasis_->dofsPerEdge-1)-localKey.index()
386 : preBasis_->edgeOffset_
387 + preBasis_->dofsPerEdge*((
size_type)gridIndexSet.subIndex(element,localKey.subEntity(),localKey.codim()))
388 + localKey.index() }};
397 if (element.type().isTriangle())
399 const int interiorLagrangeNodesPerTriangle = (k-1)*(k-2)/2;
400 *it = {{ preBasis_->triangleOffset_ + interiorLagrangeNodesPerTriangle*((
size_type)gridIndexSet.subIndex(element,0,0)) + localKey.index() }};
403 else if (element.type().isQuadrilateral())
405 const int interiorLagrangeNodesPerQuadrilateral = (k-1)*(k-1);
406 *it = {{ preBasis_->quadrilateralOffset_ + interiorLagrangeNodesPerQuadrilateral*((
size_type)gridIndexSet.subIndex(element,0,0)) + localKey.index() }};
410 DUNE_THROW(Dune::NotImplemented,
"2d elements have to be triangles or quadrilaterals");
413 const auto refElement
414 = Dune::referenceElement<double,dim>(element.type());
417 DUNE_THROW(Dune::NotImplemented,
"PQkNodalBasis for 3D grids is only implemented if k<=3");
419 if (k==3 and !refElement.type(localKey.subEntity(), localKey.codim()).isTriangle())
420 DUNE_THROW(Dune::NotImplemented,
"PQkNodalBasis for 3D grids with k==3 is only implemented if the grid is a simplex grid");
422 *it = {{ preBasis_->triangleOffset_ + ((
size_type)gridIndexSet.subIndex(element,localKey.subEntity(),localKey.codim())) }};
431 if (element.type().isTetrahedron())
433 *it = {{ preBasis_->tetrahedronOffset_ + PreBasis::dofsPerTetrahedron*((
size_type)gridIndexSet.subIndex(element,0,0)) + localKey.index() }};
436 else if (element.type().isHexahedron())
438 *it = {{ preBasis_->hexahedronOffset_ + PreBasis::dofsPerHexahedron*((
size_type)gridIndexSet.subIndex(element,0,0)) + localKey.index() }};
441 else if (element.type().isPrism())
443 *it = {{ preBasis_->prismOffset_ + PreBasis::dofsPerPrism*((
size_type)gridIndexSet.subIndex(element,0,0)) + localKey.index() }};
446 else if (element.type().isPyramid())
448 *it = {{ preBasis_->pyramidOffset_ + PreBasis::dofsPerPyramid*((
size_type)gridIndexSet.subIndex(element,0,0)) + localKey.index() }};
452 DUNE_THROW(Dune::NotImplemented,
"3d elements have to be tetrahedra, hexahedra, prisms, or pyramids");
454 DUNE_THROW(Dune::NotImplemented,
"Grids of dimension larger than 3 are no supported");
456 DUNE_THROW(Dune::NotImplemented,
"Grid contains elements not supported for the PQkNodalBasis");
469 namespace BasisBuilder {
473 template<std::
size_t k>
474 class PQkPreBasisFactory
477 static const std::size_t requiredMultiIndexSize = 1;
479 template<
class MultiIndex,
class Gr
idView>
498 template<std::
size_t k>
501 return Imp::PQkPreBasisFactory<k>();
527 template<
typename GV,
int k>
536 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_PQKNODALBASIS_HH Dune::ReservedVector< size_type, 1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: pqknodalbasis.hh:108
const Element & element() const
Return current element, throw if unbound.
Definition: pqknodalbasis.hh:267
const FiniteElement * finiteElement_
Definition: pqknodalbasis.hh:292
TP TreePath
Definition: nodes.hh:126
IndexSet< TP > indexSet() const
Create tree node index set with given root tree path.
Definition: pqknodalbasis.hh:173
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition: pqknodalbasis.hh:276
Definition: pqknodalbasis.hh:39
std::size_t size_type
Definition: nodes.hh:127
GridView gridView_
Definition: pqknodalbasis.hh:228
size_type vertexOffset_
Definition: pqknodalbasis.hh:230
PQkNodeIndexSet(const PreBasis &preBasis)
Definition: pqknodalbasis.hh:314
size_type triangleOffset_
Definition: pqknodalbasis.hh:232
auto pq()
Create a pre-basis factory that can create a PQ_k pre-basis.
Definition: pqknodalbasis.hh:499
It indices(It it) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis...
Definition: pqknodalbasis.hh:346
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: pqknodalbasis.hh:308
typename FiniteElementCache::FiniteElementType FiniteElement
Definition: pqknodalbasis.hh:258
Definition: pqknodalbasis.hh:36
size_type size() const
Size of subtree rooted in this node (element-local)
Definition: pqknodalbasis.hh:338
typename GV::template Codim< 0 >::Entity Element
Definition: pqknodalbasis.hh:257
FiniteElementCache cache_
Definition: pqknodalbasis.hh:291
const PreBasis * preBasis_
Definition: pqknodalbasis.hh:462
void bind(const Node &node)
Bind the view to a grid element.
Definition: pqknodalbasis.hh:324
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:42
size_type hexahedronOffset_
Definition: pqknodalbasis.hh:237
void initializeIndices()
Initialize the global indices.
Definition: pqknodalbasis.hh:116
std::size_t size_type
Definition: pqknodalbasis.hh:305
size_type size() const
Same as size(prefix) with empty prefix.
Definition: pqknodalbasis.hh:179
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: pqknodalbasis.hh:136
size_type prismOffset_
Definition: pqknodalbasis.hh:236
auto power(ChildPreBasisFactory &&childPreBasisFactory, const IndexMergingStrategy &ims)
Create a pre-basis factory that can build a PowerPreBasis.
Definition: powerbasis.hh:493
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: pqknodalbasis.hh:209
size_type pyramidOffset_
Definition: pqknodalbasis.hh:235
PQMultiIndex MultiIndex
Type used for global numbering of the basis vectors.
Definition: pqknodalbasis.hh:105
const Node * node_
Definition: pqknodalbasis.hh:464
PQkNode(const TreePath &treePath)
Definition: pqknodalbasis.hh:260
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: pqknodalbasis.hh:216
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: pqknodalbasis.hh:142
std::size_t size_type
Type used for indices and size information.
Definition: pqknodalbasis.hh:69
size_type tetrahedronOffset_
Definition: pqknodalbasis.hh:234
size_type edgeOffset_
Definition: pqknodalbasis.hh:231
Definition: polynomial.hh:7
PQkPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: pqknodalbasis.hh:111
A pre-basis for PQ-lagrange bases with given order.
Definition: pqknodalbasis.hh:42
typename PreBasis::template Node< TP > Node
Definition: pqknodalbasis.hh:312
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: pqknodalbasis.hh:222
const Element * element_
Definition: pqknodalbasis.hh:293
Node< TP > node(const TP &tp) const
Create tree node with given root tree path.
Definition: pqknodalbasis.hh:158
GV GridView
The grid view that the FE basis is defined on.
Definition: pqknodalbasis.hh:66
void bind(const Element &e)
Bind to element.
Definition: pqknodalbasis.hh:282
size_type quadrilateralOffset_
Definition: pqknodalbasis.hh:233
void unbind()
Unbind the view.
Definition: pqknodalbasis.hh:331