You are on page 1of 11

6.

TIME-DEPENDENT METHODS SPRING 2010

6.1 The time-dependent scalar-transport equation


6.2 One-step methods
6.3 Multi-step methods
6.4 Uses of time-marching in CFD
Summary
Examples

6.1 The Time-Dependent Scalar-Transport Equation

The time-dependent scalar-transport equation for an arbitrary control volume is


d
(amount ) + net flux = source (1)
dt
where:
amount total quantity in a cell = mass × concentration = Vφ;
flux is the rate of transport through the boundary .

In Section 4 it was shown how the flux and source terms could be discretised as
net flux − source = a P φ P − ∑ a F φ F − bP (2)
F
In this Section the time derivative will also be discretised.

We first examine numerical methods for the first-order differential equation



=F, φ(0) = φ 0 (3)
dt
where F is an arbitrary function of t and φ. Then we extend the methods to CFD.

Initial-value problems of the form (3) are solved by time- φ φ


new

marching. There are two main types of method:

∆φ
• φ old
one-step methods: use the value from the previous time
level only; ∆t

t
t old t new
φ

φ
(n+1)

• multi-step methods: use values from several previous times.


φ (n)
φ (n-2) φ (n-1)

t
t(n-2) t(n-1) t(n) t(n+1)

CFD 6–1 David Apsley


φ new
φ
6.2 One-Step Methods

For the first-order differential equation


∆φ

=F (3) φold
dt
the one-step problem is: ∆t
given φ at time t(n) … compute φ at time t(n+1)
t
t old t new
The following notation is used:
• identify everything at t(n) by a superscript “old” – this is what we currently know;
• identify everything at t(n+1) by a superscript “new” – this is what we seek.

By integration of (3), or from the figure above,


φ = F av t (4)
or
φ new = φ old + F av t (5)
These are exact. However, since the average derivative, F , isn’t known until the solution φ
av

is known, it must be estimated.

6.2.1 Simple Estimate of Derivative

This is the commonest class of time-stepping scheme in general-purpose CFD. There are
three obvious methods of making a single estimate of the average derivative.

Forward Differencing Backward Differencing Centred Differencing


(Euler Method) (Backward Euler) (Crank-Nicolson)
Take Fav as the derivative at the Take Fav as the derivative at Take Fav as the average of
start of the time-step: the end of the time-step: derivatives at the beginning and end.

φ new = φ old + F old t φ new = φ old + F new t φ new = φ old + 12 ( F old + F new ) t

φ φ φnew φ
φnew
φ new

φ old φold φold

1 1
2∆ t 2∆ t
t t t
t old t new t old t new t old t new
For: For: For:
• Easy to implement because • In CFD, no time-step • Second-order accurate in t.
explicit (the RHS is known). restrictions;
Against: Against: Against:
• Only first-order in t; • only first-order in t; • Implicit;
• In CFD, stability imposes • implicit (although, in CFD, • In CFD, stability imposes time-
time-step restrictions. no more so than steady case). step restrictions.

CFD 6–2 David Apsley


Classroom Example 1

The following differential equation is to be solved on the interval [0,1]:



=t −φ, φ( 0 ) = 1
dt
Solve this numerically, with a step size t = 0.2 using:
(a) forward differencing;
(b) backward differencing;
(c) Crank-Nicolson.

Solve the equation analytically and compare with the numerical approximations.

Classroom Example 2

Solve, numerically, the equation



= t 3 − φ3 , φ(0) = 1
dt
in the interval 0 ≤ t ≤ 1 using a timestep t = 0.25 by:
(a) the forward differencing (fully-explicit) method;
(b) the backward-differencing (fully-implicit) method;
(c) the Crank-Nicolson (semi-implicit) method.

Note that, since the equation is non-linear, the implicit methods (parts (b) and (c)) will
require iteration at every timestep.

CFD 6–3 David Apsley


6.2.2 Other Methods

For equations of the form = F , improved solutions may be obtained by making
dt
successive estimates of the average gradient. Important examples include:

Modified Euler Method (2 function evaluations; similar to Crank-Nicolson, but explicit)


φ1 = t F (φ old , t old )
φ 2 = t F (φ old + φ1 , t old + t )
φ = 12 ( φ1 + φ 2 )

Runge-Kutta (4 function evaluations)


