A MATLAB CFD benchmark project for the two-dimensional incompressible lid-driven cavity problem using a SIMPLE-style pressure-correction solver.
This repository contains only the MATLAB implementation.
This project solves the 2D incompressible Navier-Stokes equations for the classical lid-driven cavity benchmark.
The solver includes:
- full 2D incompressible momentum equations,
- pressure-correction / SIMPLE-style coupling,
- loop-based MATLAB implementation,
- vectorized MATLAB implementation,
- upwind and central convection schemes,
- red-black Gauss-Seidel pressure solver,
- red-black SOR pressure solver,
- mesh and Reynolds-number studies,
- validation against Ghia et al. benchmark data,
- automatic generation of plots and summary tables.
The purpose of the project is to understand CFD from the numerical-method level rather than relying only on black-box CFD software.
- MATLAB implementation of a 2D incompressible Navier-Stokes solver.
- SIMPLE-style pressure correction.
- Collocated structured Cartesian grid.
- Vectorized and loop-based solver comparison.
- Upwind and central differencing comparison.
- RBGS and RBSOR pressure solver comparison.
- Mesh study with
N = 32, 64, 128. - Reynolds-number study with
Re = 100, 400, 1000. - Ghia benchmark validation.
- Residual, velocity, pressure, streamline, vorticity, and validation plots.
The continuity equation is:
The incompressible Navier-Stokes equations are:
where:
uandvare velocity components,pis pressure,Reis the Reynolds number.
The solver uses a pressure-correction procedure:
- Initialize velocity and pressure.
- Predict intermediate velocities from the momentum equations.
- Solve the pressure correction Poisson equation.
- Correct velocity using the pressure correction.
- Update pressure with under-relaxation.
- Compute residuals and repeat until convergence or maximum iteration count.
The full study runs:
| Parameter | Values |
|---|---|
| Mesh sizes | 32, 64, 128 |
| Reynolds numbers | 100, 400, 1000 |
| Convection schemes | upwind, central |
| Pressure solvers | RBGS, RBSOR |
| Implementations | loop, vectorized |
Total simulations:
3 x 3 x 2 x 2 x 2 = 72 simulations
The solver is validated against the benchmark centerline velocity data from:
Ghia, U., Ghia, K. N., and Shin, C. T.
"High-Re solutions for incompressible flow using the Navier-Stokes equations and a multigrid method."
Journal of Computational Physics, 48(3), 387-411, 1982.
The validation compares:
- vertical centerline velocity
u(y)atx = 0.5, - horizontal centerline velocity
v(x)aty = 0.5.
Validation data is included for:
Re = 100,Re = 400,Re = 1000.
Lid-Cavity-Evolution/
│
├── README.md
├── LICENSE
├── .gitignore
│
├── main.m
├── main_quick.m
├── main_medium.m
├── default_config.m
│
├── run.sh
├── run_quick.sh
├── run_medium.sh
│
├── core/
├── studies/
├── validation/
├── post/
├── docs/
├── assets/
└── results/
| File | Purpose |
|---|---|
main.m |
Runs the full 72-case study |
main_quick.m |
Runs a smaller quick study |
main_medium.m |
Runs an intermediate study |
default_config.m |
Main configuration file |
| Folder | Purpose |
|---|---|
core/ |
Solver, pressure correction, residuals, boundary conditions |
studies/ |
Study automation scripts |
validation/ |
Ghia benchmark validation |
post/ |
Plotting and result export |
assets/ |
Selected figures for GitHub |
results/ |
Generated results, ignored by Git |
chmod +x run_quick.sh
./run_quick.shor in MATLAB:
main_quickchmod +x run_medium.sh
./run_medium.shor in MATLAB:
main_mediumchmod +x run.sh
./run.shor in MATLAB:
mainGenerated output is saved in:
results/data/
results/figures/
Typical generated files include:
study_summary.csv,- residual plots,
- velocity magnitude contours,
- pressure contours,
- streamlines,
- vorticity plots,
- Ghia validation plots.
The full generated results/ folder is not intended to be committed to GitHub.
Only selected figures are stored in:
assets/figures/
The generated study_summary.csv contains:
| Column | Meaning |
|---|---|
Implementation |
Loop or vectorized |
N |
Mesh size |
Re |
Reynolds number |
Scheme |
Upwind or central |
PressureSolver |
RBGS or RBSOR |
FinalRu |
Final u-velocity residual |
FinalRv |
Final v-velocity residual |
FinalRcMass |
Normalized continuity residual |
FinalRcDiv |
Raw divergence residual |
Runtime_s |
Runtime in seconds |
AvgPoissonIterations |
Average pressure iterations |
Ghia_u_L2 |
L2 error for u centerline |
Ghia_v_L2 |
L2 error for v centerline |
ValidationPass |
Benchmark validation status |
.fig files are MATLAB-native editable figures.
They are useful if you want to reopen a plot in MATLAB and edit:
- axes,
- labels,
- legends,
- colors,
- line widths,
- annotations.
They are not needed for GitHub and are ignored by .gitignore.
This is an educational and research-style MATLAB CFD solver.
Current limitations:
- The solver uses a collocated finite-difference formulation.
- It is not a commercial finite-volume CFD solver.
- Rhie-Chow interpolation is not implemented.
- Turbulence modeling is not included.
- High-Reynolds-number cases require sufficiently fine meshes.
- Coarse high-Reynolds-number cases can be under-resolved.
- The code prioritizes clarity and numerical comparison over maximum performance.
The following generated files are ignored:
*.mat
*.fig
results/data/*
results/figures/*
Only selected plots are included under:
assets/figures/
-
Ghia, U., Ghia, K. N., and Shin, C. T.
High-Re solutions for incompressible flow using the Navier-Stokes equations and a multigrid method.
Journal of Computational Physics, 48(3), 387-411, 1982. -
Patankar, S. V.
Numerical Heat Transfer and Fluid Flow.
Hemisphere Publishing, 1980. -
Ferziger, J. H., Peric, M., and Street, R. L.
Computational Methods for Fluid Dynamics.
Springer, 2002. -
Versteeg, H. K., and Malalasekera, W.
An Introduction to Computational Fluid Dynamics: The Finite Volume Method.
Pearson, 2007.
This project is licensed under the MIT License.
See LICENSE for details.
Ahmed Kandil
- GitHub: Kandil2001
- LinkedIn: Ahmed Kandil
- Email: a.akandil@outlook.com







