Iterative solvers on a 1D heat conduction problem

A rod is heated at one end and chilled at the other; the steady-state temperature is a linear ramp. The dashboard compares classical iterative solvers on the resulting discrete Poisson system, with an optional neural preconditioner applied to the residual-based methods.

heater rod: temperature u(x) ramps from hot to cold chiller +q into the first cell −q out of the last cell −u″ = f on (0,1), ends held at ambient u = 0
computing solver histories…

The problem

Steady-state heat conduction: −u″(x) = f on (0,1), with both ends held at ambient temperature (u = 0), discretized on n = 256 cells as A = tridiag(−1, 2, −1)/h², h = 1/257. The heater injects +1 into the first cell and the chiller removes 1 from the last, so the exact temperature (dashed gray in the first panel) is essentially a straight ramp from hot to cold. The eigenvalues of A are λk = (2 − 2cos(kπh))/h², giving condition number κ ≈ 2.7×10⁴ — the single number that separates these methods.

The four panels

Current temperature u (with the exact solution dashed), current residual r = b − Au, the computed step Δu applied at this iteration, and the convergence tracker (log-log; red marker = current step; all methods overlaid, the selected one highlighted). Axes are frozen over the whole history and shared across the preconditioner toggle, and the step selector holds a single global iteration value across methods and the toggle — switching anything keeps the view on the same step, so any two states are directly comparable. The computed-step panel shows most directly what the preconditioner changes: raw residual-shaped corrections become global, solution-shaped ones.

The methods

The neural preconditioner

The toggle applies a toy version of the Neural Preconditioning Operator (arXiv:2502.01337): a two-scale convolutional network — a local fine-grid stencil plus a coarse-grid branch, a miniature of the paper’s multigrid design, 1,154 weights running directly in the browser — trained offline on this A with the paper’s condition/residual losses to output z = M(r) ≈ A⁻¹r. With the toggle on, conjugate gradient becomes flexible PCG (Polak–Ribière β, with a fallback to z = r whenever the network fails to produce a descent direction), gradient descent steps along z instead of r, and each SOR sweep is followed by a line-searched correction along z — the smoother-plus-coarse-correction structure of classical multigrid, with the network in the coarse-correction role. The network is deliberately small: it accelerates the solvers severalfold without making the solve trivial.

The stopping rule is a residual test; the last table column measures each solver’s actual distance to the exact ramp at the moment it stopped — with κ ≈ 2.7×10⁴ those two notions of “converged” can differ more than you’d expect.

For the full theory, see the report series in this repo: Krylov methods & PCG, neural preconditioning, the eigenvalue story.