22 releases (4 breaking)

new 0.5.1 Dec 11, 2024
0.5.0 Nov 30, 2024
0.4.0 Nov 12, 2024
0.1.15 Jul 10, 2024
0.1.2 Feb 20, 2024

#126 in Math

Download history 26/week @ 2024-08-26 48/week @ 2024-09-02 33/week @ 2024-09-09 348/week @ 2024-09-16 134/week @ 2024-09-23 58/week @ 2024-09-30 7/week @ 2024-10-07 46/week @ 2024-10-14 173/week @ 2024-10-21 6/week @ 2024-10-28 43/week @ 2024-11-04 122/week @ 2024-11-11 17/week @ 2024-11-18 136/week @ 2024-11-25 21/week @ 2024-12-02

298 downloads per month
Used in 2 crates (via pharmsol)

MIT and GPL-3.0-or-later

710KB
18K SLoC

DiffSol

Diffsol is a library for solving ordinary differential equations (ODEs) or semi-explicit differential algebraic equations (DAEs) in Rust. You can use it out-of-the-box with vectors and matrices from the nalgebra or faer crates, or you can implement your own types by implementing the various vector and matrix traits in diffsol.

Features

DiffSol implements the following solvers:

  • A variable order Backwards Difference Formulae (BDF) solver, suitable for stiff problems and singular mass matrices.
  • A Singly Diagonally Implicit Runge-Kutta (SDIRK or ESDIRK) solver, suitable for moderately stiff problems and singular mass matrices. You can use your own butcher tableau or use one of the provided (tr_bdf2 or esdirk34).

All solvers feature:

  • adaptive step-size control to given tolerances,
  • dense output,
  • event handling,
  • stepping to specific times,
  • numerical quadrature of an optional output function over time
  • forward sensitivity analysis,
  • backwards or adjoint sensitivity analysis,

For comparison, the BDF solvers are similar to MATLAB's ode15s solver, the bdf solver in SciPy's solve_ivp function, or the BDF solver in SUNDIALS. The ESDIRK solver using the provided tr_bdf2 tableau is similar to MATLAB's ode23t solver.

Users can specify the equations to solve in the following ODE form, either using closures or the DiffSL Domain Specific Language (DSL):

M \frac{dy}{dt} = f(t, y, p)

where $M$ is a (possibly singular) mass matrix, $y$ is the state vector, $t$ is the time, $p$ is a vector of parameters, and $f$ is the right-hand side function. The mass matrix $M$ is optional (assumed to be the identity matrix if not provided).

Installation

See instructions on the crates.io page.

Usage

For more documentation and examples, see the API documentation.

Dependencies

~38–58MB
~1M SLoC