dune-grid
2.2.0
|
00001 #ifndef DUNE_DGF_MACROGRID_HH 00002 #define DUNE_DGF_MACROGRID_HH 00003 00004 00005 #include <iostream> 00006 00007 #include <dune/common/mpihelper.hh> 00008 #include <dune/grid/io/file/dgfparser/parser.hh> 00009 00010 00011 namespace Dune 00012 { 00013 // forward declarations 00014 // -------------------- 00015 class DuneGridFormatParser; 00016 00017 class MacroGrid 00018 : protected DuneGridFormatParser 00019 { 00020 template< class GridType > 00021 friend class DGFGridFactory; 00022 00023 public: 00024 typedef MPIHelper::MPICommunicator MPICommunicatorType; 00025 00026 protected: 00028 MacroGrid(const char* filename, MPICommunicatorType MPICOMM = MPIHelper::getCommunicator()) 00029 : DuneGridFormatParser( rank(MPICOMM), size(MPICOMM) ) 00030 , filename_(filename) 00031 , MPICOMM_(MPICOMM) {} 00032 00034 MacroGrid(MPICommunicatorType MPICOMM = MPIHelper::getCommunicator()) 00035 : DuneGridFormatParser( rank(MPICOMM), size(MPICOMM) ) 00036 , filename_(0) 00037 , MPICOMM_(MPICOMM) {} 00038 00040 template <class GridType> 00041 inline GridType * createGrid () 00042 { 00043 return Impl<GridType>::generate(*this,filename_,MPICOMM_); 00044 } 00045 private: 00046 static int rank( MPICommunicatorType MPICOMM ) 00047 { 00048 int rank = 0; 00049 #if HAVE_MPI 00050 MPI_Comm_rank( MPICOMM, &rank ); 00051 #endif 00052 return rank; 00053 } 00054 static int size( MPICommunicatorType MPICOMM ) 00055 { 00056 int size = 1; 00057 #if HAVE_MPI 00058 MPI_Comm_size( MPICOMM, &size ); 00059 #endif 00060 return size; 00061 } 00073 template< class GridType > 00074 struct Impl 00075 { 00076 static GridType* generate(MacroGrid& mg, 00077 const char* filename, MPICommunicatorType MPICOMM = MPIHelper::getCommunicator() ) 00078 { 00079 // make assertion depend on the template argument but always evaluate to false 00080 dune_static_assert( GridType::dimension<0,"dgf grid factory missing - did you forget to add the corresponding dgf header or dgfgridtype.hh ?"); 00081 } 00082 }; 00083 00084 const char* filename_; 00085 MPICommunicatorType MPICOMM_; 00086 }; 00087 00088 } // end namespace Dune 00089 00090 #endif