ordinary-diffeq 0.2.3

A library for solving differential equations based on the DifferentialEquations.jl julia library.
Documentation
use nalgebra::SVector;

use super::ode::ODE;

/// A function that takes in a time and a state and outputs a single float value
///
/// The integration solver will check this function for zero crossings
#[derive(Clone, Copy)]
pub struct Callback<'a, const D: usize, P> {
    /// The function to check for zero crossings
    pub event: &'a dyn Fn(f64, SVector<f64, D>, &P) -> f64,

    /// The function to change the ODE
    pub effect: &'a dyn Fn(&mut ODE<D, P>),
}

/// A convenience function for stopping the integration
pub fn stop<const D: usize, P>(ode: &mut ODE<D, P>) {
    ode.t_end = ode.t;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_basic_callbacks() {
        type Params = ();
        let _value_too_high = Callback {
            event: &|_: f64, y: SVector<f64, 3>, _p: &Params| 10.0 - y[0],
            effect: &stop,
        };
    }
}