Fluid Animation
Christopher Batty
November 17, 2011
What distinguishes fluids?
What distinguishes fluids?
β’ No βpreferredβ shape
β’ Always flows when force is applied
β’ Deforms to fit its container
β’ Internal forces depend on velocities, not
displacements
Watch fluid simulation clips
Basic Theory
Eulerian vs. Lagrangian
Lagrangian: Point of reference moves with
the material.
Eulerian: Point of reference is stationary.
e.g. Weather balloon (Lagrangian) vs.
weather station on the ground (Eulerian)
Eulerian vs. Lagrangian
Consider an evolving temperature field.
β’ Lagrangian: Set of moving particles,
each with a temperature value.
Eulerian vs. Lagrangian
Consider an evolving temperature field.
β’ Eulerian: A fixed grid of temperature
values, that temperature flows through.
Consider the temperature π(π₯, π‘) at a point following a given path, π₯(π‘).
Two ways temperature changes: 1. Heating/cooling occurs at the current point.
2. Following the path, the point moves to a cooler/warmer location.
Relating Eulerian and Lagrangian
π₯(π‘0)
π₯(π‘1) π₯(π‘πππ€)
Time derivatives
Mathematically:
Chain
rule!
Definition
of π»
Choose ππ₯
ππ‘= π’
π·
π·π‘π π₯ π‘ , π‘ =
ππ
ππ‘+ππ
ππ₯
ππ₯
ππ‘
=ππ
ππ‘+ π»π β
ππ₯
ππ‘
=ππ
ππ‘+ π β π»π
Material Derivative
This is called the material derivative, and
denoted π·
π·π‘ .
Change at the
current (fixed) point.
π·π
π·π‘=ππ
ππ‘+ ππ»π
Change due
to movement.
Change at a point moving
with the velocity field.
Advection
To track a quantity T simply moving (passively) through a velocity field:
This is the advection equation.
Think of colored dye or massless particles drifting around in fluid.
π·π
π·π‘= 0
ππ
ππ‘+ ππ»π = 0 or equivalently
Watch dye in fluid clip
Equations of Motion
β’ For general materials, we have Newtonβs
second law: F = ma.
β’ Specialized for fluids:
βNavier-Stokes Equationsβ
Navier-Stokes
Density Γ Acceleration = Sum of Forces
ππ·π
π·π‘= πππ
Expanding the material derivativeβ¦
πππ
ππ‘= βπ π β π»π + ππ
π
What are the forces on a fluid? Primarily for now:
β’ Pressure
β’ Viscosity
β’ Simple βexternalβ forces β (e.g. gravity, buoyancy, user forces)
Also:
β’ Surface tension
β’ Coriolis
β’ Possibilities for more exotic fluid types: β Elasticity (e.g. silly putty)
β Shear thickening / thinning (e.g. βoobleckβ, ketchup)
β Electromagnetic forces
β’ Skyβs the limit... Watch oobleck clip
In fullβ¦
πππ
ππ‘= βπ π β π»π + ππ
π
Advection
Change in
velocity at a
fixed point
Forces
(pressure,
viscosity
gravity,β¦)
Operator splitting
Break the equation into steps:
1. Advection: πππ
ππ‘= βπ π β π»π
2. Pressure: πππ
ππ‘= πππππ π π’ππ
3. Viscosity: πππ
ππ‘= ππ£ππ πππ ππ‘π¦
4. External: πππ
ππ‘= πππ‘βππ
1. Advection
Advection
Previously, we considered advection of a passive scalar quantity, π, by velocity π.
In Navier-Stokes we saw:
Velocity π is advected by itself!
ππ
ππ‘= βπ β π»π
ππ
ππ‘= βπ β π»π
Advection
i.e., The scalar components π’, π£ of the
vector π are each advected in the same
way.
We can reuse the same numerical method.
2. Pressure
Pressure
What does pressure do?
β Enforces incompressibility.
Typical fluids (mostly) do not compress.
β’ Exceptions: high velocity, high pressure, β¦
Incompressibility
Compressible
velocity field Incompressible
velocity field
Incompressibility
Intuitively, net flow into/out of a given region is zero (no sinks/sources).
Integrate the flow across the boundary of a closed region:
π β ππΞ©
= 0
π
Incompressibility
π β ππΞ©
= 0
By divergence theorem:
π β π = 0
But this is true for any region, so π β π = π everywhere.
Pressure
How does pressure enter in? β Pressure is the force required to ensure that
π» β π = 0.
β Pressure force has the following form:
ππ = βπ»π
Helmholtz-Hodge Decomposition
= +
Input Velocity field Curl-Free
(irrotational)
Divergence-Free
(incompressible)
π’ = π»π + π» Γ π
π’πππ = πΉππππ π π’ππ + π’πππ€
Aside: Pressure as Lagrange Multiplier
Interpret as an optimization:
Find the closest ππππ€ to ππππ where π» β ππππ€ = 0
minππππ€ππππ€ β ππππ
s. t. π» β ππππ€ = 0
A Lagrange multiplier to enforce the
constraint is exactly pressure.
3. Viscosity
[Carlson et al.
2003]
Viscosity
What characterizes a viscous liquid?
β’ βThickβ, damped behaviour
β’ Higher resistance to flow
Watch viscous honey clip
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules in different layers causes shear stress thatβ¦
β’ acts to oppose relative motion.
β’ causes an exchange of momentum
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules in different layers causes shear stress thatβ¦
β’ acts to oppose relative motion.
β’ causes an exchange of momentum
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules in different layers causes shear stress thatβ¦
β’ acts to oppose relative motion.
β’ causes an exchange of momentum
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules in different layers causes shear stress thatβ¦
β’ acts to oppose relative motion.
β’ causes an exchange of momentum
Viscosity
Imagine fluid particles with general velocities.
Each particle interacts with nearby neighbours, exchanging momentum.
Viscosity
Amount of momentum exchanged is proportional to:
β’ Velocity gradient, π»π.
β’ Viscosity coefficient, π
For any closed region, net in/out flow of momentum:
ππ»π β π = ππ β πππΞ©
So the viscosity force is: ππ£ππ πππ ππ‘π¦ = ππ β ππ
Viscosity
The end result is a smoothing of the velocity.
This is exactly the action of the Laplacian
operator, π β π.
For scalar quantities, the same operator is
used to model diffusion.
4. External Forces
External Forces
Any other forces you may want.
β’ Simplest is gravity:
β πΉπ = ππ for π = (0,β9.81)
β’ Buoyancy models are similar,
β e.g., πΉπ = π½(πππ’πππππ‘ β ππππ)π
Numerical Methods
1. Advection
Advection of a Scalar
β’ First, weβll consider advecting a scalar
quantity, π.
β temperature, color, smoke density, β¦
β’ The grid stores π and π.
Eulerian
Approximate derivatives with finite differences. ππ
ππ‘+ π β π»π = 0
FTCS = Forward Time, Centered Space:
πππ+1 β ππ
π
βπ‘+ π’ππ+1
π β ππβ1π
2βπ₯= 0
Unconditionally
Unstable!
Conditionally
Stable!
Lax:
πππ+1 β (ππ+1
π + ππβ1π)/2
βπ‘+ π’ππ+1
π β ππβ1π
2βπ₯= 0
Many possible methods, stability can be a challenge.
Lagrangian
β’ Advect data forward from grid points by integrating position according to grid velocity.
β’ Problem: New data position doesnβt necessarily land on a grid point.
?
Semi-Lagrangian
β’ Look backwards in time from grid points,
to see where data is coming from.
β’ Interpolate data at previous time.
Semi-Lagrangian - Details
1. Determine velocity ππ,π at grid point,.
2. Integrate position for a timestep of ββπ‘.
e.g. π₯ππππ = π₯π,π β βπ‘ππ,π
3. Interpolate π at π₯ππππ, call it πππππ.
4. Assign ππ,π = πππππ for the next time.
Unconditionally stable!
Advection of Velocity
β’ This is great for scalars. What about velocity advection?
β’ Same method: β Trace back with current velocity
β Interpolate velocity (component) at that point
β Assign it to the grid point at the new time.
β’ Caution: Do not overwrite the velocity field youβre using to trace back!
ππ
ππ‘= βπ β π»π
2. Pressure
Recall⦠Helmholtz-Hodge
Decomposition
= +
Input Velocity field Curl-Free
(irrotational)
Divergence-Free
(incompressible)
π’ = π»π + π» Γ π
π’πππ = πΉππππ π π’ππ + π’πππ€
Pressure Projection - Derivation
(1) πππ
ππ‘= βπ»π and (2) π» β π = 0
Discretize (1) in timeβ¦
ππππ€ = ππππ ββπ‘
ππ»π
Then plug into (2)β¦
π» β ππππ ββπ‘
ππ»π = 0
Pressure Projection
Implementation:
1) Solve a linear system for p: βπ‘
ππ» β π»π = π» β ππππ
2) Update grid velocity with:
ππππ€ = ππππ ββπ‘
ππ»π
Implementation
Discretize with finite differences:
e.g., in 1D:
βπ‘
π
ππ+1 β ππβπ₯
βππ β ππβ1βπ₯
βπ₯=π’π+1πππ β π’π
πππ
βπ₯
ππ+1 ππβ1 ππ
π’π+1 π’π
βπ‘
ππ» β π»π = π» β ππππ
Solid Boundary Conditions
52
π
π
Free Slip: ππππ€β π = 0
Staggered vs. Non-staggered
β’ Two choices for grids:
β Velocity and pressure co-located
β Velocity and pressure staggered
ππ+1 ππβ1 ππ
ππ+1 ππβ1 ππ
π’π+1 π’π
π’π+1 π’π π’πβ1
Why prefer staggered?
β’ Finite differences line up nicely.
β π’ and π»π match, π and π» β π’ match
β’ β¦which improves stability!
ππ+1 ππβ1 ππ
π’π+1 π’π
3. Viscosity
[Carlson et al.
2003]
Viscosity
PDE: πππ
ππ‘= ππ» β π»π
Use finite differences.
Discretized in time:
ππππ = ππππ +βπ‘πππ» β π»πβ
Viscosity β Time Integration
ππππ = ππππ +βπ‘ππ π» β π»πβ
Explicit integration, let πβ be ππππ: β Just estimate βπ‘π
ππ» β π»ππππ
β Add to current π. β Very unstable.
Implicit integration, let πβ be ππππ€: β Stable for high viscosities.
β Need to solve a system of equations.
Viscosity β Implicit Integration
Solve for ππππ:
ππππ ββπ‘πππ» β π»ππππ€ = ππππ
Apply separately for each velocity component.
e.g. in 1D:
π’π ββπ‘π
π
π’π+1 β π’πβπ₯
βπ’π β π’πβ1βπ₯
βπ₯= π’ππππ
π’π+1 π’πβ1 π’π
Solid Boundary Conditions
59
No-Slip: ππππ€= 0
Watch no-slip clip
4. External Forces
Gravity
Discretized form is: ππππ = ππππ + βπ‘π
Just add a downward acceleration to each
velocity, scaled by timestep.
Gravity
β’ Note: in a closed fluid-filled container,
gravity (alone) wonβt do anything!
β Incompressibility cancels it out. β (Assuming constant density)
Start After gravity step After pressure step
Simple Buoyancy
Look up πππ’πππππ‘ at grid point,
increment velocity based on difference
from a reference velocity.
ππππ = ππππ + βπ‘π½ πππ’πππππ‘ β ππππ π
π½ dictates the strength of the
buoyancy force.
See paper for a more elaborate model:
βVisual simulation of smokeβ, 2001.
User Forces
Add whatever additional forces we want,
such as:
β’ near the mouse when the user clicks
β’ Paddle forces in Plasma Pong
Watch clip
Ordering of Steps
Order turns out to be important.
Why?
1) Incompressibility is not guaranteed at
intermediate steps
2) Advecting with a compressible field
causes volume/material loss or gain!
Ordering of Steps
Consider advection in this field:
Best ordering
1) Advection
2) Viscosity
3) Add Forces
4) Make incompressible (Pressure)
Useful References
β’ Robert Bridsonβs SIGGRAPH 2007 Fluid
Course notes: http://www.cs.ubc.ca/~rbridson/fluidsimulation/
β’ βStable Fluidsβ [Stam 1999]
β’ βReal-Time Stable Fluid Dynamics for
Gamesβ [Stam, 2003]
Liquids
Liquids
Whatβs missing so far?
We need:
β’ A surface representation
β’ Boundary conditions at the surface
The Big Picture
Velocity Solver
Advect Velocities
Add Viscosity
Add Gravity
Project Velocities
to be
Incompressible
What about liquids?
Advect Velocities
Add Viscosity
Add Gravity
Project Velocities
to be
Incompressible
Surface Tracker
Velocity Solver
Surface Tracker
Given: liquid surface geometry, velocity field,
timestep
Compute: new surface geometry by
advection.
ππ
ππ+1
ππ
Surface Tracker
Ideally:
β’ Efficient
β’ Accurate
β’ Handles merging/splitting (topology changes)
β’ Conserves volume
β’ Retains small features
β’ Smooth surface for rendering
β’ Provides convenient geometric operations
β’ Easy to implementβ¦
Very hard (impossible?) to do all of these at once.
Surface Tracking Options
1. Particles
2. Level sets
3. Volume-of-fluid (VOF)
4. Triangle meshes
5. Hybrids (many of these)
Particles
[Zhu & Bridson 2005]
Particles
Perform passive Lagrangian advection on
each particle.
For rendering, need to reconstruct a surface.
Level sets
[Losasso et al.
2004]
Level sets Each grid point stores signed distance to the
surface (inside <= 0, outside > 0).
Surface is interpolated zero isocontour.
> 0
<= 0
Volume of fluid
[Mullen et al 2007]
Volume-Of-Fluid
Each cell stores fraction f Ο΅ 0,1 indicating
how empty/full it is.
Surface is transition region, f β 0.5.
0
0
0
0
0
0
0
0
0
0
0
0.4
0.4
0
0
0.
8
1
1
0.8
0.5
1
1
1
1
1
1
1
1
1
1
Meshes
[Brochu et al 2010]
Meshes
Store a triangle mesh.
Advect its vertices, and correct for collisions.