DUNE-FUNCTIONS (unstable)

refinedlagrangebasis.hh
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
17#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
18#include <dune/functions/functionspacebases/leafprebasismappermixin.hh>
19#include <dune/functions/functionspacebases/nodes.hh>
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
78 using Node = RefinedLagrangeNode<GV, k, R>;
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>
118class RefinedLagrangeNode
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
144 RefinedLagrangeNode ()
145 : finiteElement_{}
146 , element_(nullptr)
147 {}
148
153 const Element& element () const
154 {
155 return *element_;
156 }
157
164 const FiniteElement& finiteElement () const
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:
186 const FiniteElement finiteElement_;
187 const Element* element_;
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
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
GV GridView
Type of the associated GridView.
Definition: leafprebasismappermixin.hh:68
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
RefinedLagrangeNode< GV, k, R > Node
Type of the refined Lagrange tree node.
Definition: refinedlagrangebasis.hh:78
RefinedLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: refinedlagrangebasis.hh:86
auto refinedLagrange()
Create a pre-basis factory that can create a RefinedLagrange pre-basis.
Definition: refinedlagrangebasis.hh:202
Definition: polynomial.hh:17
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)