making bruteforce bracket as a function

for better readbility.
This commit is contained in:
Kai Bao 2022-01-07 15:13:33 +01:00
parent 3273f310e3
commit 5824acbf92
2 changed files with 41 additions and 22 deletions

View File

@ -612,28 +612,8 @@ computeBhpAtThpLimitProd(const std::function<std::vector<double>(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<double, 2> 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<std::vector<double>(const double)>&
}
}
template<typename Scalar>
bool
MultisegmentWellGeneric<Scalar>::
bruteForcingBracket(const std::function<double(const double)>& eq,
const std::array<double, 2>& 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<typename Scalar>
bool
MultisegmentWellGeneric<Scalar>::

View File

@ -27,6 +27,7 @@
#include <functional>
#include <optional>
#include <vector>
#include <array>
namespace Opm
{
@ -75,6 +76,11 @@ protected:
const double rho,
DeferredLogger& deferred_logger) const;
bool bruteForcingBracket(const std::function<double(const double)>& eq,
const std::array<double, 2>& range,
double& low, double& high,
DeferredLogger& deferred_logger) const;
/// Detect oscillation or stagnation based on the residual measure history
void detectOscillations(const std::vector<double>& measure_history,
const int it,