You are on page 1of 42

Numerical solution of partial

differential equations (PDEs)


NB: In the printed notes, the section
on PDEs is more technical and
assumes stronger prior knowledge.
It is also a little less structured.
Only material in these online slides is
examinable (more later)
Partial differential equations in engineering
Ordinary vs Partial differential eqns:
eg, initial-value ODEs vs PDEs
Derivative wrt to single Derivatives wrt to multiple
independent variable independent variables

dy ∂U ∂U 2
= −5 y = −10 2
dt Initial condition ∂t ∂x
is a function
y (t0 ) = y0 ⎡π x ⎤
U ( x, t = t0 ) = sin ⎢ ⎥
⎣ 3 ⎦
ODEs: Initial condition is a
number (scalar ODE), or U ( x = 0, t ) = 0
set of numbers (ODE system)
U ( x = 3, t ) = exp( −7t )
PDEs are almost always
Boundary conditions
harder to solve than ODEs (also functions)
Partial differential eqns (PDEs)

General 2nd
order PDE with
2 independent
variables

3 main categories
of PDEs

Beyond our scope


Initial-value (“parabolic”) PDE problems
Usually describes the evolution
of a “field” through time, eg,
U temperature across a rod, etc

k (“conductivity”)
x is a property of the
material

∂U ∂ 2U
= −k 2 Some applications:
Conditions
at which
∂t ∂x * Transient groundwater flows
the material U ( x, t = t0 ) = f ( x ) * Mixing processes in chemical
is initially, engineering
or will be U ( x = 0, t ) = g (t )
subjected to
U ( x = L, t ) = h(t )
Boundary-value (“elliptic”) PDE problems
Ordinary differential
Boundary conditions
equation

∂U ∂U
2 2
+ 2 = f ( x, y ); U ( Γ) = g ( x, y )
∂x 2
∂y
Usually describes the
steady-state distribution of
a quantity through space

Solution usually constrained


on the boundary of the domain

Some applications:
* Steady-state groundwater flows
* Loaded beams/foundations in structures
Analytical (exact) solutions
Exact solutions almost always preferable …
… but are very rarely available for PDEs

∂U
= − kU
∂t U (t ) = U 0 exp( − Kt )
U (t = 0) = U 0
Strong analogies between initial-
value ODE and PDE problems,
but PDE’s are much harder
∂U ∂ 2U
= −k 2
∂t ∂x
U ( x, t ) = sin( x ) exp( − Kt )
U ( x, t = 0) = sin( x )
U ( x = 0, t ) = U ( x = 1, t ) = 0 In many cases analytical solution
of PDEs is not possible
Approximate numerical solutions
Recall that numerical ODE solution required approximating a
continuous solution by discrete points

y
y(t)

y0 1) Discretization
2) Approximation

t0 t
Approximate numerical solutions
Same concepts apply to PDE approximation, but in more dimensions
y Ui,j ≈ U(xi , yj)
j
U(x,y)

i, j+1

x i-1, j i+1, j
Replace a continuous
i, j
domain by a grid

i, j-1
Solve for solution
values on the grid
i
Numerical approximation of initial-value
(“parabolic”) PDE problems
Original continuous
solution of the PDE

Discrete approximation of
the solution of the PDE

∂U ∂ 2U
= −k 2
∂t ∂x
U ( x, t = t0 ) = f ( x )
U ( x = 0, t ) = g (t )
U ( x = L, t ) = h(t )
Potential problems with PDE
approximations (“instability”)
Uncontrolled error growth
or oscillations are
is a particular concern when
solving PDEs
U More common problem than in
ODE approximations

Numerical PDE
t = t2
approximations should
be checked to ensure
approximation errors
t = t1
are adequately small
(often easier said than
t = t0
done! If we knew the
error we would have
x
exact solution!)
Initial-value
(“parabolic”) PDEs
Computational mesh (‘discretization’)
“time” n

i, n+1

Time level index


i-1, n i, n
i+1, n

n +1
i, n-1

U i
Spatial node index

“space” i
Explicit-central approximation
∂U ∂ 2U
Forward difference = −k Central finite
approximation to ∂t ∂x 2 difference
∂U/ ∂t – relative to
time-level tn approximation
to ∂2U/ ∂x2 at
time-level tn

U in +1 − U in U in−1 − 2U in − U in+1
= k
Δt Δx 2
Explicit = forward
(different name,
Re-arrange
same thing)

Δt
U n +1
= U − k 2 ⎡⎣U in−1 − 2U in + U in+1 ⎤⎦
n

Δx
i i
Explicit-central scheme
“time” n

Δt
Uin+1 = Uin − k ⎡
2 ⎣
U n
−1 − 2U n
+ U n
+1 ⎤

