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.

13. Pressure–velocity coupling, checkerboard modes and the staggered grid

School of Engineering, Nazarbayev University

Suppose you store velocity (ui,j,vi,j)(u_{i,j}, v_{i,j}) and pressure pi,jp_{i,j} together at cell centers (collocated arrangement) and discretize −∇p-\nabla p with standard second-order central differences (pi+1−pi−1)/(2Δx)(p_{i+1} - p_{i-1}) / (2\Delta x). Now insert a sawtooth pressure field pi=(−1)i=+1,−1,+1,−1,…p_i = (-1)^i = +1, -1, +1, -1, \dots of arbitrarily large amplitude: because pi+1p_{i+1} and pi−1p_{i-1} have the same sign, (pi+1−pi−1)/(2Δx)≡0(p_{i+1} - p_{i-1})/(2\Delta x) \equiv 0 everywhere. The momentum equation does not respond to odd–even checkerboard pressure modes, decoupling even-indexed and odd-indexed nodes into two non-communicating subgrids. In 1965, Harlow and Welch introduced the Marker-and-Cell (MAC) staggered grid, placing scalar pi,jp_{i,j} at cell centers while shifting ui+1/2,ju_{i+1/2,j} onto vertical cell faces and vi,j+1/2v_{i,j+1/2} onto horizontal faces. In this lecture we audit 1-D and 2-D checkerboard nullspaces, show the Neumann pressure solvability condition via discrete Gauss divergence, and project divergent face velocities onto ∇h⋅u=0\nabla_h \cdot \mathbf{u} = 0 with navier_stokes.staggered_mac_projection_2d.

Learning objectives

  1. Prove algebraically and numerically via navier_stokes.checkerboard_pressure_audit_1d why collocated central gradients annihilate (−1)i(-1)^i pressure modes while staggered face gradients detect them at full 2/Δx2/\Delta x sensitivity.

  2. Map Harlow & Welch’s (1965) 2-D MAC variable arrangement (pp on (Nx,Ny)(N_x, N_y) centers, uu on (Nx+1,Ny)(N_x+1, N_y) vertical faces, vv on (Nx,Ny+1)(N_x, N_y+1) horizontal faces) and verify discrete Gauss telescoping via grids_fvm.verify_discrete_gauss_divergence_2d.

  3. Explain the Neumann pressure compatibility condition ∑i,j(∇h⋅u∗)i,j ΔxΔy=0\sum_{i,j} (\nabla_h \cdot \mathbf{u}^*)_{i,j}\,\Delta x\Delta y = 0 and zero-mean gauge fixing in elliptic_multigrid.poisson_2d_cg(..., neumann=True).

  4. Project contaminated 2-D velocity fields onto ∥∇h⋅uproj∥∞<10−11\|\nabla_h \cdot \mathbf{u}_{\mathrm{proj}}\|_\infty < 10^{-11} using navier_stokes.staggered_mac_projection_2d and verify discrete Helmholtz–Hodge L2L^2 orthogonality.

Time: about 60 min

1. Physical Principles & The Odd–Even Checkerboard Crisis

In 1-D steady or fractional-step momentum balance, velocity responds only to the pressure gradient ∂xp\partial_x p, never to absolute pressure pp itself (physically, only p0=constp_0 = \mathrm{const} should lie in the nullspace ker⁡(∇)\ker(\nabla)). Compare two discrete gradient operators on a grid of spacing Δx=1\Delta x = 1:

  1. Naive Collocated Central Gradient (spanning 2Δx2\Delta x, skipping cell ii):

    (Gcolp)i=pi+1−pi−12Δx⟹for pi=(−1)i:(−1)i+1−(−1)i−12Δx=0∀i.(1.1)(G^{\mathrm{col}} p)_i = \frac{p_{i+1} - p_{i-1}}{2\Delta x} \quad \Longrightarrow \quad \text{for } p_i = (-1)^i:\quad \frac{(-1)^{i+1} - (-1)^{i-1}}{2\Delta x} = 0 \quad \forall i. \tag{1.1}
  2. Harlow–Welch Staggered MAC Face Gradient (spanning 1Δx1\Delta x right across face i+12i + \frac{1}{2}):

    (GMACp)i+1/2=pi+1−piΔx⟹for pi=(−1)i:(−1)i+1−(−1)iΔx=−2(−1)iΔx≠0.(1.2)(G^{\mathrm{MAC}} p)_{i+1/2} = \frac{p_{i+1} - p_i}{\Delta x} \quad \Longrightarrow \quad \text{for } p_i = (-1)^i:\quad \frac{(-1)^{i+1} - (-1)^i}{\Delta x} = \frac{-2(-1)^i}{\Delta x} \neq 0. \tag{1.2}

