common/geometry.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GRID_GEOMETRY_HH
00002 #define DUNE_GRID_GEOMETRY_HH
00003 
00008 #include <cassert>
00009 
00010 #include <dune/common/fmatrix.hh>
00011 #include <dune/common/exceptions.hh>
00012 
00013 #include <dune/grid/common/genericreferenceelements.hh>
00014 #include <dune/grid/genericgeometry/conversion.hh>
00015 
00016 namespace Dune
00017 {
00018 
00019 // External Forward Declarations
00020 // -----------------------------
00021 
00022 template< int dim, int dimworld, class ct, class GridFamily >
00023 class GridDefaultImplementation;
00024 
00025 
00026 
00027 //*****************************************************************************
00028 //
00029 // Geometry
00030 // forwards the interface to the implementation
00031 //
00032 //*****************************************************************************
00033 
00066 template<int mydim, int cdim, class GridImp, template<int,int,class> class GeometryImp>  
00067 class Geometry {
00068 
00069 protected:
00070   GeometryImp<mydim,cdim,GridImp> realGeometry;
00071   
00072   // type of underlying implementation, for internal use only 
00073   typedef GeometryImp<mydim,cdim,GridImp> ImplementationType;
00074 public:
00076   enum { dimension=GridImp::dimension  };
00078   enum { mydimension=mydim  };
00080   enum { coorddimension=cdim  };
00081 
00083   enum { dimensionworld=GridImp::dimensionworld  };
00085   typedef typename GridImp::ctype ctype;
00086 
00088   typedef FieldVector<ctype, mydim> LocalCoordinate;
00089 
00091   typedef FieldVector< ctype, cdim > GlobalCoordinate;
00092   
00094   typedef FieldMatrix<ctype,cdim,mydim> Jacobian;
00095 
00097   typedef FieldMatrix< ctype, mydim, cdim > JacobianTransposed;
00098 
00102   GeometryType type () const { return realGeometry.type(); }
00103 
00105   bool affine() const { return realGeometry.affine(); }
00106 
00113   int corners () const { return realGeometry.corners(); }
00114 
00127   GlobalCoordinate corner ( int i ) const
00128   {
00129     return realGeometry.corner(i);
00130   }
00131 
00136   GlobalCoordinate global (const LocalCoordinate& local) const
00137     {
00138       return realGeometry.global(local);
00139     }
00140 
00145   LocalCoordinate local (const GlobalCoordinate& global) const
00146     {
00147       return realGeometry.local(global);
00148     }
00149 
00173   ctype integrationElement (const LocalCoordinate& local) const
00174   {
00175     return realGeometry.integrationElement(local);
00176   }
00177  
00179   ctype volume () const
00180   {
00181     return realGeometry.volume();
00182   }
00183 
00194   GlobalCoordinate center () const
00195   {
00196     return realGeometry.center();
00197   }
00198 
00208   const JacobianTransposed &
00209   jacobianTransposed ( const LocalCoordinate& local ) const
00210   {
00211     return realGeometry.jacobianTransposed( local );
00212   }
00213 
00233   const Jacobian& jacobianInverseTransposed (const LocalCoordinate& local) const
00234   {
00235     return realGeometry.jacobianInverseTransposed(local);
00236   }
00237 
00238 public:    
00240   explicit Geometry(const GeometryImp<mydim,cdim,GridImp> & e) : realGeometry(e) {};
00241   
00242 protected:
00243   // give the GridDefaultImplementation class access to the realImp 
00244   friend class GridDefaultImplementation< 
00245             GridImp::dimension, GridImp::dimensionworld,
00246             typename GridImp::ctype,
00247             typename GridImp::GridFamily> ;
00248 
00250   GeometryImp<mydim,cdim,GridImp> & getRealImp() { return realGeometry; }
00252   const GeometryImp<mydim,cdim,GridImp> & getRealImp() const { return realGeometry; }
00253  
00254 protected:  
00256   Geometry(const Geometry& rhs) : realGeometry(rhs.realGeometry) {};
00258   Geometry & operator = (const Geometry& rhs) {
00259     realGeometry = rhs.realGeometry;
00260     return *this;
00261   };
00262 };
00263 
00264 
00265 //************************************************************************
00266 // GEOMETRY Default Implementations
00267 //*************************************************************************
00268 //
00269 // --GeometryDefault 
00270 // 
00272 template<int mydim, int cdim, class GridImp, template<int,int,class> class GeometryImp>  
00273 class GeometryDefaultImplementation
00274 {
00275 public:
00276   // save typing
00277   typedef typename GridImp::ctype ctype;
00278  
00280   ctype volume () const 
00281   {
00282     GeometryType type = asImp().type();
00283 
00284     // get corresponding reference element
00285     const GenericReferenceElement< ctype , mydim > & refElement =
00286       GenericReferenceElements< ctype, mydim >::general(type);
00287 
00288     FieldVector<ctype,mydim> localBaryCenter (0.0);
00289     // calculate local bary center 
00290     const int corners = refElement.size(0,0,mydim);
00291     for(int i=0; i<corners; ++i) localBaryCenter += refElement.position(i,mydim);
00292     localBaryCenter *= (ctype) (1.0/corners);
00293 
00294     // volume is volume of reference element times integrationElement
00295     return refElement.volume() * asImp().integrationElement(localBaryCenter);
00296   }
00297   
00299   FieldVector<ctype, cdim> center () const 
00300   {
00301     GeometryType type = asImp().type();
00302 
00303     // get corresponding reference element
00304     const GenericReferenceElement< ctype , mydim > & refElement =
00305       GenericReferenceElements< ctype, mydim >::general(type);
00306 
00307     // center is (for now) the centroid of the reference element mapped to
00308     // this geometry.
00309     return asImp().global(refElement.position(0,0));
00310   }
00311   
00312 private:
00314   GeometryImp<mydim,cdim,GridImp>& asImp () {return static_cast<GeometryImp<mydim,cdim,GridImp>&>(*this);}
00315   const GeometryImp<mydim,cdim,GridImp>& asImp () const {return static_cast<const GeometryImp<mydim,cdim,GridImp>&>(*this);}
00316 }; // end GeometryDefault 
00317 
00318 template<int cdim, class GridImp, template<int,int,class> class GeometryImp>  
00319 class GeometryDefaultImplementation<0,cdim,GridImp,GeometryImp>
00320 {
00321   // my dimension 
00322   enum { mydim = 0 };
00323 public:
00324   // save typing
00325   typedef typename GridImp::ctype ctype;
00326 
00328   FieldVector<ctype, cdim> global (const FieldVector<ctype, mydim>& local) const
00329   {
00330       return asImp().corner(0);
00331   }
00332 
00334   FieldVector<ctype, mydim> local (const FieldVector<ctype, cdim>& ) const
00335   {
00336     return FieldVector<ctype, mydim>();
00337   }
00338  
00340   bool checkInside (const FieldVector<ctype, mydim>& ) const
00341   {
00342     return true; 
00343   }
00344  
00346   ctype volume () const
00347   {
00348     return 1.0;
00349   }
00350 
00352   FieldVector<ctype, cdim> center () const 
00353   {
00354       return asImp().corner(0);
00355   }
00356   
00357 private:
00359   GeometryImp<mydim,cdim,GridImp>& asImp () {return static_cast<GeometryImp<mydim,cdim,GridImp>&>(*this);}
00360   const GeometryImp<mydim,cdim,GridImp>& asImp () const {return static_cast<const GeometryImp<mydim,cdim,GridImp>&>(*this);}
00361 }; // end GeometryDefault 
00362 
00363 }
00364 #endif // DUNE_GRID_GEOMETRY_HH

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].