dune-grid 3.0-git
macrogrid.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_DGF_MACROGRID_HH
4#define DUNE_DGF_MACROGRID_HH
5
6
7#include <iostream>
8
9#include <dune/common/parallel/mpihelper.hh>
11
12
13namespace Dune
14{
15 // forward declarations
16 // --------------------
17 class DuneGridFormatParser;
18
20 : protected DuneGridFormatParser
21 {
22 template< class GridType >
23 friend struct DGFGridFactory;
24
25 public:
26 typedef MPIHelper::MPICommunicator MPICommunicatorType;
27
28 protected:
30 MacroGrid(const char* filename, MPICommunicatorType MPICOMM = MPIHelper::getCommunicator())
31 : DuneGridFormatParser( rank(MPICOMM), size(MPICOMM) )
32 , filename_(filename)
33 , MPICOMM_(MPICOMM) {}
34
36 MacroGrid(MPICommunicatorType MPICOMM = MPIHelper::getCommunicator())
37 : DuneGridFormatParser( rank(MPICOMM), size(MPICOMM) )
38 , filename_(0)
39 , MPICOMM_(MPICOMM) {}
40
42 template <class GridType>
43 inline GridType * createGrid ()
44 {
45 return Impl<GridType>::generate(*this,filename_,MPICOMM_);
46 }
47 private:
48 static int rank( MPICommunicatorType MPICOMM )
49 {
50 int rank = 0;
51#if HAVE_MPI
52 MPI_Comm_rank( MPICOMM, &rank );
53#endif
54 return rank;
55 }
56 static int size( MPICommunicatorType MPICOMM )
57 {
58 int size = 1;
59#if HAVE_MPI
60 MPI_Comm_size( MPICOMM, &size );
61#endif
62 return size;
63 }
75 template< class GridType >
76 struct Impl
77 {
78 static GridType* generate(MacroGrid& mg,
79 const char* filename, MPICommunicatorType MPICOMM = MPIHelper::getCommunicator() )
80 {
81 // make assertion depend on the template argument but always evaluate to false
82 static_assert( GridType::dimension<0,"DGF grid factory missing. Did you forget to add the corresponding dgf header or config.h?");
83 }
84 };
85
86 const char* filename_;
87 MPICommunicatorType MPICOMM_;
88 };
89
90} // end namespace Dune
91
92#endif
Include standard header files.
Definition agrid.hh:60
Definition dgfgridfactory.hh:36
Definition macrogrid.hh:21
MacroGrid(const char *filename, MPICommunicatorType MPICOMM=MPIHelper::getCommunicator())
constructor given the name of a DGF file
Definition macrogrid.hh:30
MacroGrid(MPICommunicatorType MPICOMM=MPIHelper::getCommunicator())
constructor given the name of a DGF file
Definition macrogrid.hh:36
GridType * createGrid()
returns pointer to a new instance of type GridType created from a DGF file
Definition macrogrid.hh:43
MPIHelper::MPICommunicator MPICommunicatorType
Definition macrogrid.hh:26
The DuneGridFormatParser class: reads a DGF file and stores build information in vector structures us...
Definition parser.hh:45