diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index 958fae6a4..921294baf 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -37,8 +37,8 @@ #include #include -#include #include +#include #include #include @@ -72,8 +72,10 @@ #include #include +#include #include #include +#include #include #include @@ -224,38 +226,36 @@ public: , pffDofData_(simulator.gridView(), this->elementMapper()) , tracerModel_(simulator) { - const auto& vanguard = simulator.vanguard(); - - enableDriftCompensation_ = Parameters::Get(); - - enableVtkOutput_ = Parameters::Get(); - + this->enableDriftCompensation_ = Parameters::Get(); + this->enableVtkOutput_ = Parameters::Get(); this->enableTuning_ = Parameters::Get(); + this->initialTimeStepSize_ = Parameters::Get>(); - this->maxTimeStepAfterWellEvent_ = Parameters::Get>() * 24 * 60 * 60; + this->maxTimeStepAfterWellEvent_ = unit::convert::from + (Parameters::Get>(), unit::day); - // The value N for this parameter is defined in the following order of presedence: + // The value N for this parameter is defined in the following order of precedence: + // // 1. Command line value (--num-pressure-points-equil=N) - // 2. EQLDIMS item 2 - // Default value is defined in opm-common/src/opm/input/eclipse/share/keywords/000_Eclipse100/E/EQLDIMS - if (Parameters::IsSet()) - { - this->numPressurePointsEquil_ = Parameters::Get(); - } else { - this->numPressurePointsEquil_ = simulator.vanguard().eclState().getTableManager().getEqldims().getNumDepthNodesP(); - } + // + // 2. EQLDIMS item 2. Default value from + // opm-common/opm/input/eclipse/share/keywords/000_Eclipse100/E/EQLDIMS - explicitRockCompaction_ = Parameters::Get(); + this->numPressurePointsEquil_ = Parameters::IsSet() + ? Parameters::Get() + : simulator.vanguard().eclState().getTableManager().getEqldims().getNumDepthNodesP(); + this->explicitRockCompaction_ = Parameters::Get(); - RelpermDiagnostics relpermDiagnostics; - relpermDiagnostics.diagnosis(vanguard.eclState(), vanguard.cartesianIndexMapper()); + RelpermDiagnostics relpermDiagnostics{}; + relpermDiagnostics.diagnosis(simulator.vanguard().eclState(), + simulator.vanguard().cartesianIndexMapper()); } virtual ~FlowProblem() = default; void prefetch(const Element& elem) const - { pffDofData_.prefetch(elem); } + { this->pffDofData_.prefetch(elem); } /*! * \brief This method restores the complete state of the problem and its sub-objects diff --git a/opm/simulators/flow/FlowProblemBlackoil.hpp b/opm/simulators/flow/FlowProblemBlackoil.hpp index 63fe0153a..d0108fa96 100644 --- a/opm/simulators/flow/FlowProblemBlackoil.hpp +++ b/opm/simulators/flow/FlowProblemBlackoil.hpp @@ -43,21 +43,25 @@ #include +#include + +#include #include #include #include +#include #include -#include -#include #if HAVE_DAMARIS #include #endif #include +#include #include #include +#include #include #include @@ -209,6 +213,7 @@ public: // create the ECL writer eclWriter_ = std::make_unique(simulator); enableEclOutput_ = Parameters::Get(); + #if HAVE_DAMARIS // create Damaris writer damarisWriter_ = std::make_unique(simulator); @@ -224,23 +229,27 @@ public: FlowProblemType::beginEpisode(); auto& simulator = this->simulator(); - int episodeIdx = simulator.episodeIndex(); + + const int episodeIdx = simulator.episodeIndex(); const auto& schedule = simulator.vanguard().schedule(); // Evaluate UDQ assign statements to make sure the settings are // available as UDA controls for the current report step. - actionHandler_.evalUDQAssignments(episodeIdx, simulator.vanguard().udqState()); + this->actionHandler_ + .evalUDQAssignments(episodeIdx, simulator.vanguard().udqState()); if (episodeIdx >= 0) { const auto& oilVap = schedule[episodeIdx].oilvap(); if (oilVap.getType() == OilVaporizationProperties::OilVaporization::VAPPARS) { FluidSystem::setVapPars(oilVap.vap1(), oilVap.vap2()); - } else { + } + else { FluidSystem::setVapPars(0.0, 0.0); } } - ConvectiveMixingModule::beginEpisode(simulator.vanguard().eclState(), simulator.vanguard().schedule(), episodeIdx, moduleParams_.convectiveMixingModuleParam); + ConvectiveMixingModule::beginEpisode(simulator.vanguard().eclState(), schedule, episodeIdx, + this->moduleParams_.convectiveMixingModuleParam); } /*! @@ -248,18 +257,21 @@ public: */ void finishInit() { - // TODO: there should be room to remove duplication for this function, - // but there is relatively complicated logic in the function calls in this function - // some refactoring is needed for this function + // TODO: there should be room to remove duplication for this + // function, but there is relatively complicated logic in the + // function calls here. Some refactoring is needed. FlowProblemType::finishInit(); + auto& simulator = this->simulator(); auto finishTransmissibilities = [updated = false, this]() mutable { if (updated) { return; } + this->transmissibilities_.finishInit([&vg = this->simulator().vanguard()](const unsigned int it) { return vg.gridIdxToEquilGridIdx(it); }); + updated = true; }; @@ -279,7 +291,8 @@ public: std::function equilGridToGrid = [&simulator](unsigned int i) { return simulator.vanguard().gridEquilIdxToGridIdx(i); }; - eclWriter_->extractOutputTransAndNNC(equilGridToGrid); + + this->eclWriter_->extractOutputTransAndNNC(equilGridToGrid); } simulator.vanguard().releaseGlobalTransmissibilities(); @@ -301,10 +314,12 @@ public: // disables gravity, else the standard value of the gravity constant at sea level // on earth is used this->gravity_ = 0.0; - if (Parameters::Get()) - this->gravity_[dim - 1] = 9.80665; - if (!eclState.getInitConfig().hasGravity()) - this->gravity_[dim - 1] = 0.0; + if (Parameters::Get() && + eclState.getInitConfig().hasGravity()) + { + // unit::gravity is 9.80665 m^2/s--i.e., standard measure at Tellus equator. + this->gravity_[dim - 1] = unit::gravity; + } if (this->enableTuning_) { // if support for the TUNING keyword is enabled, we get the initial time @@ -316,8 +331,6 @@ public: this->initFluidSystem_(); - - if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) { this->maxOilSaturation_.resize(this->model().numGridDof(), 0.0); @@ -333,22 +346,25 @@ public: } return coords; }); + this->readMaterialParameters_(); this->readThermalParameters_(); // write the static output files (EGRID, INIT) if (enableEclOutput_) { - eclWriter_->writeInit(); + this->eclWriter_->writeInit(); } finishTransmissibilities(); const auto& initconfig = eclState.getInitConfig(); this->tracerModel_.init(initconfig.restartRequested()); - if (initconfig.restartRequested()) - readEclRestartSolution_(); - else - readInitialCondition_(); + if (initconfig.restartRequested()) { + this->readEclRestartSolution_(); + } + else { + this->readInitialCondition_(); + } this->tracerModel_.prepareTracerBatches(); @@ -357,14 +373,14 @@ public: if constexpr (getPropValue()) { const auto& vanguard = this->simulator().vanguard(); const auto& gridView = vanguard.gridView(); - int numElements = gridView.size(/*codim=*/0); + const int numElements = gridView.size(/*codim=*/0); this->polymer_.maxAdsorption.resize(numElements, 0.0); } this->readBoundaryConditions_(); // compute and set eq weights based on initial b values - computeAndSetEqWeights_(); + this->computeAndSetEqWeights_(); if (this->enableDriftCompensation_) { this->drift_.resize(this->model().numGridDof()); @@ -386,10 +402,11 @@ public: } // TODO: move to the end for later refactoring of the function finishInit() - // deal with DRSDT + // + // deal with DRSDT this->mixControls_.init(this->model().numGridDof(), this->episodeIndex(), - eclState.runspec().tabdims().getNumPVTTables()); + eclState.runspec().tabdims().getNumPVTTables()); } /*! diff --git a/tests/test_equil.cpp b/tests/test_equil.cpp index 75c2284c9..3d38831e4 100644 --- a/tests/test_equil.cpp +++ b/tests/test_equil.cpp @@ -20,10 +20,20 @@ module for the precise wording of the license and the list of copyright holders. */ + #include "config.h" #define BOOST_TEST_MODULE Equil +#include + +#include +#if (BOOST_VERSION / 100000 == 1) && ((BOOST_VERSION / 100) % 1000 < 71) +#include +#else +#include +#endif + #include #include #include @@ -58,42 +68,37 @@ #include #include -#include -#include -#if BOOST_VERSION / 100000 == 1 && BOOST_VERSION / 100 % 1000 < 71 -#include -#else -#include -#endif - - namespace Opm::Properties { namespace TTag { - struct TestEquilTypeTag { using InheritsFrom = std::tuple; }; + struct TestEquilVapwatTypeTag { using InheritsFrom = std::tuple; }; -} + +} // namespace TTag template struct WellModel { using type = BlackoilWellModel; }; + template struct EnableVapwat { static constexpr bool value = true; }; + template struct WellModel { using type = BlackoilWellModel; }; + template struct EnableVapwat { static constexpr bool value = true; @@ -101,18 +106,19 @@ struct EnableVapwat { } // namespace Opm::Properties +namespace { + template std::unique_ptr> initSimulator(const char *filename) { using Simulator = Opm::GetPropType; - std::string filenameArg = "--ecl-deck-file-name="; - filenameArg += filename; + const auto filenameArg = std::string {"--ecl-deck-file-name="} + filename; const char* argv[] = { "test_equil", - filenameArg.c_str() + filenameArg.c_str(), }; Opm::setupParameters_(/*argc=*/sizeof(argv)/sizeof(argv[0]), argv, /*registerParams=*/false); @@ -123,7 +129,8 @@ initSimulator(const char *filename) } template -static std::vector> cellVerticalExtent(const GridView& gridView) +std::vector> +cellVerticalExtent(const GridView& gridView) { using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper; ElementMapper elemMapper(gridView, Dune::mcmgElementLayout()); @@ -142,7 +149,7 @@ static std::vector> cellVerticalExtent(const GridView& } template -static void initDefaultFluidSystem() +void initDefaultFluidSystem() { using FluidSystem = Opm::GetPropType; @@ -207,11 +214,12 @@ static void initDefaultFluidSystem() FluidSystem::initEnd(); } -static Opm::EquilRecord mkEquilRecord( double datd, double datp, - double zwoc, double pcow_woc, - double zgoc, double pcgo_goc ) +Opm::EquilRecord +mkEquilRecord(const double datd, const double datp, + const double zwoc, const double pcow_woc, + const double zgoc, const double pcgo_goc) { - return Opm::EquilRecord( datd, datp, zwoc, pcow_woc, zgoc, pcgo_goc, true, true, 0, true); + return { datd, datp, zwoc, pcow_woc, zgoc, pcgo_goc, true, true, 0, true}; } template @@ -220,8 +228,6 @@ double centerDepth(const Simulator& sim, const std::size_t cell) return Opm::UgGridHelpers::cellCenterDepth(sim.vanguard().grid(), cell); } -namespace { - struct EquilFixture { EquilFixture() { int argc = boost::unit_test::framework::master_test_suite().argc; @@ -253,7 +259,7 @@ struct EquilFixture { CartesianIndexMapper>; }; -} +} // Anonymous namespace BOOST_GLOBAL_FIXTURE(EquilFixture); @@ -845,7 +851,6 @@ BOOST_AUTO_TEST_CASE(DeckWithCO2STORE) } } - BOOST_AUTO_TEST_CASE(DeckWithWetGas) { using TypeTag = Opm::Properties::TTag::TestEquilTypeTag;