PPTX

advertisement
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.
Relating Eulerian and Lagrangian
Consider the temperature ๐‘‡(๐‘ฅ, ๐‘ก) at a point
following a given path, ๐‘ฅ(๐‘ก).
๐‘ฅ(๐‘ก1 )
๐‘ฅ(๐‘ก๐‘›๐‘œ๐‘ค )
๐‘ฅ(๐‘ก0 )
Two ways temperature changes:
1. Heating/cooling occurs at the current point.
2. Following the path, the point moves to a
cooler/warmer location.
Time derivatives
Mathematically:
๐ท
๐œ•๐‘‡ ๐œ•๐‘‡ ๐œ•๐‘ฅ
๐‘‡ ๐‘ฅ ๐‘ก ,๐‘ก =
+
๐ท๐‘ก
๐œ•๐‘ก ๐œ•๐‘ฅ ๐œ•๐‘ก
Chain rule!
๐œ•๐‘‡
๐œ•๐‘ฅ
=
+ ๐›ป๐‘‡ โˆ™
๐œ•๐‘ก
๐œ•๐‘ก
Definition
of ๐›ป
๐œ•๐‘‡
=
+ ๐’– โˆ™ ๐›ป๐‘‡
๐œ•๐‘ก
Choose
=๐‘ข
๐œ•๐‘ฅ
๐œ•๐‘ก
Material Derivative
This is called the material derivative, and denoted
๐ท
.
๐ท๐‘ก
Change at a point moving
with the velocity field.
Change due
to movement.
๐ท๐‘‡ ๐œ•๐‘‡
=
+ ๐’–๐›ป๐‘‡
๐ท๐‘ก
๐œ•๐‘ก
Change at the current
(fixed) point.
Advection
To track a quantity T simply moving (passively)
through a velocity field:
๐ท๐‘‡
=0
๐ท๐‘ก
or equivalently
๐œ•๐‘‡
+ ๐’–๐›ป๐‘‡ = 0
๐œ•๐‘ก
This is the advection equation.
Think of colored dye or massless particles drifting
around in fluid.
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…
๐œ•๐’–
๐œŒ
= −๐œŒ ๐’– โˆ™ ๐›ป๐’– +
๐œ•๐‘ก
Change in
velocity at a
fixed point
Advection
๐‘ญ๐‘–
๐‘–
Forces
(pressure,
viscosity
gravity,…)
Operator splitting
Break the equation into steps:
1.
2.
3.
4.
๐œ•๐’–
Advection: ๐œŒ = −๐œŒ ๐’– โˆ™ ๐›ป๐’–
๐œ•๐‘ก
๐œ•๐’–
Pressure: ๐œŒ = ๐‘ญ๐‘๐‘Ÿ๐‘’๐‘ ๐‘ ๐‘ข๐‘Ÿ๐‘’
๐œ•๐‘ก
๐œ•๐’–
Viscosity: ๐œŒ = ๐‘ญ๐‘ฃ๐‘–๐‘ ๐‘๐‘œ๐‘ ๐‘–๐‘ก๐‘ฆ
๐œ•๐‘ก
๐œ•๐’–
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
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 ๐‘›
+๐‘ข
=0
โˆ†๐‘ก
2โˆ†๐‘ฅ
Unconditionally
Unstable!
Lax:
Conditionally
๐œ‘๐‘– ๐‘›+1 − (๐œ‘๐‘–+1 ๐‘› + ๐œ‘๐‘–−1 ๐‘› )/2
๐œ‘๐‘–+1 ๐‘› − ๐œ‘๐‘–−1 ๐‘›
+๐‘ข
=0
Stable!
โˆ†๐‘ก
2โˆ†๐‘ฅ
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)
๐œ•๐’–
๐œŒ
๐œ•๐‘ก
= −๐›ป๐‘
Discretize (1) in time…
and (2) ๐›ป โˆ™ ๐’– = 0
โˆ†๐‘ก
๐’–๐‘›๐‘’๐‘ค = ๐’–๐‘œ๐‘™๐‘‘ − ๐›ป๐‘
๐œŒ
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:
๐‘ข๐‘–+1
๐‘๐‘–+1
๐‘ข๐‘–
๐‘๐‘–
๐‘๐‘–−1
e.g., in 1D:
๐‘๐‘–+1 − ๐‘๐‘– ๐‘๐‘– − ๐‘๐‘–−1
๐‘œ๐‘™๐‘‘
−
โˆ†๐‘ก
๐‘ข๐‘–+1 − ๐‘ข๐‘–
โˆ†๐‘ฅ
โˆ†๐‘ฅ
=
๐œŒ
โˆ†๐‘ฅ
โˆ†๐‘ฅ
๐‘œ๐‘™๐‘‘
Solid Boundary Conditions
Free Slip:
๐’–๐‘›๐‘’๐‘ค โˆ™ ๐’ = 0
๐’
๐’–
52
Staggered vs. Non-staggered
• Two choices for grids:
– Velocity and pressure co-located
๐‘๐‘–+1
๐‘๐‘–−1
๐‘๐‘–
๐‘ข๐‘–
๐‘ข๐‘–+1
๐‘ข๐‘–−1
– Velocity and pressure staggered
๐‘๐‘–+1
๐‘ข๐‘–+1
๐‘๐‘–
๐‘ข๐‘–
๐‘๐‘–−1
Why prefer staggered?
• Finite differences line up nicely.
– ๐‘ข and ๐›ป๐‘ match, ๐‘ and ๐›ป โˆ™ ๐‘ข match
๐‘ข๐‘–+1
๐‘๐‘–+1
๐‘ข๐‘–
๐‘๐‘–
• …which improves stability!
๐‘๐‘–−1
3. Viscosity
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
No-Slip:
๐’–๐‘›๐‘’๐‘ค = 0
Watch no-slip clip
59
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?
Velocity Solver
Advect Velocities
Add Viscosity
Add Gravity
Project Velocities
to be
Incompressible
Surface Tracker
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.
2.
3.
4.
5.
Particles
Level sets
Volume-of-fluid (VOF)
Triangle meshes
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.
1
1
1
1
1
0.
8
0
0
0
1
0.4
0
0
1
1
0.4
0
0
1
1
0.8
0
0
0
1
1
0.5
0
0
0
Meshes
[Brochu et al 2010]
Meshes
Store a triangle mesh.
Advect its vertices, and correct for collisions.
Download