Lecture 3
Lecture 3
by
Dr Ceri
Computational Methods -
Morris Week 8
Discretisation
Discretisation
• Process by which a differential or integral equation is
approximated by algebraic expressions to provide values at
a number of discrete points in the flow domain
𝜕𝑓
𝑓 𝑥 + ∆𝑥
𝜕𝑥
𝜕𝑓 𝜕 𝑓 ∆𝑥
𝑓 𝑥 + ∆𝑥 +
𝜕𝑥 𝜕𝑥 2!
𝜕𝑓 𝜕 𝑓 ∆𝑥 𝜕 𝑓 ∆𝑥
𝑓 𝑥 + ∆𝑥 + +
𝜕𝑥 𝜕𝑥 2! 𝜕𝑥 3!
𝑓(𝑥)
𝑓 𝑥
𝑥 𝑥+∆𝑥
Taylor Series
𝑓 0.22 = 0.9823
𝑓 0.22 ≈0.9824 0.001% error
𝑓(𝑥)
𝑓 0.2 = 0.9511
𝑥 𝑥 + ∆𝑥
Finite difference
• Let us consider the terms in the Navier-Stokes equation
for incompressible flow in the x direction:
, ,
, , ,
Rearrange for :
,
𝑖, 𝑗 𝑖 + 1, 𝑗
, ,
, , ,
, , , ,
, ,
First Order
Forward difference
First Order Backward Difference
Taylor Series Expansion:
, ,
, , ,
Rearrange for :
,
, , 𝑖 − 1, 𝑗 𝑖, 𝑗
, , ,
, , , ,
, ,
First Order
Backward difference
Second Order Central Difference
Subtract Taylor Series expansion for , from expansion for , :
, ,
, ,
Rearrange for :
,
, , 𝑖 − 1, 𝑗 𝑖 + 1, 𝑗
, ,
, , , ,
, ,
Second Order
Central difference
Second Order Central Second Difference
, , ,
, ,
Rearrange for :
,
𝑖 − 1, 𝑗 𝑖, 𝑗 𝑖 + 1, 𝑗
, , ,
,
Second Order
Central Second Difference
Finite Difference Expressions
𝜕𝑢 𝑢 ,−𝑢, 𝜕𝑢 𝑢, −𝑢 , 𝜕𝑢 𝑢 , −𝑢 , 𝜕 𝑢 𝑢 , − 2𝑢 , + 𝑢 ,
= = = =
𝜕𝑥 ∆𝑥 𝜕𝑥 ∆𝑥 𝜕𝑥 ,
2∆𝑥 𝜕𝑥 (∆𝑥)
, , ,
𝑖, 𝑗 𝑖 + 1, 𝑗
𝑖 − 1, 𝑗
𝑖, 𝑗 − 1
1st
order 1st
order 2nd order 2nd order
forward difference backward difference central difference central 2nd difference
wrt y wrt y wrt y wrt y
Higher Order Accuracy Finite Differences
E.g.
, , , , ,
,
Fourth Order
Central difference
• E.g. 2D Navier-Stokes
steady momeequation in x direction:
, , , , , ,
Example 1: 1D linear Convection
• Consider the equation
u u
c 0
t x
c = is the transport velocity, u = u (x,t) is a transported quantity
Since c = constant this a linear problem.
u u
• There are two partial derivatives: t and x so we need to discretise in
time t and space x: time-space discretisation.
n and n+1 are two consecutive steps in time while i-1 and i are two
neighbouring spatial points.
Example 2: 1D Diffusion equation
u 2u
• Consider the PDE t x 2
• Use Forward difference in time t, with index n
• Use central difference for space x, with index i
• The discretised form is uin1 uin uin1 2uin uin1
t x 2
• Solving for u n 1
i
t
u n 1
u
n
u n
2uin uin1
i i
x 2 i 1
FD Method: Observations
• Coupled sets of
equations
• Matrix or iterative
technique needed
Explicit Vs Implicit
• Simpler to set up and • Can use much larger values
program of Δt – fewer time steps
required
Iterative Solvers
Iterative Solvers
• Consider simultaneous 4x + 2y + 3z = 8
equations shown: 3x - 5y + 2z = -14
-2x + 3y + 8z = 27
Iteration 2
• Take the y and z values from iteration 1 and solve for x
• Take the x and z values from iteration 1 and solve for y
• Take the y and z values from iteration 1 and solve for z
Y 0 2.800 5.350 2.771 1.478 3.425 3.943 2.548 2.449 3.400 3.297
Z 0 3.375 2.825 0.886 1.637 2.808 2.099 1.442 2.033 2.368 1.913
2
Value
X
0 Y
-2 Z
-4
0 5 10 15 20 25 30
Iteration
Residuals
• Move all terms in each expression to the left hand side
• The right hand side should then equal zero
• Enter the values calculated for each iteration to give the
residual for that iteration
• Residuals show how far away the estimated values are
from perfectly satisfying the equation
Residuals - Jacobi
0 1 2 3 4 5 6 7 8 9 10
X 0.00 2.00 -1.93
-8.00 15.73 3.45
Y 0.00 2.80 5.35
14.00 12.75 -12.89
Z 0.00 3.38 2.83
-27.00 4.40 15.51
30
25
20 X
Residual
15 Y
10 Z
0
0 5 10 15 20 25 30
Iteration
Iterative Solvers – Gauss-Seidel
0 1 2 3 4 5 6 7 8 9 10
X 0.00 2.00 -1.78
5
4
3
2
Value
1 X
0 Y
-1 Z
-2
-3
0 2 4 6 8 10
Iteration
Residuals – Gauss-Seidel
0 1 2 3 4 5 6 7 8 9 10
X 0.00 2.00 -1.78
-8.00 15.13
Y 0.00 4.00 2.68
14.00 4.75
Z 0.00 2.38 1.92
-27.00 0.00
30
25
20 X
Residual
15 Y
10
Z
5
0
-5 0 2 4 6 8 10
Iteration
Initial Values
• Possible to use better estimates as initial values
instead of setting all variables to 0
• Reduce the number of iterations needed to
achieve a stable solution
• Common to set all values to those at a boundary,
e.g. inlet
Iterative Solvers
• These examples used very simple equations.
Imagine how long it would take to find a
solution to the Navier-Stokes equations for
several thousand or million cells
new , used
P old
P U ( new , predicted
P old
P )
• E.g. If velocity at a given point is calculated as 2 m/s after
10 iterations and the new, predicted value after iteration
11 is 2.4 m/s
• A U value of 0.5 will result in a new, used value for
iteration 11 of 2.2 m/s
• A U value of 0.75 will results in a new, used value for
iteration 11 of 2.3 m/s
• A U value of 1.5 will result in a new, used value for
iteration 11 of 2.6 m/s
Can you?
• Explain the difference between Explicit & Implicit Methods
o Explicit – 1 unknown per variable, simple, need small Δt for
stability
o Implicit - variables based on several unknowns, matrix/iterative
approach needed, more complex but stable for larger Δt