alugrid/2d/geometry.hh

00001 #ifndef DUNE_ALU2DGRIDGEOMETRY_HH
00002 #define DUNE_ALU2DGRIDGEOMETRY_HH
00003 
00004 // System includes
00005 
00006 // Dune includes
00007 #include <dune/common/misc.hh>
00008 #include <dune/grid/common/grid.hh>
00009 
00010 // Local includes
00011 
00012 namespace Dune {
00013   // Forward declarations
00014   template<int cd, int dim, class GridImp> 
00015   class ALU2dGridEntity;
00016   template<int cd, class GridImp >
00017   class ALU2dGridEntityPointer;
00018   template<int mydim, int cdim, class GridImp>
00019   class ALU2dGridGeometry;
00020   template<int dim, int dimworld> 
00021   class ALU2dGrid;
00022 
00023   //**********************************************************************
00024   //
00025   // --ALU2dGridGeometry
00026   // --Geometry
00027   //**********************************************************************
00040 
00041 
00042   template <int mydim, int cdim, class GridImp>
00043   class ALU2dGridGeometry : 
00044     public GeometryDefaultImplementation <mydim,cdim,GridImp,ALU2dGridGeometry> 
00045   {
00046   
00048     typedef typename GridImp::template Codim<0>::Geometry Geometry;
00050     typedef ALU2dGridGeometry<mydim,cdim,GridImp> GeometryImp;
00052     enum { dimbary=mydim+1};
00053     
00054     typedef typename ALU2DSPACE Hmesh_basic::helement_t HElementType ;
00055 
00056     template <class GeomImp, int gdim> 
00057     struct CopyCoordinates;
00058     
00059     template <class GeomImp> 
00060     struct CopyCoordinates<GeomImp,2> 
00061     {
00062       template <class VecType>
00063       static inline void copyData(const double p[cdim], VecType& vec)
00064       {
00065         assert( cdim == 2 );
00066         vec[0] = p[0];
00067         vec[1] = p[1];
00068       }
00069       
00070       // copy coordinates and return determinant
00071       template<class CoordMatrixType>
00072       static inline double copy(const HElementType& item, CoordMatrixType& coord, const int ) 
00073       {
00074         assert( cdim == 2 );
00075         // copy coordinates
00076         copyData(item.getVertex(0)->coord(),coord[0]);
00077         copyData(item.getVertex(1)->coord(),coord[1]);
00078         copyData(item.getVertex(2)->coord(),coord[2]);
00079         return 2.0*item.area();
00080       }
00081     };
00082     
00083     template <class GeomImp> 
00084     struct CopyCoordinates<GeomImp,1> 
00085     {
00086       template <class VecType>
00087       static inline void copyData(const double p[cdim], VecType& vec)
00088       {
00089         assert( cdim == 2 );
00090         vec[0] = p[0];
00091         vec[1] = p[1];
00092       }
00093       
00094       // copy coordinates and return determinant
00095       template<class CoordMatrixType>
00096       static inline double copy(const HElementType& item, CoordMatrixType& coord, const int face) 
00097       {
00098         // copy coordinates
00099         for(int i=0; i<2; ++i)
00100         {    
00101           const int vx = (i+face+1)%3;
00102           copyData(item.getVertex(vx)->coord(),coord[i]);
00103         }
00104         return item.sidelength((face)%3);
00105       }
00106     };
00107     
00108     public:
00111     ALU2dGridGeometry();
00112 
00114     ALU2dGridGeometry(const int child, const int orientation );
00115     
00118     const GeometryType & type () const;
00119 
00121     int corners () const;
00122 
00124     const FieldVector<alu2d_ctype, cdim>& operator[] (int i) const;
00125 
00128     FieldVector<alu2d_ctype, cdim> global (const FieldVector<alu2d_ctype, mydim>& local) const;
00129   
00132     FieldVector<alu2d_ctype,  mydim> local (const FieldVector<alu2d_ctype, cdim>& global) const;
00133   
00135     bool checkInside(const FieldVector<alu2d_ctype, mydim>& local) const;
00136     
00138     alu2d_ctype integrationElement (const FieldVector<alu2d_ctype, mydim>& local) const;
00139        
00141     alu2d_ctype volume () const;
00142     
00144     const FieldMatrix<alu2d_ctype,mydim,mydim>& jacobianInverseTransposed (const FieldVector<alu2d_ctype, mydim>& local) const;
00145 
00146     //***********************************************************************
00148     //***********************************************************************
00150     bool builtGeom(const ALU2DSPACE Vertex & item, int );   
00151     bool builtGeom(const HElementType & item, int face);           
00152         
00155     template <class GeometryType, class LocalGeomType >
00156     bool builtLocalGeom(const GeometryType & geo , const LocalGeomType & lg);
00157                         
00159     bool builtLocalGeom(const int faceNumber, const int twist); 
00160 
00162     FieldVector<alu2d_ctype, cdim>& getCoordVec (int i);       
00163 
00165     void print (std::ostream& ss) const;
00166    
00168     //void buildGeomInFather(const int child, const int orientation); 
00169     inline bool buildGeomInFather(const Geometry &fatherGeom , const Geometry & myGeom);
00170 
00171     inline bool up2Date() const { return up2Date_; }
00172     inline void unsetUp2Date() const { up2Date_ = false; }
00173   private:
00174     // set ref coords 
00175     void setReferenceCoordinates();
00176     
00178     void buildJacobianInverseTransposed () const;
00179 
00181     void calcElMatrix () const;
00182     
00184     alu2d_ctype elDeterminant () const;
00185 
00187     GeometryType myGeomType_;    
00188 
00190     mutable FieldVector<alu2d_ctype, mydim+1> tmpVec_;
00191     
00193     mutable FieldMatrix<alu2d_ctype, mydim+1, cdim> coord_; 
00194 
00196     FieldMatrix<alu2d_ctype, 3 , 3> refCoord_; 
00197 
00199     mutable FieldVector<alu2d_ctype, cdim> globalCoord_;
00200 
00202     mutable FieldVector<alu2d_ctype, mydim> localCoord_;
00203     
00204     enum { matdim = (mydim > 0) ? mydim : 1 };
00205     mutable FieldMatrix<alu2d_ctype,matdim,matdim> Jinv_; 
00206     mutable FieldMatrix<alu2d_ctype,matdim,matdim> Mtmp_;    
00207 
00208     mutable FieldMatrix<alu2d_ctype,cdim,mydim> elMat_; 
00209     mutable FieldMatrix<alu2d_ctype,matdim,matdim> elMatT_elMat_; 
00210 
00212     mutable bool builtElMat_;
00214     mutable bool builtinverse_;
00215 
00216 #ifndef NDEBUG 
00217     mutable bool calcedDet_; 
00218 #endif
00219     mutable alu2d_ctype elDet_;                           
00220     
00222     mutable bool up2Date_;
00223 
00224     // temporary mem for integrationElement with mydim < cdim
00225     mutable FieldVector<alu2d_ctype,cdim> tmpV_; 
00226     mutable FieldVector<alu2d_ctype,cdim> tmpU_; 
00227     mutable FieldVector<alu2d_ctype,cdim> tmpZ_;
00228         
00229     mutable FieldVector<alu2d_ctype,mydim> AT_x_;
00230   
00231   };
00232   
00233   template <class GeometryImp, int nChild>
00234   class ALU2DLocalGeometryStorage {
00235     
00236     // array with pointers to the geometries
00237     std::vector < GeometryImp * > geoms_;
00238     // count local geometry creation
00239     int count_;
00240   public:
00241     // create empty storage
00242     ALU2DLocalGeometryStorage () : geoms_ (nChild) , count_ (0) {
00243       for(size_t i=0 ;i<geoms_.size(); ++i) geoms_[i] = 0;
00244     }
00245 
00246     // desctructor deleteing geometries
00247     ~ALU2DLocalGeometryStorage () {
00248       for(size_t i=0 ;i<geoms_.size(); ++i)
00249         if(geoms_[i]) delete geoms_[i];
00250     }
00251 
00252     // check if geometry has been created
00253     bool geomCreated(int child) const { return geoms_[child] != 0; }
00254 
00255     // create local geometry
00256     template <class GridImp, class Geometry>
00257     void create (const GridImp & grid, const Geometry & father, const Geometry & son, const int child)
00258     {
00259       assert( !geomCreated(child) );
00260       assert( child >=0 && child < nChild );
00261 
00262       assert( count_ < nChild );
00263       ++count_;
00264 
00265       typedef typename GeometryImp :: ImplementationType ImplType;
00266       GeometryImp * g = new GeometryImp(ImplType());
00267       geoms_[child] = g;
00268       GeometryImp & geo = *g;
00269       grid.getRealImplementation(geo).buildGeomInFather( father, son );
00270     }
00271     // return reference to local geometry
00272     const GeometryImp & operator [] (int child) const
00273     {
00274       assert( geomCreated(child) );
00275       return *(geoms_[child]);
00276     }
00277   };  
00278   
00279 } // end namespace Dune
00280 
00281 #include "geometry_imp.cc"
00282 
00283 #endif

Generated on 6 Nov 2008 with Doxygen (ver 1.5.6) [logfile].