use crate::{Integrator, IvpFunction};
#[derive(Debug)]
pub struct ForwardEuler {
dt: f64,
}
impl ForwardEuler {
pub fn new(dt: f64) -> Self {
ForwardEuler { dt }
}
}
impl<F, const D: usize> Integrator<F, D> for ForwardEuler
where
F: IvpFunction<D>,
{
fn step(&mut self, f: &mut F, t: &mut f64, x: &mut [f64; D], xdot: &mut [f64; D]) {
let a = f.compute(t, x, xdot);
for i in 0..D {
x[i] += xdot[i] * self.dt; xdot[i] += a[i] * self.dt; }
*t += self.dt; }
fn get_dt(&self) -> f64 {
self.dt
}
fn set_dt(&mut self, value: f64) {
self.dt = value;
}
fn set_adaptive(&mut self, _: bool) {}
fn evaluations_per_step(&self) -> u16 {
1
}
}