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