conspire/math/integrate/ode/explicit/fixed_step/bogacki_shampine/
mod.rs1#[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::bogacki_shampine::Tableau as BogackiShampineTableau,
9 },
10};
11use std::ops::{Div, Mul, Sub};
12
13#[doc = include_str!("doc.md")]
14#[derive(Debug, Default)]
15pub struct BogackiShampine {
16 dt: Scalar,
18}
19
20impl<Y, U> OdeIntegrator<Y, U> for BogackiShampine
21where
22 Y: Tensor,
23 U: TensorVec<Item = Y>,
24{
25}
26
27impl<T> FixedStep<T> for BogackiShampine {
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 BogackiShampine
34where
35 Y: Differentiable<T> + Div<Quantity<T>, Output = Derivative<Y, 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 = 3;
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 BogackiShampine
55where
56 Y: Differentiable<T> + Div<Quantity<T>, Output = Derivative<Y, 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 = BogackiShampineTableau;
65}