dune-grid  2.1.1
hybridmapping.hh
Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 
00004 #ifndef DUNE_GENERICGEOMETRY_HYBRIDMAPPING_HH
00005 #define DUNE_GENERICGEOMETRY_HYBRIDMAPPING_HH
00006 
00007 #include <dune/common/typetraits.hh>
00008 
00009 #include <dune/grid/genericgeometry/geometrytraits.hh>
00010 #include <dune/grid/genericgeometry/cachedmapping.hh>
00011 
00012 namespace Dune
00013 {
00014 
00015   namespace GenericGeometry
00016   {
00017 
00018 
00019     // Internal Forward Declarations
00020     // -----------------------------
00021 
00022     template< unsigned int dim, class GeometryTraits >
00023     class HybridMapping;
00024 
00025     template< class Topology, class GeometryTraits >
00026     class VirtualMapping;
00027 
00028 
00029 
00030     // HybridMappingBase
00031     // -----------------
00032 
00034     template< unsigned int dim, class GeometryTraits, unsigned int codim = dim >
00035     class HybridMappingBase;
00036 
00037     template< unsigned int dim, class GeometryTraits, unsigned int codim >
00038     class HybridMappingBase
00039     : public virtual HybridMappingBase< dim, GeometryTraits, codim-1 >
00040     {
00041       typedef HybridMapping< dim, GeometryTraits > Mapping;
00042 
00043     public:
00044       virtual ~HybridMappingBase() {}
00045 
00046     protected:
00047       using HybridMappingBase< dim, GeometryTraits, codim-1 > :: trace;
00048 
00049       virtual HybridMapping< dim - codim, GeometryTraits >*
00050       trace ( integral_constant< int, codim >, unsigned int i, char *mappingStorage ) const = 0;
00051     };
00052 
00053     template< unsigned int dim, class GeometryTraits >
00054     class HybridMappingBase< dim, GeometryTraits, 0 >
00055     {
00056       typedef HybridMapping< dim, GeometryTraits > Mapping;
00057 
00058     public:
00059       virtual ~HybridMappingBase() {}
00060 
00061     protected:
00062       virtual HybridMapping< dim, GeometryTraits >*
00063       trace ( integral_constant< int, 0 >, unsigned int i, char *mappingStorage ) const = 0;
00064     };
00069     // HybridMapping
00070     // -------------
00071 
00081     template< unsigned int dim, class GeometryTraits >
00082     class HybridMapping
00084     : public virtual HybridMappingBase< dim, GeometryTraits >
00086     {
00087       typedef HybridMapping< dim, GeometryTraits > This;
00088 
00089     protected:
00090       typedef MappingTraits
00091         < typename GeometryTraits::CoordTraits, dim, GeometryTraits::dimWorld >
00092         Traits;
00093 
00094     public:
00095       static const unsigned int dimension = Traits::dimension;
00096       static const unsigned int dimWorld = Traits::dimWorld;
00097       
00098       typedef typename Traits::FieldType FieldType;
00099       typedef typename Traits::LocalCoordinate LocalCoordinate;
00100       typedef typename Traits::GlobalCoordinate GlobalCoordinate;
00101 
00102       typedef CachedJacobianTransposed< dimension, GeometryTraits > JacobianTransposed;
00103       typedef CachedJacobianInverseTransposed< dimension, GeometryTraits > JacobianInverseTransposed;
00104 
00105       template< int codim >
00106       struct Codim
00107       {
00108         typedef HybridMapping< dimension - codim, GeometryTraits > Trace;
00109       };
00110 
00111       typedef typename GeometryTraits::Caching Caching;
00112 
00113       virtual ~HybridMapping ()
00114       {}
00115 
00117       virtual unsigned int topologyId () const = 0;
00118 
00120       virtual const GlobalCoordinate &corner ( int i ) const = 0;
00121 
00123       virtual int numCorners () const = 0;
00124 
00126       virtual GlobalCoordinate center () const = 0;
00127 
00129       virtual GlobalCoordinate global ( const LocalCoordinate &x ) const = 0;
00130 
00132       virtual LocalCoordinate local ( const GlobalCoordinate &y ) const = 0;
00133 
00135       virtual bool checkInside ( const LocalCoordinate &x ) const = 0;
00136 
00138       virtual bool affine () const = 0;
00139 
00141       virtual FieldType integrationElement ( const LocalCoordinate &x ) const = 0;
00142 
00144       virtual FieldType volume () const = 0;
00145 
00147       virtual const JacobianTransposed &
00148       jacobianTransposed ( const LocalCoordinate &x ) const = 0;
00149 
00151       virtual const JacobianInverseTransposed &
00152       jacobianInverseTransposed ( const LocalCoordinate &x ) const = 0;
00153 
00154     protected:
00155       using HybridMappingBase< dim, GeometryTraits >::trace;
00156 
00157     public:
00158       virtual This *clone () const = 0;
00159       virtual This *clone ( char *mappingStorage ) const = 0;
00160 
00161       template< int codim >
00162       typename Codim< codim >::Trace* trace ( unsigned int i, char *mappingStorage ) const
00163       {
00164         integral_constant< int, codim > codimVariable;
00165         return trace( codimVariable, i, mappingStorage );
00166       }
00167     };
00168 
00169 
00170 
00171     // VirtualMappingBase
00172     // ------------------
00173 
00175     template< class Topology, class GeometryTraits, unsigned int codim = Topology :: dimension >
00176     class VirtualMappingBase;
00177 
00178     template< class Topology, class GeometryTraits, unsigned int codim >
00179     class VirtualMappingBase
00180     : public VirtualMappingBase< Topology, GeometryTraits, codim-1 >,
00181       public virtual HybridMappingBase< Topology :: dimension, GeometryTraits, codim >
00182     {
00183       typedef GenericGeometry :: VirtualMapping< Topology, GeometryTraits >
00184         VirtualMapping;
00185 
00186     protected:
00187       using VirtualMappingBase< Topology, GeometryTraits, codim-1 > :: trace;
00188 
00189       virtual HybridMapping< Topology::dimension - codim, GeometryTraits >*
00190       trace ( integral_constant< int, codim >, unsigned int i, char *mappingStorage) const
00191       {
00192         return static_cast< const VirtualMapping & >( *this ).template trace< codim >( i, mappingStorage );
00193       }
00194     };
00195 
00196     template< class Topology, class GeometryTraits >
00197     class VirtualMappingBase< Topology, GeometryTraits, 0 >
00198     : public virtual HybridMappingBase< Topology :: dimension, GeometryTraits, 0 >
00199     {
00200       typedef GenericGeometry :: VirtualMapping< Topology, GeometryTraits >
00201         VirtualMapping;
00202 
00203     protected:
00204       virtual HybridMapping< Topology::dimension, GeometryTraits >*
00205       trace ( integral_constant< int, 0 >, unsigned int i,
00206               char *mappingStorage ) const
00207       {
00208         return static_cast< const VirtualMapping & >( *this ).template trace< 0 >( i, mappingStorage );
00209       }
00210     };
00215     template< class Topology, class GeometryTraits >
00216     class VirtualMapping
00217     : public HybridMapping< Topology :: dimension, GeometryTraits >,
00219       public VirtualMappingBase< Topology, GeometryTraits >
00221     {
00222       typedef HybridMapping< Topology :: dimension, GeometryTraits > Base;
00223       typedef VirtualMapping< Topology, GeometryTraits > This;
00224 
00225       typedef typename Base :: Traits Traits;
00226       
00227       typedef CachedMapping< Topology, GeometryTraits > Mapping;
00228 
00229     public:
00230       static const unsigned int dimension = Traits :: dimension;
00231       static const unsigned int dimWorld = Traits :: dimWorld;
00232       
00233       typedef typename Traits::FieldType FieldType;
00234       typedef typename Traits::LocalCoordinate LocalCoordinate;
00235       typedef typename Traits::GlobalCoordinate GlobalCoordinate;
00236 
00237       typedef typename Base::JacobianTransposed JacobianTransposed;
00238       typedef typename Base::JacobianInverseTransposed JacobianInverseTransposed;
00239 
00240       typedef typename Mapping::ReferenceElement ReferenceElement;
00241       
00242       template< int codim >
00243       struct Codim
00244       {
00245         typedef HybridMapping< dimension - codim, GeometryTraits > Trace;
00246       };
00247 
00248       typedef typename GeometryTraits::Caching Caching;
00249 
00250     private:
00251       Mapping mapping_;
00252 
00253     public:
00254       template< class CoordVector >
00255       explicit VirtualMapping ( const CoordVector &coordVector )
00256       : mapping_( coordVector )
00257       {}
00258 
00259       virtual unsigned int topologyId () const
00260       {
00261         return mapping_.topologyId();
00262       }
00263 
00264       virtual const GlobalCoordinate &corner ( int i ) const
00265       {
00266         return mapping_.corner( i );
00267       }
00268 
00269       virtual int numCorners () const
00270       {
00271         return mapping_.numCorners();
00272       }
00273 
00274       virtual GlobalCoordinate center () const
00275       {
00276         return mapping_.center();
00277       }
00278 
00279       virtual GlobalCoordinate global ( const LocalCoordinate &local ) const
00280       {
00281         return mapping_.global( local );
00282       }
00283 
00284       virtual LocalCoordinate local ( const GlobalCoordinate &global ) const
00285       {
00286         return mapping_.local( global );
00287       }
00288 
00289       virtual bool checkInside ( const LocalCoordinate &local ) const
00290       {
00291         return mapping_.checkInside( local );
00292       }
00293 
00294       virtual bool affine () const
00295       {
00296         return mapping_.affine();
00297       }
00298 
00299       virtual FieldType integrationElement ( const LocalCoordinate &local ) const
00300       {
00301         return mapping_.integrationElement( local );
00302       }
00303 
00304       virtual FieldType volume () const
00305       {
00306         return mapping_.volume();
00307       }
00308 
00309       virtual const JacobianTransposed &
00310       jacobianTransposed ( const LocalCoordinate &local ) const
00311       {
00312         return mapping_.jacobianTransposed( local );
00313       }
00314 
00315       virtual const JacobianInverseTransposed &
00316       jacobianInverseTransposed ( const LocalCoordinate &local ) const
00317       {
00318         return mapping_.jacobianInverseTransposed( local );
00319       }
00320 
00321       virtual Base *clone () const
00322       {
00323         return new This( *this );
00324       }
00325 
00326       virtual Base* clone ( char *mappingStorage ) const
00327       {
00328         return new( mappingStorage ) This( *this );
00329       }
00330 
00331       template< int codim >
00332       typename Codim< codim >::Trace* trace ( unsigned int i, char *mappingStorage ) const
00333       {
00334         return mapping_.template trace< codim, true >( i, mappingStorage );
00335       }
00336 
00337     protected:
00338       using VirtualMappingBase< Topology, GeometryTraits > :: trace;
00339     };
00340 
00341   }
00342   
00343 }
00344 
00345 #endif // #ifndef DUNE_GENERICGEOMETRY_HYBRIDMAPPING_HH