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_();
90 this->
alpha_w_ = gl_well.weight_factor();
102 this->
alpha_g_ = gl_well.inc_weight_factor();
114template<
typename TypeTag>
115typename GasLiftSingleWell<TypeTag>::BasicRates
119 std::vector<Scalar> potentials(this->NUM_PHASES, 0.0);
120 this->well_.computeWellRatesWithBhp(this->simulator_,
123 this->deferred_logger_);
125 const std::string msg = fmt::format(
"computed well potentials given bhp {}, "
126 "oil: {}, gas: {}, water: {}", bhp,
127 -potentials[this->oil_pos_], -potentials[this->gas_pos_],
128 -potentials[this->water_pos_]);
129 this->displayDebugMessage_(msg);
132 std::transform(potentials.begin(), potentials.end(),
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_],
143template<
typename TypeTag>
144std::optional<typename GasLiftSingleWell<TypeTag>::Scalar>
145GasLiftSingleWell<TypeTag>::
146computeBhpAtThpLimit_(Scalar alq,
bool debug_output)
const
149 const auto& wgHelper = this->simulator_.problem().wellModel().wgHelper();
150 auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlq(
153 this->summary_state_,
155 this->deferred_logger_,
157 if (bhp_at_thp_limit) {
158 if (*bhp_at_thp_limit < this->controls_.bhp_limit) {
159 if (debug_output && this->debug) {
160 const std::string msg = fmt::format(
161 "Computed bhp ({}) from thp limit is below bhp limit ({}), (ALQ = {})."
162 " Using bhp limit instead",
163 *bhp_at_thp_limit, this->controls_.bhp_limit, alq
165 this->displayDebugMessage_(msg);
167 bhp_at_thp_limit = this->controls_.bhp_limit;
172 const std::string msg = fmt::format(
173 "Failed in getting converged bhp potential from thp limit (ALQ = {})", alq);
174 this->displayDebugMessage_(msg);
176 return bhp_at_thp_limit;
179template<
typename TypeTag>
181GasLiftSingleWell<TypeTag>::
182setupPhaseVariables_()
185 bool num_phases_ok = (FluidSystem::numActivePhases()== 3);
187 if (FluidSystem::numActivePhases()== 2) {
198 if ( FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)
199 && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
200 && !FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) )
203 num_phases_ok =
true;
207 throw std::logic_error(
"Two-phase gas lift optimization only supported"
208 " for oil and water");
211 assert(num_phases_ok);
212 this->oil_pos_ = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
213 this->gas_pos_ = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
214 this->water_pos_ = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
217template<
typename TypeTag>
219GasLiftSingleWell<TypeTag>::
220setAlqMaxRate_(
const GasLiftWell& well)
222 const auto& max_alq_optional = well.max_rate();
223 if (max_alq_optional) {
226 this->max_alq_ = *max_alq_optional;
232 const auto& table = well_.vfpProperties()->getProd()->getTable(
233 this->controls_.vfp_table_number);
234 const auto& alq_values = table.getALQAxis();
237 this->max_alq_ = alq_values.back();
241template<
typename TypeTag>
243GasLiftSingleWell<TypeTag>::
244checkThpControl_()
const
246 const int well_index = this->well_state_.index(this->well_name_).value();
247 const Well::ProducerCMode& control_mode =
248 this->well_state_.well(well_index).production_cmode;
249 bool thp_control = control_mode == Well::ProducerCMode::THP;
250 const auto& well = getWell();
251 thp_control = thp_control || well.thpLimitViolatedButNotSwitched();
254 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:46
Definition: GasLiftSingleWellGeneric.hpp:48
GetPropType< TypeTag, Properties::Scalar > alpha_w_
Definition: GasLiftSingleWellGeneric.hpp:436
void updateWellStateAlqFixedValue_(const GasLiftWell &well)
std::string well_name_
Definition: GasLiftSingleWellGeneric.hpp:446
int max_iterations_
Definition: GasLiftSingleWellGeneric.hpp:444
void displayWarning_(const std::string &warning)
bool optimize_
Definition: GasLiftSingleWellGeneric.hpp:450
GetPropType< TypeTag, Properties::Scalar > orig_alq_
Definition: GasLiftSingleWellGeneric.hpp:434
const GasLiftWell * gl_well_
Definition: GasLiftSingleWellGeneric.hpp:448
bool useFixedAlq_(const GasLiftWell &well)
GetPropType< TypeTag, Properties::Scalar > alpha_g_
Definition: GasLiftSingleWellGeneric.hpp:437
void setAlqMinRate_(const GasLiftWell &well)
Definition: GasLiftSingleWell.hpp:39
GasLiftSingleWell(const 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:41
ALQState< Scalar > alq_state
Definition: SingleWellState.hpp:133
Definition: WellInterface.hpp:77
Definition: WellState.hpp:66
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:290
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:43