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
102
115
118
123
126
129 : basisFunctionSet_( basisFunctionSet )
130 {
131 localDofVector_.resize( basisFunctionSet.size() );
132 }
133
135 explicit LocalFunction ( const LocalDofVectorType &localDofVector ) : localDofVector_( localDofVector ) {}
136
139 : basisFunctionSet_( basisFunctionSet ),
140 localDofVector_( localDofVector )
141 {
142 localDofVector_.resize( basisFunctionSet.size() );
143 }
144
146 explicit LocalFunction ( LocalDofVectorType &&localDofVector ) : localDofVector_( localDofVector ) {}
147
150 : basisFunctionSet_( basisFunctionSet ),
151 localDofVector_( localDofVector )
152 {
153 localDofVector_.resize( basisFunctionSet.size() );
154 }
155
158 : basisFunctionSet_( std::move( other.basisFunctionSet_ ) ),
159 localDofVector_( std::move( other.localDofVector_ ) )
160 {}
161
163 LocalFunction ( const ThisType & other )
164 : basisFunctionSet_( other.basisFunctionSet_ ),
165 localDofVector_( other.localDofVector_ )
166 {}
167
173 const DofType &operator[] ( SizeType num ) const { return localDofVector_[ num ]; }
174
180 DofType &operator[] ( SizeType num ) { return localDofVector_[ num ]; }
181
182 using BaseType :: operator +=;
183 using BaseType :: operator -=;
184 using BaseType :: operator *=;
185 using BaseType :: operator /=;
186
191 template< class T >
193 {
194 localDofVector() = other.localDofVector();
195 }
196
198 void clear ()
199 {
200 std::fill( localDofVector().begin(), localDofVector().end(), DofType( 0 ) );
201 }
202
203#if 0
214 template< class T >
215 ThisType &axpy ( const RangeFieldType s, const LocalFunction< BasisFunctionSet, T > &other )
216 {
217 localDofVector().axpy( s, other.localDofVector() );
218 return *this;
219 }
220#endif
221 using BaseType :: axpy;
222
235 template< class PointType >
236 void axpy ( const PointType &x, const RangeType &factor )
237 {
238 basisFunctionSet().axpy( x, factor, localDofVector() );
239 }
240
253 template< class PointType >
254 void axpy ( const PointType &x, const JacobianRangeType &factor)
255 {
256 basisFunctionSet().axpy( x, factor, localDofVector() );
257 }
258 template< class PointType >
259 void axpy ( const PointType &x, const HessianRangeType &factor)
260 {
261 basisFunctionSet().axpy( x, factor, localDofVector() );
262 }
263
277 template< class PointType >
278 void axpy ( const PointType &x, const RangeType &factor1, const JacobianRangeType &factor2 )
279 {
280 basisFunctionSet().axpy( x, factor1, factor2, localDofVector() );
281 }
282
293 int order () const { return basisFunctionSet().order(); }
294
299 const BasisFunctionSetType &basisFunctionSet () const { return basisFunctionSet_; }
300
305 const EntityType &entity () const { return basisFunctionSet().entity(); }
306
311 const Geometry &geometry () const { return basisFunctionSet().geometry(); }
312
313
319 template< class PointType >
320 void evaluate ( const PointType &x, RangeType &ret ) const
321 {
323 }
324
333 template< class PointType >
334 void jacobian ( const PointType &x, JacobianRangeType &ret ) const
335 {
337 }
338
347 template< class PointType >
348 void hessian ( const PointType &x, HessianRangeType &ret ) const
349 {
351 }
352
360 int numDofs () const { return localDofVector().size(); }
361
369 SizeType size () const { return localDofVector().size(); }
370
373 template< class QuadratureType, class ... Vectors >
374 void axpyQuadrature ( const QuadratureType &quad, const Vectors& ... values )
375 {
376 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
377 std::ignore =
378 std::make_tuple( ( basisFunctionSet().axpy( quad, values, localDofVector() ), 1 )...);
379 }
380
383 template< class QuadratureType, class RangeVectorType, class JacobianRangeVectorType >
384 void axpyQuadrature ( const QuadratureType &quad,
385 const RangeVectorType& rangeVector,
386 const JacobianRangeVectorType& jacobianVector )
387 {
388 basisFunctionSet().axpy( quad, rangeVector, jacobianVector, localDofVector() );
389 }
390
392 template< class QuadratureType, class ... Vectors >
393 void evaluateQuadrature( const QuadratureType &quad, Vectors& ... vec ) const
394 {
395 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
396 std::ignore =
397 std::make_tuple( ( evaluateQuadrature( quad, vec, typename std::decay< decltype( vec[ 0 ] ) >::type() ), 1 )
398 ... );
399 }
400
403 template< class QuadratureType, class ... Vectors >
404 void jacobianQuadrature( const QuadratureType &quad, Vectors& ... vec ) const
405 {
406 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
407 std::ignore =
408 std::make_tuple( ( evaluateQuadrature( quad, vec, typename std::decay< decltype( vec[ 0 ] ) >::type() ), 1 )
409 ... );
410 }
411
413 template< class QuadratureType, class ... Vectors >
414 void hessianQuadrature( const QuadratureType &quad, Vectors& ... vec ) const
415 {
416 // make sure vec size if large enough
417 static_assert( sizeof...( Vectors ) > 0, "evaluateQuadrature needs to be called with at least one vector." );
418 std::ignore =
419 std::make_tuple( ( evaluateQuadrature( quad, vec, typename std::decay< decltype( vec[ 0 ] ) >::type() ), 1 )
420 ... );
421 }
422
424 const LocalDofVectorType &localDofVector () const { return localDofVector_; }
425
427 LocalDofVectorType &localDofVector () { return localDofVector_; }
428
429
432 bool valid () const
433 {
434 return basisFunctionSet_.valid();
435 }
436
437 protected:
446 void init ( const EntityType& entity )
447 {
448 DUNE_THROW(NotImplemented,"LocalFunction::init( entity ) must be overloaded on derived class!");
449 }
450
459 void bind ( const EntityType& entity )
460 {
461 DUNE_THROW(NotImplemented,"LocalFunction::bind( entity ) must be overloaded on derived class!");
462 }
463
467 void unbind ()
468 {
469 // basically sets entity pointer inside basis function set to nullptr
470 basisFunctionSet_ = BasisFunctionSetType();
471 }
472
486 {
487 basisFunctionSet_ = basisFunctionSet;
488 localDofVector_.resize( basisFunctionSet.size() );
489 }
490
491 // evaluate local function and store results in vector of RangeTypes
492 // 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 RangeType & ) const
496 {
497 basisFunctionSet().evaluateAll( 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 JacobianRangeType & ) const
505 {
506 basisFunctionSet().jacobianAll( quad, localDofVector(), result );
507 }
508
509 // evaluate jacobian of local function and store result in vector of
510 // JacobianRangeTypes, this method only helps to identify the correct method on
511 // the basis function set
512 template< class QuadratureType, class VectorType >
513 void evaluateQuadrature( const QuadratureType &quad, VectorType &result, const HessianRangeType & ) const
514 {
515 basisFunctionSet().hessianAll( quad, localDofVector(), result );
516 }
517
518 BasisFunctionSetType basisFunctionSet_;
519 LocalDofVectorType localDofVector_;
520 };
521
524 } // end namespace Fem
525
526} // end namespace Dune
527
528#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
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:100
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:424
void evaluate(const PointType &x, RangeType &ret) const
evaluate the local function
Definition: localfunction.hh:320
LocalFunction(ThisType &&other)
move constructor
Definition: localfunction.hh:157
void init(const EntityType &entity)
initialize the local function for an entity
Definition: localfunction.hh:446
FunctionSpaceType::DomainType DomainType
type of domain vectors, i.e., type of coordinates
Definition: localfunction.hh:108
void bind(const EntityType &entity)
initialize the local function for an entity
Definition: localfunction.hh:459
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:393
static const int dimDomain
dimension of the domain
Definition: localfunction.hh:120
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:414
const Geometry & geometry() const
obtain the geometry, this local function lives on
Definition: localfunction.hh:311
int numDofs() const
obtain the number of local DoFs
Definition: localfunction.hh:360
EntityType::Geometry Geometry
type of the geometry, the local function lives on is given by the space
Definition: localfunction.hh:98
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:348
const EntityType & entity() const
obtain the entity, this local function lives on
Definition: localfunction.hh:305
LocalDofVectorType::value_type DofType
type of DoF use with the discrete function
Definition: localfunction.hh:89
void init(const BasisFunctionSetType &basisFunctionSet)
initialize the local function for an basisFunctionSet
Definition: localfunction.hh:485
void axpy(const PointType &x, const RangeType &factor1, const JacobianRangeType &factor2)
axpy operation for local function
Definition: localfunction.hh:278
FunctionSpaceType::RangeType RangeType
type of range vectors, i.e., type of function values
Definition: localfunction.hh:110
LocalFunction(const BasisFunctionSetType &basisFunctionSet, LocalDofVector &&localDofVector)
half move ctor
Definition: localfunction.hh:149
FunctionSpaceType::DomainFieldType DomainFieldType
field type of the domain
Definition: localfunction.hh:104
LocalFunction(const BasisFunctionSetType &basisFunctionSet, const LocalDofVector &localDofVector)
copy given agruments
Definition: localfunction.hh:138
FunctionSpaceType::HessianRangeType HessianRangeType
type of the Hessian
Definition: localfunction.hh:114
void axpy(const PointType &x, const RangeType &factor)
axpy operation for local function
Definition: localfunction.hh:236
bool valid() const
Returns true if local function if bind or init was previously called.
Definition: localfunction.hh:432
BasisFunctionSetType::FunctionSpaceType FunctionSpaceType
type of functionspace
Definition: localfunction.hh:101
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:384
void jacobian(const PointType &x, JacobianRangeType &ret) const
evaluate Jacobian of the local function
Definition: localfunction.hh:334
Geometry::LocalCoordinate LocalCoordinateType
type of local coordinates
Definition: localfunction.hh:117
LocalFunction(const ThisType &other)
copy constructor
Definition: localfunction.hh:163
FunctionSpaceType::JacobianRangeType JacobianRangeType
type of the Jacobian, i.e., type of evaluated Jacobian matrix
Definition: localfunction.hh:112
static const int dimRange
dimension of the range
Definition: localfunction.hh:122
void unbind()
clears the local function by removing the basisFunctionSet
Definition: localfunction.hh:467
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:374
const DofType & operator[](SizeType num) const
access to local dofs (read-only)
Definition: localfunction.hh:173
FunctionSpaceType::RangeFieldType RangeFieldType
field type of the range
Definition: localfunction.hh:106
int order() const
obtain the order of this local function
Definition: localfunction.hh:293
void axpy(const PointType &x, const JacobianRangeType &factor)
axpy operation for local function
Definition: localfunction.hh:254
LocalFunction(const BasisFunctionSetType &basisFunctionSet)
ctor taking a basisFunctionSet, calling default ctor for LocalDofVectorType, and resize
Definition: localfunction.hh:128
LocalDofVectorType::size_type SizeType
type of index
Definition: localfunction.hh:92
void clear()
set all DoFs to zero
Definition: localfunction.hh:198
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:146
LocalDofVectorType & localDofVector()
return mutable reference to local Dof Vector
Definition: localfunction.hh:427
LocalFunction()
default constructor, calls default ctor of BasisFunctionSetType and LocalDofVectorType
Definition: localfunction.hh:125
LocalFunction(const LocalDofVectorType &localDofVector)
ctor taking a localDofVector, calling default ctor for BasisFunctionSetType
Definition: localfunction.hh:135
void assign(const LocalFunction< BasisFunctionSet, T > &other)
assign all DoFs of this local function
Definition: localfunction.hh:192
const BasisFunctionSetType & basisFunctionSet() const
obtain the basis function set for this local function
Definition: localfunction.hh:299
LocalDofVector LocalDofVectorType
type of local Dof Vector
Definition: localfunction.hh:86
SizeType size() const
obtain the number of local DoFs
Definition: localfunction.hh:369
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:404
vector space out of a tensor product of fields.
Definition: fvector.hh:91
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 (Nov 13, 23:29, 2024)