conspire/math/integrate/dae/explicit/variable_step/bogacki_shampine/
mod.rs

1use crate::math::{
2    Banded, Scalar, Tensor, TensorVec, Vector,
3    integrate::{
4        BogackiShampine, ExplicitDaeVariableStep, ExplicitDaeVariableStepFirstSameAsLast,
5        IntegrationError,
6    },
7    optimize::{
8        EqualityConstraint, FirstOrderOptimization, FirstOrderRootFinding, SecondOrderOptimization,
9        ZerothOrderRootFinding,
10    },
11};
12use std::ops::{Mul, Sub};
13
14impl<Y, Z, U, V> ExplicitDaeVariableStep<Y, Z, U, V> for BogackiShampine
15where
16    Self: ExplicitDaeZerothOrderRoot<Y, Z, U, V>,
17    Y: Tensor,
18    Z: Tensor,
19    U: TensorVec<Item = Y>,
20    V: TensorVec<Item = Z>,
21    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
22{
23    fn slopes_solve(
24        mut evolution: impl FnMut(Scalar, &Y, &Z) -> Result<Y, String>,
25        mut solution: impl FnMut(Scalar, &Y, &Z) -> Result<Z, String>,
26        y: &Y,
27        z: &Z,
28        t: Scalar,
29        dt: Scalar,
30        k: &mut [Y],
31        y_trial: &mut Y,
32        z_trial: &mut Z,
33    ) -> Result<(), String> {
34        *y_trial = &k[0] * (0.5 * dt) + y;
35        *z_trial = solution(t + 0.5 * dt, y_trial, z)?;
36        k[1] = evolution(t + 0.5 * dt, y_trial, z_trial)?;
37        *y_trial = &k[1] * (0.75 * dt) + y;
38        *z_trial = solution(t + 0.75 * dt, y_trial, z_trial)?;
39        k[2] = evolution(t + 0.75 * dt, y_trial, z_trial)?;
40        *y_trial = (&k[0] * 2.0 + &k[1] * 3.0 + &k[2] * 4.0) * (dt / 9.0) + y;
41        *z_trial = solution(t + dt, y_trial, z_trial)?;
42        Ok(())
43    }
44    fn slopes_solve_and_error(
45        &self,
46        evolution: impl FnMut(Scalar, &Y, &Z) -> Result<Y, String>,
47        solution: impl FnMut(Scalar, &Y, &Z) -> Result<Z, String>,
48        y: &Y,
49        z: &Z,
50        t: Scalar,
51        dt: Scalar,
52        k: &mut [Y],
53        y_trial: &mut Y,
54        z_trial: &mut Z,
55    ) -> Result<Scalar, String> {
56        Self::slopes_solve_and_error_fsal(evolution, solution, y, z, t, dt, k, y_trial, z_trial)
57    }
58    fn step_solve(
59        &self,
60        _: impl FnMut(Scalar, &Y, &Z) -> Result<Y, String>,
61        y: &mut Y,
62        z: &mut Z,
63        t: &mut Scalar,
64        y_sol: &mut U,
65        z_sol: &mut V,
66        t_sol: &mut Vector,
67        dydt_sol: &mut U,
68        dt: &mut Scalar,
69        k: &mut [Y],
70        y_trial: &Y,
71        z_trial: &Z,
72        e: Scalar,
73    ) -> Result<(), String> {
74        self.step_solve_fsal(
75            y, z, t, y_sol, z_sol, t_sol, dydt_sol, dt, k, y_trial, z_trial, e,
76        )
77    }
78}
79
80impl<Y, Z, U, V> ExplicitDaeVariableStepFirstSameAsLast<Y, Z, U, V> for BogackiShampine
81where
82    Y: Tensor,
83    Z: Tensor,
84    U: TensorVec<Item = Y>,
85    V: TensorVec<Item = Z>,
86    for<'a> &'a Y: Mul<Scalar, Output = Y> + Sub<&'a Y, Output = Y>,
87{
88}
89
90super::implement_solvers!(BogackiShampine);