Numerical root finding used by legacy hydraulic calculations.
More...
#include <math.h>
#include "findroot.h"
|
| int | findroot_Newton (double x1, double x2, double *rts, double xacc, newton_callback func, void *p) |
| | Find a bracketed root using Newton steps with bisection fallback.
|
| |
| double | findroot_Ridder (double x1, double x2, double xacc, ridder_callback func, void *p) |
| | Estimate a bracketed scalar root with derivative-free Ridder iterations.
|
| |
Numerical root finding used by legacy hydraulic calculations.
- Author
- Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com (OpenSWMM maintenance and extensions)
- Copyright
- Copyright (c) 2026 Caleb Buahin. OpenSWMM contributions only; original EPA SWMM credits are retained.
- License
- Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.
◆ MAXIT
◆ SIGN
Value:((b) >= 0.0 ? fabs(a) : -fabs(a))
◆ findroot_Newton()
| int findroot_Newton |
( |
double | x1, |
|
|
double | x2, |
|
|
double * | rts, |
|
|
double | xacc, |
|
|
newton_callback | func, |
|
|
void * | p ) |
Find a bracketed root using Newton steps with bisection fallback.
Finds the root of a function using Newton's method.
- Implementation arguments
- x1 (in): Bracket endpoint where the callback function is negative.
- x2 (in): Bracket endpoint where the callback function is positive; coordinate order may be reversed to obtain this sign ordering.
- rts (in,out): Non-null initial guess within the bracket, overwritten with the last estimate on convergence or iteration exhaustion.
- xacc (in): Positive absolute step tolerance in the coordinate units.
- func (in): Non-null synchronous callback filling f and df/dx; it must not retain the solver's temporary output pointers.
- p (in): Borrowed opaque callback context, passed through unchanged; may be NULL when the callback does not require it.
- Returns
- Evaluation count, or zero after more than MAXIT evaluations. A stationary floating-point estimate also ends iteration.
- Precondition
- The caller validates/orients the bracket. Endpoints are not evaluated before the initial guess, preserving the legacy callback sequence.
◆ findroot_Ridder()
| double findroot_Ridder |
( |
double | x1, |
|
|
double | x2, |
|
|
double | xacc, |
|
|
ridder_callback | func, |
|
|
void * | p ) |
Estimate a bracketed scalar root with derivative-free Ridder iterations.
Finds the root of a function using Ridder's method.
- Implementation arguments
- x1 (in): First bracket coordinate.
- x2 (in): Second bracket coordinate; endpoint function values must have opposite signs unless an endpoint is already a root.
- xacc (in): Positive absolute tolerance in the coordinate units.
- func (in): Non-null synchronous evaluator; called at both endpoints and successive trial points, without retaining the callback.
- p (in): Borrowed opaque callback context; may be NULL if unused.
- Returns
- Exact endpoint root, the last approximate root, or -1.0e20 for an unbracketed root. Exhaustion has no separate failure status.
- Note
- When a newly calculated root is within xacc of the previous estimate, the previous estimate is returned; the last callback point may differ.