Saúl Moreno
Menu
Back to selected workResearch / Rust / Computational Physics · 2026

WCSPH Fluid Simulation

Overview

A fluid simulator built entirely from scratch by me in Rust as a research and engineering project. The interactive 2D solver uses Weakly Compressible Smoothed Particle Hydrodynamics (WCSPH) to model density, pressure, viscosity, surface tension, gravity and boundary interaction without relying on a fixed internal mesh. The project became a substantial algorithmic and optimization challenge: designing the neighbour search, data layout and parallel execution required to keep the simulation responsive at 60 FPS.

A fluid simulator built entirely from scratch

I designed and implemented this simulator entirely by myself, from scratch, as a university project in modelling. It explores how a continuous fluid model can be translated into a particle-based numerical method. The simulator represents a 2D liquid as particles carrying position, velocity, mass, density and pressure, making the behaviour visible while keeping the connection with continuity and momentum equations explicit. The project connects computational implementation with chemical-engineering concepts and required building the simulation core, numerical methods, data structures and interactive renderer as one coherent system.

Weakly Compressible Smoothed Particle Hydrodynamics

The solver uses WCSPH, a Lagrangian mesh-free formulation that reconstructs local fields through weighted sums over neighbouring particles. Density is estimated with a Poly6 kernel, pressure comes from a Tait equation of state, and pressure forces use the symmetric gradient of a Spiky kernel. The model also includes laminar viscosity, surface tension from a colour field, gravity, boundary forces and XSPH velocity smoothing.

An algorithmic optimization challenge built for 60 FPS

The expensive part of SPH is evaluating interactions between nearby particles. I designed the uniform spatial grid used to assign particles to cells and only visit the surrounding nine cells when looking for neighbours. This changes the practical cost of each step from a naive all-pairs approach to a local search suitable for interactive execution. Density, acceleration and integration passes are parallelized with Rayon. Choosing the data layout, reducing unnecessary work and balancing the simulation step against rendering was a major algorithmic and optimization challenge, with the concrete target of sustaining a responsive 60 FPS experience.

Stability is part of the model, not an afterthought

The simulation uses a fixed time step of 1/240 seconds, acceleration and velocity limits, density safeguards, boundary damping, restitution and XSPH correction. These controls keep the WCSPH solver stable enough for real-time interaction while making the trade-off explicit: it is a physically grounded interactive simulator, not a production CFD package. The project documents where numerical stabilization ends and physical modelling begins.

The complete project was built by me from scratch

There is no pre-existing fluid engine behind the demo: I built the simulation core, kernels, neighbour search, integration loop, boundaries, emitters, statistics, interaction model and renderer myself. Rust provides the simulation core, Rayon provides data parallelism, and nannou renders the particle field. The application includes an emitter, upper and lower reservoirs, an open-box setup, real-time statistics and controls to attract or repel the fluid. The accompanying technical article maps the equations directly to the implementation and identifies future work such as CFL-based adaptive stepping, benchmark validation and more incompressible schemes.