Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ readme = "README.md"
keywords =["numeric", "science", "integration", "quadrature"]
categories =["science"]

[dev-dependencies]
float-cmp = "0.9"
rand = "0.8"

[dependencies]
nalgebra = "0.32"
num-complex = "0.4"
Expand All @@ -25,3 +21,8 @@ typenum = "1.17"

[build-dependencies]
phf_codegen = "0.11"

[dev-dependencies]
float-cmp = "0.9"
rand = "0.8"
rstest = "0.26.1"
39 changes: 29 additions & 10 deletions src/ivp/rk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,14 @@ impl<N: ComplexField> RungeKuttaCoefficients<4> for RK23Coefficients<N> {
-Self::RealField::from_u8(5)? / Self::RealField::from_u8(72)?,
Self::RealField::from_u8(12)?.recip(),
Self::RealField::from_u8(9)?.recip(),
Self::RealField::from_u8(8)?.recip(),
-Self::RealField::from_u8(8)?.recip(),
]))
}
}

/// Bogacki-Shampine method for solving an IVP.
///
/// Defines the Butcher Tableaux for a 5(4) order adaptive
/// Defines the Butcher Tableaux for a 3(2) order adaptive
/// Runge-Kutta method. Uses [`RungeKutta`] to do the actual solving.
/// Provides an implementation of the [`IVPSolver`] trait.
///
Expand Down Expand Up @@ -659,6 +659,7 @@ pub type RungeKutta23<'a, N, D, T, F> = RungeKutta<'a, N, D, 4, T, F, RK23Coeffi
mod test {
use super::*;
use crate::{ivp::UserError, BSVector};
use rstest::rstest;

fn quadratic_deriv(t: f64, _y: &[f64], _: &mut ()) -> Result<BSVector<f64, 1>, UserError> {
Ok(BSVector::from_column_slice(&[-2.0 * t]))
Expand All @@ -668,13 +669,27 @@ mod test {
Ok(BSVector::from_column_slice(&[t.cos()]))
}

#[test]
fn rungekutta45_quadratic() {
type TestRK<'a, const O: usize, R> = RungeKutta<
'a,
f64,
Const<1>,
O,
(),
fn(f64, &[f64], &mut ()) -> Result<BVector<f64, Const<1>>, UserError>,
R,
>;

#[rstest]
#[case::rk23(RungeKutta23::new().unwrap())]
#[case::rk45(RungeKutta45::new().unwrap())]
fn rungekutta_quadratic<'a, const O: usize, R>(#[case] rk: TestRK<'a, O, R>)
where
R: RungeKuttaCoefficients<O, RealField = f64>,
{
let t_initial = 0.0;
let t_final = 10.0;

let solver = RungeKutta45::new()
.unwrap()
let solver = rk
.with_minimum_dt(0.0001)
.unwrap()
.with_maximum_dt(0.1)
Expand Down Expand Up @@ -703,13 +718,17 @@ mod test {
}
}

#[test]
fn rungekutta45_sine() {
#[rstest]
#[case::rk23(RungeKutta23::new().unwrap())]
#[case::rk45(RungeKutta45::new().unwrap())]
fn rungekutta_sine<'a, const O: usize, R>(#[case] rk: TestRK<'a, O, R>)
where
R: RungeKuttaCoefficients<O, RealField = f64>,
{
let t_initial = 0.0;
let t_final = 10.0;

let solver = RungeKutta45::new()
.unwrap()
let solver = rk
.with_minimum_dt(0.001)
.unwrap()
.with_maximum_dt(0.01)
Expand Down
Loading