Struct BS23

Source
pub struct BS23<const L: usize, T: Real, V: State<T>, H: Fn(T) -> V, D: CallBackData> {
    pub h0: T,
    pub rtol: T,
    pub atol: T,
    pub h_max: T,
    pub h_min: T,
    pub max_steps: usize,
    pub safe: T,
    pub fac1: T,
    pub fac2: T,
    pub beta: T,
    pub max_delay: Option<T>,
    /* private fields */
}
Expand description

Bogacki-Shampine 3(2) method adapted for DDEs. 3rd order method with embedded 2nd order error estimation and 3rd order dense output (cubic Hermite interpolation). FSAL property.

§Example

use differential_equations::prelude::*;
use differential_equations::dde::methods::BS23;
use nalgebra::{Vector2, vector};

let mut bs23 = BS23::new()
   .rtol(1e-5)
   .atol(1e-5);

let t0 = 0.0;
let tf = 5.0;
let y0 = vector![1.0, 0.0];
let phi = |t| { // History function for t <= t0
    if t <= 0.0 { vector![1.0, 0.0] } else { panic!("phi called for t > t0") }
};
struct ExampleDDE;
impl DDE<1, f64, Vector2<f64>> for ExampleDDE {
    fn diff(&self, t: f64, y: &Vector2<f64>, yd: &[Vector2<f64>; 1], dydt: &mut Vector2<f64>) {
       dydt[0] = yd[0][1];
       dydt[1] = -yd[0][0] - 1.0 * y[1];
    }

    fn lags(&self, t: f64, y: &Vector2<f64>, lags: &mut [f64; 1]) {
        lags[0] = 1.0; // Constant delay tau = 1.0
    }
}
let problem = DDEProblem::new(ExampleDDE, t0, tf, y0, phi);
let solution = problem.solve(&mut bs23).unwrap();

let (t, y) = solution.last().unwrap();
println!("BS23 Solution at t={}: ({}, {})", t, y[0], y[1]);

§Settings (similar to BS23)

  • rtol, atol, h0, h_max, h_min, max_steps, safe, fac1, fac2, beta, max_delay.

§Default Settings (typical for BS23)

  • rtol - 1e-3
  • atol - 1e-6
  • h0 - None
  • h_max - None
  • h_min - 0.0
  • max_steps - 100_000
  • safe - 0.9
  • fac1 - 0.2 (1/5 for order 3, can be tuned)
  • fac2 - 10.0
  • beta - 0.0 (No PI stabilization by default for BS23, can be enabled)
  • max_delay - None

Fields§

§h0: T§rtol: T§atol: T§h_max: T§h_min: T§max_steps: usize§safe: T§fac1: T§fac2: T§beta: T§max_delay: Option<T>

Implementations§

Source§

impl<const L: usize, T: Real, V: State<T>, H: Fn(T) -> V, D: CallBackData> BS23<L, T, V, H, D>

Source

pub fn new() -> Self

Source

pub fn rtol(self, rtol: T) -> Self

Source

pub fn atol(self, atol: T) -> Self

Source

pub fn h0(self, h0: T) -> Self

Source

pub fn h_max(self, h_max: T) -> Self

Source

pub fn h_min(self, h_min: T) -> Self

Source

pub fn max_steps(self, max_steps: usize) -> Self

Source

pub fn safe(self, safe: T) -> Self

Source

pub fn fac1(self, fac1: T) -> Self

Source

pub fn fac2(self, fac2: T) -> Self

Source

pub fn beta(self, beta: T) -> Self

Source

pub fn max_delay(self, max_delay: T) -> Self

Trait Implementations§

Source§

impl<const L: usize, T: Real, V: State<T>, H: Fn(T) -> V, D: CallBackData> DDENumericalMethod<L, T, V, H, D> for BS23<L, T, V, H, D>

Source§

fn init<F>( &mut self, dde: &F, t0: T, tf: T, y0: &V, phi: H, ) -> Result<Evals, Error<T, V>>
where F: DDE<L, T, V, D>,

Initialize DDENumericalMethod before solving DDE. Read more
Source§

fn step<F>(&mut self, dde: &F) -> Result<Evals, Error<T, V>>
where F: DDE<L, T, V, D>,

Perform one integration step for the DDE. Read more
Source§

fn t(&self) -> T

Access time of the current state (end of the last accepted step).
Source§

fn y(&self) -> &V

Access solution state y at the current time t.
Source§

fn t_prev(&self) -> T

Access time at the beginning of the last accepted step.
Source§

fn y_prev(&self) -> &V

Access solution state y at the beginning of the last accepted step.
Source§

fn h(&self) -> T

Access the proposed step size h for the next step attempt.
Source§

fn set_h(&mut self, h: T)

Set the step size h for the next step attempt.
Source§

fn status(&self) -> &Status<T, V, D>

Get the current status of the solver (Solving, Complete, Error, etc.).
Source§

fn set_status(&mut self, status: Status<T, V, D>)

Set the status of the solver.
Source§

impl<const L: usize, T: Real, V: State<T>, H: Fn(T) -> V, D: CallBackData> Default for BS23<L, T, V, H, D>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const L: usize, T: Real, V: State<T>, H: Fn(T) -> V, D: CallBackData> Interpolation<T, V> for BS23<L, T, V, H, D>

Source§

fn interpolate(&mut self, t_interp: T) -> Result<V, Error<T, V>>

Interpolate between previous and current step Read more

Auto Trait Implementations§

§

impl<const L: usize, T, V, H, D> Freeze for BS23<L, T, V, H, D>
where T: Freeze, V: Freeze, D: Freeze, H: Freeze,

§

impl<const L: usize, T, V, H, D> RefUnwindSafe for BS23<L, T, V, H, D>

§

impl<const L: usize, T, V, H, D> Send for BS23<L, T, V, H, D>
where V: Send, D: Send, H: Send,

§

impl<const L: usize, T, V, H, D> Sync for BS23<L, T, V, H, D>
where V: Sync, D: Sync, H: Sync,

§

impl<const L: usize, T, V, H, D> Unpin for BS23<L, T, V, H, D>
where T: Unpin, V: Unpin, D: Unpin, H: Unpin,

§

impl<const L: usize, T, V, H, D> UnwindSafe for BS23<L, T, V, H, D>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.