00001 #ifndef DUNE_ALU2DGRIDGRID_HH
00002 #define DUNE_ALU2DGRIDGRID_HH
00003
00004
00005 #include "alu2dinclude.hh"
00006 #include <vector>
00007
00008
00009 #include <dune/grid/common/capabilities.hh>
00010 #include <dune/common/interfaces.hh>
00011 #include <dune/common/deprecated.hh>
00012 #include <dune/common/static_assert.hh>
00013
00014 #include <dune/grid/common/grid.hh>
00015 #include <dune/grid/common/referenceelements.hh>
00016 #include <dune/grid/common/defaultindexsets.hh>
00017 #include <dune/grid/common/sizecache.hh>
00018 #include <dune/common/mpihelper.hh>
00019 #if ALU2DGRID_PARALLEL
00020 #include <dune/common/mpicollectivecommunication.hh>
00021 #include "communicator.hh"
00022 #else
00023 #include <dune/common/collectivecommunication.hh>
00024 #endif
00025 #include <dune/grid/common/intersectioniteratorwrapper.hh>
00026
00027
00028 #include "indexsets.hh"
00029 #include "../3d/memory.hh"
00030 #include "datahandle.hh"
00031
00032 namespace Dune {
00033
00034 typedef double alu2d_ctype;
00035
00036
00037 template<int cd, int dim, class GridImp>
00038 class ALU2dGridEntity;
00039 template<int cd, PartitionIteratorType pitype, class GridImp >
00040 class ALU2dGridLevelIterator;
00041 template<int cd, class GridImp >
00042 class ALU2dGridEntityPointer;
00043 template<int mydim, int coorddim, class GridImp>
00044 class ALU2dGridMakeableGeometry;
00045 template<int mydim, int cdim, class GridImp>
00046 class ALU2dGridGeometry;
00047 template<class GridImp>
00048 class ALU2dGridHierarchicIterator;
00049 template<class GridImp>
00050 class ALU2dGridIntersectionBase;
00051 template<class GridImp>
00052 class ALU2dGridLevelIntersectionIterator;
00053 template<class GridImp>
00054 class ALU2dGridLeafIntersectionIterator;
00055 template<int codim, PartitionIteratorType pitype, class GridImp>
00056 class ALU2dGridLeafIterator;
00057 template <int mydim, int coorddim, class GridImp>
00058 class ALU2dGridMakeableEntity;
00059 template <class GridImp>
00060 class ALU2dGridFaceGeometryInfo;
00061 template<int dim, int dimworld>
00062 class ALU2dGridGlobalIdSet;
00063 template<int dim, int dimworld>
00064 class ALU2dGridLocalIdSet;
00065 template<int dim, int dimworld>
00066 class ALU2dGridHierarchicIndexSet;
00067 template <class EntityImp>
00068 class ALUMemoryProvider;
00069 template<int dim, int dimworld>
00070 class ALU2dGrid;
00071 template <class GeometryImp, int nChild>
00072 class ALU2DLocalGeometryStorage;
00073 template <class GridImp, int codim>
00074 struct ALU2dGridEntityFactory;
00075
00076 class ALU2dObjectStream;
00077
00078
00079
00080
00081
00082
00083
00084 template <int dim, int dimworld>
00085 struct ALU2dGridFamily
00086 {
00088 typedef ALU2dGridLocalIdSet<dim,dimworld> GlobalIdSetImp;
00089
00091 typedef ALU2dGridLocalIdSet<dim,dimworld> LocalIdSetImp;
00092
00094 typedef DefaultLevelIndexSet<ALU2dGrid < dim, dimworld > > LevelIndexSetImp;
00096 typedef DefaultLeafIndexSet<ALU2dGrid < dim, dimworld > > LeafIndexSetImp;
00097
00098 typedef int GlobalIdType;
00099 typedef int LocalIdType;
00100
00101 typedef ALU2dGrid<dim,dimworld> GridImp;
00102
00103 struct Traits
00104 {
00105 typedef ALU2dGrid<dim,dimworld> Grid;
00106
00107 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper> IntersectionIterator;
00108 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper> LeafIntersectionIterator;
00109 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper> LeafIntersection;
00110 typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorWrapper> LevelIntersectionIterator;
00111 typedef Dune::IntersectionIterator<const GridImp, LevelIntersectionIteratorWrapper> LevelIntersection;
00112
00113 typedef Dune::HierarchicIterator<const GridImp, ALU2dGridHierarchicIterator> HierarchicIterator;
00114
00115 template <int cd>
00116 struct Codim
00117 {
00118
00119 typedef Dune::Geometry<dim-cd, dimworld, const GridImp, ALU2dGridGeometry> Geometry;
00120 typedef Dune::Geometry<dim-cd, dim, const GridImp, ALU2dGridGeometry> LocalGeometry;
00121
00122 typedef Dune::Entity<cd, dim, const GridImp, ALU2dGridEntity> Entity;
00123
00124 typedef Dune::LevelIterator<cd,All_Partition,const GridImp,ALU2dGridLevelIterator> LevelIterator;
00125
00126 typedef Dune::LeafIterator<cd,All_Partition,const GridImp,ALU2dGridLeafIterator> LeafIterator;
00127
00128 typedef Dune::EntityPointer<const GridImp,ALU2dGridEntityPointer<cd,const GridImp> > EntityPointer;
00129
00130 template <PartitionIteratorType pitype>
00131 struct Partition
00132 {
00133 typedef Dune::LevelIterator<cd,pitype,const GridImp,ALU2dGridLevelIterator> LevelIterator;
00134 typedef Dune::LeafIterator<cd,pitype,const GridImp,ALU2dGridLeafIterator> LeafIterator;
00135 };
00136
00137 };
00138
00139 typedef IndexSet<GridImp,LevelIndexSetImp,DefaultLevelIteratorTypes<GridImp> > LevelIndexSet;
00140 typedef LeafIndexSetImp LeafIndexSet;
00141 typedef IdSet<GridImp,GlobalIdSetImp,GlobalIdType> GlobalIdSet;
00142 typedef IdSet<GridImp,LocalIdSetImp,LocalIdType> LocalIdSet;
00143
00144 #if ALU2DGRID_PARALLEL
00145 typedef CollectiveCommunication<MPI_Comm> CollectiveCommunication;
00146 #else
00147 typedef CollectiveCommunication<GridImp> CollectiveCommunication;
00148 #endif
00149 };
00150 };
00151
00152
00167 template <int dim, int dimworld>
00168 class ALU2dGrid :
00169 public GridDefaultImplementation<dim,dimworld,alu2d_ctype,ALU2dGridFamily<dim,dimworld> >,
00170 public HasObjectStream,
00171 public HasHierarchicIndexSet
00172 {
00173 dune_static_assert(dim == 2, "ALU2dGrid only implemented for 2dp");
00174 dune_static_assert(dimworld == 2, "ALU2dGrid only implemented for 2dw");
00175
00176 typedef ALU2dGrid<dim,dimworld> ThisType;
00177 typedef GridDefaultImplementation<dim,dimworld,alu2d_ctype,ALU2dGridFamily<dim,dimworld> > BaseType;
00178
00179 friend class ALU2dGridEntity<0,dim,const ThisType>;
00180 friend class ALU2dGridEntity<1,dim,const ThisType>;
00181 friend class ALU2dGridEntity<dim,dim,const ThisType>;
00182
00183 friend class ALU2dGridGeometry<0,dimworld,const ThisType>;
00184 friend class ALU2dGridGeometry<1,dimworld,const ThisType>;
00185 friend class ALU2dGridGeometry<dim,dimworld,const ThisType>;
00186
00187 friend class ALU2dGridEntityPointer<0,const ThisType>;
00188 friend class ALU2dGridEntityPointer<1,const ThisType>;
00189 friend class ALU2dGridEntityPointer<dim,const ThisType>;
00190
00191 friend class ALU2dGridHierarchicIndexSet<dim,dimworld>;
00192
00193
00194
00195 friend class ALU2dGridIntersectionBase < const ThisType > ;
00196 friend class ALU2dGridLevelIntersectionIterator< const ThisType > ;
00197 friend class ALU2dGridLeafIntersectionIterator< const ThisType > ;
00198
00199
00200
00201
00202 public:
00204 typedef typename ALU2dGridFamily < dim , dimworld > :: Traits Traits;
00205
00206 protected:
00207 typedef MakeableInterfaceObject<typename Traits::template
00208 Codim<0>::Geometry> GeometryObject;
00209 friend class ALU2DLocalGeometryStorage<GeometryObject, 4 >;
00210 friend class ALU2DLocalGeometryStorage<GeometryObject, 2 >;
00211
00212 public:
00213
00215 typedef ALU2dGridObjectStream ObjectStreamType;
00216
00218 typedef ALU2dGridFamily < dim , dimworld > GridFamily;
00220 typedef ALU2dGridHierarchicIndexSet<dim,dimworld> HierarchicIndexSet;
00221
00223 typedef ALU2dGridLocalIdSet<dim,dimworld> LocalIdSetImp;
00224 typedef LocalIdSetImp GlobalIdSetImp;
00225
00227 typedef typename Traits :: GlobalIdSet GlobalIdSet;
00228
00230 typedef typename Traits :: LocalIdSet LocalIdSet;
00231
00232
00234 typedef typename GridFamily :: LevelIndexSetImp LevelIndexSetImp;
00236 typedef typename GridFamily :: LeafIndexSetImp LeafIndexSetImp;
00237
00239 typedef ALU2dGridLeafIterator<0, All_Partition, const ThisType> LeafIteratorImp;
00240 typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
00241 typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
00242
00244 typedef ALU2dGridLevelIterator<0, All_Partition, const ThisType> LevelIteratorImp;
00245 typedef typename Traits::template Codim<0>::LevelIterator LevelIteratorType;
00246 typedef typename Traits::template Codim<0>::LevelIterator LevelIterator;
00247
00248 typedef ALU2dGridHierarchicIterator<ThisType> HierarchicIteratorImp;
00249
00250 typedef typename Traits::CollectiveCommunication CollectiveCommunicationType;
00251
00253 enum {
00255 MAXL = 64 };
00256
00258 enum {
00260 newElementsChunk_ = 100 };
00261
00263 enum {
00267 refineEstimate_ = 40 };
00268
00269
00270 protected:
00273 ALU2dGrid(std::string macroTriangFilename );
00274 ALU2dGrid(std::string macroTriangFilename, int nrOfHangingNodes );
00276 ALU2dGrid( int );
00277
00278 public:
00280 ~ALU2dGrid();
00281
00283 std::string name () const;
00284
00287 int maxLevel() const;
00288
00291 template<int cd, PartitionIteratorType pitype>
00292 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
00293 lbegin (int level) const;
00294
00296 template<int cd, PartitionIteratorType pitype>
00297 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
00298 lend (int level) const;
00299
00301 template<int cd>
00302 typename Traits::template Codim<cd>::
00303 template Partition<All_Partition>::LevelIterator
00304 lbegin (int level) const;
00305
00307 template<int cd>
00308 typename Traits::template Codim<cd>::
00309 template Partition<All_Partition>::LevelIterator
00310 lend (int level) const;
00311
00313 LevelIteratorType lbegin (int level) const;
00314
00316 LevelIteratorType lend (int level) const;
00317
00319 template <int codim, PartitionIteratorType pitype>
00320 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00321 leafbegin() const;
00322
00324 template <int codim, PartitionIteratorType pitype>
00325 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
00326 leafend() const;
00327
00329 template <int codim>
00330 typename Traits::template Codim<codim>::LeafIterator
00331 leafbegin() const;
00332
00334 template <int codim>
00335 typename Traits::template Codim<codim>::LeafIterator
00336 leafend() const;
00337
00338 private:
00340 LeafIteratorType leafbegin () const;
00341
00343 LeafIteratorType leafend () const;
00344
00345 public:
00347 int size (int level, int cd) const;
00348
00350 int size (int codim) const;
00351
00353 int size (int level, GeometryType type) const;
00354
00356 int size (GeometryType type) const;
00357
00359 const std::vector<GeometryType>& geomTypes (int codim) const { return geomTypes_[codim]; }
00360
00361
00362
00363
00364
00366 const GlobalIdSet & globalIdSet () const;
00367
00369 const LocalIdSet & localIdSet () const;
00370
00372 int hierSetSize (int cd) const;
00373
00375 const HierarchicIndexSet & hierarchicIndexSet () const ;
00376
00378 const typename Traits :: LeafIndexSet & leafIndexSet () const;
00379
00381 const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 ALU2DSPACE Hmesh & myGrid();
00392 ALU2DSPACE Hmesh & myGrid() const;
00393
00395 bool globalRefine(int refCount);
00396
00398 bool preAdapt ( );
00399
00401 void postAdapt ( );
00402
00406 bool adapt ( );
00407
00409 template <class DofManagerType, class RestrictProlongOperatorType>
00410 bool adapt (DofManagerType &, RestrictProlongOperatorType &, bool verbose=false );
00411
00412
00413 bool refineGrid();
00414
00418 bool mark( int refCount , const typename Traits::template Codim<0>::EntityPointer & ep );
00419
00421 int getMark(const typename Traits::template Codim<0>::EntityPointer & ) const;
00422
00424 int getMark(const typename Traits::template Codim<0>::Entity & ) const;
00425
00427 const CollectiveCommunicationType & comm() const;
00428
00429 bool mark( int refCount , const typename Traits::template Codim<0>::Entity & en );
00430 private:
00431 CollectiveCommunicationType comm_;
00432
00433 void updateStatus();
00434
00435 void calcMaxlevel();
00436
00437 void calcExtras();
00438
00439 typedef typename ALU2dImplTraits::template Codim<0>:: InterfaceType ALUElementType;
00440
00441 void hierarchicClear(ALUElementType* el);
00442 public:
00443 typedef MakeableInterfaceObject<typename Traits::template Codim<0>::Entity> EntityObject;
00444 typedef MakeableInterfaceObject<typename Traits::template Codim<1>::Entity> FaceObject;
00445 typedef MakeableInterfaceObject<typename Traits::template Codim<2>::Entity> VertexObject;
00446 private:
00447 typedef ALUMemoryProvider< EntityObject > EntityProviderType;
00448 typedef ALUMemoryProvider< FaceObject > FaceProviderType;
00449 typedef ALUMemoryProvider< VertexObject > VertexProviderType;
00450
00451 mutable EntityProviderType entityProvider_;
00452 mutable FaceProviderType faceProvider_;
00453 mutable VertexProviderType vertexProvider_;
00454
00455 friend class ALU2dGridEntityFactory<ThisType,0>;
00456 friend class ALU2dGridEntityFactory<ThisType,1>;
00457 friend class ALU2dGridEntityFactory<ThisType,2>;
00458
00459 template <int codim>
00460 MakeableInterfaceObject<typename Traits::template Codim<codim>:: Entity> * getNewEntity ( int level ) const
00461 {
00462 return ALU2dGridEntityFactory<ThisType,codim>::getNewEntity(*this,level);
00463 }
00464
00465 template <class EntityType>
00466 void freeEntity (EntityType * en) const
00467 {
00468 enum { codim = EntityType::codimension };
00469 return ALU2dGridEntityFactory<ThisType,codim>::freeEntity(*this, en);
00470 }
00471
00472
00473 void makeGeomTypes ();
00474
00475 friend class Conversion<ALU2dGrid<dim, dimworld>, HasObjectStream>;
00476 friend class Conversion<const ALU2dGrid<dim, dimworld>, HasObjectStream>;
00477
00478 friend class Conversion<ALU2dGrid<dim, dimworld>, HasHierarchicIndexSet>;
00479 friend class Conversion<const ALU2dGrid<dim, dimworld>, HasHierarchicIndexSet>;
00480
00482 ALU2dGrid( const ThisType & g );
00483
00485 ThisType & operator = (const ThisType & g);
00486
00487
00488 const char * checkMacroGridFile(const std::string & filename);
00489
00491 mutable ALU2DSPACE Hmesh* mygrid_;
00492
00493
00494 ALU2DSPACE Hmesh& mesh() const {
00495 assert(mygrid_);
00496 return *mygrid_;
00497 }
00498
00499
00501 HierarchicIndexSet hIndexSet_;
00502
00504 LocalIdSetImp localIdSet_;
00505
00507 mutable std::vector < LevelIndexSetImp * > levelIndexVec_;
00508
00509
00510 enum { numberOfGeomTypes = 1 };
00511 std::vector< std::vector<GeometryType> > geomTypes_;
00512
00514 mutable LeafIndexSetImp * leafIndexSet_;
00515
00516 int maxLevel_;
00517 int refineMarked_ , coarsenMarked_;
00518 const int nrOfHangingNodes_;
00519
00520
00521
00522
00524 typedef SingleTypeSizeCache<ThisType> SizeCacheType;
00525 SizeCacheType * sizeCache_;
00526
00527
00528 bool lockPostAdapt_;
00529
00530
00531 public:
00532 typedef ALU2dGridLeafIntersectionIterator <const ThisType> LeafIntersectionIteratorImp;
00533 typedef ALU2dGridLevelIntersectionIterator<const ThisType> LevelIntersectionIteratorImp;
00534
00535 typedef ALUMemoryProvider< LeafIntersectionIteratorImp > LeafIntersectionIteratorProviderType;
00536 typedef ALUMemoryProvider< LevelIntersectionIteratorImp > LevelIntersectionIteratorProviderType;
00537
00538 public:
00539 template <class IntersectionInterfaceType>
00540 const typename BaseType::
00541 template ReturnImplementationType<IntersectionInterfaceType> :: ImplementationType &
00542 getRealIntersectionIterator(const IntersectionInterfaceType & it) const
00543 {
00544 return this->getRealImplementation(it);
00545 }
00546
00547 private:
00548
00549 int maxlevel_;
00550 friend class LeafIntersectionIteratorWrapper< const ThisType > ;
00551 friend class LevelIntersectionIteratorWrapper< const ThisType > ;
00552
00553 LeafIntersectionIteratorProviderType & leafIntersetionIteratorProvider() const
00554 {
00555 return leafInterItProvider_;
00556 }
00557 mutable LeafIntersectionIteratorProviderType leafInterItProvider_;
00558
00559 LevelIntersectionIteratorProviderType & levelIntersetionIteratorProvider() const
00560 {
00561 return levelInterItProvider_;
00562 }
00563 mutable LevelIntersectionIteratorProviderType levelInterItProvider_;
00564
00565 mutable ALU2dGridMarkerVector marker_[MAXL];
00566 public:
00567 typedef ALU2dGridLeafMarkerVector ALU2dGridLeafMarkerVectorType;
00568 private:
00569
00570 mutable ALU2dGridLeafMarkerVectorType leafMarker_;
00571
00572 public:
00575 ALU2dGridMarkerVector & getMarkerVector(int level) const
00576 {
00577 assert( level >= 0);
00578 assert( level <= MAXL);
00579 return marker_[level];
00580 }
00581
00584 ALU2dGridLeafMarkerVectorType & getLeafMarker() const
00585 {
00586 return leafMarker_;
00587 }
00588
00591 template <GrapeIOFileFormatType ftype>
00592 bool writeGrid( const std::string filename, alu2d_ctype time ) const ;
00593
00594 bool writeGrid_Xdr( const std::string filename, alu2d_ctype time ) const ;
00595 bool writeGrid_Ascii( const std::string filename, alu2d_ctype time ) const ;
00596
00599 template <GrapeIOFileFormatType ftype>
00600 bool readGrid( const std::string filename, alu2d_ctype & time );
00601
00602 protected:
00605 bool nonConform () const
00606 {
00607 return (nrOfHangingNodes_ > 0);
00608 }
00609
00610 #if ALU2DGRID_PARALLEL
00611 typedef RankManager<ThisType> RankManagerType;
00612 RankManagerType rankManager_;
00613 public:
00614 const RankManagerType& rankManager() const
00615 {
00616 return rankManager_;
00617 }
00618 #endif
00619
00620 public:
00622 template<class DataHandleImp,class DataTypeImp>
00623 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
00624 InterfaceType iftype, CommunicationDirection dir, int level) const;
00625
00629 template<class DataHandleImp,class DataTypeImp>
00630 void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
00631 InterfaceType iftype, CommunicationDirection dir) const;
00632
00634 bool loadBalance() ;
00635
00637 template<class DataHandle>
00638 bool loadBalance(DataHandle& data) ;
00639
00640 void checkManager() {
00641 #if ALU2DGRID_PARALLEL
00642 rankManager_.notifyMarking () ;
00643 #endif
00644 }
00645
00646 };
00647
00648 template <class GridImp>
00649 struct ALU2dGridEntityFactory<GridImp,0>
00650 {
00651 enum {codim = 0};
00652 typedef typename GridImp:: template Codim<codim>::Entity Entity;
00653 typedef MakeableInterfaceObject<Entity> EntityObj;
00654 typedef typename EntityObj :: ImplementationType EntityImp;
00655
00656 static EntityObj *
00657 getNewEntity (const GridImp& grid, int level)
00658 {
00659 return grid.entityProvider_.getEntityObject( grid, level, (EntityImp *) 0);
00660 }
00661
00662 static void freeEntity( const GridImp& grid, EntityObj * e )
00663 {
00664 grid.entityProvider_.freeObject( e );
00665 }
00666 };
00667
00668 template <class GridImp>
00669 struct ALU2dGridEntityFactory<GridImp,1>
00670 {
00671 enum {codim = 1};
00672 typedef typename GridImp:: template Codim<codim>::Entity Entity;
00673 typedef MakeableInterfaceObject<Entity> EntityObj;
00674 typedef typename EntityObj :: ImplementationType EntityImp;
00675
00676 static EntityObj *
00677 getNewEntity (const GridImp& grid, int level)
00678 {
00679 return grid.faceProvider_.getEntityObject( grid, level, (EntityImp *) 0);
00680 }
00681
00682 static void freeEntity( const GridImp& grid, EntityObj * e )
00683 {
00684 grid.faceProvider_.freeObject( e );
00685 }
00686 };
00687
00688 template <class GridImp>
00689 struct ALU2dGridEntityFactory<GridImp,2>
00690 {
00691 enum {codim = 2};
00692 typedef typename GridImp:: template Codim<codim>::Entity Entity;
00693 typedef MakeableInterfaceObject<Entity> EntityObj;
00694 typedef typename EntityObj :: ImplementationType EntityImp;
00695
00696 static EntityObj *
00697 getNewEntity (const GridImp& grid, int level)
00698 {
00699 return grid.vertexProvider_.getEntityObject( grid, level, (EntityImp *) 0);
00700 }
00701
00702 static void freeEntity( const GridImp& grid, EntityObj * e )
00703 {
00704 grid.vertexProvider_.freeObject( e );
00705 }
00706 };
00707
00708 namespace Capabilities
00709 {
00710 template<int dim, int dimw, int cdim>
00711 struct hasEntity<ALU2dGrid<dim,dimw>, cdim >
00712 {
00713 static const bool v = true;
00714 };
00715
00716 template<int dim, int dimw>
00717 struct isLevelwiseConforming< ALU2dGrid<dim,dimw> >
00718 {
00719 static const bool v = false;
00720 };
00721
00722 template<int dim, int dimw>
00723 struct hasHangingNodes< ALU2dGrid<dim,dimw> >
00724 {
00725 static const bool v = false;
00726 };
00727 }
00728
00729 }
00730
00731 #include "entity.hh"
00732 #include "geometry.hh"
00733 #include "iterator.hh"
00734
00735 #include "grid_imp.cc"
00736
00737 #endif