Flux-RS is a 2D Computational Fluid Dynamics (CFD) simulation implemented in Rust. It utilizes the Stable Fluids algorithm (Jos Stam) to solve the Navier-Stokes equations for incompressible flow in real-time.
This project was built to explore systems programming, memory safety, and numerical analysis. Key technical features include:
- Navier-Stokes Equations: Implements solvers for Advection, Diffusion, and Pressure Projection.
- Linear Memory Architecture: Uses a flattened 1D array to represent 2D spatial data, optimizing for CPU cache locality and reducing pointer indirection.
- Numerical Stability: Employs a Gauss-Seidel iterative solver for the Poisson pressure equation, ensuring incompressibility and simulation stability.
-
High Performance: Designed with Rust's "Zero-Cost Abstractions," maintaining 60+ FPS on a
$100 \times 100$ grid. -
Hardware Acceleration: Uses
Macroquadfor efficient GPU-accelerated rendering.
The simulation follows these primary steps per frame:
- Diffusion: Spreading density and velocity via an implicit solver.
- Advection: Moving the fluid along its own velocity field using semi-Lagrangian back-tracing.
- Projection: Calculating a pressure field to ensure the velocity field is divergence-free (mass conservation).
Ensure you have Rust installed.
-
Clone the repository:
git clone https://github.com/Chaganti-Reddy/flux-rs.git cd flux-rs -
Run the simulation:
cargo run --release
- Left Click + Drag: Inject smoke (density) and upward force into the simulation.
- Implement Rayon for multi-threaded parallel solvers.
- Add Heat/Thermodynamics simulation (Boussinesq approximation).
- Support for rigid-body obstacles within the flow.
Distributed under the MIT License.