Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions opm/simulators/wells/GasLiftSingleWell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class GasLiftSingleWell : public GasLiftSingleWellGeneric<GetPropType<TypeTag, P
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
using IndexTraits = typename FluidSystem::IndexTraitsType;
using GLiftSyncGroups = typename GasLiftSingleWellGeneric<Scalar, IndexTraits>::GLiftSyncGroups;
using BasicRates = typename GasLiftSingleWellGeneric<Scalar, IndexTraits>::BasicRates;
using RatesAndBhp = typename GasLiftSingleWellGeneric<Scalar, IndexTraits>::RatesAndBhp;

public:
GasLiftSingleWell(const WellInterface<TypeTag>& well,
GasLiftSingleWell(WellInterface<TypeTag>& well,
const Simulator& simulator,
const SummaryState& summary_state,
DeferredLogger& deferred_logger,
Expand All @@ -61,9 +61,10 @@ class GasLiftSingleWell : public GasLiftSingleWellGeneric<GetPropType<TypeTag, P
private:
std::optional<Scalar>
computeBhpAtThpLimit_(Scalar alq,
Scalar bhp,
bool debug_ouput = true) const override;

BasicRates computeWellRates_(Scalar bhp,
RatesAndBhp computeWellRates_(Scalar bhp,
bool bhp_is_limited,
bool debug_output = true) const override;

Expand All @@ -72,7 +73,7 @@ class GasLiftSingleWell : public GasLiftSingleWellGeneric<GetPropType<TypeTag, P
bool checkThpControl_() const override;

const Simulator& simulator_;
const WellInterface<TypeTag>& well_;
WellInterface<TypeTag>& well_;
};

} // namespace Opm
Expand Down
182 changes: 95 additions & 87 deletions opm/simulators/wells/GasLiftSingleWellGeneric.cpp

Large diffs are not rendered by default.

105 changes: 55 additions & 50 deletions opm/simulators/wells/GasLiftSingleWellGeneric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
Scalar new_water_pot_,
bool water_is_limited_,
Scalar alq_,
bool alq_is_limited_)
bool alq_is_limited_,
Scalar bhp_)
: grad{grad_}
, new_oil_rate{new_oil_rate_}
, new_oil_pot{new_oil_pot_}
Expand All @@ -85,6 +86,7 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
, water_is_limited{water_is_limited_}
, alq{alq_}
, alq_is_limited{alq_is_limited_}
, bhp{bhp_}
{}

Scalar grad;
Expand All @@ -99,14 +101,12 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
bool water_is_limited;
Scalar alq;
bool alq_is_limited;
Scalar bhp;
};

const std::string& name() const { return well_name_; }

std::optional<GradInfo> calcIncOrDecGradient(Scalar oil_rate,
Scalar gas_rate,
Scalar water_rate,
Scalar alq,
std::optional<GradInfo> calcIncOrDecGradient(const GasLiftWellState<Scalar>& state,
const std::string& gr_name_dont_limit,
bool increase,
bool debug_output = true) const;
Expand All @@ -130,39 +130,43 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
const Parallel::Communication& comm,
bool glift_debug);

