20#ifndef OPM_GASLIFT_SINGLE_WELL_GENERIC_HEADER_INCLUDED
21#define OPM_GASLIFT_SINGLE_WELL_GENERIC_HEADER_INCLUDED
23#include <dune/common/version.hh>
24#include <dune/common/parallel/mpihelper.hh>
26#include <opm/core/props/BlackoilPhases.hpp>
28#include <opm/input/eclipse/Schedule/Well/WellProductionControls.hpp>
29#include <opm/simulators/wells/GasLiftGroupInfo.hpp>
30#include <opm/simulators/wells/GasLiftCommon.hpp>
31#include <opm/simulators/wells/GroupState.hpp>
45class GasLiftWellState;
48class WellInterfaceGeneric;
55 static constexpr int Water = BlackoilPhases::Aqua;
56 static constexpr int Oil = BlackoilPhases::Liquid;
57 static constexpr int Gas = BlackoilPhases::Vapour;
58 static constexpr int NUM_PHASES = 3;
59 static constexpr double ALQ_EPSILON = 1e-8;
62 using GLiftSyncGroups = std::set<int>;
63 using Rate = GasLiftGroupInfo::Rate;
68 GradInfo(
double grad_,
double new_oil_rate_,
bool oil_is_limited_,
69 double new_gas_rate_,
bool gas_is_limited_,
70 double new_water_rate_,
bool water_is_limited_,
71 double alq_,
bool alq_is_limited_) :
73 new_oil_rate{new_oil_rate_},
74 oil_is_limited{oil_is_limited_},
75 new_gas_rate{new_gas_rate_},
76 gas_is_limited{gas_is_limited_},
77 new_water_rate{new_water_rate_},
78 water_is_limited{water_is_limited_},
80 alq_is_limited{alq_is_limited_} {}
86 double new_water_rate;
87 bool water_is_limited;
94 const std::string& name()
const {
return well_name_; }
96 std::optional<GradInfo> calcIncOrDecGradient(
double oil_rate,
double gas_rate,
99 const std::string& gr_name_dont_limit,
101 bool debug_output =
true
104 std::unique_ptr<GasLiftWellState> runOptimize(
const int iteration_idx);
113 const Well& ecl_well,
114 const SummaryState& summary_state,
117 const Schedule& schedule,
118 const int report_step_idx,
119 GLiftSyncGroups& sync_groups,
120 const Parallel::Communication& comm,
131 bhp_is_limited{rates.bhp_is_limited}
133 BasicRates(
double oil_,
double gas_,
double water_,
bool bhp_is_limited_) :
137 bhp_is_limited{bhp_is_limited_}
143 bhp_is_limited = rates.bhp_is_limited;
150 double operator[](Rate rate_type)
const {
159 return this->oil + this->water;
161 throw std::runtime_error(
"This should not happen");
165 double oil, gas, water;
171 enum class LimitType {well, group, none};
173 double oil_,
double gas_,
double water_,
174 bool oil_is_limited_,
bool gas_is_limited_,
175 bool water_is_limited_,
bool bhp_is_limited_,
176 std::optional<Rate> oil_limiting_target_,
177 std::optional<Rate> water_limiting_target_
179 BasicRates(oil_, gas_, water_, bhp_is_limited_),
180 oil_is_limited{oil_is_limited_},
181 gas_is_limited{gas_is_limited_},
182 water_is_limited{water_is_limited_},
183 oil_limiting_target{oil_limiting_target_},
184 water_limiting_target{water_limiting_target_}
186 set_initial_limit_type_();
191 bool oil_is_limited_,
bool gas_is_limited_,
192 bool water_is_limited_
195 oil_is_limited{oil_is_limited_},
196 gas_is_limited{gas_is_limited_},
197 water_is_limited{water_is_limited_}
199 set_initial_limit_type_();
202 bool limited()
const {
203 return oil_is_limited || gas_is_limited || water_is_limited;
207 LimitType limit_type;
210 bool water_is_limited;
211 std::optional<Rate> oil_limiting_target;
212 std::optional<Rate> water_limiting_target;
214 void set_initial_limit_type_() {
215 limit_type = limited() ? LimitType::well : LimitType::none;
225 stop_iteration{
false},
235 std::pair<std::optional<double>,
bool> addOrSubtractAlqIncrement(
double alq);
236 double calcEcoGradient(
double oil_rate,
double new_oil_rate,
237 double gas_rate,
double new_gas_rate);
238 bool checkAlqOutsideLimits(
double alq,
double oil_rate);
239 bool checkEcoGradient(
double gradient);
240 bool checkOilRateExceedsTarget(
double oil_rate);
241 bool checkRatesViolated(
const LimitedRates& rates)
const;
242 void debugShowIterationInfo(
double alq);
243 double getBhpWithLimit();
244 void warn_(std::string msg) {parent.displayWarning_(msg);}
246 bool checkGroupALQrateExceeded(
double delta_alq,
const std::string& gr_name_dont_limit =
"")
const;
247 bool checkGroupTotalRateExceeded(
double delta_alq,
double delta_gas_rate)
const;
249 std::pair<std::optional<double>,
bool> addOrSubtractAlqIncrement_(
250 double alq,
bool increase)
const;
251 double calcEcoGradient_(
double oil_rate,
double new_oil_rate,
252 double gas_rate,
double new_gas_rate,
bool increase)
const;
253 bool checkALQequal_(
double alq1,
double alq2)
const;
254 bool checkGroupTargetsViolated(
256 bool checkInitialALQmodified_(
double alq,
double initial_alq)
const;
257 virtual bool checkThpControl_()
const = 0;
258 virtual std::optional<double> computeBhpAtThpLimit_(
double alq,
bool debug_output =
true)
const = 0;
259 std::pair<std::optional<double>,
double> computeConvergedBhpAtThpLimitByMaybeIncreasingALQ_()
const;
260 std::pair<std::optional<BasicRates>,
double> computeInitialWellRates_()
const;
261 std::optional<LimitedRates> computeLimitedWellRatesWithALQ_(
double alq)
const;
262 virtual BasicRates computeWellRates_(
double bhp,
bool bhp_is_limited,
bool debug_output =
true)
const = 0;
263 std::optional<BasicRates> computeWellRatesWithALQ_(
double alq)
const;
264 void debugCheckNegativeGradient_(
double grad,
double alq,
double new_alq,
265 double oil_rate,
double new_oil_rate,
266 double gas_rate,
double new_gas_rate,
267 bool increase)
const;
268 void debugPrintWellStateRates()
const;
269 void debugShowAlqIncreaseDecreaseCounts_();
270 void debugShowBhpAlqTable_();
271 void debugShowLimitingTargets_(
const LimitedRates& rates)
const;
272 void debugShowProducerControlMode()
const;
273 void debugShowStartIteration_(
double alq,
bool increase,
double oil_rate);
274 void debugShowTargets_();
275 void displayDebugMessage_(
const std::string& msg)
const override;
276 void displayWarning_(
const std::string& warning);
277 std::pair<double, bool> getBhpWithLimit_(
double bhp)
const;
278 std::pair<double, bool> getGasRateWithLimit_(
280 std::pair<double, bool> getGasRateWithGroupLimit_(
281 double new_gas_rate,
double gas_rate,
const std::string& gr_name_dont_limit)
const;
282 std::pair<std::optional<LimitedRates>,
double> getInitialRatesWithLimit_()
const;
284 std::tuple<double,double,bool,bool> getLiquidRateWithGroupLimit_(
285 const double new_oil_rate,
const double oil_rate,
286 const double new_water_rate,
const double water_rate,
const std::string& gr_name_dont_limit)
const;
287 std::pair<double, bool> getOilRateWithGroupLimit_(
288 double new_oil_rate,
double oil_rate,
const std::string& gr_name_dont_limit)
const;
289 std::pair<double, bool> getOilRateWithLimit_(
const BasicRates& rates)
const;
290 std::pair<double, std::optional<Rate>> getOilRateWithLimit2_(
292 double getProductionTarget_(Rate rate)
const;
293 double getRate_(Rate rate_type,
const BasicRates& rates)
const;
294 std::pair<double, std::optional<Rate>> getRateWithLimit_(
295 Rate rate_type,
const BasicRates& rates)
const;
296 std::tuple<double, const std::string*, double> getRateWithGroupLimit_(
297 Rate rate_type,
const double new_rate,
const double old_rate,
const std::string& gr_name_dont_limit)
const;
298 std::pair<double, bool> getWaterRateWithGroupLimit_(
299 double new_water_rate,
double water_rate,
const std::string& gr_name_dont_limit)
const;
300 std::pair<double, bool> getWaterRateWithLimit_(
const BasicRates& rates)
const;
301 std::pair<double, std::optional<Rate>> getWaterRateWithLimit2_(
304 bool hasProductionControl_(Rate rate)
const;
305 std::pair<LimitedRates, double> increaseALQtoPositiveOilRate_(
307 std::pair<LimitedRates, double> increaseALQtoMinALQ_(
309 void logSuccess_(
double alq,
310 const int iteration_idx);
311 std::pair<LimitedRates, double> maybeAdjustALQbeforeOptimizeLoop_(
312 const LimitedRates& rates,
double alq,
bool increase)
const;
313 std::pair<LimitedRates, double> reduceALQtoGroupAlqLimits_(
315 std::pair<LimitedRates, double> reduceALQtoGroupTarget(
317 std::pair<LimitedRates, double> reduceALQtoWellTarget_(
319 std::unique_ptr<GasLiftWellState> runOptimize1_();
320 std::unique_ptr<GasLiftWellState> runOptimize2_();
321 std::unique_ptr<GasLiftWellState> runOptimizeLoop_(
bool increase);
322 void setAlqMinRate_(
const GasLiftWell& well);
323 std::unique_ptr<GasLiftWellState> tryIncreaseLiftGas_();
324 std::unique_ptr<GasLiftWellState> tryDecreaseLiftGas_();
325 void updateGroupRates_(
328 double delta_alq)
const;
331 void updateWellStateAlqFixedValue_(
const GasLiftWell& well);
332 bool useFixedAlq_(
const GasLiftWell& well);
333 void debugInfoGroupRatesExceedTarget(
334 Rate rate_type,
const std::string& gr_name,
double rate,
double target)
const;
335 void warnMaxIterationsExceeded_();
337 const Well& ecl_well_;
338 const SummaryState& summary_state_;
341 GLiftSyncGroups& sync_groups_;
342 const WellProductionControls controls_;
359 std::string well_name_;
361 const GasLiftWell* gl_well_;
364 bool debug_limit_increase_decrease_;
365 bool debug_abort_if_decrease_and_oil_is_limited_ =
false;
366 bool debug_abort_if_increase_and_gas_is_limited_ =
false;
Definition: DeferredLogger.hpp:57
Definition: GasLiftCommon.hpp:32
Definition: GasLiftGroupInfo.hpp:50
Definition: GasLiftSingleWellGeneric.hpp:53
Definition: GroupState.hpp:34
Definition: WellInterfaceGeneric.hpp:51
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:60
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: GasLiftSingleWellGeneric.hpp:126
Definition: GasLiftSingleWellGeneric.hpp:65
Definition: GasLiftSingleWellGeneric.hpp:170
Definition: GasLiftSingleWellGeneric.hpp:220
Definition: BlackoilPhases.hpp:46