C++ Lid-Driven Cavity Solver | Ahmed Kandil

C++ Lid-Driven Cavity Solver

A serial C++17 implementation and parameter study of the two-dimensional incompressible lid-driven cavity benchmark.

Streamlines from the C++ lid-driven cavity solver
36configured executions
3 × 3meshes and Reynolds numbers
22cases meeting selected Ghia limits
C++17serial baseline solver

Problem

The lid-driven cavity benchmark is used as a controlled CFD case for pressure-velocity coupling, mesh sensitivity, convection schemes, convergence behavior, and comparison with Ghia et al. centerline velocity data.

Why this version matters

This implementation moves the reference study into a lower-level compiled language while keeping the numerical setup aligned with the MATLAB version. It provides a documented serial baseline for the broader work-in-progress comparison project.

My contribution

  • Implemented the pressure-correction workflow in serial C++17.
  • Kept the study structure aligned with the MATLAB benchmark.
  • Added CSV export for fields, residual histories, and study summaries.
  • Used Python post-processing for contours, streamlines, Ghia comparisons, and study-level figures.

Numerical methodology

Flow model

Two-dimensional incompressible Navier-Stokes equations with a moving lid and no-slip cavity walls.

Pressure coupling

Pseudo-transient pressure-correction algorithm on a structured collocated Cartesian grid.

Study matrix

N = 32, 64, 128; Re = 100, 400, 1000; upwind/central; RBGS/RBSOR.

Representative results

Results and interpretation

  • All 36 configured cases executed.
  • 22 cases met the selected Ghia centerline-error thresholds.
  • All N = 128 cases met the selected Ghia comparison thresholds.
  • RBSOR reduced pressure-solver cost while producing similar benchmark-comparison errors to RBGS.
  • All full-study cases reached the configured maximum outer-iteration limit, so execution completion must not be confused with residual convergence.

Implemented scope and limitations

The repository records the implemented solver and parameter study as configured. It is an educational solver, not a production CFD package. It uses a collocated grid without Rhie-Chow interpolation, has no multigrid acceleration, and requires stronger convergence control for the high-Reynolds-number cases. These limitations are documented rather than hidden.

© 2026 Ahmed Kandil