struct LimitedRates;
struct BasicRates
struct LimitedRatesAndBhp;
struct RatesAndBhp
{
BasicRates(const BasicRates& rates) :
RatesAndBhp(const RatesAndBhp& rates) :
oil{rates.oil},
gas{rates.gas},
water{rates.water},
bhp{rates.bhp},
bhp_is_limited{rates.bhp_is_limited}
{}

BasicRates(Scalar oil_,
RatesAndBhp(Scalar oil_,
Scalar gas_,
Scalar water_,
Scalar bhp_,
bool bhp_is_limited_)
: oil{oil_}
, gas{gas_}
, water{water_}
, bhp{bhp_}
, bhp_is_limited{bhp_is_limited_}
{}

BasicRates& operator=(const BasicRates& rates)
RatesAndBhp& operator=(const RatesAndBhp& rates)
{
oil = rates.oil;
gas = rates.gas;
water = rates.water;
bhp = rates.bhp;
bhp_is_limited = rates.bhp_is_limited;
return *this;
}

// This copy constructor cannot be defined inline here since LimitedRates
// This copy constructor cannot be defined inline here since LimitedRatesAndBhp
// has not been defined yet (it is defined below). Instead it is defined in
// in the .cpp file
explicit BasicRates(const LimitedRates& rates);
explicit RatesAndBhp(const LimitedRatesAndBhp& rates);

Scalar operator[](Rate rate_type) const
{
Expand All @@ -180,24 +184,25 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
}
}

Scalar oil, gas, water;
Scalar oil, gas, water, bhp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to earlier comment about the name BasicRates and including bhp as a member.

bool bhp_is_limited;
};