Δx
i i i
Boundary
Boundaryconditions
conditions
must be known
Keep “stepping” thru
time, updating an entire
“time level” before
proceeding to the next

n → n +1
Initial conditions (“initial
“space” i profile”) must be known
How does the resolution
(temporal and spatial) affect the
approximation error?
Error of forward-central approximation
∂U ∂ 2U Central finite difference
= −k 2 approximation to ∂2U/ ∂x2
∂t ∂x
U = U (t , xi ) + error
i
n n

error ≈ C1Δt + C2 Δx 2

U in +1 − U in U in−1 − 2U in − U in+1
=k
Δt Δx 2
Approximation Approximation
error arising error arising
from time- from space-
Forward finite difference discretization, discretization,
approximation to ∂U/ ∂t O(Δt) O(Δx2)
PDE “stiffness”
Potential problems with PDE
approximations Uncontrolled error growth
(“instability”) or oscillations are
is a particular concern when
solving PDEs
U

In most cases, instabilities


arise due to “stiffness” of
the PDE …

x
Exact solution decays
“Stiffness” U with time, but explicit
approximation is unstable

∂U ∂U 2
= −k 2
∂t ∂x
U in +1 − U in U in−1 − 2U in − U in+1
=k
Δt Δx 2 x
The forward (explicit) scheme
U → ±∞ as n → ∞
i
n
is conditionally stable:
if Δt > Δx 2 / 2k If Δt exceeds a certain limit,
the scheme becomes unstable
Forward-central scheme does and ‘blows up’ (produces
not preserve exponential meaningless results)
decline of exact solution
1) Use smaller time steps? Overcoming “stiffness”:
Works sometimes, but ODE analogy
may not be practical
2) Use a “stiff” (implicit) y
solver (preferred)

dU
Equation to be
solved = − kU
dt
t
n +1 “Small” change, but
U −U n
totally different
Explicit Euler
approximation = −kU n
Δt numerical behaviour

Implicit Euler U n +1 − U n * Explicit Euler scheme: conditionally stable


approximation = −kU n +1 (blows up if stepsize too large)
Δt * Implicit Euler scheme: unconditionally stable
(very robust): works with any stepsize
Overcoming “stiffness”: ODE vs PDE
y
Explicit (forward) methods Implicit (backward)
(ODE and PDE) based on methods (ODE and PDE)
time level n based on time level n+1

∂U ∂ 2U t
dU
= kU =k 2
dt ∂t ∂x

Explicit U n +1 − U n U in +1 − U in U in−1 − 2U in − U in+1


Euler = −kU n = k
Δt Δt Δx 2

Implicit U n +1 − U n U in +1 − U in U in−+11 − 2U in +1 − U in++11


Euler = −kU n +1 = k
Δt Δt Δx 2
ODE solution PDE solution
Implicit-central approximation
∂U ∂ 2U
= −k
∂t ∂x 2

U in +1 − U in U in−+11 − 2U in +1 − U in++11 Backward difference


= k approximation to
Δt Δx 2 ∂U/ ∂t – relative to
time-level tn+1
Re-arrange
Central difference
Δt approx to ∂2U/ ∂x2 at
−λU n +1
i −1 + (1 + 2λ ) U n +1
− λU n +1
i +1 =U ; λ = k 2
n
time-level tn+1
Δx
i i
Implicit-central approximation
Solution at new
Δt
−λU in−+11 + (1 + 2λ ) U in +1 − λU in++11 = U in ; λ =k 2 time step
Δx
Matrix with
known values
⎡1 + 2λ −λ ⎤ ⎧U1n +1 ⎫ ⎧U1n ⎫
⎢ −λ ⎥ ⎪ n +1 ⎪ ⎪ n ⎪
1 + 2λ −λ
⎢ ⎥ ⎪⎨U 2 ⎪⎬ = ⎪⎨U 2 ⎪⎬
⎢ −λ 1 + 2λ −λ ⎥ ⎪U 3n +1 ⎪ ⎪U 3n ⎪
⎢ ⎥ ⎪ n +1 ⎪ ⎪ n ⎪
⎣ −λ 1 + 2λ ⎦ ⎩U 4 ⎭ ⎩U 4 ⎭
Solution at old
time step

Example from Chapra


and Canale (p. 740)
Implicit-central approximation
„ Unconditionally stable: solutions cannot
blow-up even if the stepsize is very large
„ Requires the solution of a linear system of
equations at each time step => single
implicit step much more expensive than
single explicit step
„ Is warranted if the problem is infeasible for
explicit methods due to stability problems
Central-central method (“Crank-Nicolson”)
Central finite difference
∂U ∂ 2U approximation to ∂U/ ∂t
= −k relative to time-level n+1/2
∂t ∂x 2
Central finite difference
approximation to ∂2U/ ∂x2 at
time-level n+1/2

