Smoothed Particle Hydrodynamics (SPH) Huamin Wang
Fluid Representation Fluid is represented using a set of particles. Particle i has position x i, velocity v i, and mass m i.
Animation Example Using 10 million particles http://www.youtube.com/watch?v=q4_quqtgtm A
Smoothed Particle Interpolation Suppose each particle has a physical quantity A. The quantity can be: velocity, pressure, density, temperature. How to estimate the quantity at a new location X i? A simple solution: A i smooth = A For X i X < r A 0 A 5 A 4 A 6 A i? A 1 A 3 A 2
Smoothed Particle Interpolation Instead of assuming a particle is volumeless, let us assume each one has a volume V i. So a better solution is: A i smooth = V A For X i X < r A 0 A 5 A 4 A 6 A i? A 1 A 3 A 2
Smoothed Particle Interpolation One problem of this solution: A i smooth = V A Not smooth! (red 7 -> green 9!) For X i X < r i
Smoothed Particle Interpolation Final solution: A i smooth = V A W i W i is called smoothing kernel. When X i X is large, W i is small. When X i X is small, W i is large. For X i X < r i
Particle Volume But how do we get the volume of particle i? ρ i = V ρ W i V i = m i ρ i V i = m 0 ρ i = m W i m i m W i m 5 m 4 m 6 m 3 m 2 m 1
Final Interpolation Solution So the actual solution is: A i smooth = V A W i V = k m m k W k A i smooth = k m m k W k A W i
The advantage of This Interpolation We can easily compute its derivatives: Gradient A i smooth = V A W i A smooth i = V A W i Laplacian A i smooth = V A W i A smooth i = V A W i
A Smoothing Kernel Example W i = 3 2πh 3 2 3 q2 + 1 2 q3 (0 q < 1) 1 6 (2 q)3 (1 q < 2) 0 (2 q) q = x i x h h is called smoothing length
Kernel Derivatives Gradient at particle i (a vector) i W i = W i x i W i y i W i z i = W i q q = W i i q x i x x i x h q = x i x h W i = 3 2πh 3 2 3 q2 + 1 2 q3 (0 q < 1) 1 6 (2 q)3 (1 q < 2) 0 (2 q) W i q = 3 2πh 3 2q + 3 2 q2 (0 q < 1) 1 2 (2 q)2 (1 q < 2) 0 (2 q)
Kernel Derivatives Laplacian at particle i (a scalar) i W i = 2 W i x i 2 + 2 W i y i 2 + 2 W i z i 2 = 2 W i q 2 1 h 2 + W i q 2 h q = x i x h W i q = 3 2πh 3 2q + 3 2 q2 (0 q < 1) 1 2 (2 q)2 (1 q < 2) 0 (2 q) 2 W i q 2 = 2 + 3q (0 q < 1) 3 2 q (1 q < 2) 2πh 3 0 (2 q)
Fluid Dynamics We model fluid dynamics by applying three forces on particle i. Gravity Fluid Pressure Fluid Viscosity i
Gravity Force is: Gravity Force F i gravity = m i g i
Pressure Force Pressure is related to the density First compute the density of Particle i: ρ i = m W i Convert it into pressure (some empirical function): P i = k ρ i ρ constant 7 1 High Pressure Low pressure
Pressure Force Pressure force depends on the difference of pressure: High Pressure High Pressure High Pressure High Pressure High Pressure Low Pressure High Pressure i High Pressure High Pressure i Low Pressure No pressure force! Pressure force!
Pressure Force Mathematically, the difference of pressure => Gradient of pressure. F i pressure = V i i P smooth To compute this pressure gradient, we assume that the pressure is also smoothly represented: So: P i smooth = F i pressure = V i V P W i V P i W i
Viscosity Force Viscosity effect means: particles should move together in the same velocity. In other words, minimize the difference between the particle velocity and the velocities of its neighbors. Before Ultimately
Viscosity Force Mathematically, it means: F i vis cos ity = νm i i v smooth To compute this Laplacian, we assume that the velocity is also smoothly represented: So: v i smooth = F i vis cos ity = νm i V v W i V v i W i
For every particle i Algorithm Compute its neighborhood set Using the neighborhood, compute: Force = 0 Force + = The gravity force Force + = The pressure force Force + = The viscosity force Update v i = v i + t * Force / m i ; Update x i = x i + t *v i ; What is the bottleneck of the performance here?
Exhaustive Neighborhood Search Search over every particle pair? O(N 2 ) 10M particles means: 100 Trillion pairs i
Solution: Spatial Partition Separate the space into cells Each cell stores the particles in it To find the neighborhood of i, ust look at the surrounding cells i
Spatial Partition What if particles are not uniformly distributed? Solution: Octree, Binary Spatial Partitioning tree i
Fluid Display Need to reconstruct the water surface from particles!
Ongoing Research How to make the simulation more efficient? How to make fluids incompressible? When simulating water, only use water particles, no air particles. So particles are sparse on the water-air boundary. How to avoid artifacts there?