An Overview of Fluid Animation - University of...

Post on 09-Aug-2018

213 views 0 download

Transcript of An Overview of Fluid Animation - University of...

An Overview of Fluid Animation

Christopher Batty

March 11, 2014

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 (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.)

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 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

Advection

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...

Exotic Fluids - Oobleck

Exotic Fluids - Ferrofluid

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: ๐œŒ๐œ•๐’–

๐œ•๐‘ก= ๐‘ญ๐‘œ๐‘กโ„Ž๐‘’๐‘Ÿ

1. Advection

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.

2. Pressure

Pressure

What does pressure do?

โ€“ Enforces incompressibility (fights compression).

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.

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.

3. Viscosity

High Speed Honey

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.

๐‘ญ๐‘ฃ๐‘–๐‘ ๐‘๐‘œ๐‘ ๐‘–๐‘ก๐‘ฆ = ๐œŒ๐œ•๐’–

๐œ•๐‘ก= ๐œ‡๐› โˆ™ ๐›๐’–

4. External Forces

External Forces

Any other forces you may want.

โ€ข Simplest is gravity:

โ€“ ๐น๐‘” = ๐œŒ๐’ˆ for ๐’ˆ = (0,โˆ’9.81, 0)

โ€ข Buoyancy models are similar,

โ€“ e.g., ๐น๐‘ = ๐›ฝ(๐‘‡๐‘๐‘ข๐‘Ÿ๐‘Ÿ๐‘’๐‘›๐‘ก โˆ’ ๐‘‡๐‘Ÿ๐‘’๐‘“)๐’ˆ

Numerical Methods for Fluid

Animation

1. Advection

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.)

๐œ•๐’–

๐œ•๐‘ก= โˆ’๐’– โˆ™ ๐›ป๐’–

2. Pressure

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, ๐›ป๐‘.

3. Viscosity

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 - Solid Boundary Conditions

65

No-Slip:๐’–๐‘›๐‘’๐‘ค= 0

No-slip Condition

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.)

โˆ’๐‘๐ˆ + ๐› ๐›๐’– + ๐›๐’–๐‘ป โˆ™ ๐’ = ๐ŸŽ

4. External Forces

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!

Ordering of Steps

For example, consider advection in this field:

The Big Picture

Velocity Solver

Advect Velocities

Add Viscosity

Add Gravity

Project Velocities

to be

Incompressible

Liquids

Liquids

Whatโ€™s missing?

We still need a surface representation.

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

[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 setsEach grid point stores signed distance to the

surface (inside <= 0, outside > 0).

Surface is the interpolated zero isocontour.

> 0

<= 0

Densities / 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 deal with collisions.