unstructuredgridvanguard.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil;
2// c-basic-offset: 4 -*- vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5 OPM is free software: you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation,
8 either version 2 of the License, or (at your option) any
9 later version. OPM is distributed in the hope that it will
10 be useful, but WITHOUT ANY WARRANTY; without even the
11 implied warranty of MERCHANTABILITY or FITNESS FOR A
12 PARTICULAR PURPOSE. See the GNU General Public License
13 for more details. You should have received a copy of the
14 GNU General Public License along with OPM. If not, see
15 <http://www.gnu.org/licenses/>. Consult the COPYING file
16 in the top-level source directory of this module for the
17 precise wording of the license and the list of copyright
18 holders.
19*/
24#ifndef EWOMS_UNSTRUCTURED_GRID_VANGUARD_HH
25#define EWOMS_UNSTRUCTURED_GRID_VANGUARD_HH
26
27#include <dune/grid/io/file/dgfparser/gridptr.hh>
28
32
33#ifdef HAVE_OPM_GRID
34#include <opm/grid/UnstructuredGrid.h>
35#include <string>
36#endif
37
38namespace Opm {
39
44template <class TypeTag>
46{
51
52 using GridPointer = Dune::GridPtr<Grid>;
53
54public:
59 static void registerParameters() {
60 Parameters::Register<Parameters::GridGlobalRefinements>
61 ("The number of global refinements of the grid "
62 "executed after it was loaded");
63 Parameters::Register<Parameters::GridFile>
64 ("The file name of the file to load");
65 }
66
70 explicit UnstructuredGridVanguard(Simulator& simulator)
71 : ParentType(simulator)
72 {
73#ifdef HAVE_OPM_GRID
74 const std::string gridFileName = Parameters::Get<Parameters::GridFile>();
75 const int numRefinments = Parameters::Get<Parameters::GridGlobalRefinements>();
76
77 UnstructuredGrid* ugrid = read_grid(gridFileName.c_str());
78 if (ugrid == nullptr) {
79 throw std::runtime_error("RuntimeError: UnstructuredGridVanguard could not read grid file: " +
80 gridFileName + ". Are you sure the filename is correct?");
81 }
82 ugPtr_.reset(std::move(ugrid));
83 //GridPointer polygrid(new Grid(*ugPtr));
84 gridPtr_ = new Grid(*ugPtr_);//std::move(polygrid);
85 if (numRefinments > 0) {
86 gridPtr_->globalRefine(numRefinments);
87 }
88 this->finalizeInit_();
89#endif
90 }
91
95 Grid& grid()
96 { return *gridPtr_; }
97
102 const Grid& grid() const
103 { return *gridPtr_; }
104
105private:
106 GridPointer gridPtr_;
107 typename Grid::UnstructuredGridPtr ugPtr_;
108};
109
110} // namespace Opm
111
112#endif
Provides the base class for most (all?) simulator vanguards.
Definition: basevanguard.hh:50
void finalizeInit_()
Definition: basevanguard.hh:127
Provides a simulator vanguard which creates a grid by parsing an unstructured grid file.
Definition: unstructuredgridvanguard.hh:46
static void registerParameters()
Register all run-time parameters for the unstructured grid simulator vanguard.
Definition: unstructuredgridvanguard.hh:59
const Grid & grid() const
Return a constant reference to the grid object.
Definition: unstructuredgridvanguard.hh:102
UnstructuredGridVanguard(Simulator &simulator)
Load the grid from the file.
Definition: unstructuredgridvanguard.hh:70
Grid & grid()
Return a reference to the grid object.
Definition: unstructuredgridvanguard.hh:95
Definition: blackoilboundaryratevector.hh:39
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.