Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Solutions · 3. Poisson solvers: SOR, conjugate gradients and multigrid

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 3. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.

Exercise 1

Problem. On a 33×3333 \times 33 grid (h=1/32h = 1/32), verify that poisson_2d_fast_sine recovers v3,5=sin⁡(3πx)sin⁡(5πy)v_{3,5} = \sin(3\pi x)\sin(5\pi y) to <10−14< 10^{-14} when forced by λ3,5hv3,5\lambda_{3,5}^h v_{3,5}, and verify the exact ratio λ3,5PDE/λ3,5h\lambda_{3,5}^{\mathrm{PDE}} / \lambda_{3,5}^h when forced by (32+52)π2v3,5(3^2 + 5^2)\pi^2 v_{3,5}.


Exercise 1: Exact Discrete Eigenfunction vs Continuous PDE Eigenvalue on 33x33
==============================================================================
lam_PDE = 335.566550 vs lam_h = 330.011443 (O(h^2) relative shift = 0.01683)
Max error with discrete eigenvalue forcing = 1.55e-15
Amplitude ratio with PDE forcing           = 1.016833072668 vs lam_PDE/lam_h = 1.016833072668

Explanation. Since sin⁡2(θ/2)<(θ/2)2\sin^2(\theta/2) < (\theta/2)^2, the discrete 5-point Laplacian slightly underestimates curvature (λ3,5h=330.01<λ3,5PDE=335.57\lambda_{3,5}^h = 330.01 < \lambda_{3,5}^{\mathrm{PDE}} = 335.57), causing second-order centered differences to slightly overpredict mode amplitude by λPDE/λh−1=1.68%\lambda^{\mathrm{PDE}}/\lambda^h - 1 = 1.68\% on 33×3333 \times 33.


Exercise 2

Problem. Demonstrate Ostrowski–Reich instability of poisson_2d_sor at ω=2.04>2\omega = 2.04 > 2 on 17×1717 \times 17, show algebraically on random arrays that the discrete pure-Neumann Laplacian sums to zero (∑i,j(−∇h2u)i,j=0\sum_{i,j} (-\nabla_h^2 u)_{i,j} = 0), and verify zero-mean gauge projection in poisson_2d_cg(..., neumann=True).


Exercise 2: SOR Over-Relaxation Blowup (omega = 2.04) & Neumann Nullspace Solvability
=====================================================================================
SOR at omega = 2.04 (> 2.0): residual grew from 4.964e+00 to 1.068e+02 in 60 sweeps (amplification = 21.5x)
Sum of discrete Neumann (-lap_h u) over all cells = +2.27e-12 (exact telescoping zero)
Biased pure-Neumann CG: 1 iters, mean(u) = +3.39e-21, final res = 1.31e-14

Explanation. Every eigenvalue μk\mu_k of the Red–Black SOR iteration matrix has ∣μk∣≥ω−1|\mu_k| \geq \omega - 1 when ω≥ωopt\omega \geq \omega_{\mathrm{opt}}; once ω=2.04>2\omega = 2.04 > 2, ∣μk∣=1.04>1|\mu_k| = 1.04 > 1 for every coupled pair and the iteration diverges (the residual grows by a factor of 21.5 in 60 sweeps). For pure Neumann BCs (such as incompressible walls ∂p/∂n=0\partial p / \partial n = 0), 1T(−∇h2u)=0\mathbf{1}^T (-\nabla_h^2 u) = 0 identically, so any net mass source fˉ≠0\bar{f} \neq 0 violates mass conservation unless projected out.


Exercise 3

Problem. Implement audit_smoother_frequency_selectivity(n_pts=33, n_sweeps=10) applying Red–Black Gauss–Seidel (_rbgs_smooth) to −∇h2e=0-\nabla_h^2 e = 0 from initial error e(0)=sin⁡(kπx)sin⁡(kπy)e^{(0)} = \sin(k\pi x)\sin(k\pi y) for smooth k=1k = 1 vs. oscillatory k=16k = 16, and show that 10 sweeps damp k=16k = 16 by >105×> 10^5\times while leaving >90%> 90\% of k=1k = 1 untouched.


Exercise 3: Implement It Yourself — Smoother Wavenumber Selectivity check
=========================================================================
Smooth mode (1,1)   remaining after 10 RBGS sweeps: 91.24% (theory ~ 90.80%)
High-k mode (16,16) remaining after 10 RBGS sweeps: 1.393e-21 (damped by 7.2e+20x)

Summary. Gauss–Seidel is a poor stand-alone solver (90.8%90.8\% of the (1,1)(1,1) mode survives 10 sweeps) yet an effective smoother (it damps the k=16k=16 mode by >106×> 10^6\times in 10 sweeps). Multigrid exploits this exact dichotomy by letting coarse grids handle smooth modes on their natural length scale.