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#include <opm/grid/UnstructuredGrid.h>
34#include <string>
35
36namespace Opm {
37
42template <class TypeTag>
44{
49
50 using GridPointer = Dune::GridPtr<Grid>;
51
52public:
57 static void registerParameters() {
58 Parameters::Register<Parameters::GridGlobalRefinements>
59 ("The number of global refinements of the grid "
60 "executed after it was loaded");
61 Parameters::Register<Parameters::GridFile>
62 ("The file name of the file to load");
63 }
64
68 explicit UnstructuredGridVanguard(Simulator& simulator)
69 : ParentType(simulator)
70 {
71 const std::string gridFileName = Parameters::Get<Parameters::GridFile>();
72 const int numRefinments = Parameters::Get<Parameters::GridGlobalRefinements>();
73
74 UnstructuredGrid* ugrid = read_grid(gridFileName.c_str());
75 if (ugrid == nullptr) {
76 throw std::runtime_error("RuntimeError: UnstructuredGridVanguard could not read grid file: " +
77 gridFileName + ". Are you sure the filename is correct?");
78 }
79 ugPtr_.reset(std::move(ugrid));
80 //GridPointer polygrid(new Grid(*ugPtr));
81 gridPtr_ = new Grid(*ugPtr_);//std::move(polygrid);
82 if (numRefinments > 0) {
83 gridPtr_->globalRefine(numRefinments);
84 }
85 this->finalizeInit_();
86 }
87
91 Grid& grid()
92 { return *gridPtr_; }
93
98 const Grid& grid() const
99 { return *gridPtr_; }
100
101private:
102 GridPointer gridPtr_;
103 typename Grid::UnstructuredGridPtr ugPtr_;
104};
105
106} // namespace Opm
107
108#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:44
static void registerParameters()
Register all run-time parameters for the unstructured grid simulator vanguard.
Definition: unstructuredgridvanguard.hh:57
const Grid & grid() const
Return a constant reference to the grid object.
Definition: unstructuredgridvanguard.hh:98
UnstructuredGridVanguard(Simulator &simulator)
Load the grid from the file.
Definition: unstructuredgridvanguard.hh:68
Grid & grid()
Return a reference to the grid object.
Definition: unstructuredgridvanguard.hh:91
Definition: blackoilbioeffectsmodules.hh:45
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.