Builder
Each vector, matrix or operation in diffsol has its own context, which is used to configure the number of batches (as well as other backend-specific information). You can create a new context with a set number of batches using the with_nbatch method of the context type (e.g. NalgebraContext::with_nbatch).
let context = NalgebraContext::with_nbatch(NBATCH);
Give this context to the OdeBuilder::context method to create a new OdeSolverProblem with the specified number of batches. When you set the parameters, give a vector of values of length nparams * nbatch. Diffsol splits this vector into nbatch blocks of length nparams, one block for each batch lane.
Note that you can ignore batching when specifying your rhs, init and other equation closures. Each closure will be called once for each batch lane and will handle the specific broadcasting rules used by diffsol. The input arguments for each closure are &[T] slices that correspond to a single batch lane. Each closure does not return a value. It writes its result into a mutable &mut [T] output slice argument for the same batch lane.
let problem = OdeBuilder::<M>::new()
.context(context)
// Two parameters per lane. Parameter blocks are stored end to end:
// [lane 0 p0, lane 0 p1, lane 1 p0, lane 1 p1, ...].
.p([1.0, 10.0, 2.0, 20.0, 3.0, 30.0])
.rhs(|y: &[f64], p: &[f64], _t: f64, dy: &mut [f64]| {
// y, p, and dy are slices for one batch lane.
dy[0] = p[0] * y[0] + p[1];
})
.init(|p: &[f64], _t: f64, y: &mut [f64]| y[0] = p[1], 1)
.build()
.unwrap();
assert_eq!(problem.context().nbatch(), NBATCH);
let mut solver = problem.tsit45().unwrap();
solver.step().unwrap();