Skip to main content

conspire/math/integrate/ode/explicit/fixed_step/dormand_prince/
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, Times,
8        ode::explicit::variable_step::dormand_prince::Tableau as DormandPrinceTableau,
9    },
10};
11use std::ops::{Mul, Sub};
12
13#[doc = include_str!("doc.md")]
14#[derive(Debug, Default)]
15pub struct DormandPrince {
16    /// Fixed value for the time step.
17    dt: Scalar,
18}
19
20impl<Y, U> OdeIntegrator<Y, U> for DormandPrince
21where
22    Y: Tensor,
23    U: TensorVec<Item = Y>,
24{
25}
26
27impl<T> FixedStep<T> for DormandPrince {
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 DormandPrince
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 = 6;
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}
53
54impl<Y, U, V, T> FixedStepExplicit<Y, U, V, T> for DormandPrince
55where
56    Y: Differentiable<T> + Tensor,
57    Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
58    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
59    for<'a> &'a Derivative<Y, T>:
60        Mul<Scalar, Output = Derivative<Y, T>> + Mul<Quantity<T>, Output = Y>,
61    U: TensorVec<Item = Y>,
62    V: TensorVec<Item = Derivative<Y, T>>,
63{
64    type Tableau = DormandPrinceTableau;
65}