pub struct AdamsPredictorCorrector<E, F, T: Real, V: State<T>, D: CallBackData, const S: usize> {
pub h0: T,
pub tol: T,
pub h_max: T,
pub h_min: T,
pub max_steps: usize,
pub stages: usize,
/* private fields */
}Fields§
§h0: T§tol: T§h_max: T§h_min: T§max_steps: usize§stages: usizeImplementations§
Source§impl<T: Real, V: State<T>, D: CallBackData> AdamsPredictorCorrector<Ordinary, Adaptive, T, V, D, 4>
impl<T: Real, V: State<T>, D: CallBackData> AdamsPredictorCorrector<Ordinary, Adaptive, T, V, D, 4>
Sourcepub fn v4() -> Self
pub fn v4() -> Self
The Adams-Predictor-Corrector method is an explicit method that uses the previous states to predict the next state. This implementation uses a variable step size to maintain a desired accuracy. It is recommended to start with a small step size so that tolerance can be quickly met and the algorithm can adjust the step size accordingly.
The First 3 steps are calculated using the Runge-Kutta method of order 4(5) and then the Adams-Predictor-Corrector method is used to calculate the remaining steps until the final time./ Create a Adams-Predictor-Corrector 4th Order Variable Step Size Method instance.
§Example
use differential_equations::prelude::*;
use nalgebra::{SVector, vector};
struct HarmonicOscillator {
k: f64,
}
impl ODE<f64, SVector<f64, 2>> for HarmonicOscillator {
fn diff(&self, _t: f64, y: &SVector<f64, 2>, dydt: &mut SVector<f64, 2>) {
dydt[0] = y[1];
dydt[1] = -self.k * y[0];
}
}
let mut apcv4 = AdamsPredictorCorrector::v4();
let t0 = 0.0;
let tf = 10.0;
let y0 = vector![1.0, 0.0];
let system = HarmonicOscillator { k: 1.0 };
let results = ODEProblem::new(system, t0, tf, y0).solve(&mut apcv4).unwrap();
let expected = vector![-0.83907153, 0.54402111];
assert!((results.y.last().unwrap()[0] - expected[0]).abs() < 1e-6);
assert!((results.y.last().unwrap()[1] - expected[1]).abs() < 1e-6);§Warning
This method is not suitable for stiff problems and can results in extremely small step sizes and long computation times.```
Source§impl<T: Real, V: State<T>, D: CallBackData> AdamsPredictorCorrector<Ordinary, Fixed, T, V, D, 4>
impl<T: Real, V: State<T>, D: CallBackData> AdamsPredictorCorrector<Ordinary, Fixed, T, V, D, 4>
Sourcepub fn f4(h: T) -> Self
pub fn f4(h: T) -> Self
Adams-Predictor-Corrector 4th Order Fixed Step Size Method.
The Adams-Predictor-Corrector method is an explicit method that uses the previous states to predict the next state.
The First 3 steps, of fixed step size h, are calculated using
the Runge-Kutta method of order 4(5) and then the Adams-Predictor-Corrector
method is used to calculate the remaining steps until the final time.
§Example
use differential_equations::prelude::*;
use nalgebra::{SVector, vector};
struct HarmonicOscillator {
k: f64,
}
impl ODE<f64, SVector<f64, 2>> for HarmonicOscillator {
fn diff(&self, _t: f64, y: &SVector<f64, 2>, dydt: &mut SVector<f64, 2>) {
dydt[0] = y[1];
dydt[1] = -self.k * y[0];
}
}
let mut apcf4 = AdamsPredictorCorrector::f4(0.01);
let t0 = 0.0;
let tf = 10.0;
let y0 = vector![1.0, 0.0];
let system = HarmonicOscillator { k: 1.0 };
let results = ODEProblem::new(system, t0, tf, y0).solve(&mut apcf4).unwrap();
let expected = vector![-0.83907153, 0.54402111];
assert!((results.y.last().unwrap()[0] - expected[0]).abs() < 1e-2);
assert!((results.y.last().unwrap()[1] - expected[1]).abs() < 1e-2);§Settings
h- Step Size
Source§impl<E, F, T: Real, V: State<T>, D: CallBackData, const S: usize> AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T: Real, V: State<T>, D: CallBackData, const S: usize> AdamsPredictorCorrector<E, F, T, V, D, S>
Trait Implementations§
Source§impl<E, F, T: Real, V: State<T>, D: CallBackData, const S: usize> Default for AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T: Real, V: State<T>, D: CallBackData, const S: usize> Default for AdamsPredictorCorrector<E, F, T, V, D, S>
Source§impl<T: Real, V: State<T>, D: CallBackData> Interpolation<T, V> for AdamsPredictorCorrector<Ordinary, Adaptive, T, V, D, 4>
impl<T: Real, V: State<T>, D: CallBackData> Interpolation<T, V> for AdamsPredictorCorrector<Ordinary, Adaptive, T, V, D, 4>
Source§impl<T: Real, V: State<T>, D: CallBackData> Interpolation<T, V> for AdamsPredictorCorrector<Ordinary, Fixed, T, V, D, 4>
impl<T: Real, V: State<T>, D: CallBackData> Interpolation<T, V> for AdamsPredictorCorrector<Ordinary, Fixed, T, V, D, 4>
Source§impl<T: Real, V: State<T>, D: CallBackData> OrdinaryNumericalMethod<T, V, D> for AdamsPredictorCorrector<Ordinary, Adaptive, T, V, D, 4>
impl<T: Real, V: State<T>, D: CallBackData> OrdinaryNumericalMethod<T, V, D> for AdamsPredictorCorrector<Ordinary, Adaptive, T, V, D, 4>
Source§fn init<F>(
&mut self,
ode: &F,
t0: T,
tf: T,
y0: &V,
) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
fn init<F>(
&mut self,
ode: &F,
t0: T,
tf: T,
y0: &V,
) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
Source§fn step<F>(&mut self, ode: &F) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
fn step<F>(&mut self, ode: &F) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
Source§fn set_status(&mut self, status: Status<T, V, D>)
fn set_status(&mut self, status: Status<T, V, D>)
Source§impl<T: Real, V: State<T>, D: CallBackData> OrdinaryNumericalMethod<T, V, D> for AdamsPredictorCorrector<Ordinary, Fixed, T, V, D, 4>
impl<T: Real, V: State<T>, D: CallBackData> OrdinaryNumericalMethod<T, V, D> for AdamsPredictorCorrector<Ordinary, Fixed, T, V, D, 4>
Source§fn init<F>(
&mut self,
ode: &F,
t0: T,
tf: T,
y0: &V,
) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
fn init<F>(
&mut self,
ode: &F,
t0: T,
tf: T,
y0: &V,
) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
Source§fn step<F>(&mut self, ode: &F) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
fn step<F>(&mut self, ode: &F) -> Result<Evals, Error<T, V>>where
F: ODE<T, V, D>,
Source§fn set_status(&mut self, status: Status<T, V, D>)
fn set_status(&mut self, status: Status<T, V, D>)
Auto Trait Implementations§
impl<E, F, T, V, D, const S: usize> Freeze for AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T, V, D, const S: usize> RefUnwindSafe for AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T, V, D, const S: usize> Send for AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T, V, D, const S: usize> Sync for AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T, V, D, const S: usize> Unpin for AdamsPredictorCorrector<E, F, T, V, D, S>
impl<E, F, T, V, D, const S: usize> UnwindSafe for AdamsPredictorCorrector<E, F, T, V, D, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.