This is an updated version of Cavity_FDM_NumPy.
Simple tute scripts can be found at Cavity_FDM_tute.
Lid-driven cavity flow is a fundamental problem in fluid mechanics used to test and validate numerical methods for simulating fluid dynamics, especially in confined spaces.
An incompressible Newtonian fluid is confined in a square cavity where the top lid is set to move at a constant velocity, inducing flow within the cavity. On the other three sides of the cavity, no-slip boundary conditions are imposed to ensure that the fluid velocity is zero. A homogeneous Neumann boundary condition is imposed on all sides of the wall, i.e. the pressure gradient along the wall is zero (a homogeneous Dirichlet condition is applied at the bottom left corner).
This repository provides NumPy implementation and comparison of
- different convection schemes
- different grid systems which are often used in the finite difference method.
For a mathematical understanding of finite difference methods, a great resource can be found here.
You can also play around here.
The governing equations are the incompressible Navier-Stokes equations (dimensionless form):
where
We employ Chorin's projection method (Chorin1968), i.e. split 1 timestep into prediction and correction steps:
where the intermediate velocity field,
In summary, time marching is performed in the following manner:
- Get the intermediate velocity field:
$\mathbf{u}^{(*)} = \mathbf{u}^{(n)} + \Delta t \left( - \left( \mathbf{u}^{(n)} \cdot \nabla \right) \mathbf{u}^{(n)} + \nabla^2 \mathbf{u}^{(n)} / \mathrm{Re} \right)$ - Solve for the next pressure field:
$\nabla^2 p^{(n+1)} = \nabla \cdot \mathbf{u}^{(*)} / \Delta t$ - Get the next velocity field:
$\mathbf{u}^{(n+1)} = \mathbf{u}^{(*)} + \Delta t \left( - \nabla p^{(n+1)} \right)$
Kuwahara-Kawamura scheme uses 5-point stencil along 1 axis. Considering the sign of convective velocity, we have:
Using the relation of
where
For pressure gradient and diffusion, we simply applied the 2nd order central difference scheme.
Gradient:
Diffusion:
We denote the characteristic length as
where
and therefore,
If
Cavity flow is a steady state problem. We assume that the field has reached its steady state when the following condition is satisfied:
where
Following quantities are presented:
| Column name | Description |
|---|---|
| vel | Velocity norm |
| prs | Pressure (shifted so its mean value is zero) |
| div | Velocity divergence (ideally, zero everywhere) |
| vor | Vorticity |
| u | Horizontal velocity along the geometric center |
| v | Vertical velocity along the geometric center |
Horizontal / vertical velocity along the geometric center is compared against compared with Ghia+1982 and Erturk+2005.
To illustrate the difference due to spatial schemes for convection (2nd order central difference is used for pressure gradient and diffusion), we first present the results obtained with different schemes using the same grid system (here Arakawa-B). The Reynolds number is set to
| Scheme | vel | prs | vor | u | v |
|---|---|---|---|---|---|
| 1st order upwind | ![]() |
![]() |
![]() |
![]() |
![]() |
| Lax-Wendroff | ![]() |
![]() |
![]() |
![]() |
![]() |
| QUICK | ![]() |
![]() |
![]() |
![]() |
![]() |
| QUICKEST | ![]() |
![]() |
![]() |
![]() |
![]() |
| Kawamura-Kuwahara | ![]() |
![]() |
![]() |
![]() |
![]() |
Next, to realize the difference due to the choice of grid system, we now present the results by difference grid while using the same spatial schemes (Kawamura-Kuwahara for convection, central difference for pressure gradient and diffusion). The Reynolds number is set to
| Grid | vel | prs | div | u | v |
|---|---|---|---|---|---|
| Arakawa-A | ![]() |
![]() |
![]() |
![]() |
![]() |
| Arakawa-B | ![]() |
![]() |
![]() |
![]() |
![]() |
| Arakawa-C | ![]() |
![]() |
![]() |
![]() |
![]() |
MIT License



































