dune-functions 2.9.0
lagrangedgbasis.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_LAGRANGEDGBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
5
6#include <array>
7#include <dune/common/exceptions.hh>
8#include <dune/common/math.hh>
9
13
14
15
16
17namespace Dune {
18namespace Functions {
19
20
21
22// *****************************************************************************
23// This is the reusable part of the basis. It contains
24//
25// LagrangeDGPreBasis
26// LagrangeDGNode
27//
28// The pre-basis allows to create the others and is the owner of possible shared
29// state. These components do _not_ depend on the global basis and local view
30// and can be used without a global basis.
31// *****************************************************************************
32
33template<typename GV, int k>
35
36template<typename GV, int k>
38{
39 static const int dim = GV::dimension;
40
41public:
42
44 using GridView = GV;
45 using size_type = std::size_t;
46
47
48 // Precompute the number of dofs per entity type
49 const static int dofsPerEdge = k+1;
50 const static int dofsPerTriangle = (k+1)*(k+2)/2;
51 const static int dofsPerQuad = (k+1)*(k+1);
52 const static int dofsPerTetrahedron = (k+1)*(k+2)*(k+3)/6;
53 const static int dofsPerPrism = (k+1)*(k+1)*(k+2)/2;
54 const static int dofsPerHexahedron = (k+1)*(k+1)*(k+1);
55 const static int dofsPerPyramid = (k+1)*(k+2)*(2*k+3)/6;
56
57
59
60 static constexpr size_type maxMultiIndexSize = 1;
61 static constexpr size_type minMultiIndexSize = 1;
62 static constexpr size_type multiIndexBufferSize = 1;
63
66 gridView_(gv)
67 {}
68
69
71 {
72 switch (dim)
73 {
74 case 1:
75 {
76 break;
77 }
78 case 2:
79 {
80 quadrilateralOffset_ = dofsPerTriangle * gridView_.size(Dune::GeometryTypes::triangle);
81 break;
82 }
83 case 3:
84 {
85 prismOffset_ = dofsPerTetrahedron * gridView_.size(Dune::GeometryTypes::tetrahedron);
86
87 hexahedronOffset_ = prismOffset_ + dofsPerPrism * gridView_.size(Dune::GeometryTypes::prism);
88
89 pyramidOffset_ = hexahedronOffset_ + dofsPerHexahedron * gridView_.size(Dune::GeometryTypes::hexahedron);
90 break;
91 }
92 }
93 }
94
97 const GridView& gridView() const
98 {
99 return gridView_;
100 }
101
102 void update(const GridView& gv)
103 {
104 gridView_ = gv;
105 }
106
111 {
112 return Node{};
113 }
114
116 {
117 switch (dim)
118 {
119 case 1:
120 return dofsPerEdge*gridView_.size(0);
121 case 2:
122 {
123 return dofsPerTriangle*gridView_.size(Dune::GeometryTypes::triangle) + dofsPerQuad*gridView_.size(Dune::GeometryTypes::quadrilateral);
124 }
125 case 3:
126 {
127 return dofsPerTetrahedron*gridView_.size(Dune::GeometryTypes::tetrahedron)
128 + dofsPerPyramid*gridView_.size(Dune::GeometryTypes::pyramid)
129 + dofsPerPrism*gridView_.size(Dune::GeometryTypes::prism)
130 + dofsPerHexahedron*gridView_.size(Dune::GeometryTypes::hexahedron);
131 }
132 }
133 DUNE_THROW(Dune::NotImplemented, "No size method for " << dim << "d grids available yet!");
134 }
135
137 template<class SizePrefix>
138 size_type size(const SizePrefix& prefix) const
139 {
140 assert(prefix.size() == 0 || prefix.size() == 1);
141 return (prefix.size() == 0) ? size() : 0;
142 }
143
146 {
147 return size();
148 }
149
151 {
152 return Dune::power(k+1, int(GV::dimension));
153 }
154
155 template<typename It>
156 It indices(const Node& node, It it) const
157 {
158 const auto& gridIndexSet = gridView().indexSet();
159 const auto& element = node.element();
160
161 size_type offset = 0;
162 if constexpr (dim==1)
163 offset = dofsPerEdge*gridIndexSet.subIndex(element,0,0);
164 else if constexpr (dim==2)
165 {
166 if (element.type().isTriangle())
167 offset = dofsPerTriangle*gridIndexSet.subIndex(element,0,0);
168 else if (element.type().isQuadrilateral())
169 offset = quadrilateralOffset_ + dofsPerQuad*gridIndexSet.subIndex(element,0,0);
170 else
171 DUNE_THROW(Dune::NotImplemented, "2d elements have to be triangles or quadrilaterals");
172 }
173 else if constexpr (dim==3)
174 {
175 if (element.type().isTetrahedron())
176 offset = dofsPerTetrahedron*gridIndexSet.subIndex(element,0,0);
177 else if (element.type().isPrism())
178 offset = prismOffset_ + dofsPerPrism*gridIndexSet.subIndex(element,0,0);
179 else if (element.type().isHexahedron())
180 offset = hexahedronOffset_ + dofsPerHexahedron*gridIndexSet.subIndex(element,0,0);
181 else if (element.type().isPyramid())
182 offset = pyramidOffset_ + dofsPerPyramid*gridIndexSet.subIndex(element,0,0);
183 else
184 DUNE_THROW(Dune::NotImplemented, "3d elements have to be tetrahedrons, prisms, hexahedrons or pyramids");
185 }
186 else
187 DUNE_THROW(Dune::NotImplemented, "No index method for " << dim << "d grids available yet!");
188 for (size_type i = 0, end = node.size() ; i < end ; ++i, ++it)
189 *it = {offset + i};
190 return it;
191 }
192
194 unsigned int order() const
195 {
196 return k;
197 }
198
199protected:
201
206};
207
208
209
210namespace BasisFactory {
211
219template<std::size_t k>
221{
222 return [](const auto& gridView) {
223 return LagrangeDGPreBasis<std::decay_t<decltype(gridView)>, k>(gridView);
224 };
225}
226
227} // end namespace BasisFactory
228
229
230
231// *****************************************************************************
232// This is the actual global basis implementation based on the reusable parts.
233// *****************************************************************************
234
242template<typename GV, int k>
244
245
246
247} // end namespace Functions
248} // end namespace Dune
249
250
251#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
auto power(ChildPreBasisFactory &&childPreBasisFactory, const IndexMergingStrategy &)
Create a pre-basis factory that can build a PowerPreBasis.
Definition: powerbasis.hh:369
auto lagrangeDG()
Create a pre-basis factory that can create a LagrangeDG pre-basis.
Definition: lagrangedgbasis.hh:220
Definition: polynomial.hh:10
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
Definition: lagrangebasis.hh:387
const Element & element() const
Return current element, throw if unbound.
Definition: lagrangebasis.hh:439
Definition: lagrangedgbasis.hh:38
size_type size() const
Definition: lagrangedgbasis.hh:115
It indices(const Node &node, It it) const
Definition: lagrangedgbasis.hh:156
size_type maxNodeSize() const
Definition: lagrangedgbasis.hh:150
static constexpr size_type multiIndexBufferSize
Definition: lagrangedgbasis.hh:62
unsigned int order() const
Polynomial order used in the local Lagrange finite-elements.
Definition: lagrangedgbasis.hh:194
void update(const GridView &gv)
Definition: lagrangedgbasis.hh:102
size_t hexahedronOffset_
Definition: lagrangedgbasis.hh:205
Node makeNode() const
Create tree node.
Definition: lagrangedgbasis.hh:110
static constexpr size_type maxMultiIndexSize
Definition: lagrangedgbasis.hh:60
static const int dofsPerHexahedron
Definition: lagrangedgbasis.hh:54
LagrangeDGPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: lagrangedgbasis.hh:65
size_t pyramidOffset_
Definition: lagrangedgbasis.hh:203
static const int dofsPerTetrahedron
Definition: lagrangedgbasis.hh:52
size_type size(const SizePrefix &prefix) const
Return number possible values for next position in multi index.
Definition: lagrangedgbasis.hh:138
GV GridView
The grid view that the FE space is defined on.
Definition: lagrangedgbasis.hh:44
void initializeIndices()
Definition: lagrangedgbasis.hh:70
size_t quadrilateralOffset_
Definition: lagrangedgbasis.hh:202
static const int dofsPerEdge
Definition: lagrangedgbasis.hh:49
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: lagrangedgbasis.hh:97
static const int dofsPerQuad
Definition: lagrangedgbasis.hh:51
static const int dofsPerTriangle
Definition: lagrangedgbasis.hh:50
static const int dofsPerPyramid
Definition: lagrangedgbasis.hh:55
GridView gridView_
Definition: lagrangedgbasis.hh:200
static constexpr size_type minMultiIndexSize
Definition: lagrangedgbasis.hh:61
std::size_t size_type
Definition: lagrangedgbasis.hh:45
size_type dimension() const
Definition: lagrangedgbasis.hh:145
size_t prismOffset_
Definition: lagrangedgbasis.hh:204
static const int dofsPerPrism
Definition: lagrangedgbasis.hh:53
size_type size() const
Definition: nodes.hh:142