This repository contains a C++ program for simulating fluid dynamics using the Simple and Fast Multimedia Library (SFML). The program implements the Navier-Stokes equations and allows for interactive manipulation of the fluid behavior.
- Fluid simulation with diffusion and advection
- Visualization of the fluid dynamics in a graphical window
- User interaction to add sources and reset the simulation
Before running the program, ensure you have the following prerequisites installed:
- C++ compiler
- SFML library
-
Clone this repository to your local machine:
git clone https://github.com/SJuanOG/box-fluid-simulation.git
-
Compile the code using your C++ compiler. Make sure to link the SFML libraries correctly. For example, using g++:
g++ Fluid.cpp -o fluid_simulation -lsfml-graphics -lsfml-window -lsfml-system
-
Run the compiled executable:
./fluid_simulation
Or simply execute the file execution.sh.
- Left-click to add fluid sources.
- Right-click to reset the simulation.
- Press
Escto close the simulation window.
You can adjust the simulation parameters in the main function of Fluid.cpp, such as the grid size, diffusion, viscosity, and framerate.
This fluid simulation is based on the Navier-Stokes equations and is intended for educational and recreational purposes. The code is inspired by various fluid simulation tutorials and resources available online. Mainly by the paper Real-Time Fluid Dynamics for Games from Jos Stam.