This Python script simulates fluid dynamics using a grid-based method. It uses the Navier-Stokes equations for fluid motion and the advection-diffusion equation for density.
- Python 3.x
- NumPy
- Matplotlib
- IPywidgets
-
Install the required libraries if you haven't already:
pip install numpy matplotlib ipywidgets
-
Download the Python script
main.py
. -
Run the script using Python:
python main.py
-
Once the script is running, an interactive widget will appear. Adjust the viscosity and diffusion parameters using the sliders to observe different fluid behaviors.
-
The script initializes parameters such as grid size, time step, diffusion, and viscosity.
-
It defines functions for initializing grids, setting boundaries, solving linear equations, and simulating diffusion, advection, and projection.
-
The
update
function is called in each animation frame to update the density and velocity fields based on the current parameters. -
The simulation is visualized using Matplotlib with density and velocity grids displayed in separate subplots.
-
The interactive widget allows users to adjust viscosity and diffusion parameters in real-time to observe their effects on the fluid simulation.
-
The figure title is set to "Fluid Simulation" to provide a clear visualization window.