dune-grid  2.2.0
macrogrid.hh
Go to the documentation of this file.
1 #ifndef DUNE_DGF_MACROGRID_HH
2 #define DUNE_DGF_MACROGRID_HH
3 
4 
5 #include <iostream>
6 
7 #include <dune/common/mpihelper.hh>
9 
10 
11 namespace Dune
12 {
13  // forward declarations
14  // --------------------
15  class DuneGridFormatParser;
16 
17  class MacroGrid
18  : protected DuneGridFormatParser
19  {
20  template< class GridType >
21  friend class DGFGridFactory;
22 
23  public:
24  typedef MPIHelper::MPICommunicator MPICommunicatorType;
25 
26  protected:
28  MacroGrid(const char* filename, MPICommunicatorType MPICOMM = MPIHelper::getCommunicator())
29  : DuneGridFormatParser( rank(MPICOMM), size(MPICOMM) )
30  , filename_(filename)
31  , MPICOMM_(MPICOMM) {}
32 
34  MacroGrid(MPICommunicatorType MPICOMM = MPIHelper::getCommunicator())
35  : DuneGridFormatParser( rank(MPICOMM), size(MPICOMM) )
36  , filename_(0)
37  , MPICOMM_(MPICOMM) {}
38 
40  template <class GridType>
41  inline GridType * createGrid ()
42  {
43  return Impl<GridType>::generate(*this,filename_,MPICOMM_);
44  }
45  private:
46  static int rank( MPICommunicatorType MPICOMM )
47  {
48  int rank = 0;
49 #if HAVE_MPI
50  MPI_Comm_rank( MPICOMM, &rank );
51 #endif
52  return rank;
53  }
54  static int size( MPICommunicatorType MPICOMM )
55  {
56  int size = 1;
57 #if HAVE_MPI
58  MPI_Comm_size( MPICOMM, &size );
59 #endif
60  return size;
61  }
73  template< class GridType >
74  struct Impl
75  {
76  static GridType* generate(MacroGrid& mg,
77  const char* filename, MPICommunicatorType MPICOMM = MPIHelper::getCommunicator() )
78  {
79  // make assertion depend on the template argument but always evaluate to false
80  dune_static_assert( GridType::dimension<0,"dgf grid factory missing - did you forget to add the corresponding dgf header or dgfgridtype.hh ?");
81  }
82  };
83 
84  const char* filename_;
85  MPICommunicatorType MPICOMM_;
86  };
87 
88 } // end namespace Dune
89 
90 #endif