dune-fem 2.12-git
Loading...
Searching...
No Matches
simplegeometry.hh
Go to the documentation of this file.
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
12
13#include <dune/grid/common/geometry.hh>
14
16
17namespace Dune
18{
19
20 // SimpleGeometry
21 // --------------
22
23 template< class BasicGeometry >
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
39
42
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
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
77 {
78 return MatrixHelper::template sqrtDetAAT< mydimension, coorddimension >( jacobianTransposed( local ) );
79 }
80
82 {
83 JacobianInverseTransposed jacInverseTransposed( 0 );
84 MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed( local ), jacInverseTransposed );
85 return jacInverseTransposed;
86 }
87
89 {
90 return transpose( jacobianTransposed( local ) );
91 }
92
97
99 {
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
const GlobalIndex & global() const
LocalIndex & local()
auto transpose(const Matrix &matrix)
STL namespace.
constexpr derived_type & axpy(const field_type &a, const DenseVector< Other > &x)
constexpr FieldTraits< value_type >::real_type two_norm2() const
Definition simplegeometry.hh:26
FieldVector< ctype, mydimension > LocalCoordinate
Definition simplegeometry.hh:37
SimpleGeometry(Args &&...args)
Definition simplegeometry.hh:50
JacobianTransposed JacobianInverse
Definition simplegeometry.hh:44
int corners() const
Definition simplegeometry.hh:54
Jacobian jacobian(const LocalCoordinate &local) const
Definition simplegeometry.hh:88
LocalCoordinate local(const GlobalCoordinate &global) const
Definition simplegeometry.hh:59
FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed
Definition simplegeometry.hh:41
FieldVector< ctype, coorddimension > GlobalCoordinate
Definition simplegeometry.hh:38
ctype volume() const
Definition simplegeometry.hh:111
JacobianInverseTransposed Jacobian
Definition simplegeometry.hh:43
ctype integrationElement(const LocalCoordinate &local) const
Definition simplegeometry.hh:76
JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate &local) const
Definition simplegeometry.hh:81
BasicGeometry::ctype ctype
Definition simplegeometry.hh:27
FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed
Definition simplegeometry.hh:40
auto referenceElement() const
Definition simplegeometry.hh:119
Impl::FieldMatrixHelper< ctype > MatrixHelper
Definition simplegeometry.hh:47
GlobalCoordinate center() const
Definition simplegeometry.hh:98
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
Definition simplegeometry.hh:93
bool affine() const
Definition simplegeometry.hh:57
GlobalCoordinate corner(int i) const
Definition simplegeometry.hh:55