struct LimitedRates : public BasicRates
struct LimitedRatesAndBhp : public RatesAndBhp
{
enum class LimitType {well, group, none};
LimitedRates(Scalar oil_,
LimitedRatesAndBhp(Scalar oil_,
Scalar oil_pot_,
Scalar gas_,
Scalar gas_pot_,
Scalar water_,
Scalar water_pot_,
Scalar bhp_,
bool oil_is_limited_,
bool gas_is_limited_,
bool water_is_limited_,
bool bhp_is_limited_)
: BasicRates(oil_, gas_, water_, bhp_is_limited_)
: RatesAndBhp(oil_, gas_, water_, bhp_, bhp_is_limited_)
, oil_pot(oil_pot_)
, gas_pot(gas_pot_)
, water_pot(water_pot_)
Expand All @@ -208,14 +213,14 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
set_initial_limit_type_();
}

LimitedRates(const BasicRates& rates,
LimitedRatesAndBhp(const RatesAndBhp& rates,
Scalar oil_pot_,
Scalar gas_pot_,
Scalar water_pot_,
bool oil_is_limited_,
bool gas_is_limited_,
bool water_is_limited_)
: BasicRates(rates)
: RatesAndBhp(rates)
, oil_pot(oil_pot_)
, gas_pot(gas_pot_)
, water_pot(water_pot_)
Expand Down Expand Up @@ -273,7 +278,7 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
bool checkAlqOutsideLimits(Scalar alq, Scalar oil_rate);
bool checkEcoGradient(Scalar gradient);
bool checkOilRateExceedsTarget(Scalar oil_rate);
bool checkRatesViolated(const LimitedRates& rates) const;
bool checkRatesViolated(const LimitedRatesAndBhp& rates) const;

void debugShowIterationInfo(Scalar alq);

Expand All @@ -296,28 +301,28 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>

bool checkALQequal_(Scalar alq1, Scalar alq2) const;

bool checkGroupTargetsViolated(const BasicRates& rates,
const BasicRates& new_rates) const;
bool checkGroupTargetsViolated(const RatesAndBhp& rates,
const RatesAndBhp& new_rates) const;
bool checkInitialALQmodified_(Scalar alq, Scalar initial_alq) const;

virtual bool checkThpControl_() const = 0;
virtual std::optional<Scalar > computeBhpAtThpLimit_(Scalar alq,
virtual std::optional<Scalar > computeBhpAtThpLimit_(Scalar alq, Scalar current_bhp,
bool debug_output = true) const = 0;

std::pair<std::optional<Scalar>,Scalar>
computeConvergedBhpAtThpLimitByMaybeIncreasingALQ_() const;

std::pair<std::optional<BasicRates>,Scalar>
std::pair<std::optional<RatesAndBhp>,Scalar>
computeInitialWellRates_() const;

std::optional<LimitedRates>
computeLimitedWellRatesWithALQ_(Scalar alq) const;
std::optional<LimitedRatesAndBhp>
computeLimitedWellRatesWithALQ_(Scalar alq, Scalar bhp) const;

virtual BasicRates computeWellRates_(Scalar bhp,
virtual RatesAndBhp computeWellRates_(Scalar bhp,
bool bhp_is_limited,
bool debug_output = true) const = 0;

std::optional<BasicRates> computeWellRatesWithALQ_(Scalar alq) const;
std::optional<RatesAndBhp> computeWellRatesWithALQ_(Scalar alq, Scalar bhp) const;

void debugCheckNegativeGradient_(Scalar grad, Scalar alq, Scalar new_alq,
Scalar oil_rate, Scalar new_oil_rate,
Expand All @@ -327,7 +332,7 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
void debugPrintWellStateRates() const;
void debugShowAlqIncreaseDecreaseCounts_();
void debugShowBhpAlqTable_();
void debugShowLimitingTargets_(const LimitedRates& rates) const;
void debugShowLimitingTargets_(const LimitedRatesAndBhp& rates) const;
void debugShowProducerControlMode() const;
void debugShowStartIteration_(Scalar alq, bool increase, Scalar oil_rate);
void debugShowTargets_();
Expand All @@ -339,54 +344,54 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
Scalar gas_rate,
const std::string& gr_name_dont_limit) const;

std::pair<std::optional<LimitedRates>,Scalar >
std::pair<std::optional<LimitedRatesAndBhp>,Scalar >
getInitialRatesWithLimit_() const;

LimitedRates getLimitedRatesFromRates_(const BasicRates& rates) const;
LimitedRatesAndBhp getLimitedRatesAndBhp_(const RatesAndBhp& rates) const;


Scalar getProductionTarget_(Rate rate) const;
Scalar getRate_(Rate rate_type, const BasicRates& rates) const;
Scalar getRate_(Rate rate_type, const RatesAndBhp& rates) const;

std::pair<Scalar, std::optional<Rate>>
getRateWithLimit_(Rate rate_type, const BasicRates& rates) const;
getRateWithLimit_(Rate rate_type, const RatesAndBhp& rates) const;

std::tuple<Scalar, const std::string*>
getRateWithGroupLimit_(Rate rate_type,
const Scalar new_rate,
const Scalar old_rate,
const std::string& gr_name_dont_limit) const;

BasicRates getWellStateRates_() const;
RatesAndBhp getWellStateRates_() const;
bool hasProductionControl_(Rate rate) const;

std::pair<LimitedRates, Scalar>
std::pair<LimitedRatesAndBhp, Scalar>
increaseALQtoPositiveOilRate_(Scalar alq,
const LimitedRates& orig_rates) const;
const LimitedRatesAndBhp& orig_rates) const;

std::pair<LimitedRates, Scalar>
std::pair<LimitedRatesAndBhp, Scalar>
increaseALQtoMinALQ_(Scalar alq,
const LimitedRates& orig_rates) const;
const LimitedRatesAndBhp& orig_rates) const;

void logSuccess_(Scalar alq,
const int iteration_idx);

std::pair<LimitedRates, Scalar>
maybeAdjustALQbeforeOptimizeLoop_(const LimitedRates& rates,
std::pair<LimitedRatesAndBhp, Scalar>
maybeAdjustALQbeforeOptimizeLoop_(const LimitedRatesAndBhp& rates,
Scalar alq,
bool increase) const;

std::pair<LimitedRates, Scalar>
std::pair<LimitedRatesAndBhp, Scalar>
reduceALQtoGroupAlqLimits_(Scalar alq,
const LimitedRates& rates) const;
const LimitedRatesAndBhp& rates) const;

std::pair<LimitedRates, Scalar>
std::pair<LimitedRatesAndBhp, Scalar>
reduceALQtoGroupTarget(Scalar alq,
const LimitedRates& rates) const;
const LimitedRatesAndBhp& rates) const;

std::pair<LimitedRates, Scalar>
std::pair<LimitedRatesAndBhp, Scalar>
reduceALQtoWellTarget_(Scalar alq,
const LimitedRates& rates) const;
const LimitedRatesAndBhp& rates) const;

