Refactor out the solving algorithm of bhp from thp via VFP to make it usable for injectors

This commit is contained in:
Tor Harald Sandve 2022-02-09 10:49:17 +01:00
parent 1001d35418
commit ec08f80405
2 changed files with 37 additions and 1 deletions

View File

@ -649,13 +649,39 @@ computeBhpAtThpLimitProdCommon(const std::function<std::vector<double>(const dou
"find bhp-point where production becomes non-zero for well " + this->name());
return std::nullopt;
}
const std::array<double, 2> range {controls.bhp_limit, *bhp_max};
return computeBhpAtThpLimitCommon(frates, fbhp, range, deferred_logger);
}
std::optional<double>
WellInterfaceGeneric::
computeBhpAtThpLimitCommon(const std::function<std::vector<double>(const double)>& frates,
const std::function<double(const std::vector<double>)>& fbhp,
const std::array<double, 2> range,
DeferredLogger& deferred_logger) const
{
// Given a VFP function returning bhp as a function of phase
// rates and thp:
// fbhp(rates, thp),
// a function extracting the particular flow rate used for VFP
// lookups:
// flo(rates)
// and the inflow function (assuming the reservoir is fixed):
// frates(bhp)
// we want to solve the equation:
// fbhp(frates(bhp, thplimit)) - bhp = 0
// for bhp.
//
// This may result in 0, 1 or 2 solutions. If two solutions,
// the one corresponding to the lowest bhp (and therefore
// highest rate) should be returned.
// Define the equation we want to solve.
auto eq = [&fbhp, &frates](double bhp) {
return fbhp(frates(bhp)) - bhp;
};
// Find appropriate brackets for the solution.
const std::array<double, 2> range {controls.bhp_limit, *bhp_max};
std::optional<double> approximate_solution;
double low, high;
// trying to use bisect way to locate a bracket

View File

@ -184,6 +184,9 @@ public:
const double alq_value,
DeferredLogger& deferred_logger
) const;
protected:
bool getAllowCrossFlow() const;
double mostStrictBhpFromBhpLimits(const SummaryState& summaryState) const;
@ -198,6 +201,13 @@ protected:
const double vfp_flo_front,
DeferredLogger& deferred_logger) const;
std::optional<double> computeBhpAtThpLimitCommon(
const std::function<std::vector<double>(const double)>& frates,
const std::function<double(const std::vector<double>)>& fbhp,
const std::array<double, 2> range,
DeferredLogger& deferred_logger) const;
bool bruteForceBracket(const std::function<double(const double)>& eq,
const std::array<double, 2>& range,
double& low, double& high,