DUNE-FEM (unstable)

simplegeometry.hh
1#ifndef DUNE_FEM_GRIDPART_COMMON_SIMPLEGEOMETRY_HH
2#define DUNE_FEM_GRIDPART_COMMON_SIMPLEGEOMETRY_HH
3
4#include <type_traits>
5#include <utility>
6
9
11#include <dune/geometry/referenceelements.hh>
12
14
15#include <dune/fem/common/fmatrixcol.hh>
16
17namespace Dune
18{
19
20 // SimpleGeometry
21 // --------------
22
23 template< class BasicGeometry >
24 struct SimpleGeometry
25 : public BasicGeometry
26 {
27 typedef typename BasicGeometry::ctype ctype;
28
29 using BasicGeometry::mydimension;
30 using BasicGeometry::coorddimension;
31
32 using BasicGeometry::global;
33 using BasicGeometry::jacobianTransposed;
34 using BasicGeometry::quadrature;
35 using BasicGeometry::type;
36
37 typedef FieldVector< ctype, mydimension > LocalCoordinate;
38 typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
39
41 typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
42
43 typedef JacobianInverseTransposed Jacobian;
44 typedef JacobianTransposed JacobianInverse;
45
46 // Helper class to compute a matrix pseudo inverse
47 typedef Impl::FieldMatrixHelper< ctype > MatrixHelper;
48
49 template< class... Args, std::enable_if_t< std::is_constructible< BasicGeometry, Args &&... >::value, int > = 0 >
50 SimpleGeometry ( Args &&...args )
51 : BasicGeometry( std::forward< Args >( args )... )
52 {}
53
54 int corners () const { return referenceElement().size( mydimension ); }
55 GlobalCoordinate corner ( int i ) const { return global( referenceElement().position( i, mydimension ) ); }
56
57 bool affine () const { return false; }
58
59 LocalCoordinate local ( const GlobalCoordinate &global ) const
60 {
61 const ctype tolerance = 1e-12; // use something better here e.g. Traits::tolerance();
62 LocalCoordinate local = referenceElement().position( 0, 0 );
63 LocalCoordinate dlocal;
64 do
65 {
66 // Newton's method: DF^n dx^n = F^n, x^{n+1} -= dx^n
67 const GlobalCoordinate dglobal = this->global( local ) - global;
68 MatrixHelper::template xTRightInvA< mydimension, coorddimension >( jacobianTransposed( local ), dglobal, dlocal );
69 local -= dlocal;
70 assert( referenceElement().checkInside( local ) );
71 }
72 while( dlocal.two_norm2() > tolerance );
73 return local;
74 }
75
76 ctype integrationElement ( const LocalCoordinate &local ) const
77 {
78 return MatrixHelper::template sqrtDetAAT< mydimension, coorddimension >( jacobianTransposed( local ) );
79 }
80
81 JacobianInverseTransposed jacobianInverseTransposed ( const LocalCoordinate &local ) const
82 {
83 JacobianInverseTransposed jacInverseTransposed( 0 );
84 MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed( local ), jacInverseTransposed );
85 return jacInverseTransposed;
86 }
87
88 Jacobian jacobian ( const LocalCoordinate &local ) const
89 {
90 return transpose( jacobianTransposed( local ) );
91 }
92
93 JacobianInverse jacobianInverse ( const LocalCoordinate &local ) const
94 {
95 return transpose( jacobianInverseTransposed( local ) );
96 }
97
98 GlobalCoordinate center () const
99 {
100 GlobalCoordinate center( 0 );
101 ctype volume( 0 );
102 for( const auto &qp : quadrature( 0 ) )
103 {
104 const ctype weight = qp.weight() * integrationElement( qp.position() );
105 center.axpy( weight, global( qp.position() ) );
106 volume += weight;
107 }
108 return center /= volume;
109 }
110
111 ctype volume () const
112 {
113 ctype volume( 0 );
114 for( const auto &qp : quadrature( 0 ) )
115 volume += qp.weight() * integrationElement( qp.position() );
116 return volume;
117 }
118
119 auto referenceElement () const { return Dune::referenceElement<double>( type(), Dune::Dim<mydimension>() ); }
120 };
121
122} // namespace Dune
123
124#endif // #ifndef DUNE_FEM_GRIDPART_COMMON_SIMPLEGEOMETRY_HH
An implementation of the Geometry interface for affine geometries.
Wrapper and interface classes for element geometries.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
Dune namespace.
Definition: alignedallocator.hh:13
auto transpose(const Matrix &matrix)
Return the transposed of the given matrix.
Definition: transpose.hh:183
STL namespace.
Static tag representing a dimension.
Definition: dimension.hh:16
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)