A C++17 implementation of the two-dimensional lid-driven cavity benchmark.
This repository is one part of a larger CFD benchmark series where I solve the same physical problem with different tools and implementation styles. The goal is to keep the setup consistent, then compare accuracy, runtime, code structure, and scalability across MATLAB, C++, C, Python, OpenMP, MPI, CUDA, and OpenFOAM.
This version is the serial C++ baseline. I use it as the clean single-core version that later OpenMP, MPI, and CUDA implementations can be compared against. It is not meant to be the fastest version yet; it is meant to be readable, reproducible, and reliable enough for fair comparisons.
- Structured collocated Cartesian grid
- Pseudo-transient pressure-correction algorithm
- Serial C++17 solver
- First-order upwind and central convection schemes
- Red-black Gauss-Seidel and red-black SOR pressure solvers
- Validation against Ghia et al. centreline velocity data
- CSV export for fields, residual histories, and study summaries
- Python post-processing for contours, streamlines, validation plots, and runtime comparisons
The full parameter study runs 36 combinations:
3 meshes × 3 Reynolds numbers × 2 schemes × 2 pressure solvers × 1 implementation
For the whole benchmark series, I want the result layout to stay the same: flow-field plots on one side and Ghia centreline validation on the other. This makes the MATLAB, C++, and later OpenMP/MPI/CUDA/OpenFOAM versions easier to compare.
The C++ example below uses N = 128, Re = 1000, central differencing, RBSOR, and the serial implementation. This case is useful visually because the main recirculation region is clear.
| Flow field | Centreline validation |
|---|---|
The solver advances the non-dimensional incompressible Navier-Stokes equations through pseudo-time. At each outer iteration it predicts the velocity field, solves a pressure-correction Poisson equation, corrects velocity and pressure, reapplies the wall boundary conditions, and records convergence diagnostics.
A more detailed description is available in docs/METHODOLOGY.md.
22/36cases met the selected Ghia centreline-error limits.- All
N = 128cases met the selected validation limits. - The refined-grid central-difference cases gave the best validation behaviour.
- RBSOR gave almost the same validation error as RBGS while strongly reducing pressure-solver cost.
- The full study took about 4.83 hours on the machine where the uploaded results were generated.
The validation limits are practical comparison thresholds, not a replacement for a formal verification or grid-independence study. See docs/RESULTS.md for the full discussion.
On Linux, WSL, or a university cluster:
bash scripts/run_smoke_test.sh # small compilation/output check
bash scripts/run_single.sh # representative case
bash scripts/run_quick.sh # reduced study
bash scripts/run_medium.sh # medium study
bash scripts/run_full.sh # full 36-case studyGenerated files are written to results/data/ and results/figures/. Detailed instructions are in docs/RUNNING.md.
src/ C++ solver
scripts/ build, run, plot, and clean scripts
postprocess/ Python plotting and result-summary tools
assets/ selected figures and published summary data
docs/ methodology, results, validation, scope, and running notes
results/ generated output; full case output is ignored by Git
.github/ smoke-test workflow
For the C++ solver:
g++ with C++17 supportFor the Python post-processing:
python3 -m pip install -r requirements.txtOn Windows, WSL is recommended because the scripts are written for a Linux-style terminal.
This is an educational solver, not a replacement for a production CFD package. It uses a collocated grid without Rhie-Chow interpolation and an iterative pressure solver without multigrid acceleration. The convergence strategy and pressure-velocity treatment are the main areas for further improvement.
- Improve convergence control and stopping criteria
- Split the solver into smaller C++ modules
- Add the OpenMP version and compare it with this serial C++ baseline
- Add MPI and CUDA versions as separate implementations
- Add Python, C, and OpenFOAM versions under the same benchmark specification
- Keep the result layout consistent across all implementations
- Build one comparison table for accuracy, runtime, and speedup across the full benchmark suite
Ghia, U., Ghia, K. N., & Shin, C. T. (1982). High-Re solutions for incompressible flow using the Navier-Stokes equations and a multigrid method. Journal of Computational Physics, 48(3), 387-411.
Ahmed Kandil — Portfolio · LinkedIn
Released under the MIT License.