21#ifndef OPM_GASLIFT_SINGLE_WELL_HEADER_INCLUDED
22#define OPM_GASLIFT_SINGLE_WELL_IMPL_HEADER_INCLUDED
27#include <opm/input/eclipse/Schedule/GasLiftOpt.hpp>
28#include <fmt/format.h>
32template<
typename TypeTag>
35 const Simulator& simulator,
36 const SummaryState &summary_state,
41 GLiftSyncGroups &sync_groups,
55 simulator.vanguard().schedule(),
56 simulator.episodeIndex(),
61 , simulator_{simulator}
70 setAlqMaxRate_(gl_well);
74 setupPhaseVariables_();
85 this->
alpha_w_ = gl_well.weight_factor();
97 this->
alpha_g_ = gl_well.inc_weight_factor();
109template<
typename TypeTag>
114 std::vector<double> potentials(NUM_PHASES, 0.0);
115 this->well_.computeWellRatesWithBhp(
116 this->simulator_,
bhp, potentials, this->deferred_logger_);
118 const std::string msg = fmt::format(
"computed well potentials given bhp {}, "
119 "oil: {}, gas: {}, water: {}",
bhp,
120 -potentials[this->oil_pos_], -potentials[this->gas_pos_],
121 -potentials[this->water_pos_]);
122 displayDebugMessage_(msg);
125 for (
auto& potential : potentials) {
126 potential = std::min(0.0, potential);
128 return {-potentials[this->oil_pos_],
129 -potentials[this->gas_pos_],
130 -potentials[this->water_pos_],
135template<
typename TypeTag>
137GasLiftSingleWell<TypeTag>::
138computeBhpAtThpLimit_(
double alq,
bool debug_output)
const
140 auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlq(
142 this->summary_state_,
144 this->deferred_logger_);
145 if (bhp_at_thp_limit) {
146 if (*bhp_at_thp_limit < this->controls_.bhp_limit) {
147 if (debug_output && this->debug) {
148 const std::string msg = fmt::format(
149 "Computed bhp ({}) from thp limit is below bhp limit ({}), (ALQ = {})."
150 " Using bhp limit instead",
151 *bhp_at_thp_limit, this->controls_.bhp_limit, alq
153 displayDebugMessage_(msg);
155 bhp_at_thp_limit = this->controls_.bhp_limit;
160 const std::string msg = fmt::format(
161 "Failed in getting converged bhp potential from thp limit (ALQ = {})", alq);
162 displayDebugMessage_(msg);
164 return bhp_at_thp_limit;
167template<
typename TypeTag>
169GasLiftSingleWell<TypeTag>::
170setupPhaseVariables_()
172 const auto& pu = this->phase_usage_;
174 bool num_phases_ok = (pu.num_phases == 3);
176 if (pu.num_phases == 2) {
192 num_phases_ok =
true;
196 throw std::logic_error(
"Two-phase gas lift optimization only supported"
197 " for oil and water");
200 assert(num_phases_ok);
201 this->oil_pos_ = pu.phase_pos[Oil];
202 this->gas_pos_ = pu.phase_pos[Gas];
203 this->water_pos_ = pu.phase_pos[Water];
206template<
typename TypeTag>
208GasLiftSingleWell<TypeTag>::
209setAlqMaxRate_(
const GasLiftWell &well)
211 auto& max_alq_optional = well.max_rate();
212 if (max_alq_optional) {
215 this->max_alq_ = *max_alq_optional;
221 const auto& table = well_.vfpProperties()->getProd()->getTable(
222 this->controls_.vfp_table_number);
223 const auto& alq_values = table.getALQAxis();
226 this->max_alq_ = alq_values.back();
230template<
typename TypeTag>
232GasLiftSingleWell<TypeTag>::
233checkThpControl_()
const
235 const int well_index = this->well_state_.index(this->well_name_).value();
236 const Well::ProducerCMode& control_mode =
237 this->well_state_.well(well_index).production_cmode;
238 bool thp_control = control_mode == Well::ProducerCMode::THP;
239 const WellInterfaceGeneric &well = getWell();
240 thp_control = thp_control || well.thpLimitViolatedButNotSwitched();
243 displayDebugMessage_(
"Well is not under THP control, skipping iteration..");
@ Liquid
Definition: BlackoilPhases.hpp:42
@ Aqua
Definition: BlackoilPhases.hpp:42
@ Vapour
Definition: BlackoilPhases.hpp:42
Definition: DeferredLogger.hpp:57
WellState< double > & well_state_
Definition: GasLiftCommon.hpp:57
Definition: GasLiftGroupInfo.hpp:45
Definition: GasLiftSingleWellGeneric.hpp:49
double alpha_w_
Definition: GasLiftSingleWellGeneric.hpp:345
int max_iterations_
Definition: GasLiftSingleWellGeneric.hpp:353
const GasLiftWell * gl_well_
Definition: GasLiftSingleWellGeneric.hpp:357
double orig_alq_
Definition: GasLiftSingleWellGeneric.hpp:343
void setAlqMinRate_(const GasLiftWell &well)
bool optimize_
Definition: GasLiftSingleWellGeneric.hpp:359
void displayWarning_(const std::string &warning)
double alpha_g_
Definition: GasLiftSingleWellGeneric.hpp:346
bool useFixedAlq_(const GasLiftWell &well)
std::string well_name_
Definition: GasLiftSingleWellGeneric.hpp:355
void updateWellStateAlqFixedValue_(const GasLiftWell &well)
Definition: GasLiftSingleWell.hpp:38
GasLiftSingleWell(const WellInterface< TypeTag > &well, const Simulator &simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, GasLiftGroupInfo &group_info, GLiftSyncGroups &sync_groups, const Parallel::Communication &comm, bool glift_debug)
Definition: GasLiftSingleWell_impl.hpp:34
Definition: GroupState.hpp:35
Definition: WellInterface.hpp:75
Definition: WellState.hpp:62
Scalar getALQ(const std::string &name) const
Definition: WellState.hpp:175
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
VFPEvaluation bhp(const VFPProdTable &table, const double aqua, const double liquid, const double vapour, const double thp, const double alq, const double explicit_wfr, const double explicit_gfr, const bool use_vfpexplicit)
Definition: BlackoilPhases.hpp:27
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
Definition: GasLiftSingleWellGeneric.hpp:122