DUNE-FEM (unstable)

simple.hh
1#ifndef DUNE_FEM_SHAPEFUNCTIONSET_SIMPLE_HH
2#define DUNE_FEM_SHAPEFUNCTIONSET_SIMPLE_HH
3
4// C++ includes
5#include <cstddef>
6#include <vector>
7
8#include <dune/fem/common/coordinate.hh>
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15
16 // AbstractShapeFunction
17 // ---------------------
18
19 template< class FunctionSpace >
20 class AbstractShapeFunction
21 {
22 typedef AbstractShapeFunction< FunctionSpace > ThisType;
23
24 public:
25 typedef FunctionSpace FunctionSpaceType;
26
27 typedef typename FunctionSpaceType::DomainType DomainType;
28 typedef typename FunctionSpaceType::RangeType RangeType;
29 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
30 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
31
32 virtual ~AbstractShapeFunction () {}
33
34 virtual void evaluate ( const DomainType &x, RangeType &value ) const = 0;
35
36 virtual void jacobian ( const DomainType &x, JacobianRangeType &jacobian ) const = 0;
37
38 virtual void hessian ( const DomainType &x, HessianRangeType &hessian ) const = 0;
39
40 const ThisType *clone () const = 0;
41 };
42
43
44
45 // SimpleShapeFunctionSet
46 // ----------------------
47
48 template< class ShapeFunction >
49 class SimpleShapeFunctionSet
50 {
51 typedef SimpleShapeFunctionSet< ShapeFunction > ThisType;
52
53 public:
54 typedef ShapeFunction ShapeFunctionType;
55
56 typedef ThisType ScalarFunctionSpaceType;
57
58 typedef typename ShapeFunction::FunctionSpaceType FunctionSpaceType;
59 typedef typename FunctionSpaceType::DomainType DomainType;
60 typedef typename FunctionSpaceType::RangeType RangeType;
61 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
62 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
63
64 // this number is positive if the shape function set
65 // is using Lagrange polynomials
66 static const int lagrangePointId = -1;
67
68 template< class Factory >
69 explicit SimpleShapeFunctionSet ( const Factory &factory );
70
71 SimpleShapeFunctionSet ( const ThisType &other );
72
73 const ThisType &operator= ( const ThisType &other );
74
75 ~SimpleShapeFunctionSet ();
76
77 int order () const { return order_; }
78
79 // Shape Function Set Interface Methods
80 std::size_t size () const { return shapeFunctions_.size(); }
81
82 template< class Point, class Functor >
83 void evaluateEach ( const Point &x, Functor functor ) const;
84
85 template< class Point, class Functor >
86 void jacobianEach ( const Point &x, Functor functor ) const;
87
88 template< class Point, class Functor >
89 void hessianEach ( const Point &x, Functor functor ) const;
90
91 protected:
92 std::vector< const ShapeFunctionType * > shapeFunctions_;
93 int order_;
94 };
95
96
97
98 // Implementation of SimpleShapeFunctionSet
99 // ----------------------------------------
100
101 template< class ShapeFunction >
102 template< class Factory >
103 inline SimpleShapeFunctionSet< ShapeFunction >
104 ::SimpleShapeFunctionSet ( const Factory &factory )
105 {
106 const std::size_t numShapeFunctions = factory.numShapeFunctions();
107 shapeFunctions_.resize( numShapeFunctions );
108 for( std::size_t i = 0; i < numShapeFunctions; ++i )
109 shapeFunctions_[ i ] = factory.createShapeFunction( i );
110 order_ = factory.order();
111 }
112
113 template< class ShapeFunction >
114 inline SimpleShapeFunctionSet< ShapeFunction >
115 ::SimpleShapeFunctionSet ( const ThisType &other )
116 {
117 *this = other;
118 }
119
120 template< class ShapeFunction >
121 inline const typename SimpleShapeFunctionSet< ShapeFunction >::ThisType &
122 SimpleShapeFunctionSet< ShapeFunction >::operator= ( const ThisType &other )
123 {
124 if( this == &other )
125 return *this;
126
127 for( std::size_t i = 0; i < size(); ++i )
128 delete shapeFunctions_[ i ];
129
130 const std::size_t numShapeFunctions = other.size();
131 shapeFunctions_.resize( numShapeFunctions );
132 for( std::size_t i = 0; i < numShapeFunctions; ++i )
133 shapeFunctions_[ i ] = other.shapeFunctions_[ i ]->clone();
134
135 order_ = other.order_;
136 return *this;
137 }
138
139
140 template< class ShapeFunction >
141 inline SimpleShapeFunctionSet< ShapeFunction >::~SimpleShapeFunctionSet ()
142 {
143 for( std::size_t i = 0; i < size(); ++i )
144 delete shapeFunctions_[ i ];
145 }
146
147
148 template< class ShapeFunction >
149 template< class Point, class Functor >
150 inline void SimpleShapeFunctionSet< ShapeFunction >
151 ::evaluateEach ( const Point &x, Functor functor ) const
152 {
153 for( std::size_t i = 0; i < size(); ++i )
154 {
155 RangeType value;
156 shapeFunctions_[ i ]->evaluate( coordinate( x ), value );
157 functor( i, value );
158 }
159 }
160
161
162 template< class ShapeFunction >
163 template< class Point, class Functor >
164 inline void SimpleShapeFunctionSet< ShapeFunction >
165 ::jacobianEach ( const Point &x, Functor functor ) const
166 {
167 for( std::size_t i = 0; i < size(); ++i )
168 {
169 JacobianRangeType jacobian;
170 shapeFunctions_[ i ]->jacobian( coordinate( x ), jacobian );
171 functor( i, jacobian );
172 }
173 }
174
175
176 template< class ShapeFunction >
177 template< class Point, class Functor >
178 inline void SimpleShapeFunctionSet< ShapeFunction >
179 ::hessianEach ( const Point &x, Functor functor ) const
180 {
181 for( std::size_t i = 0; i < size(); ++i )
182 {
183 HessianRangeType hessian;
184 shapeFunctions_[ i ]->hessian( coordinate( x ), hessian );
185 functor( i, hessian );
186 }
187 }
188
189 } // namespace Fem
190
191} // namespace Dune
192
193#endif // #ifndef DUNE_FEM_SHAPEFUNCTIONSET_SIMPLE_HH
Definition: explicitfieldvector.hh:75
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
A vector valued function space.
Definition: functionspace.hh:60
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)