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
30
31#ifdef HAVE_OPM_GRID
32#include "opm/grid/UnstructuredGrid.h"
33#endif
34
35namespace Opm {
40template <class TypeTag>
41class UnstructuredGridVanguard : public BaseVanguard<TypeTag> {
46
47 using GridPointer = Dune::GridPtr< Grid >;
48
49 public:
54 static void registerParameters() {
55 Parameters::registerParam<TypeTag, Properties::GridGlobalRefinements>
56 ("The number of global refinements of the grid "
57 "executed after it was loaded");
58 Parameters::registerParam<TypeTag, Properties::GridFile>,
59 ("The file name of the file to load");
60 }
61
65 UnstructuredGridVanguard(Simulator& simulator) : ParentType(simulator){
66#ifdef HAVE_OPM_GRID
67 const std::string gridFileName = Parameters::get<TypeTag, Properties::GridFile>();
68 unsigned numRefinments = Parameters::get<TypeTag, Properties::GridGlobalRefinements>();
69
70 const char* c_str = gridFileName.c_str();
71
72 UnstructuredGrid* grid = read_grid(c_str);
73 if (grid == nullptr) {
74 std::string msg =
75 "RuntimeError: UnstructuredGridVanguard could not read grid file: " +
76 gridFileName + ". Are you sure the filename is correct?";
77 throw std::runtime_error(msg);
78 }
79 ugPtr_.reset(std::move( grid ));
80 //GridPointer polygrid( new Grid(*ugPtr) );
81 gridPtr_ = new Grid(*ugPtr_);//std::move(polygrid);
82 if (numRefinments > 0) {
83 gridPtr_->globalRefine(static_cast<int>(numRefinments));
84 }
85 this->finalizeInit_();
86#endif
87 }
88
92 Grid& grid() { return *gridPtr_; }
93
98 const Grid& grid() const { return *gridPtr_; }
99
100 private:
101 GridPointer gridPtr_;
102 typename Grid::UnstructuredGridPtr ugPtr_;
103};
104
105} // namespace Opm
106
107#endif
Provides the base class for most (all?) simulator vanguards.
Definition: basevanguard.hh:49
void finalizeInit_()
Definition: basevanguard.hh:115
Provides a simulator vanguard which creates a grid by parsing an unstructured grid file.
Definition: unstructuredgridvanguard.hh:41
static void registerParameters()
Register all run-time parameters for the unstructured grid simulator vanguard.
Definition: unstructuredgridvanguard.hh:54
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:65
Grid & grid()
Return a reference to the grid object.
Definition: unstructuredgridvanguard.hh:92
Definition: blackoilboundaryratevector.hh:37
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:242
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.