Skip to main content

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

1#[cfg(test)]
2mod test;
3
4use crate::math::{
5    Derivative, Differentiable, Quantity, Scalar, Tensor, TensorVec,
6    integrate::{
7        Explicit, FixedStep, FixedStepExplicit, IntegrationError, OdeIntegrator, Spectrum, Times,
8        ode::explicit::variable_step::verner_8::Tableau as Verner8Tableau,
9    },
10};
11use std::ops::{Mul, Sub};
12
13#[doc = include_str!("doc.md")]
14#[derive(Debug, Default)]
15pub struct Verner8 {
16    /// Fixed value for the time step.
17    dt: Scalar,
18}
19
20impl<Y, U> OdeIntegrator<Y, U> for Verner8
21where
22    Y: Tensor,
23    U: TensorVec<Item = Y>,
24{
25}
26
27impl<T> FixedStep<T> for Verner8 {
28    fn dt(&self) -> Quantity<T> {
29        Quantity::new(self.dt)
30    }
31}
32
33impl<Y, U, V, T> Explicit<Y, U, V, T> for Verner8
34where
35    Y: Differentiable<T> + Tensor,
36    Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
37    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
38    for<'a> &'a Derivative<Y, T>:
39        Mul<Scalar, Output = Derivative<Y, T>> + Mul<Quantity<T>, Output = Y>,
40    U: TensorVec<Item = Y>,
41    V: TensorVec<Item = Derivative<Y, T>>,
42{
43    const SLOPES: usize = 12;
44    fn integrate(
45        &self,
46        function: impl FnMut(Quantity<T>, &Y) -> Result<Derivative<Y, T>, String>,
47        time: &[Quantity<T>],
48        initial_condition: Y,
49    ) -> Result<(Times<T>, U, V), IntegrationError> {
50        self.integrate_fixed_step(function, time, initial_condition)
51    }
52    fn integrate_bounded(
53        &self,
54        function: impl FnMut(Quantity<T>, &Y) -> Result<Derivative<Y, T>, String>,
55        bound: impl FnMut(Quantity<T>, &Y) -> Result<Spectrum<T>, String>,
56        safety: Scalar,
57        time: &[Quantity<T>],
58        initial_condition: Y,
59    ) -> Result<(Times<T>, U, V), IntegrationError> {
60        self.integrate_fixed_step_bounded(function, bound, safety, time, initial_condition)
61    }
62}
63
64impl<Y, U, V, T> FixedStepExplicit<Y, U, V, T> for Verner8
65where
66    Y: Differentiable<T> + Tensor,
67    Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
68    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
69    for<'a> &'a Derivative<Y, T>:
70        Mul<Scalar, Output = Derivative<Y, T>> + Mul<Quantity<T>, Output = Y>,
71    U: TensorVec<Item = Y>,
72    V: TensorVec<Item = Derivative<Y, T>>,
73{
74    type Tableau = Verner8Tableau;
75}