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 · 12. The projection method and the Taylor–Green vortex

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 12. 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 64×6464 \times 64 periodic mesh [0,2π)2[0, 2\pi)^2 with ν=0.08\nu = 0.08 at t=0.4 st = 0.4\text{ s}, evaluate navier_stokes.taylor_green_vortex_exact and verify pointwise to <10−14< 10^{-14} that ∇2p=+2(∂xu ∂yv−∂yu ∂xv)\nabla^2 p = +2(\partial_x u\,\partial_y v - \partial_y u\,\partial_x v), and verify across t∈{0.0,0.4,1.0}t \in \{0.0, 0.4, 1.0\} that mean enstrophy Z(t)=12⟨ω2⟩\mathcal{Z}(t) = \frac{1}{2}\langle \omega^2 \rangle equals 2Ek(t)2 E_k(t).


Exercise 1: Exact Pressure Poisson Source Identity & Enstrophy-Energy Relation Z(t) = 2*E_k(t)
==============================================================================================
t=0.0 s | max |lap(p) - PPE_rhs| = 6.66e-16 | Z(t) = 0.500000 vs 2*E_k(t) = 0.500000
t=0.4 s | max |lap(p) - PPE_rhs| = 6.66e-16 | Z(t) = 0.439927 vs 2*E_k(t) = 0.439927
t=1.0 s | max |lap(p) - PPE_rhs| = 4.44e-16 | Z(t) = 0.363075 vs 2*E_k(t) = 0.363075

Explanation. Since ux+vy=0  ⟹  ux2+vy2=−2uxvyu_x + v_y = 0 \implies u_x^2 + v_y^2 = -2 u_x v_y, we have −∇⋅[(u⋅∇)u]=−(ux2+2uyvx+vy2)=+2(uxvy−uyvx)-\nabla\cdot[(\mathbf{u}\cdot\nabla)\mathbf{u}] = -(u_x^2 + 2u_y v_x + v_y^2) = +2(u_x v_y - u_y v_x). Using cos⁡2xcos⁡2y−sin⁡2xsin⁡2y=12(cos⁡2x+cos⁡2y)\cos^2 x \cos^2 y - \sin^2 x \sin^2 y = \frac{1}{2}(\cos 2x + \cos 2y), +2(uxvy−uyvx)=−(cos⁡2x+cos⁡2y)e−4νt+2(u_x v_y - u_y v_x) = -(\cos 2x + \cos 2y)e^{-4\nu t} matches ∇2p\nabla^2 p identically (note ∇2p>0\nabla^2 p > 0 at vortex centers (π/2,π/2)(\pi/2, \pi/2), confirming pressure minima inside vortex cores). Moreover, because ∣k∣2=12+12=2|\mathbf{k}|^2 = 1^2 + 1^2 = 2, Parseval’s identity forces Z(t)=∣k∣2Ek(t)=2Ek(t)\mathcal{Z}(t) = |\mathbf{k}|^2 E_k(t) = 2 E_k(t).


Exercise 2

Problem. Demonstrate numerically: (a) on a 24×2424 \times 24 mesh, projecting a divergent velocity field with continuum kx2+ky2k_x^2 + k_y^2 leaves >10−2> 10^{-2} discrete divergence whereas keff2k_{\mathrm{eff}}^2 achieves <10−14< 10^{-14}; and (b) running taylor_green_projection_2d(nx=32, dt=0.18, n_steps=90, nu=0.25) exceeds the 2-D explicit Fourier diffusion bound Δtmax⁡=Δx2/(4ν)≈0.0386\Delta t_{\max} = \Delta x^2 / (4\nu) \approx 0.0386 and blows up.


Exercise 2: Wavenumber Mismatch Divergence Leak & 2-D Explicit Viscous Fourier Blow-Up
======================================================================================
24x24 projection divergence: naive k^2 = 6.3901e-01 vs consistent k_eff^2 = 4.2188e-15
2-D viscous limit dx^2/(4*nu) = 0.0386 s | dt=0.02 err=2.4024e-04 | dt=0.18 blew_up=True

Explanation. Even when pressure projection enforces ∇h⋅un+1=0\nabla_h \cdot \mathbf{u}^{n+1} = 0 at every step, explicit treatment of ν∇h2u\nu \nabla_h^2 \mathbf{u} multiplies the 2-D checkerboard Nyquist mode (π/Δx,π/Δx)(\pi/\Delta x, \pi/\Delta x) by 1−8νΔtΔx21 - \frac{8\nu \Delta t}{\Delta x^2}, so stability demands ∣1−8r∣≤1  ⟹  r=νΔtΔx2≤14|1 - 8r| \leq 1 \implies r = \frac{\nu \Delta t}{\Delta x^2} \leq \frac{1}{4} (twice as strict as 1-D r≤12r \leq \frac{1}{2}).


Exercise 3

Problem. Implement my_taylor_green_projection_2d(nx, dt, n_steps, nu) from scratch in pure NumPy, verify that u, v, and p match navier_stokes.taylor_green_projection_2d on a 40×4040 \times 40 grid (dt=0.0025, n_steps=160, nu=0.12) to < 1e-14, and verify max_divergence < 1e-14.


Exercise 3: Implement It Yourself — 2-D Chorin Fractional-Step Taylor-Green Solver
==================================================================================
Max |u_mine - u_ref| = 0.000e+00 | Max |p_mine - p_ref| = 0.000e+00 | max_div = 4.441e-16

Summary. Chorin’s projection decouples momentum advection-diffusion from incompressibility by solving one scalar elliptic Poisson problem per step; matching the discrete Poisson operator to Dx2+Dy2D_x^2 + D_y^2 guarantees exact discrete mass conservation on periodic domains. Note, however, the zeroed Nyquist modes (sin(pi) = 0) on collocated grids: Lecture 13 shows why wall-bounded collocated grids admit a (−1)i(-1)^i checkerboard pressure mode and how Harlow & Welch’s staggered MAC grid cures it permanently.