From 25aed6d79a150699a07c08ee690954198623e882 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 5 Jul 2024 17:49:51 +0200 Subject: [PATCH] move Cells(X|Y|Z) to TypeTag-free parameter system --- examples/problems/co2ptflashproblem.hh | 27 ++++++++---------- examples/problems/diffusionproblem.hh | 30 ++++++++++++-------- examples/problems/fingerproblem.hh | 22 +++++++-------- examples/problems/lensproblem.hh | 23 ++++++--------- examples/problems/powerinjectionproblem.hh | 30 ++++++++++++-------- examples/tutorial1problem.hh | 33 +++++++++++++--------- opm/models/io/cubegridvanguard.hh | 29 ++++++++++--------- opm/models/io/simplexvanguard.hh | 25 ++++++++-------- opm/models/io/structuredgridvanguard.hh | 18 ++++++------ opm/models/utils/basicparameters.hh | 11 ++------ 10 files changed, 128 insertions(+), 120 deletions(-) diff --git a/examples/problems/co2ptflashproblem.hh b/examples/problems/co2ptflashproblem.hh index b512be650..2aa101811 100644 --- a/examples/problems/co2ptflashproblem.hh +++ b/examples/problems/co2ptflashproblem.hh @@ -156,19 +156,6 @@ struct EpisodeLength { using type = Properties::UndefinedProperty;}; template struct Initialpressure { using type = Properties::UndefinedProperty;}; -template -struct CellsX -{ static constexpr unsigned value = 30; }; - -template -struct CellsY -{ static constexpr unsigned value = 1; }; - -// CellsZ is not needed, while to keep structuredgridvanguard.hh compile -template -struct CellsZ -{ static constexpr unsigned value = 1; }; - //\Note: from the Julia code, the problem is a 1D problem with 3X1 cell. //\Note: DomainSizeX is 3.0 meters //\Note: DomainSizeY is 1.0 meters @@ -424,6 +411,16 @@ public: ("The name of the simulation used for the output files"); Parameters::registerParam ("Time interval [s] for episode length"); + + Parameters::SetDefault(30); + + if constexpr (dim > 1) { + Parameters::SetDefault(1); + } + + if constexpr (dim == 3) { + Parameters::SetDefault(1); + } } /*! @@ -517,7 +514,7 @@ public: { int spatialIdx = context.globalSpaceIndex(spaceIdx, timeIdx); int inj = 0; - int prod = Parameters::get() - 1; + int prod = Parameters::Get() - 1; if (spatialIdx == inj || spatialIdx == prod) { return 1.0; } else { @@ -568,7 +565,7 @@ private: // p0 = 75e5 // T0 = 423.25 int inj = 0; - int prod = Parameters::get() - 1; + int prod = Parameters::Get() - 1; int spatialIdx = context.globalSpaceIndex(spaceIdx, timeIdx); ComponentVector comp; comp[0] = Evaluation::createVariable(0.5, 1); diff --git a/examples/problems/diffusionproblem.hh b/examples/problems/diffusionproblem.hh index f2a330020..aa276a14d 100644 --- a/examples/problems/diffusionproblem.hh +++ b/examples/problems/diffusionproblem.hh @@ -110,18 +110,6 @@ struct EnableDiffusion { static constexpr b namespace Opm::Parameters { -template -struct CellsX -{ static constexpr unsigned value = 250; }; - -template -struct CellsY -{ static constexpr unsigned value = 1; }; - -template -struct CellsZ -{ static constexpr unsigned value = 1; }; - // define the properties specific for the diffusion problem template struct DomainSizeX @@ -245,6 +233,24 @@ public: setupInitialFluidStates_(); } + /*! + * \copydoc FvBaseMultiPhaseProblem::registerParameters + */ + static void registerParameters() + { + ParentType::registerParameters(); + + Parameters::SetDefault(250); + + if constexpr (dim > 1) { + Parameters::SetDefault(1); + } + + if constexpr (dim == 3) { + Parameters::SetDefault(1); + } + } + /*! * \name Auxiliary methods */ diff --git a/examples/problems/fingerproblem.hh b/examples/problems/fingerproblem.hh index 497ef6171..c7cf3f2aa 100644 --- a/examples/problems/fingerproblem.hh +++ b/examples/problems/fingerproblem.hh @@ -131,18 +131,6 @@ namespace Opm::Parameters { template struct InitialWaterSaturation { using type = Properties::UndefinedProperty; }; -template -struct CellsX -{ static constexpr unsigned value = 20; }; - -template -struct CellsY -{ static constexpr unsigned value = 70; }; - -template -struct CellsZ -{ static constexpr unsigned value = 1; }; - // define the properties specific for the finger problem template struct DomainSizeX @@ -320,6 +308,16 @@ public: Parameters::registerParam ("The initial saturation in the domain [] of the wetting phase"); + + Parameters::SetDefault(20); + + if constexpr (dim > 1) { + Parameters::SetDefault(70); + } + + if constexpr (dim == 3) { + Parameters::SetDefault(1); + } } /*! diff --git a/examples/problems/lensproblem.hh b/examples/problems/lensproblem.hh index 3b4de2d3a..87363aed2 100644 --- a/examples/problems/lensproblem.hh +++ b/examples/problems/lensproblem.hh @@ -138,18 +138,6 @@ struct LensUpperRightY { using type = Properties::UndefinedProperty; }; template struct LensUpperRightZ { using type = Properties::UndefinedProperty; }; -template -struct CellsX -{ static constexpr unsigned value = 48; }; - -template -struct CellsY -{ static constexpr unsigned value = 32; }; - -template -struct CellsZ -{ static constexpr unsigned value = 16; }; - template struct DomainSizeX { @@ -343,7 +331,7 @@ public: lensUpperRight_[0] = Parameters::get(); lensUpperRight_[1] = Parameters::get(); - if (dimWorld == 3) { + if constexpr (dim == 3) { lensLowerLeft_[2] = Parameters::get(); lensUpperRight_[2] = Parameters::get(); } @@ -388,12 +376,19 @@ public: Parameters::registerParam ("The y-coordinate of the lens' upper-right corner [m]."); - if (dimWorld == 3) { + if constexpr (dim == 3) { Parameters::registerParam ("The z-coordinate of the lens' lower-left corner [m]."); Parameters::registerParam ("The z-coordinate of the lens' upper-right corner [m]."); } + + Parameters::SetDefault(48); + Parameters::SetDefault(32); + + if constexpr (dim == 3) { + Parameters::SetDefault(16); + } } /*! diff --git a/examples/problems/powerinjectionproblem.hh b/examples/problems/powerinjectionproblem.hh index 3e0904281..f831f7603 100644 --- a/examples/problems/powerinjectionproblem.hh +++ b/examples/problems/powerinjectionproblem.hh @@ -123,18 +123,6 @@ public: namespace Opm::Parameters { -template -struct CellsX -{ static constexpr unsigned value = 250; }; - -template -struct CellsY -{ static constexpr unsigned value = 1; }; - -template -struct CellsZ -{ static constexpr unsigned value = 1; }; - // define the properties specific for the power injection problem template struct DomainSizeX @@ -270,6 +258,24 @@ public: setupInitialFluidState_(); } + /*! + * \copydoc FvBaseMultiPhaseProblem::registerParameters + */ + static void registerParameters() + { + ParentType::registerParameters(); + + Parameters::SetDefault(250); + + if constexpr (dim > 1) { + Parameters::SetDefault(1); + } + + if constexpr (dim == 3) { + Parameters::SetDefault(1); + } + } + /*! * \name Auxiliary methods */ diff --git a/examples/tutorial1problem.hh b/examples/tutorial1problem.hh index 1f69fd88d..476d47e7e 100644 --- a/examples/tutorial1problem.hh +++ b/examples/tutorial1problem.hh @@ -124,19 +124,6 @@ public: namespace Opm::Parameters { -// // define the number of cells used for discretizing the physical domain -template -struct CellsX -{ static constexpr unsigned value = 100; }; - -template -struct CellsY -{ static constexpr unsigned value = 1; }; - -template -struct CellsZ -{ static constexpr unsigned value = 1; }; /*@\label{tutorial1:default-params-end}@*/ - // define the physical size of the problem's domain [m] template struct DomainSizeX @@ -193,7 +180,10 @@ class Tutorial1Problem using GridView = GetPropType; // Grid dimension - enum { dimWorld = GridView::dimensionworld }; + enum { + dim = GridView::dimension, + dimWorld = GridView::dimensionworld + }; // The type of the intrinsic permeability tensor using DimMatrix = Dune::FieldMatrix; @@ -247,6 +237,21 @@ public: materialParams_.finalize(); } + /*! + * \copydoc FvBaseMultiPhaseProblem::registerParameters + */ + static void registerParameters() + { + ParentType::registerParameters(); + + Parameters::SetDefault(100); + Parameters::SetDefault(1); + + if constexpr (dim == 3) { + Parameters::SetDefault(1); + } + } + //! Specifies the problem name. This is used for files generated by the simulation. std::string name() const { return "tutorial1"; } diff --git a/opm/models/io/cubegridvanguard.hh b/opm/models/io/cubegridvanguard.hh index d1cf07ddd..b8b827f3f 100644 --- a/opm/models/io/cubegridvanguard.hh +++ b/opm/models/io/cubegridvanguard.hh @@ -58,7 +58,10 @@ class CubeGridVanguard : public BaseVanguard using GridPointer = std::unique_ptr; using CoordScalar = typename Grid::ctype; - enum { dimWorld = Grid::dimensionworld }; + enum { + dim = Grid::dimension, + dimWorld = Grid::dimensionworld, + }; using GlobalPosition = Dune::FieldVector; public: @@ -72,18 +75,18 @@ public: "executed after it was loaded"); Parameters::registerParam ("The size of the domain in x direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in x direction"); - if (dimWorld > 1) { + if constexpr (dim > 1) { Parameters::registerParam ("The size of the domain in y direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in y direction"); } - if (dimWorld > 2) { + if constexpr (dim > 2) { Parameters::registerParam ("The size of the domain in z direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in z direction"); } } @@ -94,22 +97,22 @@ public: CubeGridVanguard(Simulator& simulator) : ParentType(simulator) { - std::array cellRes; + std::array cellRes; GlobalPosition upperRight(0.0); GlobalPosition lowerLeft(0.0); - for (unsigned i = 0; i < dimWorld; ++i) + for (unsigned i = 0; i < dim; ++i) cellRes[i] = 0; upperRight[0] = Parameters::get(); - cellRes[0] = Parameters::get(); - if (dimWorld > 1) { + cellRes[0] = Parameters::Get(); + if constexpr (dim > 1) { upperRight[1] = Parameters::get(); - cellRes[1] = Parameters::get(); + cellRes[1] = Parameters::Get(); } - if (dimWorld > 2) { + if constexpr (dim > 2) { upperRight[2] = Parameters::get(); - cellRes[2] = Parameters::get(); + cellRes[2] = Parameters::Get(); } unsigned numRefinements = Parameters::Get(); diff --git a/opm/models/io/simplexvanguard.hh b/opm/models/io/simplexvanguard.hh index a475ce833..1e1a8eefe 100644 --- a/opm/models/io/simplexvanguard.hh +++ b/opm/models/io/simplexvanguard.hh @@ -53,7 +53,10 @@ class SimplexGridVanguard using GridPointer = std::unique_ptr; using CoordScalar = typename Grid::ctype; - enum { dimWorld = Grid::dimensionworld }; + enum { + dim = Grid::dimension, + dimWorld = Grid::dimensionworld, + }; using GlobalPosition = Dune::FieldVector; public: @@ -67,18 +70,18 @@ public: "executed after it was loaded"); Parameters::registerParam ("The size of the domain in x direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in x direction"); if (dimWorld > 1) { Parameters::registerParam ("The size of the domain in y direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in y direction"); } - if (dimWorld > 2) { + if constexpr (dim > 2) { Parameters::registerParam ("The size of the domain in z direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in z direction"); } } @@ -89,22 +92,22 @@ public: SimplexGridVanguard(Simulator& simulator) : ParentType(simulator) { - Dune::array cellRes; + Dune::array cellRes; GlobalPosition upperRight; GlobalPosition lowerLeft; lowerLeft[0] = 0.0; upperRight[0] = Parameters::get(); - cellRes[0] = Parameters::get(); - if (dimWorld > 1) { + cellRes[0] = Parameters::Get(); + if constexpr (dim > 1) { lowerLeft[1] = 0.0; upperRight[1] = Parameters::get(); - cellRes[1] = Parameters::get(); + cellRes[1] = Parameters::Get(); } - if (dimWorld > 2) { + if constexpr (dim > 2) { lowerLeft[2] = 0.0; upperRight[2] = Parameters::get(); - cellRes[2] = Parameters::get(); + cellRes[2] = Parameters::Get(); } simplexGrid_ = Dune::StructuredGridFactory::createSimplexGrid(lowerLeft, diff --git a/opm/models/io/structuredgridvanguard.hh b/opm/models/io/structuredgridvanguard.hh index 162b6997a..2cdeb2528 100644 --- a/opm/models/io/structuredgridvanguard.hh +++ b/opm/models/io/structuredgridvanguard.hh @@ -100,7 +100,7 @@ class StructuredGridVanguard : public BaseVanguard using GridPointer = std::unique_ptr; - static const int dim = Grid::dimension; + static constexpr int dim = Grid::dimension; public: /*! @@ -113,18 +113,18 @@ public: "executed after it was loaded"); Parameters::registerParam ("The size of the domain in x direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in x direction"); if (dim > 1) { Parameters::registerParam ("The size of the domain in y direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in y direction"); } - if (dim > 2) { + if constexpr (dim > 2) { Parameters::registerParam ("The size of the domain in z direction"); - Parameters::registerParam + Parameters::Register ("The number of intervalls in z direction"); } } @@ -144,11 +144,11 @@ public: upperRight[0] = Parameters::get(); upperRight[1] = Parameters::get(); - cellRes[0] = Parameters::get(); - cellRes[1] = Parameters::get(); - if (dim == 3) { + cellRes[0] = Parameters::Get(); + cellRes[1] = Parameters::Get(); + if constexpr (dim == 3) { upperRight[2] = Parameters::get(); - cellRes[2] = Parameters::get(); + cellRes[2] = Parameters::Get(); } std::stringstream dgffile; diff --git a/opm/models/utils/basicparameters.hh b/opm/models/utils/basicparameters.hh index f0683ec19..bfc1181e3 100644 --- a/opm/models/utils/basicparameters.hh +++ b/opm/models/utils/basicparameters.hh @@ -33,14 +33,9 @@ namespace Opm::Parameters { //! grid resolution -template -struct CellsX { using type = Properties::UndefinedProperty; }; - -template -struct CellsY { using type = Properties::UndefinedProperty; }; - -template -struct CellsZ { using type = Properties::UndefinedProperty; }; +struct CellsX { static constexpr unsigned value = 1; }; +struct CellsY { static constexpr unsigned value = 1; }; +struct CellsZ { static constexpr unsigned value = 1; }; //! domain size template