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

Numerical root finding used by legacy hydraulic calculations. More...

#include <math.h>
#include "findroot.h"
Include dependency graph for findroot.c:

Macros

#define SIGN(a, b)
 
#define MAXIT   60
 

Functions

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.
 

Detailed Description

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)
License
Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.

Macro Definition Documentation

◆ MAXIT

#define MAXIT   60

◆ SIGN

#define SIGN ( a,
b )
Value:
((b) >= 0.0 ? fabs(a) : -fabs(a))

Function Documentation

◆ 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.