alugrid/2d/grid.hh

00001 #ifndef DUNE_ALU2DGRIDGRID_HH
00002 #define DUNE_ALU2DGRIDGRID_HH
00003 
00004 //- System includes
00005 #include "alu2dinclude.hh"
00006 #include <vector>
00007 
00008 //- Dune includes
00009 #include <dune/grid/common/capabilities.hh>
00010 #include <dune/common/interfaces.hh>
00011 
00012 #include <dune/grid/common/grid.hh>
00013 #include <dune/grid/common/referenceelements.hh>
00014 #include <dune/grid/common/defaultindexsets.hh>
00015 #include <dune/grid/common/sizecache.hh>
00016 #include <dune/common/collectivecommunication.hh>
00017 #include <dune/grid/common/intersectioniteratorwrapper.hh>
00018 
00019 //- Local includes
00020 #include "indexsets.hh"
00021 #include "../3d/memory.hh"
00022 #include "datahandle.hh"
00023 namespace Dune {
00024 
00025   typedef double alu2d_ctype;
00026 
00027   // Forward declarations
00028   template<int cd, int dim, class GridImp> 
00029   class ALU2dGridEntity;  
00030   template<int cd, PartitionIteratorType pitype, class GridImp > 
00031   class ALU2dGridLevelIterator;
00032   template<int cd, class GridImp >
00033   class ALU2dGridEntityPointer;  
00034   template<int mydim, int coorddim, class GridImp>  
00035   class ALU2dGridMakeableGeometry;
00036   template<int mydim, int cdim, class GridImp>  
00037   class ALU2dGridGeometry;
00038   template<class GridImp>
00039   class ALU2dGridHierarchicIterator;    
00040   template<class GridImp>
00041   class ALU2dGridIntersectionBase;
00042   template<class GridImp>
00043   class ALU2dGridLevelIntersectionIterator;
00044   template<class GridImp>
00045   class ALU2dGridLeafIntersectionIterator;  
00046   template<int codim, PartitionIteratorType pitype, class GridImp>  
00047   class ALU2dGridLeafIterator;
00048   template <int mydim, int coorddim, class GridImp>
00049   class ALU2dGridMakeableEntity;
00050   template <class GridImp>
00051   class ALU2dGridFaceGeometryInfo;
00052   template<int dim, int dimworld> 
00053   class ALU2dGridGlobalIdSet;
00054   template<int dim, int dimworld>
00055   class ALU2dGridLocalIdSet;
00056   template<int dim, int dimworld> 
00057   class ALU2dGridHierarchicIndexSet;
00058   template <class EntityImp>
00059   class ALUMemoryProvider;
00060   template<int dim, int dimworld> 
00061   class ALU2dGrid;
00062   template <class GeometryImp, int nChild>
00063   class ALU2DLocalGeometryStorage;
00064   template <class GridImp, int codim>
00065   struct ALU2dGridEntityFactory;  
00066   
00067   class ALU2dObjectStream;
00068   
00069   //**********************************************************************
00070   //
00071   // --ALU2dGrid
00072   // --Grid
00073   //
00074   //**********************************************************************
00075   template <int dim, int dimworld>
00076   struct ALU2dGridFamily   
00077   {
00079     typedef ALU2dGridLocalIdSet<dim,dimworld> GlobalIdSetImp;
00080 
00082     typedef ALU2dGridLocalIdSet<dim,dimworld> LocalIdSetImp;
00083            
00085     typedef DefaultLevelIndexSet<ALU2dGrid < dim, dimworld > >  LevelIndexSetImp;
00087     typedef DefaultLeafIndexSet<ALU2dGrid < dim, dimworld > >   LeafIndexSetImp;
00088 
00089     typedef int GlobalIdType;
00090     typedef int LocalIdType;
00091 
00092     typedef ALU2dGrid<dim,dimworld> GridImp;
00093 
00094     struct Traits
00095     {
00096       typedef ALU2dGrid<dim,dimworld> Grid;
00097 
00098       typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper> IntersectionIterator;      
00099       typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper> LeafIntersectionIterator;      
00100       typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorWrapper> LevelIntersectionIterator;      
00101       
00102       typedef Dune::HierarchicIterator<const GridImp, ALU2dGridHierarchicIterator> HierarchicIterator;
00103 
00104       template <int cd>
00105       struct Codim
00106       {
00107         // IMPORTANT: Codim<codim>::Geometry == Geometry<dim-codim,dimw>
00108         typedef Dune::Geometry<dim-cd, dimworld, const GridImp, ALU2dGridGeometry> Geometry;
00109         typedef Dune::Geometry<dim-cd, dim, const GridImp, ALU2dGridGeometry> LocalGeometry;
00110         // we could - if needed - introduce an other struct for dimglobal of Geometry
00111         typedef Dune::Entity<cd, dim, const GridImp, ALU2dGridEntity> Entity;
00112 
00113         typedef Dune::LevelIterator<cd,All_Partition,const GridImp,ALU2dGridLevelIterator> LevelIterator;
00114 
00115         typedef Dune::LeafIterator<cd,All_Partition,const GridImp,ALU2dGridLeafIterator> LeafIterator;
00116 
00117         typedef Dune::EntityPointer<const GridImp,ALU2dGridEntityPointer<cd,const GridImp> > EntityPointer;
00118 
00119         template <PartitionIteratorType pitype>
00120         struct Partition
00121         {
00122           typedef Dune::LevelIterator<cd,pitype,const GridImp,ALU2dGridLevelIterator> LevelIterator;
00123           typedef Dune::LeafIterator<cd,pitype,const GridImp,ALU2dGridLeafIterator> LeafIterator;
00124         };
00125 
00126       };
00127 
00128       typedef IndexSet<GridImp,LevelIndexSetImp,DefaultLevelIteratorTypes<GridImp> > LevelIndexSet;
00129       typedef LeafIndexSetImp LeafIndexSet;
00130       typedef IdSet<GridImp,GlobalIdSetImp,GlobalIdType> GlobalIdSet;
00131       typedef IdSet<GridImp,LocalIdSetImp,LocalIdType> LocalIdSet;
00132 
00133       typedef CollectiveCommunication<GridImp> CollectiveCommunication;
00134     };
00135   }; // end of ALU2dGridFamily
00136 
00137 
00152   template <int dim, int dimworld>
00153   class ALU2dGrid : 
00154     public GridDefaultImplementation<dim,dimworld,alu2d_ctype,ALU2dGridFamily<dim,dimworld> >,
00155     public HasObjectStream, 
00156     public HasHierarchicIndexSet 
00157   {
00158     CompileTimeChecker<(dim      == 2)> ALU2dGrid_only_implemented_for_2dp; 
00159     CompileTimeChecker<(dimworld == 2)> ALU2dGrid_only_implemented_for_2dw;
00160 
00161     typedef ALU2dGrid<dim,dimworld> ThisType; 
00162     typedef GridDefaultImplementation<dim,dimworld,alu2d_ctype,ALU2dGridFamily<dim,dimworld> > BaseType;
00163     
00164     friend class ALU2dGridEntity<0,dim,const ThisType>;
00165     friend class ALU2dGridEntity<1,dim,const ThisType>;
00166     friend class ALU2dGridEntity<dim,dim,const ThisType>;
00167     
00168     friend class ALU2dGridGeometry<0,dimworld,const ThisType>;
00169     friend class ALU2dGridGeometry<1,dimworld,const ThisType>;
00170     friend class ALU2dGridGeometry<dim,dimworld,const ThisType>;
00171  
00172     friend class ALU2dGridEntityPointer<0,const ThisType>;
00173     friend class ALU2dGridEntityPointer<1,const ThisType>;
00174     friend class ALU2dGridEntityPointer<dim,const ThisType>;
00175     
00176     friend class ALU2dGridHierarchicIndexSet<dim,dimworld>;
00177     //friend class ALU2dGridGlobalIdSet<dim,dimworld>;
00178     //friend class ALU2dGridLocalIdSet<dim,dimworld>;
00179 
00180     friend class ALU2dGridIntersectionBase < const ThisType > ;
00181     friend class ALU2dGridLevelIntersectionIterator< const ThisType > ;
00182     friend class ALU2dGridLeafIntersectionIterator< const ThisType > ;
00183     
00184     //**********************************************************
00185     // The Interface Methods
00186     //**********************************************************
00187   public:
00189     typedef typename ALU2dGridFamily < dim , dimworld > :: Traits Traits;
00190 
00191   protected:
00192     typedef MakeableInterfaceObject<typename Traits::template
00193             Codim<0>::Geometry> GeometryObject;
00194     friend class ALU2DLocalGeometryStorage<GeometryObject, 4 >;
00195     friend class ALU2DLocalGeometryStorage<GeometryObject, 2 >;
00196     
00197   public:  
00198    
00200     typedef ALU2dGridObjectStream ObjectStreamType;
00201 
00203     typedef ALU2dGridFamily < dim , dimworld > GridFamily;
00205     typedef ALU2dGridHierarchicIndexSet<dim,dimworld> HierarchicIndexSet;
00206     
00208     typedef ALU2dGridLocalIdSet<dim,dimworld> LocalIdSetImp;
00209     typedef LocalIdSetImp GlobalIdSetImp;
00210 
00212     typedef typename Traits :: GlobalIdSet GlobalIdSet;
00213     
00215     typedef typename Traits :: LocalIdSet LocalIdSet;
00216    
00217 
00219     typedef typename GridFamily :: LevelIndexSetImp  LevelIndexSetImp;
00221     typedef typename GridFamily :: LeafIndexSetImp  LeafIndexSetImp;
00222     
00224     typedef ALU2dGridLeafIterator<0, All_Partition, const ThisType> LeafIteratorImp;
00225     typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
00226     typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
00227     
00229     typedef ALU2dGridLevelIterator<0, All_Partition, const ThisType> LevelIteratorImp;
00230     typedef typename Traits::template Codim<0>::LevelIterator LevelIteratorType;
00231     typedef typename Traits::template Codim<0>::LevelIterator LevelIterator;       
00232     
00233     typedef ALU2dGridHierarchicIterator<ThisType> HierarchicIteratorImp;
00234 
00235     typedef typename Traits::CollectiveCommunication CollectiveCommunicationType;
00236 
00238     enum { 
00240       MAXL = 64 };
00241 
00243     enum {
00245       newElementsChunk_ = 100 };
00246 
00248     enum {
00252       refineEstimate_ = 40 };
00253         
00254 
00255   protected:  
00258     ALU2dGrid(std::string macroTriangFilename );    
00259     ALU2dGrid(std::string macroTriangFilename, int nrOfHangingNodes ); 
00261     ALU2dGrid( int );
00262     
00263   public: 
00265     ~ALU2dGrid();
00266 
00268     std::string name () const; 
00269    
00272     int maxLevel() const;
00273            
00276     template<int cd, PartitionIteratorType pitype>
00277     typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
00278     lbegin (int level) const; 
00279   
00281     template<int cd, PartitionIteratorType pitype>
00282     typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
00283     lend (int level) const;
00284       
00286     template<int cd>
00287     typename Traits::template Codim<cd>::
00288     template Partition<All_Partition>::LevelIterator 
00289     lbegin (int level) const;
00290 
00292     template<int cd>
00293     typename Traits::template Codim<cd>::
00294     template Partition<All_Partition>::LevelIterator 
00295     lend (int level) const;
00296     
00298     LevelIteratorType lbegin (int level) const;
00299 
00301     LevelIteratorType lend (int level) const;
00302         
00304     template <int codim, PartitionIteratorType pitype>
00305     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00306     leafbegin() const;
00307 
00309     template <int codim, PartitionIteratorType pitype>
00310     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00311     leafend() const;
00312 
00314     template <int codim>
00315     typename Traits::template Codim<codim>::LeafIterator
00316     leafbegin() const;
00317 
00319     template <int codim>
00320     typename Traits::template Codim<codim>::LeafIterator
00321     leafend() const;
00322   
00323   private:  
00325     LeafIteratorType leafbegin () const;
00326 
00328     LeafIteratorType leafend () const;    
00329   
00330   public:  
00332     int size (int level, int cd) const;
00333     
00335     int size (int codim) const;
00336     
00338     int size (int level, GeometryType type) const;
00339 
00341     int size (GeometryType type) const;
00342 
00344     const std::vector<GeometryType>& geomTypes (int codim) const { return geomTypes_[codim]; }
00345     
00346     //****************************************************************
00347     // index and id sets 
00348     //****************************************************************
00349 
00351     const GlobalIdSet & globalIdSet () const; 
00352 
00354     const LocalIdSet & localIdSet () const;
00355     
00357     int hierSetSize (int cd) const;
00358     
00360     const HierarchicIndexSet & hierarchicIndexSet () const ;
00361     
00363     const typename Traits :: LeafIndexSet & leafIndexSet () const;
00364     
00366     const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;   
00367     
00368     
00369     //**********************************************************
00370     // End of Interface Methods
00371     //**********************************************************
00372     
00373     // return reference to org ALU2dGrid 
00374     // private method, but otherwise we have to friend class all possible
00375     // types of LevelIterator ==> later
00376     ALU2DSPACE Hmesh & myGrid();
00377     ALU2DSPACE Hmesh & myGrid() const;
00378 
00380     bool globalRefine(int refCount);
00381     
00383     bool preAdapt ( );
00384     
00386     void postAdapt ( );
00387     
00391     bool adapt ( );
00392     
00394     template <class DofManagerType, class RestrictProlongOperatorType>
00395     bool adapt (DofManagerType &, RestrictProlongOperatorType &, bool verbose=false );
00396 
00397     // refine grid
00398     bool refineGrid();
00399    
00403     bool mark( int refCount , const typename Traits::template Codim<0>::EntityPointer & ep );
00404     
00406     int getMark(const typename Traits::template Codim<0>::EntityPointer & ) const;
00407 
00409     const CollectiveCommunicationType & comm() const;
00410   private:
00411     CollectiveCommunicationType comm_;
00412    
00413     bool mark( int refCount , const typename Traits::template Codim<0>::Entity & en );                  
00414     
00415     void updateStatus();
00416     
00417     void calcMaxlevel();
00418     
00419     void calcExtras();
00420    
00421     typedef typename ALU2dImplTraits::template Codim<0>:: InterfaceType ALUElementType; 
00422     // clear refinement marker of element and all children 
00423     void hierarchicClear(ALUElementType* el);
00424   public:
00425     typedef MakeableInterfaceObject<typename Traits::template Codim<0>::Entity> EntityObject;
00426   private:
00427     typedef ALUMemoryProvider< EntityObject > EntityProviderType;
00428 
00429     mutable EntityProviderType entityProvider_;   
00430     
00431     template <int codim>
00432     MakeableInterfaceObject<typename Traits::template Codim<codim>:: Entity> * getNewEntity ( int level ) const
00433     {
00434       return ALU2dGridEntityFactory<ThisType,codim>::getNewEntity(*this,entityProvider_,level);
00435     }
00436 
00437     template <class EntityType>
00438     void freeEntity (EntityType * en) const
00439     {
00440       enum { codim = EntityType::codimension };
00441       return ALU2dGridEntityFactory<ThisType,codim>::freeEntity(entityProvider_, en);
00442     }
00443 
00444     // create GeomTypes
00445     void makeGeomTypes ();
00446     
00447     friend class Conversion<ALU2dGrid<dim, dimworld>, HasObjectStream>;
00448     friend class Conversion<const ALU2dGrid<dim, dimworld>, HasObjectStream>;
00449 
00450     friend class Conversion<ALU2dGrid<dim, dimworld>, HasHierarchicIndexSet>;
00451     friend class Conversion<const ALU2dGrid<dim, dimworld>, HasHierarchicIndexSet>;
00452 
00454     ALU2dGrid( const ThisType & g );
00455   
00457     ThisType & operator = (const ThisType & g); 
00458 
00459     // check macro file and return const char * to filename 
00460     const char * checkMacroGridFile(const std::string & filename);
00461   
00463     mutable ALU2DSPACE Hmesh* mygrid_;
00464     ALU2DSPACE Hmesh& mesh() {
00465       assert(mygrid_);
00466       return *mygrid_;
00467     }
00468     ALU2DSPACE Hmesh& mesh() const {
00469       assert(mygrid_);
00470       return *mygrid_;
00471     }
00472     // mutable ALU2DSPACE Hmesh& mesh_;
00473 
00475     HierarchicIndexSet hIndexSet_;
00476 
00478     LocalIdSetImp localIdSet_;
00479  
00481     mutable std::vector < LevelIndexSetImp * > levelIndexVec_;
00482         
00483     // at the moment the number of different geom types is 1
00484     enum { numberOfGeomTypes = 1 };
00485     std::vector< std::vector<GeometryType> > geomTypes_;
00486     
00488     mutable LeafIndexSetImp * leafIndexSet_;
00489 
00490     int maxLevel_;
00491     int refineMarked_ , coarsenMarked_;
00492     const int nrOfHangingNodes_;
00493     
00494     //typedef ALU2dGridVertexList VertexListType;
00495     //mutable VertexListType vertexList_[MAXL];
00496 
00498     typedef SingleTypeSizeCache<ThisType> SizeCacheType;
00499     SizeCacheType * sizeCache_;
00500 
00501     // new intersection iterator is a wrapper which get itersectioniteratoimp as pointers
00502   public:    
00503     typedef ALU2dGridLeafIntersectionIterator <const ThisType>  LeafIntersectionIteratorImp;
00504     typedef ALU2dGridLevelIntersectionIterator<const ThisType> LevelIntersectionIteratorImp;
00505 
00506     typedef ALUMemoryProvider< LeafIntersectionIteratorImp > LeafIntersectionIteratorProviderType;
00507     typedef ALUMemoryProvider< LevelIntersectionIteratorImp > LevelIntersectionIteratorProviderType;
00508 
00509   public:
00510     template <class IntersectionInterfaceType>
00511     const typename BaseType::
00512     template ReturnImplementationType<IntersectionInterfaceType> :: ImplementationType &
00513     getRealIntersectionIterator(const IntersectionInterfaceType & it) const
00514     {
00515       return this->getRealImplementation(it);
00516     }
00517 
00518   private: 
00519     // max level of grid
00520     int maxlevel_;
00521     friend class LeafIntersectionIteratorWrapper< const ThisType > ;
00522     friend class LevelIntersectionIteratorWrapper< const ThisType > ;
00523     // return reference to intersectioniterator storage
00524     LeafIntersectionIteratorProviderType & leafIntersetionIteratorProvider() const 
00525     { 
00526       return leafInterItProvider_; 
00527     }
00528     mutable LeafIntersectionIteratorProviderType leafInterItProvider_;
00529     
00530     LevelIntersectionIteratorProviderType & levelIntersetionIteratorProvider() const 
00531     { 
00532       return levelInterItProvider_; 
00533     }
00534     mutable LevelIntersectionIteratorProviderType levelInterItProvider_;
00535 
00536     mutable ALU2dGridMarkerVector marker_[MAXL];
00537   public: 
00538     typedef ALU2dGridLeafMarkerVector ALU2dGridLeafMarkerVectorType;
00539   private:  
00540     // always update this marker!!!
00541     mutable ALU2dGridLeafMarkerVectorType leafMarker_;
00542 
00543   public: 
00546     ALU2dGridMarkerVector & getMarkerVector(int level) const
00547     {
00548       assert( level >= 0);
00549       assert( level <= MAXL);
00550       return marker_[level];
00551     }
00552 
00555     ALU2dGridLeafMarkerVectorType & getLeafMarker() const
00556     {
00557       return leafMarker_;
00558     }
00559     
00562     template <GrapeIOFileFormatType ftype>
00563     bool writeGrid( const std::string filename, alu2d_ctype time ) const ;
00564 
00565     bool writeGrid_Xdr( const std::string filename, alu2d_ctype time ) const ;
00566     bool writeGrid_Ascii( const std::string filename, alu2d_ctype time ) const ;
00567   
00570     template <GrapeIOFileFormatType ftype>
00571     bool readGrid( const std::string filename, alu2d_ctype & time );
00572 
00573   protected:
00574     int getNrOfHangingNodes() const {
00575       return nrOfHangingNodes_;
00576     }
00577     
00578   }; // end class ALU2dGrid
00579 
00580     template <class GridImp, int codim>
00581     struct ALU2dGridEntityFactory
00582     {
00583       typedef typename GridImp:: template Codim<codim>::Entity Entity;
00584       typedef MakeableInterfaceObject<Entity> EntityObj; 
00585       typedef typename EntityObj::ImplementationType EntityImp;
00586       
00587       template <class EntityProviderType>
00588       static EntityObj *
00589       getNewEntity (const GridImp & grid, EntityProviderType & ep, int level)
00590       {
00591         return new EntityObj(EntityImp(grid, level));
00592       }
00593 
00594       template <class EntityProviderType>
00595       static void freeEntity( EntityProviderType & ep, EntityObj * e )
00596       {
00597         delete e;
00598       }
00599     };
00600     
00601     template <class GridImp>
00602     struct ALU2dGridEntityFactory<GridImp,0>
00603     { 
00604       enum {codim = 0};
00605       typedef typename GridImp:: template Codim<codim>::Entity Entity;
00606       typedef MakeableInterfaceObject<Entity> EntityObj;       
00607       typedef typename EntityObj :: ImplementationType EntityImp;
00608       
00609       template <class EntityProviderType>
00610       static EntityObj *
00611       getNewEntity (const GridImp & grid, EntityProviderType & ep, int level)
00612       {
00613         return ep.getEntityObject( grid, level, (EntityImp *) 0);
00614       }
00615 
00616       template <class EntityProviderType>
00617       static void freeEntity( EntityProviderType & ep, EntityObj * e )
00618       {
00619         ep.freeObject( e );
00620       }
00621     };
00622 
00623 
00624   namespace Capabilities 
00625   {
00626     template<int dim, int dimw, int cdim>
00627     struct hasEntity<ALU2dGrid<dim,dimw>, cdim >
00628     {
00629       static const bool v = true;
00630     };
00631 
00632   template<int dim, int dimw>
00633   struct isLevelwiseConforming< ALU2dGrid<dim,dimw> >
00634   {
00635     static const bool v = false;
00636   };
00637 
00638   template<int dim, int dimw>
00639   struct hasHangingNodes< ALU2dGrid<dim,dimw> >
00640   {
00641     static const bool v = false;
00642   };
00643   } // end namespace Capabilities
00644   
00645 } // end namespace Dune
00646 
00647 #include "entity.hh"
00648 #include "geometry.hh"
00649 #include "iterator.hh"
00650 
00651 #include "grid_imp.cc"
00652 
00653 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)