dune-geometry  2.3.1
affinegeometry.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOMETRY_AFFINEGEOMETRY_HH
4 #define DUNE_GEOMETRY_AFFINEGEOMETRY_HH
5 
11 #include <dune/common/fmatrix.hh>
12 #include <dune/common/fvector.hh>
13 
14 #include <dune/geometry/type.hh>
17 
18 namespace Dune
19 {
20 
21  // External Forward Declarations
22  // -----------------------------
23 
24  template< class ctype, int dim >
25  class ReferenceElement;
26 
27  template< class ctype, int dim >
28  struct ReferenceElements;
29 
30 
31 
37  template< class ct, int mydim, int cdim>
39  {
40  public:
41 
43  typedef ct ctype;
44 
46  static const int mydimension= mydim;
47 
49  static const int coorddimension = cdim;
50 
52  typedef FieldVector< ctype, mydimension > LocalCoordinate;
53 
55  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
56 
58  typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
59 
61  typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
62 
65 
66  private:
69 
71 
72  // Helper class to compute a matrix pseudo inverse
74 
75  public:
77  AffineGeometry ( const ReferenceElement &refElement, const GlobalCoordinate &origin,
78  const JacobianTransposed &jt )
79  : refElement_(&refElement), origin_(origin), jacobianTransposed_(jt)
80  {
81  integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
82  }
83 
86  const JacobianTransposed &jt )
87  : refElement_( &ReferenceElements::general( gt ) ), origin_(origin), jacobianTransposed_( jt )
88  {
89  integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
90  }
91 
93  template< class CoordVector >
94  AffineGeometry ( const ReferenceElement &refElement, const CoordVector &coordVector )
95  : refElement_(&refElement), origin_(coordVector[0])
96  {
97  for( int i = 0; i < mydimension; ++i )
98  jacobianTransposed_[ i ] = coordVector[ i+1 ] - origin_;
99  integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
100  }
101 
103  template< class CoordVector >
104  AffineGeometry ( Dune::GeometryType gt, const CoordVector &coordVector )
105  : refElement_(&ReferenceElements::general( gt )), origin_(coordVector[0] )
106  {
107  for( int i = 0; i < mydimension; ++i )
108  jacobianTransposed_[ i ] = coordVector[ i+1 ] - origin_;
109  integrationElement_ = MatrixHelper::template rightInvA< mydimension, coorddimension >( jacobianTransposed_, jacobianInverseTransposed_ );
110  }
111 
113  bool affine () const { return true; }
114 
116  Dune::GeometryType type () const { return refElement_->type(); }
117 
119  int corners () const { return refElement_->size( mydimension ); }
120 
122  GlobalCoordinate corner ( int i ) const
123  {
124  return global( refElement_->position( i, mydimension ) );
125  }
126 
128  GlobalCoordinate center () const { return global( refElement_->position( 0, 0 ) ); }
129 
137  {
138  GlobalCoordinate global( origin_ );
139  jacobianTransposed_.umtv( local, global );
140  return global;
141  }
142 
155  {
157  jacobianInverseTransposed_.mtv( global - origin_, local );
158  return local;
159  }
160 
172  {
173  DUNE_UNUSED_PARAMETER(local);
174  return integrationElement_;
175  }
176 
178  ctype volume () const
179  {
180  return integrationElement_ * refElement_->volume();
181  }
182 
190  {
191  DUNE_UNUSED_PARAMETER(local);
192  return jacobianTransposed_;
193  }
194 
202  {
203  DUNE_UNUSED_PARAMETER(local);
204  return jacobianInverseTransposed_;
205  }
206 
207  private:
208  const ReferenceElement* refElement_;
209  GlobalCoordinate origin_;
210  JacobianTransposed jacobianTransposed_;
211  JacobianInverseTransposed jacobianInverseTransposed_;
212  ctype integrationElement_;
213 
214  };
215 
216 } // namespace Dune
217 
218 #endif // #ifndef DUNE_GEOMETRY_AFFINEGEOMETRY_HH