Storing stationary points during solving

In our library of SIR models (see e.g. sir-julia/ode.md at master · epirecipes/sir-julia · GitHub), I’m trying to store the maximum of one of the state variables (I); I don’t want to just calculate the maximum of the state using the output from the solution, as it doesn’t use interpolation. What’s the best way of doing this in the #sciml ecosystem using callbacks (e.g. storing u[2] when du[2]=0)?

Is there a reason to save in callbacks instead of using save_idxs here?

No specific reason - in my model I just need to store I(t) when dI/dt=0 as the model runs.

Just use a continuous callback on integrator(t,Val{1}) to get the derivatives and then save to some array in the affect!

Thanks - I was looking for examples that worked on derivatives rather than states, but couldn’t find any. What does the Val{1} mean in integrator(t,Val{1})?

The number in the brackets indicates which derivative you get from the integrator, so Val{1} means first derivative. The default is Val{0}, i.e, you get the state values.

Explained here:
https://diffeq.sciml.ai/stable/basics/integrator/

Specifically this line:


integrator(t,deriv::Type=Val{0};idxs=nothing,continuity=:left)

1 Like