Skip to content

Commit b7c643f

Browse files
author
Tor Harald Sandve
committed
Fixes for gliftopt item 3 maximum gas+alq
1 parent 0a7715a commit b7c643f

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

opm/simulators/wells/BlackoilWellModelGasLift_impl.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,6 @@ gasLiftOptimizationStage1(const Simulator& simulator,
248248
group_alq_rates[j]);
249249
}
250250
}
251-
if constexpr (glift_debug) {
252-
int counter = 0;
253-
if (comm.rank() == i) {
254-
counter = wellState.gliftGetDebugCounter();
255-
}
256-
counter = comm.sum(counter);
257-
if (comm.rank() != i) {
258-
wellState.gliftSetDebugCounter(counter);
259-
}
260-
}
261251
}
262252
}
263253
}

opm/simulators/wells/GasLiftGroupInfo.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,19 @@ getProducerWellRates_(const Well* well, int well_index)
549549

550550
if (controls.hasControl(Well::ProducerCMode::ORAT) && oil_rate > static_cast<Scalar>(controls.oil_rate)) {
551551
water_rate *= (static_cast<Scalar>(controls.oil_rate) / oil_rate);
552+
gas_rate *= (static_cast<Scalar>(controls.oil_rate) / oil_rate);
552553
oil_rate = static_cast<Scalar>(controls.oil_rate);
553554
}
554555

555-
if (controls.hasControl(Well::ProducerCMode::GRAT)) {
556-
gas_rate = std::min(static_cast<Scalar>(controls.gas_rate), gas_rate);
556+
if (controls.hasControl(Well::ProducerCMode::GRAT) && gas_rate > static_cast<Scalar>(controls.gas_rate)) {
557+
water_rate *= (static_cast<Scalar>(controls.gas_rate) / gas_rate);
558+
oil_rate *= (static_cast<Scalar>(controls.gas_rate) / gas_rate);
559+
gas_rate = static_cast<Scalar>(controls.gas_rate);
557560
}
558561

559562
if (controls.hasControl(Well::ProducerCMode::WRAT) && water_rate > static_cast<Scalar>(controls.water_rate)) {
560563
oil_rate *= (static_cast<Scalar>(controls.water_rate) / water_rate);
564+
gas_rate *= (static_cast<Scalar>(controls.water_rate) / water_rate);
561565
water_rate = static_cast<Scalar>(controls.water_rate);
562566
}
563567
if (controls.hasControl(Well::ProducerCMode::LRAT)) {
@@ -566,6 +570,7 @@ getProducerWellRates_(const Well* well, int well_index)
566570
if (liquid_rate > liquid_rate_lim) {
567571
water_rate = water_rate / liquid_rate * liquid_rate_lim;
568572
oil_rate = oil_rate / liquid_rate * liquid_rate_lim;
573+
gas_rate = gas_rate / liquid_rate * liquid_rate_lim;
569574
}
570575
}
571576

@@ -670,12 +675,17 @@ initializeGroupRatesRecursive_(const Group& group)
670675

671676
if (oil_target && oil_rate > *oil_target) {
672677
water_rate *= (*oil_target/oil_rate);
678+
gas_rate *= (*oil_target/oil_rate);
673679
oil_rate = *oil_target;
674680
}
675-
if (gas_target && gas_rate > *gas_target)
681+
if (gas_target && gas_rate > *gas_target) {
682+
water_rate *= (*gas_target/gas_rate);
683+
oil_rate *= (*gas_target/gas_rate);
676684
gas_rate = *gas_target;
685+
}
677686
if (water_target && water_rate > *water_target) {
678687
oil_rate *= (*water_target/water_rate);
688+
gas_rate *= (*water_target/water_rate);
679689
water_rate = *water_target;
680690
}
681691
if (liquid_target) {
@@ -684,6 +694,7 @@ initializeGroupRatesRecursive_(const Group& group)
684694
if (liquid_rate > liquid_rate_limited) {
685695
oil_rate = oil_rate / liquid_rate * liquid_rate_limited;
686696
water_rate = water_rate / liquid_rate * liquid_rate_limited;
697+
gas_rate = gas_rate / liquid_rate * liquid_rate_limited;
687698
}
688699
}
689700
}

opm/simulators/wells/GasLiftSingleWellGeneric.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ calcIncOrDecGradient(Scalar oil_rate,
116116
BasicRates oldrates = {oil_rate, gas_rate, water_rate, false};
117117
const auto new_rates = updateRatesToGroupLimits_(oldrates, ratesLimited, gr_name_dont_limit);
118118

119+
auto delta_gas_rate = new_rates.gas - gas_rate;
120+
if (increase && checkGroupTotalRateExceeded(delta_alq, delta_gas_rate, gr_name_dont_limit))
121+
return std::nullopt;
122+
123+
119124
if (!increase && new_rates.oil < 0) {
120125
return std::nullopt;
121126
}
@@ -293,7 +298,7 @@ addOrSubtractAlqIncrement_(Scalar alq, bool increase) const
293298
if (limited && checkALQequal_(orig_alq, alq))
294299
alq_opt = std::nullopt;
295300

296-
return {alq_opt, limited};
301+
return {alq_opt, limited && increase };
297302
}
298303

299304
template<typename Scalar, typename IndexTraits>
@@ -1841,10 +1846,16 @@ checkGroupALQrateExceeded(Scalar delta_alq,
18411846
template<typename Scalar, typename IndexTraits>
18421847
bool GasLiftSingleWellGeneric<Scalar, IndexTraits>::
18431848
checkGroupTotalRateExceeded(Scalar delta_alq,
1844-
Scalar delta_gas_rate) const
1849+
Scalar delta_gas_rate,
1850+
const std::string& gr_name_dont_limit) const
18451851
{
18461852
const auto& pairs = group_info_.getWellGroups(well_name_);
18471853
for (const auto& [group_name, efficiency] : pairs) {
1854+
// in stage 2 we don't want to limit the rate to the group
1855+
// target we are trying to redistribute the gaslift within
1856+
if (gr_name_dont_limit == group_name)
1857+
continue;
1858+
18481859
auto max_total_rate_opt = group_info_.maxTotalGasRate(group_name);
18491860
if (max_total_rate_opt) {
18501861
Scalar alq = group_info_.alqRate(group_name) + efficiency * delta_alq;

opm/simulators/wells/GasLiftSingleWellGeneric.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ class GasLiftSingleWellGeneric : public GasLiftCommon<Scalar, IndexTraits>
267267
bool checkGroupALQrateExceeded(Scalar delta_alq,
268268
const std::string& gr_name_dont_limit = "") const;
269269
bool checkGroupTotalRateExceeded(Scalar delta_alq,
270-
Scalar delta_gas_rate) const;
270+
Scalar delta_gas_rate,
271+
const std::string& gr_name_dont_limit = "") const;
271272

272273
std::pair<std::optional<Scalar>, bool>
273274
addOrSubtractAlqIncrement_(Scalar alq, bool increase) const;

opm/simulators/wells/GasLiftStage2.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ checkRateAlreadyLimited_(const std::string& well_name,
217217
well_name,
218218
state.alq(),
219219
(increase ? "incremental" : "decremental"),
220-
(state.oilIsLimited() ? "oil" : (state.gasIsLimited() ? "gas" : "alq"))
220+
(state.oilIsLimited() ? "oil" : (state.gasIsLimited() ? "gas" : (state.waterIsLimited() ? "water" : "alq")))
221221
);
222222
displayDebugMessage_(msg);
223223
return true;
@@ -431,7 +431,14 @@ optimizeGroup_(const Group& group)
431431
OPM_TIMEFUNCTION();
432432
const auto& group_name = group.name();
433433
const auto prod_control = this->group_state_.production_control(group_name);
434-
if ((prod_control != Group::ProductionCMode::NONE) && (prod_control != Group::ProductionCMode::FLD))
434+
const auto max_totalgas = getGroupMaxTotalGas_(group);
435+
bool restricted_by_max_totalgas = false;
436+
if (max_totalgas) {
437+
auto [oil_rate, gas_rate, water_rate, alq] = getCurrentGroupRates_(group);
438+
restricted_by_max_totalgas = (gas_rate + alq) > max_totalgas;
439+
}
440+
441+
if (restricted_by_max_totalgas || ((prod_control != Group::ProductionCMode::NONE) && (prod_control != Group::ProductionCMode::FLD)))
435442
{
436443
if (this->debug) {
437444
const std::string msg = fmt::format("optimizing (control = {})", Group::ProductionCMode2String(prod_control));

0 commit comments

Comments
 (0)