Drasil icon indicating copy to clipboard operation
Drasil copied to clipboard

ODE solver libraries analysis

Open cd155 opened this issue 2 years ago • 3 comments

Currently, we use four ODE libraries to solve odes, and they are

  • python - Scipy library
  • Java - Apache Commons Math library
  • C# - Oslo library
  • C++ - odeint v2 library

Libraries Options similar to spline

Scipy library - Python

  • scipy.integrate.ode is more generic. It is a generic interface class. After returning to this class, we can set algorithm methods and initial values. It supports five different ode calculation methods (vode, zvode, lsoda, dopri5, dop853). We can ask this class to give a numerical point value at a certain time point. I think this is more close to a spline we talked about last week.

Oslo Microsoft library - C#

  • this library uses the Runge-Kutta method and Nordsieck's method, we use Runge-Kutta in nopcm
  • it has some options: it can return an enumerable sequence of solution points and it is an endless sequence of solution points.
  • later we can give a start time, finish time, and time step to a get a partial solution.

Libraries Options return points

Apache Commons Math library - Java

  • Multiple methods to solve ode, we use Dormand Prince method in nopcm.
  • Giving ode equations, method, start time, final time, and time step, it will return a list of double in each iteration. We can collect the list in each iteration.

Odeint Boost Library - C++

  • Multiple methods to solve ode, we use Runge-Kutta in nopcm
  • it is similar to Apache Commons Math library. Giving ode equations, method, start time, final time, and time step, it will return a list of double in each iteration.

Potential problem

To return a function or other object close to a function, there might be a problem with the return type. Currently, the return type is defined in the SRS. https://github.com/JacquesCarette/Drasil/blob/adfc15f13c7cf81101c1dbab97a6aa61f10a4ec6/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs#L415-L419 In nopcm example, tempW is a Vect Rational type, and it is the temperature of the water we want to calculate. Because we set it to Vect Rational type, the function for calculating tempW will return a list/array of numbers (this part happens in GOOL). We might have to change SRS to match the return type. However, based on the previous analysis for each library, their capability is different.

cd155 avatar May 12 '22 21:05 cd155

I recently made a summary of the availability of ODE's output types in four selected external libraries.

Screenshot from 2022-08-04 16-05-56

  • R^k means a finite sequence of real numbers
  • R^n means an infinite sequence of real numbers
  • -> means a function
  • ? means an unknown satisfied object
  • (? -> R)^n means a finite sequence of function(? -> R)

One thing I wasn't so sure about is whether the generic interface of scipy.integrate.ode can be represented as (? -> R)^n. The scipy.integrate.ode is a generic interface which contains the ODE equation. We can later add other configuration information to get a partial numerical solution base on initial values, time range, time step, and so on.

The reason I use the question mark (?) in (? -> R) is that I am not 100% sure how the Scipy library solves the ODE on the backend. I know the output of the function is a real number, but the input is unclear. @smiths

cd155 avatar Aug 04 '22 20:08 cd155

The output being a sequence of real numbers makes sense, but I don't understand the output of Scipy. If the output is a function, then shouldn't it be the function R -> R? The input is the independent variable, and the output is the value of dependent variable? In your case you are only solving for one dependent variable, I believe. In the case of coupled ODEs, the output would have a dimension greater than 1.

Maybe I'm missing something?

smiths avatar Aug 05 '22 02:08 smiths

Thanks for pointing it out. I think my approach is more code-oriented, and it turns out to be wrong. The output should be R -> R^i in Scipy.

Here is the updated table. Screenshot from 2022-08-04 23-19-04

cd155 avatar Aug 05 '22 03:08 cd155

This ticket seems discussed the same issue with #2975. I will make comments on #2975.

cd155 avatar Sep 19 '22 16:09 cd155