differential_equations/methods/erk/fixed/
mod.rs

1//! Runge-Kutta solvers with fixed step-size.
2
3mod ordinary;
4mod delay;
5mod stochastic;
6
7use super::ExplicitRungeKutta;
8use crate::methods::{Fixed, Ordinary, Delay, Stochastic};
9
10use crate::{
11    traits::{CallBackData, Real, State},
12    tableau::ButcherTableau,
13};
14
15// Macro for fixed step constructors
16macro_rules! impl_erk_fixed_step_constructor {
17    ($method_name:ident, $fsal_val:expr, $order_val:expr, $s_val:expr, $doc:expr) => {
18        impl<E, T: Real, V: State<T>, D: CallBackData> ExplicitRungeKutta<E, Fixed, T, V, D, $order_val, $s_val, $s_val> {
19            #[doc = $doc]
20            pub fn $method_name(h0: T) -> Self {
21                let tableau = ButcherTableau::$method_name();
22                let c = tableau.c;
23                let a = tableau.a;
24                let b = tableau.b;
25                let fsal = $fsal_val;
26
27                ExplicitRungeKutta {
28                    h0,
29                    c,
30                    a,
31                    b,
32                    fsal,
33                    ..Default::default()
34                }
35            }
36        }
37    };
38}
39
40// Fixed step methods (S = I, no embedded error estimation, cubic Hermite interpolation)
41impl_erk_fixed_step_constructor!(euler, false, 1, 1, "Creates an Explicit Euler method (1st order, 1 stage).");
42impl_erk_fixed_step_constructor!(midpoint, false, 2, 2, "Creates an Explicit Midpoint method (2nd order, 2 stages).");
43impl_erk_fixed_step_constructor!(heun, false, 2, 2, "Creates an Explicit Heun method (2nd order, 2 stages).");
44impl_erk_fixed_step_constructor!(ralston, false, 2, 2, "Creates an Explicit Ralston method (2nd order, 2 stages).");
45impl_erk_fixed_step_constructor!(rk4, false, 4, 4, "Creates the classical 4th order Runge-Kutta method.");
46impl_erk_fixed_step_constructor!(three_eighths, false, 4, 4, "Creates the three-eighths rule 4th order Runge-Kutta method.");