dune-geometry  2.2.1
mapping.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH
2 #define DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH
3 
8 
9 namespace Dune
10 {
11 
12  namespace GenericGeometry
13  {
14 
15  // Mapping
16  // -------
17 
27  template< class CoordTraits, class Topo, int dimW, class Impl >
28  class Mapping
29  {
31 
32  typedef Impl Implementation;
33 
34  public:
35  typedef Topo Topology;
37 
38  static const unsigned int dimension = Traits :: dimension;
39  static const unsigned int dimWorld = Traits :: dimWorld;
40 
41  typedef typename Traits :: FieldType FieldType;
46 
48 
50 
51  template< unsigned int codim, unsigned int i >
52  struct SubTopology
53  {
55  typedef typename Implementation :: template SubTopology< codim, i > :: Trace TraceImpl;
57  };
58 
59  static const bool alwaysAffine = Implementation :: alwaysAffine;
60 
61  protected:
62  Implementation impl_;
63 
64  public:
65  template< class CoordVector >
66  explicit Mapping ( const CoordVector &coords )
67  : impl_( coords )
68  {}
69 
70  Mapping ( const Implementation &implementation )
71  : impl_( implementation )
72  {}
73 
74  const GlobalCoordinate &corner ( int i ) const
75  {
76  return implementation().corner( i );
77  }
78 
79  void global ( const LocalCoordinate &x, GlobalCoordinate &y ) const
80  {
81  implementation().global( x, y );
82  }
83 
84  void local ( const GlobalCoordinate &y, LocalCoordinate &x ) const
85  {
86  const FieldType epsilon = CoordTraits::epsilon();
87  x = ReferenceElement::template baryCenter< 0 >( 0 );
88  LocalCoordinate dx;
89  do
90  {
91  // DF^n dx^n = F^n, x^{n+1} -= dx^n
93  jacobianTransposed( x, JT );
95  global( x, z );
96  z -= y;
97  MatrixHelper::template xTRightInvA< dimension, dimWorld >( JT, z, dx );
98  x -= dx;
99  } while( dx.two_norm2() > epsilon*epsilon );
100  }
101 
103  JacobianTransposedType &JT ) const
104  {
105  return implementation().jacobianTransposed( x, JT );
106  }
107 
108  FieldType
110  {
112  jacobianTransposed( x, JT );
113  return MatrixHelper :: template rightInvA< dimension, dimWorld >( JT, JTInv );
114  }
115 
117  {
119  jacobianTransposed( x, JT );
120  return MatrixHelper :: template sqrtDetAAT< dimension, dimWorld >( JT );
121  }
122 
123  const Implementation &implementation () const
124  {
125  return impl_;
126  }
127 
128  template< unsigned int codim, unsigned int i >
129  typename SubTopology< codim, i > :: Trace trace () const
130  {
131  return impl_.template trace< codim, i >();
132  }
133  };
134 
135  }
136 
137 }
138 
139 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH