From 1a09608263ce65624bc082dd471e2174f451d344 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Thu, 27 Oct 2022 15:52:12 +0200 Subject: [PATCH] Fix removeSurplus alq Add water rate target limit Add the gradient to the checkXXXTarget so that surplus alq is removed until it would go below the target. I.e. the group still want to produce it target --- .../wells/GasLiftSingleWellGeneric.cpp | 4 +- opm/simulators/wells/GasLiftStage2.cpp | 61 ++++++++++++------- opm/simulators/wells/GasLiftStage2.hpp | 11 ++-- opm/simulators/wells/GasLiftWellState.hpp | 7 ++- 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/opm/simulators/wells/GasLiftSingleWellGeneric.cpp b/opm/simulators/wells/GasLiftSingleWellGeneric.cpp index 2683153ca..e204939e9 100644 --- a/opm/simulators/wells/GasLiftSingleWellGeneric.cpp +++ b/opm/simulators/wells/GasLiftSingleWellGeneric.cpp @@ -750,8 +750,9 @@ GasLiftSingleWellGeneric::getRateWithGroupLimit_(Rate rate_type, const double ne double gr_target, new_gr_rate, efficiency; const std::string* group_name = nullptr; for (const auto& [group_name_temp, efficiency_temp] : pairs) { - if (gr_name_no_check == group_name_temp) + if (gr_name_no_check == group_name_temp) { continue; + } auto gr_target_opt = this->group_info_.getTarget(rate_type, group_name_temp); if (gr_target_opt) { @@ -1251,6 +1252,7 @@ GasLiftSingleWellGeneric::runOptimizeLoop_(bool increase) cur_alq, alq_is_limited, new_rates.water, + new_rates.water_is_limited, increase_opt); return ret_value; } diff --git a/opm/simulators/wells/GasLiftStage2.cpp b/opm/simulators/wells/GasLiftStage2.cpp index 82eb4370a..526bf6f93 100644 --- a/opm/simulators/wells/GasLiftStage2.cpp +++ b/opm/simulators/wells/GasLiftStage2.cpp @@ -115,18 +115,19 @@ addOrRemoveALQincrement_(GradMap &grad_map, const std::string& well_name, bool a } state.update(gi.new_oil_rate, gi.oil_is_limited, gi.new_gas_rate, gi.gas_is_limited, - gi.alq, gi.alq_is_limited, gi.new_water_rate, add); - this->well_state_.setALQ(well_name, gi.alq); - const auto& pu = this->well_state_.phaseUsage(); - std::vector well_pot(pu.num_phases, 0.0); - if(pu.phase_used[BlackoilPhases::PhaseIndex::Liquid]) - well_pot[pu.phase_pos[BlackoilPhases::PhaseIndex::Liquid]] = gi.new_oil_rate; - if(pu.phase_used[BlackoilPhases::PhaseIndex::Aqua]) - well_pot[pu.phase_pos[BlackoilPhases::PhaseIndex::Aqua]] = gi.new_water_rate; - if(pu.phase_used[BlackoilPhases::PhaseIndex::Vapour]) - well_pot[pu.phase_pos[BlackoilPhases::PhaseIndex::Vapour]] = gi.new_gas_rate; + gi.alq, gi.alq_is_limited, gi.new_water_rate, gi.water_is_limited, add); - this->well_state_[well_name].well_potentials = well_pot; + this->well_state_.setALQ(well_name, gi.alq); + const auto& pu = this->well_state_.phaseUsage(); + std::vector well_pot(pu.num_phases, 0.0); + if(pu.phase_used[BlackoilPhases::PhaseIndex::Liquid]) + well_pot[pu.phase_pos[BlackoilPhases::PhaseIndex::Liquid]] = gi.new_oil_rate; + if(pu.phase_used[BlackoilPhases::PhaseIndex::Aqua]) + well_pot[pu.phase_pos[BlackoilPhases::PhaseIndex::Aqua]] = gi.new_water_rate; + if(pu.phase_used[BlackoilPhases::PhaseIndex::Vapour]) + well_pot[pu.phase_pos[BlackoilPhases::PhaseIndex::Vapour]] = gi.new_gas_rate; + + this->well_state_[well_name].well_potentials = well_pot; } std::optional @@ -192,7 +193,7 @@ checkRateAlreadyLimited_(GasLiftWellState &state, bool increase) if (increase) do_check = true; } if (do_check) { - if (state.gasIsLimited() || state.oilIsLimited() || state.alqIsLimited()) { + if (state.gasIsLimited() || state.oilIsLimited() || state.alqIsLimited() || state.waterIsLimited()) { const std::string msg = fmt::format( "{} gradient : skipping since {} was limited in previous step", (increase ? "incremental" : "decremental"), @@ -757,7 +758,7 @@ removeSurplusALQ_(const Group &group, displayDebugMessage_(msg); } SurplusState state {*this, group, oil_rate, gas_rate, water_rate, alq, - min_eco_grad, controls.oil_target, controls.gas_target, + min_eco_grad, controls.oil_target, controls.gas_target, controls.water_target, controls.liquid_target, max_glift }; while (!stop_iteration) { @@ -768,8 +769,8 @@ removeSurplusALQ_(const Group &group, const auto well_name = dec_grad_itr->first; auto eco_grad = dec_grad_itr->second; bool remove = false; - if (state.checkOilTarget() || state.checkGasTarget() - || state.checkLiquidTarget() || state.checkALQlimit()) + if (state.checkOilTarget(eco_grad) || state.checkGasTarget(eco_grad) + || state.checkLiquidTarget(eco_grad) || state.checkWaterTarget(eco_grad) || state.checkALQlimit()) { remove = true; } @@ -1085,10 +1086,10 @@ checkEcoGradient(const std::string &well_name, double eco_grad) bool GasLiftStage2::SurplusState:: -checkGasTarget() +checkGasTarget(double eco_grad) { if (this->group.has_control(Group::ProductionCMode::GRAT)) { - if (this->gas_target < this->gas_rate ) { + if (this->gas_target < (this->gas_rate - eco_grad) ) { if (this->parent.debug) { const std::string msg = fmt::format("group: {} : " "gas rate {} is greater than gas target {}", this->group.name(), @@ -1102,11 +1103,11 @@ checkGasTarget() } bool GasLiftStage2::SurplusState:: -checkLiquidTarget() +checkLiquidTarget(double eco_grad) { if (this->group.has_control(Group::ProductionCMode::LRAT)) { auto liquid_rate = this->oil_rate + this->water_rate; - if (this->liquid_target < liquid_rate ) { + if (this->liquid_target < (liquid_rate - eco_grad) ) { if (this->parent.debug) { const std::string msg = fmt::format("group: {} : " "liquid rate {} is greater than liquid target {}", this->group.name(), @@ -1121,10 +1122,10 @@ checkLiquidTarget() bool GasLiftStage2::SurplusState:: -checkOilTarget() +checkOilTarget(double eco_grad) { if (this->group.has_control(Group::ProductionCMode::ORAT)) { - if (this->oil_target < this->oil_rate ) { + if (this->oil_target < (this->oil_rate - eco_grad) ) { if (this->parent.debug) { const std::string msg = fmt::format("group: {} : " "oil rate {} is greater than oil target {}", this->group.name(), @@ -1137,6 +1138,24 @@ checkOilTarget() return false; } +bool +GasLiftStage2::SurplusState:: +checkWaterTarget(double eco_grad) +{ + if (this->group.has_control(Group::ProductionCMode::WRAT)) { + if (this->water_target < (this->water_rate - eco_grad) ) { + if (this->parent.debug) { + const std::string msg = fmt::format("group: {} : " + "water rate {} is greater than oil target {}", this->group.name(), + this->water_rate, this->water_target); + this->parent.displayDebugMessage_(msg); + } + return true; + } + } + return false; +} + void GasLiftStage2::SurplusState:: updateRates(const std::string &well_name) diff --git a/opm/simulators/wells/GasLiftStage2.hpp b/opm/simulators/wells/GasLiftStage2.hpp index a1321d0dc..d1ffa6294 100644 --- a/opm/simulators/wells/GasLiftStage2.hpp +++ b/opm/simulators/wells/GasLiftStage2.hpp @@ -173,7 +173,7 @@ protected: SurplusState( GasLiftStage2& parent_, const Group& group_, double oil_rate_, double gas_rate_, double water_rate_, double alq_, double min_eco_grad_, - double oil_target_, double gas_target_, double liquid_target_, + double oil_target_, double gas_target_, double water_target_, double liquid_target_, std::optional max_glift_) : parent{parent_}, group{group_}, @@ -184,6 +184,7 @@ protected: min_eco_grad{min_eco_grad_}, oil_target{oil_target_}, gas_target{gas_target_}, + water_target(water_target_), liquid_target{liquid_target_}, max_glift{max_glift_}, it{0} @@ -197,6 +198,7 @@ protected: const double min_eco_grad; const double oil_target; const double gas_target; + const double water_target; const double liquid_target; std::optional max_glift; int it; @@ -205,9 +207,10 @@ protected: GradMap &grad_map, const std::string& well_name, bool add); bool checkALQlimit(); bool checkEcoGradient(const std::string& well_name, double eco_grad); - bool checkGasTarget(); - bool checkLiquidTarget(); - bool checkOilTarget(); + bool checkGasTarget(double eco_grad); + bool checkLiquidTarget(double eco_grad); + bool checkOilTarget(double eco_grad); + bool checkWaterTarget(double eco_grad); void updateRates(const std::string& name); }; }; diff --git a/opm/simulators/wells/GasLiftWellState.hpp b/opm/simulators/wells/GasLiftWellState.hpp index 204ed7534..3bda6db71 100644 --- a/opm/simulators/wells/GasLiftWellState.hpp +++ b/opm/simulators/wells/GasLiftWellState.hpp @@ -31,7 +31,7 @@ namespace Opm //GasLiftWellState() { } GasLiftWellState(double oil_rate, bool oil_is_limited, double gas_rate, bool gas_is_limited, - double alq, bool alq_is_limited, double water_rate, std::optional increase) : + double alq, bool alq_is_limited, double water_rate, bool water_is_limited, std::optional increase) : oil_rate_{oil_rate}, oil_is_limited_{oil_is_limited}, gas_rate_{gas_rate}, @@ -39,6 +39,7 @@ namespace Opm alq_{alq}, alq_is_limited_{alq_is_limited}, water_rate_{water_rate}, + water_is_limited_{water_is_limited}, increase_{increase} {} double alq() const { return alq_; } @@ -51,9 +52,11 @@ namespace Opm bool oilIsLimited() const { return oil_is_limited_; } double oilRate() const { return oil_rate_; } double waterRate() const { return water_rate_; } + bool waterIsLimited() const { return water_is_limited_; } void update(double oil_rate, bool oil_is_limited, double gas_rate, bool gas_is_limited, double alq, bool alq_is_limited, double water_rate, + double water_is_limited, bool increase) { oil_rate_ = oil_rate; @@ -63,6 +66,7 @@ namespace Opm alq_ = alq; alq_is_limited_ = alq_is_limited; water_rate_ = water_rate; + water_is_limited_ = water_is_limited; increase_ = increase; } private: @@ -73,6 +77,7 @@ namespace Opm double alq_; bool alq_is_limited_; double water_rate_; + bool water_is_limited_; std::optional increase_; };