conspire/math/integrate/ode/explicit/fixed_step/verner_9/
mod.rs

1#[cfg(test)]
2mod test;
3
4use crate::math::{
5    Scalar, Tensor, TensorVec, Vector,
6    integrate::{
7        Explicit, FixedStep, FixedStepExplicit, IntegrationError, OdeIntegrator,
8        VariableStepExplicit, Verner9 as Verner9VariableStep,
9    },
10};
11use std::ops::{Mul, Sub};
12
13#[doc = include_str!("doc.md")]
14#[derive(Debug, Default)]
15pub struct Verner9 {
16    /// Fixed value for the time step.
17    dt: Scalar,
18}
19
20impl<Y, U> OdeIntegrator<Y, U> for Verner9
21where
22    Y: Tensor,
23    U: TensorVec<Item = Y>,
24{
25}
26
27impl FixedStep for Verner9 {
28    fn dt(&self) -> Scalar {
29        self.dt
30    }
31}
32
33impl<Y, U> Explicit<Y, U> for Verner9
34where
35    Y: Tensor,
36    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
37    U: TensorVec<Item = Y>,
38{
39    const SLOPES: usize = 15;
40    fn integrate(
41        &self,
42        function: impl FnMut(Scalar, &Y) -> Result<Y, String>,
43        time: &[Scalar],
44        initial_condition: Y,
45    ) -> Result<(Vector, U, U), IntegrationError> {
46        self.integrate_fixed_step(function, time, initial_condition)
47    }
48}
49
50impl<Y, U> FixedStepExplicit<Y, U> for Verner9
51where
52    Verner9VariableStep: VariableStepExplicit<Y, U>,
53    Y: Tensor,
54    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
55    U: TensorVec<Item = Y>,
56{
57    fn step(
58        &self,
59        function: impl FnMut(Scalar, &Y) -> Result<Y, String>,
60        y: &Y,
61        t: Scalar,
62        dt: Scalar,
63        k: &mut [Y],
64        y_trial: &mut Y,
65    ) -> Result<(), String> {
66        Verner9VariableStep::slopes(function, y, t, dt, k, y_trial)
67    }
68}