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::massetc.)
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 thenalgebracrate dense matrix.FaerMat, this is a thin wrapper around thefaercrate dense matrix.FaerSparseMat, this is a thin wrapper around thefaersparse matrix.CudaMat, this is diffsol's CUDA matrix type (requires thecudafeature)
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.