DUNE-FEM (unstable)

localfunction.hh
1#ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_LOCALFUNCTION_HH
2#define DUNE_FEM_FUNCTION_LOCALFUNCTION_LOCALFUNCTION_HH
3
4#include <utility>
5#include <type_traits>
6#include <tuple>
7
10
11
12namespace Dune
13{
14 namespace Fem {
15 // forward declaration for DenseMatVecTraits
16 template< class BasisFunctionSet, class LocalDofVector >
17 class LocalFunction;
18 }
19
20
21 // DenseMatVecTraits for LocalFunction for Discrete Functions
22 // ----------------------------------------------------------
23
24 template< class BasisFunctionSet, class LocalDofVector >
25 struct DenseMatVecTraits< Fem::LocalFunction< BasisFunctionSet, LocalDofVector > >
26 {
27 typedef Fem::LocalFunction< BasisFunctionSet, LocalDofVector > derived_type;
28 typedef typename LocalDofVector::value_type value_type;
29 //typedef LocalDofVector container_type;
30 typedef typename LocalDofVector::size_type size_type;
31 };
32
33
34
35 // FieldTraits for LocalContribution for Discrete Functions
36 // --------------------------------------------------------
37
38 template< class BasisFunctionSet, class LocalDofVector >
39 struct FieldTraits< Fem::LocalFunction< BasisFunctionSet, LocalDofVector > >
40 {
41 typedef typename FieldTraits< typename LocalDofVector::value_type >::field_type field_type;
42 typedef typename FieldTraits< typename LocalDofVector::value_type >::real_type real_type;
43 };
44
45
46 namespace Fem
47 {
48
64 // LocalFunction
65 // -------------
66
74 template< class BasisFunctionSet, class LocalDofVector >
76 : public Dune::DenseVector< LocalFunction< BasisFunctionSet, LocalDofVector > >
77 {
80 public:
81
84
86 typedef LocalDofVector LocalDofVectorType;
87
89 typedef typename LocalDofVectorType::value_type DofType;
92 typedef typename LocalDofVectorType::size_type SizeType;
93
96
99
112
114 typedef typename EntityType::Geometry::LocalCoordinate LocalCoordinateType;
115
120
123
126 : basisFunctionSet_( basisFunctionSet )
127 {
128 localDofVector_.resize( basisFunctionSet.size() );
129 }
130
132 explicit LocalFunction ( const LocalDofVectorType &localDofVector ) : localDofVector_( localDofVector ) {}
133
136 : basisFunctionSet_( basisFunctionSet ),
137 localDofVector_( localDofVector )
138 {
139 localDofVector_.resize( basisFunctionSet.size() );
140 }
141
143 explicit LocalFunction ( LocalDofVectorType &&localDofVector ) : localDofVector_( localDofVector ) {}
144
147 : basisFunctionSet_( basisFunctionSet ),
148 localDofVector_( localDofVector )
149 {
150 localDofVector_.resize( basisFunctionSet.size() );
151 }
152
155 : basisFunctionSet_( std::move( other.basisFunctionSet_ ) ),
156 localDofVector_( std::move( other.localDofVector_ ) )
157 {}
158
160 LocalFunction ( const ThisType & other )
161 : basisFunctionSet_( other.basisFunctionSet_ ),
162 localDofVector_( other.localDofVector_ )
163 {}
164
170 const DofType &operator[] ( SizeType num ) const { return localDofVector_[ num ]; }
171
177 DofType &operator[] ( SizeType num ) { return localDofVector_[ num ]; }
178
179 using BaseType :: operator +=;
180 using BaseType :: operator -=;
181 using BaseType :: operator *=;
182 using BaseType :: operator /=;
183
188 template< class T >
190 {
191 localDofVector() = other.localDofVector();
192 }
193
195 void clear ()
196 {
197 std::fill( localDofVector().begin(), localDofVector().end(), DofType( 0 ) );
198 }
199
200#if 0
211 template< class T >
212 ThisType &axpy ( const RangeFieldType s, const LocalFunction< BasisFunctionSet, T > &other )
213 {
214 localDofVector().axpy( s, other.localDofVector() );
215 return *this;
216 }
217#endif
218 using BaseType :: axpy;
219
232 template< class PointType >
233 void axpy ( const PointType &x, const RangeType &factor )
234 {
235 basisFunctionSet().axpy( x, factor, localDofVector() );
236 }
237
250 template< class PointType >
251 void axpy ( const PointType &x, const JacobianRangeType &factor)
252 {
253 basisFunctionSet().axpy( x, factor, localDofVector() );
254 }
255 template< class PointType >
256 void axpy ( const PointType &x, const HessianRangeType &factor)
257 {
258 basisFunctionSet().axpy( x, factor, localDofVector() );
259 }
260
274 template< class PointType >
275 void axpy ( const PointType &x, const RangeType &factor1, const JacobianRangeType &factor2 )
276 {
277 basisFunctionSet().axpy( x, factor1, factor2, localDofVector() );
278 }
279
290 int order () const { return basisFunctionSet().order(); }
291
296 const BasisFunctionSetType &basisFunctionSet () const { return basisFunctionSet_; }
297
302 const EntityType &entity () const { return basisFunctionSet().entity(); }
303
304
310 template< class PointType >
311 void evaluate ( const PointType &x, RangeType &ret ) const
312 {
314 }
315
324 template< class PointType >
325 void jacobian ( const PointType &x, JacobianRangeType &ret ) const
326 {
328 }
329
338 template< class PointType >
339 void hessian ( const PointType &x, HessianRangeType &ret ) const
340 {
342 }
343
351 int numDofs () const { return localDofVector().size(); }
352
360 SizeType size () const { return localDofVector().size(); }
361
364 template< class QuadratureType, class ... Vectors >
365 void axpyQuadrature ( const QuadratureType &quad, const Vectors& ... values )
366 {
367 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
368 std::ignore =
369 std::make_tuple( ( basisFunctionSet().axpy( quad, values, localDofVector() ), 1 )...);
370 }
371
374 template< class QuadratureType, class RangeVectorType, class JacobianRangeVectorType >
375 void axpyQuadrature ( const QuadratureType &quad,
376 const RangeVectorType& rangeVector,
377 const JacobianRangeVectorType& jacobianVector )
378 {
379 basisFunctionSet().axpy( quad, rangeVector, jacobianVector, localDofVector() );
380 }
381
383 template< class QuadratureType, class ... Vectors >
384 void evaluateQuadrature( const QuadratureType &quad, Vectors& ... vec ) const
385 {
386 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
387 std::ignore =
388 std::make_tuple( ( evaluateQuadrature( quad, vec, typename std::decay< decltype( vec[ 0 ] ) >::type() ), 1 )
389 ... );
390 }
391
394 template< class QuadratureType, class ... Vectors >
395 void jacobianQuadrature( const QuadratureType &quad, Vectors& ... vec ) const
396 {
397 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
398 std::ignore =
399 std::make_tuple( ( evaluateQuadrature( quad, vec, typename std::decay< decltype( vec[ 0 ] ) >::type() ), 1 )
400 ... );
401 }
402
404 template< class QuadratureType, class ... Vectors >
405 void hessianQuadrature( const QuadratureType &quad, Vectors& ... vec ) const
406 {
407 // make sure vec size if large enough
408 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
409 std::ignore =
410 std::make_tuple( ( evaluateQuadrature( quad, vec, typename std::decay< decltype( vec[ 0 ] ) >::type() ), 1 )
411 ... );
412 }
413
415 const LocalDofVectorType &localDofVector () const { return localDofVector_; }
416
418 LocalDofVectorType &localDofVector () { return localDofVector_; }
419
420
423 bool valid () const
424 {
425 return basisFunctionSet_.valid();
426 }
427
428 protected:
437 void init ( const EntityType& entity )
438 {
439 DUNE_THROW(NotImplemented,"LocalFunction::init( entity ) must be overloaded on derived class!");
440 }
441
450 void bind ( const EntityType& entity )
451 {
452 DUNE_THROW(NotImplemented,"LocalFunction::bind( entity ) must be overloaded on derived class!");
453 }
454
458 void unbind ()
459 {
460 // basically sets entity pointer inside basis function set to nullptr
461 basisFunctionSet_ = BasisFunctionSetType();
462 }
463
477 {
478 basisFunctionSet_ = basisFunctionSet;
479 localDofVector_.resize( basisFunctionSet.size() );
480 }
481
482 // evaluate local function and store results in vector of RangeTypes
483 // this method only helps to identify the correct method on
484 // the basis function set
485 template< class QuadratureType, class VectorType >
486 void evaluateQuadrature( const QuadratureType &quad, VectorType &result, const RangeType & ) const
487 {
488 basisFunctionSet().evaluateAll( quad, localDofVector(), result );
489 }
490
491 // evaluate jacobian of local function and store result in vector of
492 // JacobianRangeTypes, this method only helps to identify the correct method on
493 // the basis function set
494 template< class QuadratureType, class VectorType >
495 void evaluateQuadrature( const QuadratureType &quad, VectorType &result, const JacobianRangeType & ) const
496 {
497 basisFunctionSet().jacobianAll( quad, localDofVector(), result );
498 }
499
500 // evaluate jacobian of local function and store result in vector of
501 // JacobianRangeTypes, this method only helps to identify the correct method on
502 // the basis function set
503 template< class QuadratureType, class VectorType >
504 void evaluateQuadrature( const QuadratureType &quad, VectorType &result, const HessianRangeType & ) const
505 {
506 basisFunctionSet().hessianAll( quad, localDofVector(), result );
507 }
508
509 BasisFunctionSetType basisFunctionSet_;
510 LocalDofVectorType localDofVector_;
511 };
512
515 } // end namespace Fem
516
517} // end namespace Dune
518
519#endif // #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_LOCALFUNCTION_HH
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:229
Iterator begin()
begin iterator
Definition: densevector.hh:347
Iterator end()
end iterator
Definition: densevector.hh:353
Wrapper class for entities.
Definition: entity.hh:66
Interface class for basis function sets.
Definition: basisfunctionset.hh:32
const EntityType & entity() const
return entity
void axpy(const Quadrature &quad, const Vector &values, DofVector &dofs) const
evaluate all basis function and multiply with given values and add to dofs
std::size_t size() const
return size of basis function set
int order() const
return order of basis function set
bool valid() const
return true if entity was set
void hessianAll(const Point &x, const DofVector &dofs, HessianRangeType &hessian) const
void jacobianAll(const QuadratureType &quad, const DofVector &dofs, JacobianArray &jacobians) const
evaluate the jacobian of all basis functions and store the result in the jacobians array
void evaluateAll(const Quadrature &quad, const DofVector &dofs, RangeArray &ranges) const
evaluate all basis functions and store the result in the ranges array
Definition: explicitfieldvector.hh:75
FunctionSpaceTraits::DomainFieldType DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspaceinterface.hh:60
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
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
A vector valued function space.
Definition: functionspace.hh:60
interface for local functions
Definition: localfunction.hh:77
const LocalDofVectorType & localDofVector() const
return const reference to local Dof Vector
Definition: localfunction.hh:415
void evaluate(const PointType &x, RangeType &ret) const
evaluate the local function
Definition: localfunction.hh:311
LocalFunction(ThisType &&other)
move constructor
Definition: localfunction.hh:154
void init(const EntityType &entity)
initialize the local function for an entity
Definition: localfunction.hh:437
FunctionSpaceType::DomainType DomainType
type of domain vectors, i.e., type of coordinates
Definition: localfunction.hh:105
void bind(const EntityType &entity)
initialize the local function for an entity
Definition: localfunction.hh:450
void evaluateQuadrature(const QuadratureType &quad, Vectors &... vec) const
evaluate all basisfunctions for all quadrature points and store the results in the result vector
Definition: localfunction.hh:384
static const int dimDomain
dimension of the domain
Definition: localfunction.hh:117
void hessianQuadrature(const QuadratureType &quad, Vectors &... vec) const
evaluate all hessians of all basis functions for all quadrature points and store the results in the r...
Definition: localfunction.hh:405
int numDofs() const
obtain the number of local DoFs
Definition: localfunction.hh:351
BasisFunctionSet BasisFunctionSetType
type of basis function set
Definition: localfunction.hh:83
void hessian(const PointType &x, HessianRangeType &ret) const
evaluate Hessian of the local function
Definition: localfunction.hh:339
const EntityType & entity() const
obtain the entity, this local function lives on
Definition: localfunction.hh:302
LocalDofVectorType::value_type DofType
type of DoF use with the discrete function
Definition: localfunction.hh:89
EntityType::Geometry::LocalCoordinate LocalCoordinateType
type of local coordinates
Definition: localfunction.hh:114
void init(const BasisFunctionSetType &basisFunctionSet)
initialize the local function for an basisFunctionSet
Definition: localfunction.hh:476
void axpy(const PointType &x, const RangeType &factor1, const JacobianRangeType &factor2)
axpy operation for local function
Definition: localfunction.hh:275
FunctionSpaceType::RangeType RangeType
type of range vectors, i.e., type of function values
Definition: localfunction.hh:107
LocalFunction(const BasisFunctionSetType &basisFunctionSet, LocalDofVector &&localDofVector)
half move ctor
Definition: localfunction.hh:146
FunctionSpaceType::DomainFieldType DomainFieldType
field type of the domain
Definition: localfunction.hh:101
LocalFunction(const BasisFunctionSetType &basisFunctionSet, const LocalDofVector &localDofVector)
copy given agruments
Definition: localfunction.hh:135
FunctionSpaceType::HessianRangeType HessianRangeType
type of the Hessian
Definition: localfunction.hh:111
void axpy(const PointType &x, const RangeType &factor)
axpy operation for local function
Definition: localfunction.hh:233
bool valid() const
Returns true if local function if bind or init was previously called.
Definition: localfunction.hh:423
BasisFunctionSetType::FunctionSpaceType FunctionSpaceType
type of functionspace
Definition: localfunction.hh:98
void axpyQuadrature(const QuadratureType &quad, const RangeVectorType &rangeVector, const JacobianRangeVectorType &jacobianVector)
evaluate all basisfunctions for all quadrature points, multiply with the given factor and add the res...
Definition: localfunction.hh:375
void jacobian(const PointType &x, JacobianRangeType &ret) const
evaluate Jacobian of the local function
Definition: localfunction.hh:325
LocalFunction(const ThisType &other)
copy constructor
Definition: localfunction.hh:160
FunctionSpaceType::JacobianRangeType JacobianRangeType
type of the Jacobian, i.e., type of evaluated Jacobian matrix
Definition: localfunction.hh:109
static const int dimRange
dimension of the range
Definition: localfunction.hh:119
void unbind()
clears the local function by removing the basisFunctionSet
Definition: localfunction.hh:458
void axpyQuadrature(const QuadratureType &quad, const Vectors &... values)
evaluate all basisfunctions for all quadrature points, multiply with the given factor and add the res...
Definition: localfunction.hh:365
const DofType & operator[](SizeType num) const
access to local dofs (read-only)
Definition: localfunction.hh:170
FunctionSpaceType::RangeFieldType RangeFieldType
field type of the range
Definition: localfunction.hh:103
int order() const
obtain the order of this local function
Definition: localfunction.hh:290
void axpy(const PointType &x, const JacobianRangeType &factor)
axpy operation for local function
Definition: localfunction.hh:251
LocalFunction(const BasisFunctionSetType &basisFunctionSet)
ctor taking a basisFunctionSet, calling default ctor for LocalDofVectorType, and resize
Definition: localfunction.hh:125
LocalDofVectorType::size_type SizeType
type of index
Definition: localfunction.hh:92
void clear()
set all DoFs to zero
Definition: localfunction.hh:195
BasisFunctionSetType::EntityType EntityType
type of the entity, the local function lives on is given by the space
Definition: localfunction.hh:95
LocalFunction(LocalDofVectorType &&localDofVector)
half move ctor
Definition: localfunction.hh:143
LocalDofVectorType & localDofVector()
return mutable reference to local Dof Vector
Definition: localfunction.hh:418
LocalFunction()
default constructor, calls default ctor of BasisFunctionSetType and LocalDofVectorType
Definition: localfunction.hh:122
LocalFunction(const LocalDofVectorType &localDofVector)
ctor taking a localDofVector, calling default ctor for BasisFunctionSetType
Definition: localfunction.hh:132
void assign(const LocalFunction< BasisFunctionSet, T > &other)
assign all DoFs of this local function
Definition: localfunction.hh:189
const BasisFunctionSetType & basisFunctionSet() const
obtain the basis function set for this local function
Definition: localfunction.hh:296
LocalDofVector LocalDofVectorType
type of local Dof Vector
Definition: localfunction.hh:86
SizeType size() const
obtain the number of local DoFs
Definition: localfunction.hh:360
void jacobianQuadrature(const QuadratureType &quad, Vectors &... vec) const
evaluate all Jacobians for all basis functions for all quadrature points and store the results in the...
Definition: localfunction.hh:395
Default exception for dummy implementations.
Definition: exceptions.hh:263
Definition of the DUNE_NO_DEPRECATED_* macros.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 24, 22:29, 2024)