Expand description
Time evolution for systems that have no closed form.
Motion is a function of t: ask for the world at
0.7 s and you get it, without having computed 0.6 s first. That is worth a
great deal — an exposure can be sampled at seven instants for motion blur, and
frame 7 of a recording does not depend on having rendered frame 6 — and it is
why drift, oscillation and spin are written the way they are.
It is also not available in general. Three bodies under gravity have no closed form, and neither do contact, heat conduction, or a stiff reaction network. Those systems have to be rolled forward, and frame 7 genuinely does depend on frame 6.
§Reproducibility survives the trade, under three rules
- Fixed steps only.
Integrator::steptakesdtand uses it. An adaptive step chosen from the local error makes the floating-point path depend on the values, so two runs that should agree diverge at the first place one of them decided to halve the step. Where stability demands a smaller step, take a fixed number of substeps — seesubsteps_for. - No wall clock. Nothing here reads a timer.
- Ordered reduction. Summing forces in parallel changes the answer,
because floating-point addition is not associative. That rule belongs to the
domains, but it is the reason
State::axpyis a sequential operation on a whole state rather than a per-element one to be farmed out.
§Symplectic versus accurate
Integrator::Rk4 is fourth-order accurate and loses energy steadily.
velocity_verlet is second-order and does not: its energy error oscillates
within a bound instead of drifting, because it preserves the geometric
structure of a Newtonian system rather than merely fitting its derivative.
Over ten steps RK4 wins; over ten million, it has quietly cooled the system
down. For anything conservative — orbits, molecules, an undamped spring — use
the symplectic one and let crate::conserved::audit confirm it.
The test module proves exactly this on a harmonic oscillator, against the closed-form energy.
Enums§
- Integrator
- Explicit fixed-step integrators.
Traits§
- Dynamics
- A first-order system:
ds/dt = f(s, t). - Newtonian
- A Newtonian system:
d²x/dt² = a(x, t), with no dependence on velocity. - State
- A state vector that an integrator can do arithmetic on.
Functions§
- substeps_
for - How many equal substeps of at most
limitit takes to coverdt. - velocity_
verlet - One velocity-Verlet step, in place. Symplectic, second order, and the right default for anything whose energy is supposed to stay put.