mapping.hh

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

Generated on Tue Jul 28 22:28:19 2009 for dune-grid by  doxygen 1.5.6