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>
35template<
typename TypeTag>
38 const Simulator& simulator,
39 const SummaryState& summary_state,
44 GLiftSyncGroups &sync_groups,
56 simulator.vanguard().schedule(),
57 simulator.episodeIndex(),
61 , simulator_{simulator}
64 const auto& gl_well = *this->
gl_well_;
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>
110typename GasLiftSingleWell<TypeTag>::BasicRates
114 std::vector<Scalar> potentials(this->NUM_PHASES, 0.0);
115 this->well_.computeWellRatesWithBhp(this->simulator_,
118 this->deferred_logger_);
120 const std::string msg = fmt::format(
"computed well potentials given bhp {}, "
121 "oil: {}, gas: {}, water: {}", bhp,
122 -potentials[this->oil_pos_], -potentials[this->gas_pos_],
123 -potentials[this->water_pos_]);
124 this->displayDebugMessage_(msg);
127 for (
auto& potential : potentials) {
128 potential = std::min(Scalar{0.0}, potential);
130 return {-potentials[this->oil_pos_],
131 -potentials[this->gas_pos_],
132 -potentials[this->water_pos_],
137template<
typename TypeTag>
138std::optional<typename GasLiftSingleWell<TypeTag>::Scalar>
139GasLiftSingleWell<TypeTag>::
140computeBhpAtThpLimit_(Scalar alq,
bool debug_output)
const
142 auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlq(
144 this->summary_state_,
146 this->deferred_logger_);
147 if (bhp_at_thp_limit) {
148 if (*bhp_at_thp_limit < this->controls_.bhp_limit) {
149 if (debug_output && this->debug) {
150 const std::string msg = fmt::format(
151 "Computed bhp ({}) from thp limit is below bhp limit ({}), (ALQ = {})."
152 " Using bhp limit instead",
153 *bhp_at_thp_limit, this->controls_.bhp_limit, alq
155 this->displayDebugMessage_(msg);
157 bhp_at_thp_limit = this->controls_.bhp_limit;
162 const std::string msg = fmt::format(
163 "Failed in getting converged bhp potential from thp limit (ALQ = {})", alq);
164 this->displayDebugMessage_(msg);
166 return bhp_at_thp_limit;
169template<
typename TypeTag>
171GasLiftSingleWell<TypeTag>::
172setupPhaseVariables_()
174 const auto& pu = this->phase_usage_;
176 bool num_phases_ok = (pu.num_phases == 3);
178 if (pu.num_phases == 2) {
194 num_phases_ok =
true;
198 throw std::logic_error(
"Two-phase gas lift optimization only supported"
199 " for oil and water");
202 assert(num_phases_ok);
203 this->oil_pos_ = pu.phase_pos[this->Oil];
204 this->gas_pos_ = pu.phase_pos[this->Gas];
205 this->water_pos_ = pu.phase_pos[this->Water];
208template<
typename TypeTag>
210GasLiftSingleWell<TypeTag>::
211setAlqMaxRate_(
const GasLiftWell& well)
213 auto& max_alq_optional = well.max_rate();
214 if (max_alq_optional) {
217 this->max_alq_ = *max_alq_optional;
223 const auto& table = well_.vfpProperties()->getProd()->getTable(
224 this->controls_.vfp_table_number);
225 const auto& alq_values = table.getALQAxis();
228 this->max_alq_ = alq_values.back();
232template<
typename TypeTag>
234GasLiftSingleWell<TypeTag>::
235checkThpControl_()
const
237 const int well_index = this->well_state_.index(this->well_name_).value();
238 const Well::ProducerCMode& control_mode =
239 this->well_state_.well(well_index).production_cmode;
240 bool thp_control = control_mode == Well::ProducerCMode::THP;
241 const auto& well = getWell();
242 thp_control = thp_control || well.thpLimitViolatedButNotSwitched();
245 this->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< GetPropType< TypeTag, Properties::Scalar > > & well_state_
Definition: GasLiftCommon.hpp:55
Definition: GasLiftGroupInfo.hpp:46
Definition: GasLiftSingleWellGeneric.hpp:50
bool optimize_
Definition: GasLiftSingleWellGeneric.hpp:454
std::string well_name_
Definition: GasLiftSingleWellGeneric.hpp:450
GetPropType< TypeTag, Properties::Scalar > alpha_w_
Definition: GasLiftSingleWellGeneric.hpp:440
GetPropType< TypeTag, Properties::Scalar > alpha_g_
Definition: GasLiftSingleWellGeneric.hpp:441
void displayWarning_(const std::string &warning)
GetPropType< TypeTag, Properties::Scalar > orig_alq_
Definition: GasLiftSingleWellGeneric.hpp:438
bool useFixedAlq_(const GasLiftWell &well)
void updateWellStateAlqFixedValue_(const GasLiftWell &well)
void setAlqMinRate_(const GasLiftWell &well)
int max_iterations_
Definition: GasLiftSingleWellGeneric.hpp:448
const GasLiftWell * gl_well_
Definition: GasLiftSingleWellGeneric.hpp:452
Definition: GasLiftSingleWell.hpp:36
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< Scalar > &group_info, GLiftSyncGroups &sync_groups, const Parallel::Communication &comm, bool glift_debug)
Definition: GasLiftSingleWell_impl.hpp:37
Definition: GroupState.hpp:38
Definition: WellInterface.hpp:73
Definition: WellState.hpp:62
Scalar getALQ(const std::string &name) const
Definition: WellState.hpp:181
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:37
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.