This project implements an incompressible fluid simulation solving the Navier-Stokes equations on the GPU using CUDA. It serves as an example and testbed for Mimir, a library for real-time visualization of GPU data. The simulation supports a variety of obstacle shapes and leverages ImGui for interactive parameter adjustments.
- 2D incompressible Navier-Stokes solver with pressure projection
- Dynamic time step adjustment based on CFL condition
- Multiple obstacle shapes: none, square, circle, triangle, vertical and diagonal barriers
- Visualization via Mimir with buffer views updated directly from GPU memory
- Interactive GUI controls using ImGui for obstacle selection and simulation tuning
- CUDA Toolkit 12.6 (or compatible)
- GCC 12.3 (or newer, supporting C++20)
- CMake 3.17 or newer
- C++20 C++20 standard enabled for host-side code
- Mimir library
- Slang shader language
-
Create a build directory and navigate into it:
mkdir build && cd build
-
Configure the project specifying:
CMAKE_PREFIX_PATH: the root directory where you installed the Mimir libraryMIMIR_SHADER_DIR: the directory containing Mimir shaderscmake .. \ -DCMAKE_PREFIX_PATH=/path/to/mimir_install \ -DMIMIR_SHADER_DIR=/path/to/mimir/shaders
-
Build the project using the following command:
make -j$(nproc) -
Once the build completes successfully, run the simulation from the executables directory:
./fluid_simulation
- Use the GUI to:
- Press the key
Vto toggle the visibility of the emitter barrier - Press the key
Fto toggle whether the obstacle follows the mouse cursor - Select obstacle shape (none, square, circle, triangle, vertical barrier, diagonal barrier)
- Press the key
fluid_simulation.cu: Main simulation logic and visualization setupkernels.cu/kernels.cuh: CUDA kernels implementing the fluid dynamics