Post on 09-Aug-2018
What distinguishes fluids?
โข No โpreferredโ shape.
โข Always flows when force is applied.
โข Deforms to fit its container.
โข Internal forces depend on velocities, not
displacements (compare v.s., elastic objects)
Examples
For further detail on todayโs material, see Robert Bridsonโs online fluid notes.
http://www.cs.ubc.ca/~rbridson/fluidsimulation/
(Thereโs also a book.)
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 scalar field (e.g., temperature).
Lagrangian view: Set of moving particles, each with a
temperature value.
Eulerian vs. Lagrangian
Consider an evolving scalar field (e.g., temperature).
Eulerian view: A fixed grid of temperature values, that
temperature flows through.
Consider the temperature ๐(๐ฅ, ๐ก) at a point following a given path, ๐ฅ(๐ก).
How can temperature measured at ๐ฅ(๐ก) change?1. There is a hot/cold โsourceโ 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๐ท
๐ท๐ก.
(AKA total derivative.)
Change at the current
(fixed) point.
๐ท๐
๐ท๐ก=๐๐
๐๐ก+ ๐๐ป๐
Change due
to movement
of the point.
Change at a point moving
along the given path, x(t).
Advection
To track a quantity T moving (passively) through a velocity field:
This is the advection equation.
Think of colored dye or massless particles drifting around in fluid.
๐ท๐
๐ท๐ก= 0
๐๐
๐๐ก+ ๐๐ป๐ = 0or equivalently
Equations of Motion
For general materials, we have Newtonโs
second law: F = ma.
The Navier-Stokes equations are essentially
the same equation, specialized to fluids.
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, paints)
โ Electromagnetic forces: magnetohydrodynamics, ferrofluids, etc.
โข Skyโs the limit...
In fullโฆ
๐๐๐
๐๐ก= โ๐ ๐ โ ๐ป๐ +
๐
๐ญ๐
Advection (of
velocity)
Change in
velocity at a
fixed point
Forces
(pressure,
viscosity
gravity,โฆ)
Operator splitting
Break the full, nonlinear equation into sub-
steps:
1. Advection: ๐๐๐
๐๐ก= โ๐ ๐ โ ๐ป๐
2. Pressure: ๐๐๐
๐๐ก= ๐ญ๐๐๐๐ ๐ ๐ข๐๐
3. Viscosity: ๐๐๐
๐๐ก= ๐ญ๐ฃ๐๐ ๐๐๐ ๐๐ก๐ฆ
4. External: ๐๐๐
๐๐ก= ๐ญ๐๐กโ๐๐
Advection
Earlier, we considered advection of a passive scalar quantity, ๐, by velocity ๐.
In Navier-Stokes we saw:
Velocity ๐ is advected by itself!
๐๐
๐๐ก= โ๐ โ ๐ป๐
๐๐
๐๐ก= โ๐ โ ๐ป๐
Advection
That is, ๐ข, ๐ฃ, ๐ค components of velocity ๐ are
advected as separate scalars.
May be able to reuse the same numerical
method.
Pressure
What does pressure do?
โ Enforces incompressibility (fights compression).
Typical fluids (mostly) do not compress.
โข Exceptions: high velocity, high pressure, โฆ
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.
Incompressibility implies ๐ is divergence-free.
Pressure
Where does pressure come in?
โ Pressure is the force needed to enforce the
constraint ๐ป โ ๐ = 0.
โ Pressure force has the following form:
๐ญ๐ = โ๐ป๐
Helmholtz Decomposition
= +
Input (Arbitrary)
Velocity Field
Curl-Free
(Irrotational)
Divergence-Free
(Incompressible)
๐ข = ๐ป๐ + ๐ป ร ๐
๐ข๐๐๐ = ๐น๐๐๐๐ ๐ ๐ข๐๐ + ๐ข๐๐๐ค
Aside: Pressure as Lagrange Multiplier
Interpret as an optimization:
Find the closest ๐๐๐๐ค to ๐๐๐๐ where ๐ป โ ๐๐๐๐ค = 0
argmin๐๐๐๐ค
๐
2๐๐๐๐ค โ ๐๐๐๐
2
subject to ๐ป โ ๐๐๐๐ค = 0
The Lagrange multiplier that enforces the constraint is the pressure.e.g., recall the โfast projectionโ paper, Goldenthal et al. 2007.
Viscosity
What characterizes a viscous liquid?
โข โThickโ, damped behaviour.
โข Strong resistance to flow.
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules causes shear stressthatโฆ
โข opposes relative motion.
โข causes an exchange of momentum.
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules causes shear stressthatโฆ
โข opposes relative motion.
โข causes an exchange of momentum.
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules causes shear stressthatโฆ
โข opposes relative motion.
โข causes an exchange of momentum.
Viscosity
Loss of energy due to internal friction between molecules moving at different velocities.
Interactions between molecules causes shear stressthatโฆ
โข opposes relative motion.
โข causes an exchange of momentum.
Viscosity
Imagine fluid particles with general velocities.
Each particle interacts with nearby neighbours, exchanging momentum.
Diffusion
The momentum exchange is related to:
โข Velocity gradient, ๐ป๐, in a region.
โข Viscosity coefficient, ๐.
Net effect is a smoothing or diffusion of the
velocity over time.
Viscosity
Diffusion is typically modeled using the heat equation:๐๐
๐๐ก= ๐ผ๐ โ ๐๐
Viscosity
Diffusion applied to velocity gives our viscous
force:
Usually, diffuse each component of ๐ =(u, v, w)
separately.
๐ญ๐ฃ๐๐ ๐๐๐ ๐๐ก๐ฆ = ๐๐๐
๐๐ก= ๐๐ โ ๐๐
External Forces
Any other forces you may want.
โข Simplest is gravity:
โ ๐น๐ = ๐๐ for ๐ = (0,โ9.81, 0)
โข Buoyancy models are similar,
โ e.g., ๐น๐ = ๐ฝ(๐๐๐ข๐๐๐๐๐ก โ ๐๐๐๐)๐
Advection of a Scalar
Consider advecting a quantity, ๐
โ temperature, color, smoke density, โฆ
according to a velocity field ๐.
Allocate a grid (2D array) that
stores scalar ๐ and velocity ๐.
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 (e.g. forward Euler).
Problem: New data position doesnโt necessarily land on a grid point.
?
Semi-Lagrangian
โข Look backwards in time from a grid point, to
see where its new 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 new time.
Unconditionally stable!(Though dissipative โ drains energy over time.)
Advection of Velocity
This handles scalars. What about advecting velocity?
Same method:โ Trace back with current velocity
โ Interpolate velocity 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! (Make a copy.)
๐๐
๐๐ก= โ๐ โ ๐ป๐
Recallโฆ Helmholtz 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 of equations for p:โ๐ก
๐๐ป โ ๐ป๐ = ๐ป โ ๐๐๐๐
2) Given p, plug back in to update velocity:
๐๐๐๐ค = ๐๐๐๐ โโ๐ก
๐๐ป๐
Implementation
Discretize with finite differences:
e.g., in 1D:
โ๐ก
๐
๐๐+1 โ ๐๐โ๐ฅ
โ๐๐ โ ๐๐โ1โ๐ฅ
โ๐ฅ=๐ข๐+1๐๐๐โ ๐ข๐
๐๐๐
โ๐ฅ
๐๐+1 ๐๐โ1๐๐
๐ข๐+1 ๐ข๐
โ๐ก
๐๐ป โ ๐ป๐ = ๐ป โ ๐๐๐๐
Solid Boundary Conditions
58
๐
๐
Free Slip:๐๐๐๐คโ ๐ = 0
i.e., Fluid cannot penetrate or
flow out of the wall, but may
slip along it.
Air (โFree surfaceโ) Boundary
Conditions
Assume air (outside the liquid) is at some
constant atmospheric pressure, ๐ = ๐๐๐ก๐.
Free Surface Boundary Conditions
Only the pressure gradient matters, so simplify
and assume ๐ = ๐๐๐ก๐ = 0.
p=0
p=10
p=20
p=100
p=110
p=120
Same (vertical)
pressure
gradient, ๐ป๐.
Viscosity
PDE: ๐๐๐
๐๐ก= ๐๐ป โ ๐ป๐
Again, apply finite differences.
Discretized in time:
๐๐๐๐ = ๐๐๐๐ +โ๐ก๐๐๐ป โ ๐ป๐โ
๐๐๐๐ -> explicit
๐๐๐๐ -> implicit
Viscosity โ Time Integration
Explicit integration:
โ Compute โ๐ก๐๐๐ป โ ๐ป๐๐๐๐ from current velocities.
โ Add on to current ๐.
โ Quite unstable (stability restriction: โ๐ก โ ๐(โ๐ฅ2))
Implicit integration:
โ Stable even for high viscosities, large steps.
โ Must solve a system of equations.
๐๐๐๐ = ๐๐๐๐ +โ๐ก๐๐ ๐ป โ ๐ป๐๐๐๐
๐๐๐๐ = ๐๐๐๐ +โ๐ก๐๐ ๐ป โ ๐ป๐๐๐๐ค
Viscosity โ Implicit Integration
Solve for ๐๐๐๐:
๐๐๐๐ โโ๐ก๐๐๐ป โ ๐ป๐๐๐๐ค = ๐๐๐๐
(Apply separately for each velocity component.)
e.g. in 1D:
๐ข๐ โโ๐ก๐
๐
๐ข๐+1 โ ๐ข๐โ๐ฅ
โ๐ข๐ โ ๐ข๐โ1โ๐ฅ
โ๐ฅ= ๐ข๐๐๐๐
๐ข๐+1 ๐ข๐โ1๐ข๐
Viscosity - Free Surface Conditions
We want to model no momentum exchange with the โairโ.
Simplest attempt: ๐ป๐ข โ ๐ = 0
Drawback: Breaks rotation!
True conditions are more involved:
(Still ignores surface tension!)
See [Batty & Bridson, 2008] for the current standard solution in graphics. (Needed e.g., for honey coiling.)
โ๐๐ + ๐ ๐๐ + ๐๐๐ป โ ๐ = ๐
Gravity
Discretized form is:
๐๐๐๐ = ๐๐๐๐ + โ๐ก๐
Simply increment the vertical velocities at
each step!
Gravity
Notice: 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
Track an extra scalar field T, representing local
temperature.
Apply advection and diffusion to evolve it with the
velocity field.
Difference between current and โreferenceโ
temperature induces buoyancy.
Simple Buoyancy
e.g.
๐๐๐๐ = ๐๐๐๐ + โ๐ก๐ฝ ๐๐๐ข๐๐๐๐๐ก โ ๐๐๐๐ ๐
๐ฝ dictates the strength of the buoyancy
force.
For an enhanced version of this:
โVisual simulation of smokeโ, [Stam et al., 2001].
User Forces
Add whatever additional
forces we want:
โข Wind forces near a
mouse click.
โข Paddle forces in
Plasma Pong.
Plasma Pong
Ordering of Steps
Order is important.
Why?
1) Incompressibility is not satisfied at
intermediate steps.
2) Advecting with a compressive field causes
volume/material loss or gain!
The Big Picture
Velocity Solver
Advect Velocities
Add Viscosity
Add Gravity
Project Velocities
to be
Incompressible
Interaction between
Solver and Surface Tracker
Advect Velocities
Add Viscosity
Add Gravity
Project Velocities
to be
Incompressible
Surface Tracker
Velocity Solver
Velocity
Information
Geometric
Information
Solver-to-Surface Tracker
Given: current surface geometry, velocity field,
and timestep.
Compute: new surface geometry by advection.
๐๐
๐๐+1
๐๐
Surface Tracker-to-Solver
Given the surface geometry, identify the type of each cell.
Solver uses this information for boundary conditions.
S
S
S
S
S
S S S S
S
S
S
L L
L L
L
A A A
Surface Tracker
Ideally:
โข Efficient
โข Accurate
โข Handles merging/splitting (topology changes)
โข Conserves volume
โข Retains small features
โข Gives a smooth surface for rendering
โข Provides convenient geometric operations (post-processing?)
โข 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
Perform passive Lagrangian advection on each
particle.
For rendering, need to reconstruct a surface.
Level setsEach grid point stores signed distance to the
surface (inside <= 0, outside > 0).
Surface is the interpolated zero isocontour.
> 0
<= 0
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