dune-grid  2.2.0
alugrid/3d/grid.hh
Go to the documentation of this file.
00001 #ifndef DUNE_ALU3DGRIDGRID_HH
00002 #define DUNE_ALU3DGRIDGRID_HH
00003 
00004 //- System includes
00005 #include <vector>
00006 
00007 //- Dune includes
00008 #include <dune/grid/utility/grapedataioformattypes.hh>
00009 #include <dune/grid/common/capabilities.hh>
00010 #include <dune/grid/alugrid/common/interfaces.hh>
00011 #include <dune/common/bigunsignedint.hh>
00012 #include <dune/common/deprecated.hh>
00013 #include <dune/common/static_assert.hh>
00014 
00015 #include <dune/geometry/referenceelements.hh>
00016 
00017 #include <dune/grid/common/grid.hh>
00018 #include <dune/grid/alugrid/common/defaultindexsets.hh>
00019 #include <dune/grid/common/sizecache.hh>
00020 #include <dune/grid/alugrid/common/intersectioniteratorwrapper.hh>
00021 #include <dune/grid/common/datahandleif.hh>
00022 #include <dune/grid/common/defaultgridview.hh>
00023 
00024 // bnd projection stuff 
00025 #include <dune/grid/common/boundaryprojection.hh>
00026 #include <dune/grid/alugrid/common/bndprojection.hh>
00027 #include <dune/grid/alugrid/common/objectfactory.hh>
00028 
00029 //- Local includes
00030 #include "alu3dinclude.hh"
00031 #include "topology.hh"
00032 #include "indexsets.hh"
00033 #include "datahandle.hh"
00034 
00035 #include <dune/grid/alugrid/3d/lbdatahandle.hh>
00036 
00037 #include <dune/common/mpihelper.hh>
00038 
00039 #if ALU3DGRID_PARALLEL
00040 #include <dune/common/mpicollectivecommunication.hh>
00041 #else 
00042 #include <dune/common/collectivecommunication.hh>
00043 #endif
00044 
00045 namespace Dune
00046 {
00047 
00048   // Forward declarations
00049   template<int cd, int dim, class GridImp> 
00050   class ALU3dGridEntity;  
00051   template<int cd, PartitionIteratorType pitype, class GridImp > 
00052   class ALU3dGridLevelIterator;
00053   template<int cd, class GridImp >
00054   class ALU3dGridEntityPointerBase;  
00055   template<int cd, class GridImp >
00056   class ALU3dGridEntitySeed;  
00057   template<int cd, class GridImp >
00058   class ALU3dGridEntityPointer;  
00059   template<int mydim, int coorddim, class GridImp>  
00060   class ALU3dGridGeometry;
00061   template<class GridImp>
00062   class ALU3dGridHierarchicIterator;
00063   template<class GridImp>
00064   class ALU3dGridIntersectionIterator;
00065   template<class GridImp>
00066   class ALU3dGridLevelIntersectionIterator;
00067   template<int codim, PartitionIteratorType pitype, class GridImp>
00068   class ALU3dGridLeafIterator;
00069   template <int mydim, int coorddim, class GridImp>
00070   class ALU3dGridMakeableEntity;
00071   template <class GridImp>
00072   class ALU3dGridFaceGeometryInfo;
00073   template< ALU3dGridElementType, class >
00074   class ALU3dGridGlobalIdSet;
00075   template< ALU3dGridElementType, class >
00076   class ALU3dGridLocalIdSet;
00077   template< ALU3dGridElementType, class >
00078   class ALU3dGridHierarchicIndexSet;
00079   template <class EntityImp>
00080   class ALUMemoryProvider;
00081   template< class >
00082   class ALU3dGridFactory;
00083   template <class GridImp, class GeometryImp, int nChild> 
00084   class ALULocalGeometryStorage;
00085   template< ALU3dGridElementType elType, class Comm >
00086   struct ALU3dGridCommHelper;
00087 
00088 
00089 
00090   // Internal Forward Declarations
00091   // -----------------------------
00092 
00093 #if ALU3DGRID_PARALLEL
00094   template< ALU3dGridElementType elType, class Comm = MPI_Comm >
00095   class ALU3dGrid;
00096 #else // #if ALU3DGRID_PARALLEL
00097   template< ALU3dGridElementType elType, class Comm = No_Comm >
00098   class ALU3dGrid;
00099 #endif // #else // #if ALU3DGRID_PARALLEL
00100 
00101   template < class Comm > 
00102   struct ALUGridBaseGrid< 3, 3, cube, Comm > 
00103   {
00104     typedef ALU3dGrid< hexa, Comm >  BaseGrid ; 
00105   };
00106 
00107   template < class Comm> 
00108   struct ALUGridBaseGrid< 3, 3, simplex, Comm > 
00109   {
00110     typedef ALU3dGrid< tetra, Comm >  BaseGrid ; 
00111   };
00112 
00113   namespace DefaultIndexSetHelper
00114   {
00115 
00116     template< ALU3dGridElementType elType, class Comm, class Index >
00117     struct ContainsIndex< ALU3dGrid< elType, Comm >, Index >
00118     {
00119       typedef ALU3dGrid< elType, Comm > Grid;
00120 
00121       static bool
00122       contains ( const PersistentContainer< Grid, Index > &container,
00123                  const size_t index ) 
00124       {
00125         return (container.getData( index ).index() >= 0);
00126       }
00127     };
00128 
00129   } // namespace DefaultIndexSetHelper
00130 
00131 
00132 
00133   // ALU3dGridCommunications
00134   // -----------------------
00135 
00136   template< ALU3dGridElementType elType, class Comm >
00137   struct ALU3dGridCommunications;
00138 
00139   template< ALU3dGridElementType elType >
00140   struct ALU3dGridCommunications< elType, No_Comm >
00141   {
00142     typedef ALU3dGridLocalIdSet< elType, No_Comm > GlobalIdSet;
00143     typedef int GlobalId;
00144 
00145     typedef ALU3DSPACE GitterDuneImpl GitterImplType;
00146 
00147     typedef Dune::CollectiveCommunication< No_Comm > CollectiveCommunication;
00148 
00149     explicit ALU3dGridCommunications ( No_Comm comm ) {}
00150 
00151     int nlinks () const { return 0; }
00152 
00153     GitterImplType *createALUGrid ( const std::string &macroName, ALU3DSPACE ProjectVertex *projection )
00154     {
00155       if( macroName.empty() )
00156         return new GitterImplType();
00157       else
00158         return new GitterImplType ( macroName.c_str(), projection );
00159     }
00160 
00161     static No_Comm defaultComm () { return No_Comm(); }
00162 
00163     static int getRank ( No_Comm comm ) { return 0; }
00164 
00165     static typename ALU3DSPACE Gitter::Geometric::BuilderIF &getBuilder ( GitterImplType &grid )
00166     {
00167       return dynamic_cast< ALU3DSPACE Gitter::Geometric::BuilderIF & >( grid.container() );
00168     }
00169 
00170     static void duneNotifyMacroGridChanges ( GitterImplType &gird ) {}
00171 
00172     CollectiveCommunication ccobj_;
00173   };
00174 
00175 #if ALU3DGRID_PARALLEL
00176   template< ALU3dGridElementType elType >
00177   struct ALU3dGridCommunications< elType, MPI_Comm >
00178   {
00179     typedef ALU3dGridGlobalIdSet< elType, MPI_Comm > GlobalIdSet;
00180     typedef ALUGridId< ALUMacroKey > GlobalId;
00181 
00182     typedef ALU3DSPACE GitterDunePll GitterImplType;
00183 
00184     typedef Dune::CollectiveCommunication< MPI_Comm > CollectiveCommunication;
00185 
00186     explicit ALU3dGridCommunications ( MPI_Comm comm )
00187     : ccobj_( comm ), mpAccess_( comm )
00188     {}
00189 
00190     int nlinks () const { return mpAccess_.nlinks(); }
00191 
00192     GitterImplType *createALUGrid ( const std::string &macroName, ALU3DSPACE ProjectVertex *projection )
00193     {
00194       return new GitterImplType( macroName.c_str(), mpAccess_, projection );
00195     }
00196 
00197     static MPI_Comm defaultComm () { return MPI_COMM_WORLD; }
00198 
00199     static int getRank ( MPI_Comm comm )
00200     {
00201       int rank = 0;
00202       MPI_Comm_rank( comm, &rank );
00203       return rank;
00204     }
00205 
00206     static typename ALU3DSPACE Gitter::Geometric::BuilderIF &getBuilder ( GitterImplType &grid )
00207     {
00208       return dynamic_cast< ALU3DSPACE Gitter::Geometric::BuilderIF & >( grid.containerPll() );
00209     }
00210 
00211     static void duneNotifyMacroGridChanges ( GitterImplType &grid )
00212     {
00213       grid.duneNotifyMacroGridChanges();
00214     } 
00215 
00216     CollectiveCommunication ccobj_;
00217     ALU3DSPACE MpAccessMPI mpAccess_;
00218   };
00219 #endif // #if ALU3DGRID_PARALLEL
00220 
00221 
00222 
00223   // ALU3dGridFamily
00224   // ---------------
00225 
00226   template< ALU3dGridElementType elType, class Comm >
00227   struct ALU3dGridFamily
00228   {
00229     typedef ALU3dGrid< elType, Comm > GridImp;
00230     typedef ALU3dGridFamily< elType, Comm > GridFamily;
00231 
00232     static const int dim = 3;
00233     static const int dimworld = 3;
00234 
00236     typedef ALU3dGridLocalIdSet< elType, Comm > LocalIdSetImp;
00237 
00239     typedef typename ALU3dGridCommunications< elType, Comm >::GlobalIdSet GlobalIdSetImp;
00240     
00242     typedef typename ALU3dGridCommunications< elType, Comm >::GlobalId GlobalIdType;
00243 
00245     typedef int LocalIdType;
00246 
00247     struct Traits
00248     {
00250       typedef typename GridFamily::LocalIdType LocalIdType;
00251 
00253       typedef typename GridFamily::GlobalIdType GlobalIdType;
00254       
00255       typedef typename GridFamily::GridImp Grid;
00256 
00257       typedef Dune::Intersection< const Grid, LeafIntersectionWrapper > LeafIntersection;
00258       typedef Dune::Intersection< const Grid, LevelIntersectionWrapper > LevelIntersection;
00259       
00260       typedef Dune::IntersectionIterator< const Grid, LeafIntersectionIteratorWrapper, LeafIntersectionWrapper > IntersectionIterator;
00261       
00262       typedef Dune::IntersectionIterator< const Grid, LeafIntersectionIteratorWrapper, LeafIntersectionWrapper > LeafIntersectionIterator;
00263       typedef Dune::IntersectionIterator< const Grid, LevelIntersectionIteratorWrapper, LevelIntersectionWrapper > LevelIntersectionIterator;
00264 
00265       typedef Dune::EntityIterator< 0, const Grid, ALU3dGridHierarchicIterator< const Grid > > HierarchicIterator;
00266 
00267       typedef DuneBoundaryProjection< dimworld > DuneBoundaryProjectionType;
00268       typedef std::vector< const DuneBoundaryProjectionType * > DuneBoundaryProjectionVector;
00269 
00270       template< int cd >
00271       struct Codim
00272       {
00273         // IMPORTANT: Codim<codim>::Geometry == Geometry<dim-codim,dimw>
00274         typedef ALU3dGridGeometry< dim-cd, dimworld, const Grid > GeometryImpl;
00275         typedef ALU3dGridGeometry< dim-cd, dim, const Grid > LocalGeometryImpl;
00276         typedef Dune::Geometry< dim-cd, dimworld, const Grid, ALU3dGridGeometry > Geometry;
00277         typedef Dune::Geometry< dim-cd, dim, const Grid, ALU3dGridGeometry > LocalGeometry;
00278 
00279         typedef Dune::Entity< cd, dim, const Grid, ALU3dGridEntity > Entity;
00280 
00281         // minimal information to generate entities
00282         typedef ALU3dGridEntitySeed< cd , const Grid> EntitySeed ; 
00283 
00284         typedef ALU3dGridEntityPointer< cd, const Grid > EntityPointerImpl;
00285         typedef Dune::EntityPointer< const Grid, EntityPointerImpl > EntityPointer;
00286 
00287         template< PartitionIteratorType pitype >
00288         struct Partition
00289         {
00290           typedef Dune::EntityIterator< cd, const Grid, ALU3dGridLevelIterator< cd, pitype, const Grid > > LevelIterator;
00291           typedef Dune::EntityIterator< cd, const Grid, ALU3dGridLeafIterator< cd, pitype, const Grid > > LeafIterator;
00292         }; // struct Partition
00293 
00294         typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
00295         typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
00296       }; // struct Codim
00297       
00298       template< PartitionIteratorType pitype >
00299       struct Partition
00300       {
00301         typedef Dune::GridView<DefaultLevelGridViewTraits< const Grid, pitype > > LevelGridView;
00302         typedef Dune::GridView<DefaultLeafGridViewTraits< const Grid, pitype > > LeafGridView;
00303       }; // struct Partition
00304 
00306       typedef DefaultIndexSet< GridImp, typename Codim< 0 > :: LevelIterator > LevelIndexSetImp; 
00307 
00309       typedef DefaultIndexSet< GridImp, typename Codim< 0 > :: LeafIterator > LeafIndexSetImp; 
00310 
00311       typedef IndexSet< Grid, LevelIndexSetImp > LevelIndexSet;
00312       typedef IndexSet< Grid, LeafIndexSetImp > LeafIndexSet;
00313       typedef IdSet< Grid, LocalIdSetImp, LocalIdType > LocalIdSet;
00314       typedef IdSet< Grid, GlobalIdSetImp, GlobalIdType > GlobalIdSet;
00315 
00316       typedef Dune::CollectiveCommunication< Comm > CollectiveCommunication;
00317     }; // struct Traits
00318 
00320     typedef typename Traits :: LevelIndexSetImp  LevelIndexSetImp; 
00321 
00323     typedef typename Traits :: LeafIndexSetImp   LeafIndexSetImp; 
00324 
00325   }; // struct ALU3dGridFamily
00326 
00327 
00328 
00329   //**********************************************************************
00330   //
00331   // --ALU3dGrid
00332   // --Grid
00333   //
00334   //**********************************************************************
00335 
00356   template< ALU3dGridElementType elType, class Comm >
00357   class ALU3dGrid
00358   : public GridDefaultImplementation< 3, 3, alu3d_ctype, 
00359                                       ALU3dGridFamily< elType, Comm > >,
00360     public HasObjectStream,
00361     public HasHierarchicIndexSet
00362   {
00363     typedef ALU3dGrid< elType, Comm > ThisType; 
00364     typedef GridDefaultImplementation< 3, 3, alu3d_ctype, ALU3dGridFamily< elType, Comm > > BaseType;
00365 
00366     // for compatibility: MyType := ThisType
00367     typedef ThisType MyType;
00368 
00369     // friend declarations
00370     friend class ALU3dGridEntity< 0, 3, const ThisType>;
00371     friend class ALU3dGridEntity< 1, 3, const ThisType>;
00372     friend class ALU3dGridEntity< 2, 3, const ThisType>;
00373     friend class ALU3dGridEntity< 3, 3, const ThisType>;
00374 
00375     friend class ALU3dGridIntersectionIterator< ThisType >;
00376 
00377     friend class ALU3dGridEntityPointerBase< 0, const ThisType >;
00378     friend class ALU3dGridEntityPointerBase< 1, const ThisType >;
00379     friend class ALU3dGridEntityPointerBase< 2, const ThisType >;
00380     friend class ALU3dGridEntityPointerBase< 3, const ThisType >;
00381 
00382     friend class ALU3dGridEntityPointer< 0, const ThisType >;
00383     friend class ALU3dGridEntityPointer< 1, const ThisType >;
00384     friend class ALU3dGridEntityPointer< 2, const ThisType >;
00385     friend class ALU3dGridEntityPointer< 3, const ThisType >;
00386   
00387     friend class ALU3dGridIntersectionIterator< const ThisType >;
00388     friend class ALU3dGridHierarchicIterator< const ThisType >;
00389 
00390     friend class ALU3dGridHierarchicIndexSet< elType, Comm >;
00391     friend class ALU3dGridGlobalIdSet< elType, Comm >;
00392     friend class ALU3dGridLocalIdSet< elType, Comm >;
00393 
00394     friend class Conversion< ThisType, HasObjectStream >;
00395     friend class Conversion< const ThisType, HasObjectStream >;
00396 
00397     friend class Conversion< ThisType, HasHierarchicIndexSet >;
00398     friend class Conversion< const ThisType, HasHierarchicIndexSet >;
00399 
00400     friend class ALU3dGridCommHelper< elType, Comm >;
00401 
00402     // new intersection iterator is a wrapper which get itersectioniteratoimp as pointers
00403   public:    
00404     typedef ALU3dGridIntersectionIterator<const ThisType>
00405       IntersectionIteratorImp;
00406     typedef ALU3dGridIntersectionIterator<const ThisType>
00407       LeafIntersectionIteratorImp;
00408     typedef ALU3dGridLevelIntersectionIterator<const ThisType>
00409       LevelIntersectionIteratorImp;
00410 
00411     friend class IntersectionIteratorWrapper < const ThisType, LeafIntersectionIteratorImp > ;
00412     friend class IntersectionIteratorWrapper < const ThisType, LevelIntersectionIteratorImp > ;
00413     friend class LeafIntersectionIteratorWrapper < const ThisType > ;
00414     friend class LevelIntersectionIteratorWrapper< const ThisType > ;
00415 
00416     //**********************************************************
00417     // The Interface Methods
00418     //**********************************************************
00419   public:
00420     enum { refineStepsForHalf = 1 };
00421     
00422     static const ALU3dGridElementType elementType = elType;
00423     typedef typename ALU3DSPACE GatherScatterType::ObjectStreamType ObjectStreamType;
00424     typedef ObjectStreamType  InStreamType ;
00425     typedef ObjectStreamType  OutStreamType ;
00426 
00427     typedef ALU3dGridFamily< elType, Comm > GridFamily;
00428     typedef typename GridFamily::Traits Traits;
00429 
00430     static const int dimension = BaseType::dimension;
00431     static const int dimensionworld = BaseType::dimensionworld;
00432 
00433   protected:
00434     typedef MakeableInterfaceObject< typename Traits::template Codim< 0 >::Geometry > GeometryObject;
00435     friend class ALULocalGeometryStorage< const ThisType, GeometryObject, 8 >;
00436 
00437   public: 
00439     typedef ALU3dGridHierarchicIndexSet< elType, Comm > HierarchicIndexSet;
00440     
00442     typedef typename GridFamily::LevelIndexSetImp LevelIndexSetImp; 
00444     typedef typename GridFamily::LeafIndexSetImp LeafIndexSetImp; 
00445 
00447     typedef GenericReferenceElement< alu3d_ctype, dimension > ReferenceElementType;
00448 
00450     typedef typename Traits::DuneBoundaryProjectionType DuneBoundaryProjectionType;
00452     typedef typename Traits::DuneBoundaryProjectionVector DuneBoundaryProjectionVector;
00453 
00455     typedef ALU3DSPACE ProjectVertex ALUGridVertexProjectionType;
00456 
00458     typedef typename Traits::CollectiveCommunication CollectiveCommunication;
00459 
00460   public:
00461     typedef MakeableInterfaceObject<typename Traits::template Codim<0>::Entity> EntityObject; 
00462     typedef MakeableInterfaceObject<typename Traits::template Codim<1>::Entity> FaceObject; 
00463     typedef MakeableInterfaceObject<typename Traits::template Codim<2>::Entity> EdgeObject; 
00464     typedef MakeableInterfaceObject<typename Traits::template Codim<3>::Entity> VertexObject; 
00465 
00466     typedef ALUGridObjectFactory< ThisType >  GridObjectFactoryType;
00467 
00468   protected:
00469     friend class ALUGridBoundaryProjection< ThisType, alu3d_ctype >;
00470     // type of ALUGrid boundary projection wrapper 
00471     typedef ALUGridBoundaryProjection< ThisType, alu3d_ctype > ALUGridBoundaryProjectionType;
00472 
00474     typedef typename GridFamily::LocalIdSetImp LocalIdSetImp;
00475     
00477     typedef typename GridFamily::GlobalIdSetImp GlobalIdSetImp;
00478    
00480     typedef typename Traits::GlobalIdSet GlobalIdSet;
00481     
00483     typedef typename Traits::LocalIdSet LocalIdSet;
00484     
00486     typedef ALU3dGridLeafIterator< 0, All_Partition, const ThisType > LeafIteratorImp;
00487     typedef typename Traits::template Codim< 0 >::LeafIterator LeafIteratorType;
00488     typedef typename Traits::template Codim< 0 >::LeafIterator LeafIterator;
00489     
00490     typedef ALU3dGridHierarchicIterator< const ThisType > HierarchicIteratorImp;
00491       
00492     typedef typename ALU3dImplTraits< elType, Comm >::GitterImplType GitterImplType;
00493 
00495     enum { 
00497       MAXL = 32 };
00498 
00500     enum { 
00502       newElementsChunk_ = 128 };
00503 
00505     enum { 
00509       refineEstimate_ = 8 };
00510 
00511   public:
00512     typedef Comm MPICommunicatorType;
00513 
00514     typedef ALU3dGridCommunications< elType, Comm > Communications;
00515 
00516   protected:
00517     typedef ALU3dGridVertexList< Comm > VertexListType; 
00518     typedef ALU3dGridLeafVertexList< Comm > LeafVertexListType; 
00519 
00522     ALU3dGrid ( const std::string &macroTriangFilename,
00523                 const MPICommunicatorType mpiComm,
00524                 const DuneBoundaryProjectionType *bndPrj,
00525                 const DuneBoundaryProjectionVector *bndVec,
00526                 const ALUGridRefinementType refinementType );
00527 
00528   public:  
00530     virtual ~ALU3dGrid();
00531 
00533     static inline std::string name (); 
00534    
00538     int maxLevel() const;
00539 
00541     template<int cd, PartitionIteratorType pitype>
00542     typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
00543     lbegin (int level) const;
00544   
00546     template<int cd, PartitionIteratorType pitype>
00547     typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
00548     lend (int level) const;
00549   
00551     template<int cd>
00552     typename Traits::template Codim<cd>::
00553     template Partition<All_Partition>::LevelIterator 
00554     lbegin (int level) const;
00555 
00557     template<int cd>
00558     typename Traits::template Codim<cd>::
00559     template Partition<All_Partition>::LevelIterator 
00560     lend (int level) const;
00561 
00562   private:  
00564     template <int codim, PartitionIteratorType pitype>
00565     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00566     leafbegin(int level) const;
00567 
00569     template <int codim, PartitionIteratorType pitype>
00570     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00571     leafend(int level) const;
00572 
00574     template <int codim>
00575     typename Traits::template Codim<codim>::LeafIterator
00576     leafbegin(int level) const;
00577 
00579     template <int codim>
00580     typename Traits::template Codim<codim>::LeafIterator
00581     leafend(int level) const;
00582 
00584     LeafIteratorType leafbegin (int level) const;
00585 
00587     LeafIteratorType leafend (int level) const;
00588 
00590     LeafIteratorType leafbegin () const;
00591 
00593     LeafIteratorType leafend () const;
00594 
00595   public:
00597     template <int codim, PartitionIteratorType pitype>
00598     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00599     leafbegin() const;
00600 
00602     template <int codim, PartitionIteratorType pitype>
00603     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00604     leafend() const;
00605 
00607     template <int codim>
00608     typename Traits::template Codim<codim>::LeafIterator
00609     leafbegin() const;
00610 
00612     template <int codim>
00613     typename Traits::template Codim<codim>::LeafIterator
00614     leafend() const;
00615 
00616   private:
00618     template <int codim, PartitionIteratorType pitype>
00619     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00620     createLeafIteratorBegin (int level) const;
00621 
00623     template <int codim, PartitionIteratorType pitype>
00624     typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00625     createLeafIteratorEnd(int level) const;
00626     
00627   public:  
00629     int size (int level, int cd) const;
00630 
00632     int size (int codim) const;
00633 
00635     int size (int level, GeometryType type) const;
00636 
00638     size_t numBoundarySegments() const;
00639 
00641     int size (GeometryType type) const;
00642 
00644     int global_size (int cd) const ;
00645 
00646     // (no interface method) number of grid entities in the entire grid for given codim
00647     int hierSetSize (int cd) const;
00648 
00650     const GlobalIdSet &globalIdSet () const
00651     {
00652       if( !globalIdSet_ )
00653         globalIdSet_ = new GlobalIdSetImp( *this );
00654       return *globalIdSet_;
00655     }
00656 
00658     const LocalIdSet & localIdSet () const { return localIdSet_; }
00659 
00661     const typename Traits :: LeafIndexSet & leafIndexSet () const; 
00662 
00664     const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;
00665 
00670     bool loadBalance ();
00671   
00698     template <class DataHandle>
00699     bool loadBalance (DataHandle & data);
00700 
00701     template< class DataHandleImpl, class Data >
00702     bool loadBalance ( CommDataHandleIF< DataHandleImpl, Data > &dataHandle )
00703     {
00704       typedef ALUGridLoadBalanceDataHandle< ThisType, DataHandleImpl, Data > LBHandle;
00705       LBHandle lbHandle( *this, dataHandle );
00706       return loadBalance( lbHandle );
00707     }
00708  
00710     int ghostSize (int level, int codim) const; 
00711 
00713     int overlapSize (int level, int codim) const { return 0; } 
00714 
00716     int ghostSize (int codim) const;
00717 
00719     int overlapSize (int codim) const { return 0; } 
00720 
00722     template<class DataHandleImp,class DataTypeImp>
00723     void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data, 
00724         InterfaceType iftype, CommunicationDirection dir, int level) const;
00725 
00729     template<class DataHandleImp,class DataTypeImp>
00730     void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data, 
00731         InterfaceType iftype, CommunicationDirection dir) const;
00732 
00733   private:
00734     typedef ALU3DSPACE GatherScatter GatherScatterType;
00735 
00736   public:
00738     const CollectiveCommunication &comm () const { return communications().ccobj_; }
00739  
00741     bool preAdapt ( );
00742 
00744     void postAdapt ( );
00745 
00747     bool adapt ();
00748 
00753     template< class GridImp, class DataHandle >
00754     bool adapt ( AdaptDataHandleInterface< GridImp, DataHandle > &handle );
00755 
00757     void globalRefine ( int refCount );
00758 
00759     template< class GridImp, class DataHandle >
00760     void globalRefine ( int refCount, AdaptDataHandleInterface< GridImp, DataHandle > &handle );
00761 
00762     //**********************************************************
00763     // End of Interface Methods
00764     //**********************************************************
00767     template <GrapeIOFileFormatType ftype>
00768     bool writeGrid( const std::string filename, alu3d_ctype time ) const ;
00769 
00770     bool writeGrid_Xdr( const std::string filename, alu3d_ctype time ) const ;
00772     bool writeGrid_Ascii( const std::string filename, alu3d_ctype time, bool scientific = false ) const ;
00773   
00776     bool writeMacroGrid( const std::string path, const std::string filename ) const ;
00777 
00780     template <GrapeIOFileFormatType ftype>
00781     bool readGrid( const std::string filename, alu3d_ctype & time );
00782 
00783     // (no interface method) get hierarchic index set of the grid
00784     const HierarchicIndexSet & hierarchicIndexSet () const { return hIndexSet_; }
00785 
00786     // set max of given mxl and actual maxLevel 
00787     // for loadBalance 
00788     void setMaxLevel (int mxl);
00789  
00790     // no interface method, but has to be public 
00791     void updateStatus ();
00792  
00794     bool mark( int refCount , const typename Traits::template Codim<0>::Entity & e);
00795     
00797     int getMark( const typename Traits::template Codim<0>::Entity & e) const;
00798     
00799   public:
00800     static MPICommunicatorType defaultCommunicator ()
00801     {
00802       return Communications::defaultComm();
00803     }
00804 
00805     using BaseType :: getRealImplementation ;
00806 
00807     template< class IntersectionType >
00808     static const typename BaseType
00809       :: template ReturnImplementationType< IntersectionType >
00810       :: ImplementationType &
00811     getRealIntersection ( const IntersectionType &intersection )
00812     {
00813       return getRealImplementation( intersection );
00814     }
00815 
00817     const std::vector<GeometryType>& geomTypes (int codim) const { return geomTypes_[codim]; }
00818     
00819     // return reference to org ALU3dGrid 
00820     // private method, but otherwise we have to friend class all possible
00821     // types of LevelIterator ==> later
00822     GitterImplType &myGrid () const;
00823 
00824     virtual GitterImplType *createALUGrid ( const std::string &macroName )
00825     {
00826       assert( communications_ );
00827       return communications_->createALUGrid( macroName, vertexProjection() );
00828     }
00829 
00830     ALUGridVertexProjectionType* vertexProjection() { return (ALUGridVertexProjectionType *) vertexProjection_; }
00831 
00832     // return appropriate ALUGrid builder 
00833     virtual typename ALU3DSPACE Gitter::Geometric::BuilderIF &getBuilder () const
00834     {
00835       return Communications::getBuilder( myGrid() );
00836     }
00837 
00838     // helper function for factory 
00839     virtual void duneNotifyMacroGridChanges ()
00840     {
00841       Communications::duneNotifyMacroGridChanges( myGrid() );
00842     }
00843     
00845     const ReferenceElementType & referenceElement() const { return referenceElement_; }
00846 
00847     template < class EntitySeed > 
00848     typename Traits :: template Codim< EntitySeed :: codimension > :: EntityPointer
00849     entityPointer( const EntitySeed& seed ) const 
00850     {
00851       enum { codim = EntitySeed :: codimension };
00852       typedef typename Traits :: template Codim< codim > :: EntityPointer EntityPointer;
00853       typedef ALU3dGridEntityPointer < codim, const ThisType > ALUPointer ;
00854       return ALUPointer( factory(), seed ) ;
00855     }
00856 
00857     // number of links to other processors, for internal use only 
00858     int nlinks () const { return communications().nlinks(); }
00859 
00860     LeafVertexListType & getLeafVertexList() const 
00861     {
00862       if( !leafVertexList_.up2Date() ) leafVertexList_.setupVxList(*this);
00863       return leafVertexList_;
00864     }
00865 
00866     int getLevelOfLeafVertex ( const typename ALU3dImplTraits< elType, Comm >::VertexType &vertex ) const
00867     {
00868       assert( leafVertexList_.up2Date() );
00869       return leafVertexList_.getLevel(vertex);
00870     }
00871       
00872     VertexListType & getVertexList(int level) const 
00873     {
00874       assert( level >= 0 );
00875       assert( level <= maxLevel() );
00876       VertexListType & vxList = vertexList_[level];
00877       if(!vxList.up2Date()) vxList.setupVxList(*this,level);
00878       return vxList; 
00879     }
00880     
00881     ALU3dGridItemListType & getGhostLeafList(int codim) const
00882     {
00883       assert( codim >= 1 );
00884       assert( codim <= 3 );
00885       return ghostLeafList_[codim-1];
00886     }
00887     
00888     ALU3dGridItemListType & getGhostLevelList(int codim, int level) const
00889     {
00890       assert( codim >= 1 );
00891       assert( codim <= 3 );
00892 
00893       assert( level >= 0 );
00894       assert( level <= maxLevel() );
00895       return ghostLevelList_[codim-1][level];
00896     }
00897     
00898     ALU3dGridItemListType & getEdgeList(int level) const 
00899     { 
00900       assert( level >= 0 );
00901       assert( level <= maxLevel() );
00902       return levelEdgeList_[level]; 
00903     }
00904 
00905   protected:
00907     ALU3dGrid( const ThisType & );
00908   
00910     const ThisType &operator= ( const ThisType & );
00911   
00913     void calcExtras();
00914   
00916     void calcMaxLevel();
00917   
00919     void recalcGlobalSize();
00920 
00922     void checkMacroGridFile (const std::string filename);
00923 
00925     void checkMacroGrid ();
00926 
00928     const DuneBoundaryProjectionType* boundaryProjection(const int segmentIndex) const 
00929     {
00930       if( bndPrj_ ) 
00931       {
00932         return bndPrj_;
00933       }
00934       else 
00935       {
00936         // pointer can be zero (which is emulates the identity mapping then)
00937         assert( bndVec_ );
00938         assert( segmentIndex < (int) bndVec_->size() );
00939         return (*bndVec_)[ segmentIndex ];
00940       }
00941     }
00942 
00943     const Communications &communications () const
00944     {
00945       assert( communications_ );
00946       return *communications_;
00947     }
00948 
00949     const GridObjectFactoryType& factory() const { 
00950 #ifdef USE_SMP_PARALLEL
00951       assert( (int) factoryVec_.size() > GridObjectFactoryType :: threadNumber() );
00952       return factoryVec_[ GridObjectFactoryType :: threadNumber() ];
00953 #else 
00954       return factory_; 
00955 #endif
00956     }
00957 
00958     bool conformingRefinement() const
00959     {
00960       return (refinementType_ == conforming) ;
00961     }
00962   protected:
00964     //
00965     // Internal variables  
00966     //
00968 
00969     // the real ALU grid 
00970     mutable GitterImplType *mygrid_;
00971 
00972     // max level of grid 
00973     int maxlevel_; 
00974 
00975     // count how much elements where marked 
00976     mutable int coarsenMarked_;
00977     mutable int refineMarked_;
00978 
00979     // at the moment the number of different geom types is 1 
00980     enum { numberOfGeomTypes = 1 };
00981     std::vector< std::vector<GeometryType> > geomTypes_; 
00982 
00983     // our hierarchic index set 
00984     HierarchicIndexSet hIndexSet_;
00985 
00986     // out global id set 
00987     mutable GlobalIdSetImp *globalIdSet_; 
00988 
00989     // out global id set 
00990     LocalIdSetImp localIdSet_;
00991 
00992     // the level index set ( default type )
00993     mutable std::vector < LevelIndexSetImp * > levelIndexVec_;
00994 
00995     // the leaf index set
00996     mutable LeafIndexSetImp * leafIndexSet_;
00997  
00998     // the reference element 
00999     const ReferenceElementType& referenceElement_;
01000 
01001     mutable VertexListType vertexList_[MAXL];   
01002 
01003     mutable ALU3dGridItemListType ghostLeafList_[ dimension ];   
01004     mutable ALU3dGridItemListType ghostLevelList_[ dimension ][MAXL];   
01005     
01006     mutable ALU3dGridItemListType levelEdgeList_[MAXL];   
01007 
01008     mutable LeafVertexListType leafVertexList_;
01009     
01010     // the type of our size cache 
01011     typedef SizeCache<MyType> SizeCacheType;
01012     SizeCacheType * sizeCache_;
01013 
01014 #ifdef USE_SMP_PARALLEL
01015     std::vector< GridObjectFactoryType > factoryVec_;
01016 #else 
01017     GridObjectFactoryType factory_;
01018 #endif
01019 
01020     // variable to ensure that postAdapt ist called after adapt
01021     bool lockPostAdapt_;
01022 
01023     // pointer to Dune boundary projection 
01024     const DuneBoundaryProjectionType* bndPrj_; 
01025 
01026     // pointer to Dune boundary projection 
01027     const DuneBoundaryProjectionVector* bndVec_; 
01028 
01029     // boundary projection for vertices  
01030     ALUGridBoundaryProjectionType* vertexProjection_ ;
01031 
01032     // pointer to communications object 
01033     Communications *communications_;
01034 
01035     // refinement type (nonconforming or conforming)
01036     const ALUGridRefinementType refinementType_ ;
01037   }; // end class ALU3dGrid
01038 
01039 
01040     bool checkMacroGrid ( ALU3dGridElementType elType , 
01041                           const std::string filename );
01042     const char* elType2Name( ALU3dGridElementType elType );
01043 
01044   namespace Capabilities
01045   {
01046 
01047     template< ALU3dGridElementType elType, class Comm, int cdim >
01048     struct hasEntity< Dune::ALU3dGrid< elType, Comm >, cdim >
01049     {
01050       static const bool v = true;
01051     };
01052     
01053     template< ALU3dGridElementType elType, class Comm >
01054     struct isParallel< ALU3dGrid< elType, Comm > >
01055     {
01056       static const bool v = true;
01057     };
01058 
01059     template< ALU3dGridElementType elType, class Comm >
01060     struct isLevelwiseConforming< ALU3dGrid< elType, Comm > >
01061     {
01062       static const bool v = true;
01063     };
01064   
01065     template< ALU3dGridElementType elType, class Comm >
01066     struct hasBackupRestoreFacilities< ALU3dGrid< elType, Comm > >
01067     {
01068       static const bool v = true;
01069     };
01070 
01071   } // end namespace Capabilities
01072   
01073 } // end namespace Dune
01074 
01075 #include "grid_inline.hh"
01076 #if COMPILE_ALUGRID_INLINE
01077   #include "grid_imp.cc"
01078 #endif
01079 #endif