DUNE PDELab (git)

rannacherturekbasis.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_RANNACHERTUREKBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
9
11
13
14#include <dune/localfunctions/common/localfiniteelementvariant.hh>
16#include <dune/localfunctions/crouzeixraviart.hh>
17
18#include <dune/functions/functionspacebases/nodes.hh>
19#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
20#include <dune/functions/functionspacebases/leafprebasismixin.hh>
21
22
23namespace Dune {
24namespace Functions {
25
26// *****************************************************************************
27// This is the reusable part of the basis. It contains
28//
29// RannacherTurekPreBasis
30// RannacherTurekNode
31//
32// The pre-basis allows to create the others and is the owner of possible shared
33// state. These components do _not_ depend on the global basis and local view
34// and can be used without a global basis.
35// *****************************************************************************
36
37template<typename GV>
38class RannacherTurekNode;
39
40template<typename GV>
41class RannacherTurekPreBasis;
42
55template<typename GV>
57 public LeafPreBasisMixin< RannacherTurekPreBasis<GV> >
58{
59 static const int dim = GV::dimension;
60
61public:
62
64 using GridView = GV;
65
67 using size_type = std::size_t;
68
70 using Node = RannacherTurekNode<GV>;
71
74 gridView_(gv)
75 {
76 for(auto type : gv.indexSet().types(0))
77 if (!type.isSimplex() && !type.isCube())
78 DUNE_THROW(Dune::NotImplemented, "Rannacher-Turek or Crouzeix-Raviart elements are only implemented for grids with simplex or cube elements.");
79 }
80
83 {}
84
86 const GridView& gridView() const
87 {
88 return gridView_;
89 }
90
92 void update (const GridView& gv)
93 {
94 gridView_ = gv;
95 }
96
101 {
102 return Node{};
103 }
104
107 {
108 return (size_type)(gridView_.size(1));
109 }
110
113 {
114 return 2*GV::dimension;
115 }
116
117 template<typename It>
118 It indices(const Node& node, It it) const
119 {
120 for (size_type i = 0, end = node.size() ; i < end ; ++i, ++it)
121 {
122 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
123 const auto& gridIndexSet = gridView().indexSet();
124 const auto& element = node.element();
125
126 *it = {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),1)) }};
127 }
128 return it;
129 }
130
131protected:
132 GridView gridView_;
133};
134
135
136
137template<typename GV>
138class RannacherTurekNode :
139 public LeafBasisNode
140{
141 static const int dim = GV::dimension;
142 static const int maxSize = 2*dim;
143
144 constexpr static bool hasFixedElementType = Capabilities::hasSingleGeometryType<typename GV::Grid>::v;
145
146 using CubeFiniteElement = RannacherTurekLocalFiniteElement<typename GV::ctype,double,dim>;
147 using SimplexFiniteElement = CrouzeixRaviartLocalFiniteElement<typename GV::ctype,double,dim>;
148
149 constexpr static unsigned int topologyId = Capabilities::hasSingleGeometryType<typename GV::Grid>::topologyId; // meaningless if hasFixedElementType is false
150 constexpr static GeometryType type = GeometryType(topologyId, GV::dimension);
151
152public:
153
154 using size_type = std::size_t;
155 using Element = typename GV::template Codim<0>::Entity;
156 using FiniteElement = std::conditional_t<hasFixedElementType,
157 std::conditional_t<type.isCube(),CubeFiniteElement,SimplexFiniteElement>,
158 LocalFiniteElementVariant<CubeFiniteElement, SimplexFiniteElement> >;
159
160 RannacherTurekNode() :
161 finiteElement_(),
162 element_(nullptr)
163 {}
164
166 const Element& element() const
167 {
168 return *element_;
169 }
170
175 const FiniteElement& finiteElement() const
176 {
177 return finiteElement_;
178 }
179
181 void bind(const Element& e)
182 {
183 element_ = &e;
184 if constexpr (!hasFixedElementType)
185 finiteElement_ = e.type().isCube() ? static_cast<FiniteElement>(CubeFiniteElement())
186 : static_cast<FiniteElement>(SimplexFiniteElement()) ;
187 this->setSize(finiteElement_.size());
188 }
189
190protected:
191
192 FiniteElement finiteElement_;
193 const Element* element_;
194};
195
196
197
198namespace BasisFactory {
199
205template<class Dummy=void>
207{
208 return [](const auto& gridView) {
209 return RannacherTurekPreBasis<std::decay_t<decltype(gridView)>>(gridView);
210 };
211}
212
213} // end namespace BasisFactory
214
215
216
217
229template<typename GV>
231
232} // end namespace Functions
233} // end namespace Dune
234
235#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:50
A generic MixIn class for PreBasis.
Definition: leafprebasismixin.hh:36
Pre-basis for a Rannacher-Turek basis.
Definition: rannacherturekbasis.hh:58
void initializeIndices()
Initialize the global indices.
Definition: rannacherturekbasis.hh:82
std::size_t size_type
Type used for indices and size information.
Definition: rannacherturekbasis.hh:67
Node makeNode() const
Create tree node.
Definition: rannacherturekbasis.hh:100
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: rannacherturekbasis.hh:92
GV GridView
The grid view that the FE basis is defined on.
Definition: rannacherturekbasis.hh:64
size_type dimension() const
Same as size(prefix) with empty prefix.
Definition: rannacherturekbasis.hh:106
RannacherTurekPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: rannacherturekbasis.hh:73
RannacherTurekNode< GV > Node
Template mapping root tree path to type of created tree node.
Definition: rannacherturekbasis.hh:70
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: rannacherturekbasis.hh:86
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: rannacherturekbasis.hh:112
Describe position of one degree of freedom.
Definition: localkey.hh:24
constexpr unsigned int subEntity() const noexcept
Return number of associated subentity.
Definition: localkey.hh:56
Default exception for dummy implementations.
Definition: exceptions.hh:263
A set of traits classes to store static information about grid implementation.
A few common exception classes.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto rannacherTurek()
Create a pre-basis factory that can create a Rannacher-Turek pre-basis.
Definition: rannacherturekbasis.hh:206
Dune namespace.
Definition: alignedallocator.hh:13
Convenience header that includes all available Rannacher-Turek LocalFiniteElements.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)