Macro implicit_runge_kutta_method

Source
macro_rules! 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 a fixed-step implicit Runge-Kutta solver from a Butcher tableau.

This macro generates the necessary struct and trait implementations for a fixed-step implicit Runge-Kutta method. It uses a simple fixed-point iteration to solve the implicit stage equations.

§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: Weights for final summation
  • c: Time offsets for each stage
  • order: Order of accuracy of the method
  • stages: Number of stages in the method

§Note on Solver

The implicit stage equations k_i = f(t_n + c_i*h, y_n + h * sum(a_{ij}*k_j)) are solved using fixed-point iteration. This is simple but may fail to converge for stiff problems unless h is sufficiently small (h * L < 1, where L is the Lipschitz constant). More robust solvers (like Newton’s method) require Jacobians and linear algebra.

§Example

use differential_equations::implicit_runge_kutta_method;

// Define Implicit Euler method
implicit_runge_kutta_method!(
    /// Implicit Euler (Backward Euler) Method (1st Order)
    name: ImplicitEulerExample,
    a: [[1.0]],
    b: [1.0],
    c: [1.0],
    order: 1,
    stages: 1
);