This repository contains custom, from-scratch Python solvers for the 2D incompressible Navier-Stokes equations. The project demonstrates the implementation of fundamental CFD principles and advanced numerical methods for solving classic fluid dynamics benchmark problems, without relying on external CFD libraries.
The primary goal is to showcase a deep, first-principles understanding of solver architecture, numerical schemes, and validation techniques.
This collection of solvers demonstrates proficiency across a range of essential CFD techniques:
- Discretization: Cell-centered Finite Volume Method (FVM) on structured grids.
- Grid Systems:
- Staggered Grid: To prevent pressure-velocity decoupling and avoid spurious checkerboard pressure fields.
- Stretched Curvilinear Grid: For efficient mesh clustering in regions with high gradients (e.g., near walls and steps).
- Pressure-Velocity Coupling Algorithms:
- SIMPLE Algorithm: The classic Semi-Implicit Method for Pressure-Linked Equations, an iterative segregation-based approach.
- Artificial Compressibility Method: A pseudo-time marching method that allows the use of explicit schemes (like Runge-Kutta) for incompressible flow.
- Schemes:
- Power-Law Scheme: For robust and stable discretization of convection-diffusion terms.
- 2nd-Order Central Differencing: For spatial discretization of fluxes.
- Stability & Time-Stepping:
- 4th-Order Artificial Dissipation: To suppress numerical oscillations and maintain stability in convection-dominated flows.
- 4th-Order Low-Storage Runge-Kutta (LSRK4): For high-accuracy explicit pseudo-time integration with optimized memory usage.
- Linear System Solvers:
- Line-by-Line TDMA (Thomas Algorithm): For solving the resulting algebraic equations.
- Strongly Implicit Procedure (SIP): A combination of Successive Under-Relaxation and TDMA.
This case simulates the developing flow of viscous oil (Re=200) in a 2D channel, including the conjugate heat transfer problem. It serves as a validation for the SIMPLE algorithm.
Figure 3: U velocity contours at Re=200
Figure 4: U velocity contours at Re=200
Results & Validation:
The solver correctly captures the development of the parabolic velocity profile from a uniform inlet. Crucially, the calculated Fanning friction factor converges to the theoretical value of 24/Re = 0.12 for fully developed flow between parallel plates.
This classic CFD benchmark simulates the vortex formation within a square cavity where the top lid moves at a constant velocity. It is an excellent test for the solver's robustness and accuracy in handling strong vortical flows.
Figure 3: U velocity contours at Re=200
Figure 4: U velocity contours at Re=200
- Python 3.x
- NumPy
- Matplotlib
You can install the required packages using pip:
pip install numpy matplotlibTo run a simulation, execute one of the main scripts from the root directory.
To run the Channel Flow simulation:
python main_channel.pyTo run the Backward-Facing Step simulation:
python main_bfs.pyThe scripts will print convergence residuals to the console. Upon completion, plot images (e.g., u_contour.png, streamlines.png) will be saved to the root directory.



