This project focuses on simulating the Lid-Driven Cavity problem using the Navier-Stokes equations for incompressible fluid flow. The code was developed as part of a master's thesis and aims to bridge the theoretical and numerical aspects of fluid mechanics. Through this work, we study the incompressible Navier-Stokes equations, starting from their derivation from physical conservation laws to their numerical implementation using the Fractional Step Method (FSM). The ultimate goal is to enhance understanding of fluid mechanics by solving the Lid-Driven Cavity problem in a laminar regime.
The Fractional Step Method (FSM) is a numerical technique widely used for simulating incompressible fluid flows. It decouples the pressure and velocity components of the Navier-Stokes equations, allowing their independent calculation. This is achieved through the Helmholtz-Hodge decomposition, which breaks the equations into:
- Intermediate Velocity Calculation: An intermediate velocity field is computed without considering the pressure term.
- Pressure Correction: The pressure is determined by solving a Poisson equation derived from the incompressibility condition.
- Velocity Correction: The intermediate velocity field is updated using the computed pressure to satisfy the incompressibility constraint.
The method uses:
- Finite Volume Method with staggered meshes for spatial discretization.
- Explicit Adam-Bashforth Schemes for temporal discretization.
The Lid-Driven Cavity problem is a classic benchmark in computational fluid dynamics. It involves a two-dimensional square cavity of characteristic length ( L ) filled with a Newtonian, incompressible fluid. The top lid of the cavity moves at a constant characteristic velocity ( U ), while the other three walls remain stationary. The fluid's movement generates a recirculating flow inside the cavity, with distinct pressure gradients and velocity patterns, as shown below:
The moving lid induces a primary circulation that collides with the cavity's boundaries, generating secondary eddies and pressure gradients near the corners.
Clone this repository:
git clone git@github.com:nramirez-f/Lid-Driven-Cavity.git(Optional) Create a virtual enviroment:
python3 -m venv <env-name>Install required libraries:
pip install -r requirements.txtEdit the configuration file to set up the simulation parameters. Below is an example:
from src.fsm import lid_driven_cavity_2D
# Mesh Variables
x0, xf, nx = 0, 1, 10 # X-axis range and number of volumes
y0, yf, ny = 0, 1, 10 # Y-axis range and number of volumes
# Physical Variables
nu = 1/100 # Dynamic viscosity
U = 1 # Characteristic velocity
L = 1 # Characteristic length
Re = (L * U) / nu # Reynolds numberYou can customize the simulation through the main function fsm_2D, which accepts the following arguments:
| Parameter | Description | Default Value |
|---|---|---|
x0, xf, nx |
Start, end, and number of volumes in the X-direction. | Required |
y0, yf, ny |
Start, end, and number of volumes in the Y-direction. | Required |
Re |
Reynolds number. | Required |
nu |
Dynamic viscosity. | Required |
security_factor |
Safety factor for time step calculation. | 0 |
dt |
Time step for simulation. If ( \leq 0 ), CFL condition is applied. | 0 |
convergence_criteria |
Relative error threshold for convergence. | 1e-6 |
bicgstab_flag |
Use BiCGSTAB (1) or LU (0) for Poisson equation. | 0 |
bicgstab_rtol |
Relative tolerance for BiCGSTAB. | 0.001 |
bicgstab_maxiter |
Maximum iterations for BiCGSTAB. | 3000 |
sns_flag |
Enable (1) or disable (0) saving snapshots. | 0 |
sns_step |
Interval for saving snapshots (iterations). | 1000 |
max_iterations |
Maximum number of iterations. | 200000 |
Execute the script to start the simulation. Results will be saved in a simulation directory:
python lid-driven-cavity.pyThe following results are generated:
info.txt: Simulation details.steady_state_contour.png: Contours of velocity (u, v) and pressure (p) at steady state.steady_state_field.png: Velocity field overlaid on pressure contours.snapshots(if enabled): Sequential snapshots of the simulation saved as.npyfiles.
