differential_equations/methods/erk/dormandprince/
mod.rs

1//! Runge-Kutta solvers with support for dense output, embedded error estimation, and fixed steps.
2
3mod delay;
4mod ordinary;
5
6use crate::{
7    methods::{DormandPrince, ExplicitRungeKutta},
8    tableau::ButcherTableau,
9    traits::{Real, State},
10};
11
12// Macro for adaptive step constructors
13macro_rules! impl_erk_dormand_prince_constructor {
14    ($method_name:ident, $order_val:expr, $s_val:expr, $m_val:expr, $doc:expr) => {
15        impl<E, T: Real, Y: State<T>>
16            ExplicitRungeKutta<E, DormandPrince, T, Y, $order_val, $s_val, $m_val>
17        {
18            #[doc = $doc]
19            pub fn $method_name() -> Self {
20                let tableau = ButcherTableau::<T, $s_val, $m_val>::$method_name();
21                let c = tableau.c;
22                let a = tableau.a;
23                let b = tableau.b;
24                let bh = tableau.bh;
25                let er = tableau.er;
26                let bi = tableau.bi;
27                let fsal = true; // DOP methods are FSAL by definition, also this isn't used in implementation because its assumed but just for consistency
28
29                ExplicitRungeKutta {
30                    c,
31                    a,
32                    b,
33                    bh,
34                    er,
35                    bi,
36                    fsal,
37                    ..Default::default()
38                }
39            }
40        }
41    };
42}
43
44// Adaptive step methods (embedded error estimation, cubic Hermite interpolation)
45impl_erk_dormand_prince_constructor!(
46    dop853,
47    8,
48    12,
49    16,
50    "Creates the DOP853 method (8th order, 12 stages, 4 dense output stages)."
51);
52impl_erk_dormand_prince_constructor!(
53    dopri5,
54    5,
55    7,
56    7,
57    "Creates the DOPRI5 method (5th order, 7 stages)."
58);