DUNE-FEM (unstable)

shapefunctionset.hh
1#ifndef DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
2#define DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
3
4#include <cassert>
5#include <cstdlib>
6
8#include <dune/fem/common/forloop.hh>
9
10#include <dune/geometry/type.hh>
12
13#include <dune/fem/space/common/functionspace.hh>
14#include <dune/fem/space/shapefunctionset/simple.hh>
15
16#include "genericbasefunctions.hh"
17#include "genericlagrangepoints.hh"
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
49 typedef typename FunctionSpaceType::DomainType DomainType;
50 typedef typename FunctionSpaceType::RangeType RangeType;
51 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
52 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
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:
88 typedef GenericLagrangeBaseFunction< FunctionSpace, GeometryType, polOrder >
89 GenericBaseFunctionType;
90
91 typedef typename BaseType::DomainType DomainType;
92 typedef typename BaseType::RangeType RangeType;
93 typedef typename BaseType::JacobianRangeType JacobianRangeType;
94 typedef typename BaseType::HessianRangeType HessianRangeType;
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:
109 GenericBaseFunctionType genericShapeFunction_;
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
173 typedef SimpleShapeFunctionSet< typename ShapeFunctionFactoryType::ShapeFunctionType > BaseType;
174
175 public:
176 LagrangeShapeFunctionSet ( const Dune::GeometryType &type, const int order = maxPolOrder )
177 : BaseType( ShapeFunctionFactoryType( type, order ) )
178 {
179 }
180 };
181
182
183
184 // Implementation of LagrangeShapeFunction
185 // ---------------------------------------
186
187 template< class FunctionSpace, class GeometryType, unsigned int 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 >
197 inline void LagrangeShapeFunction< FunctionSpace, GeometryType, 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 >
213 inline void LagrangeShapeFunction< FunctionSpace, GeometryType, 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();
249 typedef typename GeometryWrapper< topologyId, dimension >
250 ::ImplType ImplType;
251
252 template <int polOrd>
253 struct CheckOrder
254 {
255 // type of scalar shape function for current polynomial order
256 typedef LagrangeShapeFunction< FunctionSpace, ImplType, polOrd > ShapeFunctionImpl;
257 typedef typename ShapeFunctionImpl::GenericBaseFunctionType GenericBaseFunctionType;
258
259 static void apply ( const int order, std::size_t &size )
260 {
261 if( order == polOrd )
262 {
263 size = GenericLagrangePoint< ImplType, polOrd >::numLagrangePoints;
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
279 Dune::Fem::ForLoop< CheckOrder, 0, maxPolOrder >::apply( order, 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
285 Dune::Fem::ForLoop< CheckOrder, 0, maxPolOrder >::apply( i, order, shapeFunction );
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 >
307 inline std::size_t LagrangeShapeFunctionFactory< FunctionSpace, polOrder >
308 ::numShapeFunctions () const
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 >
319 inline typename LagrangeShapeFunctionFactory< FunctionSpace, polOrder >::ShapeFunctionType *
320 LagrangeShapeFunctionFactory< FunctionSpace, 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
336 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 1, 1 >, 1 >;
337 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 2, 1 >, 1 >;
338 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 3, 1 >, 1 >;
339 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 1, 1 >, 1 >;
340 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 2, 1 >, 1 >;
341 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 3, 1 >, 1 >;
342
343 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 1, 1 >, 2 >;
344 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 2, 1 >, 2 >;
345 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 3, 1 >, 2 >;
346 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 1, 1 >, 2 >;
347 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 2, 1 >, 2 >;
348 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 3, 1 >, 2 >;
349
350 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 1, 1 >, 3 >;
351 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 2, 1 >, 3 >;
352 extern template class LagrangeShapeFunctionFactory< FunctionSpace< double, double, 3, 1 >, 3 >;
353 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 1, 1 >, 3 >;
354 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 2, 1 >, 3 >;
355 extern template class LagrangeShapeFunctionFactory< FunctionSpace< float, float, 3, 1 >, 3 >;
356
357 } // namespace Fem
358
359} // namespace Dune
360
361#endif // #ifndef DUNE_FEM_SPACE_LAGRANGE_SHAPEFUNCTIONSET_HH
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
A vector valued function space.
Definition: functionspace.hh:60
factory class
Definition: shapefunctionset.hh:126
abstract base class for Lagrange shape functions
Definition: shapefunctionset.hh:41
Lagrange shape function set.
Definition: shapefunctionset.hh:169
implementation of Lagrange shape function using generic Lagrange shape functions
Definition: shapefunctionset.hh:81
vector space out of a tensor product of fields.
Definition: fvector.hh:91
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implements a vector constructed from a given type representing a field and a compile-time given size.
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)