φ1 = t F (φ old , t old )
φ 2 = t F (φ old + 1
2 φ1 , t old + 1
2 t)
φ 3 = t F (φ old + 12 φ 2 , t old + 12 t )
φ 4 = t F (φ old + φ 3 , t old + t )
φ = 16 ( φ1 + 2 φ 2 + 2 φ 3 + φ 4 )

More details of these – and other advanced methods – can be found in the course notes for the
“Computational Mechanics” unit.

For scalar φ, such methods are popular. Runge-Kutta is probably the most widely-used
method in engineering. However, in CFD, φ and F represent vectors of nodal values, and
calculating the derivative F (evaluating flux and source terms) is very expensive. The
majority of CFD calculations are performed with the simpler methods of 6.2.1.

Exercise. Using Microsoft Excel (or other computational tool of your choice) solve the
Classroom Examples from the previous subsection using Modified-Euler or Runge-Kutta
methods.

6.2.3 One-Step Methods in CFD

General scalar-transport equation:


d
( Vφ P ) + net flux − source = 0 (6)
dt
For one-step methods the time derivative is always discretised as
d ( Vφ P ) new − ( Vφ P ) old
( Vφ P ) → (7)
dt t
Flux and source terms could be discretised at any particular time level as
net flux − source = a P φ P − ∑ a F φ F − bP (8)
Different time-marching schemes arise from the time level at which (8) is evaluated.

CFD 6–4 David Apsley


Forward Differencing
( Vφ P ) new − ( Vφ P ) old
t
[
+ a P φ P − ∑ a F φ F − bP ]
old
=0
Rearranging, and dropping any “new” superscripts as tacitly understood:
old
V  V 
φ P = ( − a P )φ P + b P + ∑ a F φ F  (9)
t  t 

Assessment.
• Explicit; no simultaneous equations to be solved.
V
• Timestep restrictions; for stability a positive coefficient of φ old
p requires − aP ≥ 0 .
t

Backward Differencing
( Vφ P ) new − ( Vφ P ) old
t
[
+ a P φ P − ∑ a F φ F − bP ]
new
=0
Rearranging, and dropping any “new” superscripts:
V Vφ P old
( + a P )φ P − ∑ a F φ F = b P + ( ) (10)
t t

Assessment.
• Straightforward to implement; amounts to a simple change of coefficients:
V V
aP → aP + bP → bP + ( ) old (11)
t t
• No timestep restrictions.

Crank-Nicolson
( Vφ P ) new − ( Vφ P ) old 1
t
[
+ 2 a P φ P − ∑ a F φ F − bP ]
old
[
+ 12 a P φ P − ∑ a F φ F − bP ]
new
=0
Rearranging, and dropping any “new” superscripts:
old
V 1  V 1 
( + 2 a P )φ P − 12 ∑ a F φ F = 12 bP + ( − 2 a P )φ P + 12 (bP + ∑ a F φ F )
t  t 
or, multiplying by 2 for convenience:
old
V  V 
(2 + a P )φ P − ∑ a F φ F = b P + ( 2 − a P )φ P + (bP + ∑ a F φ F ) (12)
t  t 

Assessment.
• Fairly straightforward to implement; amounts to a change of coefficients:
old
V  V 
aP → aP + 2 , b P → b P + ( 2 − a P )φ P + (bP + ∑ a F φ F ) (13)
t  t 
V
• Timestep restrictions; for stability, a positive coefficient of φ old
p requires 2 − aP ≥ 0 .
t

CFD 6–5 David Apsley


In general, weightings 1 – and can be applied to derivatives at each end of the time step:
d
( Vφ P ) ≈ F new + (1 − ) F old (14)
dt
This includes the special cases of Forward Differencing ( = 0), Backward Differencing
( = 1) and Crank-Nicolson ( = ½).

For 0 this so-called “ method” can be implemented by a simple change in matrix


coefficients. For 1 (i.e. anything other than fully-implicit Backward-Differencing),
stability imposes a timestep restriction
1 V
t< ( ) old (15)
1 − aP

Example. Consider a 1-d time-dependent advection-diffusion problem


