Skip to main content

Crate rowmap

Crate rowmap 

Source
Expand description

ROWMAP: a Krylov-W method of order 4(3) for large stiff ODEs y' = f(t, y).

The method is GRK4T (Kaps–Rentrop). Its linear stage systems are solved in Krylov subspaces built by a multiple Arnoldi process (MAP). That process keeps the order 4 already for small, n-independent Krylov dimensions: 4/7/8/11 for autonomous problems, 4/9/10/15 for non-autonomous ones. The Jacobian is only needed as a product J·v, which the user supplies exactly.

Based on R. Weiner, B.A. Schmitt, H. Podhaisky: ROWMAP – a ROW-code with Krylov techniques for large stiff ODEs (1996). Design, proofs and experiments are in the repository: AGENTS.md, docs/map.md, docs/comparison.md.

§Example

The 1D heat equation u_t = u_xx on (0, 1), zero boundary values, semi-discretized with central differences:

use rowmap::{OdeSystem, Rowmap};

struct Heat {
    n: usize,
}

impl Heat {
    fn lap(&self, u: &[f64], out: &mut [f64]) {
        let h2 = 1.0 / ((self.n + 1) as f64).powi(2);
        for i in 0..self.n {
            let l = if i > 0 { u[i - 1] } else { 0.0 };
            let r = if i + 1 < self.n { u[i + 1] } else { 0.0 };
            out[i] = (l - 2.0 * u[i] + r) / h2;
        }
    }
}

impl OdeSystem for Heat {
    fn dim(&self) -> usize {
        self.n
    }
    fn rhs(&self, _t: f64, y: &[f64], dy: &mut [f64]) {
        self.lap(y, dy);
    }
    // exact Jacobian-vector product (the problem is linear: J = Laplacian)
    fn jac_vec(&self, _t: f64, _y: &[f64], v: &[f64], out: &mut [f64]) {
        self.lap(v, out);
    }
    fn autonomous(&self) -> bool {
        true
    }
}

let sys = Heat { n: 200 };
let pi = std::f64::consts::PI;
let x = |i: usize| (i + 1) as f64 / 201.0;
let mut y: Vec<f64> = (0..200).map(|i| (pi * x(i)).sin()).collect();

let sol = Rowmap::new(1e-6, 1e-6).solve(&sys, 0.0, &mut y, 0.1)?;

// exact solution of the semi-discrete problem: sin(πx) e^{λ t}
let lam = -4.0 * 201.0f64.powi(2) * (pi / (2.0 * 201.0)).sin().powi(2);
let err = (0..200).map(|i| (y[i] - (pi * x(i)).sin() * (lam * 0.1).exp()).abs()).fold(0.0, f64::max);
assert!(err < 1e-5);
println!("{} steps, {} f-evaluations, {} J·v", sol.stats.steps, sol.stats.f_evals, sol.stats.jv);

Non-autonomous problems (the default of OdeSystem::autonomous) must also implement OdeSystem::dfdt. Dense output and early termination are available through Rowmap::solve_with.

Structs§

DimStats
Min/max/mean of the Krylov dimension at the end of one stage.
Rowmap
The ROWMAP integrator. Create with Rowmap::new; the other settings have defaults that fit most problems.
Solution
Result of a successful integration.
Stats
Integration statistics.
Step
An accepted step, passed to the callback of Rowmap::solve_with.
Unsupported
Returned by the default OdeSystem::dfdt: the system does not provide ∂f/∂t.

Enums§

Method
The underlying ROW method.
RowmapError
Errors. On error, the state vector holds the last accepted solution at the time given in the error.
Status
How the integration ended.
Tol
A tolerance: one value for all components, or one per component.

Traits§

OdeSystem
An initial value problem y' = f(t, y) with an exact Jacobian-vector product.