# What is best ODE solver for stiff problem?

**URL:** <https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282>\
**Category:** Uncategorized\
**Created:** [November 16, 2021, 9:12am UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282 "2021-11-16T09:12:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [November 16, 2021, 9:12am UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/1 "2021-11-16T09:12:57Z")

</div>

Dear all,

I know @ivanpribec has a stiff3 ODE solver for stiff problem,

> **[GitHub - ivan-pi/stiff3: Adaptive solver for stiff systems of ODEs using...](https://github.com/ivan-pi/stiff3)**
>
> Adaptive solver for stiff systems of ODEs using semi-implicit Runge-Kutta method of third order - GitHub - ivan-pi/stiff3: Adaptive solver for stiff systems of ODEs using semi-implicit Runge-Kutta ...

Is there some other stiff ODE solver too?

@prince_mahajan point to Hairer solver too,

[http://www.unige.ch/~hairer/software.html](http://www.unige.ch/~hairer/software.html)

How is stiff3 algorithm compare with Hairer method? In terms of accuracy and speed?

Thank you very much in advance!

---

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://fortran-lang.discourse.group/u/martin)\
**Post date:** [November 16, 2021, 12:04pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/2 "2021-11-16T12:04:32Z")

</div>

DIRK solvers are rather thoroughly investigated in the recent paper

> **[20160005923.pdf](https://ntrs.nasa.gov/api/citations/20160005923/downloads/20160005923.pdf)**
>
> 1070.79 KB

Without any special needs, I found the suggested default solver “ESDIRK4(3)6L[2]SA” pretty good.  
Speed greatly depends on how fast the underlying implicit equation can be solved (by Newton?) and how good the adaptive time step control can be tuned.

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [November 16, 2021, 5:54pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/3 "2021-11-16T17:54:16Z")

</div>

Thank you @martin !  
Welcome to the community!

---

<div class="post-metadata">

**Author:** ![nicholaswogan](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nicholaswogan](https://fortran-lang.discourse.group/u/nicholaswogan)\
**Post date:** [November 16, 2021, 9:40pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/4 "2021-11-16T21:40:05Z")

</div>

> What is best ODE solver for stiff problem?

It depends on the problem. DifferentialEquations.jl has a great summary of recommended methods [https://diffeq.sciml.ai/stable/solvers/ode\_solve/#ode\_solve](https://diffeq.sciml.ai/stable/solvers/ode_solve/#ode_solve)

I do atmospheric chemical kinetics involving 10,000s ODEs, which are very stiff. For this problem, one of the best methods is [CVODE BDF](https://computing.llnl.gov/projects/sundials/cvode) with the banded matrix solver. CVODE is written in C but has an excellent Fortran interface.

---

<div class="post-metadata">

**Author:** ![Lapis17](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@Lapis17](https://fortran-lang.discourse.group/u/Lapis17)\
**Post date:** [August 15, 2023, 10:55am UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/7 "2023-08-15T10:55:12Z")

</div>

Have you tried SEULEX from Hairer? For my problem it seems to be 2-3 times faster than DVODE when its stiff and on par with it when its mildly or not stiff.

---

<div class="post-metadata">

**Author:** ![bendelBoy](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@bendelBoy](https://fortran-lang.discourse.group/u/bendelBoy)\
**Post date:** [August 17, 2023, 12:51pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/8 "2023-08-17T12:51:50Z")

</div>

I’ve had good results with ROCK2 from Hairer and RKC from Netlib. When they fail I tend to find MEBDF next best, followed by VODEPK. ‘Best code’ is probably ‘best code for my problem’, so you may need to try a variety.

---

<div class="post-metadata">

**Author:** ![Lapis17](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@Lapis17](https://fortran-lang.discourse.group/u/Lapis17)\
**Post date:** [August 18, 2023, 12:11pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/9 "2023-08-18T12:11:07Z")

</div>

@bendelBoy Would it be possible for you to provide a simple driver for MEBDF? I downloaded one from [here](https://archimede.uniba.it/~testset/solvers/mebdfdae.php) but cant seem to get it working properly.

---

<div class="post-metadata">

**Author:** ![bendelBoy](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@bendelBoy](https://fortran-lang.discourse.group/u/bendelBoy)\
**Post date:** [August 18, 2023, 1:32pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/10 "2023-08-18T13:32:01Z")

</div>

I’ve been using an older version, when the main routine was called STIFF.

Mine was taken from here – algorithm 703. [[Collected Algorithms of the ACM](https://netlib.org/toms/index.html)]. That includes a driver.

My own routine isn’t suitable – built around my need, with extensions to the original. I have lots of parameters that I pass through for use with an unsteady-state process simulator.

case (8) ! MBEDF with full Jacobian (8)  
mf = 22  
LOUT = 10 ! For error messages  
select case (m1(2))  
case (1, -1); index = 1  
case (2, -2); index = 2  
end select

TempOutput = OutputTime  
call DRIVER(ny, t0, m2(3), y, OutputTime, TempOutput,

- m2(1), MF, INDEX, LOUT, iw1,
- w(1), iw2 , w(iw1+1), MBND,
- np, ns, ni, nx, np1, np2, npi,
- o, z1, z2, s, p1, p2, pi, x, m1(5), m2(7), m3,
- w(iw3), w(iw4), StartTime, StopTime)

m1(4) = index ! Preserve original error code

---

<div class="post-metadata">

**Author:** ![Lapis17](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@Lapis17](https://fortran-lang.discourse.group/u/Lapis17)\
**Post date:** [August 18, 2023, 2:46pm UTC](https://fortran-lang.discourse.group/t/what-is-best-ode-solver-for-stiff-problem/2282/12 "2023-08-18T14:46:29Z")

</div>

Thanx! The netlib version works.
