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