School project

Particle-Based Viscoelastic Fluid Simulation

A C++ particle-fluid simulation based on a research paper, combining viscosity, adaptive springs, and double-density relaxation.

  • Simulation
  • C++
  • Physics
  • Particle Methods
  • OpenGL
Watch demo Read report (PDF)

Overview

This was a two-month individual project during my second year of engineering school, when I was still relatively new to computer graphics. The assignment was to choose a research paper and implement its ideas. I chose Particle-based viscoelastic fluid simulation by Simon Clavet, Philippe Beaudoin, and Pierre Poulin.

I implemented a particle-based fluid simulation in C++, combining viscosity, density constraints, and adaptive springs to model viscoelastic behavior. The simulation runs on the CPU, while OpenGL displays the individual particles as small shaded spheres. This is a simulation of particle motion, not a continuous water-surface renderer.

Particle-based fluid simulation, rendered as individual spheres
Particle-based fluid simulation, rendered as individual spheres

Viscosity and double-density relaxation

Each simulation step starts by finding nearby particles, applying gravity and viscosity, and predicting new positions. Viscosity applies pairwise velocity impulses when particles move toward one another, with linear and quadratic coefficients controlling the response.

The solver then uses double-density relaxation to correct particle positions. For every particle, it estimates a local density and a near-density from its neighbors, using distance-dependent quadratic and cubic contributions. These values produce pressure-like terms that push neighboring particles apart or pull them together through positional corrections. After the corrections, the solver reconstructs velocities from the difference between previous and updated positions.

This method works directly with particles, so the simulation does not require a fixed Eulerian fluid grid. It is an implementation of the paper's approach rather than a physically validated fluid solver.

Adaptive springs and viscoelastic behavior

To introduce elastic and plastic behavior, the simulation maintains springs between nearby particles. Each spring stores a rest length. When the distance between its particles moves outside a yield interval, that rest length gradually changes, allowing deformation to persist instead of always returning to the original shape.

The spring system applies positional corrections before density relaxation. Its stiffness, plasticity, and yield parameters can be adjusted, alongside the viscosity and density parameters, to explore different material behaviors.

Neighbor search and interactive controls

Most of the calculations depend on finding nearby particles. Rather than checking every possible pair, the solver uses a spatial hash: particles are grouped into cells, and neighbor candidates are gathered from a cell and its 26 surrounding cells. Distance filtering produces the neighbor lists used by viscosity, springs, and density relaxation.

I used a small OpenGL viewer with Dear ImGui controls to inspect the simulation. It supports two initial particle groups, a particle emitter, parameter sliders, pause/reset, camera movement, and optional frame or particle-position export. The viewer renders individual sphere meshes, keeping the particle representation visible while experimenting with the solver.

From particles to a rendered surface

I later explored a different way to visualize the simulation in my Marching Cubes project, reconstructing a continuous triangle surface from particle positions. The surface reconstruction is a separate project rather than part of this simulator's active rendering pipeline.

Presentation and report

The original project includes a 15-minute presentation and a more detailed written report.