dune-functions 2.10
Loading...
Searching...
No Matches
refinedlagrangebasis.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
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
9
10#include <type_traits>
11
12#include <dune/common/exceptions.hh>
13#include <dune/common/math.hh>
14
15#include <dune/localfunctions/refined.hh>
16
20
21#include <dune/geometry/type.hh>
22
23#include <dune/grid/common/mcmgmapper.hh>
24
25
26namespace Dune {
27namespace Functions {
28
29template<typename GV, int k, typename R>
30class RefinedLagrangeNode;
31
43template <typename GV, int k, typename R = double>
45 public LeafPreBasisMapperMixin< GV >
46{
48
49 static const int dim = GV::dimension;
50
51 // refined basis only implemented for P0 and P1
52 static_assert(k == 0 || k == 1);
53
54 // the layout is defined in terms of a MCMGLayout specialized for k == 0 or 1
55 static MCMGLayout dofLayout()
56 {
57 if constexpr(k == 0)
58 // a refined P0 basis assigns each element 2^dim DOFs
59 return [](GeometryType gt, int) -> size_t {
60 return (gt.dim() == dim) ? (1 << dim) : 0;
61 };
62 else if constexpr(k == 1)
63 // a refined P1 basis has the same layout as a P2 basis
64 return [](GeometryType gt, int) -> size_t {
65 return Dune::binomial(int(k),int(gt.dim()));
66 };
67 else
68 DUNE_THROW(Dune::NotImplemented,
69 "Refined basis not implemented for higher-order Lagrange (k>=2) elements.");
70 }
71
72public:
73
75 using GridView = GV;
76
79
87 : Base(gv, dofLayout())
88 {
89 for (auto gt : gv.indexSet().types(0)) {
90 if (!gt.isSimplex())
91 DUNE_THROW(Dune::NotImplemented,
92 "Refined Lagrange basis only implemented for simplex grids.");
93 }
94 }
95
97 Node makeNode () const
98 {
99 return Node{};
100 }
101
109 static constexpr unsigned int order()
110 {
111 return k;
112 }
113};
114
115
116
117template <typename GV, int k, typename R>
119 : public LeafBasisNode
120{
121 static constexpr int dim = GV::dimension;
122
123 // refined basis only implemented for P0 and P1
124 static_assert(k == 0 || k == 1);
125
126public:
128 using Element = typename GV::template Codim<0>::Entity;
129
131 using FiniteElement = std::conditional_t<(k==0),
132 Dune::RefinedP0LocalFiniteElement<typename GV::ctype,R,dim>,
133 Dune::RefinedP1LocalFiniteElement<typename GV::ctype,R,dim>>;
134
146 , element_(nullptr)
147 {}
148
153 const Element& element () const
154 {
155 return *element_;
156 }
157
165 {
166 return finiteElement_;
167 }
168
170 void bind (const Element& e)
171 {
172 element_ = &e;
173 this->setSize(finiteElement_.size());
174 }
175
180 static constexpr unsigned int order()
181 {
182 return k;
183 }
184
185protected:
188};
189
190
191
192namespace BasisFactory {
193
201template <int k, typename R=double>
203{
204 return [](const auto& gridView) {
205 return RefinedLagrangePreBasis<std::decay_t<decltype(gridView)>, k, R>(gridView);
206 };
207}
208
209} // end namespace BasisFactory
210
211
225template <typename GV, int k, typename R=double>
227
228} // end namespace Functions
229} // end namespace Dune
230
231
232#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
auto refinedLagrange()
Create a pre-basis factory that can create a RefinedLagrange pre-basis.
Definition refinedlagrangebasis.hh:202
Definition polynomial.hh:17
Global basis for given pre-basis.
Definition defaultglobalbasis.hh:50
A generic MixIn class for PreBasis with flat indices computed from a mapper.
Definition leafprebasismappermixin.hh:62
void setSize(const size_type size)
Definition nodes.hh:169
Definition nodes.hh:191
Definition refinedlagrangebasis.hh:120
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition refinedlagrangebasis.hh:164
const Element * element_
Definition refinedlagrangebasis.hh:187
void bind(const Element &e)
Bind the node to the element e.
Definition refinedlagrangebasis.hh:170
const FiniteElement finiteElement_
Definition refinedlagrangebasis.hh:186
static constexpr unsigned int order()
Polynomial order used in the local Lagrange finite-elements in subdomains of the element.
Definition refinedlagrangebasis.hh:180
typename GV::template Codim< 0 >::Entity Element
Type of the element in the GridView.
Definition refinedlagrangebasis.hh:128
std::conditional_t<(k==0), Dune::RefinedP0LocalFiniteElement< typename GV::ctype, R, dim >, Dune::RefinedP1LocalFiniteElement< typename GV::ctype, R, dim > > FiniteElement
Type of the local finite-element.
Definition refinedlagrangebasis.hh:133
RefinedLagrangeNode()
The default constructor initializes all members to their default.
Definition refinedlagrangebasis.hh:144
const Element & element() const
Return current element. The behavior is undefined if the node is not bound to any element.
Definition refinedlagrangebasis.hh:153
A pre-basis for a refined Lagrange bases.
Definition refinedlagrangebasis.hh:46
static constexpr unsigned int order()
Polynomial order used in the local Lagrange finite-elements.
Definition refinedlagrangebasis.hh:109
Node makeNode() const
Create tree node.
Definition refinedlagrangebasis.hh:97
GV GridView
The grid view that the FE basis is defined on.
Definition refinedlagrangebasis.hh:75
RefinedLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition refinedlagrangebasis.hh:86