alu3dutility.hh

00001 #ifndef DUNE_ALU3DUTILITY_HH
00002 #define DUNE_ALU3DUTILITY_HH
00003 
00004 //- system includes 
00005 #include <vector>
00006 
00007 //- local includes 
00008 #include "topology.hh"
00009 #include "alu3dinclude.hh"
00010 
00011 namespace Dune {
00012 
00013   template <class GeometryImp, int nChild>
00014   class LocalGeometryStorage
00015   {
00016     // array with pointers to the geometries 
00017     std::vector < GeometryImp * > geoms_;
00018     // count local geometry creation 
00019     int count_;
00020   public:
00021     // create empty storage 
00022     LocalGeometryStorage () : geoms_ (nChild) , count_ (0) 
00023     {
00024       for(size_t i=0 ;i<geoms_.size(); ++i) geoms_[i] = 0;
00025     }
00026 
00027     // desctructor deleteing geometries 
00028     ~LocalGeometryStorage () {
00029       for(size_t i=0 ;i<geoms_.size(); ++i)
00030         if(geoms_[i]) delete geoms_[i];
00031     }
00032 
00033     // check if geometry has been created 
00034     bool geomCreated(int child) const { return geoms_[child] != 0; }
00035 
00036     // create local geometry 
00037     template <class GridImp, class Geometry>
00038     void create (const GridImp & grid, const Geometry & father,
00039                  const Geometry & son, const int child)
00040     {
00041       assert( !geomCreated(child) );
00042       assert( child >=0 && child < nChild );
00043 
00044       assert( count_ < nChild );
00045       ++count_;
00046 
00047       typedef typename GeometryImp :: ImplementationType ImplType;
00048       GeometryImp * g = new GeometryImp(ImplType());
00049       geoms_[child] = g;
00050       GeometryImp & geo = *g;
00051       grid.getRealImplementation(geo).buildGeomInFather( father, son );
00052     }
00053 
00054     // return reference to local geometry
00055     const GeometryImp & operator [] (int child) const
00056     {
00057       assert( geomCreated(child) );
00058       return *(geoms_[child]);
00059     }
00060   };
00061 
00062   inline const ALU3dImplTraits<tetra>::GEOFaceType*
00063   getFace(const ALU3DSPACE GEOTetraElementType& elem, int index) {
00064     assert(index >= 0 && index < 4);
00065     return elem.myhface3(ElementTopologyMapping<tetra>::dune2aluFace(index));
00066   }
00067 
00068   inline const ALU3dImplTraits<hexa>::GEOFaceType*
00069   getFace(const ALU3DSPACE GEOHexaElementType& elem, int index) {
00070     assert(index >= 0 && index < 6);
00071     return elem.myhface4(ElementTopologyMapping<hexa>::dune2aluFace(index));
00072   }
00073 
00074 } // end namespace Dune 
00075 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].