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

The builder

The simplest way to create a new problem is to use the OdeBuilder struct. You can set many configuration options such as:

  • initial time (OdeBuilder::t0),
  • initial step size (OdeBuilder::h0)
  • relative tolerance (OdeBuilder::rtol)
  • absolute tolerance (OdeBuilder::atol)
  • parameters (OdeBuilder::p)
  • equations (OdeBuilder::rhs, OdeBuilder::init, OdeBuilder::mass etc.)

or leave them at their default values. Then, call the OdeBuilder::build method to create a OdeSolverProblem.

    type M = NalgebraMat<f64>;
    let _problem = OdeBuilder::<M>::new()
        .p(vec![1.0, 10.0])
        .rhs(|x, p, _t, y| y[0] = p[0] * x[0] * (1.0 - x[0] / p[1]))
        .init(|_p, _t, y| y.fill(0.1), 1)
        .build()
        .unwrap();

Note that the OdeBuilder struct has a generic parameter M, which defines the matrix type to use when solving the problem. This matrix type must satisfy the trait Matrix, and could be one of the matrix types included with diffsol:

  • NalgebraMat, this is a thin wrapper around the nalgebra crate dense matrix.
  • FaerMat, this is a thin wrapper around the faer crate dense matrix.
  • FaerSparseMat, this is a thin wrapper around the faer sparse matrix.
  • CudaMat, this is diffsol's CUDA matrix type (requires the cuda feature)

Each matrix type is parameterised by a scalar type that satisfies the Scalar trait, each matrix type also has an associated type that defines its corresponding vector type (bounded by the Vector trait). So whenever you create a builder you are also defining what matrix, vector and scalar types to use for the problem that you will create using that builder.