In Fourier space (pj=eiθjp_j = e^{i\theta j}, grid phase θ=kΔx∈[−π,π]\theta = k\Delta x \in [-\pi, \pi]), the collocated symbol is isin⁡θ/Δxi\sin\theta / \Delta x, which vanishes both at θ=0\theta = 0 and at Nyquist θ=±π\theta = \pm\pi. The staggered symbol is 2iΔxeiθ/2sin⁡(θ/2)\frac{2i}{\Delta x}e^{i\theta/2}\sin(\theta/2), whose magnitude 2Δx∣sin⁡(θ/2)∣\frac{2}{\Delta x}|\sin(\theta/2)| increases monotonically all the way to its maximum 2/Δx2/\Delta x at θ=±π\theta = \pm\pi.


Demonstration 1: Collocated Checkerboard Blindness vs Staggered MAC Detection
=============================================================================
Alternating pressure p_i = (-1)^i       : [ 1. -1.  1. -1.  1. -1.  1. -1.] ...
Collocated ||(p_{i+1} - p_{i-1})/2||_inf : 0.000000000000000  (zero for the checkerboard mode)
Staggered  || p_{i+1} - p_i ||_inf       : 2.000000000000000  (the full amplitude)
<Figure size 1210x451 with 2 Axes>

Figure 13.1. (a) A checkerboard pressure field in one dimension, its collocated central gradient, which is zero everywhere, and its staggered face gradient, which is ±2\pm 2. (b) Fourier symbol of the collocated and the staggered gradient against the wavenumber, with the exact symbol.

What Demonstration 1 shows. In 2-D, a collocated central stencil has a null space of four linearly independent pressure modes, 1, (−1)i(-1)^i, (−1)j(-1)^j and (−1)i+j(-1)^{i+j}, unless stabilized by Rhie–Chow (1983) momentum interpolation. By contrast, Harlow & Welch’s staggered MAC stencil has a 1-dimensional nullspace consisting solely of the physical hydrostatic constant pi,j=constp_{i,j} = \mathrm{const}.


2. 2-D MAC Topology & Neumann Pressure Solvability

On an Nx×NyN_x \times N_y Cartesian FVM mesh (dx, dy), the 2-D MAC grid stores:

  • Cell-centered pressure & divergence pi,j,(∇h⋅u)i,jp_{i,j}, (\nabla_h \cdot \mathbf{u})_{i,j}: shape (nx, ny)

  • Normal horizontal velocity on vertical faces ui+1/2,ju_{i+1/2, j}: shape (nx + 1, ny)

  • Normal vertical velocity on horizontal faces vi,j+1/2v_{i, j+1/2}: shape (nx, ny + 1)

Every cell’s discrete divergence is an exact compact 1Δx1\Delta x flux balance, and composing MAC divergence with MAC face gradients automatically generates the compact 5-point cell-centered Poisson stencil (with homogeneous Neumann boundary conditions ∂np=0\partial_n p = 0 on impermeable walls where u0,j=uNx,j=vi,0=vi,Ny=0u_{0,j} = u_{N_x,j} = v_{i,0} = v_{i,N_y} = 0):

(∇h⋅u)i,j=ui+1/2,j−ui−1/2,jΔx+vi,j+1/2−vi,j−1/2Δy,∑i=0Nx−1∑j=0Ny−1(∇h⋅u∗)i,j ΔxΔy=∮∂Ωu∗⋅n ds=0(2.1)(\nabla_h \cdot \mathbf{u})_{i,j} = \frac{u_{i+1/2,j} - u_{i-1/2,j}}{\Delta x} + \frac{v_{i,j+1/2} - v_{i,j-1/2}}{\Delta y}, \qquad \sum_{i=0}^{N_x-1}\sum_{j=0}^{N_y-1} (\nabla_h \cdot \mathbf{u}^*)_{i,j}\,\Delta x\Delta y = \oint_{\partial\Omega} \mathbf{u}^* \cdot \mathbf{n}\,ds = 0 \tag{2.1}

Because −∇h2p=f-\nabla_h^2 p = f with pure Neumann walls satisfies ∑i,j(−∇h2p)i,j=0\sum_{i,j} (-\nabla_h^2 p)_{i,j} = 0, a solution exists if and only if the right-hand side has zero mean (∑i,jfi,j=0\sum_{i,j} f_{i,j} = 0, guaranteed automatically by impermeable walls via discrete Gauss divergence), and elliptic_multigrid.poisson_2d_cg(..., neumann=True) fixes the additive constant by projecting onto zero-mean pressure pˉ=0\bar{p} = 0.


Demonstration 2: MAC Telescoping Gauss Theorem & Zero-Mean Neumann Compatibility
================================================================================
Volume integral sum(div_h u*)*dx*dy : +1.776e-16
Boundary flux integral              : +0.000e+00 (discrepancy = 1.776e-16)
Neumann CG converged in 141 iterations | final residual = 6.191e-13
Gauge-fixed mean cell pressure <p>  : +1.028e-18

What Demonstration 2 shows. Interior face fluxes cancel pairwise across every shared cell wall, so ∑i,j(∇h⋅u∗)i,jΔxΔy≡0\sum_{i,j} (\nabla_h \cdot \mathbf{u}^*)_{i,j}\Delta x\Delta y \equiv 0 holds to 10-15 even for random interior velocities, making the Neumann pressure Poisson equation solvable without artificial boundary pressure guesses.


3. 2-D Staggered MAC Projection & Vortex Extraction

We test navier_stokes.staggered_mac_projection_2d on [0,1]2[0, 1]^2 by contaminating an exact solenoidal cellular vortex ψ(x,y)=sin⁡(πx)sin⁡(πy)\psi(x, y) = \sin(\pi x)\sin(\pi y) (usol=∂yψu_{\mathrm{sol}} = \partial_y \psi, vsol=−∂xψv_{\mathrm{sol}} = -\partial_x \psi) with a strong compressible potential flow ∇ϕ\nabla \phi where ϕ(x,y)=0.25cos⁡(πx)cos⁡(2πy)\phi(x, y) = 0.25\cos(\pi x)\cos(2\pi y) (∂nϕ=0\partial_n \phi = 0 on all walls):

u∗=usol+∇ϕ→MAC Projectionuproj≈usol,pcell≈ϕΔt(3.1)\mathbf{u}^* = \mathbf{u}_{\mathrm{sol}} + \nabla \phi \quad \xrightarrow{\text{MAC Projection}} \quad \mathbf{u}_{\mathrm{proj}} \approx \mathbf{u}_{\mathrm{sol}}, \qquad p_{\mathrm{cell}} \approx \frac{\phi}{\Delta t} \tag{3.1}

Demonstration 3: 2-D MAC Projection — Stripping Compressible Contamination to Recover Exact Vortex
==================================================================================================
Max |div_h u| before projection : 12.2788
Max |div_h u| after projection  : 7.550e-13
Recovered solenoidal ||u_proj - u_sol||_2 : 2.3934e-04
Recovered potential  ||p_cell - phi||_2   : 1.0929e-04
Discrete orthogonality <u_proj, grad_h p> : -3.392e-16
<Figure size 1210x473 with 4 Axes>

Figure 13.2. Projection on a staggered grid. (a) Provisional velocity (arrows) and its discrete divergence (colors). (b) Velocity after the projection and the pressure-like potential; the titles give the largest divergence.

What Demonstration 3 shows. The projection removes the potential component ∇ϕ\nabla \phi (the potential is recovered to 1.1×10−41.1\times 10^{-4} in the L2L_2 norm) and leaves the divergence-free vortex unchanged (to 2.4×10−42.4\times 10^{-4}), and satisfies discrete Helmholtz–Hodge orthogonality ⟨uproj,∇hp⟩h=0\langle \mathbf{u}_{\mathrm{proj}}, \nabla_h p \rangle_h = 0 to 10-14.


4. Sensitivity to the parameters

Because u∗=uproj+Δt∇hp\mathbf{u}^* = \mathbf{u}_{\mathrm{proj}} + \Delta t \nabla_h p with uproj⊥∇hp\mathbf{u}_{\mathrm{proj}} \perp \nabla_h p, the discrete face L2L_2 norm obeys an exact Pythagorean energy theorem:

∥u∗∥h2=∥uproj∥h2+∥Δt∇hp∥h2⟹∥uproj∥h2≤∥u∗∥h2(4.1)\|\mathbf{u}^*\|_h^2 = \|\mathbf{u}_{\mathrm{proj}}\|_h^2 + \|\Delta t \nabla_h p\|_h^2 \quad \Longrightarrow \quad \|\mathbf{u}_{\mathrm{proj}}\|_h^2 \leq \|\mathbf{u}^*\|_h^2 \tag{4.1}

Projection never creates spurious kinetic energy, which is important for stability on stretched or anisotropic meshes. We test this Pythagorean identity and Conjugate-Gradient iteration count across grid aspect ratios AR=Δx/Δy∈{0.5,1.0,2.0,4.0}\mathrm{AR} = \Delta x / \Delta y \in \{0.5, 1.0, 2.0, 4.0\}.


