A real-time 3D Smoothed Particle Hydrodynamics (SPH) fluid simulation implemented in Python using OpenGL for visualization.
This project implements a particle-based fluid simulation using the SPH method. The simulation features:
- Real-time 3D visualization using OpenGL
- Interactive camera controls
- Dam break scenario simulation
- Particle pressure and velocity visualization
- Physics-based fluid behavior including:
- Surface tension
- Pressure forces
- Viscosity
- Gravity
- Wall constraints
- Velocity damping
- Clone the repository:
git clone <repository-url>
cd 3D-Fluid-Simulation-Pygame
- Create and activate a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt
make sure you have the pyopengl folder
Run the simulation: inside the 3D-Fluid-Simulation-Pygame folder run:
python sph
you can adjust the particle count in config.py if your system can not handle defult value.
- Arrow Keys: Rotate camera view
- Up/Down: Rotate around X-axis
- Left/Right: Rotate around Y-axis
- Q/E: Zoom in/out
- V: Switch to velocity-based particle coloring
- P: Switch to pressure-based particle coloring
- ESC: Exit simulation
- Particle System: Uses a vectorized particle system for efficient computation
- Real-time Physics: Implements SPH algorithm with:
- Density calculation
- Pressure forces
- Viscosity forces
- Surface tension
- Visualization:
- Smooth particle rendering
- Color coding based on particle properties
- 3D environment with walls and dam
- Real-time FPS and memory usage display
- Performance:
- Optimized neighbor search
- Vectorized calculations using NumPy
- Efficient OpenGL rendering
- Written in Python 3
- Uses PyOpenGL for 3D rendering
- Pygame for window management and user input
- NumPy for efficient numerical computations
- Implements Leapfrog integration for particle physics
- Python 3.9 - 3.12 (pyOpenGL might not install in other versions, tested on 3.10 only)
- NumPy
- Pygame
- PyOpenGL
- PyOpenGL_accelerate
- psutil
The simulation performance depends on:
- Number of particles (configured in config.py)
- Hardware capabilities
- Screen resolution
- Particle size and rendering settings