# Has anyone used DVODE and is it good?

**URL:** <https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281>\
**Category:** Uncategorized\
**Created:** [November 16, 2021, 9:08am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281 "2021-11-16T09:08:06Z")\
**Posts on this page:** 20\
**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:08am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/1 "2021-11-16T09:08:06Z")

</div>

Dear all,

Has anyone used DVODE to solve ODEs?

[https://www.radford.edu/~thompson/vodef90web/](https://www.radford.edu/~thompson/vodef90web/)

What is the drawback of DVODE? Is it slow or inaccurate or something?

Thank you very much in advance!

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [November 16, 2021, 10:00am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/2 "2021-11-16T10:00:44Z")

</div>

> [@CRquantum](#):
>
> What is the drawback of DVODE? Is it slow or inaccurate or something?

Hey @CRQuantum, I find it slightly demeaning to tacitly assume the code has some drawbacks. After all, the solver was developed by accomplished mathematicians including [Alan Hindmarsh](https://people.llnl.gov/hindmarsh1), which authored a dozen other ODE solvers. Perhaps you can search for the paper which introduced the method to learn what the authors had to say about it, and then check the papers which cited it.

If the code was developed a few decades ago it likely doesn’t follow the latest programming models or benefit from the latest compiler performance tweaks. Without specifying what are the alternatives, we are left with an [incomplete comparison](https://en.wikipedia.org/wiki/Incomplete_comparison).

Asking others about their experience with using a certain ODE solver code is of course more than welcome.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [November 16, 2021, 7:20pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/3 "2021-11-16T19:20:17Z")

</div>

Besides what @ivanpribec said, I believe dvode is also at the heart of the SciPy’s ODE integrator: [scipy.integrate.ode — SciPy v1.7.1 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html). So I would assume it is rather very good.

We should create an fpm package out of it, add examples how to use it and maintain under fortran-lang.

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [November 16, 2021, 7:26pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/4 "2021-11-16T19:26:49Z")

</div>

DVODE, DLSODE, and related are good. They need to be modernized. Unfortunately, it was done, but only by converting it to C ( [CVODE | Computing (llnl.gov)](https://computing.llnl.gov/projects/sundials/cvode)).

DDEABM is also similar: i have modernized that one: [jacobwilliams/ddeabm: Modern Fortran implementation of the DDEABM Adams-Bashforth algorithm (github.com)](https://github.com/jacobwilliams/ddeabm)

---

<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:32pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/5 "2021-11-16T21:32:38Z")

</div>

I’m sure DVODE is great. But, CVODE is probably the best maintained flavor of VODE, with a bunch of different matrix sparsity options. It’s written in C but has a good Fortran interface.

---

<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 17, 2021, 1:49am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/6 "2021-11-17T01:49:11Z")

</div>

Thank you all! @ivanpribec@certik @jacobwilliams @nicholaswogan

Yes @jacobwilliams,  
I actually have both @prince_mahajan 's FLINT and your DOP853 and DDEABM at hand. The structure of both of your code are similar, both are modernized. I learned a lot from your code!  
Perhaps according to FLINT’s benchmark, FLINT’s DOP853 is slightly faster. But I have not done through test myself.  
My plan is to put FLINT, your DOP853 and DDEABM inside a package I am developing (which needs solving ODE to make prediction), and also add at least an ODE solver for stiff problem. Currently I may just add the f90 version DVODE.

@jacobwilliams ,  
May I ask, what do you mean by modernized, Uhm, does that mean making Dvode object-oriented?  
Will that make DVODE faster?  
Thank you very much!

@nicholaswogan  
Thank you very much for your suggestion of CVODE, which is a part of Sundials. It should be great.  
Uhm, I currently may just try to use a Fortran ODE instead. It is relatively easy for me to use Sundials for my own research. But I am developing a package, adding Sundials inside my package may be a little bit not not too easy right now.

By the way, has anyone by any chance tried both DVODE and CVODE, if so, is CVODE faster than DVODE for the same ODEs?

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [November 17, 2021, 3:48am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/7 "2021-11-17T03:48:23Z")

</div>

> [@CRquantum](#):
>
> May I ask, what do you mean by modernized,

What we have done and agreed upon for other packages such as FFTPACK, modernize means: compile with fpm, use free form, possibly add into modules, ensure all interfaces are present, remove implicit typing, add tests, documentation, examples and so on.

---

<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 17, 2021, 4:44am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/8 "2021-11-17T04:44:40Z")

</div>

Time difference between CVODE and DVODE will depend on the problem but I’m guessing it will be small, like within a factor of 2. The exception is if you want to do some really big problem. Then CVODE will win/allow a solution to be calculated because it has stuff like GMRES.

---

<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 17, 2021, 7:30am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/9 "2021-11-17T07:30:29Z")

</div>

@certik @jacobwilliams  
Alright. Uhm, do you think the current DVODE by Byrne and Thompson is modernized? link is below,  
[File Listing (radford.edu)](https://www.radford.edu/~thompson/vodef90web/vodef90source/misc.html)

I have downloaded the DVODE.f90 distribution file there,  
 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/c/c0a81b4245e05dc9bf6c7a9c9a83efc0872fe948.png)

uhm, it seem it is somehow modernized a little bit.  
It uses module and f90 format, and implicit none.  
In windows it looks like below, and it can compile and run without problem,

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/5/5a54c02a82ec30fefe36a31eeb7704596bfe0d61.jpeg)

Seem not too bad.

---

<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:** [January 6, 2022, 1:47pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/10 "2022-01-06T13:47:59Z")

</div>

@CRquantum im not able to access the code via the link your originally posted. Do you know an alternative link?

---

<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:** [January 6, 2022, 6:56pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/11 "2022-01-06T18:56:38Z")

</div>

Thank you very much for the message @nicholaswogan ,  
true, strangely, the original link does not work any more. Fortunately, I have downloaded their whole website (the latest version) of dvode before.  
Now I pushed it to a new gitlab repo, you could download it from the link below,

> **[Chen Rong / DVODE\_backup](https://gitlab.com/CRquantum/dvode_backup#modal-create-new-dir)**
>
> It is a backup of DVODE from https://www.radford.edu/~thompson/vodef90web/vodef90source/misc.html

In the folder VODE\_F90 Support Page , double click index.html,  
then you should see the whole original website, and you can download all the corresponding files locally.  
Hope that helps 🙂

---

<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:** [January 6, 2022, 7:01pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/12 "2022-01-06T19:01:50Z")

</div>

I have not test the speed of dvode, but I guess it should not be too bad.  
dvode can handle both stiff and non-stiff problem.  
The only issue seems to be that dvode does not natively support interpolation.

---

<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:** [January 6, 2022, 7:40pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/13 "2022-01-06T19:40:22Z")

</div>

Thanks!! This looks great. I think the code does have interpolation. Section 5 of the documentation, which is all in `dvode_f90_m.f90`, talked about interpolation.

---

<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:** [January 6, 2022, 8:18pm UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/14 "2022-01-06T20:18:06Z")

</div>

Great! Thank you so much for letting me know! I did not read the file carefully enough LOL.  
Right, from line 1554 there are instructions about how to do interpolation using subroutine DVINDY.  
Then the dvode seems a quite versatile ODEs solver!

---

<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:** [January 8, 2022, 7:51am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/15 "2022-01-08T07:51:20Z")

</div>

Hi @nicholaswogan ,  
Have you by any chance tried the interpolation function in DVODE?  
It is the subroutine DVINDY.

It is a little strange that, I solve the ODE ( just say Y(t), I want Y at given t ) within the time t range, say from T0 to Tf.  
Then I can call DVINDY to interpolate Y for t\>Tf. (But this is strange, it is more like extrapolation than interpolation)

However , if I just want to interpolate Y at t within T0 to Tf, then DVINDY give me some error, something like t is not within the range like below,

```auto
Error in DVINDY, T(=R1) is illegal. T is not
In the above message, R1 = 0.6000000000000D+01
 in interval TCUR - HU(= R1) to TCUR(=R2)
In the above message, R1 = 0.2364435159699D+02 R2 = 0.7499440289459D+02

```

Just curious, have you meet similar issues?

I think DVINDY can correctly do interpolation, but I just do not know which part did I do is wrong… LOL.

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [January 8, 2022, 9:08am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/16 "2022-01-08T09:08:53Z")

</div>

The interpolation routine DVINDY has the following requirement, which is stated in the source code:

> For valid results, T must lie between TCUR - HU and TCUR.

In other words, if interpolation is desired, it should be performed after each successful integration step, which covers Tcur - Hu to Tcur (both evaluated with the current value of Tcur).

If, instead, you perform a number of successive integration steps and only then try to interpolate over the entire range of the independent variable, that will not be possible. The capability for doing that could have been provided, but that would have required a large amount of supporting information to be stored. At the time the software was published (1989), how much RAM did our PCs have?

You can verify for yourself the relation between T and Tcur by adding the following print statement at the beginning of subroutine DVINDY\_CORE:

```auto
print '(A,3ES12.4)','T, TP, TN = ',T,TP,TN

```

and running the two example problems in your Gitlab repository.

---

<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:** [January 9, 2022, 12:48am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/17 "2022-01-09T00:48:45Z")

</div>

Thank you very much @mecej4 !

1. 

What I want is, call DVODE between time [0, 24], then interpolate points at [0,2,4,6,8,10,…22,24].

So, I mean if I call

```auto
CALL DVODE_F90(..., T=0,TOUT=24,...)

```

Where T=0 is the initial time, TOUT=24 is the final time.  
So the integration is in the range of [0,24].  
I would expect then I should be able to do things like

```auto
CALL DVINDY(Time,...)

```

where Time should be within [0,24], am I right?

But DVINDY does not seem to interpolate as I said above.  
It seems after I do

```auto
CALL DVODE_F90(..., T,TOUT,...)

```

T becomes TOUT, then DVINDY can only interpolate at time between like [24-xxx, 24+yyy], such as [23, 75]. But Definitely not the original range [0,24] which is what I really want.

Overall, it seems DVINDY is not particularly useful. It can only interpolate at its own particular range TCUR - HU and TCUR. Instead of the original range [0,24].

I may just CALL DVODE\_F90 between [0,2], then [2,4], then [4,6], … [22,24].

1. 

Are you saying adding the print you mentioned at the position below in dvode\_f90\_m.f90?

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/c/cb6783fb6e636966285bbee45cfbbc7842d655b2.png)  
Line 6941 is where I added the print you mentioned.  
But here TP seems has not been calculated yet?

Or, do I add the print at line 6947 below?

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/c/cdd8f964d3ebfb24e199dbe0fdaa93c4ed4413c5.png)

1. 

> [@mecej4](#):
>
> If, instead, you perform a number of successive integration steps and only then try to interpolate over the entire range of the independent variable, that will not be possible. The capability for doing that could have been provided, but that would have required a large amount of supporting information to be stored.

Do you know if there is quick way that I can add something in DVODE so that all those points are stored? Then I guess DVINDY will be more useful.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [January 9, 2022, 1:57am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/18 "2022-01-09T01:57:51Z")

</div>

_Edit:_ the follow-up [post](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/19) from @mecej4 addresses the actual problem of output at regular intervals, without the need to call `DVINDY`.

* * *

> [@CRquantum](#):
>
> Overall, it seems DVINDY is not particularly useful. It can only interpolate at its own particular range TCUR - HU and TCUR. Instead of the original range [0,24].

To use interpolation you should consult the instructions under `itask` in `dvode` (original or \_f90):

```
! ITASK = An index specifying the task to be performed.
! Input only. ITASK has the following values and meanings.
! 1 means normal computation of output values of y(t) at
! t = TOUT (by overshooting and interpolating).
! 2 means take one step only and return.
! 3 means stop at the first internal mesh point at or
! beyond t = TOUT and return.
! 4 means normal computation of output values of y(t) at
! t = TOUT but without overshooting t = TCRIT.
! TCRIT must be input as RWORK(1). TCRIT may be equal to
! or beyond TOUT, but not behind it in the direction of
! integration. This option is useful if the problem
! has a singularity at or beyond t = TCRIT.
! 5 means take one step, without passing TCRIT, and return.
! TCRIT must be input as RWORK(1).

```

I assume you are currently using `itask = 1`. Probably you’d want to use 2 (or 5 in case you have a known singularity) and integrate in “one-step” mode. This is a fairly common pattern in classic Fortran ODE solvers.

A similar mechanism is used also in [RKC (Runge-Kutta-Chebyshev)](http://netlib.org/ode/rkc.f) with which I’m more familiar. The `rkc` subroutine has the interface:

```auto
      subroutine rkc(neqn,f,y,t,tend,rtol,atol,info,work,idid)

```

The array of integers `info` is used to control the procedure. Specifically `info(1)` fulfill the same role as `itask`:

```fortran
c INFO(1): RKC integrates the initial value problem from T to TEND. 
c This is done by computing approximate solutions at points 
c chosen automatically throughout [T, TEND]. Ordinarily RKC
c returns at each step with an approximate solution. These
c approximations show how y behaves throughout the interval.
c The subroutine RKCINT can be used to obtain answers anywhere
c in the span of a step very inexpensively. This makes it 
c possible to obtain answers at specific points in [T, TEND]
c and to obtain many answers very cheaply when attempting to
c locating where some function of the solution has a zero
c (event location). Sometimes you will be interested only in
c a solution at TEND, so you can suppress the returns at each
c step along the way if you wish.
c
c INFO(1) = 0 Return after each step on the way to TEND with a
c solution Y(*) at the output value of T.
c
c ` = 1 Compute a solution Y(*) at TEND only.
c

```

An example of integration with interpolation to produce output at regularly spaced time intervals can be found in [`rkc-exa.f`](http://netlib.org/ode/rkc-exa.f).

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [January 9, 2022, 2:10am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/19 "2022-01-09T02:10:08Z")

</div>

No, your expectations do not match the design of the VODE integrator package.

Look at the code in example1.f90 and see how it calls the integrator inside a loop. For your desired calculation you would have to set up a loop that is run 12 times, with Tout = 2, 4,…,24.

Note also that the driver program in example1.f90 does not itself call DVINDY. Such calls could be needed if, for example, you wanted to obtain many more values for plotting the solutions (which is sometimes labelled “dense output”).

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [January 9, 2022, 2:17am UTC](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281/20 "2022-01-09T02:17:21Z")

</div>

> [@mecej4](#):
>
> Note also that the driver program in example1.f90 does not itself call DVINDY. Such calls could be needed if, for example, you wanted to obtain many more values for plotting the solutions.

I think the purpose of DVINDY is actually to get derivatives of `y` as stated in this comment:

```
! CALL DVINDY(,,,,,) Provide derivatives of y, of various
! (See below.) orders, at a specified point T, if
! desired. It may be called only after
! a successful return from DVODE.

```

and not interpolation per se.

While the solution with `itask=2` might work, I agree with what @mecej4 just suggested.

[Next page](https://fortran-lang.discourse.group/t/has-anyone-used-dvode-and-is-it-good/2281.md?page=2)
