dune-fem 2.8.0
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
7#include <dune/common/fvector.hh>
9
10#include <dune/geometry/type.hh>
11#include <dune/geometry/quadraturerules.hh>
12
15
18
19/*
20 @file
21 @brief Shape function set for Lagrange space
22 @author Christoph Gersbacher
23*/
24
25namespace Dune
26{
27
28 namespace Fem
29 {
30
31 // LagrangeShapeFunctionInterface
32 // ------------------------------
33
39 template< class FunctionSpace >
41 {
43
44 static_assert( (FunctionSpace::dimRange == 1), "FunctionSpace must be scalar." );
45
46 public:
48
53
55
56 virtual void evaluate ( const DomainType &x, RangeType &value ) const = 0;
57 virtual void jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const = 0;
58 virtual void hessian ( const DomainType &x, HessianRangeType &hessian ) const = 0;
59
60 virtual int order () const = 0;
61
62 virtual const ThisType *clone () const = 0;
63 };
64
65
66
67 // LagrangeShapeFunction
68 // ---------------------
69
78 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
80 : public LagrangeShapeFunctionInterface< FunctionSpace >
81 {
84
85 static const int dimension = FunctionSpace::dimDomain;
86
87 public:
90
95
96 explicit LagrangeShapeFunction ( const GenericBaseFunctionType &genericShapeFunction )
97 : genericShapeFunction_( genericShapeFunction )
98 {}
99
100 virtual void evaluate ( const DomainType &x, RangeType &value ) const;
101 virtual void jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const;
102 virtual void hessian ( const DomainType &x, HessianRangeType &hessian ) const;
103
104 virtual int order () const { return polOrder; }
105
106 virtual const BaseType *clone () const { return new ThisType( *this ); }
107
108 protected:
110 };
111
112
113
114 // LagrangeShapeFunctionFactory
115 // ----------------------------
116
124 template< class FunctionSpace, int maxPolOrder >
126 {
127 static const int dimension = FunctionSpace::dimDomain;
128
129 public:
131
132 private:
133 template< GeometryType::Id geometryId>
134 struct Switch;
135
136 public:
137 explicit LagrangeShapeFunctionFactory ( const Dune::GeometryType &type, const int order = maxPolOrder )
138 : gt_(type),
139 order_( order )
140 {}
141
142 int order () const;
143
144 std::size_t numShapeFunctions () const;
145
146 ShapeFunctionType *createShapeFunction( std::size_t i ) const;
147
148 private:
149 const Dune::GeometryType gt_;
150 const int order_;
151 };
152
153
154
155 // LagrangeShapeFunctionSet
156 // ------------------------
157
164 template< class FunctionSpace, int maxPolOrder >
166 : public SimpleShapeFunctionSet<
167 typename LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >::ShapeFunctionType
168 >
169 {
170 static_assert( (FunctionSpace::dimRange == 1), "FunctionSpace must be scalar." );
171
174
175 public:
176 LagrangeShapeFunctionSet ( const Dune::GeometryType &type, const int order = maxPolOrder )
178 {
179 }
180 };
181
182
183
184 // Implementation of LagrangeShapeFunction
185 // ---------------------------------------
186
187 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
188 inline void LagrangeShapeFunction< FunctionSpace, GeometryType, polOrder >
189 ::evaluate ( const DomainType &x, RangeType &value ) const
190 {
191 FieldVector< int, 0 > diffVariable;
192 genericShapeFunction_.evaluate( diffVariable, x, value );
193 }
194
195
196 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
198 ::jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const
199 {
200 FieldVector< int, 1 > diffVariable;
201 RangeType tmp;
202
203 int &i = diffVariable[ 0 ];
204 for( i = 0; i < dimension; ++i )
205 {
206 genericShapeFunction_.evaluate( diffVariable, x, tmp );
207 jacobian[ 0 ][ i ] = tmp[ 0 ];
208 }
209 }
210
211
212 template< class FunctionSpace, class GeometryType, unsigned int polOrder >
214 ::hessian ( const DomainType &x, HessianRangeType &hessian ) const
215 {
216 FieldVector< int, 2 > diffVariable;
217 RangeType tmp;
218
219 int &i = diffVariable[ 0 ];
220 for( i = 0; i < dimension; ++i )
221 {
222 // we use symmetrized evaluation of the hessian, since calling
223 // evaluate is in general quite expensive
224 int &j = diffVariable[ 1 ];
225 for( j = 0; j < i; ++j )
226 {
227 genericShapeFunction_.evaluate( diffVariable, x, tmp );
228 hessian[ 0 ][ i ][ j ] = hessian[ 0 ][ j ][ i ] = tmp[ 0 ];
229 }
230
231 assert( j == i );
232 genericShapeFunction_.evaluate( diffVariable, x, tmp );
233 hessian[ 0 ][ i ][ i ] = tmp[ 0 ];
234 }
235 }
236
237
238
239 // LagrangeShapeFunctionFactory::Switch
240 // ------------------------------------
241
242 template< class FunctionSpace, int maxPolOrder >
243 template< GeometryType::Id geometryId>
244 struct LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >::Switch
245 {
246 // get generic geometry type
247 static constexpr GeometryType gt = geometryId;
248 static const unsigned int topologyId = gt.id();
250 ::ImplType ImplType;
251
252 template <int polOrd>
254 {
255 // type of scalar shape function for current polynomial order
258
259 static void apply ( const int order, std::size_t &size )
260 {
261 if( order == polOrd )
262 {
264 }
265 }
266
267 static void apply ( const std::size_t &i, const int order, ShapeFunctionType *&shapeFunction )
268 {
269 if( order == polOrd )
270 {
271 shapeFunction = new ShapeFunctionImpl( GenericBaseFunctionType( i ) );
272 }
273 }
274 };
275
276 static void apply ( const int order, std::size_t &size )
277 {
278 // loop over all possible polynomial order to find correct size
280 }
281
282 static void apply ( const std::size_t &i, const int order, ShapeFunctionType *&shapeFunction )
283 {
284 // loop over all possible polynomial order to create correct shape function
286 }
287 };
288
289
290
291 // Implementation of LagrangeShapeFunctionFactory
292 // ----------------------------------------------
293
294 template< class FunctionSpace, int maxPolOrder >
295 const int LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >::dimension;
296
297
298 template< class FunctionSpace, int maxPolOrder >
299 inline int LagrangeShapeFunctionFactory< FunctionSpace, maxPolOrder >
300 ::order () const
301 {
302 return order_;
303 }
304
305
306 template< class FunctionSpace, int polOrder >
309 {
310 std::size_t numShapeFunctions( 0 );
311 Dune::Impl::toGeometryTypeIdConstant<dimension>(gt_, [&](auto geometryTypeId) {
312 Switch<decltype(geometryTypeId)::value>::apply(order_, numShapeFunctions);
313 });
314 return numShapeFunctions;
315 }
316
317
318 template< class FunctionSpace, int polOrder >
321 ::createShapeFunction( const std::size_t i ) const
322 {
323 ShapeFunctionType *shapeFunction( nullptr );
324 Dune::Impl::toGeometryTypeIdConstant<dimension>(gt_, [&](auto geometryTypeId) {
325 Switch<decltype(geometryTypeId)::value>::apply(i, order_,shapeFunction);
326 });
327 assert( shapeFunction );
328 return shapeFunction;
329 }
330
331
332
333 // Extern Template Instantiations
334 // ------------------------------
335
342
349
356
357 } // namespace Fem
358
359} // namespace Dune
360
361#endif // #ifndef DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
Definition: bindguard.hh:11
static DUNE_PRIVATE void apply(Args &&... args)
Definition: forloop.hh:23
A vector valued function space.
Definition: functionspace.hh:60
ExplicitFieldVector< FieldMatrix< RangeFieldType, dimDomain, dimDomain >, dimRange > HessianRangeType
Intrinsic type used for the hessian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:79
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
@ dimDomain
dimension of domain vector space
Definition: functionspaceinterface.hh:46
@ dimRange
dimension of range vector space
Definition: functionspaceinterface.hh:48
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
Definition: genericgeometry.hh:175
Definition: genericlagrangepoints.hh:21
abstract base class for Lagrange shape functions
Definition: lagrange/shapefunctionset.hh:41
FunctionSpaceType::DomainType DomainType
Definition: lagrange/shapefunctionset.hh:49
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: lagrange/shapefunctionset.hh:52
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:51
FunctionSpaceType::RangeType RangeType
Definition: lagrange/shapefunctionset.hh:50
virtual void hessian(const DomainType &x, HessianRangeType &hessian) const =0
virtual const ThisType * clone() const =0
virtual ~LagrangeShapeFunctionInterface()
Definition: lagrange/shapefunctionset.hh:54
FunctionSpace FunctionSpaceType
Definition: lagrange/shapefunctionset.hh:47
implementation of Lagrange shape function using generic Lagrange shape functions
Definition: lagrange/shapefunctionset.hh:81
GenericBaseFunctionType genericShapeFunction_
Definition: lagrange/shapefunctionset.hh:109
BaseType::RangeType RangeType
Definition: lagrange/shapefunctionset.hh:92
virtual void evaluate(const DomainType &x, RangeType &value) const
Definition: lagrange/shapefunctionset.hh:189
virtual void hessian(const DomainType &x, HessianRangeType &hessian) const
Definition: lagrange/shapefunctionset.hh:214
GenericLagrangeBaseFunction< FunctionSpace, GeometryType, polOrder > GenericBaseFunctionType
Definition: lagrange/shapefunctionset.hh:89
LagrangeShapeFunction(const GenericBaseFunctionType &genericShapeFunction)
Definition: lagrange/shapefunctionset.hh:96
BaseType::HessianRangeType HessianRangeType
Definition: lagrange/shapefunctionset.hh:94
virtual const BaseType * clone() const
Definition: lagrange/shapefunctionset.hh:106
BaseType::JacobianRangeType JacobianRangeType
Definition: lagrange/shapefunctionset.hh:93
virtual int order() const
Definition: lagrange/shapefunctionset.hh:104
virtual void jacobian(const DomainType &x, JacobianRangeType &jacobian) const
Definition: lagrange/shapefunctionset.hh:198
BaseType::DomainType DomainType
Definition: lagrange/shapefunctionset.hh:91
factory class
Definition: lagrange/shapefunctionset.hh:126
LagrangeShapeFunctionFactory(const Dune::GeometryType &type, const int order=maxPolOrder)
Definition: lagrange/shapefunctionset.hh:137
ShapeFunctionType * createShapeFunction(std::size_t i) const
Definition: lagrange/shapefunctionset.hh:321
std::size_t numShapeFunctions() const
Definition: lagrange/shapefunctionset.hh:308
LagrangeShapeFunctionInterface< FunctionSpace > ShapeFunctionType
Definition: lagrange/shapefunctionset.hh:130
int order() const
Definition: lagrange/shapefunctionset.hh:300
Lagrange shape function set.
Definition: lagrange/shapefunctionset.hh:169
LagrangeShapeFunctionSet(const Dune::GeometryType &type, const int order=maxPolOrder)
Definition: lagrange/shapefunctionset.hh:176
Definition: lagrange/shapefunctionset.hh:254
LagrangeShapeFunction< FunctionSpace, ImplType, polOrd > ShapeFunctionImpl
Definition: lagrange/shapefunctionset.hh:256
static void apply(const int order, std::size_t &size)
Definition: lagrange/shapefunctionset.hh:259
static void apply(const std::size_t &i, const int order, ShapeFunctionType *&shapeFunction)
Definition: lagrange/shapefunctionset.hh:267
ShapeFunctionImpl::GenericBaseFunctionType GenericBaseFunctionType
Definition: lagrange/shapefunctionset.hh:257
Definition: space/shapefunctionset/simple.hh:50