OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
OdeSolver.hpp File Reference

Runge-Kutta-Cash-Karp (RK45) ODE integrator with adaptive step control. More...

#include <functional>
#include <vector>
Include dependency graph for OdeSolver.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  openswmm
 
namespace  openswmm::ode
 

Typedefs

using openswmm::ode::DerivFunc = std::function< void(double x, const double *y, double *dydx)>
 Derivative function signature.
 
using openswmm::ode::BatchDerivFunc = std::function< void(double x, const double *y0, const double *y1, double *dy0, double *dy1, int n_sys)>
 Integrate N independent 2-equation ODE systems in batch.
 

Functions

int openswmm::ode::integrate (double *y, int n, double x1, double x2, double eps, double h1, const DerivFunc &derivs)
 Integrate an ODE system from x1 to x2 using RK45 Cash-Karp.
 
int openswmm::ode::integrate_batch_2eq (double *y0, double *y1, int n_sys, double x1, double x2, double eps, double h1, const BatchDerivFunc &derivs)
 

Variables

constexpr int openswmm::ode::MAXSTP = 10000
 Maximum integration steps.
 
constexpr double openswmm::ode::TINY = 1.0e-30
 Underflow protection.
 
constexpr double openswmm::ode::SAFETY = 0.9
 Step adjustment safety factor.
 
constexpr double openswmm::ode::PGROW = -0.2
 Exponent for step increase.
 
constexpr double openswmm::ode::PSHRNK = -0.25
 Exponent for step decrease.
 
constexpr double openswmm::ode::ERRCON = 1.89e-4
 = (5/SAFETY)^(1/PGROW)
 
constexpr int openswmm::ode::ODE_OK = 0
 Success.
 
constexpr int openswmm::ode::ODE_TOO_MANY = 1
 n > allocated max
 
constexpr int openswmm::ode::ODE_UNDERFLOW = 2
 Step size underflowed.
 
constexpr int openswmm::ode::ODE_MAX_STEPS = 3
 Exceeded MAXSTP.
 

Detailed Description

Runge-Kutta-Cash-Karp (RK45) ODE integrator with adaptive step control.

Numerically identical to legacy odesolve.c. Uses 5th-order Runge-Kutta with embedded 4th-order error estimate for automatic step size control.

Used by:

  • Groundwater two-zone model (2 ODEs per subcatchment)
  • Subcatchment runoff ponded-depth integration

Vectorization note: Each subcatchment's ODE system is independent. For batch integration over N subcatchments, call integrate() N times or use integrate_batch() which processes all subcatchments in a single pass with SoA state arrays.

Note
Legacy reference: src/legacy/engine/odesolve.c
Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License\n MIT License