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_cand its callers (CORE-R100):Copy, twof64s, the textbook formulas and nothing else (no dependency).
Constants§
- MAX_
STEPS - Upper bound on substeps per
integratecall (CORE-R37). - MIN_
STEP - Smallest substep
integratewill use; smaller, zero, negative or NaNh_maxis raised to this (CORE-R37).
Functions§
- integrate
- Integrate
y' = f(t, y)fromttot + dtin equal RK4 substeps no longer thanh_max, returning how many were taken (CORE-R37). - rk4_
step - Advance
y' = f(t, y)by one classical Runge–Kutta 4 step of sizeh(CORE-R37). - tridiag_
apply_ c - Solve with a matrix factored by
tridiag_factor_c, in place intorhs: 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_iandc_prime[i] = sup[i]/m_i. Mismatched lengths or a zero (or non-finite) pivot returnfalsewith 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 intorhsby the Thomas algorithm, in O(n) (CORE-R59).sub[0]andsup[n − 1]are ignored;scratchholds the eliminated super-diagonal. - tridiag_
solve_ c tridiag_solveoverC64(CORE-R100): solvesub[i]·x[i−1] + diag[i]·x[i] + sup[i]·x[i+1] = rhs[i]in place intorhs,scratchholding the eliminated super-diagonal. Mismatched lengths or a zero (or non-finite) pivot returnfalsewithrhsuntouched.- verlet_
integrate - Advance
x'' = a(x)bydtin equal leapfrog substeps no longer thanh_max, returning how many were taken (CORE-R44). - verlet_
step - One kick–drift–kick leapfrog (velocity Verlet) step of size
hforx'' = a(x)(CORE-R44).