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/GasLiftOpt.hpp>
29#include <opm/input/eclipse/Schedule/Well/Well.hpp>
30#include <opm/simulators/wells/GasLiftGroupInfo.hpp>
31#include <opm/simulators/wells/GasLiftCommon.hpp>
44class GasLiftWellState;
47class WellInterfaceGeneric;
54 static constexpr int Water = BlackoilPhases::Aqua;
55 static constexpr int Oil = BlackoilPhases::Liquid;
56 static constexpr int Gas = BlackoilPhases::Vapour;
57 static constexpr int NUM_PHASES = 3;
58 static constexpr double ALQ_EPSILON = 1e-8;
61 using GLiftSyncGroups = std::set<int>;
62 using Rate = GasLiftGroupInfo::Rate;
67 GradInfo(
double grad_,
double new_oil_rate_,
bool oil_is_limited_,
68 double new_gas_rate_,
bool gas_is_limited_,
69 double new_water_rate_,
bool water_is_limited_,
70 double alq_,
bool alq_is_limited_) :
72 new_oil_rate{new_oil_rate_},
73 oil_is_limited{oil_is_limited_},
74 new_gas_rate{new_gas_rate_},
75 gas_is_limited{gas_is_limited_},
76 new_water_rate{new_water_rate_},
77 water_is_limited{water_is_limited_},
79 alq_is_limited{alq_is_limited_} {}
85 double new_water_rate;
86 bool water_is_limited;
93 const std::string& name()
const {
return well_name_; }
95 std::optional<GradInfo> calcIncOrDecGradient(
double oil_rate,
double gas_rate,
96 double alq,
bool increase)
const;
98 std::unique_ptr<GasLiftWellState> runOptimize(
const int iteration_idx);
107 const Well& ecl_well,
108 const SummaryState& summary_state,
111 const Schedule& schedule,
112 const int report_step_idx,
113 GLiftSyncGroups& sync_groups,
114 const Parallel::Communication& comm,
125 bhp_is_limited{rates.bhp_is_limited}
127 BasicRates(
double oil_,
double gas_,
double water_,
bool bhp_is_limited_) :
131 bhp_is_limited{bhp_is_limited_}
137 bhp_is_limited = rates.bhp_is_limited;
144 double operator[](Rate rate_type)
const {
153 return this->oil + this->water;
155 throw std::runtime_error(
"This should not happen");
159 double oil, gas, water;
165 enum class LimitType {well, group, none};
167 double oil_,
double gas_,
double water_,
168 bool oil_is_limited_,
bool gas_is_limited_,
169 bool water_is_limited_,
bool bhp_is_limited_,
170 std::optional<Rate> oil_limiting_target_,
171 std::optional<Rate> water_limiting_target_
173 BasicRates(oil_, gas_, water_, bhp_is_limited_),
174 oil_is_limited{oil_is_limited_},
175 gas_is_limited{gas_is_limited_},
176 water_is_limited{water_is_limited_},
177 oil_limiting_target{oil_limiting_target_},
178 water_limiting_target{water_limiting_target_}
180 set_initial_limit_type_();
185 bool oil_is_limited_,
bool gas_is_limited_,
186 bool water_is_limited_
189 oil_is_limited{oil_is_limited_},
190 gas_is_limited{gas_is_limited_},
191 water_is_limited{water_is_limited_}
193 set_initial_limit_type_();
196 bool limited()
const {
197 return oil_is_limited || gas_is_limited || water_is_limited;
201 LimitType limit_type;
204 bool water_is_limited;
205 std::optional<Rate> oil_limiting_target;
206 std::optional<Rate> water_limiting_target;
208 void set_initial_limit_type_() {
209 limit_type = limited() ? LimitType::well : LimitType::none;
219 stop_iteration{
false},
229 std::pair<std::optional<double>,
bool> addOrSubtractAlqIncrement(
double alq);
230 double calcEcoGradient(
double oil_rate,
double new_oil_rate,
231 double gas_rate,
double new_gas_rate);
232 bool checkAlqOutsideLimits(
double alq,
double oil_rate);
233 bool checkEcoGradient(
double gradient);
234 bool checkOilRateExceedsTarget(
double oil_rate);
235 bool checkRatesViolated(
const LimitedRates& rates)
const;
236 void debugShowIterationInfo(
double alq);
237 double getBhpWithLimit();
238 void warn_(std::string msg) {parent.displayWarning_(msg);}
240 bool checkGroupALQrateExceeded(
double delta_alq)
const;
241 bool checkGroupTotalRateExceeded(
double delta_alq,
double delta_gas_rate)
const;
243 std::pair<std::optional<double>,
bool> addOrSubtractAlqIncrement_(
244 double alq,
bool increase)
const;
245 double calcEcoGradient_(
double oil_rate,
double new_oil_rate,
246 double gas_rate,
double new_gas_rate,
bool increase)
const;
247 bool checkALQequal_(
double alq1,
double alq2)
const;
248 bool checkGroupTargetsViolated(
250 bool checkInitialALQmodified_(
double alq,
double initial_alq)
const;
251 virtual bool checkThpControl_()
const = 0;
252 virtual std::optional<double> computeBhpAtThpLimit_(
double alq)
const = 0;
253 std::pair<std::optional<double>,
double> computeConvergedBhpAtThpLimitByMaybeIncreasingALQ_()
const;
254 std::pair<std::optional<BasicRates>,
double> computeInitialWellRates_()
const;
255 std::optional<LimitedRates> computeLimitedWellRatesWithALQ_(
double alq)
const;
256 virtual BasicRates computeWellRates_(
double bhp,
bool bhp_is_limited,
bool debug_output =
true)
const = 0;
257 std::optional<BasicRates> computeWellRatesWithALQ_(
double alq)
const;
258 void debugCheckNegativeGradient_(
double grad,
double alq,
double new_alq,
259 double oil_rate,
double new_oil_rate,
260 double gas_rate,
double new_gas_rate,
261 bool increase)
const;
262 void debugPrintWellStateRates()
const;
263 void debugShowAlqIncreaseDecreaseCounts_();
264 void debugShowBhpAlqTable_();
265 void debugShowLimitingTargets_(
const LimitedRates& rates)
const;
266 void debugShowProducerControlMode()
const;
267 void debugShowStartIteration_(
double alq,
bool increase,
double oil_rate);
268 void debugShowTargets_();
269 void displayDebugMessage_(
const std::string& msg)
const override;
270 void displayWarning_(
const std::string& warning);
271 std::pair<double, bool> getBhpWithLimit_(
double bhp)
const;
272 std::pair<double, bool> getGasRateWithLimit_(
274 std::pair<double, bool> getGasRateWithGroupLimit_(
275 double new_gas_rate,
double gas_rate)
const;
276 std::pair<std::optional<LimitedRates>,
double> getInitialRatesWithLimit_()
const;
278 std::tuple<double,double,bool,bool> getLiquidRateWithGroupLimit_(
279 const double new_oil_rate,
const double oil_rate,
280 const double new_water_rate,
const double water_rate)
const;
281 std::pair<double, bool> getOilRateWithGroupLimit_(
282 double new_oil_rate,
double oil_rate)
const;
283 std::pair<double, bool> getOilRateWithLimit_(
const BasicRates& rates)
const;
284 std::pair<double, std::optional<Rate>> getOilRateWithLimit2_(
286 double getProductionTarget_(Rate rate)
const;
287 double getRate_(Rate rate_type,
const BasicRates& rates)
const;
288 std::pair<double, std::optional<Rate>> getRateWithLimit_(
289 Rate rate_type,
const BasicRates& rates)
const;
290 std::tuple<double, const std::string*, double> getRateWithGroupLimit_(
291 Rate rate_type,
const double new_rate,
const double old_rate)
const;
292 std::pair<double, bool> getWaterRateWithGroupLimit_(
293 double new_water_rate,
double water_rate)
const;
294 std::pair<double, bool> getWaterRateWithLimit_(
const BasicRates& rates)
const;
295 std::pair<double, std::optional<Rate>> getWaterRateWithLimit2_(
298 bool hasProductionControl_(Rate rate)
const;
299 std::pair<LimitedRates, double> increaseALQtoPositiveOilRate_(
301 std::pair<LimitedRates, double> increaseALQtoMinALQ_(
303 void logSuccess_(
double alq,
304 const int iteration_idx);
305 std::pair<LimitedRates, double> maybeAdjustALQbeforeOptimizeLoop_(
306 const LimitedRates& rates,
double alq,
bool increase)
const;
307 std::pair<LimitedRates, double> reduceALQtoGroupAlqLimits_(
309 std::pair<LimitedRates, double> reduceALQtoGroupTarget(
311 std::pair<LimitedRates, double> reduceALQtoWellTarget_(
313 std::unique_ptr<GasLiftWellState> runOptimize1_();
314 std::unique_ptr<GasLiftWellState> runOptimize2_();
315 std::unique_ptr<GasLiftWellState> runOptimizeLoop_(
bool increase);
316 void setAlqMinRate_(
const GasLiftOpt::Well& well);
317 std::unique_ptr<GasLiftWellState> tryIncreaseLiftGas_();
318 std::unique_ptr<GasLiftWellState> tryDecreaseLiftGas_();
319 void updateGroupRates_(
322 double delta_alq)
const;
325 void updateWellStateAlqFixedValue_(
const GasLiftOpt::Well& well);
326 bool useFixedAlq_(
const GasLiftOpt::Well& well);
327 void debugInfoGroupRatesExceedTarget(
328 Rate rate_type,
const std::string& gr_name,
double rate,
double target)
const;
329 void warnMaxIterationsExceeded_();
332 const Well& ecl_well_;
333 const SummaryState& summary_state_;
336 GLiftSyncGroups& sync_groups_;
337 const Well::ProductionControls controls_;
354 std::string well_name_;
356 const GasLiftOpt::Well* gl_well_;
359 bool debug_limit_increase_decrease_;
360 bool debug_abort_if_decrease_and_oil_is_limited_ =
false;
361 bool debug_abort_if_increase_and_gas_is_limited_ =
false;
Definition: DeferredLogger.hpp:57
Definition: GasLiftCommon.hpp:32
Definition: GasLiftGroupInfo.hpp:47
Definition: GasLiftSingleWellGeneric.hpp:52
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:56
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: GasLiftSingleWellGeneric.hpp:120
Definition: GasLiftSingleWellGeneric.hpp:64
Definition: GasLiftSingleWellGeneric.hpp:164
Definition: GasLiftSingleWellGeneric.hpp:214
Definition: BlackoilPhases.hpp:46