diff --git a/dumux/io/grid/CMakeLists.txt b/dumux/io/grid/CMakeLists.txt index 4b60d65fddd73ae1110a3869b8689a9a353d7bd9..304ac5b43628f4fa3d4f07965ee915a436f73863 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 8f1e27ef69c011d169a167bb59aa73d7d2c59eca..dd7ed6c93f15ed5cf93b75c77dac896ae6840b2d 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 <opm/grid/CpGrid.hpp> @@ -32,50 +32,36 @@ #include <dumux/common/parameters.hh> -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<Grid>; using Deck = Opm::Deck; -public: /*! * \brief Create the Grid. */ - static void makeGrid() + void init(const std::string& paramGroup = "") { - auto fileName = getParam<std::string>("Grid.File"); - - static auto deckLocal = Opm::Parser().parseFile(fileName); - Opm::EclipseGrid ecl_grid(deckLocal); - deck() = deckLocal; - - gridPtr() = std::make_shared<Grid>(*(new Grid())); - gridPtr()->processEclipseFormat(ecl_grid, false, false); + const auto fileName = getParamFromGroup<std::string>(paramGroup, "Grid.File"); + deck_ = std::make_shared<Opm::Deck>(Opm::Parser().parseFile(fileName)); + Opm::EclipseGrid eclGrid(*deck_); + grid_ = std::make_shared<Grid>(); + 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<Deck> 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> deck_; //!< the eclipse deck + std::shared_ptr<Grid> 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 5850c3b1f660ce0de375f35f098daac655221230..46d94376ef676016856db3481b6c75e71af8ffe0 100644 --- a/test/porousmediumflow/2p/implicit/cornerpoint/problem.hh +++ b/test/porousmediumflow/2p/implicit/cornerpoint/problem.hh @@ -87,25 +87,26 @@ template<class TypeTag> class TwoPCornerPointTestProblem : public PorousMediumFlowProblem<TypeTag> { using ParentType = PorousMediumFlowProblem<TypeTag>; - 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<const FVGridGeometry> fvGridGeometry) - : ParentType(fvGridGeometry) + TwoPCornerPointTestProblem(std::shared_ptr<const FVGridGeometry> fvGridGeometry, + std::shared_ptr<typename ParentType::SpatialParams> spatialParams) + : ParentType(fvGridGeometry, spatialParams) { gravity_ = {0, 0, 9.81}; injectionElement_ = getParam<int>("Problem.InjectionElement"); diff --git a/test/porousmediumflow/2p/implicit/cornerpoint/spatialparams.hh b/test/porousmediumflow/2p/implicit/cornerpoint/spatialparams.hh index 1e8ee307f76f4eddb6c8a18b4f7265467d4b42cb..52873727f9aa2d3e4617b8f198a336c2e5e46bcc 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 <dumux/io/grid/cpgridcreator.hh> +#include <opm/parser/eclipse/Deck/Deck.hpp> + #include <dumux/material/spatialparams/fv.hh> #include <dumux/material/fluidmatrixinteractions/2p/regularizedvangenuchten.hh> #include <dumux/material/fluidmatrixinteractions/2p/efftoabslaw.hh> @@ -57,16 +58,18 @@ public: using MaterialLawParams = typename MaterialLaw::Params; using PermeabilityType = DimWorldMatrix; - TwoPCornerPointTestSpatialParams(std::shared_ptr<const FVGridGeometry> fvGridGeometry) + TwoPCornerPointTestSpatialParams(std::shared_ptr<const FVGridGeometry> fvGridGeometry, + std::shared_ptr<const Opm::Deck> deck) : ParentType(fvGridGeometry) + , deck_(deck) { homogeneous_ = getParam<bool>("Problem.Homogeneous"); - const std::vector<int>& globalCell = this->fvGridGeometry().grid().globalCell(); + const std::vector<int>& globalCell = this->fvGridGeometry().gridView().grid().globalCell(); - if (CpGridCreator::deck().hasKeyword("PORO")) { + if (deck_->hasKeyword("PORO")) { std::cout << "Found PORO..." << std::endl; - std::vector<double> eclVector = CpGridCreator::deck().getKeyword("PORO").getRawDoubleData(); + std::vector<double> 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<double> eclVector = CpGridCreator::deck().getKeyword("PERMX").getRawDoubleData(); + std::vector<double> 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<double> eclVector = CpGridCreator::deck().getKeyword("PERMZ").getRawDoubleData(); + std::vector<double> 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<const Opm::Deck> deck_; //!< the eclipse deck MaterialLawParams materialParams_; std::vector<Scalar> porosity_; std::vector<Scalar> permX_; diff --git a/test/porousmediumflow/2p/implicit/cornerpoint/test_2p_cornerpoint.cc b/test/porousmediumflow/2p/implicit/cornerpoint/test_2p_cornerpoint.cc index eb7436cc7aab1645ef295a51136ea7d484202f87..45ee211089f4cee32a437266d7d2d8bbb24b4a1d 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 <dumux/discretization/methods.hh> #include <dumux/io/vtkoutputmodule.hh> -#include <dumux/io/grid/cpgridcreator.hh> +#include <dumux/io/grid/cpgridmanager.hh> /*! * \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<Problem>(fvGridGeometry); + auto spatialParams = std::make_shared<typename Problem::SpatialParams>(fvGridGeometry, gridManager.getDeck()); + auto problem = std::make_shared<Problem>(fvGridGeometry, spatialParams); // the solution vector using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector);