Skip to main content

Module ode

Module ode 

Source
Expand description

Fixed-step ODE integration for deterministic physics scenes (SPEC-001 CORE-R37, CORE-R44) and tridiagonal solvers for implicit diffusion (CORE-R59) and complex Crank–Nicolson steps (CORE-R100).

RK4 state is a const-generic [f64; N] so every stage lives on the stack: no allocation, no trait objects, and the closure is monomorphised into a tight loop. Classical RK4 is the sweet spot for a 60 Hz visual simulation: 4th-order accurate with four evaluations, and far better behaved than Euler on orbits and pendulums.

Long-lived conservative systems (N-body, choreographies) instead want the symplectic kick–drift–kick leapfrog (verlet_step): 2nd order, one force evaluation per step, time-reversible, and with a bounded energy error where RK4 slowly drifts. It works on caller-owned slices because N-body state is sized at runtime.

Structs§

C64
A plain complex number for tridiag_solve_c and its callers (CORE-R100): Copy, two f64s, the textbook formulas and nothing else (no dependency).

Constants§

MAX_STEPS
Upper bound on substeps per integrate call (CORE-R37).
MIN_STEP
Smallest substep integrate will use; smaller, zero, negative or NaN h_max is raised to this (CORE-R37).

Functions§

integrate
Integrate y' = f(t, y) from t to t + dt in equal RK4 substeps no longer than h_max, returning how many were taken (CORE-R37).
rk4_step
Advance y' = f(t, y) by one classical Runge–Kutta 4 step of size h (CORE-R37).
tridiag_apply_c
Solve with a matrix factored by tridiag_factor_c, in place into rhs: two complex multiply-adds per unknown. Mismatched lengths do nothing (CORE-R100).
tridiag_factor_c
Factor a complex tridiagonal matrix once for tridiag_apply_c (CORE-R100): inv_pivot[i] = 1/m_i and c_prime[i] = sup[i]/m_i. Mismatched lengths or a zero (or non-finite) pivot return false with both outputs untouched.
tridiag_solve
Solve the tridiagonal system sub[i]·x[i−1] + diag[i]·x[i] + sup[i]·x[i+1] = rhs[i] in place into rhs by the Thomas algorithm, in O(n) (CORE-R59). sub[0] and sup[n − 1] are ignored; scratch holds the eliminated super-diagonal.
tridiag_solve_c
tridiag_solve over C64 (CORE-R100): solve sub[i]·x[i−1] + diag[i]·x[i] + sup[i]·x[i+1] = rhs[i] in place into rhs, scratch holding the eliminated super-diagonal. Mismatched lengths or a zero (or non-finite) pivot return false with rhs untouched.
verlet_integrate
Advance x'' = a(x) by dt in equal leapfrog substeps no longer than h_max, returning how many were taken (CORE-R44).
verlet_step
One kick–drift–kick leapfrog (velocity Verlet) step of size h for x'' = a(x) (CORE-R44).