Skip to main content

differential_equations/methods/
mod.rs

1//! Numerical Methods for Differential Equations
2
3use crate::{
4    tolerance::Tolerance,
5    traits::{Real, State},
6};
7
8mod h_init;
9
10mod apc;
11mod bdf;
12mod dirk;
13mod erk;
14mod irk;
15mod milstein;
16
17pub mod bvp;
18
19pub use apc::AdamsPredictorCorrector;
20pub use bdf::BackwardDifferentiationFormula;
21pub use dirk::DiagonallyImplicitRungeKutta;
22pub use erk::ExplicitRungeKutta;
23pub use irk::ImplicitRungeKutta;
24pub use milstein::Milstein;
25
26// Typestate categories for differential equation types.
27#[derive(Clone)]
28pub struct Ordinary;
29#[derive(Clone)]
30pub struct Delay;
31#[derive(Clone)]
32pub struct Stochastic;
33#[derive(Clone)]
34pub struct Algebraic;
35
36/// Fixed-step methods
37#[derive(Clone)]
38pub struct Fixed;
39
40/// Adaptive-step methods
41#[derive(Clone)]
42pub struct Adaptive;
43
44/// Explicit Adaptive-step methods by Dormand-Prince
45#[derive(Clone)]
46pub struct DormandPrince;
47
48/// Radau IIA methods
49#[derive(Clone)]
50pub struct Radau;
51
52/// Trait to allow configuring tolerances on numerical methods generically.
53pub trait ToleranceConfig<T: Real> {
54    fn rtol<V: Into<Tolerance<T>>>(self, rtol: V) -> Self;
55    fn atol<V: Into<Tolerance<T>>>(self, atol: V) -> Self;
56}
57
58impl<E, F, T: Real, Y: State<T>, const O: usize, const S: usize, const I: usize> ToleranceConfig<T>
59    for ExplicitRungeKutta<E, F, T, Y, O, S, I>
60{
61    fn rtol<V: Into<Tolerance<T>>>(self, rtol: V) -> Self {
62        self.rtol(rtol)
63    }
64    fn atol<V: Into<Tolerance<T>>>(self, atol: V) -> Self {
65        self.atol(atol)
66    }
67}
68
69impl<E, F, T: Real, Y: State<T>, const O: usize, const S: usize, const I: usize> ToleranceConfig<T>
70    for ImplicitRungeKutta<E, F, T, Y, O, S, I>
71{
72    fn rtol<V: Into<Tolerance<T>>>(self, rtol: V) -> Self {
73        self.rtol(rtol)
74    }
75    fn atol<V: Into<Tolerance<T>>>(self, atol: V) -> Self {
76        self.atol(atol)
77    }
78}
79
80impl<E, F, T: Real, Y: State<T>, const O: usize, const S: usize, const I: usize> ToleranceConfig<T>
81    for DiagonallyImplicitRungeKutta<E, F, T, Y, O, S, I>
82{
83    fn rtol<V: Into<Tolerance<T>>>(self, rtol: V) -> Self {
84        self.rtol(rtol)
85    }
86    fn atol<V: Into<Tolerance<T>>>(self, atol: V) -> Self {
87        self.atol(atol)
88    }
89}