[Scilab-users] Sundials ode solvers

Stéphane Mottelet stephane.mottelet at utc.fr
Fri Dec 17 18:29:02 CET 2021


Dear Scilab users,

A new version 0.2 of sci-sundials has been just released:

https://atoms.scilab.org/toolboxes/sci_sundials/0.2

Among other internal improvements and code factorization

-the differential-algebraic solver IDA is now available
-the documentation is now exhaustive about the features of solvers and 
the options

There has been an important change in the api. For example for CVODE, 
the two gateways cvode_solve() and cvode_extend() have been fused in 
cvode() and the extension is done by giving the solution as first argument:

             [t,y] = cvode(f,tspan,y0,options)
             [t,y,te,ye,ie] = cvode(f,tspan,y0,options)
             sol = cvode(...)
             solext = cvode(sol,tfinal,options)

Still no gateway for ARKODE but I will now focus on the upgrade of 
SUNDIALS in Sscilab itself.

Merry Christmas (in advance).

S.

Le 25/10/2021 à 16:35, Stéphane Mottelet a écrit :
>
> Hi all,
>
> As discussed in this thread last month
>
> https://www.mail-archive.com/users@lists.scilab.org/msg10679.html
>
> I am glad to annouce that a first version of the  sci-sundials toolbox 
> (maybe part of Scilab in the future) is available on Atoms in the 
> "Differential Equations" category (refresh the package list if you 
> don't see it).  To have an idea of its features I pasted below the 
> content of the README.md file on the gitlab project of sci-sundials 
> (https://gitlab.com/mottelet/sci-sundials/).
>
> If you appreciate the work and want to help, doc, demos, or even more 
> if you know how to code in C and C++ you are welcome !
>
> S.
>
>
>     What has been done and what is to be done
>
> Until now only CVODE has been interfaced but many common features have 
> been developped in the OdeManager class, hence interfacing IDA will be 
> quite easy. ARKODE (various modern explicit, implicit and mixed 
> explicit/implicit Runge-Kutta solvers) does not exist in the old 2.4.0 
> version of Sundials which is used in Scilab hence won't be interfaced 
> unless an upgrade is done (Sundials is now at version 5.7.0). The 
> support of Sparse Jacobians is also missing for the same reason.
>
>
>     Features
>
> The CVODE gateway cvode_solve() implements the following features 
> which were missing by the legacy LSODE/LSODA/LSODAR/... ode() gateway :
>
>   * full a posteriori access to solver continuous extension of
>     solution at arbitrary points via a MList output when only one lhs
>     is given:
>
> |sol = cvode_solve(f, [t0 tf], y0) t = linspace(t0, tf, 1000) plot(t, 
> sol(t)) |
>
> The |sol| MList fields gathers all information related to the obtained 
> solution (time steps, solution at time steps, events, ...). The solver 
> can be restarted by giving the MLlist as first argument to 
> |cvode_extend| :
>
> |sol2 = cvode_extend(sol, tx, ...)|
>
> where |tx| is the time point to which solution has to be extended. The 
> options of the call that yielded |sol| are used and can be changed as 
> optional named parameters after |tx|.
>
>   * a user-friendly access to solver options via optional named
>     parameters in cvode_solve call, i.e.
>
> |cvode_solve(f, tspan, y0, h0=0.01, rtol=1e-3)|
>
>   * a really simpler way to give time span of integration allowing to
>     choose between error driven solver internal time steps and user
>     fixed time steps, i.e.
>
> |[t,y] = cvode_solve(f, [t0 tf], y0) [t,y] = cvode_solve(f, [t0 t1 ... 
> tf], y0) [t,t] = cvode_solve(f, tspan, y0, t0=0)|
>
> the latter style being the closest to actual |ode()| behavior where 
> solution is by default given at user time steps and |t0| is not 
> necessarily equal to |tspan(1)|, which is the default in the two 
> former calls above.
>
>   * a better and user-friendly specification of events via a variable
>     number of outputs event function (giving value of event equations,
>     wheter to stop integration for a given event and event direction
>     selection), minimal style beeing a single output. Information
>     about events is also simpler to get:
>
> |function [eq,term,dir] = evfun(t,y) eq = y(1)-1.7; term = %f; dir = 
> 1; end [t,y,te,ye,ie] = cvode_solve(f, tspan, y0, events = evfun) sol 
> = cvode_solve(f, tspan, y0, events = evfun)|
>
> in the latter call information about events is recovered in 
> |sol.te,sol.ye,sol.ie|.
>
>   * support of complex solution with detection of complexity in |y0|
>     or |f(t0,y0)|, e.g.
>
> |function out = crhs(t,y) out = 10*exp(2*%i*%pi*t)*y; end [t,y] = 
> cvode_solve(crhs, [0,5], 1) plot(t,real(y),t,imag(y))|
>
>   * Support of a callback function called after each successfull step,
>     giving access to current solver statistics and allowing to stop
>     integration (e.g. by a "stop" button on a GUI), e.g.
>
> |function stop = scicallback(t,y,flag,stats) stop = %f if flag == 
> "step" mprintf("%s : hlast=%g\n", flag, stats.hlast) end end [t,y] = 
> cvode_solve(f, tspan, y0, intcb=scicallback);|
>
>   * support of an arbitrary number of dimensions of ode state
>
>
>     Performance
>
> |cvode_solve()| is roughly two times faster than |ode()| for both 
> fixed methods (Adams and BDF). As |ode()| already did, compiled and 
> dynamically linked C,C++ or Fortran externals are supported by 
> |cvode_solve()|. When using such externals instead of Scilab functions 
> |cvode_solve()| is generally an order of magnitude faster.
>
> -- 
> Stéphane Mottelet
> Ingénieur de recherche
> EA 4297 Transformations Intégrées de la Matière Renouvelable
> Département Génie des Procédés Industriels
> Sorbonne Universités - Université de Technologie de Compiègne
> CS 60319, 60203 Compiègne cedex
> Tel : +33(0)344234688
> http://www.utc.fr/~mottelet
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> https://antispam.utc.fr/proxy/v3?i=cWdzUmRSM0ZiRHpoUDkxTSw3-90dQgKDkqmWWemZ6js&r=WXNQOUY5VXRSNUlTdlVTTgAgPzRHrDev93-c71JTxG3gYERdftx8enpEGCicW5Zy&f=R0pWUVNEaUFuMTBCTlptbqaYxU0NWnHz-Aov_fSSM1D4vfIz2L0jb50-moW0RphD&u=http%3A//lists.scilab.org/mailman/listinfo/users&k=8YLU

-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20211217/e658cd8b/attachment.htm>


More information about the users mailing list