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 · 13. Pressure–velocity coupling, checkerboard modes and the staggered grid

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 13. 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 16×1616 \times 16 periodic grid (Δx=Δy=1\Delta x = \Delta y = 1), evaluate both the collocated central gradient and the staggered MAC face gradient on all four basis candidates of ker⁡(Gcol)\ker(G^{\mathrm{col}}): p(0)=1p^{(0)} = 1, p(x)=(−1)ip^{(x)} = (-1)^i, p(y)=(−1)jp^{(y)} = (-1)^j, and p(xy)=(−1)i+jp^{(xy)} = (-1)^{i+j}. Prove numerically that dim⁡ker⁡(Gcol)≥4\dim\ker(G^{\mathrm{col}}) \geq 4 while only p(0)p^{(0)} vanishes under GMACG^{\mathrm{MAC}}.


Exercise 1: 4-Mode Collocated Spurious Nullspace vs 1-Mode Physical Hydrostatic Nullspace on MAC
================================================================================================
Constant p = 1              | Collocated ||grad||_inf = 0.0000 | MAC ||grad||_inf = 0.0000
Vertical stripes (-1)^i     | Collocated ||grad||_inf = 0.0000 | MAC ||grad||_inf = 2.0000
Horizontal stripes (-1)^j   | Collocated ||grad||_inf = 0.0000 | MAC ||grad||_inf = 2.0000
2-D Chessboard (-1)^(i+j)   | Collocated ||grad||_inf = 0.0000 | MAC ||grad||_inf = 2.0000

Explanation. In 2-D, taking tensor products of {1,(−1)i}⊗{1,(−1)j}\{1, (-1)^i\} \otimes \{1, (-1)^j\} creates three non-physical sawtooth modes invisible to (pi+1,j−pi−1,j)/(2Δx)(p_{i+1,j}-p_{i-1,j})/(2\Delta x) and (pi,j+1−pi,j−1)/(2Δy)(p_{i,j+1}-p_{i,j-1})/(2\Delta y). Staggering normal velocities onto cell faces shrinks the difference stencil to 1Δx1\Delta x, eliminating all three oscillatory modes without adding artificial fourth-order pressure dissipation.


Exercise 2

Problem. Verify that navier_stokes.staggered_mac_projection_2d raises ValueError when given collocated (16, 16) velocity arrays instead of staggered (17, 16) and (16, 17) arrays, and use grids_fvm.verify_discrete_gauss_divergence_2d to show that an uncompensated inlet u0,j=1.5 m/su_{0,j} = 1.5\text{ m/s} into a closed box (Lx=1.0,Ly=0.8 mL_x = 1.0, L_y = 0.8\text{ m}) creates a net volume source ∑(∇h⋅u)ΔV=−1.2 m2/s≠0\sum (\nabla_h\cdot\mathbf{u})\Delta V = -1.2\text{ m}^2/\text{s} \neq 0.


Exercise 2: MAC Shape Mismatch Guard & Net-Flux Solvability check
=================================================================
Uncompensated inlet: sum(div_h u)*dx*dy = -1.200000 == boundary integral = -1.200000

Explanation. You cannot pump incompressible fluid into a rigid sealed container without an equal outflow (∮∂Ωu⋅n ds=0\oint_{\partial\Omega} \mathbf{u}\cdot\mathbf{n}\,ds = 0). In open-channel CFD with inflows and outflows, outlet velocities must always be scaled to satisfy global mass conservation before solving the Neumann pressure Poisson equation.


Exercise 3

Problem. Implement my_staggered_mac_projection_2d(u_face, v_face, dx, dy, dt=1.0) using elliptic_multigrid.poisson_2d_cg(..., neumann=True, tol=1e-12), test it on a 28×2228 \times 22 MAC mesh with random interior face velocities, and verify < 1e-12 agreement with navier_stokes.staggered_mac_projection_2d and max_div_after < 1e-11.


Exercise 3: Implement It Yourself — 2-D Staggered MAC Helmholtz-Hodge Projector
===============================================================================
Max |u_mine - u_ref| = 0.000e+00 | Max |p_mine - p_ref| = 0.000e+00 | max_div_after = 4.903e-13

Summary. Harlow & Welch’s staggered MAC arrangement is the standard arrangement for incompressible flow on structured grids: it has no checkerboard pressure modes, it conserves mass discretely, and its projection does not create kinetic energy. Next, in Lecture 14, we explore an alternative 2-D strategy that eliminates pressure analytically via the curl operator (ω\omega–ψ\psi formulation) to solve the lid-driven cavity problem and compare with the results of Ghia, Ghia and Shin.