∂ ∂ ∂φ
( φ) + ( uφ − )=S
∂t ∂x ∂x
with the first-order upwind advection scheme on a uniform grid of spacing x, it is readily
shown that at any time-level the coefficients in the flux-source discretisation are
aW = D + C , a E = D, a P = aW + a E = 2 D + C
where the mass flow rate C and diffusive transfer coefficient D are given by
A
C = uA, D=
x
In the 1-d case the cross-sectional area A = 1 and the time-step restriction (15) becomes
2 t u t 1
+ <
( x) 2
x 1−

Special cases are:–


( / ) t 1
• explicit (forward differencing; = 0) and pure diffusion (u = 0): <
( x) 2 2
u t
• explicit (forward differencing; = 0) and pure advection ( = 0): <1
x
• implicit (backward differencing; = 1): no restrictions.

Courant Number

The Courant number c is defined by:


u t
c= (16)
x
It can be interpreted as the ratio of distance of travel in one time step (u t) to the mesh
spacing x.

For the fully-explicit method the Courant-number restriction c < 1 means that the distance
which information can be advected in one time step should not exceed the mesh spacing.

The Courant-number restriction is only slightly milder when = ½ (Crank-Nicolson).

CFD 6–6 David Apsley


φ

6.3 Multi-Step Methods


φ
(n+1)
One-step methods use only information from time level t(n) to
calculate (dφ/dt)av.
φ (n)
Multi-step methods use the values of φ at earlier time levels as φ (n-2) φ (n-1)
well: t(n-1), t(n-2), ... .
t
t(n-2) t(n-1) t(n) t(n+1)
One example is Gear’s method:
3φ ( n ) − 4φ ( n −1) + φ ( n − 2 )
(n)
 dφ 
  = (17)
 dt  2 t
This is second-order in t; (exercise: prove it).

A wider class of schemes is furnished by so-called predictor-corrector methods which refine


their initial prediction with one (or more) corrections. A popular example of this type is the
Adams-Bashforth-Moulton method:
+1
predictor: φ npred = φ n + 241 t [−9 F n −3 + 37 F n −2 − 59 F n−1 + 55F n ]
corrector: φ n +1 = φn + 1
24 t [ F n −2 − 5 F n −1 + 19 F n + 9 F pred
n +1
]

Just as three-point advection schemes permit greater spatial accuracy than two-point schemes,
so the use of multiple time levels allows greater temporal accuracy. However, there are a
number of disadvantages which limit their application in CFD:
• Storage; each computational variable has to be stored at all nodes at each time level.
• Start-up; initially, only data at time t = 0 is available; the first step inevitably requires
a single-step method.

6.4 Uses of Time-Marching in CFD

Time-dependent schemes are used in two ways:


(1) for a genuinely time-dependent problem;
(2) for time marching to steady state.

In case (1) accuracy and stability often impose restrictions on the time step and hence how
fast one can advance the solution in time. Because all nodal values must be updated at the
same rate the time step t is global; i.e. the same at all grid nodes.

In case (2) one is not seeking high accuracy so one simply adopts a stable algorithm, usually
Backward Differencing. Alternatively, if using an explicit scheme such as Forward
Differencing, the time step can be local, i.e. vary from cell to cell, in order to satisfy Courant-
number restrictions in each cell individually.

In practice, for incompressible flow, steady flow should be computable without time-
marching. This is not the case in compressible flow, where time-marching is necessary in
transonic calculations (flows with both subsonic and supersonic regions).

CFD 6–7 David Apsley


Summary

• The time-dependent fluid-flow equations are first-order in time and are solved by
time-marching.

• Time-marching schemes may be explicit (time derivative known at the start of the
time step) or implicit (require iteration at each time step).

• Common one-step methods are Forward Differencing (fully-explicit), Backward


Differencing (fully-implicit) and Crank-Nicolson (semi-implicit).

• One-step methods are easily implemented via changes to the matrix coefficients. For
the Backward-Differencing scheme the only concessions required are:
V ( Vφ P ) old
aP → aP + , b P → bP +
t t

• The only unconditionally-stable two-time-level scheme is Backward Differencing


(fully-implicit timestepping). Other schemes have time-step restrictions: typically
limitations on the Courant number
u t
c=
x

• The Crank-Nicolson scheme is second-order accurate in t. The Backward-


Differencing and Forward-Differencing schemes are both first order in t, which
means they need more time steps to achieve the same time accuracy.

• Multi-step methods may be used to achieve accuracy and/or stability. However, these
are less favoured in CFD because of large storage overheads.