U in +1 − U in U in−+11/2 − 2U in +1/2 − U in++11/2


= k
Δt Δx 2

Re-arrange

Set of linear equations (similar to U in = U (t n , xi ) + error


implicit-central method, more complex)
error ≈ C1Δt 2 + C2 Δx 2
Crank-Nicolson approximation
„ Unconditionally stable: solutions cannot blow-up
even if the stepsize is very large
„ Requires the solution of a linear system of
equations (similar to the implicit method)
„ Is usually more accurate than the implicit method
(central instead of backward differences for ∂U/∂t)
„ Is warranted if the problem is infeasible for
explicit methods due to stability problems
„ Comparison with the implicit method is case-
specific (implicit scheme often more robust)
COMPUTATIONAL
EFFICIENCY
Computational efficiency/practicality
„ A key practical factor in any computation
– For PDEs, the “size” of the problem increases very fast,
(eg, 1000 nodes x 1000 steps = 1,000,000 values of
solution to contend with)
„ Computational cost depends on:
– The “time resolution” (Δt)
– The “space resolution” (Δx)
„ Stability is an important consideration
– If a method requires a small stepsize to maintain stability,
it can become highly inefficient
– Implicit methods are unconditionally stable (robust) and in
many cases more efficient than explicit methods
– But explicit scheme is simpler to program … tradeoff!
Sensitivity to initial
conditions
The Butterfly Effect
„ “Can a flap of a Butterfly’s wings in Brazil set off a
tornado in Texas?”
Mathematical chaos, or
“Chaotic system”: A system
that depends so strongly on
initial conditions that long-
term forecasts are impossible

Imposes fundamental limits on


what can be predicted and how
NB: not all engineering
far into the future: for any
phenomena are chaotic,
differential equation (ODE/PDE) and most are stable
Boundary-value
(“elliptic”) PDEs
T (eg, temperature) is
the dependent variable

j
∂T ∂T
2 2
+ 2 =0
∂x 2
∂y
x and y are space
coordinates
i

NB: T = temperature, t = time (not


represented in elliptic PDEs)
is known

Defines a linear
1
Ti , j = ( Ti −1, j −1 + Ti −1, j +1 + Ti +1, j −1 + Ti +1, j +1 )
relationship between
unknown solution
4 values at the nodes

Can solve the linear system using iteration

1 K
T K +1
i, j = ( Ti −1, j −1 + Ti −K1, j +1 + Ti +K1, j −1 + Ti +K1, j +1 ) Iteration index (DO
4 NOT confuse with
time level!)
Spatial K +1
Iterate until Ti , j ≈ Ti , j
K
location index
Laplace equation

j
∂T ∂T
2 2
+ 2 =0
∂x 2
∂y
x and y are space
coordinates
i

1 K
T K +1
i, j = (Ti −1, j −1 + Ti −K1, j +1 + Ti +K1, j −1 + Ti +K1, j +1 ) Unlike initial-value
4 PDEs, where solution
progressed level-by-
level, elliptic PDEs
K +1
Iterate until Ti , j ≈ Ti , j
K
need to be solved
simultaneously over
entire domain
Fundamental differences
between solving
initial- vs boundary-value
differential equations
Initial-value (time-dependent) PDEs Boundary-value (space-dependent) PDEs

n
j

i i
∂U ∂ 2U ∂U ∂U
2 2
= −k 2 + 2 =0
∂t ∂x ∂x 2
∂y
Δt
U n +1
= U − k 2 ⎡⎣U in−1 − 2U in + U in+1 ⎤⎦ U iK, j+1 = 1 (U iK−1, j −1 + U iK−1, j +1 + U iK+1, j −1 + U iK+1, j +1 )
n

Δx
i i
4

Keep time stepping till K +1


Iterate until U i , j ≈ U i , j
K

requested time tFinal


Connections between
elliptic/parabolic PDEs
vs ODEs
Elliptic PDEs are “steady-state”
versions of parabolic PDEs
Solve the (harder) initial- Many engineering Solve the simpler
value problem if want to steady-state problem
know entire behaviour phenomena approach if not interest in
“steady-state” over time early times

∂U ∂U 2
∂U 2
= −k 2 0= 2
∂t ∂x ∂x
Parabolic PDE in 1D space Boundary-value ODE
t→∞
∂U ∂ U ∂ U 2 2
∂U ∂U2 2
= 2 + 2 0= 2 + 2
∂t ∂x ∂y ∂x ∂y
Parabolic PDE in 2D space Boundary-value PDE (2D)
Irregular domains (intro)
Finite-differences vs finite-elements

Finite-difference
approximation Finite-element
(forces a regular approximation
Actual system grid unto an (more suitable for
irregular system!) complex systems)
END OF PDE SECTION

You might also like