You are on page 1of 15

Acknowledgement

Computational Fluid Dynamics


An Introduction

This slide set is based on:


n

Simulation in Computer Graphics


University of Freiburg

John D. Anderson, Jr., Computational Fluid Dynamics


The Basics with Applications, McGraw-Hill, Inc.,
New York, ISBN 0-07-001685-2

WS 04/05

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Motivation

Outline
n
n
n

introduction
pre-requisites
governing equations
n
n
n

D. Enright, S. Marschner, R. Fedkiw,


Animation and Rendering of
Complex Water Surfaces,
Siggraph 2002, ACM TOG,
vol. 21, pp. 736-744, 2002.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

solution techniques
n
n
n

continuity equation
momentum equation
summary
Lax-Wendroff
MacCormack
numerical aspects

recent research in graphics


University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Introduction
n

physical aspects of fluid flow are governed by


three principles
n
n
n

mass is conserved
force = mass acceleration (Newtons second law)
energy is conserved (not considered in this lecture)

principles can be described with integral equations or


partial differential equations
in CFD, these governing equations are replaced by
discretized algebraic forms
algebraic forms provide quantities at discrete points
in time and space, no closed-form analytical solution
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Continuous Quantities
n
n

Governing
Equations

Discretization

Navier-Stokes
Euler

Finite
Difference

System of
Algebraic
Equations

Discrete
Nodal
Values

Equation
Solver

Approx.
Solution

Lax-Wendroff
MacCormack

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Problem

x, y, z 3D coordinate system
t time

( x,y,z,t ) density
v ( x,y,z,t ) velocity

v ( x,y,z,t ) = (u ( x,y,z,t ), v ( x,y,z,t ), w ( x,y,z,t ) )T

Numerical Solution - Overview

v (x,y,z,t )
(x,y,z,t )
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

v (x,y,z,t+t )
(x,y,z,t+t )

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Substantial Derivative of

Outline
n
n
n

introduction
pre-requisites
governing equations
n
n
n

continuity equation
momentum equation
summary

solution techniques
n
n
n

Lax-Wendroff
MacCormack
numerical aspects

recent research in graphics

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Substantial Derivative of
n

Taylor series at point 1




2 = 1 +
( x 2 x1 ) +
x 1
y



v +
w +

z 1
t 1
1

n
n
n

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

1 ( x1,y1,z1,t1 )
2 ( x2,y2,z2,t2 )

substantial derivative of
D


u
+v
+w
+
x
y
z
Dt
t
substantial derivative = local derivative + convective derivative

+ (v )
t
Dt

t2 t1
2 1

=
u +
t2 t1
x 1
y

v1(x1,y1,z1,t1) = (u (x1,y1,z1,t1 ),v (x1,y1,z1,t1 ),w (x1,y1,z1,t1 ))T


v2(x2,y2,z2,t2) = (u (x2,y2,z2,t2 ),v (x2,y2,z2,t2 ),w (x2,y2,z2,t2 ))T

Substantial Derivative



( y 2 y 1 ) +
(z 2 z 1 ) +
(t2 t1 )
z 1
t 1
1

y 2 y1 z 2 z 1

+
+

z 1 t 2 t1 t 1
1 t 2 t1

( x1,y1,z1 ) position at time t1


( x2,y2,z2 ) position at time t2

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

2 1 x 2 x1
=
+

t2 t1
x 1 t 2 t1 y

infinitesimally small fluid element moving with the flow


=
,
,
x y z

local derivative time rate of change at a fixed location


convective derivative time rate of change due to fluid flow
subst. derivative = total derivative with respect to time
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Divergence of v
n

Outline

divergence of velocity v = time rate of change of the


volume V of a moving fluid element per unit volume
v =

