From cc08df226e9e2f8913f289a0f86187088cb9c6fc Mon Sep 17 00:00:00 2001 From: Vegard Kippe Date: Mon, 26 Aug 2024 13:16:19 +0200 Subject: [PATCH 1/5] Update after merging #5527 --- opm/simulators/flow/FlowProblem.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index 8b50c6a32..c4c06b7eb 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -601,7 +601,9 @@ public: // update maximum water saturation and minimum pressure // used when ROCKCOMP is activated - asImp_().updateExplicitQuantities_(episodeIdx, timeStepSize); + // Do not update max RS first step after a restart + asImp_().updateExplicitQuantities_(episodeIdx, timeStepSize, first_step_ && (episodeIdx > 0)); + first_step_ = false; if (nonTrivialBoundaryConditions()) { this->model().linearizer().updateBoundaryConditionData(); @@ -1871,7 +1873,7 @@ private: Implementation& asImp_() { return *static_cast(this); } protected: - void updateExplicitQuantities_(int episodeIdx, int timeStepSize) + void updateExplicitQuantities_(int episodeIdx, int timeStepSize, const bool first_step_after_restart = false) { OPM_TIMEBLOCK(updateExplicitQuantities); const bool invalidateFromMaxWaterSat = updateMaxWaterSaturation_(); @@ -1882,8 +1884,8 @@ protected: const bool invalidateFromMaxOilSat = updateMaxOilSaturation_(); - // deal with DRSDT and DRVDT - const bool invalidateDRDT = this->asImp_().updateCompositionChangeLimits_(); + // deal with DRSDT and DRVDT (do not update first step after a restart) + const bool invalidateDRDT = !first_step_after_restart && this->asImp_().updateCompositionChangeLimits_(); // the derivatives may have change bool invalidateIntensiveQuantities @@ -2886,10 +2888,9 @@ private: BCData bcindex_; bool nonTrivialBoundaryConditions_ = false; bool explicitRockCompaction_ = false; - + bool first_step_ = true; ModuleParams moduleParams_; - }; } // namespace Opm From 8f45cbe4c4a5da99dc81d4cf769028aa4b154dfa Mon Sep 17 00:00:00 2001 From: Vegard Kippe Date: Mon, 26 Aug 2024 18:01:01 +0200 Subject: [PATCH 2/5] Properly initialize mixing controls after restart. --- opm/simulators/flow/FlowProblem.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index c4c06b7eb..e47a760db 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -2211,9 +2211,8 @@ protected: const auto& schedule = simulator.vanguard().schedule(); const auto& eclState = simulator.vanguard().eclState(); const auto& initconfig = eclState.getInitConfig(); + const int restart_step = initconfig.getRestartStep(); { - int restart_step = initconfig.getRestartStep(); - simulator.setTime(schedule.seconds(restart_step)); simulator.startNextEpisode(simulator.startTime() + simulator.time(), @@ -2247,6 +2246,9 @@ protected: this->micp_.resize(numElems); } + // Initialize mixing controls before trying to set any lastRx valuesx + this->mixControls_.init(numElems, restart_step, eclState.runspec().tabdims().getNumPVTTables()); + for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) { auto& elemFluidState = initialFluidStates_[elemIdx]; elemFluidState.setPvtRegionIndex(pvtRegionIndex(elemIdx)); From 0485bfb47f1ee250a68d3595be0de54d0ee548ea Mon Sep 17 00:00:00 2001 From: Vegard Kippe Date: Tue, 27 Aug 2024 15:51:56 +0200 Subject: [PATCH 3/5] Set correct episode before initial call to invalidateAndUpdateIntensiveQuantities --- opm/simulators/flow/FlowProblem.hpp | 13 ++++++------- .../flow/SimulatorFullyImplicitBlackoil.hpp | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index e47a760db..e697752f2 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -601,9 +601,7 @@ public: // update maximum water saturation and minimum pressure // used when ROCKCOMP is activated - // Do not update max RS first step after a restart - asImp_().updateExplicitQuantities_(episodeIdx, timeStepSize, first_step_ && (episodeIdx > 0)); - first_step_ = false; + asImp_().updateExplicitQuantities_(episodeIdx, timeStepSize); if (nonTrivialBoundaryConditions()) { this->model().linearizer().updateBoundaryConditionData(); @@ -1873,7 +1871,7 @@ private: Implementation& asImp_() { return *static_cast(this); } protected: - void updateExplicitQuantities_(int episodeIdx, int timeStepSize, const bool first_step_after_restart = false) + void updateExplicitQuantities_(int episodeIdx, int timeStepSize) { OPM_TIMEBLOCK(updateExplicitQuantities); const bool invalidateFromMaxWaterSat = updateMaxWaterSaturation_(); @@ -1884,8 +1882,8 @@ protected: const bool invalidateFromMaxOilSat = updateMaxOilSaturation_(); - // deal with DRSDT and DRVDT (do not update first step after a restart) - const bool invalidateDRDT = !first_step_after_restart && this->asImp_().updateCompositionChangeLimits_(); + // deal with DRSDT and DRVDT + const bool invalidateDRDT = this->asImp_().updateCompositionChangeLimits_(); // the derivatives may have change bool invalidateIntensiveQuantities @@ -2890,9 +2888,10 @@ private: BCData bcindex_; bool nonTrivialBoundaryConditions_ = false; bool explicitRockCompaction_ = false; - bool first_step_ = true; + ModuleParams moduleParams_; + }; } // namespace Opm diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp index 7a9b7a5c9..3f25e15be 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp @@ -195,6 +195,8 @@ public: { init(timer); // Make cache up to date. No need for updating it in elementCtx. + // NB! Need to be at the correct step in case of restart + simulator_.setEpisodeIndex(timer.currentStepNum()); simulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0); // Main simulation loop. while (!timer.done()) { From 0b6dd939031717d720ec86f1191fb98f50ae64ff Mon Sep 17 00:00:00 2001 From: Vegard Kippe Date: Wed, 28 Aug 2024 15:02:26 +0200 Subject: [PATCH 4/5] Avoid negative time step size after restart (trouble for DRSDT init) --- opm/simulators/flow/EclWriter.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opm/simulators/flow/EclWriter.hpp b/opm/simulators/flow/EclWriter.hpp index 19f345523..57419cd52 100644 --- a/opm/simulators/flow/EclWriter.hpp +++ b/opm/simulators/flow/EclWriter.hpp @@ -574,6 +574,8 @@ public: thpres.setFromRestart(thpresValues); } restartTimeStepSize_ = restartValues.getExtra("OPMEXTRA")[0]; + if (restartTimeStepSize_ <= 0) + restartTimeStepSize_ = std::numeric_limits::max(); // initialize the well model from restart values simulator_.problem().wellModel().initFromRestartFile(restartValues); From eb869f211f54dc1d1e04e1aae30aa6ee31ca2be5 Mon Sep 17 00:00:00 2001 From: Vegard Kippe Date: Wed, 28 Aug 2024 16:28:51 +0200 Subject: [PATCH 5/5] Avoid time step dependent jump in RS after restart --- opm/simulators/flow/FlowProblem.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index e697752f2..d750edb0d 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -601,7 +601,9 @@ public: // update maximum water saturation and minimum pressure // used when ROCKCOMP is activated - asImp_().updateExplicitQuantities_(episodeIdx, timeStepSize); + // Do not update max RS first step after a restart + asImp_().updateExplicitQuantities_(episodeIdx, timeStepSize, first_step_ && (episodeIdx > 0)); + first_step_ = false; if (nonTrivialBoundaryConditions()) { this->model().linearizer().updateBoundaryConditionData(); @@ -1871,7 +1873,7 @@ private: Implementation& asImp_() { return *static_cast(this); } protected: - void updateExplicitQuantities_(int episodeIdx, int timeStepSize) + void updateExplicitQuantities_(int episodeIdx, int timeStepSize, const bool first_step_after_restart = false) { OPM_TIMEBLOCK(updateExplicitQuantities); const bool invalidateFromMaxWaterSat = updateMaxWaterSaturation_(); @@ -1883,7 +1885,7 @@ protected: // deal with DRSDT and DRVDT - const bool invalidateDRDT = this->asImp_().updateCompositionChangeLimits_(); + const bool invalidateDRDT = !first_step_after_restart && this->asImp_().updateCompositionChangeLimits_(); // the derivatives may have change bool invalidateIntensiveQuantities @@ -2888,7 +2890,7 @@ private: BCData bcindex_; bool nonTrivialBoundaryConditions_ = false; bool explicitRockCompaction_ = false; - + bool first_step_ = true; ModuleParams moduleParams_;