From e718ce8359f8b2f04bd9787573ae231e1deb10d0 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Fri, 24 Oct 2025 13:32:19 +0200 Subject: [PATCH] make sure phase is active before getting phase_pos --- opm/simulators/wells/WellConstraints.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/opm/simulators/wells/WellConstraints.cpp b/opm/simulators/wells/WellConstraints.cpp index 553133810d..9d73bc43a7 100644 --- a/opm/simulators/wells/WellConstraints.cpp +++ b/opm/simulators/wells/WellConstraints.cpp @@ -220,21 +220,28 @@ activeProductionConstraint(const SingleWellState& ws, } if (controls.hasControl(Well::ProducerCMode::LRAT) && currentControl != Well::ProducerCMode::LRAT) { - const int oil_pos = pu.canonicalToActivePhaseIdx(IndexTraits::oilPhaseIdx); - const int water_pos = pu.canonicalToActivePhaseIdx(IndexTraits::waterPhaseIdx); - Scalar current_rate = -ws.surface_rates[oil_pos]; - current_rate -= ws.surface_rates[water_pos]; + Scalar current_rate = 0.; + if (pu.phaseIsActive(IndexTraits::oilPhaseIdx)) { + const int oil_pos = pu.canonicalToActivePhaseIdx(IndexTraits::oilPhaseIdx); + current_rate -= ws.surface_rates[oil_pos]; + } + if (pu.phaseIsActive(IndexTraits::waterPhaseIdx)) { + const int water_pos = pu.canonicalToActivePhaseIdx(IndexTraits::waterPhaseIdx); + current_rate -= ws.surface_rates[water_pos]; + } bool skip = false; - if (controls.liquid_rate == controls.oil_rate) { + if (controls.liquid_rate == controls.oil_rate && pu.phaseIsActive(IndexTraits::waterPhaseIdx)) { + const int water_pos = pu.canonicalToActivePhaseIdx(IndexTraits::waterPhaseIdx); const Scalar current_water_rate = ws.surface_rates[water_pos]; if (std::abs(current_water_rate) < 1e-12) { skip = true; deferred_logger.debug("LRAT_ORAT_WELL", "Well " + well_.name() + " The LRAT target is equal the ORAT target and the water rate is zero, skip checking LRAT"); } } - if (!skip && controls.liquid_rate < current_rate) + if (!skip && controls.liquid_rate < current_rate) { return Well::ProducerCMode::LRAT; + } } if (controls.hasControl(Well::ProducerCMode::RESV) && currentControl != Well::ProducerCMode::RESV) {