packages

ode::problems

Standard test problems with their exact Jacobians and reference values: the stiff ones from Hairer and Wanner (Solving ODEs II, IV.10) and the IVP test set of Mazzia and Magherini, plus Lorenz, the Kepler problem and an N-body cluster for the non-stiff and symplectic integrators.

Structs

ProblemSource

pub struct Problem

A test problem: y' = f(t, y) from y0 over span, jac its exact Jacobian, reference the solution at span.end (as far as it is known; empty otherwise).

nabi
use ode::{Jacobian, Method};

let p = ode::problems::robertson();
let r = try ode::solve_ivp(p.f, p.span, p.y0, method: Method::Bdf, rtol: 1e-6, atol: [1e-8, 1e-12, 1e-8], jac: Jacobian::Exact(p.jac));
assert((r.last()[0] - p.reference[0]).abs() < 1e-5);
  • pub f: fn(f64, Vector<f64>) -> Vector<f64>§

    Source

    The right-hand side.

  • pub jac: fn(f64, Vector<f64>) -> Matrix<f64>§

    Source

    df/dy.

  • pub y0: Vector<f64>§

    Source

    The initial value.

  • pub span: Range<f64>§

    Source

    The time span.

  • pub reference: Vector<f64>§

    Source

    The solution at span.end.

Functions

robertsonSource

pub fn robertson() -> Problem

Robertson's chemical kinetics (1966), stiff, over 0..1e11 (reference from Radau at rtol 1e-13).

nabi
let p = ode::problems::robertson();
assert(p.y0.len() == 3 && p.span.end == 1e11);

van_der_polSource

pub fn van_der_pol(mu: f64) -> Problem

Van der Pol's oscillator y'' = mu (1 - y^2) y' - y as a system, from [2, 0], stiff for large mu; over 0..3000 for mu = 1000 (with its reference), 0..20 otherwise (no reference).

nabi
let p = ode::problems::van_der_pol(1000.0);
assert(p.reference.len() == 2);

hiresSource

pub fn hires() -> Problem

HIRES, eight reactions of plant physiology (Schafer 1975), over 0..321.8122; reference from the IVP test set.

nabi
assert(ode::problems::hires().y0.len() == 8);

oregonatorSource

pub fn oregonator() -> Problem

The Oregonator, Field and Noyes' model of the Belousov-Zhabotinsky reaction, over 0..360; reference from the IVP test set.

nabi
assert(ode::problems::oregonator().reference[1] > 1000.0);

lorenzSource

pub fn lorenz() -> Problem

Lorenz's convection model with the classic sigma = 10, rho = 28, beta = 8/3, from [1, 1, 1] over 0..10 (chaotic: the reference from DOP853 at rtol 1e-13 holds a few digits).

nabi
assert(ode::problems::lorenz().span.end == 10.0);

keplerSource

pub fn kepler(e: f64) -> (fn(Vector<f64>) -> Vector<f64>, Vector<f64>, Vector<f64>, fn(Vector<f64>, Vector<f64>) -> f64)

The Kepler problem q'' = -q / |q|^3 in the plane, from the pericentre of an orbit of eccentricity e with period 2 pi: q0 = [1 - e, 0], p0 = [0, sqrt((1 + e) / (1 - e))]. Returns the force (the acceleration), q0, p0 and the energy function, which is -1/2 on this orbit.

nabi
use core::array::Vector;

let (force, q0, p0, energy) = ode::problems::kepler(0.5);
assert((energy(q0, p0) + 0.5).abs() < 1e-15);

gravitySource

pub fn gravity(mass: List<f64>, eps: f64) -> fn(Vector<f64>) -> Vector<f64>

Gravitational acceleration of bodies point masses mass in 3-d, unit G, with Plummer softening eps: for q laid out as [x0, y0, z0, x1, ...]. O(bodies^2) per call.

nabi
use core::array::Vector;

let a = ode::problems::gravity([1.0, 1.0], 0.0);
let q: Vector<f64> = [0.0, 0.0, 0.0, 2.0, 0.0, 0.0];
assert(a(q)[0] == 0.25 && a(q)[3] == -0.25);