std::unique_ptr<GasLiftWellState<Scalar>> runOptimize1_();
std::unique_ptr<GasLiftWellState<Scalar>> runOptimize2_();
Expand All @@ -396,13 +401,13 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
std::unique_ptr<GasLiftWellState<Scalar>> tryIncreaseLiftGas_();
std::unique_ptr<GasLiftWellState<Scalar>> tryDecreaseLiftGas_();

void updateGroupRates_(const LimitedRates& rates,
const LimitedRates& new_rates,
void updateGroupRates_(const LimitedRatesAndBhp& rates,
const LimitedRatesAndBhp& new_rates,
Scalar delta_alq) const;

LimitedRates
updateRatesToGroupLimits_(const BasicRates& old_rates,
const LimitedRates& rates,
LimitedRatesAndBhp
updateRatesToGroupLimits_(const RatesAndBhp& old_rates,
const LimitedRatesAndBhp& rates,
const std::string& gr_name = "") const;

void updateWellStateAlqFixedValue_(const GasLiftWell& well);
Expand Down
19 changes: 11 additions & 8 deletions opm/simulators/wells/GasLiftSingleWell_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Opm {

template<typename TypeTag>
GasLiftSingleWell<TypeTag>::
GasLiftSingleWell(const WellInterface<TypeTag>& well,
GasLiftSingleWell(WellInterface<TypeTag>& well,
const Simulator& simulator,
const SummaryState& summary_state,
DeferredLogger& deferred_logger,
Expand Down Expand Up @@ -112,7 +112,7 @@ GasLiftSingleWell(const WellInterface<TypeTag>& well,
****************************************/

template<typename TypeTag>
typename GasLiftSingleWell<TypeTag>::BasicRates
typename GasLiftSingleWell<TypeTag>::RatesAndBhp
GasLiftSingleWell<TypeTag>::
computeWellRates_(Scalar bhp, bool bhp_is_limited, bool debug_output ) const
{
Expand All @@ -136,24 +136,27 @@ computeWellRates_(Scalar bhp, bool bhp_is_limited, bool debug_output ) const
return {-potentials[this->oil_pos_],
-potentials[this->gas_pos_],
-potentials[this->water_pos_],
bhp,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now returns BasicRates which seems to indicate to the reader that well rates are returned, but BasicRates now includes bhp which is a pressure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename to something like BasicWellState or LimitedWellState? However, that may be confused with the well state? Any other suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about RatesAndBhp and LimitedRatesAndBhp ?

bhp_is_limited
};
}

template<typename TypeTag>
std::optional<typename GasLiftSingleWell<TypeTag>::Scalar>
GasLiftSingleWell<TypeTag>::
computeBhpAtThpLimit_(Scalar alq, bool debug_output) const
computeBhpAtThpLimit_(Scalar alq, Scalar current_bhp, bool debug_output) const
{
OPM_TIMEFUNCTION();
const auto& groupStateHelper = this->simulator_.problem().wellModel().groupStateHelper();
auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlq(
// we compute new bhp value based on the alq rate by finding the intersection
// between the vfp curve and the IPR. The IPR is computed using the current bhp
// value
auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlqUsingIPR(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment why we now are using computeBhpAtThpLimitProdWithAlqUsingIPR() instead of computeBhpAtThpLimitProdWithAlq() ?

this->simulator_,
groupStateHelper,
this->well_state_,
current_bhp,
this->summary_state_,
alq,
this->deferred_logger_,
/*iterate_if_no_solution */ false);
this->deferred_logger_);
if (bhp_at_thp_limit) {
if (*bhp_at_thp_limit < this->controls_.bhp_limit) {
if (debug_output && this->debug) {
Expand Down
Loading