Simulation II
10.1 Lagrangian vs. Eulerian Views
Continua such as deformable solids and fluids are essentially fields (velocity, density, temperature). There are two ways to observe and discretize them:
| Lagrangian View | Eulerian View | |
|---|---|---|
| Sensors | Move passively with the simulated material | Fixed in space; never move |
| Question asked | “What are my position and velocity?” | “What is the material velocity passing by?” |
| Discretization | Dynamic particles or mesh | Static grid or mesh |
| Physical quantities | Carried by moving nodes (mass, velocity, …) | Stored at fixed nodes; their values change |
Particle systems and mass-spring systems from Simulation I are Lagrangian. This chapter continues the Lagrangian view with 3D deformable solids and particle fluids, then turns to Eulerian grids and hybrids of the two.
10.2 Lagrangian Deformable Solids
10.2.1 Deformation Gradient
Definition 10.1 (Deformation Map and Deformation Gradient) The deformation map \(\phi\) is a vector-to-vector function relating rest (material) position \(\mathbf{X}\) to deformed position \(\mathbf{x}\):
\[ \mathbf{x} = \phi(\mathbf{X}). \]
The deformation gradient is its Jacobian,
\[ \mathbf{F} := \frac{\partial(\phi_1, \phi_2, \phi_3)}{\partial(X_1, X_2, X_3)} = \begin{pmatrix} \partial\phi_1/\partial X_1 & \partial\phi_1/\partial X_2 & \partial\phi_1/\partial X_3 \\ \partial\phi_2/\partial X_1 & \partial\phi_2/\partial X_2 & \partial\phi_2/\partial X_3 \\ \partial\phi_3/\partial X_1 & \partial\phi_3/\partial X_2 & \partial\phi_3/\partial X_3 \end{pmatrix}, \]
and \(J = \det(\mathbf{F})\) is the deformed-to-rest volume ratio.
Deformation gradients are translation invariant: \(\phi_1(\mathbf{X})\) and \(\phi_2(\mathbf{X}) = \phi_1(\mathbf{X}) + \mathbf{c}\) have the same \(\mathbf{F}\).
10.2.2 Strain Energy and Hyperelasticity
Hyperelastic materials are materials whose stress–strain relationship is defined by a strain energy density function \(\psi = \psi(\mathbf{F})\).
- \(\psi\) is a potential function that penalizes deformation.
- “Stress” refers to the material’s internal elastic forces; “strain” can be read as the deformation gradient \(\mathbf{F}\) for now.
- Do not confuse \(\psi\) (strain energy density) with \(\phi\) (deformation map); they are completely different.
10.2.3 Force and Traction
Point mass: In a conservative field the force is the negative energy gradient, e.g., gravity \(\mathbf{f} = -\partial E(\mathbf{x}) / \partial \mathbf{x} = (0, 0, -mg)\).
Force density: For continuous material, \(\mathbf{f}(\mathbf{X})\) denotes force per unit undeformed volume in an infinitesimal region around \(\mathbf{X}\), so the total force on a region \(A\) is
\[ \mathbf{f}_{\text{aggregate}}(A) = \int_A \mathbf{f}(\mathbf{X})\,d\mathbf{X}. \]
Traction: On boundaries, the traction \(\boldsymbol{\tau}(\mathbf{X})\) is the surface force density per unit undeformed area, so the total force on a boundary surface \(B\) is
\[ \mathbf{f}_{\text{aggregate}}(B) = \oint_B \boldsymbol{\tau}(\mathbf{X})\,dS. \]
10.2.4 Constitutive Models
A constitutive model is a formula relating \(\psi\) and \(\mathbf{F}\). Different models (e.g., neo-Hookean, Mooney–Rivlin, Fung, StVK) produce visibly different behavior under the same load. Linear elasticity is valid only for small deformations; two nonlinear models are popular in graphics.
Definition 10.2 (Neo-Hookean and Fixed Corotated Models) With Lamé parameters \(\mu, \lambda\) and first Piola–Kirchhoff stress \(\mathbf{P}(\mathbf{F}) = \partial\psi / \partial\mathbf{F}\):
Neo-Hookean:
\[ \begin{aligned} \psi(\mathbf{F}) &= \frac{\mu}{2}\sum_i\bigl[(\mathbf{F}^\top\mathbf{F})_{ii} - 1\bigr] - \mu\log(J) + \frac{\lambda}{2}\log^2(J), \\ \mathbf{P}(\mathbf{F}) &= \mu\bigl(\mathbf{F} - \mathbf{F}^{-\top}\bigr) + \lambda\log(J)\,\mathbf{F}^{-\top}. \end{aligned} \]
(Fixed) corotated, where \(\sigma_i\) are the singular values of \(\mathbf{F}\) and \(\mathbf{R}\) is the rotation from the polar decomposition \(\mathbf{F} = \mathbf{R}\mathbf{S}\):
\[ \begin{aligned} \psi(\mathbf{F}) &= \mu\sum_i(\sigma_i - 1)^2 + \frac{\lambda}{2}(J - 1)^2, \\ \mathbf{P}(\mathbf{F}) &= 2\mu(\mathbf{F} - \mathbf{R}) + \lambda(J - 1)J\,\mathbf{F}^{-\top}. \end{aligned} \]
10.2.5 Finite Element Discretization
Discretize the geometry using a tetrahedral mesh or a lattice.
Interpolate vertex positions \(\mathbf{x}\) into a continuous deformation map \(\hat{\phi}(\mathbf{X}; \mathbf{x})\).
Evaluate the strain energy as a function of vertex positions:
\[ E(\mathbf{x}) := E\bigl[\hat{\phi}(\mathbf{X}; \mathbf{x})\bigr] = \int_\Omega \Psi\bigl(\hat{\mathbf{F}}(\mathbf{X}; \mathbf{x})\bigr)\,d\mathbf{X}. \]
Compute the elastic force on each mesh node:
\[ \mathbf{f}_i(\mathbf{x}) = -\frac{\partial E(\mathbf{x})}{\partial \mathbf{x}_i}. \]
10.2.5.1 Linear FEM
Linear FEM assumes that within each element, any reference point \(\mathbf{X}\) maps to
\[ \mathbf{x} = \mathbf{F}\mathbf{X} + \mathbf{c}, \]
with a constant matrix \(\mathbf{F} = \partial\mathbf{x}/\partial\mathbf{X}\) (the deformation gradient) and a constant translation \(\mathbf{c}\). The translation cancels for any edge vector, \(\mathbf{x}_{ba} = \mathbf{x}_b - \mathbf{x}_a = \mathbf{F}\mathbf{X}_b + \mathbf{c} - \mathbf{F}\mathbf{X}_a - \mathbf{c} = \mathbf{F}\mathbf{X}_{ba}\), so the edges of a triangle determine \(\mathbf{F}\):
\[ \mathbf{F}\begin{bmatrix}\mathbf{X}_{10} & \mathbf{X}_{20}\end{bmatrix} = \begin{bmatrix}\mathbf{x}_{10} & \mathbf{x}_{20}\end{bmatrix} \implies \mathbf{F} = \begin{bmatrix}\mathbf{x}_{10} & \mathbf{x}_{20}\end{bmatrix}\begin{bmatrix}\mathbf{X}_{10} & \mathbf{X}_{20}\end{bmatrix}^{-1}. \]
- A tetrahedron uses three edge vectors in the same way: \(\mathbf{F} = [\mathbf{x}_{10}\;\mathbf{x}_{20}\;\mathbf{x}_{30}][\mathbf{X}_{10}\;\mathbf{X}_{20}\;\mathbf{X}_{30}]^{-1}\).
- Because \(\mathbf{F}\) is constant per element, the energy integral becomes a sum of \(\Psi(\mathbf{F}_e)\) weighted by each element’s rest area or volume.
- \(\mathbf{F}\) measures deformation but also contains rotation, which is why models such as fixed corotated factor out \(\mathbf{R}\).
- Sifakis, FEM Simulation of 3D Deformable Solids: A Practitioner’s Guide to Theory, Discretization and Model Reduction (SIGGRAPH 2012 course).
- Jiang et al., The Material Point Method for Simulating Continuum Materials (SIGGRAPH 2016 course), for more constitutive models.
10.3 Smoothed Particle Hydrodynamics (SPH)
A Lagrangian fluid treats each water “molecule” as a particle carrying position \(\mathbf{x}_i\), velocity \(\mathbf{v}_i\), and mass \(m_i\); the particles are typically rendered as a reconstructed liquid surface.
10.3.1 Fluid Forces
Fluid dynamics applies three forces to each particle \(i\):
Gravity: \(\mathbf{F}_i^{\text{gravity}} = m_i\mathbf{g}\).
Pressure: Pressure is related to density. First compute the density of particle \(i\), then convert it to pressure with an empirical equation of state (\(\rho_0\) is the rest density):
\[ \rho_i = \sum_j m_j W_{ij}, \qquad P_i = k\left(\left(\frac{\rho_i}{\rho_0}\right)^7 - 1\right). \]
Pressure force depends on the difference of pressure: a particle surrounded by uniformly high pressure feels no net force, while one with high pressure on one side and low on the other is pushed toward the low side.
Viscosity: Particles should move together with the same velocity, so viscosity minimizes the difference between a particle’s velocity and its neighbors’ velocities.
10.3.2 Smoothed Interpolation
To estimate a quantity \(A\) (velocity, pressure, density, temperature, …) at location \(\mathbf{x}_i\) from neighbors \(j\) with \(\|\mathbf{x}_i - \mathbf{x}_j\| < R\), refine the estimate in three steps:
- Simple average: \(A_i^{\text{smooth}} = \frac{1}{n}\sum_j A_j\). Every neighbor counts equally, so the result is biased toward densely sampled regions.
- Volume-weighted average: Let each particle represent a volume \(V_j\), giving \(A_i^{\text{smooth}} = \frac{1}{n}\sum_j V_j A_j\). This is not smooth: as \(\mathbf{x}_i\) moves, neighbors enter or leave the support abruptly (e.g., \(7 \to 9\) neighbors), so the estimate jumps.
- Kernel-weighted sum: Weight each neighbor by a smoothing kernel \(W_{ij}\) that is large when \(\|\mathbf{x}_i - \mathbf{x}_j\|\) is small and decays to zero as it grows.
Definition 10.3 (SPH Smoothed Interpolation) With smoothing kernel \(W_{ij}\), a quantity \(A\) is interpolated as
\[ A_i^{\text{smooth}} = \sum_j V_j A_j W_{ij}, \qquad V_i = \frac{m_i}{\rho_i^{\text{smooth}}} = \frac{m_i}{\sum_j m_j W_{ij}}, \]
where the volume follows from interpolating density itself, \(\rho_i^{\text{smooth}} = \sum_j V_j \rho_j W_{ij} = \sum_j m_j W_{ij}\). Combined,
\[ A_i^{\text{smooth}} = \sum_j \frac{m_j}{\sum_k m_k W_{jk}} A_j W_{ij}. \]
Smoothed interpolation makes derivatives easy, since they act only on the kernel:
\[ \nabla A_i^{\text{smooth}} = \sum_j V_j A_j \nabla W_{ij}, \qquad \Delta A_i^{\text{smooth}} = \sum_j V_j A_j \Delta W_{ij}. \]
A common choice is the cubic spline kernel with smoothing length \(h\) and \(q = \|\mathbf{x}_i - \mathbf{x}_j\| / h\):
\[ W_{ij} = \frac{3}{2\pi h^3} \begin{cases} \frac{2}{3} - q^2 + \frac{1}{2}q^3, & 0 \le q < 1, \\ \frac{1}{6}(2 - q)^3, & 1 \le q < 2, \\ 0, & q \ge 2. \end{cases} \]
10.3.3 SPH Pressure and Viscosity Forces
Pressure force: The difference of pressure is the pressure gradient. Representing pressure smoothly, \(P_i^{\text{smooth}} = \sum_j V_j P_j W_{ij}\), gives
\[ \mathbf{F}_i^{\text{pressure}} = -V_i \nabla_i P^{\text{smooth}} = -V_i \sum_j V_j P_j \nabla_i W_{ij}. \]
Viscosity force: Smoothing out velocity differences is the velocity Laplacian (with viscosity coefficient \(\nu\)). Representing velocity smoothly, \(\mathbf{v}_i^{\text{smooth}} = \sum_j V_j \mathbf{v}_j W_{ij}\), gives
\[ \mathbf{F}_i^{\text{viscosity}} = \nu m_i \Delta_i \mathbf{v}^{\text{smooth}} = \nu m_i \sum_j V_j \mathbf{v}_j \Delta_i W_{ij}. \]
10.3.4 SPH Algorithm
for each particle i:
N[i] = find_neighbors(i) # performance bottleneck
rho[i] = sum(m[j] * W(i, j) for j in N[i])
P[i] = k * ((rho[i] / rho_0) ** 7 - 1)
for each particle i:
F[i] = m[i] * g + pressure_force(i) + viscosity_force(i)
for each particle i:
v[i] += dt * F[i] / m[i]
x[i] += dt * v[i]The performance bottleneck is the neighborhood search: a naive search costs \(O(n^2)\), so practical solvers bucket particles into a spatial grid or hash table.
10.4 Eulerian Fluids
10.4.1 Height Field Water
In 2D, a (1.5D) height field describes water by a height function \(h(x)\) and a horizontal velocity \(u(x)\).
Mass conservation: The flux through a column face is \(hu\), and the net flux \(d(hu) = h(x + dx)u(x + dx) - h(x)u(x)\) changes the height:
\[ \frac{\partial h}{\partial t} + \frac{\partial (hu)}{\partial x} = 0. \]
Momentum: Velocity changes through advection, pressure (\(\rho\) density, \(P\) pressure), and external acceleration \(a(x)\):
\[ \frac{\partial u}{\partial t} = \underbrace{-u\frac{\partial u}{\partial x}}_{\text{advection}} - \frac{1}{\rho}\frac{\partial P}{\partial x} + \underbrace{a(x)}_{\text{external}}. \]
Simplified momentum: Ignoring advection and external acceleration leaves \(\frac{\partial u}{\partial t} = -\frac{1}{\rho}\frac{\partial P}{\partial x}\), so \(u\) decreases where \(dP > 0\) and increases where \(dP < 0\).
Expanding mass conservation, dropping the \(u\,\partial h/\partial x\) term, and differentiating in \(t\); differentiating the simplified momentum equation in \(x\):
\[ \frac{\partial h}{\partial t} + h\frac{\partial u}{\partial x} = 0 \implies \frac{\partial^2 h}{\partial t^2} + h\frac{\partial^2 u}{\partial x\,\partial t} = 0, \qquad \frac{\partial^2 u}{\partial x\,\partial t} = -\frac{1}{\rho}\frac{\partial^2 P}{\partial x^2}. \]
Definition 10.4 (Shallow Wave Equation) Eliminating \(u\) from the two equations above gives the shallow wave equation
\[ \frac{\partial^2 h}{\partial t^2} = \frac{h}{\rho}\frac{\partial^2 P}{\partial x^2}. \]
10.4.2 Finite Differencing
Finite differencing approximates derivatives by differences, justified by Taylor expansion \(f(t_0 \pm \Delta t) = f(t_0) \pm \Delta t\,f'(t_0) + \frac{\Delta t^2}{2}f''(t_0) \pm \cdots\):
| Scheme | Approximation of \(f'(t_0)\) | Order |
|---|---|---|
| Forward | \(\dfrac{f(t_0 + \Delta t) - f(t_0)}{\Delta t}\) | First |
| Backward | \(\dfrac{f(t_0) - f(t_0 - \Delta t)}{\Delta t}\) | First |
| Central | \(\dfrac{f(t_0 + \Delta t) - f(t_0 - \Delta t)}{2\Delta t}\) | Second |
Applying central differencing twice—first at the half steps \(t_0 \pm 0.5\Delta t\), then between them—estimates second derivatives in time and in space (columns \(i\) of width \(\Delta x\)):
\[ \begin{aligned} \frac{d^2 h_i(t_0)}{dt^2} &\approx \frac{\frac{dh_i(t_0 + 0.5\Delta t)}{dt} - \frac{dh_i(t_0 - 0.5\Delta t)}{dt}}{\Delta t} \approx \frac{h_i(t_0 + \Delta t) + h_i(t_0 - \Delta t) - 2h_i(t_0)}{\Delta t^2}, \\ \frac{d^2 P_i}{dx^2} &\approx \frac{\frac{dP_{i+0.5}}{dx} - \frac{dP_{i-0.5}}{dx}}{\Delta x} \approx \frac{P_{i+1} + P_{i-1} - 2P_i}{\Delta x^2}. \end{aligned} \]
10.4.3 Discretized Shallow Wave Equation
Discretizing the height field into columns \(h_i\) of width \(\Delta x\) and substituting both second differences into the shallow wave equation gives an explicit update from the past and present heights:
\[ h_i(t_0 + \Delta t) = 2h_i(t_0) - h_i(t_0 - \Delta t) + \frac{\Delta t^2 h_i}{\Delta x^2 \rho}(P_{i+1} + P_{i-1} - 2P_i). \]
10.4.3.1 Volume Preservation
Suppose \(\sum_i h_i(t_0) = \sum_i h_i(t_0 - \Delta t) = V\). Summing the update,
\[ \sum_i h_i(t_0 + \Delta t) = V + \sum_i \frac{\Delta t^2 h_i}{\Delta x^2 \rho}(P_{i+1} + P_{i-1} - 2P_i), \]
and the last sum need not be zero because each term carries a different weight \(h_i\). The easy fix is to treat \(h_i\) in the right-hand term as a constant \(H\):
\[ \sum_i h_i(t_0 + \Delta t) = V + \frac{\Delta t^2 H}{\Delta x^2 \rho}\sum_i\bigl[(P_{i-1} - P_i) + (P_{i+1} - P_i)\bigr], \]
where the sum telescopes to zero, so volume is preserved exactly.
10.4.3.2 Pressure and Viscosity
Pressure: Hydrostatic pressure is \(P_i = \rho g h_i\), so the update depends only on heights, with constant \(\alpha = \Delta t^2 H g / \Delta x^2\):
\[ h_i(t_0 + \Delta t) = 2h_i(t_0) - h_i(t_0 - \Delta t) + \alpha\bigl(h_{i+1}(t_0) + h_{i-1}(t_0) - 2h_i(t_0)\bigr). \]
Viscosity: Like damping, viscosity slows down the waves. Rewriting \(2h_i(t_0) - h_i(t_0 - \Delta t) = h_i(t_0) + \bigl(h_i(t_0) - h_i(t_0 - \Delta t)\bigr)\) exposes the momentum term, which is scaled by a viscosity constant \(\beta < 1\):
\[ h_i(t_0 + \Delta t) = h_i(t_0) + \beta\bigl(h_i(t_0) - h_i(t_0 - \Delta t)\bigr) + \alpha\bigl(h_{i+1}(t_0) + h_{i-1}(t_0) - 2h_i(t_0)\bigr). \]
10.4.3.3 Boundary Conditions
The boundary condition decides what replaces the missing neighbor \(h_{i+1}\) in the stencil term \((h_{i+1} - h_i) + (h_{i-1} - h_i)\):
- Dirichlet boundary (open): The boundary height \(H_{i+1}\) is constant, so the term becomes \((H_{i+1} - h_i) + (h_{i-1} - h_i)\).
- Neumann boundary (closed): The boundary derivative is specified; zero derivative means \(h_{i+1} \equiv h_i\), so the term becomes \(h_{i-1} - h_i\) and no water is exchanged through the boundary.
10.4.4 Grid-Based Incompressible Fluids
An Eulerian grid stores physical quantities over a (usually regular) grid: scalars such as density/color, pressure, and temperature, and vectors such as velocity. The grid can be viewed as a sampled scalar or vector field.
Definition 10.5 (Incompressible Viscous Navier–Stokes Equations) With velocity \(\mathbf{u}\), pressure \(p\) (density normalized to \(1\)), and kinematic viscosity \(\nu\):
\[ \nabla \cdot \mathbf{u} = 0 \quad \text{(incompressibility)}, \qquad \frac{\partial \mathbf{u}}{\partial t} = \underbrace{\mathbf{g}}_{\text{external acceleration}} - \underbrace{(\mathbf{u} \cdot \nabla)\mathbf{u}}_{\text{advection}} + \underbrace{\nu\Delta\mathbf{u}}_{\text{(Laplacian) diffusion}} - \underbrace{\nabla p}_{\text{internal pressure}}. \]
The long momentum equation is solved in steps, each updating \(\mathbf{u}\) with one term:
- External acceleration: \(\partial\mathbf{u}/\partial t = \mathbf{g}\).
- Advection: \(\partial\mathbf{u}/\partial t = -(\mathbf{u} \cdot \nabla)\mathbf{u}\).
- Diffusion: \(\partial\mathbf{u}/\partial t = \nu\Delta\mathbf{u}\).
- Pressure projection: \(\partial\mathbf{u}/\partial t = -\nabla p\).
10.4.4.1 Finite Differences on a Grid
A regular grid with spacing \(h\) is friendly to central differencing. First derivatives land on half-indices,
\[ \frac{\partial f_{i+0.5,j}}{\partial x} \approx \frac{f_{i+1,j} - f_{i,j}}{h}, \qquad \frac{\partial f_{i-0.5,j}}{\partial x} \approx \frac{f_{i,j} - f_{i-1,j}}{h}, \]
and differencing them again yields the second derivatives and the five-point discrete Laplacian:
\[ \frac{\partial^2 f_{i,j}}{\partial x^2} \approx \frac{f_{i-1,j} + f_{i+1,j} - 2f_{i,j}}{h^2}, \qquad \Delta f_{i,j} = \frac{\partial^2 f_{i,j}}{\partial x^2} + \frac{\partial^2 f_{i,j}}{\partial y^2} \approx \frac{f_{i-1,j} + f_{i+1,j} + f_{i,j-1} + f_{i,j+1} - 4f_{i,j}}{h^2}. \]
10.4.4.2 Staggered Grid
Central differencing gives the derivative in the middle, which causes a mismatch on a collocated grid:
- A first derivative between cells, e.g., at \((i + 0.5, j)\), has no cell to be stored in.
- Computing \(\partial f_{i,j}/\partial x\) at the cell center needs \(f_{i-1,j}\) and \(f_{i+1,j}\), leaving \(f_{i,j}\) itself unused.
The staggered grid fixes this by storing velocities on faces:
The \(x\)-component \(u_{i,j}\) lives on vertical faces, and the \(y\)-component \(v_{i,j}\) lives on horizontal faces (\(u_{i,j}\) and \(v_{i,j}\) on the left and bottom faces of cell \((i, j)\)).
Face velocities represent flow speed between two cells, so the volume-changing speed of cell \((i, j)\) is \(u_{i+1,j} + v_{i,j+1} - u_{i,j} - v_{i,j}\).
No volume change means the fluid is incompressible, i.e., the velocity field is divergence-free:
\[ \nabla \cdot \mathbf{u}_{i,j} = \frac{\partial u_{i,j}}{\partial x} + \frac{\partial v_{i,j}}{\partial y} \approx \frac{u_{i+1,j} - u_{i,j}}{h} + \frac{v_{i,j+1} - v_{i,j}}{h} = 0 \iff u_{i+1,j} + v_{i,j+1} - u_{i,j} - v_{i,j} = 0. \]
10.4.4.3 Bilinear Interpolation of Staggered Velocities
To sample \(u\) at an arbitrary point \(\mathbf{x} = (x, y)\), shift \(\mathbf{x}\) by the half-cell offset of the \(u\) samples so that \(u_{i,j}\) sits at integer coordinates, take \(i = \lfloor x \rfloor\) and \(j = \lfloor y \rfloor\), and blend the four surrounding samples:
\[ \begin{aligned} u(\mathbf{x}) \leftarrow{} & (i + 1 - x)(j + 1 - y)\,u_{i,j} + (x - i)(j + 1 - y)\,u_{i+1,j} \\ & + (i + 1 - x)(y - j)\,u_{i,j+1} + (x - i)(y - j)\,u_{i+1,j+1}. \end{aligned} \]
The \(v\) component is interpolated the same way with its own offset.
10.4.4.4 Step 1: External Acceleration
Updating \(\mathbf{u}\) by \(\partial\mathbf{u}/\partial t = \mathbf{g}\) simply adds acceleration to \(u\) and \(v\). If gravity is the only external acceleration, only \(v\) changes, with time step \(\Delta t\):
\[ v_{i,j}^{\text{new}} \leftarrow v_{i,j} + \Delta t\,g. \]
10.4.4.5 Step 2: Advection
Advection \(\partial\mathbf{u}/\partial t = -(\mathbf{u} \cdot \nabla)\mathbf{u}\), with \((\mathbf{u} \cdot \nabla)\mathbf{u} = u\,\partial\mathbf{u}/\partial x + v\,\partial\mathbf{u}/\partial y\), can be unstable when finite-differenced in an Eulerian way. Since advection just means carrying physical quantities with the velocity, the semi-Lagrangian method traces a virtual particle backward over time instead:
- Define \(\mathbf{x}_0 \leftarrow (i - 0.5, j)\), the location of sample \(u_{i,j}\).
- Compute \(\mathbf{u}(\mathbf{x}_0)\).
- Trace backward: \(\mathbf{x}_1 \leftarrow \mathbf{x}_0 - \Delta t\,\mathbf{u}(\mathbf{x}_0)\).
- Compute \(\mathbf{u}(\mathbf{x}_1)\) and set \(u_{i,j}^{\text{new}} \leftarrow u(\mathbf{x}_1)\).
Because velocities are staggered, every evaluation of \(\mathbf{u}(\cdot)\) uses staggered bilinear interpolation.
10.4.4.6 Step 3: Diffusion
Applying the discrete Laplacian to each velocity component gives an explicit diffusion step:
\[ \begin{aligned} u_{i,j}^{\text{new}} &\leftarrow u_{i,j} + \nu\Delta t\,\frac{u_{i-1,j} + u_{i+1,j} + u_{i,j-1} + u_{i,j+1} - 4u_{i,j}}{h^2}, \\ v_{i,j}^{\text{new}} &\leftarrow v_{i,j} + \nu\Delta t\,\frac{v_{i-1,j} + v_{i+1,j} + v_{i,j-1} + v_{i,j+1} - 4v_{i,j}}{h^2}. \end{aligned} \]
If \(\nu\Delta t\) is large, these formulae can be unstable.
10.4.4.7 Step 4: Pressure Projection
Staggering makes the pressure gradient update straightforward (with \(\Delta t\) absorbed into \(p\)):
\[ u_{i,j}^{\text{new}} \leftarrow u_{i,j} - \frac{1}{h}(p_{i,j} - p_{i-1,j}), \qquad v_{i,j}^{\text{new}} \leftarrow v_{i,j} - \frac{1}{h}(p_{i,j} - p_{i,j-1}). \]
Pressure is caused by incompressibility: after the update, \(\nabla \cdot \mathbf{u}^{\text{new}} = 0\) must hold, i.e., \(u_{i+1,j}^{\text{new}} + v_{i,j+1}^{\text{new}} - u_{i,j}^{\text{new}} - v_{i,j}^{\text{new}} = 0\). Substituting the update,
\[ \begin{aligned} &\Bigl(u_{i+1,j} - \frac{p_{i+1,j} - p_{i,j}}{h}\Bigr) + \Bigl(v_{i,j+1} - \frac{p_{i,j+1} - p_{i,j}}{h}\Bigr) \\ &\quad - \Bigl(u_{i,j} - \frac{p_{i,j} - p_{i-1,j}}{h}\Bigr) - \Bigl(v_{i,j} - \frac{p_{i,j} - p_{i,j-1}}{h}\Bigr) = 0. \end{aligned} \]
Definition 10.6 (Discrete Pressure Poisson Equation) On a staggered grid with spacing \(h\), the pressure that makes the updated velocity divergence-free solves
\[ 4p_{i,j} - p_{i-1,j} - p_{i+1,j} - p_{i,j-1} - p_{i,j+1} = h\bigl(-u_{i+1,j} - v_{i,j+1} + u_{i,j} + v_{i,j}\bigr), \]
with boundary conditions at a missing neighbor (e.g., \(p_{i-1,j}\)):
- Dirichlet boundary (open): \(p_{i-1,j} = P\) for a constant \(P\).
- Neumann boundary (closed): \(p_{i-1,j} = p_{i,j}\).
Once \(p\) is solved from this sparse linear system, updating \(\mathbf{u}\) with the pressure gradient completes the time step.
10.5 Hybrid Lagrangian–Eulerian Methods
10.5.1 Motivation
A fluid solver usually has two components: advection (evolving the fields) and projection (enforcing incompressibility). Grids and particles are good at opposite halves:
| Advection | Projection | |
|---|---|---|
| Eulerian grids | Bad: dissipative, losing energy and geometry | Good: easy to discretize, efficient neighbor look-up, easy to precondition (geometric multigrid) |
| Lagrangian particles | Good: simply move coordinates; more conservative (lower dissipation) | Bad: tricky to discretize; needs complex data structures for neighbor look-up |
Hybrid methods combine the two: Lagrangian particles store most of the information, while an Eulerian grid (often auxiliary) handles the operations particles are bad at. Each step cycles through four stages:
- Particle-to-grid transfer (P2G).
- Grid operations: pressure projection, boundary conditions, ….
- Grid-to-particle transfer (G2P).
- Particle operations: move particles, update material, ….
10.5.2 Particle-in-Cell (PIC)
Particle-in-cell (Harlow 1964) is the basic transfer scheme:
- P2G: Each particle scatters its quantities (velocity, temperature, force, …) to nearby grid nodes.
- G2P: Each particle gathers the updated quantities back from the same nodes.
- Weights: A particle does not treat its neighbors equally; closer nodes get more importance through a kernel \(N\) (e.g., a quadratic B-spline), giving weights \(w_{ip} = N(\mathbf{x}_i - \mathbf{x}_p)\).
G2P in PIC loses information. With a single particle in 2D and a quadratic B-spline kernel, the \(3 \times 3\) surrounding nodes hold \(18\) velocity DoFs, but the particle keeps only \(2\), so repeated transfers dissipate everything except the average motion. There are two ways to reduce this dissipation:
- Transfer more information: APIC, PolyPIC.
- Transfer the delta: FLIP.
10.5.3 Affine Particle-in-Cell (APIC)
APIC (Jiang et al.) lets each particle carry an affine velocity matrix \(\mathbf{C}_p\) in addition to \(\mathbf{v}_p\), so the particle stores the local velocity field \(\mathbf{v}_p + \mathbf{C}_p(\mathbf{x} - \mathbf{x}_p)\)—in 2D, two constant modes plus four linear modes.
Definition 10.7 (APIC for Incompressible Fluids) With weights \(w_{ip}\) on a grid of spacing \(\Delta x\), one APIC step is:
Particle to grid (P2G):
\[ (m\mathbf{v})_i^{n+1} = \sum_p w_{ip}\bigl[m_p\mathbf{v}_p^n + m_p\mathbf{C}_p^n(\mathbf{x}_i - \mathbf{x}_p^n)\bigr], \qquad m_i^{n+1} = \sum_p m_p w_{ip}. \]
Grid operations: compute grid velocity \(\hat{\mathbf{v}}_i^{n+1} = (m\mathbf{v})_i^{n+1} / m_i^{n+1}\), then apply Chorin-style pressure projection \(\mathbf{v}^{n+1} = \operatorname{Project}(\hat{\mathbf{v}}^{n+1})\).
Grid to particle (G2P):
\[ \begin{aligned} \mathbf{v}_p^{n+1} &= \sum_i w_{ip}\mathbf{v}_i^{n+1} && \text{(particle velocity)}, \\ \mathbf{C}_p^{n+1} &= \frac{4}{\Delta x^2}\sum_i w_{ip}\mathbf{v}_i^{n+1}(\mathbf{x}_i - \mathbf{x}_p^n)^\top && \text{(particle velocity gradient)}, \\ \mathbf{x}_p^{n+1} &= \mathbf{x}_p^n + \Delta t\,\mathbf{v}_p^{n+1} && \text{(particle position)}. \end{aligned} \]
The factor \(4 / \Delta x^2\) is specific to quadratic B-spline weights.
10.5.4 Fluid-Implicit Particle (FLIP)
FLIP (Brackbill & Ruppel 1986; brought to graphics by Zhu & Bridson 2005) does not gather the physical quantity itself; it gathers the delta of the quantity before and after the grid operation:
\[ \text{PIC: } \mathbf{v}_p^{t+1} = \operatorname{gather}(\mathbf{v}_i^{t+1}), \qquad \text{FLIP: } \mathbf{v}_p^{t+1} = \mathbf{v}_p^t + \operatorname{gather}(\mathbf{v}_i^{t+1} - \mathbf{v}_i^t). \]
- Grid operation: Pressure projection in incompressible fluid simulation; internal forces and boundary conditions in solid simulation (MPM).
- Blending: PIC is too dissipative while FLIP is too noisy, so solvers interpolate between them, e.g., \(\text{FLIP0.99} = 0.99 \cdot \text{FLIP} + 0.01 \cdot \text{PIC}\).
- Terminology: Some VFX practitioners say “FLIP” for a whole fluid solver using Chorin-style pressure projection with FLIP advection, but FLIP itself is just an advection scheme.
10.5.5 Choosing a Transfer Scheme
| Scheme | Particle Update | Trade-off |
|---|---|---|
| PIC | Gather new grid velocity | Stable but very dissipative; almost never used in graphics |
| FLIP | Add gathered grid velocity change | Low dissipation but noisy; must store a backup grid velocity |
| APIC | Gather velocity and affine matrix \(\mathbf{C}_p\) | Low dissipation, stable, conserves angular momentum |
| PolyPIC | Gather higher-order polynomial modes | Generalizes APIC to transfer even more information |
The usual suggestion is to start with APIC:
- Easy to implement.
- Storage friendly: no backup velocity field, unlike FLIP.
- Preserves angular momentum.
- Stable, with nice visual results.
- The basis of MLS-MPM.
10.5.6 Material Point Method (MPM)
The material point method is a hybrid Lagrangian–Eulerian simulation scheme, not just an advection scheme: particles carry much more than velocity (mass, volume, deformation gradient, …). Invented by Sulsky & Schreyer in 1996, it entered graphics with snow simulation (Stomakhin et al. 2013) and remains a very active research topic.
- Automatic coupling: Different materials (liquids, solids, granular materials) interact without special handling.
- Automatic (self-)collision handling and fracture.
- Large deformations: Capable of simulating them robustly.
- Division of labor: The Eulerian grid handles collisions and the momentum update; Lagrangian particles track state such as advection and deformation.
10.5.6.1 Moving Least Squares MPM (MLS-MPM)
MLS-MPM (Hu et al. 2018) builds on APIC, halves the FLOPs of traditional MPM (2× faster), and is much easier to implement—88 lines of code in Taichi (ti example mpm88, mpm99, mpm128). The bandwidth-saving cycle (Hu et al. 2019, Taichi) is:
- P2G: For each particle, update it using its (affine) velocity and scatter mass and momentum to the nearby \(3 \times 3 \times 3\) nodes.
- Grid operation: For each grid node, divide momentum by mass to get velocity, then apply gravity and boundary conditions.
- G2P: For each particle, gather velocity and affine velocity from the \(3 \times 3 \times 3\) nodes.
Notation: scalars are non-bold (\(m_i\), \(V_p^0\)); vectors and matrices are bold lower- and upper-case (\(\mathbf{v}_p\), \(\mathbf{C}_p\)); subscript \(i\) marks grid nodes and \(p\) particles; superscripts mark time steps.
Definition 10.8 (Explicit MLS-MPM Step) With initial particle volume \(V_p^0\), deformation gradient \(\mathbf{F}_p\), and first Piola–Kirchhoff stress \(\mathbf{P}\), one explicit MLS-MPM step is:
Particle to grid (P2G):
\[ \begin{aligned} \mathbf{F}_p^{n+1} &= (\mathbf{I} + \Delta t\,\mathbf{C}_p^n)\mathbf{F}_p^n \quad \text{(deformation update)}, \\ (m\mathbf{v})_i^{n+1} &= \sum_p w_{ip}\Bigl\{m_p\mathbf{v}_p^n + \Bigl[m_p\mathbf{C}_p^n - \frac{4\Delta t}{\Delta x^2}V_p^0\,\mathbf{P}(\mathbf{F}_p^{n+1})(\mathbf{F}_p^{n+1})^\top\Bigr](\mathbf{x}_i - \mathbf{x}_p^n)\Bigr\}, \\ m_i^{n+1} &= \sum_p m_p w_{ip}. \end{aligned} \]
Grid operations: \(\hat{\mathbf{v}}_i^{n+1} = (m\mathbf{v})_i^{n+1} / m_i^{n+1}\), then \(\mathbf{v}_i^{n+1} = \operatorname{BC}(\hat{\mathbf{v}}_i^{n+1})\) with boundary condition operator \(\operatorname{BC}\).
Grid to particle (G2P): identical to APIC (Definition 10.7),
\[ \begin{aligned} \mathbf{v}_p^{n+1} &= \sum_i w_{ip}\mathbf{v}_i^{n+1}, \\ \mathbf{C}_p^{n+1} &= \frac{4}{\Delta x^2}\sum_i w_{ip}\mathbf{v}_i^{n+1}(\mathbf{x}_i - \mathbf{x}_p^n)^\top, \\ \mathbf{x}_p^{n+1} &= \mathbf{x}_p^n + \Delta t\,\mathbf{v}_p^{n+1}. \end{aligned} \]
In classical B-spline MPM, the deformation update usually happens after G2P instead.
10.5.6.2 Deformation Update
Deformation gradients evolve because the local velocity field is not constant, \(\nabla\mathbf{v} = \left.\partial\mathbf{v}^n / \partial\mathbf{x}\right|_{\mathbf{x} = \mathbf{x}_p^n} \ne \mathbf{0}\), so the material keeps deforming:
\[ \mathbf{F}_p^{n+1} = (\mathbf{I} + \Delta t\,\nabla\mathbf{v})\mathbf{F}_p^n. \]
MLS-MPM uses the APIC matrix \(\mathbf{C}_p^n\) as the approximation of \(\nabla\mathbf{v}\), giving \(\mathbf{F}_p^{n+1} = (\mathbf{I} + \Delta t\,\mathbf{C}_p^n)\mathbf{F}_p^n\).
10.5.6.3 Internal Forces in P2G
The P2G grid momentum consists of two terms:
- APIC momentum: \(w_{ip}\bigl[m_p\mathbf{v}_p^n + m_p\mathbf{C}_p^n(\mathbf{x}_i - \mathbf{x}_p^n)\bigr]\).
- Particle elastic force (impulse): \(\Delta t\,\mathbf{f}_{ip} = -w_{ip}\frac{4\Delta t}{\Delta x^2}V_p^0\,\mathbf{P}(\mathbf{F}_p^{n+1})(\mathbf{F}_p^{n+1})^\top(\mathbf{x}_i - \mathbf{x}_p^n)\).
For hyperelastic materials, the nodal force is the negative gradient of the total elastic potential energy \(U\), where \(\psi_p\) is the elastic energy density of particle \(p\):
\[ U = \sum_p V_p^0\,\psi_p(\mathbf{F}_p), \qquad \mathbf{f}_i = -\frac{\partial U}{\partial \mathbf{x}_i}. \]
Move the grid forward by a virtual time \(\tau \to 0\): node \(i\) moves to \(\hat{\mathbf{x}}_i = \mathbf{x}_i + \tau\mathbf{v}_i\), the affine matrix is \(\mathbf{C}_p = \frac{4}{\Delta x^2}\sum_i w_{ip}\mathbf{v}_i(\mathbf{x}_i - \mathbf{x}_p)^\top\), and the deformation gradient becomes \(\mathbf{F}'_p = (\mathbf{I} + \tau\mathbf{C}_p)\mathbf{F}_p\). Since \(\partial\hat{\mathbf{x}}_i = \tau\,\partial\mathbf{v}_i\), the chain rule gives
\[ \begin{aligned} \mathbf{f}_i &= -\frac{\partial U}{\partial \mathbf{x}_i} = -\sum_p V_p^0 \frac{\partial \psi_p(\mathbf{F}'_p)}{\partial \hat{\mathbf{x}}_i} = -\sum_p \frac{V_p^0}{\tau}\frac{\partial \psi_p(\mathbf{F}'_p)}{\partial \mathbf{v}_i} \\ &= -\sum_p \frac{V_p^0}{\tau}\, \frac{\partial \psi_p(\mathbf{F}'_p)}{\partial \mathbf{F}'_p}\, \frac{\partial \mathbf{F}'_p}{\partial \mathbf{C}_p}\, \frac{\partial \mathbf{C}_p}{\partial \mathbf{v}_i} \\ &= -\sum_p \frac{V_p^0}{\tau}\,\mathbf{P}_p(\mathbf{F}'_p) \cdot \tau\mathbf{F}_p^\top \cdot \frac{4w_{ip}}{\Delta x^2}(\mathbf{x}_i - \mathbf{x}_p) \\ &= -\frac{4}{\Delta x^2}\sum_p V_p^0\,\mathbf{P}(\mathbf{F}'_p)\,\mathbf{F}_p^\top w_{ip}(\mathbf{x}_i - \mathbf{x}_p). \end{aligned} \]
10.5.6.4 Grid Boundary Conditions
Boundary conditions in MPM are applied on the grid. For every grid node \(i\) within the boundary, with surface normal \(\mathbf{n}\):
\[ \begin{aligned} \mathbf{v}_i^{n+1} &= \operatorname{BC}_{\text{sticky}}(\hat{\mathbf{v}}_i^{n+1}) = \mathbf{0}, \\ \mathbf{v}_i^{n+1} &= \operatorname{BC}_{\text{slip}}(\hat{\mathbf{v}}_i^{n+1}) = \hat{\mathbf{v}}_i^{n+1} - \mathbf{n}\bigl(\mathbf{n}^\top\hat{\mathbf{v}}_i^{n+1}\bigr), \\ \mathbf{v}_i^{n+1} &= \operatorname{BC}_{\text{separate}}(\hat{\mathbf{v}}_i^{n+1}) = \hat{\mathbf{v}}_i^{n+1} - \mathbf{n} \cdot \min\bigl(\mathbf{n}^\top\hat{\mathbf{v}}_i^{n+1}, 0\bigr). \end{aligned} \]
Extra grid operations include adding gravity (\(\hat{\mathbf{v}}_i^{n+1} \mathrel{+}= \Delta t\,\mathbf{g}\)), moving collision objects, and Coulomb friction.