differential_equations/methods/irk/fixed/
mod.rs

1//! IRK with Newton solves (fixed step).
2
3mod ordinary;
4
5use crate::{
6    methods::{Fixed, ImplicitRungeKutta},
7    tableau::ButcherTableau,
8    traits::{Real, State},
9};
10
11// Fixed-step constructors
12macro_rules! impl_irk_fixed_step_constructor {
13    ($method_name:ident, $order_val:expr, $s_val:expr, $m_val:expr, $doc:expr) => {
14        impl<E, T: Real, Y: State<T>>
15            ImplicitRungeKutta<E, Fixed, T, Y, $order_val, $s_val, $m_val>
16        {
17            #[doc = $doc]
18            pub fn $method_name(h0: T) -> Self {
19                let tableau = ButcherTableau::<T, $s_val>::$method_name();
20                let c = tableau.c;
21                let a = tableau.a;
22                let b = tableau.b;
23
24                ImplicitRungeKutta {
25                    h0,
26                    c,
27                    a,
28                    b,
29                    order: $order_val,
30                    stages: $s_val,
31                    dense_stages: $m_val,
32                    ..Default::default()
33                }
34            }
35        }
36    };
37}
38
39// Fixed-step IRK methods
40impl_irk_fixed_step_constructor!(
41    backward_euler,
42    1,
43    1,
44    1,
45    "Backward Euler, order 1, 1 stage. A-stable; stiff-suitable."
46);
47impl_irk_fixed_step_constructor!(
48    crank_nicolson,
49    2,
50    2,
51    2,
52    "Crank-Nicolson, order 2, 2 stages. A-stable; stiff-suitable."
53);
54impl_irk_fixed_step_constructor!(
55    trapezoidal,
56    2,
57    2,
58    2,
59    "Trapezoidal, order 2, 2 stages. A-stable; stiff-suitable."
60);