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/helpertemplates.hh>
00012 #include <dune/common/exceptions.hh>
00013 
00014 #include <dune/grid/genericgeometry/conversion.hh>
00015 #include "referenceelements.hh"
00016 
00017 namespace Dune
00018 {
00019 
00020  // forward deklaration for volume implementation
00021  template<typename ctype, int dim> class ReferenceElement;
00022  template<typename ctype, int dim> class ReferenceElements;
00023   
00024 //*****************************************************************************
00025 //
00026 // Geometry
00027 // forwards the interface to the implementation
00028 //
00029 //*****************************************************************************
00030 
00065 template<int mydim, int cdim, class GridImp, template<int,int,class> class GeometryImp>  
00066 class Geometry {
00067 
00068 protected:
00069   GeometryImp<mydim,cdim,GridImp> realGeometry;
00070   
00071   // type of underlying implementation, for internal use only 
00072   typedef GeometryImp<mydim,cdim,GridImp> ImplementationType;
00073 public:
00075   enum { dimension=GridImp::dimension  };
00077   enum { mydimension=mydim  };
00079   enum { coorddimension=cdim  };
00080 
00082   enum { dimensionworld=GridImp::dimensionworld  };
00084   typedef typename GridImp::ctype ctype;
00085   
00086 
00090   GeometryType type () const { return realGeometry.type(); };
00091 
00097   int corners () const { return realGeometry.corners(); };
00098 
00104   const FieldVector< ctype, cdim > &operator[] ( int i ) const DUNE_DEPRECATED
00105     {
00106       return realGeometry[i];
00107     }
00108 
00126   FieldVector< ctype, cdim > corner ( int i ) const
00127   {
00128     typedef GenericGeometry::MapNumberingProvider< mydimension > Numbering;
00129     const unsigned int tid = GenericGeometry::topologyId( type() );
00130     const int j = Numbering::template generic2dune< mydimension >( tid, i );
00131     return realGeometry[ j ];
00132   }
00133 
00138   FieldVector<ctype, cdim> global (const FieldVector<ctype, mydim>& local) const
00139     {
00140       return realGeometry.global(local);
00141     }
00142 
00147   FieldVector<ctype, mydim> local (const FieldVector<ctype, cdim>& global) const
00148     {
00149       return realGeometry.local(global);
00150     }
00151 
00153   bool checkInside (const FieldVector<ctype, mydim>& local) const
00154     {
00155       return realGeometry.checkInside(local);
00156     }
00157 
00181   ctype integrationElement (const FieldVector<ctype, mydim>& local) const
00182   {
00183     return realGeometry.integrationElement(local);
00184   }
00185  
00187   ctype volume () const
00188   {
00189     return realGeometry.volume();
00190   }
00191 
00208   const FieldMatrix<ctype,cdim,mydim>& jacobianInverseTransposed (const FieldVector<ctype, mydim>& local) const
00209   {
00210   return realGeometry.jacobianInverseTransposed(local);
00211   }
00212 
00213 public:    
00215   explicit Geometry(const GeometryImp<mydim,cdim,GridImp> & e) : realGeometry(e) {};
00216   
00217 protected:
00218   // give the GridDefaultImplementation class access to the realImp 
00219   friend class GridDefaultImplementation< 
00220             GridImp::dimension, GridImp::dimensionworld,
00221             typename GridImp::ctype,
00222             typename GridImp::GridFamily> ;
00223 
00225   GeometryImp<mydim,cdim,GridImp> & getRealImp() { return realGeometry; }
00227   const GeometryImp<mydim,cdim,GridImp> & getRealImp() const { return realGeometry; }
00228  
00229 protected:  
00231   Geometry(const Geometry& rhs) : realGeometry(rhs.realGeometry) {};
00233   Geometry & operator = (const Geometry& rhs) {
00234     realGeometry = rhs.realGeometry;
00235     return *this;
00236   };
00237 };
00238 
00239 
00240 //************************************************************************
00241 // GEOMETRY Default Implementations
00242 //*************************************************************************
00243 //
00244 // --GeometryDefault 
00245 // 
00247 template<int mydim, int cdim, class GridImp, template<int,int,class> class GeometryImp>  
00248 class GeometryDefaultImplementation
00249 {
00250 public:
00251   // save typing
00252   typedef typename GridImp::ctype ctype;
00253  
00255   ctype volume () const 
00256   {
00257     GeometryType type = asImp().type();
00258 
00259     // get corresponding reference element
00260     const ReferenceElement< ctype , mydim > & refElement =
00261       ReferenceElements< ctype, mydim >::general(type);
00262 
00263     FieldVector<ctype,mydim> localBaryCenter (0.0);
00264     // calculate local bary center 
00265     const int corners = refElement.size(0,0,mydim);
00266     for(int i=0; i<corners; ++i) localBaryCenter += refElement.position(i,mydim);
00267     localBaryCenter *= (ctype) (1.0/corners);
00268 
00269     // volume is volume of reference element times integrationElement
00270     return refElement.volume() * asImp().integrationElement(localBaryCenter);
00271   }
00272   
00273 private:
00275   GeometryImp<mydim,cdim,GridImp>& asImp () {return static_cast<GeometryImp<mydim,cdim,GridImp>&>(*this);}
00276   const GeometryImp<mydim,cdim,GridImp>& asImp () const {return static_cast<const GeometryImp<mydim,cdim,GridImp>&>(*this);}
00277 }; // end GeometryDefault 
00278 
00279 template<int cdim, class GridImp, template<int,int,class> class GeometryImp>  
00280 class GeometryDefaultImplementation<0,cdim,GridImp,GeometryImp>
00281 {
00282   // my dimension 
00283   enum { mydim = 0 };
00284 public:
00285   // save typing
00286   typedef typename GridImp::ctype ctype;
00287 
00289   FieldVector<ctype, cdim> global (const FieldVector<ctype, mydim>& local) const
00290   {
00291     return asImp()[0];
00292   }
00293 
00295   FieldVector<ctype, mydim> local (const FieldVector<ctype, cdim>& ) const
00296   {
00297     return FieldVector<ctype, mydim>();
00298   }
00299  
00301   bool checkInside (const FieldVector<ctype, mydim>& ) const
00302   {
00303     return true; 
00304   }
00305  
00307   ctype volume () const { return 1.0; }
00308   
00309 private:
00311   GeometryImp<mydim,cdim,GridImp>& asImp () {return static_cast<GeometryImp<mydim,cdim,GridImp>&>(*this);}
00312   const GeometryImp<mydim,cdim,GridImp>& asImp () const {return static_cast<const GeometryImp<mydim,cdim,GridImp>&>(*this);}
00313 }; // end GeometryDefault 
00314 
00315 }
00316 #endif // DUNE_GRID_GEOMETRY_HH

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