Adaptive step size control ensures accuracy while maximizing efficiency.
The Problem¶
Fixed step sizes face a dilemma:
- Too large: Accuracy suffers
- Too small: Computation wasted
Solution: Adjust step size based on local error estimate.
Step 1: Local Error Estimation¶
Embedded Methods¶
Using a \((p, p-1)\) embedded pair (e.g., Tsit5):
Error Estimate¶
This estimates the local truncation error without extra function evaluations.
Step 2: Error Norm¶
For systems of equations, we use a weighted norm:
Where the scale factor is:
| Parameter | Meaning | Typical Value |
|---|---|---|
atol |
Absolute tolerance | \(10^{-6}\) |
rtol |
Relative tolerance | \(10^{-6}\) |
Step 3: Step Size Control¶
Accept/Reject Decision¶
Optimal Step Size¶
The "optimal" next step size:
Where \(p\) is the order of the lower-order formula.
Step 4: Safety Factors¶
Practical Formula¶
| Factor | Value | Purpose |
|---|---|---|
fac |
0.9 | Safety margin |
fac_min |
0.2 | Prevent drastic decrease |
fac_max |
10.0 | Prevent drastic increase |
Step 5: PID Controller¶
The Apogee simulator uses a PID controller for smoother step adaptation.
The Idea¶
Instead of using only the current error, we incorporate history:
Gains¶
For Tsit5 (order 5):
Implementation:
stepsize_controller = diffrax.PIDController(rtol=1e-6, atol=1e-6)
Configuration in Apogee¶
Default Parameters¶
@dataclass(frozen=True, slots=True)
class NumericsParams:
# ...
dt0: float # Initial step size [s]
rtol: float # Relative tolerance
atol: float # Absolute tolerance
# ...
Typical Values¶
| Parameter | Value | Meaning |
|---|---|---|
dt0 |
0.5 s | Initial step size |
rtol |
\(10^{-6}\) | Relative tolerance |
atol |
\(10^{-6}\) | Absolute tolerance |
max_steps |
100,000 | Safety limit |
Step Size Evolution¶
During a typical Falcon 9 simulation:
| Phase | Typical Step Size |
|---|---|
| Liftoff | ~0.1 s (rapid changes) |
| Max-Q | ~0.5 s |
| Coast | ~5-10 s (slow dynamics) |
| Final burn | ~1 s |
The solver automatically adapts to the dynamics.
References¶
-
Hairer, E., Nørsett, S.P., & Wanner, G. (1993). Solving Ordinary Differential Equations I. Springer. Chapter II.4.
-
Söderlind, G. (2002). "Automatic control and adaptive time-stepping." Numerical Algorithms, 31, 281-310.
-
Diffrax Documentation: Step Size Controllers
Next Steps¶
- Shooting Method - Using ODE solvers for optimization
- Singularity Guards - Numerical stability