dune-fem  2.8-git
compositegeometry.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_COMMON_COMPOSITEGEOMETRY_HH
2 #define DUNE_FEM_GRIDPART_COMMON_COMPOSITEGEOMETRY_HH
3 
4 #include <type_traits>
5 #include <utility>
6 
7 #include <dune/common/fmatrix.hh>
8 #include <dune/common/fvector.hh>
9 
10 #include <dune/geometry/affinegeometry.hh>
11 #include <dune/geometry/quadraturerules.hh>
12 #include <dune/geometry/type.hh>
13 
14 #include <dune/grid/common/geometry.hh>
15 
17 
18 namespace Dune
19 {
20 
21  // CompositeGeometry
22  // -----------------
23 
24  template< class Geometry, class Embedding >
26  {
27  static const int mydimension = Embedding::mydimension;
28  static const int coorddimension = Geometry::coorddimension;
29 
30  typedef typename Geometry::ctype ctype;
31  typedef FieldVector< ctype, mydimension > LocalCoordinate;
32  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
33 
34  typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
35  typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
37 
38  // Helper class to compute a matrix pseudo inverse
39  typedef Impl::FieldMatrixHelper< ctype > MatrixHelper;
40 
41  CompositeGeometry ( Geometry geometry, Embedding embedding, int order )
42  : geometry_( std::move( geometry ) ), embedding_( std::move( embedding ) ), order_( order )
43  {}
44 
45  GeometryType type () const { return embedding_.type(); }
46 
47  int corners () const { return embedding_.corners(); }
48  GlobalCoordinate corner( int i ) const { return geometry_.global( embedding_.corner( i ) ); }
49 
50  bool affine () const { return geometry_.affine() && embedding_.affine(); }
51 
52  GlobalCoordinate global ( const LocalCoordinate &local ) const { return geometry_.global( embedding_.global( local ) ); }
53  LocalCoordinate local ( const GlobalCoordinate &global ) const { return embedding_.local( geometry_.local( global ) ); }
54 
56  {
57  const FieldMatrix< ctype, mydimension, Embedding::coorddimension > jacEmbedding( embedding_.jacobianTransposed( local ) );
58  const auto jacGeometry = geometry_.jacobianTransposed( embedding_.global( local ) );
59 
60  JacobianTransposed jacTransposed( 0 );
61  for( int i = 0; i < mydimension; ++i )
62  jacGeometry.mtv( jacEmbedding[ i ], jacTransposed[ i ] );
63  return jacTransposed;
64  }
65 
67  {
68  JacobianInverseTransposed jacInverseTransposed( 0 );
69  MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed( local ), jacInverseTransposed );
70  return jacInverseTransposed;
71  }
72 
73  ctype integrationElement ( const LocalCoordinate &local ) const
74  {
75  return MatrixHelper::template sqrtDetAAT< mydimension, coorddimension >( jacobianTransposed( local ) );
76  }
77 
79  {
81  ctype volume( 0 );
82  for( const auto &qp : QuadratureRules< ctype, mydimension >::rule( type(), order_+1 ) )
83  {
84  const ctype weight = qp.weight() * integrationElement( qp.position() );
85  center.axpy( weight, global( qp.position() ) );
86  volume += weight;
87  }
88  return center /= volume;
89  }
90 
91  ctype volume () const
92  {
93  ctype volume( 0 );
94  for( const auto &qp : QuadratureRules< ctype, mydimension >::rule( type(), order_ ) )
95  volume += qp.weight() * integrationElement( qp.position() );
96  return volume;
97  }
98 
99  private:
100  Geometry geometry_;
101  Embedding embedding_;
102  int order_;
103  };
104 
105 } // namespace Dune
106 
107 #endif // #ifndef DUNE_FEM_GRIDPART_GEOMETRYGRIDPART_GEOMETRY_HH
Definition: bindguard.hh:11
Definition: compositegeometry.hh:26
Geometry::ctype ctype
Definition: compositegeometry.hh:30
GlobalCoordinate corner(int i) const
Definition: compositegeometry.hh:48
int corners() const
Definition: compositegeometry.hh:47
FieldVector< ctype, mydimension > LocalCoordinate
Definition: compositegeometry.hh:31
JacobianTransposed jacobianTransposed(const LocalCoordinate &local) const
Definition: compositegeometry.hh:55
bool affine() const
Definition: compositegeometry.hh:50
GlobalCoordinate global(const LocalCoordinate &local) const
Definition: compositegeometry.hh:52
ctype volume() const
Definition: compositegeometry.hh:91
CompositeGeometry(Geometry geometry, Embedding embedding, int order)
Definition: compositegeometry.hh:41
ctype integrationElement(const LocalCoordinate &local) const
Definition: compositegeometry.hh:73
JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate &local) const
Definition: compositegeometry.hh:66
JacobianInverseTransposed Jacobian
Definition: compositegeometry.hh:36
GlobalCoordinate center() const
Definition: compositegeometry.hh:78
static const int mydimension
Definition: compositegeometry.hh:27
FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed
Definition: compositegeometry.hh:34
FieldVector< ctype, coorddimension > GlobalCoordinate
Definition: compositegeometry.hh:32
static const int coorddimension
Definition: compositegeometry.hh:28
GeometryType type() const
Definition: compositegeometry.hh:45
Impl::FieldMatrixHelper< ctype > MatrixHelper
Definition: compositegeometry.hh:39
FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed
Definition: compositegeometry.hh:35