# Storing stationary points during solving

**URL:** <https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258>\
**Category:** Modelling & Simulations\
**Created:** [March 1, 2022, 8:09pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258 "2022-03-01T20:09:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)\
**Post date:** [March 1, 2022, 8:09pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258/1 "2022-03-01T20:09:04Z")

</div>

In our library of SIR models (see e.g. [https://github.com/epirecipes/sir-julia/blob/master/markdown/ode/ode.md](https://github.com/epirecipes/sir-julia/blob/master/markdown/ode/ode.md)), 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)?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 2, 2022, 12:15pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258/2 "2022-03-02T12:15:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)\
**Post date:** [March 2, 2022, 4:05pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258/3 "2022-03-02T16:05:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 2, 2022, 4:41pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258/4 "2022-03-02T16:41:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)\
**Post date:** [March 2, 2022, 7:22pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258/5 "2022-03-02T19:22:44Z")

</div>

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})`?

---

<div class="post-metadata">

**Author:** ![vettert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vettert/32/30599_2.png) [@vettert](https://discourse.julialang.org/u/vettert)\
**Post date:** [March 2, 2022, 7:59pm UTC](https://discourse.julialang.org/t/storing-stationary-points-during-solving/77258/6 "2022-03-02T19:59:10Z")

</div>

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/](https://diffeq.sciml.ai/stable/basics/integrator/)

Specifically this line:

```julia

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

```
