conspire/math/integrate/ode/explicit/fixed_step/ralston/
mod.rs1#[cfg(test)]
2mod test;
3
4use crate::math::{
5 Derivative, Differentiable, Quantity, Scalar, Tensor, TensorVec,
6 integrate::{
7 ButcherTableau, Explicit, FixedStep, FixedStepExplicit, IntegrationError, OdeIntegrator,
8 Times,
9 },
10};
11use std::ops::{Add, Mul};
12
13#[derive(Debug)]
15pub struct Tableau;
16
17impl ButcherTableau for Tableau {
18 const STAGES: usize = 2;
19 const ORDER: Scalar = 2.0;
20 const A: &'static [&'static [Scalar]] = &[&[], &[0.75]];
21 const C: &'static [Scalar] = &[0.0, 0.75];
22 const B: &'static [Scalar] = &[1.0 / 3.0, 2.0 / 3.0];
23}
24
25#[doc = include_str!("doc.md")]
26#[derive(Debug, Default)]
27pub struct Ralston {
28 dt: Scalar,
30}
31
32impl<Y, U> OdeIntegrator<Y, U> for Ralston
33where
34 Y: Tensor,
35 U: TensorVec<Item = Y>,
36{
37}
38
39impl<T> FixedStep<T> for Ralston {
40 fn dt(&self) -> Quantity<T> {
41 Quantity::new(self.dt)
42 }
43}
44
45impl<Y, U, V, T> Explicit<Y, U, V, T> for Ralston
46where
47 Y: Differentiable<T> + Tensor,
48 Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
49 for<'a> &'a Derivative<Y, T>: Add<Derivative<Y, T>, Output = Derivative<Y, T>>
50 + Mul<Scalar, Output = Derivative<Y, T>>
51 + Mul<Quantity<T>, Output = Y>,
52 U: TensorVec<Item = Y>,
53 V: TensorVec<Item = Derivative<Y, T>>,
54{
55 const SLOPES: usize = 2;
56 fn integrate(
57 &self,
58 function: impl FnMut(Quantity<T>, &Y) -> Result<Derivative<Y, T>, String>,
59 time: &[Quantity<T>],
60 initial_condition: Y,
61 ) -> Result<(Times<T>, U, V), IntegrationError> {
62 self.integrate_fixed_step(function, time, initial_condition)
63 }
64}
65
66impl<Y, U, V, T> FixedStepExplicit<Y, U, V, T> for Ralston
67where
68 Y: Differentiable<T> + Tensor,
69 Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
70 for<'a> &'a Derivative<Y, T>: Add<Derivative<Y, T>, Output = Derivative<Y, T>>
71 + Mul<Scalar, Output = Derivative<Y, T>>
72 + Mul<Quantity<T>, Output = Y>,
73 U: TensorVec<Item = Y>,
74 V: TensorVec<Item = Derivative<Y, T>>,
75{
76 type Tableau = Tableau;
77}