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.

Step 10 -- 2D Poisson Equation

Authors
Affiliations
University of Valencia

The Poisson equation adds a source term to the Laplace equation:

∇2p=b\nabla^2 p = b

Physics: The Poisson equation is the pressure equation in incompressible fluid dynamics. After discretising the Navier--Stokes momentum equations, we must solve a Poisson equation at every time step to enforce the divergence-free constraint. Mastering this solver is a prerequisite for Steps 12 and 13.

What you will learn:

  1. How to solve the Poisson equation with three boundary-condition types

  2. The connection between BC type and spectral method (DST / DCT / FFT)

  3. How the solver converges as the grid is refined (O(Δx2)O(\Delta x^2))

  4. Comparative wall-clock times for different BC types

Arakawa C-Grid and Boundary Conditions

The solver operates on a 2D Arakawa C-grid where scalar fields (temperature, pressure, streamfunction) live at cell centres and velocity components live on cell faces:

       V_{j+1/2}
    ┌─────●─────┐
    │           │
 U  ●     T     ●  U
i-1/2   (i,j)    i+1/2
    │           │
    └─────●─────┘
       V_{j-1/2}

The spectral solver operates on interior cells only. The boundary condition type determines which spectral transform is used.

Three BC types correspond to three spectral transforms:

BC typeTransformGhost condition
Dirichlet (ϕ=0\phi=0)DSTAntisymmetric
Neumann (∂ϕ/∂n=0\partial\phi/\partial n=0)DCTSymmetric
PeriodicFFTWrap-around

1. Dirichlet BCs (DST solver)

Homogeneous Dirichlet: p=0p = 0 on all walls.

Test problem: pexact=sin⁡(πx)sin⁡(πy)p_{\text{exact}} = \sin(\pi x)\sin(\pi y), b=−2π2sin⁡(πx)sin⁡(πy)b = -2\pi^2 \sin(\pi x)\sin(\pi y).

Dirichlet 64x64: L2 error = 5.585729e-02, time = 0.0060s

Visualise the Dirichlet solution:

<Figure size 1000x400 with 4 Axes>

2. Neumann BCs (DCT solver)

Homogeneous Neumann: ∂p/∂n=0\partial p / \partial n = 0 on all walls.

Test problem: pexact=cos⁡(πx)cos⁡(πy)p_{\text{exact}} = \cos(\pi x)\cos(\pi y), b=−2π2cos⁡(πx)cos⁡(πy)b = -2\pi^2 \cos(\pi x)\cos(\pi y).

The cosine modes naturally satisfy zero-derivative BCs.

Neumann 64x64: L2 error = 3.570450e-02, time = 0.0102s

3. Periodic BCs (FFT solver)

Full periodicity in both x and y.

Test problem: pexact=sin⁡(2πx)sin⁡(2πy)p_{\text{exact}} = \sin(2\pi x)\sin(2\pi y), b=−8π2sin⁡(2πx)sin⁡(2πy)b = -8\pi^2 \sin(2\pi x)\sin(2\pi y).

Periodic 64x64: L2 error = 4.198612e-02, time = 0.0054s

4. Convergence study

The spectral solver on a uniform grid with second-order finite differences should converge as O(Δx2)O(\Delta x^2). We vary the grid resolution and measure the L2 error for each BC type.

n=  16  Dir=2.05e-01  Neu=1.42e-01  Per=1.36e-01
n=  32  Dir=1.09e-01  Neu=7.15e-02  Per=7.86e-02
n=  64  Dir=5.59e-02  Neu=3.57e-02  Per=4.20e-02
n= 128  Dir=2.83e-02  Neu=1.78e-02  Per=2.17e-02
<Figure size 1200x500 with 2 Axes>

Summary

| BC type | Spectral method | Test function | somax API | |-----------|--------|-----------| | Dirichlet | DST | "dirichlet" | | Neumann | DCT | "neumann" | | Periodic | FFT | "periodic" |

All three methods converge at O(Δx2)O(\Delta x^2) and run in O(Nlog⁡N)O(N \log N) time. The Poisson solver is the key building block for the pressure projection in Steps 12 and 13.

Next: Step 11 extends the Poisson solver with a Helmholtz (screening) term.