Factor the two-dimensional heat operator
For \(u_t=\kappa(u_{xx}+u_{yy})\) on a rectangle, first impose homogeneous Dirichlet data. Centred second differences on a Cartesian mesh give \(\dot U=(X+Y)U\), where \(X,Y\) are the directional diffusion matrices. For constant diffusivity and these boundaries the Kronecker factors commute and are symmetric negative definite. Put \(s=h/2\). Multiplying out a factored Crank–Nicolson step introduces \(s^2XY\) on both sides:
Applied to a smooth solution the added defect is \(s^2XY(U^{n+1}-U^n)=O(h^3)\) at fixed mesh. The Peaceman–Rachford realisation uses line solves
For a shared eigenmode with directional eigenvalues \(\lambda_x,\lambda_y\le0\), the amplification factor is the product of their midpoint factors. Each has modulus at most one and the product matches the exponential through order two. This argument establishes unconditional stability for the separable case. For highly damped modes a midpoint factor can change sign. Stability alone does not guarantee monotonicity or accurate damping.
Give the intermediate grid a mathematically consistent boundary
An intermediate variable solves an algebraic factor equation. It has no general obligation to equal the physical wall data at the midpoint time. For inhomogeneous boundaries choose a smooth lifting \(w\) whose trace equals the specified boundary values at all times, and evolve \(v=u-w\) with zero trace and forcing \(f+\kappa\Delta w-w_t\). For \(u=a(t)x\) with prescribed trace on all sides, \(w=a(t)x\) and \(f=a'(t)x\) give identically zero lifted field. A nonzero computed field in this manufactured case isolates a boundary or source inconsistency.
For a smooth lifted source \(g\), add \(s g(t_n+s)\) to both line-equation right sides. Expansion of the first stage and substitution into the second yields \(h g+h^2(X+Y)g/2\) through second order, along with the midpoint approximation to the source time variation. Mixing time levels at the wall can instead inject a first-order defect. Check that spatial derivatives of the lifted source stay resolved when taking a simultaneous time–space limit.
OneSimulation experiment · Propagate one heat mode in two directions
Double the spatial resolution while holding the final time fixed. Keep the grid-dependent reference in the comparison.
Download the executable notebook · Python source
Adjust the heat field and rotate its surface. Take initial data \(\sin(\pi x)\sin(q\pi y)\) on the unit square with zero wall values and \(\kappa=1\). Its directional grid eigenvalues are \(\lambda_x=-4\sin^2(\pi\Delta x/2)/\Delta x^2\) and \(\lambda_y=-4\sin^2(q\pi\Delta x/2)/\Delta x^2\). Each time step multiplies its amplitude by
The browser evaluates \(G^N\), exactly the mode reduction of the two matrix solves in the OneSimulation notebook. The rotatable surface shows the numerical field; its vertical coordinate is temperature, so this remains a two-dimensional spatial problem. The plot compares an antinode slice with both \(e^{(\lambda_x+\lambda_y)t}\) and the continuum amplitude \(e^{-\pi^2(1+q^2)t}\). First double the number of time steps on one fixed mesh, then refine the mesh. Choose a higher vertical mode and very few steps to see stable but inaccurate damping, sometimes with a reversed sign. A vertical reference from −1 to +1 keeps amplitude loss visible as the field cools.
"""Measure the temporal order of an ADI heat step against an exact grid mode."""
import matplotlib.pyplot as plt
import numpy as np
from onesim.numerics.linear.matrices.dense_linear_algebra import solve_dense
m = 9
spacing = 1/(m+1)
d = (np.diag(-2*np.ones(m)) + np.diag(np.ones(m-1), 1) + np.diag(np.ones(m-1), -1))/spacing**2
sine = np.sin(np.pi*spacing*np.arange(1, m+1))
initial = np.outer(sine, sine)
decay = -4*np.sin(np.pi*spacing/2)**2/spacing**2
end = 0.1
ref = initial*np.exp(2*decay*end)
steps, errors = np.array([2, 4, 8, 16, 32]), []
for count in steps:
plus, minus = np.eye(m) + end*d/(2*count), np.eye(m) - end*d/(2*count)
state = initial.copy()
for _ in range(count):
half = solve_dense(minus, state @ plus)
state = solve_dense(minus, (plus @ half).T).T
errors.append(np.max(abs(state-ref)))
orders = np.log2(np.array(errors[:-1])/errors[1:])
print(f"Finest-grid temporal order: {orders[-1]:.4f}")
assert abs(orders[-1]-2) < 0.01
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
ax.loglog(end/steps, errors, "o-", label="ADI")
ax.loglog(end/steps, errors[-1]*(steps[-1]/steps)**2, "--", label="Quadratic reference")
ax.set(xlabel="Time step", ylabel="Maximum error relative to the spatially discrete mode")
ax.legend()
fig.savefig("numerics-adi-heat.png", dpi=170)
Output from the reference run
Finest-grid temporal order: 2.0003

Measure transport, time and splitting independently
A time-dependent transport–reaction problem can have noncommuting operators even on a periodic grid. Let \(Au=-c u_x,\ Bu=-k(x)u\). Direct differentiation gives \((AB-BA)u=c k'(x)u\). Expanding a product \(e^{hB}e^{hA}\) through \(h^2\) and subtracting \(e^{h(A+B)}\) leaves \(h^2(BA-AB)u/2\). Reversing the order reverses this leading defect. The symmetric composition \(e^{hA/2}e^{hB}e^{hA/2}\) cancels it, giving second-order global convergence for sufficiently smooth data and compatible boundaries.
An independent solution follows characteristics: \(u(x,t)=u_0(x-ct)\exp[-\int_0^t k(x-c(t-s))\,ds]\). For \(k=k_0+k_1\sin x\), the integral is \(k_0t+(k_1/c)[\cos(x-ct)-\cos x]\). Compare the split method first to a tightly integrated unsplit system on the same mesh, then to this continuum formula. Halve time at fixed mesh and halve the mesh at a suitably small time step. A single combined refinement cannot identify which contribution dominates.
How expensive is this factorisation?
On an \(m\)-by-\(m\) grid each half-step contains \(m\) tridiagonal systems of length \(m\). A tridiagonal factorisation and substitution lead to \(O(m^2)\) work per step. The small reference notebook deliberately uses the OneSimulation dense solver for each block of right-hand sides so the matrices can be inspected directly.
Tutorial on damping and noncommutation
Calculate the amplification of a strongly anisotropic mode
Work through the solution
With \(s\lambda_x=-10\) and \(s\lambda_y=-0.1\), the factors are \(-9/11\) and \(9/11\). Their product is \(-81/121\). The exact one-step decay is \(e^{-20.2}\), which is much smaller. Halve the time step until damping agrees with the resolution required.
Design a test where reversing the split should change nothing
Work through the solution
A constant reaction rate has \(k'=0\), so advection and reaction commute for periodic boundaries. With exact component updates the two orders agree at any time step. Change \(k\) to a sinusoid and use the order difference to expose the commutator.