From 8d1aa538c928310ba28df341d2ad25f36e05b491 Mon Sep 17 00:00:00 2001 From: Martin Schneider Date: Fri, 29 Jun 2018 10:57:53 +0200 Subject: [PATCH] [cornerpoints] Change the cornerpoint grid creator into a grid manager --- dumux/io/grid/CMakeLists.txt | 2 +- .../{cpgridcreator.hh => cpgridmanager.hh} | 57 ++++++++----------- .../2p/implicit/cornerpoint/problem.hh | 11 ++-- .../2p/implicit/cornerpoint/spatialparams.hh | 23 ++++---- .../cornerpoint/test_2p_cornerpoint.cc | 11 ++-- 5 files changed, 50 insertions(+), 54 deletions(-) rename dumux/io/grid/{cpgridcreator.hh => cpgridmanager.hh} (72%) diff --git a/dumux/io/grid/CMakeLists.txt b/dumux/io/grid/CMakeLists.txt index 4b60d65fdd..304ac5b436 100644 --- a/dumux/io/grid/CMakeLists.txt +++ b/dumux/io/grid/CMakeLists.txt @@ -1,6 +1,6 @@ install(FILES cakegridcreator.hh -cpgridcreator.hh +cpgridmanager.hh gmshgriddatahandle.hh griddata.hh gridmanager.hh diff --git a/dumux/io/grid/cpgridcreator.hh b/dumux/io/grid/cpgridmanager.hh similarity index 72% rename from dumux/io/grid/cpgridcreator.hh rename to dumux/io/grid/cpgridmanager.hh index 8f1e27ef69..dd7ed6c93f 100644 --- a/dumux/io/grid/cpgridcreator.hh +++ b/dumux/io/grid/cpgridmanager.hh @@ -21,8 +21,8 @@ * \ingroup InputOutput * \brief A grid creator that reads Petrel files and generates a CpGrid. */ -#ifndef DUMUX_CPGRID_CREATOR_HH -#define DUMUX_CPGRID_CREATOR_HH +#ifndef DUMUX_IO_GRID_CPGRIDMANAGER_HH +#define DUMUX_IO_GRID_CPGRIDMANAGER_HH #if HAVE_OPM_GRID #include @@ -32,50 +32,36 @@ #include -namespace Dumux -{ +namespace Dumux { /*! * \ingroup InputOutput * \brief A grid creator that reads Petrel files and generates a CpGrid. */ -class CpGridCreator +class CpGridManager { +public: using Grid = Dune::CpGrid; - using GridPointer = std::shared_ptr; using Deck = Opm::Deck; -public: /*! * \brief Create the Grid. */ - static void makeGrid() + void init(const std::string& paramGroup = "") { - auto fileName = getParam("Grid.File"); - - static auto deckLocal = Opm::Parser().parseFile(fileName); - Opm::EclipseGrid ecl_grid(deckLocal); - deck() = deckLocal; - - gridPtr() = std::make_shared(*(new Grid())); - gridPtr()->processEclipseFormat(ecl_grid, false, false); + const auto fileName = getParamFromGroup(paramGroup, "Grid.File"); + deck_ = std::make_shared(Opm::Parser().parseFile(fileName)); + Opm::EclipseGrid eclGrid(*deck_); + grid_ = std::make_shared(); + grid_->processEclipseFormat(eclGrid, false, false); } /*! * \brief Returns a reference to the grid. */ - static Grid &grid() + Grid &grid() { - return *gridPtr(); - } - - /*! - * \brief Returns a reference to the grid pointer. - */ - static GridPointer &gridPtr() - { - static GridPointer cpGrid; - return cpGrid; + return *grid_; } /*! @@ -83,22 +69,27 @@ public: * * The input deck can be used to read parameters like porosity/permeability. */ - static Deck &deck() + std::shared_ptr getDeck() const { - static Deck deck_; return deck_; } /*! * \brief Distributes the grid over all processes for a parallel computation. */ - static void loadBalance() + void loadBalance() { - if (gridPtr()->comm().size() > 1) - gridPtr()->loadBalance(); + if (grid_->comm().size() > 1) + grid_->loadBalance(); } + +private: + std::shared_ptr deck_; //!< the eclipse deck + std::shared_ptr grid_; //!< the grid pointer }; -} + +} // end namespace Dumux + #endif // HAVE_OPM_GRID #endif diff --git a/test/porousmediumflow/2p/implicit/cornerpoint/problem.hh b/test/porousmediumflow/2p/implicit/cornerpoint/problem.hh index 5850c3b1f6..46d94376ef 100644 --- a/test/porousmediumflow/2p/implicit/cornerpoint/problem.hh +++ b/test/porousmediumflow/2p/implicit/cornerpoint/problem.hh @@ -87,25 +87,26 @@ template class TwoPCornerPointTestProblem : public PorousMediumFlowProblem { using ParentType = PorousMediumFlowProblem; - using GridView = typename GET_PROP_TYPE(TypeTag, GridView); - using Element = typename GridView::template Codim<0>::Entity; using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar); using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem); using PrimaryVariables = typename GET_PROP_TYPE(TypeTag, PrimaryVariables); using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables)::LocalView; using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); + using GridView = typename FVGridGeometry::GridView; + using Element = typename GridView::template Codim<0>::Entity; using FVElementGeometry = typename FVGridGeometry::LocalView; using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; using SubControlVolume = typename FVElementGeometry::SubControlVolume; - using BoundaryTypes = typename GET_PROP_TYPE(TypeTag, BoundaryTypes); using GlobalPosition = typename Element::Geometry::GlobalCoordinate; + using BoundaryTypes = typename GET_PROP_TYPE(TypeTag, BoundaryTypes); using NumEqVector = typename GET_PROP_TYPE(TypeTag, NumEqVector); using Indices = typename GET_PROP_TYPE(TypeTag, ModelTraits)::Indices; enum { dimWorld = GridView::dimensionworld }; public: - TwoPCornerPointTestProblem(std::shared_ptr fvGridGeometry) - : ParentType(fvGridGeometry) + TwoPCornerPointTestProblem(std::shared_ptr fvGridGeometry, + std::shared_ptr spatialParams) + : ParentType(fvGridGeometry, spatialParams) { gravity_ = {0, 0, 9.81}; injectionElement_ = getParam("Problem.InjectionElement"); diff --git a/test/porousmediumflow/2p/implicit/cornerpoint/spatialparams.hh b/test/porousmediumflow/2p/implicit/cornerpoint/spatialparams.hh index 1e8ee307f7..52873727f9 100644 --- a/test/porousmediumflow/2p/implicit/cornerpoint/spatialparams.hh +++ b/test/porousmediumflow/2p/implicit/cornerpoint/spatialparams.hh @@ -23,7 +23,8 @@ #ifndef DUMUX_TWOP_CORNERPOINT_TEST_SPATIAL_PARAMS_HH #define DUMUX_TWOP_CORNERPOINT_TEST_SPATIAL_PARAMS_HH -#include +#include + #include #include #include @@ -57,16 +58,18 @@ public: using MaterialLawParams = typename MaterialLaw::Params; using PermeabilityType = DimWorldMatrix; - TwoPCornerPointTestSpatialParams(std::shared_ptr fvGridGeometry) + TwoPCornerPointTestSpatialParams(std::shared_ptr fvGridGeometry, + std::shared_ptr deck) : ParentType(fvGridGeometry) + , deck_(deck) { homogeneous_ = getParam("Problem.Homogeneous"); - const std::vector& globalCell = this->fvGridGeometry().grid().globalCell(); + const std::vector& globalCell = this->fvGridGeometry().gridView().grid().globalCell(); - if (CpGridCreator::deck().hasKeyword("PORO")) { + if (deck_->hasKeyword("PORO")) { std::cout << "Found PORO..." << std::endl; - std::vector eclVector = CpGridCreator::deck().getKeyword("PORO").getRawDoubleData(); + std::vector eclVector = deck_->getKeyword("PORO").getRawDoubleData(); porosity_.resize(globalCell.size()); for (size_t i = 0; i < globalCell.size(); ++i) { @@ -77,9 +80,9 @@ public: } } - if (CpGridCreator::deck().hasKeyword("PERMX")) { + if (deck_->hasKeyword("PERMX")) { std::cout << "Found PERMX..." << std::endl; - std::vector eclVector = CpGridCreator::deck().getKeyword("PERMX").getRawDoubleData(); + std::vector eclVector = deck_->getKeyword("PERMX").getRawDoubleData(); permX_.resize(globalCell.size()); for (size_t i = 0; i < globalCell.size(); ++i) { @@ -91,9 +94,9 @@ public: } } - if (CpGridCreator::deck().hasKeyword("PERMZ")) { + if (deck_->hasKeyword("PERMZ")) { std::cout << "Found PERMZ..." << std::endl; - std::vector eclVector = CpGridCreator::deck().getKeyword("PERMZ").getRawDoubleData(); + std::vector eclVector = deck_->getKeyword("PERMZ").getRawDoubleData(); permZ_.resize(globalCell.size()); for (size_t i = 0; i < globalCell.size(); ++i) { @@ -151,7 +154,6 @@ public: const ElementSolution& elemSol) const { int eIdx = this->fvGridGeometry().gridView().indexSet().index(element); - return porosity_[eIdx]; } @@ -190,6 +192,7 @@ public: { return permZ_[eIdx]; } private: + std::shared_ptr deck_; //!< the eclipse deck MaterialLawParams materialParams_; std::vector porosity_; std::vector permX_; diff --git a/test/porousmediumflow/2p/implicit/cornerpoint/test_2p_cornerpoint.cc b/test/porousmediumflow/2p/implicit/cornerpoint/test_2p_cornerpoint.cc index eb7436cc7a..45ee211089 100644 --- a/test/porousmediumflow/2p/implicit/cornerpoint/test_2p_cornerpoint.cc +++ b/test/porousmediumflow/2p/implicit/cornerpoint/test_2p_cornerpoint.cc @@ -56,7 +56,7 @@ #include #include -#include +#include /*! * \brief Provides an interface for customizing error messages associated with @@ -108,15 +108,15 @@ int main(int argc, char** argv) try Parameters::init(argc, argv, usage); // try to create a grid (from the given grid file or the input file) - CpGridCreator::makeGrid(); - CpGridCreator::loadBalance(); + CpGridManager gridManager; + gridManager.init(); //////////////////////////////////////////////////////////// // run instationary non-linear problem on this grid //////////////////////////////////////////////////////////// // we compute on the leaf grid view - const auto& leafGridView = CpGridCreator::grid().leafGridView(); + const auto& leafGridView = gridManager.grid().leafGridView(); // create the finite volume grid geometry using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); @@ -125,7 +125,8 @@ int main(int argc, char** argv) try // the problem (initial and boundary conditions) using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - auto problem = std::make_shared(fvGridGeometry); + auto spatialParams = std::make_shared(fvGridGeometry, gridManager.getDeck()); + auto problem = std::make_shared(fvGridGeometry, spatialParams); // the solution vector using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector); -- GitLab