# Control of Time-Step size in OrdinaryDiffEq

**URL:** <https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949>\
**Category:** Numerics\
**Tags:** ordinarydiffeq\
**Created:** [July 28, 2022, 11:10pm UTC](https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949 "2022-07-28T23:10:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Whyborn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/whyborn/32/34755_2.png) [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Post date:** [July 28, 2022, 11:10pm UTC](https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949/1 "2022-07-28T23:10:07Z")

</div>

Hi,

I am trying to use OrdinaryDiffEq for the time integration of a hyperbolic PDE system in a finite-volume context. I want to control the size of the time-step through a CFL condition, rather than by some error norm. The calculation of this desired time-step is simple for a given state U, but I can’t see a way to specify that time-step to the solver.

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [July 29, 2022, 3:23am UTC](https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949/2 "2022-07-29T03:23:33Z")

</div>

There’s an implementation of a CFL-based stepsize controller via a DiscreteCallback in [12 Explicit time stepping · Trixi.jl](https://trixi-framework.github.io/Trixi.jl/dev/tutorials/time_stepping/#CFL-based-step-size-control).

---

<div class="post-metadata">

**Author:** ![Whyborn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/whyborn/32/34755_2.png) [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Post date:** [July 29, 2022, 6:46pm UTC](https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949/3 "2022-07-29T18:46:56Z")

</div>

Based on their implementation, it looks like one can simply set the “dt” attribute for the integrator in a callback function?

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [July 29, 2022, 9:59pm UTC](https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949/4 "2022-07-29T21:59:20Z")

</div>

Yup, using the DiscreteCallback from the DiffEqCallbackLibrary should let you do this through the integrator interface.

---

<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:** [July 29, 2022, 11:39pm UTC](https://discourse.julialang.org/t/control-of-time-step-size-in-ordinarydiffeq/84949/5 "2022-07-29T23:39:52Z")

</div>

This callback in the library specifically: [GitHub - SciML/DiffEqCallbacks.jl: A library of useful callbacks for hybrid scientific machine learning (SciML) with augmented differential equation solvers](https://github.com/SciML/DiffEqCallbacks.jl#stepsizelimiter)