u v w
1 D ( V
+
+
=
x y
z
V
Dt

n
n
n

introduction
pre-requisites
governing equations
n
n
n

solution techniques
n
n
n

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Continuity Equation
n
n
n

time rate of change of the mass of the moving fluid


element is zero
D m
D ( V )
D
D V
=
= V
+
=0
Dt
Dt
Dt
Dt

Lax-Wendroff
MacCormack
numerical aspects

recent research in graphics


University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Continuity Equation

mass is conserved
infinitesimally small fluid element moving with the flow
fixed mass m, variable volume V, variable density
m = V

D
1 D V
+
=0
Dt
V Dt

continuity equation
momentum equation
summary

D
+ v = 0
Dt
substantial derivative
time rate of change of
density of a moving
fluid element

divergence of velocity time rate of change of volume


of a moving fluid element per
volume

D
+ v = 0
Dt

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Continuity Equation
n

non-conservation form (considers moving element)

Continuity Equation
n

D
+ v = 0
Dt
manipulation
D

+ v =
+ v + v =
+ ( v )
Dt
t
t
conservation form (considers element at fixed location)

motivation for conservation form


n
n
n
n

+ ( v ) = 0
t

+ ( v ) = 0
t

time rate of mass


increase per volume

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Outline
n
n
n

introduction
pre-requisites
governing equations
n
n
n

solution techniques
n
n
n

continuity equation
momentum equation
summary
Lax-Wendroff
MacCormack
numerical aspects

recent research in graphics

infinitesimally small element at a fixed location


mass flux through element
difference of mass inflow and outflow = net mass flow
net mass flow = time rate of mass increase

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Momentum Equation
n
n
n

consider a moving fluid element


physical principle: F = ma (Newtons second law)
two sources of forces
n

body forces
n gravity
surface forces
n based on pressure distribution on the surface
n based on shear and normal stress distribution on the surface
due to deformation of the fluid element
friction
fluid
element
gravity

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

net mass flow


per volume

pressure

normal
stress

shear
stress

velocity

velocity

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Pressure Force

Body Force
n
n

f = body force per unit mass


gravity: f = mg / m = g
body force on fluid element
f (dx dy dz )

n
n

consider the x component


pressure force
acts orthogonal
p dy dz
to surface into
the fluid element

dx

net pressure force in x direction

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Stress

n
n

dy

dx dy dz
p p + dx dy dz =
x
x

dz

( p + p/ x dx ) dy dz
dx

dy

fluid
element

dz

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Stress

normal stress related to the time rate of change of volume


shear stress related to the time rate of change
of the shearing deformation
jk stress in k direction applied to a surface perpendicular
to the j axis
xx normal stress in x direction
zx , yx shear stresses in x directions
yx

n
n
n

normal stress is related to pressure orthogonal to surface


shear stress is related to friction parallel to surface
friction and pressure are related to the velocity gradient
n
n

friction (shear stress) models viscosity (viscous flow)


in contrast to inviscid flow, where friction is not considered
friction
pressure

normal
stress

shear
stress

velocity

velocity
xx
x
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Surface Forces in x

Momentum Equation in x
(yx + yx / y dy) dx dz

m a x = Fx

dz

p dy dz

( p + p/ x dx ) dy dz

xx dy dz

(xx + xx / x dx) dy dz
dy

dx
yx dx dz

Fx = p p + dx dy dz + xx + xx dx xx dy dz
x
x

zx not illustrated

dx dy dz
mass

+ yx + yx dy yx dx dz + zx + zx dz zx dy dz
z
y

p xx yx zx
+
dx dy dz
Fx =
+
+
y
z
x
x

n
n

viscous flow, non-conversation form


Navier-Stokes equations
yx zx
Du
p

= + xx +
+
+ fx
Dt
x x
y
z

Dv
p xy yy zy
= +
+
+
+ fy
Dt
y x
y
z

yz zz
Dw
p

= + xz +
+
+ fz
Dt
z
x
y
z

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

acceleration
time rate of change
of velocity of a
moving fluid element

surface force
pressure
normal stress
shear stress

body force
gravity

yx zx
p
Du
= + xx +
+
+ fx
x
x
y
z
Dt

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Momentum Equation

Du p xx yx zx
dx dy dz + f x dx dy dz
+
= +
+
Dt x x
y
z

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Momentum Equation in x
n

obtaining the conservation form of Navier-Stokes

Du
u
=
+ v u
Dt
t

( u)
u

=
+u
t
t
t

u
( u)
=u

t
t
t

( u v ) = u ( v) + ( v ) u

( v ) u = ( u v) u ( v)

Du ( u)

=
u + ( v) + ( u v )
Dt
t
t

continuity equation

Du ( u )
=
+ ( u v )
Dt
t

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Momentum Equation
n

Navier-Stokes equations in conservation form


yx zx
( u )
p
+
+ fx
+ ( u v ) = + xx +
y
z
t
x x
( v )
p xy yy zy
+ fy
+
+
+ ( v v) = +
z
y
t
y x

Newtonian Fluids
n

xx = ( v ) + 2

n
n

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

n
n
n
n

intermolecular forces are negligible


R specific gas constant
T temperature
termal equation of state p = R T

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

u
x

v u
xy = yx = +
x y

yz zz
( w )
p
+
+ fz
+ ( w v ) = + xz +
y
z
t
z
x

Perfect Gas

Newton: shear stress in a fluid is proportional


to velocity gradients
most fluids can be assumed to be newtonian,
but blood is a popular non-newtonian fluid
Stokes:
yy = ( v ) + 2

v
y

u w
xz = zx = +

z x

zz = ( v ) + 2

w
z

w v
yz = zy = +
y z

is the molecular viscosity coefficient


is the second viscosity coefficient with = -2/3
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Momentum Equation in x
yx zx
( u )
p
+ ( u v ) = + xx +
+
+ fx
t
x x
y
z
n

now,
p can be expressed using density and
can be expressed using velocity gradients,
fx is user-defined (e. g. gravity)

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Governing Equations
Viscous Compressible Flow

n
n
n

introduction
pre-requisites
governing equations
n
n
n

n
n

continuity equation
momentum equation
summary

( v )
p xy yy zy
+ ( v v) =
+
+
+
+ fy
t
y
x
y
z

Lax-Wendroff
MacCormack
numerical aspects

yz zz
( w )
p
+
+ fz
+ ( w v ) = + xz +
y
z
t
z
x

recent research in graphics

Governing Equations
Inviscid Compressible Flow
Euler equations

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Comments
on the Governing Equations
n

continuity equation

( u )
p
+ ( u v ) = + f x
t
x

( v )
p
+ ( v v ) = + f y
t
y
( w )
p
+ ( w v ) = + f z
t
z

n
n

momentum equation

+ ( v ) = 0
t

continuity equation

yx zx
( u )
p
+
+ fx
+ ( u v ) = + xx +
y
z
t
x x

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

thus, four equations and four unknowns , u, v, w

+ ( v ) = 0
t

solution techniques
n

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

momentum equation

Outline

coupled system of nonlinear partial differential equations


normal and shear stress terms are functions of the
velocity gradients
pressure is a function of the density
only momentum equations are Navier-Stokes equations,
however the name is commonly used for the full set
of governing equations (plus energy equation)

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Governing Equations in
Conservation Form
n

can be obtained directly from a control volume fixed in


space
consider flux of mass, momentum (and energy) into and
out of the volume
have a divergence term which involves the flux of
mass (v), momentum in x, y, z (u v, v v, w v)
can be expressed in a generic form

Generic Form
viscous flow

?v
u
?w

u u + p xx
? u w t zx
u
? u v t yx

? fx
U=
F=
G =
H =
J
=

? f
v u xy
? v w + p t zy
v
? v v + p t yy

y
w
w u

? ww + p t
? f
? wv t

yz
xz
zz

inviscid flow


u
?v

u
uu + p
?u v
U=
F
=
G
=
vu
?v v + p
v

w
wu

?w v

U F G H
+
+
+
=J
t x y z

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Generic Form
n
n
n

n
n

U solution vector (to be solved for)


F, G, H flux vectors
J source vector (external forces, energy changes)
U
F G H
=J
+
+
t
x y z
dependent flow field variables can be solved progressively
in steps of time (time-marching )
spatial derivatives are know from previous time steps
numbers can be obtained for density and flux variables
u, v, w

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Motivation for Different Forms


of the Governing Equations
in many real-world problems, discontinuous changes in
the flow-field variables , v occur (shocks, shock waves)
problem: differential form of the governing equations
assumes differentiable (continuous) flow properties
simple 1-D shock wave: 1 u1 = 2 u2

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

?w
0

?u w
? fx
H =
J
=
? f
?v w + p

y
?w w + p
? f

conservation form solves for u, sees no discontinuity


positive effect on numerical accuracy and stability
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

10

Outline
n
n
n

introduction
pre-requisites
governing equations
n
n
n

continuity equation
momentum equation
summary

solution techniques
n
n
n

Lax-Wendroff Technique

Lax-Wendroff
MacCormack
numerical aspects

n
n

recent research in graphics


University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Lax-Wendroff
Example
n

flow-field variables , u, v, w are known at each discrete


spatial position ( x, y, z ) at time t
Lax-Wendroff computes all information at time t +t
second-order accuracy in space and time
explicit, finite-difference method
particularly suited to marching solutions
marching suited to hyperbolic, parabolic PDEs
unsteady (time-dependent), compressible flow
is governed by hyperbolic PDEs
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Taylor Series Expansions

2D, inviscid flow, no body force, in non-conservation form

n
n

ti,j density at position (i, j ) and time t


ti,j , u ti,j , v ti,j are known

v

=
+u
+
+v

y
y

2

it,+j t = it, j +
t +
2
t i , j
t

u
u
u R T
= u
+v
+
t
y
x
x

2u
u
u it ,+j t = u it, j +
t + 2
t i , j
t

v
v
v R T

= u
+v
+
t

x
y
y

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

( t )2

+ ...
i, j 2
t

( t )

+ ...
i , j 2
t

2 v ( t )2
v
v it,+j t = v it, j +
+ ...
t + 2
t i , j
t i, j 2
t

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

11

Taylor Expansion - Density


2

it,+j t = it, j +
t + 2
t i, j
t
t

( t )

+ ...
i, j 2
t

/t can be replaced by spatial derivatives


given in the governing equations

=
+u
+
+v
t
x
y
y
x

Taylor Expansion - Density

2u
2
u
2 u
2v
v
2 v
=
+
+u
+
+
+
+v

+
t 2
x t x t
y t y t
y t y t
x t x t

using second-order central differences

t
t
vt
t
t u it+ 1, j u it 1, j
it 1, j
vit 1, j
it 1, j

+ u it, j i + 1, j
+ it, j i + 1, j
+ v it, j i + 1, j

= i , j
2 x
2 x
2 y
2 y
t i , j

2/t 2 can be obtained by differentiating the governing


equation with respect to time

mixed second derivatives can be obtained by differentiating


the governing equations with respect to a spatial variable,
e. g.
2
2
2
2
2
2

u u
u
R T
u
u v R T
= u
+
+v
+
2
+
x 2 x
x t
x
y
y
x

x
x 2

brackets missing on pp. 219, 220 in Andersons book!

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Taylor Expansion - Density


n

2/t 2 can be computed using central differences for


spatial derivatives
higher-order terms are required, e. g.
t

u
u
2 =

i, j
2

t
i +1, j

2u + u
t
i, j
2

(x )

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Outline
n
n
n

t
i 1, j

ut
+ ut
ut
ut
2u

= i+1, j +1 i 1, j1 i 1, j +1 i +1, j 1
4xy
xy i, j

introduction
pre-requisites
governing equations
n
n

solution techniques
n
n
n

... u, v are computed in the same way


University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

continuity equation
momentum equation
summary
Lax-Wendroff
MacCormack
numerical aspects

recent research in graphics


University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

12

MacCormack Technique

MacCormack Technique
n
n
n
n
n

same characteristics like Lax-Wendroff


second-order accuracy in space and time
requires only first time derivative
predictor corrector
illustrated for density

predictor step for density

t
t
vt
t
t u it +1 , j u it1 , j
it1, j
v it 1, j
it 1, j

+ u it, j i + 1, j
+ it, j i + 1, j
+ v it, j i + 1, j

= i , j
2
x
2
x
2
y
2

y
t i, j


it,+j t = it, j +
t
t i , j
t

av


it,+j t = it, j +
t
t i, j

u, v are predicted the same way


u
u it, +j t = u ti , j +
t
t i , j
t

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Comments

corrector step for density


t + t

i , j

u
= it,+j t

t + t
i +1 , j

2 x

t + t
i 1 , j

+ u it,+j t

t + t
i +1 , j

2x

t+ t
i 1 , j

+ it,+j t

av
t

1

t
it,+j t = it, j +
t = i, j +
+

t
t

i, j
i , j t

t+ t
i +1 , j

2 y

t + t
i 1 , j

+ v it,+j t

t + t
i +1 , j

2 y

t + t
i 1, j

t + t

i , j

corresponds to Heun scheme for ODEs


other higher-order schemes, e. g. Runge-Kutta 2 or 4,
could be used as well

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Lax-Wendroff and MacCormack can be used for


unsteady flow
n

n
n

n
n

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

MacCormack Technique
n

v
v it,+j t = vit, j +
t
t i, j

non-conservation form
conservation form
viscous flow
inviscid flow

higher-order accuracy required to avoid numerical


dissipation, artificial viscosity, numerical dispersion
note, that viscosity is represented by second partial
derivatives in the governing equations

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

13

Outline
n
n
n

introduction
pre-requisites
governing equations
n
n
n

solution techniques
n
n
n

continuity equation
momentum equation
summary
Lax-Wendroff
MacCormack
numerical aspects

Numerical Effects
n
n

n
n

truncation error causes dissipation and dispersion


numerical dissipation is caused by even-order terms
of the truncation error
numerical dispersion is caused by odd-order terms
leading term in the truncation error dominates the
behavior

recent research in graphics

original function

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Numerical Effects
n

artificial viscosity compromises the accuracy, but


improves the stability of the solution
adding artificial viscosity increases the probability of
making the solution less accurate, but improves
the stability
similar to iterative solution schemes for implicit integration
schemes, where a smaller number of iterations introduces
artificial viscosity, but improves the stability

x
dissipation

x
dispersion

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Summary
n

governing equations for compressible flow


n
n
n

continuity equation, momentum equation


Navier-Stokes (viscous flow) and Euler (inviscid flow)
discussion of conservation and non-conservation form

explicit time-marching techniques


n
n
n

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Lax-Wendroff
MacCormack
numerical aspects

recent research in graphics

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

14

Recent Research

Recent Research

M. Carlson, P. J. Mucha, G. Turk, Rigid Fluid: Animating the


Interplay Between Rigid Bodies and Fluid, Siggraph 2004.

T. G. Goktekin, A. W. Bargteil, J. F. OBrien,


A Method for Animating Viscoelastic Fluids, Siggraph 2004.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

15

You might also like