Cvode Rust Wrap fork / merge
Go to file
2021-06-10 17:03:00 +02:00
cvode-5-sys Added support for cvode sensi 2021-06-10 15:11:53 +02:00
cvode-wrap Syntaxic switch, bugs remain 2021-06-10 17:03:00 +02:00
example Syntaxic switch, bugs remain 2021-06-10 17:03:00 +02:00
.gitignore Init 2021-05-07 18:29:56 +02:00
Cargo.toml Rename test-solver to example 2021-06-08 15:00:11 +02:00
Readme.md Simplify by removing wrapping at the cost of adding one more indirection 2021-06-09 16:06:15 +02:00

A wrapper around the sundials ODE solver.

Example

An oscillatory 2-D system.

use cvode_wrap::*;

let y0 = [0., 1.];
// define the right-hand-side as a rust function of type RhsF<Realtype, 2>
fn f(
  _t: Realtype,
   y: &[Realtype; 2],
   ydot: &mut [Realtype; 2],
   k: &Realtype,
) -> RhsResult {
    *ydot = [y[1], -y[0] * k];
    RhsResult::Ok
}
//initialize the solver
let mut solver = cvode::Solver::new(
    LinearMultistepMethod::Adams,
    wrapped_f,
    0.,
    &y0,
    1e-4,
    AbsTolerance::scalar(1e-4),
    1e-2,
)
.unwrap();
//and solve
let ts: Vec<_> = (1..100).collect();
println!("0,{},{}", y0[0], y0[1]);
for &t in &ts {
    let (_tret, &[x, xdot]) = solver.step(t as _, StepKind::Normal).unwrap();
    println!("{},{},{}", t, x, xdot);
}