dune-geometry  2.3beta2
mapping.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_GENERICGEOMETRY_MAPPING_HH
4 #define DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH
5 
10 
11 namespace Dune
12 {
13 
14  namespace GenericGeometry
15  {
16 
17  // Mapping
18  // -------
19 
29  template< class CoordTraits, class Topo, int dimW, class Impl >
30  class Mapping
31  {
33 
34  typedef Impl Implementation;
35 
36  public:
37  typedef Topo Topology;
39 
40  static const unsigned int dimension = Traits :: dimension;
41  static const unsigned int dimWorld = Traits :: dimWorld;
42 
43  typedef typename Traits :: FieldType FieldType;
48 
50 
52 
53  template< unsigned int codim, unsigned int i >
54  struct SubTopology
55  {
57  typedef typename Implementation :: template SubTopology< codim, i > :: Trace TraceImpl;
59  };
60 
62 
63  protected:
64  Implementation impl_;
65 
66  public:
67  template< class CoordVector >
68  explicit Mapping ( const CoordVector &coords )
69  : impl_( coords )
70  {}
71 
72  Mapping ( const Implementation &implementation )
73  : impl_( implementation )
74  {}
75 
76  const GlobalCoordinate &corner ( int i ) const
77  {
78  return implementation().corner( i );
79  }
80 
81  void global ( const LocalCoordinate &x, GlobalCoordinate &y ) const
82  {
83  implementation().global( x, y );
84  }
85 
86  void local ( const GlobalCoordinate &y, LocalCoordinate &x ) const
87  {
88  const FieldType epsilon = CoordTraits::epsilon();
90  LocalCoordinate dx;
91  do
92  {
93  // DF^n dx^n = F^n, x^{n+1} -= dx^n
95  jacobianTransposed( x, JT );
97  global( x, z );
98  z -= y;
99  MatrixHelper::template xTRightInvA< dimension, dimWorld >( JT, z, dx );
100  x -= dx;
101  } while( dx.two_norm2() > epsilon*epsilon );
102  }
103 
105  JacobianTransposedType &JT ) const
106  {
107  return implementation().jacobianTransposed( x, JT );
108  }
109 
110  FieldType
112  {
114  jacobianTransposed( x, JT );
115  return MatrixHelper :: template rightInvA< dimension, dimWorld >( JT, JTInv );
116  }
117 
119  {
121  jacobianTransposed( x, JT );
122  return MatrixHelper :: template sqrtDetAAT< dimension, dimWorld >( JT );
123  }
124 
125  const Implementation &implementation () const
126  {
127  return impl_;
128  }
129 
130  template< unsigned int codim, unsigned int i >
131  typename SubTopology< codim, i > :: Trace trace () const
132  {
133  return impl_.template trace< codim, i >();
134  }
135  };
136 
137  }
138 
139 }
140 
141 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH