From cbbd75164e5a42957318e657ad9f6c9b2f21852b Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Tue, 2 Jul 2019 10:51:28 +0200 Subject: [PATCH] refactoring the ration economic limit checking --- opm/simulators/wells/WellInterface.hpp | 34 +++++---- opm/simulators/wells/WellInterface_impl.hpp | 76 +++++++++------------ 2 files changed, 52 insertions(+), 58 deletions(-) diff --git a/opm/simulators/wells/WellInterface.hpp b/opm/simulators/wells/WellInterface.hpp index e6641e099..d7173073f 100644 --- a/opm/simulators/wells/WellInterface.hpp +++ b/opm/simulators/wells/WellInterface.hpp @@ -379,20 +379,16 @@ namespace Opm double mostStrictBhpFromBhpLimits(Opm::DeferredLogger& deferred_logger) const; - // a tuple type for ratio limit check. - // first value indicates whether ratio limit is violated, when the ratio limit is not violated, the following two - // values should not be used. - // second value indicates the index of the worst-offending completion. - // the last value indicates the extent of the violation for the worst-offending completion, which is defined by - // the ratio of the actual value to the value of the violated limit. - using RatioCheckTuple = std::tuple; + struct RatioLimitCheckReport; - RatioCheckTuple checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state) const; + void checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits, + const WellState& well_state, + RatioLimitCheckReport& report) const; - RatioCheckTuple checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state, - Opm::DeferredLogger& deferred_logger) const; + void checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, + const WellState& well_state, + RatioLimitCheckReport& report, + Opm::DeferredLogger& deferred_logger) const; template bool checkMaxRatioLimitWell(const WellState& well_state, @@ -403,8 +399,7 @@ namespace Opm void checkMaxRatioLimitCompletions(const WellState& well_state, const double max_ratio_limit, const RatioFunc& ratioFunc, - int& worst_offending_completion, - double& violation_extent) const; + RatioLimitCheckReport& report) const; double scalingFactor(const int comp_idx) const; @@ -499,6 +494,17 @@ namespace Opm bool obey_bhp_limit_with_thp_limit = true; }; + + + template + struct + WellInterface:: + RatioLimitCheckReport{ + bool ratio_limit_violated = false; + int worst_offending_completion = INVALIDCOMPLETION; + double violation_extent = 0.0; + }; + const std::string modestring[4] = { "BHP", "THP", "RESERVOIR_RATE", "SURFACE_RATE" }; } diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index 937bc0601..d36570f47 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -605,10 +605,11 @@ namespace Opm template - typename WellInterface::RatioCheckTuple + void WellInterface:: checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits, - const WellState& well_state) const + const WellState& well_state, + RatioLimitCheckReport& report) const { assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)); @@ -635,17 +636,12 @@ namespace Opm const double max_water_cut_limit = econ_production_limits.maxWaterCut(); assert(max_water_cut_limit > 0.); - const bool water_cut_limit_violated = checkMaxRatioLimitWell(well_state, max_water_cut_limit, waterCut); + const bool watercut_limit_violated = checkMaxRatioLimitWell(well_state, max_water_cut_limit, waterCut); - int worst_offending_completion = INVALIDCOMPLETION; - double violation_extent = -1.; - - if (water_cut_limit_violated) { - checkMaxRatioLimitCompletions(well_state, max_water_cut_limit, waterCut, - worst_offending_completion, violation_extent); + if (watercut_limit_violated) { + report.ratio_limit_violated = true; + checkMaxRatioLimitCompletions(well_state, max_water_cut_limit, waterCut, report); } - - return std::make_tuple(water_cut_limit_violated, worst_offending_completion, violation_extent); } @@ -653,10 +649,11 @@ namespace Opm template - typename WellInterface::RatioCheckTuple + void WellInterface:: checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits, const WellState& well_state, + RatioLimitCheckReport& report, Opm::DeferredLogger& deferred_logger) const { // TODO: not sure how to define the worst-offending completion when more than one @@ -667,21 +664,8 @@ namespace Opm // Among the worst-offending completions, we use the one has the biggest violation // extent. - bool any_limit_violated = false; - int worst_offending_completion = INVALIDCOMPLETION; - double violation_extent = -1.0; - if (econ_production_limits.onMaxWaterCut()) { - const RatioCheckTuple water_cut_return = checkMaxWaterCutLimit(econ_production_limits, well_state); - bool water_cut_violated = std::get<0>(water_cut_return); - if (water_cut_violated) { - any_limit_violated = true; - const double violation_extent_water_cut = std::get<2>(water_cut_return); - if (violation_extent_water_cut > violation_extent) { - violation_extent = violation_extent_water_cut; - worst_offending_completion = std::get<1>(water_cut_return); - } - } + checkMaxWaterCutLimit(econ_production_limits, well_state, report); } if (econ_production_limits.onMaxGasOilRatio()) { @@ -696,12 +680,10 @@ namespace Opm deferred_logger.warning("NOT_SUPPORTING_MAX_GLR", "the support for max Gas-Liquid ratio is not implemented yet!"); } - if (any_limit_violated) { - assert(worst_offending_completion != INVALIDCOMPLETION); - assert(violation_extent > 1.); + if (report.ratio_limit_violated) { + assert(report.worst_offending_completion != INVALIDCOMPLETION); + assert(report.violation_extent > 1.); } - - return std::make_tuple(any_limit_violated, worst_offending_completion, violation_extent); } @@ -738,11 +720,9 @@ namespace Opm checkMaxRatioLimitCompletions(const WellState& well_state, const double max_ratio_limit, const RatioFunc& ratioFunc, - int& worst_offending_completion, - double& violation_extent) const + RatioLimitCheckReport& report) const { - worst_offending_completion = INVALIDCOMPLETION; - violation_extent = -1.0; + int worst_offending_completion = INVALIDCOMPLETION; // the maximum water cut value of the completions // it is used to identify the most offending completion @@ -775,7 +755,13 @@ namespace Opm assert(max_ratio_completion > max_ratio_limit); assert(worst_offending_completion != INVALIDCOMPLETION); - violation_extent = max_ratio_completion / max_ratio_limit; + const double violation_extent = max_ratio_completion / max_ratio_limit; + assert(violation_extent > 1.0); + + if (violation_extent > report.violation_extent) { + report.worst_offending_completion = worst_offending_completion; + report.violation_extent = violation_extent; + } } @@ -900,21 +886,23 @@ namespace Opm return; } - // checking for ratio related limits, mostly all kinds of ratio. - bool ratio_limits_violated = false; - RatioCheckTuple ratio_check_return; - if (econ_production_limits.onAnyRatioLimit()) { - ratio_check_return = checkRatioEconLimits(econ_production_limits, well_state, deferred_logger); - ratio_limits_violated = std::get<0>(ratio_check_return); + if ( !econ_production_limits.onAnyRatioLimit() ) { + // there is no need to check the ratio limits + return; } - if (ratio_limits_violated) { + // checking for ratio related limits, mostly all kinds of ratio. + RatioLimitCheckReport ratio_report; + + checkRatioEconLimits(econ_production_limits, well_state, ratio_report, deferred_logger); + + if (ratio_report.ratio_limit_violated) { const WellEcon::WorkoverEnum workover = econ_production_limits.workover(); switch (workover) { case WellEcon::CON: { - const int worst_offending_completion = std::get<1>(ratio_check_return); + const int worst_offending_completion = ratio_report.worst_offending_completion; well_test_state.addClosedCompletion(name(), worst_offending_completion, simulation_time); if (write_message_to_opmlog) {