Introduction to Finite Difference Methods

Introduction
to Finite
Difference
Methods
Discretisation
Mathematical
derivation
Time
derivatives
Heat
conduction
equation
Summary
Introduction to Finite Difference Methods
ECM3112/3: FD Lecture 2
Introduction
to Finite
Difference
Methods
Discretisation
Mathematical
derivation
Time
derivatives
Heat
conduction
equation
Summary
Discretisation
Aim : to solve continuum mechanics problems governed by
PDE’s using computers. However . . . computers can only add
up!
Need to find a representation of the PDE that the computer
can deal with.
Represent the continuous field T (x) as values at specified
points in space T1 , T2 , T3 etc.
T
x
T1
T2
T3
T4
T5
T6
T7
Introduction
to Finite
Difference
Methods
I.E. we need to discretize the PDE – produces a difference
equation
Discretisation
Mathematical
derivation
How do we deal with terms such as
Heat
conduction
equation
Summary
∂2T
,
∂x 2
∂T
,
∂x
Time
derivatives
∂T
∂t
?
A derivative is a rate of change – a tangent to the curve T (x).
dT
dx x=p
T
∂T
= tangent
∂x
p
x
Introduction
to Finite
Difference
Methods
Approximate this by differences :
dT
dx x=p
T
Discretisation
Forward Difference
Te − Tp
∂T
=
∂x
δx
Mathematical
derivation
Time
derivatives
Heat
conduction
equation
Summary
w
x
e
p
δx
– a forward difference. Alternatively :
T
Backward difference
dT
dx x=p
Tp − Tw
∂T
=
∂x
δx
w
p
e
δx
– a backward difference
x
Introduction
to Finite
Difference
Methods
Finally,
Discretisation
Mathematical
derivation
dT
dx x=p
T
Central difference
Time
derivatives
Te − Tw
∂T
=
∂x
2δx
Heat
conduction
equation
Summary
w
p
e
x
2δx
– central differencing.
Note : there is no inherent reason to prefer one over the other
– however each will produce different errors. Different choices
= different numerical schemes = different errors.
Introduction
to Finite
Difference
Methods
Discretisation
Mathematical derivation
Need to be able to derive these expressions rigorously. Start
from Taylor’s theorem :
Mathematical
derivation
Time
derivatives
2 1
∂T 2∂ T +
(δx)
∂x x 2
∂x 2 x
1
∂3T + (δx)3 3 + . . .
3!
∂x x
T (x + δx) = T (x) + δx
Heat
conduction
equation
Summary
Here we can write
Te = Tp + δx
2 ∂T 1
2∂ T (δx)
+
+ ...
∂x p 2
∂x 2 p
Truncating this at the (δx)2 term and rearanging,
Te − Tp
∂T '
∂x p
δx
(1)
Introduction
to Finite
Difference
Methods
Discretisation
The largest error here is a term which contains δx – this is a
1st order approximation.
We can apply this to any derivative. For example,
Mathematical
derivation
2 1
∂T 2∂ T +
(δx)
− ...
∂x p 2
∂x 2 p
Time
derivatives
Tw = Tp − δx
Heat
conduction
equation
If we subtract (2) from (1), we get
Summary
Te − Tw = 2δx
∂T + O(δx 3 )
∂x p
in other words
∂T Te − Tw
+ O(δx 2 )
=
∂x p
2δx
– so this expression is 2nd order accurate.
(2)
Introduction
to Finite
Difference
Methods
Discretisation
Mathematical
derivation
As you refine the mesh, 2nd order errors disappear faster than
1st order ones. However this does not necessarily mean that
the 2nd order expression is better! (Checkerboarding).
Time
derivatives
Heat
conduction
equation
If we add (2) and (1), the
∂T
∂x
terms will cancel. This gives
Te + Tw = 2Tp + δx 2
Summary
so
∂ 2 T ∂x 2 p
Te − 2Tp + Tw
∂2T
'
2
∂x
δx 2
Introduction
to Finite
Difference
Methods
Discretisation
Time derivatives
We need to discretize
Mathematical
derivation
0
Time
derivatives
Heat
conduction
equation
T1
∂T
∂t .
0
T2
t=0
Do this by time-marching
0
T3
0
T4
t
Summary
Time derivative becomes
∂T
T n+1 − T n
=
∂t
δt
0
T5
0
T6
Introduction
to Finite
Difference
Methods
Heat conduction equation
Thus for the heat conduction equation
Discretisation
∂T
∂2T
=α 2
∂t
∂x
Mathematical
derivation
Time
derivatives
Heat
conduction
equation
we have
Tpn+1 − Tpn
Ten − 2Tpn + Twn
=α
δt
δx 2
Summary
Rearanging this we have an algorithm
Tpn+1 = Tpn +
αδt
Ten − 2Tpn + Twn
2
δx
This could also be written as
Tpn+1 = sTen + (1 − 2s)Tpn + sTwn
with s = αδt/δx 2
Introduction
to Finite
Difference
Methods
We can depict this pictorially :
1st step :
0
T1
Discretisation
0
T2
0
T3
t=0
Mathematical
derivation
0
T4
0
T5
0
T6
δt
t
Time
derivatives
Heat
conduction
equation
Summary
2nd step :
0
T1
t=0
0
T2
0
T3
0
T4
0
T5
0
T6
t
δt
Introduction
to Finite
Difference
Methods
Summary
Discretisation
Mathematical
derivation
Time
derivatives
Heat
conduction
equation
Summary
• PDE’s need to be discretized – converted to difference
equation form – for computational solution.
• We can discretize time and space derivatives on a grid or
mesh. Different differencing schemes give different errors,
different algorithms
• For time-dependent problems, we time-step, or
time-march.
• Need to start this process – provide initial conditions for
the solution
• Also need to provide values at the two ends – boundary
conditions.