Integration methods for the Berton 2023 model
I started off using the same integration method as in the paper to get a good baseline for validation against the paper’s results (see last entry). However, the integration method used in the paper (an explicit Euler method) isn’t very good. It requires a very small timestep (0.02-0.04 seconds), so a very large number of steps (900,000 for the oscillatory case in the paper!). The paper makes a comment about the method being stable because of the timestep choice, but that’s more a comment on the bad choice of integration method than anything else.
For future experiments, I wanted to use a better method. The model is stiff: the timescale of the oscillations is around 10 hours, while the damping coefficient is around 20 s⁻¹, corresponding to a timescale of around 0.05 s, giving a stiffness ratio of 720,000. This is why Berton’s integrator only works for very small timesteps, and a stiff solver is almost guaranteed to do a better job.
The Scipy solve_ivp
function
gives access to a range of solvers. I took a look at the Radau and BDF methods
(fairly common methods for stiff system) and LSODA, which is a sophisticated
“comprehensive” ODE stepper with automatic stiffness detection and method
switching. I kept the original explicit Euler method for comparison.
Fixed-output comparisons
The first comparison to do is to force the Scipy integrators to produce output
points at the same time resolution as the fixed timestep of the explicit Euler
method. The Scipy methods normally select variable timesteps themselves based
on solution smoothness and tolerance parameters, but it’s possible to get
solve_ivp to run a post-processing step on the solution to produce equally
spaced output points.
The plots here show solutions for the steady and oscillatory test cases for the original explicit Euler method and the Radau, BDF and LSODA integrators from Scipy. Three important physical quantities (vertical position , crystal mass and vertical velocity ) are plotted for each case and each integrator.
At the scale of these plots (which are at a scale where physically meaningful differences would be visible), results from the Scipy integrators are essentially indistinguishable from the explicit Euler results for both test cases.
Native solver output times
As noted above, the Scipy integrators do not naturally produce output points at a fixed timestep. The comparison in the previous section is there simply to do a like-for-like comparison with the explicit Euler method. For real applications, we will use the natural output times from the Scipy integrators. These are generally much sparser that the Δt = 0.02s output of the explicit Euler method.
The plots below show the same trajectories as above for the Scipy integrators, but here we show exactly the output points the solvers produce to give some idea of this sparseness: a few hundred output points instead of 900,000 for the oscillatory case.
Integration time
The timings here are approximate wall-clock times. For the Scipy integrators, each bar is the median of three full simulations. For the explicit Euler method, the times are projected from shorter calculations, because the method is very slow. A logarithmic -axis is needed to be able to display the explicit Euler timings alongside the Scipy integrator times.
For the Scipy integrators, the fixed-output integrations have to do more work just because of the final fixed timestep interpolation. Otherwise, the most striking thing here is the enormous difference between the explicit Euler method and the Scipy integrators: this is all down to the stiffness of the model and the requirement to use a tiny timestep with the Euler method.
From these results, either the BDF or LSODA methods would be a good choice for future experiments.