Macro adaptive_implicit_runge_kutta_method

Source
macro_rules! adaptive_implicit_runge_kutta_method {
    (
        $(#[$attr:meta])*
        name: $name:ident,
        a: $a:expr,
        b: $b:expr,
        c: $c:expr,
        order: $order:expr,
        stages: $stages:expr
        $(,)? // Optional trailing comma
    ) => { ... };
}
Expand description

Macro to create an adaptive implicit Runge-Kutta solver from a Butcher tableau.

This macro generates the necessary struct and trait implementations for an adaptive-step implicit Runge-Kutta method. It uses Newton’s iteration to solve the implicit stage equations and estimates the error by comparing the result from the primary b weights with a secondary set of weights b_hat.

§Arguments

  • name: Name of the solver struct to create
  • a: Matrix of coefficients for intermediate stages (can be non-zero on diagonal/upper triangle)
  • b: 2D array where the first row is the primary weights (b) and the second row is the secondary weights (b_hat) for error estimation.
  • c: Time offsets for each stage
  • order: Order of accuracy of the primary method (used for step size control)
  • stages: Number of stages in the method

§Note on Solver and Error Estimation

  • The implicit stage equations k_i = f(t_n + c_i*h, y_n + h * sum(a_{ij}*k_j)) are solved using Newton’s iteration. This requires the ODE system to provide its Jacobian.
  • Error estimation uses the difference between solutions computed with b and b_hat. The validity of b_hat as an error estimator depends on the specific method’s tableau. For methods like Gauss-Legendre, this might not be the standard approach.

§Example (Illustrative - Requires a valid tableau with error estimator)

// Assuming a hypothetical 2-stage, 2nd order implicit method with error estimator
/*
use differential_equations::adaptive_implicit_runge_kutta_method;
adaptive_implicit_runge_kutta_method!(
    name: AdaptiveImplicitExample,
    a: [[0.5, 0.0], [0.5, 0.5]], // Example 'a' matrix
    b: [
        [0.5, 0.5], // Primary weights (e.g., order 2)
        [1.0, 0.0]  // Secondary weights (e.g., order 1)
    ],
    c: [0.5, 1.0],
    order: 2,
    stages: 2
);
*/