diff --git a/opm/simulators/wells/MultisegmentWellGeneric.cpp b/opm/simulators/wells/MultisegmentWellGeneric.cpp index 4a502c06e..70e7b52e6 100644 --- a/opm/simulators/wells/MultisegmentWellGeneric.cpp +++ b/opm/simulators/wells/MultisegmentWellGeneric.cpp @@ -612,28 +612,8 @@ computeBhpAtThpLimitProd(const std::function(const double)>& if (!finding_bracket) { deferred_logger.debug(" trying the brute force way for last attempt "); - // resetting the high and low - low = controls.bhp_limit; - high = bhp_max; - const int sample_number = 100; - const double interval = (high - low) / sample_number; - double eq_low = eq(low); - double eq_high; - for (int i = 0; i < sample_number + 1; ++i) { - high = controls.bhp_limit + interval * i; - eq_high = eq(high); - if (eq_high * eq_low <= 0.) { - finding_bracket = true; - break; - } - low = high; - eq_low = eq_high; - } - if (finding_bracket) { - deferred_logger.debug( - " brute force solve found low " + std::to_string(low) + " with eq_low " + std::to_string(eq_low) + - " high " + std::to_string(high) + " with eq_high " + std::to_string(eq_high)); - } + const std::array range {controls.bhp_limit, bhp_max}; + finding_bracket = this->bruteForcingBracket(eq, range, low, high, deferred_logger); } if (!finding_bracket) { @@ -656,6 +636,39 @@ computeBhpAtThpLimitProd(const std::function(const double)>& } } +template +bool +MultisegmentWellGeneric:: +bruteForcingBracket(const std::function& eq, + const std::array& range, + double& low, double& high, + DeferredLogger& deferred_logger) const +{ + bool finding_bracket = false; + low = range[0]; + high = range[1]; + const int sample_number = 100; + const double interval = (high - low) / sample_number; + double eq_low = eq(low); + double eq_high; + for (int i = 0; i < sample_number + 1; ++i) { + high = range[0] + interval * i; + eq_high = eq(high); + if (eq_high * eq_low <= 0.) { + finding_bracket = true; + break; + } + low = high; + eq_low = eq_high; + } + if (finding_bracket) { + deferred_logger.debug( + " brute force solve found low " + std::to_string(low) + " with eq_low " + std::to_string(eq_low) + + " high " + std::to_string(high) + " with eq_high " + std::to_string(eq_high)); + } + return finding_bracket; +} + template bool MultisegmentWellGeneric:: diff --git a/opm/simulators/wells/MultisegmentWellGeneric.hpp b/opm/simulators/wells/MultisegmentWellGeneric.hpp index 784c02141..591458e7b 100644 --- a/opm/simulators/wells/MultisegmentWellGeneric.hpp +++ b/opm/simulators/wells/MultisegmentWellGeneric.hpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace Opm { @@ -75,6 +76,11 @@ protected: const double rho, DeferredLogger& deferred_logger) const; + bool bruteForcingBracket(const std::function& eq, + const std::array& range, + double& low, double& high, + DeferredLogger& deferred_logger) const; + /// Detect oscillation or stagnation based on the residual measure history void detectOscillations(const std::vector& measure_history, const int it,