DUNE PDELab (git)

lagrangedgbasis.hh
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_LAGRANGEDGBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
5
6#include <array>
8#include <dune/common/math.hh>
9
10#include <dune/functions/functionspacebases/nodes.hh>
11#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
12#include <dune/functions/functionspacebases/lagrangebasis.hh>
13#include <dune/functions/functionspacebases/leafprebasismixin.hh>
14
15
16
17
18namespace Dune {
19namespace Functions {
20
21
22
23// *****************************************************************************
24// This is the reusable part of the basis. It contains
25//
26// LagrangeDGPreBasis
27// LagrangeDGNode
28//
29// The pre-basis allows to create the others and is the owner of possible shared
30// state. These components do _not_ depend on the global basis and local view
31// and can be used without a global basis.
32// *****************************************************************************
33
34template<typename GV, int k>
35using LagrangeDGNode = LagrangeNode<GV, k>;
36
37template<typename GV, int k>
38class LagrangeDGPreBasis :
39 public LeafPreBasisMixin< LagrangeDGPreBasis<GV,k> >
40{
41 static const int dim = GV::dimension;
42
43public:
44
46 using GridView = GV;
47 using size_type = std::size_t;
48
49
50 // Precompute the number of dofs per entity type
51 const static int dofsPerEdge = k+1;
52 const static int dofsPerTriangle = (k+1)*(k+2)/2;
53 const static int dofsPerQuad = (k+1)*(k+1);
54 const static int dofsPerTetrahedron = (k+1)*(k+2)*(k+3)/6;
55 const static int dofsPerPrism = (k+1)*(k+1)*(k+2)/2;
56 const static int dofsPerHexahedron = (k+1)*(k+1)*(k+1);
57 const static int dofsPerPyramid = (k+1)*(k+2)*(2*k+3)/6;
58
59
60 using Node = LagrangeDGNode<GV, k>;
61
63 LagrangeDGPreBasis(const GridView& gv) :
64 gridView_(gv)
65 {}
66
67
68 void initializeIndices()
69 {
70 switch (dim)
71 {
72 case 1:
73 {
74 break;
75 }
76 case 2:
77 {
78 quadrilateralOffset_ = dofsPerTriangle * gridView_.size(Dune::GeometryTypes::triangle);
79 break;
80 }
81 case 3:
82 {
83 prismOffset_ = dofsPerTetrahedron * gridView_.size(Dune::GeometryTypes::tetrahedron);
84
85 hexahedronOffset_ = prismOffset_ + dofsPerPrism * gridView_.size(Dune::GeometryTypes::prism);
86
87 pyramidOffset_ = hexahedronOffset_ + dofsPerHexahedron * gridView_.size(Dune::GeometryTypes::hexahedron);
88 break;
89 }
90 }
91 }
92
95 const GridView& gridView() const
96 {
97 return gridView_;
98 }
99
100 void update(const GridView& gv)
101 {
102 gridView_ = gv;
103 }
104
108 Node makeNode() const
109 {
110 return Node{};
111 }
112
113 size_type dimension() const
114 {
115 switch (dim)
116 {
117 case 1:
118 return dofsPerEdge*gridView_.size(0);
119 case 2:
120 {
121 return dofsPerTriangle*gridView_.size(Dune::GeometryTypes::triangle) + dofsPerQuad*gridView_.size(Dune::GeometryTypes::quadrilateral);
122 }
123 case 3:
124 {
125 return dofsPerTetrahedron*gridView_.size(Dune::GeometryTypes::tetrahedron)
126 + dofsPerPyramid*gridView_.size(Dune::GeometryTypes::pyramid)
127 + dofsPerPrism*gridView_.size(Dune::GeometryTypes::prism)
128 + dofsPerHexahedron*gridView_.size(Dune::GeometryTypes::hexahedron);
129 }
130 }
131 DUNE_THROW(Dune::NotImplemented, "No size method for " << dim << "d grids available yet!");
132 }
133
134 size_type maxNodeSize() const
135 {
136 return Dune::power(k+1, int(GV::dimension));
137 }
138
139 template<typename It>
140 It indices(const Node& node, It it) const
141 {
142 const auto& gridIndexSet = gridView().indexSet();
143 const auto& element = node.element();
144
145 size_type offset = 0;
146 if constexpr (dim==1)
147 offset = dofsPerEdge*gridIndexSet.subIndex(element,0,0);
148 else if constexpr (dim==2)
149 {
150 if (element.type().isTriangle())
151 offset = dofsPerTriangle*gridIndexSet.subIndex(element,0,0);
152 else if (element.type().isQuadrilateral())
153 offset = quadrilateralOffset_ + dofsPerQuad*gridIndexSet.subIndex(element,0,0);
154 else
155 DUNE_THROW(Dune::NotImplemented, "2d elements have to be triangles or quadrilaterals");
156 }
157 else if constexpr (dim==3)
158 {
159 if (element.type().isTetrahedron())
160 offset = dofsPerTetrahedron*gridIndexSet.subIndex(element,0,0);
161 else if (element.type().isPrism())
162 offset = prismOffset_ + dofsPerPrism*gridIndexSet.subIndex(element,0,0);
163 else if (element.type().isHexahedron())
164 offset = hexahedronOffset_ + dofsPerHexahedron*gridIndexSet.subIndex(element,0,0);
165 else if (element.type().isPyramid())
166 offset = pyramidOffset_ + dofsPerPyramid*gridIndexSet.subIndex(element,0,0);
167 else
168 DUNE_THROW(Dune::NotImplemented, "3d elements have to be tetrahedrons, prisms, hexahedrons or pyramids");
169 }
170 else
171 DUNE_THROW(Dune::NotImplemented, "No index method for " << dim << "d grids available yet!");
172 for (size_type i = 0, end = node.size() ; i < end ; ++i, ++it)
173 *it = {offset + i};
174 return it;
175 }
176
178 unsigned int order() const
179 {
180 return k;
181 }
182
183protected:
184 GridView gridView_;
185
186 size_t quadrilateralOffset_;
187 size_t pyramidOffset_;
188 size_t prismOffset_;
189 size_t hexahedronOffset_;
190};
191
192
193
194namespace BasisFactory {
195
203template<std::size_t k>
205{
206 return [](const auto& gridView) {
207 return LagrangeDGPreBasis<std::decay_t<decltype(gridView)>, k>(gridView);
208 };
209}
210
211} // end namespace BasisFactory
212
213
214
215// *****************************************************************************
216// This is the actual global basis implementation based on the reusable parts.
217// *****************************************************************************
218
226template<typename GV, int k>
228
229
230
231} // end namespace Functions
232} // end namespace Dune
233
234
235#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
Default exception for dummy implementations.
Definition: exceptions.hh:263
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto lagrangeDG()
Create a pre-basis factory that can create a LagrangeDG pre-basis.
Definition: lagrangedgbasis.hh:204
constexpr GeometryType prism
GeometryType representing a 3D prism.
Definition: type.hh:528
constexpr GeometryType triangle
GeometryType representing a triangle.
Definition: type.hh:504
constexpr GeometryType quadrilateral
GeometryType representing a quadrilateral (a square).
Definition: type.hh:510
constexpr GeometryType hexahedron
GeometryType representing a hexahedron.
Definition: type.hh:534
constexpr GeometryType pyramid
GeometryType representing a 3D pyramid.
Definition: type.hh:522
constexpr GeometryType tetrahedron
GeometryType representing a tetrahedron.
Definition: type.hh:516
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)