Demonstration 4: Pythagorean Energy Theorem & CG Conditioning Across Mesh Aspect Ratios
=======================================================================================
AR = dx/dy |  CG iters |   ||u*||_h^2 |  ||u_p||^2 + ||dp||^2 | Pythagorean diff
--------------------------------------------------------------------------------
       0.5 |       192 |     0.934797 |              0.934797 |        1.110e-16
       1.0 |       124 |     1.869593 |              1.869593 |        0.000e+00
       2.0 |       190 |     3.739187 |              3.739187 |        4.441e-16
       4.0 |       259 |     7.478373 |              7.478373 |        1.776e-15

Inside the algorithm

What Demonstration 4 shows. Why does the discrete Pythagorean theorem hold to 10-13 regardless of cell aspect ratio Δx/Δy\Delta x / \Delta y? Because on a staggered MAC grid with impermeable walls, the negative discrete divergence −DMAC-D^{\mathrm{MAC}} and the interior face gradient GMACG^{\mathrm{MAC}} are exact negative matrix transposes (DMAC=−(GMAC)TD^{\mathrm{MAC}} = -(G^{\mathrm{MAC}})^T), making −DMACGMAC-D^{\mathrm{MAC}} G^{\mathrm{MAC}} symmetric positive semi-definite (ideal for Conjugate Gradient). High aspect ratio (AR=4.0\mathrm{AR} = 4.0) increases matrix condition number κ∝1+AR2\kappa \propto 1 + \mathrm{AR}^2, requiring more CG iterations while preserving exact orthogonality.

Check against the library


Inside the Algorithm: MAC Discrete Adjoint Identity <-div_h(u), q>_cell == <u, grad_h(q)>_face
==============================================================================================
def checkerboard_pressure_audit_1d(n_cells: int = 16) -> dict:
    """Show collocated central gradient annihilates (-1)^i checkerboard while staggered MAC gradient detects it."""
    idx = np.arange(n_cells, dtype=float)
    p_cb = (-1.0) ** idx
    # Periodic collocated central gradient (p_{i+1} - p_{i-1}) / (2*dx):
    grad_collocated = 0.5 * (np.roll(p_cb, -1) - np.roll(p_cb, 1))
    # Staggered face gradient (p_{i+1} - p_i) / dx:
    grad_staggered = np.roll(p_cb, -1) - p_cb
    return {
        "p_checkerboard": p_cb,
        "collocated_grad_norm": float(np.max(np.abs(grad_collocated))),
        "staggered_grad_norm": float(np.max(np.abs(grad_staggered))),
    }

def staggered_mac_projection_2d(
    u_face: np.ndarray,
    v_face: np.ndarray,
    dx: float,
    dy: float,
    dt: float = 1.0,
) -> dict:
    """Project arbitrary staggered MAC face velocities (u_face:(nx+1,ny), v_face:(nx,ny+1)) onto div_h(u) == 0."""
    uf = np.asarray(u_face, dtype=float).copy()
    vf = np.asarray(v_face, dtype=float).copy()
    nx = uf.shape[0] - 1
    ny = uf.shape[1]
    if vf.shape != (nx, ny + 1):
        raise ValueError("Require u_face (nx+1, ny) and v_face (nx, ny+1).")

    # Enforce impermeable normal walls before projection:
    uf[0, :] = 0.0
    uf[-1, :] = 0.0
    vf[:, 0] = 0.0
    vf[:, -1] = 0.0

    div_before = (uf[1:, :] - uf[:-1, :]) / dx + (vf[:, 1:] - vf[:, :-1]) / dy
    cg = poisson_2d_cg(-div_before / dt, dx=dx, dy=dy, neumann=True, tol=1e-12)
    p_cell = cg["u"]

    uf[1:-1, :] -= dt * (p_cell[1:, :] - p_cell[:-1, :]) / dx
    vf[:, 1:-1] -= dt * (p_cell[:, 1:] - p_cell[:, :-1]) / dy
    div_after = (uf[1:, :] - uf[:-1, :]) / dx + (vf[:, 1:] - vf[:, :-1]) / dy
    return {
        "u_projected": uf,
        "v_projected": vf,
        "p_cell": p_cell,
        "max_div_before": float(np.max(np.abs(div_before))),
        "max_div_after": float(np.max(np.abs(div_after))),
    }

Cell inner product <-div_h(u), q> : +4.113271407807
Face inner product <u, grad_h(q)> : +4.113271407807 | difference = 0.000e+00

Exercises

Worked solutions are in 13_solutions.ipynb. The cell below the list is a short self-check to start from.

  1. Verify a result. 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}}.

  2. Find how it fails. 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.

  3. Implement it yourself. 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.


Self-check for the exercises
============================
2-D chessboard (-1)^(i+j): collocated max |grad| = 0.0, MAC max |grad| = 2.0
All checks passed.