dune-grid 2.12-git
Loading...
Searching...
No Matches
macrogrid.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © 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
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:
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
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 const bool hasDGFFactory = (GridType::dimension<0);
81 static GridType* generate(MacroGrid& /*mg*/,
82 const char* /*filename*/, [[maybe_unused]] MPICommunicatorType MPICOMM = MPIHelper::getCommunicator() )
83 {
84 // make assertion depend on the template argument but always evaluate to false
85 static_assert( hasDGFFactory, "DGF grid factory missing. Did you forget to add the corresponding dgf header?");
86 }
87 };
88
89 const char* filename_;
90 MPICommunicatorType MPICOMM_;
91
92 // provide check to see if Impl<GridType> was overloaded
93 template<class T, class = void>
94 struct ImplHasDGFFactory : std::true_type {}; // absent: specialized Impl, assume available
95 template<class T>
96 struct ImplHasDGFFactory<T, std::void_t<decltype(Impl<T>::hasDGFFactory)> > : std::bool_constant<Impl<T>::hasDGFFactory> {};
97
98 public:
99 template<class GridType> static constexpr bool noDGFFactory = !ImplHasDGFFactory<GridType>::value;
100 };
101
102} // end namespace Dune
103
104#endif
int size() const
typename Impl::voider< Types... >::type void_t
STL namespace.
Include standard header files.
MPI_Comm MPICommunicator
static MPICommunicator getCommunicator()
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
static constexpr bool noDGFFactory
Definition macrogrid.hh:99
The DuneGridFormatParser class: reads a DGF file and stores build information in vector structures us...
Definition parser.hh:47
T generate(T... args)