1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! 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`.
//!
//! [repository]: https://github.com/mlu-numerics/rowmap/tree/main/rowmap-ng
//!
//! # 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);
//! # Ok::<(), rowmap::RowmapError>(())
//! ```
//!
//! Non-autonomous problems (the default of [`OdeSystem::autonomous`]) must
//! also implement [`OdeSystem::dfdt`]. Dense output and early termination
//! are available through [`Rowmap::solve_with`].
// Index loops that mirror the formulas (Σ_j a_ij x_j) are clearer in numerical
// kernels than iterator chains.
pub use ;
pub use ;