20#ifndef OPM_GASLIFT_SINGLE_WELL_IMPL_HEADER_INCLUDED
21#define OPM_GASLIFT_SINGLE_WELL_IMPL_HEADER_INCLUDED
24#ifndef OPM_GASLIFT_SINGLE_WELL_HEADER_INCLUDED
29#include <opm/common/TimingMacros.hpp>
31#include <opm/input/eclipse/Schedule/GasLiftOpt.hpp>
32#include <opm/input/eclipse/Schedule/Well/Well.hpp>
37#include <fmt/format.h>
41template<
typename TypeTag>
44 const Simulator& simulator,
45 const SummaryState& summary_state,
50 GLiftSyncGroups &sync_groups,
61 simulator.vanguard().schedule(),
62 simulator.episodeIndex(),
66 , simulator_{simulator}
69 const auto& gl_well = *this->
gl_well_;
75 setAlqMaxRate_(gl_well);
79 setupPhaseVariables_();
91 this->
alpha_w_ = gl_well.weight_factor();
103 this->
alpha_g_ = gl_well.inc_weight_factor();
115template<
typename TypeTag>
116typename GasLiftSingleWell<TypeTag>::RatesAndBhp
120 std::vector<Scalar> potentials(this->NUM_PHASES, 0.0);
121 this->well_.computeWellRatesWithBhp(this->simulator_,
124 this->deferred_logger_);
126 const std::string msg = fmt::format(
"computed well potentials given bhp {}, "
127 "oil: {}, gas: {}, water: {}", bhp,
128 -potentials[this->oil_pos_], -potentials[this->gas_pos_],
129 -potentials[this->water_pos_]);
130 this->displayDebugMessage_(msg);
133 std::ranges::transform(potentials, potentials.begin(),
134 [](
const auto& potential)
135 { return std::min(Scalar{0}, potential); });
136 return {-potentials[this->oil_pos_],
137 -potentials[this->gas_pos_],
138 -potentials[this->water_pos_],
144template<
typename TypeTag>
145std::optional<typename GasLiftSingleWell<TypeTag>::Scalar>
146GasLiftSingleWell<TypeTag>::
147computeBhpAtThpLimit_(Scalar alq, Scalar current_bhp,
bool debug_output)
const
153 auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlqUsingIPR(
157 this->summary_state_,
159 if (bhp_at_thp_limit) {
160 if (*bhp_at_thp_limit < this->controls_.bhp_limit) {
161 if (debug_output && this->debug) {
162 const std::string msg = fmt::format(
163 "Computed bhp ({}) from thp limit is below bhp limit ({}), (ALQ = {})."
164 " Using bhp limit instead",
165 *bhp_at_thp_limit, this->controls_.bhp_limit, alq
167 this->displayDebugMessage_(msg);
169 bhp_at_thp_limit = this->controls_.bhp_limit;
174 const std::string msg = fmt::format(
175 "Failed in getting converged bhp potential from thp limit (ALQ = {})", alq);
176 this->displayDebugMessage_(msg);
178 return bhp_at_thp_limit;
181template<
typename TypeTag>
183GasLiftSingleWell<TypeTag>::
184setupPhaseVariables_()
187 bool num_phases_ok = (FluidSystem::numActivePhases()== 3);
189 if (FluidSystem::numActivePhases()== 2) {
200 if ( FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)
201 && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
202 && !FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) )
205 num_phases_ok =
true;
209 throw std::logic_error(
"Two-phase gas lift optimization only supported"
210 " for oil and water");
213 assert(num_phases_ok);
214 this->oil_pos_ = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
215 this->water_pos_ = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
221 this->gas_pos_ = FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)
222 ?
static_cast<int>(FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx))
223 :
static_cast<int>(FluidSystem::numActivePhases());
226template<
typename TypeTag>
228GasLiftSingleWell<TypeTag>::
229setAlqMaxRate_(
const GasLiftWell& well)
231 const auto& max_alq_optional = well.max_rate();
232 if (max_alq_optional) {
235 this->max_alq_ = *max_alq_optional;
241 const auto& table = well_.vfpProperties()->getProd()->getTable(
242 this->controls_.vfp_table_number);
243 const auto& alq_values = table.getALQAxis();
246 this->max_alq_ = alq_values.back();
250template<
typename TypeTag>
252GasLiftSingleWell<TypeTag>::
253checkThpControl_()
const
255 const int well_index = this->well_state_.index(this->well_name_).value();
256 const Well::ProducerCMode& control_mode =
257 this->well_state_.well(well_index).production_cmode;
258 bool thp_control = control_mode == Well::ProducerCMode::THP;
259 const auto& well = getWell();
260 thp_control = thp_control || well.thpLimitViolatedButNotSwitched();
263 this->displayDebugMessage_(
"Well is not under THP control, skipping iteration..");
Definition: DeferredLogger.hpp:57
WellState< GetPropType< TypeTag, Properties::Scalar >, GetPropType< TypeTag, Properties::FluidSystem >::IndexTraitsType > & well_state_
Definition: GasLiftCommon.hpp:54
Definition: GasLiftGroupInfo.hpp:47
Definition: GasLiftSingleWellGeneric.hpp:48
GetPropType< TypeTag, Properties::Scalar > alpha_w_
Definition: GasLiftSingleWellGeneric.hpp:448
void updateWellStateAlqFixedValue_(const GasLiftWell &well)
std::string well_name_
Definition: GasLiftSingleWellGeneric.hpp:458
int max_iterations_
Definition: GasLiftSingleWellGeneric.hpp:456
void displayWarning_(const std::string &warning)
bool optimize_
Definition: GasLiftSingleWellGeneric.hpp:462
GetPropType< TypeTag, Properties::Scalar > orig_alq_
Definition: GasLiftSingleWellGeneric.hpp:439
const GasLiftWell * gl_well_
Definition: GasLiftSingleWellGeneric.hpp:460
bool useFixedAlq_(const GasLiftWell &well)
GetPropType< TypeTag, Properties::Scalar > alpha_g_
Definition: GasLiftSingleWellGeneric.hpp:449
void setAlqMinRate_(const GasLiftWell &well)
Definition: GasLiftSingleWell.hpp:39
GasLiftSingleWell(WellInterface< TypeTag > &well, const Simulator &simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger, WellState< Scalar, IndexTraits > &well_state, const GroupState< Scalar > &group_state, GasLiftGroupInfo< Scalar, IndexTraits > &group_info, GLiftSyncGroups &sync_groups, const Parallel::Communication &comm, bool glift_debug)
Definition: GasLiftSingleWell_impl.hpp:43
Definition: GroupState.hpp:42
ALQState< Scalar > alq_state
Definition: SingleWellState.hpp:181
Definition: WellInterface.hpp:79
Definition: WellState.hpp:68
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:315
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45