dune-geometry  2.2.0
mapping.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH
00002 #define DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH
00003 
00004 #include <dune/geometry/genericgeometry/topologytypes.hh>
00005 #include <dune/geometry/genericgeometry/referenceelements.hh>
00006 #include <dune/geometry/genericgeometry/matrixhelper.hh>
00007 #include <dune/geometry/genericgeometry/geometrytraits.hh>
00008 
00009 namespace Dune
00010 {
00011 
00012   namespace GenericGeometry
00013   {
00014 
00015     // Mapping
00016     // -------
00017 
00027     template< class CoordTraits, class Topo, int dimW, class Impl >
00028     class Mapping
00029     {
00030       typedef Mapping< CoordTraits, Topo, dimW, Impl > This;
00031 
00032       typedef Impl Implementation;
00033 
00034     public:
00035       typedef Topo Topology;
00036       typedef MappingTraits< CoordTraits, Topology :: dimension, dimW > Traits;
00037      
00038       static const unsigned int dimension = Traits :: dimension;
00039       static const unsigned int dimWorld = Traits :: dimWorld;
00040 
00041       typedef typename Traits :: FieldType FieldType;           
00042       typedef typename Traits :: LocalCoordinate LocalCoordinate;
00043       typedef typename Traits :: GlobalCoordinate GlobalCoordinate;
00044       typedef typename Traits :: JacobianType JacobianType;
00045       typedef typename Traits :: JacobianTransposedType JacobianTransposedType;
00046 
00047       typedef typename Traits :: MatrixHelper MatrixHelper;
00048 
00049       typedef GenericGeometry :: ReferenceElement< Topology, FieldType > ReferenceElement;
00050 
00051       template< unsigned int codim, unsigned int i >
00052       struct SubTopology
00053       {
00054         typedef typename GenericGeometry :: SubTopology< Topo, codim, i > :: type Topology;
00055         typedef typename Implementation :: template SubTopology< codim, i > :: Trace TraceImpl;
00056         typedef Mapping< CoordTraits, Topology, dimWorld, TraceImpl > Trace;
00057       };
00058 
00059       static const bool alwaysAffine = Implementation :: alwaysAffine;
00060 
00061     protected:
00062       Implementation impl_;
00063      
00064     public:
00065       template< class CoordVector >
00066       explicit Mapping ( const CoordVector &coords )
00067       : impl_( coords )
00068       {}
00069 
00070       Mapping ( const Implementation &implementation )
00071       : impl_( implementation )
00072       {}
00073 
00074       const GlobalCoordinate &corner ( int i ) const
00075       {
00076         return implementation().corner( i );
00077       }
00078 
00079       void global ( const LocalCoordinate &x, GlobalCoordinate &y ) const
00080       {
00081         implementation().global( x, y );
00082       }
00083 
00084       void local ( const GlobalCoordinate &y, LocalCoordinate &x ) const
00085       {
00086         const FieldType epsilon = CoordTraits::epsilon();
00087         x = ReferenceElement::template baryCenter< 0 >( 0 );
00088         LocalCoordinate dx;
00089         do
00090         {
00091           // DF^n dx^n = F^n, x^{n+1} -= dx^n
00092           JacobianTransposedType JT;
00093           jacobianTransposed( x, JT );
00094           GlobalCoordinate z;
00095           global( x, z );
00096           z -= y;
00097           MatrixHelper::template xTRightInvA< dimension, dimWorld >( JT, z, dx );
00098           x -= dx;
00099         } while( dx.two_norm2() > epsilon*epsilon );
00100       }
00101 
00102       bool jacobianTransposed ( const LocalCoordinate &x,
00103                                 JacobianTransposedType &JT ) const
00104       {
00105         return implementation().jacobianTransposed( x, JT );
00106       }
00107 
00108       FieldType
00109       jacobianInverseTransposed ( const LocalCoordinate &x, JacobianType &JTInv ) const
00110       {
00111         JacobianTransposedType JT;
00112         jacobianTransposed( x, JT );
00113         return MatrixHelper :: template rightInvA< dimension, dimWorld >( JT, JTInv );
00114       }
00115 
00116       FieldType integrationElement ( const LocalCoordinate &x ) const
00117       {
00118         JacobianTransposedType JT;
00119         jacobianTransposed( x, JT );
00120         return MatrixHelper :: template sqrtDetAAT< dimension, dimWorld >( JT );
00121       }
00122 
00123       const Implementation &implementation () const
00124       {
00125         return impl_;
00126       }
00127 
00128       template< unsigned int codim, unsigned int i >
00129       typename SubTopology< codim, i > :: Trace trace () const
00130       {
00131         return impl_.template trace< codim, i >();
00132       }
00133     };
00134 
00135   }
00136 
00137 }
00138 
00139 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPING_HH