OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm::findroot Namespace Reference

Typedefs

using NewtonFunc = std::function<void(double x, double* f, double* df)>
 Synchronous function and derivative evaluator for newton().
 
using RidderFunc = std::function<double(double x)>
 Synchronous scalar function evaluator for ridder().
 

Functions

int newton (double x1, double x2, double *rts, double xacc, const NewtonFunc &func)
 Find a root with Newton steps and a bisection fallback.
 
double ridder (double x1, double x2, double xacc, const RidderFunc &func)
 Estimate a bracketed root with derivative-free Ridder iterations.
 

Variables

constexpr int MAXIT = 60
 Maximum iterations.
 

Typedef Documentation

◆ NewtonFunc

using openswmm::findroot::NewtonFunc = std::function<void(double x, double* f, double* df)>

Synchronous function and derivative evaluator for newton().

Parameters
[in]xCandidate root, in the caller's independent-variable units.
[out]fNon-null solver-owned slot for f(x).
[out]dfNon-null solver-owned slot for df/dx.
Note
The callback must fill both slots and must not retain their addresses.

◆ RidderFunc

using openswmm::findroot::RidderFunc = std::function<double(double x)>

Synchronous scalar function evaluator for ridder().

Parameters
[in]xCandidate root in caller-selected units.
Returns
f(x); no derivative is required.

Function Documentation

◆ newton()

int openswmm::findroot::newton ( double x1,
double x2,
double * rts,
double xacc,
const NewtonFunc & func )

Find a root with Newton steps and a bisection fallback.

Parameters
[in]x1Bracket endpoint where f(x1) < 0, regardless of coordinate order.
[in]x2Bracket endpoint where f(x2) > 0.
[in,out]rtsNon-null caller-owned initial guess inside the bracket; overwritten with the final estimate on both convergence and iteration exhaustion.
[in]xaccPositive absolute step tolerance in the units of x1 and x2.
[in]funcNonempty synchronous callback producing f and df/dx for each candidate. It is not retained; callback exceptions propagate.
Returns
Number of function evaluations on convergence or a stationary floating-point estimate; zero when more than MAXIT evaluations are needed.

The caller must orient and validate the bracket. This function does not pre-evaluate endpoints; preserving callback sequence matches legacy findroot_Newton(). Newton steps outside the bracket, or steps that converge too slowly, are replaced by bisection.

Here is the caller graph for this function:

◆ ridder()

double openswmm::findroot::ridder ( double x1,
double x2,
double xacc,
const RidderFunc & func )

Estimate a bracketed root with derivative-free Ridder iterations.

Parameters
[in]x1First finite bracket coordinate.
[in]x2Second finite bracket coordinate; endpoint function values must have opposite signs unless an endpoint is already a root.
[in]xaccPositive absolute tolerance in the units of x1 and x2, applied to successive estimates and bracket width.
[in]funcNonempty synchronous evaluator, not retained. Exceptions propagate; callback invocation order follows legacy findroot_Ridder().
Returns
An exact endpoint root, an approximate root, or -1.0e20 if the endpoints do not straddle a root. On iteration exhaustion the last estimate is returned without a distinct failure code.
Note
When a new estimate differs by at most xacc, the previous estimate is returned. The callback's most recent input need not equal the result.

Variable Documentation

◆ MAXIT

int openswmm::findroot::MAXIT = 60
constexpr

Maximum iterations.