Finished dopri5, interpolation, and callbacks

This commit is contained in:
Connor Johnstone
2023-03-14 16:55:06 -06:00
parent 75b88f7152
commit 43ec9eb0ac
9 changed files with 228 additions and 73 deletions

View File

@@ -3,12 +3,18 @@ use nalgebra::SVector;
use super::ode::ODE;
pub mod dormand_prince;
pub mod rosenbrock;
// pub mod rosenbrock;
/// Integrator Trait
pub trait Integrator<const D: usize> {
const ORDER: usize;
const STAGES: usize;
fn step(&mut self, ode: &ODE<D>, h: f64) -> (SVector<f64,D>, Option<f64>);
const ADAPTIVE: bool;
const DENSE: bool;
/// Returns a new y value, then possibly an error value, and possibly a dense output
/// coefficient set
fn step(&self, ode: &ODE<D>, h: f64) -> (SVector<f64,D>, Option<f64>, Option<Vec<SVector<f64, D>>>);
fn interpolate(&self, t_start: f64, t_end: f64, dense: &Vec<SVector<f64,D>>, t: f64) -> SVector<f64,D>;
}
@@ -27,13 +33,13 @@ mod tests {
let y0 = Vector3::new(1.0, 1.0, 1.0);
let mut ode = ODE::new(&derivative, 0.0, 4.0, y0);
let mut dp45 = DormandPrince45::new(1e-12_f64, 1e-4_f64);
let dp45 = DormandPrince45::new(1e-12_f64, 1e-4_f64);
// Test that y'(t) = y(t) solves to y(t) = e^t for rkf54
// and also that the error seems reasonable
let step = 0.0005;
let step = 0.001;
while ode.t < ode.t_end {
let (new_y, err) = dp45.step(&ode, step);
let (new_y, err, _) = dp45.step(&ode, step);
ode.y = new_y;
ode.t += step;
assert_relative_eq!(ode.y[0], ode.t.exp(), max_relative=0.01);