1
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Partial Differential Equationsfor Computer Animation
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Acknowledgement
• A major part of this slide set and all accompanyingdemos are courtesy of Matthias Müller, ETH Zurich, NovodeX AG.
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Motivation
• Most dynamic effects and physical processes can bedescribed by partial differential equations PDEs
• We give a short overview of a large research field in mathematics and physicsapplied to the fields of animation and computer graphics
• Goals• You know what a PDE is• You know PDEs for specific effects• You know how to solve these PDEs numerically• You can use your knowledge to implement
your own effects and animationsUniversity of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Introductory Example
• Simulate temperature evolution• One space dimension + time
T
x
cT(x,0)
• Given the temperature distribution T(x,0) at time t=0and wind speed c.
• Find PDE for the temperature evolution T(x,t) at time t !
2
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Advection
• How does the temperature change in one time step?
• PDE for T(x,t) is 1-d advection (transport) equation.
x
TT(x,t)
T(x,t+∆t)c∆t
∆T
x
xT
tcT
∂∂≈
∆∆−
xTc
tT
∂∂−=
∂∂
xt cTT −=or0→∆t
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Analytical Solution
• Any T(x,t) of the form
)(),( ctxftxT −=
solves
• Any T(x,t) of the form
)()0,( 0 xTxT =
• The physical solution also needs to satisfy the initial condition
• Thus, the solution is)(),( 0 ctxTtxT −=
xt cTT −=
• T is obtained by shifting T0 through a distance ct withoutany change of shape of T0 .
• Only simple PDEs can be solved analytically.
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Numerical Solution – Finite Differences
..)2,1,0(),,..,1(),,(][ ∈∈∆⋅⋅= tnitthiTiT t• Sample T(x,t):
• Discretize the derivatives (e.g. first-order backward scheme)
xt cTT −=h
iTiTct
iTiT tttt ]1[][][][1 −−−=∆
−+
hiTiTctiTiT
tttt ]1[][][][1 −−⋅∆−=+
• Solving for Tt+1[i] yields the explicit update rule
• Before starting the simulation, initialize T0[i]• Possible boundary conditions are periodic boundaries
]1[]1[],[]0[ tttt TnTnTT =+=
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Outline
Mathematical BackgroundWhat is a PDE?Types of PDEsBoundary Conditions
Solution TechniquesAnalytical MethodsNumerical Methods
ExamplesAdvectionDiffusionThe Wave Equation
3
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Mathematical Definition of a PDE
• A Partial Differential Equation (PDE) is an equation thatdetermines the behavior of u in terms of
• partial derivatives of u, e.g. uxy, utt, • u itself and• the independent variables, e.g. x,y,z,t
xuuu xytt +=• Example:
,..),,(,..),(2
2
2
yxuyx
utut
u xytt ∂∂∂=
∂∂=• Notation:
• Given a function u of two or more independent variables, e.g. u(x,y,z,t)
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
PDEs in Physics
• Independent variables are • Static Problem: x (1D), x,y (2D), x,y,z (3D)• Dynamic Problem: x,t (1D+1) x,y,t (2D+1) x,y,z,t (3D+1)
• Unknown function u can be • u(x,..) a scalar,
e.g. temperature T, density ρ• u(x,..) = [u(x,..), v(x,..), w(x,..)]T a vector,
e.g. displacement u, velocity v
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
PDE Classification
• Order• Order of PDE = Order of highest partial derivative
0),(),(),(),(
),(),(),(
7654
321
=+++
+++
yxfuyxfuyxfuyxf
uyxfuyxfuyxf
yx
yyxyxx
• 2nd order linear PDE of 2 independent variables:
uuu xyxx =⋅• Non-linear example
• Linear• u and its partial derivatives only occur linearly• coefficients may be functions of independent variables
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
PDE Classification
• Classification of 2nd order linear PDEs
),,,,(),(),(2),( yxyyxyxx uuuyxFuyxCuyxBuyxA =++
• Hyperbolic B2-AC > 0• Parabolic B2-AC = 0
• Elliptic B2-AC < 0
• Geometric motivation• Different mathematical and physical behavior• Determines type of boundary conditions needed• For more than 2 independent variables use generalized
criterion (see textbook)
4
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
PDE Classification
Hyperbolic• time-dependent processes• not evolving to a steady state, reversible• propagate behavior undiminished, e. g. wave motion
Parabolic• time-dependent processes• evolving to a steady state, irreversible• dissipative, e. g. heat diffusion
Elliptic• time-independent• already in steady state
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Boundary Conditions
• Generally, there are many u which solve the PDE
• In physical applications only one solution is expected
x
t
D
x0
x1
• Typically u is only defined in a region D
• The physical solution is required to satisfy certainconditions on the boundary δD of D
Initial condition)()0,( xuxu o=
)(),( 11 tftxu =
Value prescribedDirichlet condition
)(),( 00 tftxux =Derivative prescribedNeumann condition
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Outline
Mathematical BackgroundWhat is a PDE?Types of PDEsBoundary Conditions
Solution TechniquesAnalytical MethodsNumerical Methods
ExamplesAdvectionDiffusionThe Wave Equation
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Analytical Solution Techniques
• Analytical solutions only exist for small and simple problems
• linear equations, simple geometry, initial and boundary conditions
• Examples for analytical solution techniques (see textbooks):• Method of separation of variables• Theory of characteristics• Green function method• Laplace transform
• Real-world problems are typically solved numerically
5
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Numerical Solution - Overview
GoverningEquationsIC / BC
DiscretizationSystem ofAlgebraicEquations
Equation(Matrix)Solver
Approx.Solution
ContinuousSolution
Finite DifferenceFinite VolumeFinite ElementSpectralBoundary Element
DiscreteNodal Values
ExplicitsolutionCG
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Discretization
Spatial derivatives• Finite-difference method FDM• Finite-element method FEM• Finite-volume method FVM• Spectral methods• Boundary element methods• …
Time derivatives• Finite-difference methods
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
The Finite Difference Method
• Simplest method to understand and implement
),,(],,[ tthjhiutjiu ∆⋅⋅⋅=
• Sample function u on a regular grid, e.g.
,...)2,1,0(),,..,1(),,..,1( ∈∈∈ tmjni
• with grid spacing h and time step ∆t
u[i,j,t]h
h
x
y
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
The Finite Difference Method
• Approximation of the temporal derivative
• Approximation of spatial derivatives (three possibilities)
)(],,[]1,,[
],,[ tOt
tjiutjiutjiut ∆+
∆−+
=
)(],,[],,1[
],,[ hOh
tjiutjiutjiux +
−+= forward scheme
)(],,1[],,[
],,[ hOh
tjiutjiutjiux +
−−= backward scheme
)(2
],,1[],,1[],,[ 2hO
htjiutjiu
tjiux +−−+
= central scheme
• If information moves from left to right (as in ut= -cux)backward is upwind (upwind is best choice)
6
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
The Finite Difference Method
• Approximation of higher derivatives
)(],,1[],,[2],,1[
],,1[],,[],,[
22 hO
htjiutjiutjiu
htjiutjiu
tjiu xxxx
+−+−+
=
−−=
• Higher-order approximations
)(12
],,2[],,1[8],,1[8],,2[],,[ 4hO
htjiutjiutjiutjiu
tjiux ++−++−−−
=
)(12
],,2[],,1[16],,[30],,1[16],,2[],,[ 4
2hO
htjiutjiutjiutjiutjiu
tjiuxx ++−++−−+−−
=
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
The Finite Difference Method
• PDE becomes system of algebraic equationsfor the grid values u[i,j,t]
• Linear PDE becomes system of linear equationsfor the grid values u[i,j,t]
• Simple stability rule: Information must not travel morethan one grid cell in one time step
cht /<∆→<∆ htc
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Explicit Schemes – Linear Scalar Advection
• upwind (c>0)
0]1,[],[],[],1[
=∆
−−+
∆−+
xituitu
ct
ituitu ( )]1,[],[],[],1[ −−∆∆
−=+ ituituxt
cituitu
• downwind (c>0)
0],[]1,[],[],1[
=∆
−++
∆−+
xituitu
ct
ituitu ( )],[]1,[],[],1[ ituituxt
cituitu −+∆∆
−=+
• centered (Forward time centered space FTCS)
02
]1,[]1,[],[],1[=
∆−−+
+∆
−+x
ituituc
tituitu ( )]1,[]1,[
2],[],1[ −−+
∆∆
−=+ ituituxt
cituitu
• Leap-frog
02
]1,[]1,[2
],1[],1[=
∆−−+
+∆
−−+x
ituituc
tituitu ( )]1,[]1,[],1[],1[ −−+
∆∆
−−=+ ituituxt
cituitu
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Explicit Schemes – Linear Scalar Advection• Lax-Wendroff
( ) ( )]1,[],[2]1,[21
]1,[]1,[2
],[],1[2
−+−+
∆∆
+−−+∆∆
−=+ ituituituxt
cituituxt
cituitu
• Beam-Warming (c>0)
• Lax-Friedrich
• CFL number (Courant-Friedrichs-Lewy), important in stability analysis
( ) ( )]2,[]1,[2],[21
]2,[]1,[4],[32
],[],1[2
−+−−
∆∆
+−+−−∆∆
−=+ ituituituxt
cituituituxt
cituitu
( ) ( )]1,[]1,[2
]1,[]1,[21
],1[ −−+∆∆
−−−+=+ ituituxt
cituituitu
xt
c∆∆
=σ
7
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Outline
Mathematical BackgroundWhat is a PDE?Types of PDEsBoundary Conditions
Solution TechniquesAnalytical MethodsNumerical Methods
ExamplesAdvectionDiffusionThe Wave Equation
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Advection in 2D and 3D
• In 2D and 3D, speed c is a vector with direction ncand length c
xt cTT −=• For 1D advection we had
TTt ∇⋅−= c
• Since c = cnc the general advection PDE reads
• We have the spatial derivative of T in direction nc
)( TcT ct ∇⋅−= n• Thus, we have
,TTc
c
∇⋅=∂∂ nn
∂∂∂∂
=∇
=∇
yx
TT
Ty
x
//
,:2Din
Nabla operator
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Finite Differences Solution
−−+−−∆−=+
hjiTjiTc
hjiTjiTctjiTjiT yx
tt ]1,[],[],1[],[],[],[1
• The update rule in 2D
TyxTt ∇⋅−= ),(c
• Make the wind velocity a function of the location
• T is advected by a general wind field• Use velocity array, replace cx by cx[i,j] and cy by cy[i,j]• PDE still first order and linear
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Diffusion in 1D
• Conduction law: The mass flow through an area A (flux) is proportional to the gradient of the density normal to A:
• The density ρ(x) describes the concentration of a substance in a tube with cross section A.
xx x+dx
Am=ρ(x)Adx
A
xxdxxx kkdtA
AdxxddtAdm ρρρ −==
+
)(
xxxxdxxx
t kdx
k ρρρ
ρ =−
= +xxt kρρ =
Conductivity
8
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Diffusion in 3D
• The diffusion PDE in 3D
• Intuition for second spatial derivatives• Constant concentration gradient ρ(x)=a+bx has no effect
Flux but no change Flux and positive change
ρρρρρρ ∆=∇=++= kkk zzyyxxt2)(
Laplace operator
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Finite Differences Solution
21 ],[4]1,[]1,[],1[],1[],[],[
hktjiji jijijijijitt ρρρρρρρ −−+++−++∆+=+
• The update rule in 2D
• Intuition:If the average concentration of the neighbor cells is larger than the concentration of the cell, its concentration increases and vice versa.
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
The 1D Wave Equation
• Function u(x) is displacement of the string normal to x-axis
u
• Assuming small displacements and constant stress σ
xu Auf σ≈• Component in u-direction
xxdxxxtt uAuAuAdx σσρ −=+
)( xxtt uu σρ =
• Newton’s 2nd law for an infinitesimal segment
• Force acting normal to cross section A is Af σ=
xx x+dx
A
u
Vibrating string
fuf
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Analytical Solution
xxtt uu σρ =
)()( ctxfbctxfa −⋅++⋅• with the analytical solution
• For the string we have
xxtt ucu 2=?s
c =• The standard form is where
• so c is the speed with which waves travel
9
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
2D Wave Equation
• The wave equation in 2D
ucucuucu yyxxtt ∆=∇=+= 2222 )(
• Waves propagate with velocity c• For the vibrating string we have c2=σ/ρ
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Finite Differences Solution
221 ],[4]1,[]1,[],1[],1[],[],[
hctjivjiv jiujiujiujiujiutt −−+++−++∆+=+
• The update rule in 2D
• Very simple to implement• Yields cool water surface animation
],[],[],[ 11 jivtjiujiu ttt ++ ∆+=
• Boundary conditions assuming• Periodic:• Mirror:
• Analog for j
],1[],1[],,[],0[ jujnujnuju =+=],[],1[],,1[],0[ jnujnujuju =+=
),..,1( ni ∈
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Demo
tw
tt utcvv 221 ∇∆+=+
• Combination of wave equation, diffusion, advection (1D)
xxwtt ucu 2−=
xxdt ucu =
xat ucu −=
( )ta
td
ttt ucucvtuu ∇−∇+∆+= ++ 211
• Explicit Leap-frog integration
wave equation
advection
diffusion
University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory
Literature
• Alan Jeffrey, „Applied Partial Differential Equations – An Introduction,“ Academic Press, Amsterdam, ISBN 0-12-382252-1
• John D. Anderson, „Computational Fluid Dynamics – TheBasics with Applications,“ McGraw-Hill Inc., New York, ISBN 0-07-001685-2