dune-fem 2.12-git
Loading...
Searching...
No Matches
lagrange/shapefunctionset.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
2#define DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
3
4#include <cassert>
5#include <cstdlib>
6
9
10#include <dune/geometry/type.hh>
12
15
18
19#if __GNUC__ >= 13
20// save diagnostic state
21#pragma GCC diagnostic push
22// turn off the specific warning, caused by code in line 216 (false positive).
23#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
24#endif
25
26/*
27 @file
28 @brief Shape function set for Lagrange space
29 @author Christoph Gersbacher
30*/
31
32namespace Dune
33{
34
35 namespace Fem
36 {
37
38 // LagrangeShapeFunctionInterface
39 // ------------------------------
40
46 template< class FunctionSpace >
48 {
50
51 static_assert( (FunctionSpace::dimRange == 1), "FunctionSpace must be scalar." );
52
53 public:
55
60
62
63 virtual void evaluate ( const DomainType &x, RangeType &value ) const = 0;
64 virtual void jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const = 0;
65 virtual void hessian ( const DomainType &x, HessianRangeType &hessian ) const = 0;
66
67 virtual int order () const = 0;
68
69 virtual const ThisType *clone () const = 0;
70 };
71
72
73
74 // LagrangeShapeFunction
75 // ---------------------
76
85 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
87 : public LagrangeShapeFunctionInterface< FunctionSpace >
88 {
91
92 static const int dimension = FunctionSpace::dimDomain;
93
94 public:
97
102
103 explicit LagrangeShapeFunction ( const GenericBaseFunctionType &genericShapeFunction )
104 : genericShapeFunction_( genericShapeFunction )
105 {}
106
107 virtual void evaluate ( const DomainType &x, RangeType &value ) const;
108 virtual void jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const;
109 virtual void hessian ( const DomainType &x, HessianRangeType &hessian ) const;
110
111 virtual int order () const { return polOrder; }
112
113 virtual const BaseType *clone () const { return new ThisType( *this ); }
114
115 protected:
117 };
118
119
120
121 // LagrangeShapeFunctionFactory
122 // ----------------------------
123
131 template< class FunctionSpace, int maxPolOrder >
133 {
134 static const int dimension = FunctionSpace::dimDomain;
135
136 public:
138
139 private:
140 template< GeometryType::Id geometryId>
141 struct Switch;
142
143 public:
144 explicit LagrangeShapeFunctionFactory ( const Dune::GeometryType &type, const int order = maxPolOrder )
145 : gt_(type),
146 order_( order )
147 {}
148
149 int order () const;
150
152
154
155 private:
156 const Dune::GeometryType gt_;
157 const int order_;
158 };
159
160
161
162 // LagrangeShapeFunctionSet
163 // ------------------------
164
171 template< class FunctionSpace, int maxPolOrder >
173 : public SimpleShapeFunctionSet<
174 typename LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >::ShapeFunctionType
175 >
176 {
177 static_assert( (FunctionSpace::dimRange == 1), "FunctionSpace must be scalar." );
178
181
182 public:
183 LagrangeShapeFunctionSet ( const Dune::GeometryType &type, const int order = maxPolOrder )
185 {
186 }
187 };
188
189
190
191 // Implementation of LagrangeShapeFunction
192 // ---------------------------------------
193
194 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
195 inline void LagrangeShapeFunction< FunctionSpace, GeometryType, polOrder >
196 ::evaluate ( const DomainType &x, RangeType &value ) const
197 {
198 FieldVector< int, 0 > diffVariable;
199 genericShapeFunction_.evaluate( diffVariable, x, value );
200 }
201
202
203 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
205 ::jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const
206 {
207 FieldVector< int, 1 > diffVariable;
208 RangeType tmp;
209
210 int &i = diffVariable[ 0 ];
211 for( i = 0; i < dimension; ++i )
212 {
213 genericShapeFunction_.evaluate( diffVariable, x, tmp );
214 jacobian[ 0 ][ i ] = tmp[ 0 ];
215 }
216 }
217
218
219 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
221 ::hessian ( const DomainType &x, HessianRangeType &hessian ) const
222 {
223 FieldVector< int, 2 > diffVariable;
224 RangeType tmp;
225
226 int &i = diffVariable[ 0 ];
227 for( i = 0; i < dimension; ++i )
228 {
229 // we use symmetrized evaluation of the hessian, since calling
230 // evaluate is in general quite expensive
231 int &j = diffVariable[ 1 ];
232 for( j = 0; j < i; ++j )
233 {
234 genericShapeFunction_.evaluate( diffVariable, x, tmp );
235 hessian[ 0 ][ i ][ j ] = hessian[ 0 ][ j ][ i ] = tmp[ 0 ];
236 }
237
238 assert( j == i );
239 genericShapeFunction_.evaluate( diffVariable, x, tmp );
240 hessian[ 0 ][ i ][ i ] = tmp[ 0 ];
241 }
242 }
243
244
245
246 // LagrangeShapeFunctionFactory::Switch
247 // ------------------------------------
248
249 template< class FunctionSpace, int maxPolOrder >
250 template< GeometryType::Id geometryId>
251 struct LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >::Switch
252 {
253 // get generic geometry type
254 static constexpr GeometryType gt = geometryId;
255 static const unsigned int topologyId = gt.id();
257 ::ImplType ImplType;
258
259 template <int polOrd>
261 {
262 // type of scalar shape function for current polynomial order
265
266 static void apply ( const int order, std::size_t &size )
267 {
268 if( order == polOrd )
269 {
271 }
272 }
273
274 static void apply ( const std::size_t &i, const int order, ShapeFunctionType *&shapeFunction )
275 {
276 if( order == polOrd )
277 {
278 shapeFunction = new ShapeFunctionImpl( GenericBaseFunctionType( i ) );
279 }
280 }
281 };
282
283 static void apply ( const int order, std::size_t &size )
284 {
285 // loop over all possible polynomial order to find correct size
287 }
288
289 static void apply ( const std::size_t &i, const int order, ShapeFunctionType *&shapeFunction )
290 {
291 // loop over all possible polynomial order to create correct shape function
293 }
294 };
295
296
297
298 // Implementation of LagrangeShapeFunctionFactory
299 // ----------------------------------------------
300
301 template< class FunctionSpace, int maxPolOrder >
302 const int LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >::dimension;
303
304
305 template< class FunctionSpace, int maxPolOrder >
306 inline int LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >
307 ::order () const
308 {
309 return order_;
310 }
311
312
313 template< class FunctionSpace, int polOrder >
316 {
317 std::size_t numShapeFunctions( 0 );
318 Dune::Impl::toGeometryTypeIdConstant<dimension>(gt_, [&](auto geometryTypeId) {
319 Switch<decltype(geometryTypeId)::value>::apply(order_, numShapeFunctions);
320 });
321 return numShapeFunctions;
322 }
323
324
325 template< class FunctionSpace, int polOrder >
329 {
330 ShapeFunctionType *shapeFunction( nullptr );
331 Dune::Impl::toGeometryTypeIdConstant<dimension>(gt_, [&](auto geometryTypeId) {
332 Switch<decltype(geometryTypeId)::value>::apply(i, order_,shapeFunction);
333 });
334 assert( shapeFunction );
335 return shapeFunction;
336 }
337
338
339
340 // Extern Template Instantiations
341 // ------------------------------
342
349
356
363
364 } // namespace Fem
365
366} // namespace Dune
367
368#if __GNUC__ >= 13
369// turn the warnings back on
370#pragma GCC diagnostic pop
371#endif // #if defined(__GNUC__)
372
373#endif // #ifndef DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
int size() const
static Type apply(T &t)
Definition explicitfieldvector.hh:75
static DUNE_PRIVATE void apply(Args &&... args)
Definition forloop.hh:23
A vector valued function space.
Definition functionspace.hh:60
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition functionspaceinterface.hh:71
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition functionspaceinterface.hh:75
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition functionspaceinterface.hh:67
@ dimDomain
dimension of domain vector space
Definition functionspaceinterface.hh:46
@ dimRange
dimension of range vector space
Definition functionspaceinterface.hh:48
Definition genericgeometry.hh:175
Definition genericlagrangepoints.hh:21
abstract base class for Lagrange shape functions
Definition lagrange/shapefunctionset.hh:48
FunctionSpaceType::DomainType DomainType
Definition lagrange/shapefunctionset.hh:56
FunctionSpaceType::HessianRangeType HessianRangeType
Definition lagrange/shapefunctionset.hh:59
virtual void evaluate(const DomainType &x, RangeType &value) const =0
virtual void jacobian(const DomainType &x, JacobianRangeType &jacobian) const =0
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition lagrange/shapefunctionset.hh:58
FunctionSpaceType::RangeType RangeType
Definition lagrange/shapefunctionset.hh:57
virtual void hessian(const DomainType &x, HessianRangeType &hessian) const =0
virtual const ThisType * clone() const =0
virtual ~LagrangeShapeFunctionInterface()
Definition lagrange/shapefunctionset.hh:61
FunctionSpace FunctionSpaceType
Definition lagrange/shapefunctionset.hh:54
implementation of Lagrange shape function using generic Lagrange shape functions
Definition lagrange/shapefunctionset.hh:88
GenericBaseFunctionType genericShapeFunction_
Definition lagrange/shapefunctionset.hh:116
BaseType::RangeType RangeType
Definition lagrange/shapefunctionset.hh:99
virtual void evaluate(const DomainType &x, RangeType &value) const
Definition lagrange/shapefunctionset.hh:196
virtual void hessian(const DomainType &x, HessianRangeType &hessian) const
Definition lagrange/shapefunctionset.hh:221
GenericLagrangeBaseFunction< FunctionSpace, GeometryType, polOrder > GenericBaseFunctionType
Definition lagrange/shapefunctionset.hh:96
LagrangeShapeFunction(const GenericBaseFunctionType &genericShapeFunction)
Definition lagrange/shapefunctionset.hh:103
BaseType::HessianRangeType HessianRangeType
Definition lagrange/shapefunctionset.hh:101
virtual const BaseType * clone() const
Definition lagrange/shapefunctionset.hh:113
BaseType::JacobianRangeType JacobianRangeType
Definition lagrange/shapefunctionset.hh:100
virtual int order() const
Definition lagrange/shapefunctionset.hh:111
virtual void jacobian(const DomainType &x, JacobianRangeType &jacobian) const
Definition lagrange/shapefunctionset.hh:205
BaseType::DomainType DomainType
Definition lagrange/shapefunctionset.hh:98
factory class
Definition lagrange/shapefunctionset.hh:133
LagrangeShapeFunctionFactory(const Dune::GeometryType &type, const int order=maxPolOrder)
Definition lagrange/shapefunctionset.hh:144
ShapeFunctionType * createShapeFunction(std::size_t i) const
Definition lagrange/shapefunctionset.hh:328
std::size_t numShapeFunctions() const
Definition lagrange/shapefunctionset.hh:315
LagrangeShapeFunctionInterface< FunctionSpace > ShapeFunctionType
Definition lagrange/shapefunctionset.hh:137
int order() const
Definition lagrange/shapefunctionset.hh:307
Lagrange shape function set.
Definition lagrange/shapefunctionset.hh:176
LagrangeShapeFunctionSet(const Dune::GeometryType &type, const int order=maxPolOrder)
Definition lagrange/shapefunctionset.hh:183
Definition lagrange/shapefunctionset.hh:261
LagrangeShapeFunction< FunctionSpace, ImplType, polOrd > ShapeFunctionImpl
Definition lagrange/shapefunctionset.hh:263
static void apply(const int order, std::size_t &size)
Definition lagrange/shapefunctionset.hh:266
static void apply(const std::size_t &i, const int order, ShapeFunctionType *&shapeFunction)
Definition lagrange/shapefunctionset.hh:274
ShapeFunctionImpl::GenericBaseFunctionType GenericBaseFunctionType
Definition lagrange/shapefunctionset.hh:264
Definition space/shapefunctionset/simple.hh:50