Struct bacon_sci::ivp::RK45

source ·
pub struct RK45<N, const S: usize>where
    N: ComplexField + FromPrimitive,
    <N as ComplexField>::RealField: FromPrimitive,{ /* private fields */ }
Expand description

Runge-Kutta-Fehlberg method for solving an IVP.

Defines the Butch Tableaux for a 5(4) order adaptive runge-kutta method. Uses RKInfo to do the actual solving. Provides an interface for setting the conditions on RKInfo.

Examples

use nalgebra::SVector;
use bacon_sci::ivp::{RK45, RungeKuttaSolver};
fn derivatives(_t: f64, state: &[f64], _p: &mut ()) -> Result<SVector<f64, 1>, String> {
    Ok(SVector::<f64, 1>::from_column_slice(state))
}

fn example() -> Result<(), String> {
    let rk45 = RK45::new()
        .with_dt_max(0.1)?
        .with_dt_min(0.001)?
        .with_start(0.0)?
        .with_end(10.0)?
        .with_tolerance(0.0001)?
        .with_initial_conditions(&[1.0])?
        .build();
    let path = rk45.solve_ivp(derivatives, &mut ())?;
    for (time, state) in &path {
        assert!((time.exp() - state.column(0)[0]).abs() < 0.001);
    }
    Ok(())
}

Implementations§

source§

impl<N, const S: usize> RK45<N, S>where N: ComplexField + FromPrimitive + Copy, <N as ComplexField>::RealField: FromPrimitive + Copy,

source

pub fn new() -> Self

Trait Implementations§

source§

impl<N, const S: usize> Clone for RK45<N, S>where N: ComplexField + FromPrimitive + Clone, <N as ComplexField>::RealField: FromPrimitive,

source§

fn clone(&self) -> RK45<N, S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N, const S: usize> Debug for RK45<N, S>where N: ComplexField + FromPrimitive + Debug, <N as ComplexField>::RealField: FromPrimitive,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<N, const S: usize> From<RK45<N, S>> for RKInfo<N, S, 6>where N: ComplexField + FromPrimitive, <N as ComplexField>::RealField: FromPrimitive,

source§

fn from(rk: RK45<N, S>) -> RKInfo<N, S, 6>

Converts to this type from the input type.
source§

impl<N, const S: usize> RungeKuttaSolver<N, S, 6> for RK45<N, S>where N: ComplexField + FromPrimitive + Copy, <N as ComplexField>::RealField: FromPrimitive + Copy,

source§

fn t_coefficients() -> SVector<N::RealField, 6>

Returns a vec of coeffecients to multiply the time step by when getting intermediate results. Upper-left portion of Butch Tableaux
source§

fn k_coefficients() -> SMatrix<N::RealField, 6, 6>

Returns the coefficients to use on the k_i’s when finding another k_i. Upper-right portion of the Butch Tableax. Should be an NxN-1 matrix, where N is the order of the Runge-Kutta Method (Or order+1 for adaptive methods)
source§

fn avg_coefficients() -> SVector<N::RealField, 6>

Coefficients to use when calculating the final step to take. These are the weights of the weighted average of k_i’s. Bottom portion of the Butch Tableaux. For adaptive methods, this is the first row of the bottom portion.
source§

fn error_coefficients() -> SVector<N::RealField, 6>

Coefficients to use on the k_i’s to find the error between the two orders of Runge-Kutta methods. In the Butch Tableaux, this is the first row of the bottom portion minus the second row.
source§

fn solve_ivp<T, F>( self, f: F, params: &mut T ) -> Result<Vec<(N::RealField, SVector<N, S>)>, String>where T: Clone, F: FnMut(N::RealField, &[N], &mut T) -> Result<SVector<N, S>, String>,

Ideally, call RKInfo.solve_ivp
source§

fn with_tolerance(self, tol: N::RealField) -> Result<Self, String>

Set the error tolerance for this solver.
source§

fn with_dt_max(self, max: N::RealField) -> Result<Self, String>

Set the maximum time step for this solver.
source§

fn with_dt_min(self, min: N::RealField) -> Result<Self, String>

Set the minimum time step for this solver.
source§

fn with_start(self, t_initial: N::RealField) -> Result<Self, String>

Set the initial time for this solver.
source§

fn with_end(self, t_final: N::RealField) -> Result<Self, String>

Set the end time for this solver.
source§

fn with_initial_conditions(self, start: &[N]) -> Result<Self, String>

Set the initial conditions for this solver.
source§

fn build(self) -> Self

Build this solver.

Auto Trait Implementations§

§

impl<N, const S: usize> RefUnwindSafe for RK45<N, S>where N: RefUnwindSafe, <N as ComplexField>::RealField: RefUnwindSafe,

§

impl<N, const S: usize> Send for RK45<N, S>

§

impl<N, const S: usize> Sync for RK45<N, S>

§

impl<N, const S: usize> Unpin for RK45<N, S>where N: Unpin, <N as ComplexField>::RealField: Unpin,

§

impl<N, const S: usize> UnwindSafe for RK45<N, S>where N: UnwindSafe, <N as ComplexField>::RealField: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.