20#include <opm/input/eclipse/Schedule/GasLiftOpt.hpp>
21#include <fmt/format.h>
25template<
typename TypeTag>
26GasLiftSingleWell<TypeTag>::
27GasLiftSingleWell(
const WellInterface<TypeTag> &well,
28 const Simulator &ebos_simulator,
29 const SummaryState &summary_state,
30 DeferredLogger &deferred_logger,
31 WellState &well_state,
32 const GroupState &group_state,
33 GasLiftGroupInfo &group_info,
34 GLiftSyncGroups &sync_groups,
35 const Parallel::Communication& comm,
40 : GasLiftSingleWellGeneric(
48 ebos_simulator.vanguard().schedule(),
49 ebos_simulator.episodeIndex(),
54 , ebos_simulator_{ebos_simulator}
57 const auto& gl_well = *gl_well_;
58 if(useFixedAlq_(gl_well)) {
59 updateWellStateAlqFixedValue_(gl_well);
60 this->optimize_ =
false;
63 setAlqMaxRate_(gl_well);
64 this->optimize_ =
true;
67 setupPhaseVariables_();
72 this->orig_alq_ = this->well_state_.getALQ(this->well_name_);
74 setAlqMinRate_(gl_well);
78 this->alpha_w_ = gl_well.weight_factor();
79 if (this->alpha_w_ <= 0 ) {
80 displayWarning_(
"Nonpositive value for alpha_w ignored");
90 this->alpha_g_ = gl_well.inc_weight_factor();
94 this->max_iterations_ = 1000;
102template<
typename TypeTag>
103GasLiftSingleWellGeneric::BasicRates
104GasLiftSingleWell<TypeTag>::
105computeWellRates_(
double bhp,
bool bhp_is_limited,
bool debug_output )
const
107 std::vector<double> potentials(NUM_PHASES, 0.0);
108 this->well_.computeWellRatesWithBhp(
109 this->ebos_simulator_, bhp, potentials, this->deferred_logger_);
111 const std::string msg = fmt::format(
"computed well potentials given bhp {}, "
112 "oil: {}, gas: {}, water: {}", bhp,
113 -potentials[this->oil_pos_], -potentials[this->gas_pos_],
114 -potentials[this->water_pos_]);
115 displayDebugMessage_(msg);
118 for (
auto& potential : potentials) {
119 potential = std::min(0.0, potential);
121 return {-potentials[this->oil_pos_],
122 -potentials[this->gas_pos_],
123 -potentials[this->water_pos_],
128template<
typename TypeTag>
130GasLiftSingleWell<TypeTag>::
131computeBhpAtThpLimit_(
double alq,
bool debug_output)
const
133 auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlq(
134 this->ebos_simulator_,
135 this->summary_state_,
137 this->deferred_logger_);
138 if (bhp_at_thp_limit) {
139 if (*bhp_at_thp_limit < this->controls_.bhp_limit) {
140 if (debug_output && this->debug) {
141 const std::string msg = fmt::format(
142 "Computed bhp ({}) from thp limit is below bhp limit ({}), (ALQ = {})."
143 " Using bhp limit instead",
144 *bhp_at_thp_limit, this->controls_.bhp_limit, alq
146 displayDebugMessage_(msg);
148 bhp_at_thp_limit = this->controls_.bhp_limit;
153 const std::string msg = fmt::format(
154 "Failed in getting converged bhp potential from thp limit (ALQ = {})", alq);
155 displayDebugMessage_(msg);
157 return bhp_at_thp_limit;
160template<
typename TypeTag>
162GasLiftSingleWell<TypeTag>::
163setupPhaseVariables_()
165 const auto& pu = this->phase_usage_;
167 bool num_phases_ok = (pu.num_phases == 3);
169 if (pu.num_phases == 2) {
180 if ( pu.phase_used[BlackoilPhases::Aqua] == 1
181 && pu.phase_used[BlackoilPhases::Liquid] == 1
182 && pu.phase_used[BlackoilPhases::Vapour] == 0)
185 num_phases_ok =
true;
189 throw std::logic_error(
"Two-phase gas lift optimization only supported"
190 " for oil and water");
193 assert(num_phases_ok);
194 this->oil_pos_ = pu.phase_pos[Oil];
195 this->gas_pos_ = pu.phase_pos[Gas];
196 this->water_pos_ = pu.phase_pos[Water];
199template<
typename TypeTag>
201GasLiftSingleWell<TypeTag>::
202setAlqMaxRate_(
const GasLiftWell &well)
204 auto& max_alq_optional = well.max_rate();
205 if (max_alq_optional) {
208 this->max_alq_ = *max_alq_optional;
214 const auto& table = well_.vfpProperties()->getProd()->getTable(
215 this->controls_.vfp_table_number);
216 const auto& alq_values = table.getALQAxis();
219 this->max_alq_ = alq_values.back();
223template<
typename TypeTag>
225GasLiftSingleWell<TypeTag>::
226checkThpControl_()
const
228 const int well_index = this->well_state_.index(this->well_name_).value();
229 const Well::ProducerCMode& control_mode =
230 this->well_state_.well(well_index).production_cmode;
231 bool thp_control = control_mode == Well::ProducerCMode::THP;
232 const WellInterfaceGeneric &well = getWell();
233 thp_control = thp_control || well.thpLimitViolatedButNotSwitched();
236 displayDebugMessage_(
"Well is not under THP control, skipping iteration..");
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
Definition: phaseUsageFromDeck.cpp:37