From 1e13cfef3783bfd3c4b016364cc8d331fa9fdb3c Mon Sep 17 00:00:00 2001 From: rube051 Date: Thu, 18 Feb 2021 18:54:15 +0100 Subject: [PATCH] Added vanguard for the unstructured grid --- opm/models/io/unstructuredgridvanguard.hh | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 opm/models/io/unstructuredgridvanguard.hh diff --git a/opm/models/io/unstructuredgridvanguard.hh b/opm/models/io/unstructuredgridvanguard.hh new file mode 100644 index 000000000..71deed0e7 --- /dev/null +++ b/opm/models/io/unstructuredgridvanguard.hh @@ -0,0 +1,105 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; +// c-basic-offset: 4 -*- vi: set et ts=4 sw=4 sts=4: +/* + This file is part of the Open Porous Media project (OPM). + OPM is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, + either version 2 of the License, or (at your option) any + later version. OPM is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A + PARTICULAR PURPOSE. See the GNU General Public License + for more details. You should have received a copy of the + GNU General Public License along with OPM. If not, see + . Consult the COPYING file + in the top-level source directory of this module for the + precise wording of the license and the list of copyright + holders. +*/ +/*! + * \file + * \copydoc Opm::UnstructuredGridVanguard + */ +#ifndef EWOMS_UNSTRUCTURED_GRID_VANGUARD_HH +#define EWOMS_UNSTRUCTURED_GRID_VANGUARD_HH + +#include +#include +#include + +#include "opm/grid/UnstructuredGrid.h" + + +namespace Opm { +/*! + * \brief Provides a simulator vanguard which creates a grid + * by parsing an unstructured grid file + */ +template +class UnstructuredGridVanguard : public BaseVanguard { + using ParentType = BaseVanguard; + using Scalar = GetPropType; + using Simulator = GetPropType; + using Grid = GetPropType; + + using GridPointer = Dune::GridPtr< Grid >; + + public: + /*! + * \brief Register all run-time parameters for the + * unstructured grid simulator vanguard. + */ + static void registerParameters() { + EWOMS_REGISTER_PARAM(TypeTag, unsigned, GridGlobalRefinements, + "The number of global refinements of the grid " + "executed after it was loaded"); + EWOMS_REGISTER_PARAM(TypeTag, std::string, GridFile, + "The file name of the file to load"); + } + + /*! + * \brief Load the grid from the file. + */ + UnstructuredGridVanguard(Simulator& simulator) : ParentType(simulator){ + + const std::string gridFileName = EWOMS_GET_PARAM(TypeTag, std::string, GridFile); + unsigned numRefinments = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements); + + const char* c_str = gridFileName.c_str(); + + UnstructuredGrid* grid = read_grid(c_str); + if (grid == nullptr) { + std::string msg = + "RuntimeError: UnstructuredGridVanguard could not read grid file: " + + gridFileName + ". Are you sure the filename is correct?"; + throw std::runtime_error(msg); + } + ugPtr_.reset(std::move( grid )); + //GridPointer polygrid( new Grid(*ugPtr) ); + gridPtr_ = new Grid(*ugPtr_);//std::move(polygrid); + if (numRefinments > 0) { + gridPtr_->globalRefine(static_cast(numRefinments)); + } + this->finalizeInit_(); + } + + /*! + * \brief Return a reference to the grid object. + */ + Grid& grid() { return *gridPtr_; } + + /*! + * \brief Return a constant reference to the grid + * object. + */ + const Grid& grid() const { return *gridPtr_; } + + private: + GridPointer gridPtr_; + typename Grid::UnstructuredGridPtr ugPtr_; +}; + +} // namespace Opm + +#endif