1 #ifndef DUNE_FEM_SHAPEFUNCTIONSET_TENSORPRODUCT_HH 2 #define DUNE_FEM_SHAPEFUNCTIONSET_TENSORPRODUCT_HH 11 #include <dune/common/fmatrix.hh> 12 #include <dune/common/forloop.hh> 13 #include <dune/common/fvector.hh> 14 #include <dune/common/tuples.hh> 15 #include <dune/common/tupleutility.hh> 28 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
34 "dimDomain of FunctionSpace must coincide with length of ShapeFunctionSetTuple." );
36 "FunctionSpace must be scalar (i.e., dimRange = 1)." );
41 template<
int i >
struct Size;
42 template<
int i >
struct EvaluateAll;
43 template<
int i >
struct JacobianAll;
44 template<
int i >
struct HessianAll;
66 const ThisType &
operator= (
const ThisType &other );
70 std::size_t
size ()
const;
72 template<
class Po
int,
class Functor >
73 void evaluateEach (
const Point &x, Functor functor )
const;
75 template<
class Po
int,
class Functor >
76 void jacobianEach (
const Point &x, Functor functor )
const;
78 template<
class Po
int,
class Functor >
79 void hessianEach (
const Point &x, Functor functor )
const;
82 template<
class Functor >
83 void doEvaluateEach (
int d, RangeType value, std::size_t &index,
const RangeFieldType *buffer, Functor functor )
const;
84 template<
class Functor >
85 void doJacobianEach (
int d, JacobianRangeType jacobian, std::size_t &index,
const RangeFieldType *buffer, Functor functor )
const;
86 template<
class Functor >
87 void doHessianEach (
int d, HessianRangeType hessian, std::size_t &index,
const RangeFieldType *buffer, Functor functor )
const;
89 ShapeFunctionSetTuple shapeFunctionSetTuple_;
90 std::array< std::size_t, dimension > sizes_;
91 RangeFieldType *buffer_;
99 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
106 buffer_[ i ] = value;
110 void operator() (
const std::size_t i,
const FieldVector< T, 1 > &value )
112 (*this)( i, value[ 0 ] );
116 void operator() (
const std::size_t i,
const FieldMatrix< T, 1, 1 > &value )
118 (*this)( i, value[ 0 ][ 0 ] );
130 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
135 template<
class ShapeFunctionSet >
141 operator int()
const {
return order_; }
151 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
155 static void apply (
const ShapeFunctionSetTuple &tuple, std::array< std::size_t, FunctionSpace::dimDomain > &
size )
157 size[ i ] = std::get< i >( tuple ).
size();
166 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
172 Dune::FieldVector< DomainFieldType, 1 > xi( x[ i ] );
174 it += std::get< i >( tuple ).
size();
183 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
189 Dune::FieldVector< DomainFieldType, 1 > xi( x[ i ] );
190 const std::size_t
size = std::get< i >( tuple ).
size();
202 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
208 Dune::FieldVector< DomainFieldType, 1 > xi( x[ i ] );
209 const std::size_t
size = std::get< i >( tuple ).
size();
222 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
225 : shapeFunctionSetTuple_( shapeFunctionSetTuple )
227 ForLoop< Size, 0, dimension-1 >::apply( shapeFunctionSetTuple_, sizes_ );
228 std::size_t buffer_size = 0;
229 for(
int i = 0; i < dimension; ++i )
230 buffer_size += sizes_[ i ];
235 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
243 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
246 : shapeFunctionSetTuple_( other.shapeFunctionSetTuple_ )
248 std::size_t buffer_size = 0;
249 for(
int i = 0; i < dimension; ++i )
251 sizes_[ i ] = other.sizes_[ i ];
252 buffer_size += sizes_[ i ];
258 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
267 shapeFunctionSetTuple_ = other.shapeFunctionSetTuple_;
268 std::size_t buffer_size = 0;
269 for(
int i = 0; i < dimension; ++i )
271 sizes_[ i ] = other.sizes_[ i ];
272 buffer_size += sizes_[ i ];
279 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
282 Dune::ForEachValue< const ShapeFunctionSetTupleType > forEach( shapeFunctionSetTuple_ );
284 forEach.apply( functor );
289 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
293 std::size_t
size( 1 );
294 for(
int i = 0; i < dimension; ++i )
300 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
301 template<
class Po
int,
class Functor >
306 ForLoop< EvaluateAll, 0, dimension-1 >::apply( shapeFunctionSetTuple_,
coordinate( x ), it );
308 std::size_t index = 0;
313 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
314 template<
class Po
int,
class Functor >
319 ForLoop< JacobianAll, 0, dimension-1 >::apply( shapeFunctionSetTuple_,
coordinate( x ), it );
321 std::size_t index = 0;
323 for(
int i = 0; i < dimension; ++i )
325 doJacobianEach( 0, jacobian, index, buffer_, functor );
329 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
330 template<
class Po
int,
class Functor >
335 ForLoop< HessianAll, 0, dimension-1 >::apply( shapeFunctionSetTuple_,
coordinate( x ), it );
337 std::size_t index = 0;
339 for(
int i = 0; i < dimension; ++i )
340 for(
int j = 0; j < dimension; ++j )
342 doHessianEach( 0, hessian, index, buffer_, functor );
346 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
347 template<
class Functor >
353 for( std::size_t i = 0; i < sizes_[ d ]; ++i )
356 v[ 0 ] *= buffer[ i ];
357 doEvaluateEach( d+1, v, index, buffer+sizes_[ d ], functor );
361 functor( index++, value );
365 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
366 template<
class Functor >
372 for( std::size_t i = 0; i < sizes_[ d ]; ++i )
375 j[ 0 ][ d ] *= buffer[ i + sizes_[ d ] ];
376 for(
int k = 1; k < dimension; ++k )
377 j[ 0 ][ (d+k)%dimension ] *= buffer[ i ];
378 doJacobianEach( d+1, j, index, buffer+2*sizes_[ d ], functor );
382 functor( index++, jacobian );
386 template<
class FunctionSpace,
class ShapeFunctionSetTuple >
387 template<
class Functor >
393 for( std::size_t i = 0; i < sizes_[ d ]; ++i )
396 h[ 0 ][ d ][ d ] *= buffer[ i + 2*sizes_[ d ] ];
397 for(
int j = 1; j < dimension; ++j )
399 h[ 0 ][ (d+j)%dimension ][ d ] *= buffer[ i * sizes_[ d ] ];
400 h[ 0 ][ d ][ (d+j)%dimension ] *= buffer[ i * sizes_[ d ] ];
401 for(
int k = 1; k < dimension; ++k )
402 h[ 0 ][ (d+j)%dimension ][ (d+k)%dimension ] *= buffer[ i ];
404 doHessianEach( d+1, h, index, buffer+3*sizes_[ d ], functor );
408 functor( index++, hessian );
415 #endif // #ifndef DUNE_FEM_SHAPEFUNCTIONSET_TENSORPRODUCT_HH int order() const
return order of shape functions
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:62
TensorProductShapeFunctionSet()=default
Definition: tensorproduct.hh:131
Assign(RangeFieldType *buffer)
Definition: tensorproduct.hh:102
void evaluateEach(const Point &x, Functor functor) const
Definition: tensorproduct.hh:303
void visit(const ShapeFunctionSet &shapeFunctionSet)
Definition: tensorproduct.hh:136
A vector valued function space.
Definition: functionspace.hh:16
FunctionSpaceType::DomainFieldType DomainFieldType
Definition: tensorproduct.hh:52
Order()
Definition: tensorproduct.hh:133
static constexpr T max(T a)
Definition: utility.hh:65
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:74
std::size_t size() const
Definition: tensorproduct.hh:291
FieldVector< FieldMatrix< RangeFieldType, dimDomain, dimDomain >, dimRange > HessianRangeType
Intrinsic type used for the hessian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:78
Definition: tensorproduct.hh:100
const ThisType & operator=(const ThisType &other)
Definition: tensorproduct.hh:261
Definition: shapefunctionset/shapefunctionset.hh:33
Definition: tensorproduct.hh:29
FunctionSpace FunctionSpaceType
Definition: tensorproduct.hh:49
dimension of domain vector space
Definition: functionspaceinterface.hh:45
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: tensorproduct.hh:53
dimension of range vector space
Definition: functionspaceinterface.hh:47
ShapeFunctionSetTuple ShapeFunctionSetTupleType
Definition: tensorproduct.hh:50
FunctionSpaceType::RangeType RangeType
Definition: tensorproduct.hh:56
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: tensorproduct.hh:57
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::DomainFieldType DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspaceinterface.hh:59
~TensorProductShapeFunctionSet()
Definition: tensorproduct.hh:237
Definition: coordinate.hh:4
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:66
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: tensorproduct.hh:58
FunctionSpaceType::DomainType DomainType
Definition: tensorproduct.hh:55
void hessianEach(const Point &x, Functor functor) const
Definition: tensorproduct.hh:332
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:70
int order() const
Definition: tensorproduct.hh:280
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:11
void jacobianEach(const Point &x, Functor functor) const
Definition: tensorproduct.hh:316