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 · 14. The lid-driven cavity

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 14. 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. Evaluate Thom’s bottom-wall vorticity formula ωThom(x,0)=−2ψ(x,h)/h2\omega_{\mathrm{Thom}}(x, 0) = -2\psi(x, h)/h^2 across N∈{17,33,65,129}N \in \{17, 33, 65, 129\} on two analytical streamfunctions satisfying ψ(x,0)=u(x,0)=0\psi(x, 0) = u(x, 0) = 0: (a) symmetric ψA(x,y)=sin⁡2(πy)sin⁡(πx)\psi_A(x,y) = \sin^2(\pi y)\sin(\pi x) (∂y3ψ∣0=0\partial_y^3\psi|_0 = 0) and (b) cubic-shear ψB(x,y)=y2(1−y)sin⁡(πx)\psi_B(x,y) = y^2(1 - y)\sin(\pi x) (∂y3ψ∣0=−6sin⁡πx≠0\partial_y^3\psi|_0 = -6\sin\pi x \neq 0). Verify observed convergence orders pA≈2.0p_A \approx 2.0 and pB≈1.0p_B \approx 1.0 from Taylor’s remainder theorem.


Exercise 1: Taylor Remainder Analysis of Thom's Wall Vorticity Formula
======================================================================
Symmetric psi_A orders : [1.9944 1.9986 1.9997] (O(h^2) when d^3 psi/dy^3|_wall == 0)
Cubic     psi_B orders : [1. 1. 1.] (exact leading error = 2*h*sin(pi*x) -> O(h^1))

Explanation. Expanding ψ(x,h)=h22ψyy(x,0)+h36ψyyy(x,0)+h424ψyyyy(x,0)+…\psi(x, h) = \frac{h^2}{2}\psi_{yy}(x,0) + \frac{h^3}{6}\psi_{yyy}(x,0) + \frac{h^4}{24}\psi_{yyyy}(x,0) + \dots shows that −2ψ(x,h)/h2=ω(x,0)+h3∂yω∣0+O(h2)-2\psi(x,h)/h^2 = \omega(x,0) + \frac{h}{3}\partial_y\omega|_0 + O(h^2): Thom’s formula is truncation-exact for pure linear wall shear (ψ∝y2\psi \propto y^2), first-order in the presence of normal vorticity gradient ∂yω∣0=1ν∂xp∣0\partial_y\omega|_0 = \frac{1}{\nu}\partial_x p|_0, and second-order whenever tangential pressure gradient vanishes.


Exercise 2

Problem. Verify that navier_stokes.lid_driven_cavity_2d raises ValueError for invalid inputs (n_grid=5, Re=0.0, U_lid=-1.0), and demonstrate on n_grid=33, Re=50 (ν=0.02,h=1/32\nu = 0.02, h = 1/32) that automatic time-stepping (dt=None) converges stably while forcing dt=0.04 (>h2/(4ν)≈0.0122> h^2/(4\nu) \approx 0.0122) blows up.


Exercise 2: Input Guards & Explicit Wall-Coupled Viscous Time-Step Blow-Up
==========================================================================
dt=None (auto ~ 0.0107): psi_min = -0.09946, stable = True
dt=0.04 (> h^2/(4*nu)=0.0122): vorticity blew up = True

Explanation. The automatic time step of lid_driven_cavity_2d is dt_diff = 0.22 * h^2 / nu, slightly stricter than the periodic 0.25h2/ν0.25 h^2 / \nu bound, because Thom’s explicit wall vorticity boundary condition couples ωwall\omega_{\mathrm{wall}} to ψadj\psi_{\mathrm{adj}} and tightens the boundary spectral radius.


Exercise 3

Problem. Implement my_lid_cavity_step(psi, omega, h, nu, dt, U_lid) in pure NumPy using elliptic_multigrid.poisson_2d_fast_sine, evolve 150 steps from rest on n_grid=25, Re=100 at the exact auto dt = min(0.22*h^2/nu, 0.35*h/U_lid), and verify < 1e-13 agreement with navier_stokes.lid_driven_cavity_2d(n_grid=25, Re=100, max_steps=150, tol=1e-12).


Exercise 3: Implement It Yourself — DST-Accelerated Vorticity-Streamfunction Cavity Stepper
===========================================================================================
After 150 steps: max |psi_mine - psi_ref| = 0.000e+00 | max |omega_mine - omega_ref| = 0.000e+00

Summary. Combining ω\omega–ψ\psi curl elimination with O(Nlog⁡N)O(N \log N) Fast Sine Poisson solves gives a compact two-dimensional Navier–Stokes solver without a pressure equation. Lecture 15 introduces the lattice Boltzmann method, which needs no global elliptic solve at all.