Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Solving the problem

Each solver implements the OdeSolverMethod trait, which provides a number of high-level methods to solve the problem.

  • solve - solve the problem from an initial state up to a specified time, returning the solution at all the internal timesteps used by the solver.
  • solve_dense - solve the problem from an initial state, returning the solution at a Vec of times provided by the user.

The following example shows how to solve a simple ODE problem up to \(t=10\) using the solve method on the OdeSolverMethod trait. The solver will return the solution at all the internal timesteps used by the solver (_ys), as well as the timesteps used by the solver (_ts). The solution is returned as a matrix whose columns are the solution at each timestep.

use crate::{T, V};
use diffsol::{OdeEquations, OdeSolverMethod};

pub fn solve<'a, Solver, Eqn>(solver: &mut Solver)
where
    Solver: OdeSolverMethod<'a, Eqn>,
    Eqn: OdeEquations<T = T, V = V> + 'a,
{
    let (_ys, _ts) = solver.solve(10.0).unwrap();
}

solve_dense will solve a problem from an initial state, returning the solution as a matrix whose columns are the solution at each timestep in times.

use crate::{T, V};
use diffsol::{OdeEquations, OdeSolverMethod};

pub fn solve_dense<'a, Solver, Eqn>(solver: &mut Solver)
where
    Solver: OdeSolverMethod<'a, Eqn>,
    Eqn: OdeEquations<T = T, V = V> + 'a,
{
    let times = vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
    let _soln = solver.solve_dense(&times).unwrap();
}