cs 231 fluid simulation - computer science and …vbz/cs231f15/lecture11-15.pdf · fluid simulation...
TRANSCRIPT
CS 231
Fluid simulation
Why Simulate Fluids?
Feature film special effects
Computer games
Medicine (e.g. blood flow in heart)
Because it’s fun
Fluid Simulation
Called Computational Fluid Dynamics (CFD)
Many approaches from math and
engineering
Graphics favors finite difference
Introduced fast and stable methods to
graphics [Stam 1999]
Vector Fields (Fluid Velocity)
uij = (ux,uy)
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion
Body Forces
Pressure
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion Pressure
Body Forces
Fluid Grids
All values live on regular grids
Need scalar and vector fields
Scalar fields: amount of smoke or dye
Vector fields: fluid velocity
Subtract adjacent quantities to approximate
derivatives
Scalar Field (Smoke, Dye)
cij
1.2 3.7 5.1 …
Diffusion
cij
Diffusion
1
1
1
1
-4
cijnew = cij + k Dt (ci-1j + ci+1j + cij-1 + cij+1 - 4cij)
ct = k2c
value relative
to neighbors
Diffusion = Blurring
Original Some Diffusion More Diffusion
Vector Field Diffusion
ut = k2u
… blur the x-velocity and the y-velocity
uxt = k2ux
uyt = k2uy
Two separate diffusions:
viscosity
Effect of Viscosity
• Each one is ten times higher
viscosity than the last
Low Medium High Very High
Variable Viscosity
Viscosity can vary based on position
Viscosity field k can change with temperature
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion Pressure
Body Forces
Advection = Pushing Stuff
Scalar Field Advection
ct = –(u)c
change in value advection current values
Vector Field Advection
ut = –(u)u
uxt = –(u)ux
uyt = –(u)uy
Two separate advections:
… push around x-velocity and y-velocity
Advection
Easy to code
Method stable even at large time steps
Problem: numerical inaccuracy diffuses flow
Diffusion/dissipation
in first order advection
Original Image After 360 degree rotationusing first order advection
Solution: Error Correction
1) Perform forward advection
2) Do backward advection from new position
3) Compute error and take correction step
4) Do forward advection from corrected
position
error
Compensate
Forward
BackwardForward
Solution: Error Correction
Navier-Stokes Equations
u=0
ut = k2u –(u)u – p + f
Incompressibility
Change in Velocity
Advection
Diffusion Pressure
Body Forces
Divergence
High divergence Low divergence
Zero divergence
Enforcing Incompressibility
First do velocity diffusion and advection
Find “closest” vector field that is divergence-
free
Need to calculate divergence
Need to find and use pressure
Measuring Divergence
u=?
uij=(uxi+1j - ux
i-1j) + (uyij+1-u
yij-1)
?
-uyij-1
uyij+1
-uxi-1j uxi+1j
Pressure Term
unew = u – p
Take divergence of both sides…
unew = u – p
u = 2p
zero
Pressure Term
u = 2p
pnewij = pij + ( uij - (pi-1j + pi+1j + pij-1 + pij+1 - 4pij))
known unknown
?
pij-1
pij+1
pi-1j pi+1j
Pressure Term
unew = u – p
…and velocity is now divergence-free
Fluid Simulator
1) Diffuse velocity
2) Advect velocity
3) Add body forces (e.g. gravity)
4) Pressure projection
5) Diffuse dye/smoke
6) Advect dye/smoke
Where is the Water?
Water is often modeled as a fluid with a
free surface
The only thing we’re missing so far is how to
track where the water is:
Voxelized: which cells are fluid vs. empty?
Better: where does air/water interface cut
through grid lines?
Marker Particles
Simplest approach is to use marker particles
Sample fluid volume with particles
At each time step, mark grid cells containing any
marker particles as Fluid, rest as Empty or Solid
Move particles in incompressible grid velocity field
(interpolating as needed)
Rendering Marker Particles
Need to wrap a surface around the particles
E.g. blobbies, or Zhu & Bridson ‘05
Problem: rendered surface has bumpy detail
that the fluid solver doesn’t have access to
The simulation can’t animate that detail properly
if it can’t “see” it.
Result: looks fine for splashy, noisy surfaces,
but fails on smooth, glassy surfaces.
Improvement
Sample (implicit) surface function on simulation grid
Even just union of spheres is reasonable if we smooth
and render from the grid
Issues, must make sure that each particle always shows up
on grid or droplets can flicker in and out of existence…
Or: you must delete stray particles
But still not perfect for flat fluid surfaces.
Level Sets
Idea: drop the particles all together, and just sample the
implicit surface function on the grid
In particular, best behaved type of implicit surface function is
signed distance
Computing Signed Distance
Many algorithms exist
Simplest and most robust (and accurate enough for
animation) are geometric in nature
Our example algorithm is based on a Fast Sweeping method
[Tsai’02]
Level Sets
Surface is exactly where =0
We need to evolve on the grid
The surface (=0) moves at the velocity of the fluid (any fluid
particle with =0 should continue with =0)
See e.g. the book [Osher&Fedkiw’02]
Reinitializing
One problem is that advecting this way
doesn’t preserve signed distance property
Eventually gets badly distorted
Causes problems particularly for extrapolation,
also for accuracy in general
Reinitialize: recompute distance to surface
Ideally shouldn’t change surface at all, just
values in the volume
Small-scale liquid-solid
Interactions
Lake ( >1 meter) Water drops (millimeters)
What makes large water and small water behave
differently?
Surface Tension
Viscosity
Surface Tension
Normal (always pointing outward)
Surface Tension Force
surfF N
0 0
Virtual Surface Method
Solid
Virtual
Surface
Virtual Liquid
Liquid
Air
60s 90s 120s
hydrophillic hydrophobic
Virtual Surface Method