• Time-accurate solutions require a global time step. A local time step may be used for
time-marching to steady state. In the latter case, high time accuracy is not required
and backward differencing is favoured as the most stable approach.

CFD 6–8 David Apsley


Examples

Q1.
Use: (a) forward-differencing; (b) backward-differencing to solve the equation

= t 2 − 2φ , φ(0) = 0
dt
numerically over the interval 0 ≤ t ≤ 1, using a timestep ∆t = 0.25.

Q2.
Gear’s scheme for the approximation of a time derivative is
3φ ( n ) − 4φ ( n −1) + φ ( n − 2 )
(n)
 dφ 
  =
 dt  2 t
where superscripts (n – 2), (n – 1), (n) denote successive time levels. Show that this scheme is
second-order accurate in time.

Q3.
The semi-discretised version of the scalar transport equation
d
(amount ) + net outward flux = source
dt
over a control volume, centred at node P and containing fluid mass V, can be written
d
( Vφ P ) + a P φ P − ∑ a F φ F = bP
dt

(a) Show that time integration using backward differencing, with a timestep t, can be
implemented by simple changes to the coefficients aP, {aF} and bP.

(b) Show that time integration using forward differencing is explicit, but imposes a
maximum timestep for stability, tmax.

(c) Show that time integration using the Crank-Nicolson method, with a timestep t, can
be implemented by changes to the coefficients aP, {aF} and bP and derive an
expression for the maximum stable timestep, tmax.

Q4. (Computational Hydraulics examination, May 2008 – part)


(a) Solve the first-order differential equation
1 dφ
= 1 − φt , φ(0) = 1
φ 2 dt
with a timestep t = 0.25 on the interval 0 t 1, using:
(i) forward differencing;
(ii) backward differencing.

(b) State (without mathematical detail) the advantages and disadvantages of using:
(i) forward-differencing
(ii) backward-differencing
methods in computational fluid dynamics.

CFD 6–9 David Apsley


Selected Answers

Classroom Example 1

t φ
(a) Forward (b) Backward (c) Crank-Nicolson Exact
differencing differencing ( φ = t − 1 + 2e −t )
0 1 1 1 1
0.2 0.8 0.866667 0.836364 0.837462
0.4 0.68 0.788889 0.738843 0.740640
0.6 0.624 0.757407 0.695417 0.697623
0.8 0.6192 0.764506 0.696250 0.698658
1.0 0.65536 0.803755 0.733296 0.735759

Classroom Example 2

(a) Forward-differencing
t(old) φ(old) t(new) φ(new)
0.00 1.0000 0.25 0.7500
0.25 0.7500 0.50 0.6484
0.50 0.6484 0.75 0.6115
0.75 0.6115 1.00 0.6598

(b) Backward-differencing:
t(old) φ(old) t(new) φ(new)
0.00 1.0000 0.25 0.8502
0.25 0.8502 0.50 0.7681
0.50 0.7681 0.75 0.7627
0.75 0.7627 1.00 0.8559

(c) Crank-Nicolson:
t(old) φ(old) t(new) φ(new)
0.00 1.0000 0.25 0.8104
0.25 0.8104 0.50 0.7156
0.50 0.7156 0.75 0.6960
0.75 0.6960 1.00 0.7737

CFD 6 – 10 David Apsley


Q1.
(a) Forward differencing:
told φold tnew φnew
0.00 0 0.25 0
0.25 0 0.50 0.01563
0.50 0.01563 0.75 0.07031
0.75 0.07031 1.00 0.1758

(b) Backward differencing:


told φold tnew φnew
0.00 0 0.25 0.01042
0.25 0.01042 0.50 0.04861
0.50 0.04861 0.75 0.1262
0.75 0.1262 1.00 0.2508

Q4(a)
(i) Forward differencing
t old φ old t new φ new
0 1 0.25 1.2500
0.25 1.2500 0.50 1.5186
0.50 1.5186 0.75 1.6574
0.75 1.6574 1.00 1.4905
1.00 1.4905

(ii) Backward differencing


t old φ old t new φ new
0 1 0.25 1.2778
0.25 1.2778 0.50 1.4238
0.50 1.4238 0.75 1.3995
0.75 1.3995 1.00 1.2830
1.00 1.2830

CFD 6 – 11 David Apsley