From c0431ce4f9d226e41ce597fd6127a4e7aa7d883d Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Thu, 27 Mar 2025 00:55:52 +0100 Subject: [PATCH] Set thp from network in well testing --- .../wells/BlackoilWellModel_impl.hpp | 12 ++++++++++ opm/simulators/wells/WellInterface_impl.hpp | 23 ++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index b0ca78e5f1..375de73604 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -565,6 +565,18 @@ namespace Opm { well->setPrevSurfaceRates(this->wellState(), this->prevWellState()); } + const auto& network = this->schedule()[timeStepIdx].network(); + if (network.active() && !this->node_pressures_.empty()) { + if (well->isProducer()) { + const auto it = this->node_pressures_.find(well->wellEcl().groupName()); + if (it != this->node_pressures_.end()) { + // The well belongs to a group which has a network nodal pressure, + // set the dynamic THP constraint based on the network nodal pressure + const Scalar nodal_pressure = it->second; + well->setDynamicThpLimit(nodal_pressure); + } + } + } try { using GLiftEclWells = typename GasLiftGroupInfo::GLiftEclWells; GLiftEclWells ecl_well_map; diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index 0fe6a8639b..65a43bffc2 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -397,6 +397,15 @@ namespace Opm WellState well_state_copy = well_state; auto& ws = well_state_copy.well(this->indexOfWell()); + const auto& summary_state = simulator.vanguard().summaryState(); + const bool has_thp_limit = this->wellHasTHPConstraints(summary_state); + if (has_thp_limit) { + ws.production_cmode = Well::ProducerCMode::THP; + } + else { + ws.production_cmode = Well::ProducerCMode::BHP; + } + updateWellStateWithTarget(simulator, group_state, well_state_copy, deferred_logger); calculateExplicitQuantities(simulator, well_state_copy, deferred_logger); updatePrimaryVariables(simulator, well_state_copy, deferred_logger); @@ -715,19 +724,8 @@ namespace Opm DeferredLogger& deferred_logger) { OPM_TIMEFUNCTION(); - // keep a copy of the original well state - const WellState well_state0 = well_state; const double dt = simulator.timeStepSize(); - const auto& summary_state = simulator.vanguard().summaryState(); - const bool has_thp_limit = this->wellHasTHPConstraints(summary_state); - bool converged; - if (has_thp_limit) { - well_state.well(this->indexOfWell()).production_cmode = Well::ProducerCMode::THP; - } - else { - well_state.well(this->indexOfWell()).production_cmode = Well::ProducerCMode::BHP; - } - converged = iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger); + const bool converged = iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger); if (converged) { deferred_logger.debug("WellTest: Well equation for well " + this->name() + " converged"); return true; @@ -735,7 +733,6 @@ namespace Opm const int max_iter = this->param_.max_welleq_iter_; deferred_logger.debug("WellTest: Well equation for well " + this->name() + " failed converging in " + std::to_string(max_iter) + " iterations"); - well_state = well_state0; return false; }