Position-Based Fluids: Density and Surface Constraints

The Position-Based Dynamics framework can be elegantly extended from solids to simulate incompressible fluids. The resulting method, known as Position-Based Fluids (PBF) [Macklin & Muller 2013], replaces the complex pressure solves of traditional Smoothed Particle Hydrodynamics (SPH) [Koschier et al. 2020] with a set of geometric constraints. This approach inherits the stability and efficiency of PBD, allowing for large time steps suitable for real-time applications, while effectively enforcing the constant-density condition that characterizes incompressible flow.

The Per-Particle Density Constraint

The fundamental principle of PBF is to ensure that the density around each fluid particle remains constant. The density at a given particle's location is estimated using a kernel-based summation over its neighbors.

The density for a particle at position is estimated as: where the sum is over all neighboring particles , is the mass of particle , is the smoothing kernel radius, and is a radially symmetric smoothing kernel function. For simplicity, we can assume all particles have equal mass and absorb it into the density calculation.

The goal is to enforce that this estimated density matches a user-defined rest density . This is formulated as a per-particle constraint function .

Definition 33.4.1 (PBF Density Constraint). For each particle , the density constraint is defined as the scaled deviation from the rest density : The constraint is satisfied when .

To solve this system of constraints, PBF computes a position correction for each particle. Following the PBD methodology, we first compute the gradient of with respect to the position of a particle : The standard PBD solver computes a single Lagrange multiplier for each constraint using the formula . The position correction for a particle is then derived from the influence of its own constraint and the constraints of its neighbors. Due to the symmetry of the kernel gradient (), this results in a simple and efficient final update rule for the position correction of particle : Here, a different kernel, the Spiky kernel, is typically used for its non-vanishing gradient, which prevents particle clustering.

Remark 33.4.1 (Robustness and Constraint Softening). A practical issue arises when a particle has few neighbors, as the denominator can approach zero, leading to large, unstable position corrections. To prevent this, a small relaxation parameter is added to the denominator, softening the constraint. This is known as Constraint Force Mixing (CFM) [Smith & others 2005]. Then:

Correcting for Tensile Instability

A well-known artifact in SPH-based fluid simulations is the "tensile instability," where particles near a free surface clump together due to an inability to satisfy the rest density. PBF offers a direct solution by incorporating an artificial pressure term.

Specifically, an artificial pressure term, , is introduced to create a short-range repulsive force between nearby particles. This term is a function of : where and are small positive constants (e.g., ), and is a vector representing a small distance within the kernel radius (e.g., ). This term is only applied to push particles apart and is incorporated directly into the position correction calculation from Equation (33.4.4): This prevents clumping, and implicitly creates a surface tension-like effect at the fluid's boundary.

Velocity-Level Corrections: Viscosity and Vorticity

While the primary constraints in PBF operate on positions, velocity-level updates are still necessary to model phenomena like viscosity and to reintroduce lost energy. These are applied as a post-process after the main PBD solver loop has updated positions and velocities.

XSPH Viscosity: To impart a more coherent, liquid-like motion and reduce particle intermixing, XSPH viscosity is applied. It adjusts each particle's velocity to be closer to the average velocity of its neighbors: where is a positive viscosity coefficient, typically a small value like .

Vorticity Confinement: The iterative nature of PBD can introduce numerical damping, causing the fluid to lose rotational energy and appear overly viscous. Vorticity confinement can be used to counteract this by calculating the vorticity (curl of the velocity field) at each particle and applying a corrective force to reintroduce small-scale rotational details. This force is then integrated to update particle velocities.