2021-06-10 18:02:06 +02:00
2021-06-10 17:03:00 +02:00
2021-05-07 18:29:56 +02:00
2021-06-10 17:57:08 +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);
}
Description
Cvode Rust Wrap fork / merge
Readme 114 KiB
Languages
Rust 100%