From 5e5a57dfd3f123d4db4926a48255e5b86ba15b38 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Wed, 5 Nov 2025 15:43:39 +0100 Subject: [PATCH] adding the group name to the SingleWellState:;group_target so we might be able to use it to identifiy the NONE control group --- opm/simulators/wells/BlackoilWellModelGeneric.cpp | 2 +- opm/simulators/wells/GroupStateHelper.cpp | 8 ++++---- opm/simulators/wells/GroupStateHelper.hpp | 12 ++++++------ opm/simulators/wells/SingleWellState.hpp | 2 +- opm/simulators/wells/WellGroupControls.cpp | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index e252da4a2d..5593a49f63 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -1338,7 +1338,7 @@ updateAndCommunicateGroupData(const int reportStepIdx, const Scalar efficiencyFactor = well->wellEcl().getEfficiencyFactor() * ws.efficiency_scaling_factor; // Translate injector type from control to Phase. - std::optional group_target; + std::optional> group_target; if (well->isProducer()) { group_target = group_state_helper.getWellGroupTargetProducer( well->name(), diff --git a/opm/simulators/wells/GroupStateHelper.cpp b/opm/simulators/wells/GroupStateHelper.cpp index 53f3f734d5..12675f1d9c 100644 --- a/opm/simulators/wells/GroupStateHelper.cpp +++ b/opm/simulators/wells/GroupStateHelper.cpp @@ -177,7 +177,7 @@ GroupStateHelper::checkGroupConstraintsInj(const std::strin if (this->schedule_.hasWell(name) && this->wellState().well(name).group_target) { // for wells we already have computed the target Scalar scale = 1.0; - const Scalar group_target_rate_available = *this->wellState().well(name).group_target; + const Scalar group_target_rate_available = (*this->wellState().well(name).group_target).second; const Scalar current_well_rate_available = tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers. if (current_well_rate_available > 1e-12) { @@ -319,7 +319,7 @@ GroupStateHelper::checkGroupConstraintsProd(const std::stri // Switch sign since 'rates' are negative for producers. const Scalar current_well_rate_available = -tcalc.calcModeRateFromRates(rates); - const Scalar group_target_rate_available = *this->wellState().well(name).group_target; + const Scalar group_target_rate_available = (*this->wellState().well(name).group_target).second; Scalar scale = 1.0; if (current_well_rate_available > 1e-12) { scale = group_target_rate_available / current_well_rate_available; @@ -648,7 +648,7 @@ GroupStateHelper::getWellGroupTargetInjector(const std::str } template -std::optional +std::optional> GroupStateHelper::getWellGroupTargetProducer(const std::string& name, const std::string& parent, const Group& group, @@ -740,7 +740,7 @@ GroupStateHelper::getWellGroupTargetProducer(const std::str do_addback); // Avoid negative target rates coming from too large local reductions. - return std::max(Scalar(0.0), target / efficiency_factor); + return {group.name(), std::max(Scalar(0.0), target / efficiency_factor)}; } template diff --git a/opm/simulators/wells/GroupStateHelper.hpp b/opm/simulators/wells/GroupStateHelper.hpp index f298adc06d..b36af8371e 100644 --- a/opm/simulators/wells/GroupStateHelper.hpp +++ b/opm/simulators/wells/GroupStateHelper.hpp @@ -251,12 +251,12 @@ public: const Scalar efficiency_factor, const std::vector& resv_coeff) const; - std::optional getWellGroupTargetProducer(const std::string& name, - const std::string& parent, - const Group& group, - const Scalar* rates, - const Scalar efficiency_factor, - const std::vector& resv_coeff) const; + std::optional> getWellGroupTargetProducer(const std::string& name, + const std::string& parent, + const Group& group, + const Scalar* rates, + const Scalar efficiency_factor, + const std::vector& resv_coeff) const; GuideRate::RateVector getWellRateVector(const std::string& name) const; diff --git a/opm/simulators/wells/SingleWellState.hpp b/opm/simulators/wells/SingleWellState.hpp index 73a12d5901..bb3332c6b0 100644 --- a/opm/simulators/wells/SingleWellState.hpp +++ b/opm/simulators/wells/SingleWellState.hpp @@ -127,7 +127,7 @@ public: std::vector prev_surface_rates; PerfData perf_data; bool trivial_group_target; - std::optional group_target; + std::optional> group_target; SegmentState segments; Events events; WellInjectorCMode injection_cmode{WellInjectorCMode::CMODE_UNDEFINED}; diff --git a/opm/simulators/wells/WellGroupControls.cpp b/opm/simulators/wells/WellGroupControls.cpp index 6f283a0f77..4e9e463773 100644 --- a/opm/simulators/wells/WellGroupControls.cpp +++ b/opm/simulators/wells/WellGroupControls.cpp @@ -124,7 +124,7 @@ getGroupInjectionControl(const Group& group, const auto target_rate = well_state.well(well_.indexOfWell()).group_target; if (target_rate) { - control_eq = injection_rate - *target_rate; + control_eq = injection_rate - target_rate->second; } else { const auto& controls = well.injectionControls(summaryState); control_eq = bhp - controls.bhp_limit; @@ -190,7 +190,7 @@ getGroupInjectionTargetRate(const Group& group, return std::nullopt; } - return groupStateHelper.wellState().well(well_.indexOfWell()).group_target; + return groupStateHelper.wellState().well(well_.indexOfWell()).group_target->second; } template @@ -258,7 +258,7 @@ getGroupProductionControl(const Group& group, const auto target_rate = well_state.well(well_.indexOfWell()).group_target; if (target_rate) { const auto current_rate = -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers. - control_eq = current_rate - *target_rate; + control_eq = current_rate - target_rate->second; } else { const auto& controls = well.productionControls(summaryState); control_eq = bhp - controls.bhp_limit; @@ -310,7 +310,7 @@ getGroupProductionTargetRate(const Group& group, if (!target_rate) { return 1.0; } - if (*target_rate == 0.0) { + if (target_rate->second == 0.0) { return 0.0; } const auto& ws = well_state.well(well_.indexOfWell()); @@ -318,7 +318,7 @@ getGroupProductionTargetRate(const Group& group, const auto current_rate = -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers. Scalar scale = 1.0; if (current_rate > 1e-14) - scale = *target_rate / current_rate; + scale = target_rate->second / current_rate; return scale; }