conspire/math/integrate/ode/explicit/fixed_step/euler/
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::Mul;
12
13#[derive(Debug)]
15pub struct Tableau;
16
17impl ButcherTableau for Tableau {
18 const STAGES: usize = 1;
19 const ORDER: Scalar = 1.0;
20 const A: &'static [&'static [Scalar]] = &[&[]];
21 const C: &'static [Scalar] = &[0.0];
22 const B: &'static [Scalar] = &[1.0];
23}
24
25#[doc = include_str!("doc.md")]
26#[derive(Debug, Default)]
27pub struct Euler {
28 dt: Scalar,
30}
31
32impl<Y, U> OdeIntegrator<Y, U> for Euler
33where
34 Y: Tensor,
35 U: TensorVec<Item = Y>,
36{
37}
38
39impl<T> FixedStep<T> for Euler {
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 Euler
46where
47 Y: Differentiable<T> + Tensor,
48 for<'a> &'a Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
49 U: TensorVec<Item = Y>,
50 V: TensorVec<Item = Derivative<Y, T>>,
51{
52 const SLOPES: usize = 1;
53 fn integrate(
54 &self,
55 function: impl FnMut(Quantity<T>, &Y) -> Result<Derivative<Y, T>, String>,
56 time: &[Quantity<T>],
57 initial_condition: Y,
58 ) -> Result<(Times<T>, U, V), IntegrationError> {
59 self.integrate_fixed_step(function, time, initial_condition)
60 }
61}
62
63impl<Y, U, V, T> FixedStepExplicit<Y, U, V, T> for Euler
64where
65 Y: Differentiable<T> + Tensor,
66 for<'a> &'a Derivative<Y, T>: Mul<Quantity<T>, Output = Y>,
67 U: TensorVec<Item = Y>,
68 V: TensorVec<Item = Derivative<Y, T>>,
69{
70 type Tableau = Tableau;
71}