numerical methods

149
Numerical Methods in Meteorology and Oceanography Kristofer Döös and Laurent Brodeau Department of Meteorology Stockholm University http://doos.misu.su.se/pub/compnum.pdf E-mail: [email protected], [email protected] January 16, 2014

Upload: victor-kevin-contreras

Post on 16-Jan-2016

20 views

Category:

Documents


0 download

DESCRIPTION

An Introduction Book for learn Numerical Methods for oceanic process

TRANSCRIPT

Page 1: Numerical Methods

Numerical Methods inMeteorology and Oceanography

Kristofer Döös and Laurent BrodeauDepartment of Meteorology

Stockholm Universityhttp://doos.misu.su.se/pub/compnum.pdf

E-mail: [email protected], [email protected]

January 16, 2014

Page 2: Numerical Methods

2

Page 3: Numerical Methods

Contents

1 Introduction 9

2 Partial Differential Equations (PDE) 112.1 Elliptic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.2 Parabolic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.3 Hyperbolic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3 Finite differences 173.1 The grid point method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.2 Finite difference schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.3 Finite time differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.3.1 Two-level-schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.3.2 Three-level-schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4 Numerical stability of the advection equation (hyperbolic) 234.1 The advection equation with leap-frog-scheme, i.e. O [(∆x)] 2 . . . . . . . . . . . . . . 23

4.2 Stability of the the advection equation with leap-frog-scheme . . . . . . . . . . . . . . . 24

4.3 The advection equation with Euler (forward) scheme in time and centred scheme in space 28

4.4 The upstream or upwind scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.5 The advection equation with an O[(∆x)4

]scheme . . . . . . . . . . . . . . . . . . . . 31

5 The numerical mode 355.1 The numerical mode of the three level schemes . . . . . . . . . . . . . . . . . . . . . . 35

5.1.1 The computational initial condition . . . . . . . . . . . . . . . . . . . . . . . . 37

5.2 Suppression of the computational mode . . . . . . . . . . . . . . . . . . . . . . . . . . 37

5.2.1 Euler forward or backward at regular intervals . . . . . . . . . . . . . . . . . . 37

5.2.2 Robert-Asselin filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.2.3 The Robert-Asselin-Williams filter . . . . . . . . . . . . . . . . . . . . . . . . . 38

6 Accuracy of the numerical phase speed 416.1 Dispersion due to the spatial discretisation . . . . . . . . . . . . . . . . . . . . . . . . . 41

6.2 Dispersion due to the time discretisation . . . . . . . . . . . . . . . . . . . . . . . . . . 41

6.3 Dispersion due to both the spatial and time discretisation . . . . . . . . . . . . . . . . . 43

3

Page 4: Numerical Methods

4 CONTENTS

7 Diffusion and friction terms (parabolic) 477.1 Rayleigh friction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

7.2 The heat equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

7.3 Advection-diffusion equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

8 The shallow water equations 578.1 One-dimensional gravity waves with centred space differencing . . . . . . . . . . . . . 57

8.2 Two-dimensional gravity waves with centred space differencing . . . . . . . . . . . . . 59

8.3 The linearised shallow water equations without friction . . . . . . . . . . . . . . . . . . 62

8.4 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

8.4.1 Closed boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

8.4.2 Open boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

8.4.3 Cyclic boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

8.5 Conservation of mass, energy and enstrophy . . . . . . . . . . . . . . . . . . . . . . . . 68

8.5.1 The shallow water equations with non-linear advection terms . . . . . . . . . . . 68

8.5.2 Discretisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

9 Implicit and semi-implicit schemes 739.1 Implicit versus explicit schemes, simple example . . . . . . . . . . . . . . . . . . . . . 73

9.2 Semi-implicit scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

9.2.1 Crank-Nicolson method with 1D difusion equation . . . . . . . . . . . . . . . . 74

9.2.2 2D pure gravity waves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

9.3 The semi-implicit method of Kwizak and Robert . . . . . . . . . . . . . . . . . . . . . 76

10 The semi-Lagrangian technique 7910.1 1-D Passive advection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

10.2 Interpolation and Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

11 Poisson and Laplace equations (elliptic) 8311.1 Jacobi iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

11.2 Gauss-Seidel iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

11.3 Successive Over Relaxation (SOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

12 Model Coordinates 8712.1 Vertical ocean coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

12.1.1 Fixed height or depth coordinates . . . . . . . . . . . . . . . . . . . . . . . . . 87

12.2 Atmospheric vertical coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

12.2.1 Pressure coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

12.2.2 Atmospheric sigma coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . 91

12.2.3 Hybrid coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

12.3 Horizontal coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

12.3.1 Finite differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Page 5: Numerical Methods

CONTENTS 5

12.3.2 Finite elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

13 3D modelling 9713.1 The Equations of motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

13.2 The tracer Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

13.3 Discretised on a cartesian grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

13.4 Discretised on an orthogonal curvilinear grid . . . . . . . . . . . . . . . . . . . . . . . 103

14 Spherical Harmonics 10514.1 Spectral methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

14.2 Spherical harmonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

14.3 The spectral transform method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

14.4 Application to the shallow water equations on a sphere . . . . . . . . . . . . . . . . . . 109

15 Practical computer exercises 11115.1 Exercise 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

15.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

15.3 Technical aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

15.4 Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

15.5 Theoretical exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

15.6 Experimental exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

15.7 1D Shallow water model exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

15.8 2D Shallow water model exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

A Exams at Stockholm University 127

Page 6: Numerical Methods

6 CONTENTS

Page 7: Numerical Methods

Preface

The purpose of this compendium is to give an introduction and an overview of numerical modelling

of the ocean and the atmosphere. Numerical schemes for the most common equation in oceanography

and meteorology are described. For simplicity the equations will often be referred as the hydrodynamic

equations since the numerical methods described in this compendium are valid for both modelling of the

ocean and the atmosphere. Due to the non-linearities of the hydrodynamic equations, it is not possible

to find analytical solutions. This is the main reason to make numerical approximations of the equations

and solve them numerically by constructing numerical circulation models. These models are often called

as general circulation models when they are the 3D global circulation of the atmosphere or the ocean

and are based on the NavierÐStokes equations (Coriolis effect included) with thermodynamic terms for

various energy sources (radiation, latent heat) and salt tracer equation for the ocean. An atmospheric and

an ocean general circulation model coupled together is the core part of a climate model of the Earth.

Kristofer Döös, professor of climate modelling at the Department of Meteorology, Stockholm Univer-

sity

7

Page 8: Numerical Methods

8 CONTENTS

Page 9: Numerical Methods

Chapter 1

Introduction

A numerical model of circulation of the atmosphere or the ocean is basically composed of three things:

a) A grid in space

b) Equations describing conservation of mass, heat, salt and momentum

c) Open boundaries

9

Page 10: Numerical Methods

10 CHAPTER 1. INTRODUCTION

Conservation of:-mass-heat-salt-momentum

modelgrid cell

Wind stress

Precipitation

Evaporation

Heat exchage

Clouds

River run-off

Topography

Solar radiation

Terrestialradiation

Figure 1.1: Schematic illustration of a numerical ocean-atmosphere circulation model

Page 11: Numerical Methods

Chapter 2

Partial Differential Equations (PDE)

Before going into the numerics let us first classify the most usual types of PDE that occur in meteorology

and oceanography. Partial differential equations are of vast importance in applied mathematics and

engineeringsince so many real physical situations can be modelled by them. Second order linear PDEs

can be classified into three categories - hyperbolic, parabolic and elliptic. These partial differential

equations are the general linear homogeneous equations of the second order:

a∂2u

∂x2+ b

∂2u

∂x∂y+ c

∂2u

∂y2+ d

∂u

∂x+ e

∂u

∂y+ fu+ g = 0 (2.1)

Equation (2.1) resembles the equation for a conic section

ax2 + bxy + cy2 + dx+ ey + f = 0 (2.2)

where a, b, c, d, e, f are constants, Equation (2.2) represents an ellipse, parabola or a hyperbola according

to b2 − 4ac <,= or > 0.

Thus one can classify the PDE according to Table 2.1.

These types of systems give rise to significantly different characteristic behaviour and, the solution

scheme for each method can also differ. The three classes of PDEs require the specification of different

kinds of boundary conditions. All three classes are represented among the most common equations in

hydrodynamics.

We will now give examples of these equations.

Table 2.1: Classification of the three PDEs and their different kinds of boundary conditions

PDE b2 − 4ac Boundary conditions1. elliptic b2 − 4ac < 0 Dirichlet/Neumann/Robin

2. parabolic b2 − 4ac = 0 One initial+some boundary condition3. hyperbolic b2 − 4ac > 0 Cauchy+some boundary condition

11

Page 12: Numerical Methods

12 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS (PDE)

Figure 2.1: A diagram of conic sections, including a circle, an ellipse, a parabola and ahyperbola. Note that these geometrical representations of Equation (2.2) are not solutionsto the PDE Equation (2.1).

2.1 Elliptic

Laplace’s or Poisson’s equations. Examples: steady state temperature of a plate, stream function/ vortic-

ity relationship.

∂2u

∂x2+∂2u

∂y2= 0 (or f (x, y))

From Eq. (2.1), we get a = 1, b = 0 and c = 1 which leads to that b2 − 4ac = −4 < 0 and hence the

PDE must be elliptic.

Helmholtz’s equations. Many problems related to steady-state oscillations (mechanical, acoustical,

thermal, electromagnetic) lead to the two-dimensional Helmholtz equation. For f < 0, this equation

describes mass transfer processes with volume chemical reactions of the first order.

∂2u

∂x2+∂2u

∂y2+ λ2u = 0

Schrödinger’s equation describes the space- and time-dependence of quantum mechanical systems:

∂2u

∂x2+∂2u

∂y2+ k(E − V )u = 0

Another example of an elliptic equation can be found from the simplest equation of motion in the

atmosphere and the ocean. The linearised shallow water equations without friction. Note that the in-

Page 13: Numerical Methods

2.2. PARABOLIC 13

dependent variables x and y in 2.1 do not have anything with x and y in the equations below and must

therefore be replaced in order to calculate b2 − 4ac.

∂u

∂t− fv = −g∂h

∂x(2.3)

∂v

∂t+ fu = −g∂h

∂y(2.4)

∂h

∂t+H

(∂u

∂x+∂v

∂y

)= 0 (2.5)

From (2.3, 2.4,2.5 we can deduce

∂t

[∂2

∂t2+ f2 − gH

(∂2

∂x2+

∂2

∂y2

)]h = 0

If we integrate this in time we get

∂2h

∂t2+ f2h− gH

(∂2

∂x2+

∂2

∂y2

)h = ξ (x, y)

If the problem is time independent then we get the geostrophic relationship

f2h− gH(∂2

∂x2+

∂2

∂y2

)h = ξ (x, y)

From Eq. (2.1), we get a = −gH , b = 0 and c = −gH which leads to that b2−4ac = −4g2H2 < 0

and hence the PDE must be elliptic.

There are three different types of possible boundary conditions for this class:

a) u to be specified on the boundary (Dirichlet).

b) ∂u∂n to be specified on the boundary (Neumann)

c) au+ ∂u∂x to be specified on the boundary (Cauchy)

2.2 Parabolic

Diffusion equation. Example: temperature, salinity, passive tracers.

∂T

∂t= K

∂2T

∂x2where K > 0

From Eq. (2.1), we get a = K, b = 0 and c = 0 which leads to that b2 − 4ac = 0 and hence the PDE

must be parabolic.

T (x, t) is the temperature distribution along the x-axis as a function of time. To solve the equation

in the interval 0 ≤ x ≤ L one must specify an initial condition T (x, 0) on 0 ≤ x ≤ L and the boundary

conditions T (0, t)andT (L, t) must be specified during the whole time period.

Page 14: Numerical Methods

14 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS (PDE)

2.3 Hyperbolic

Wave equation. Examples: vibrating string, ocean and atmospheric gravity waves.

∂2u

∂t2= c0

2∂2u

∂x2

The first order PDE (advection equation) can also be classified as a hyperbolic, since its solutions

satisfy the wave equation.

∂u

∂t= −c0

∂u

∂x

By derivating the advection equation first with respect to t and then with respect to to x, ( ∂∂t − c0∂∂x)

it is possible to eliminate utxbetween the two equations and we obtain the wave equation.

From Eq. (2.1) we get b2 − 4ac = 4c20 > 0 i.e. hyperbolic. In order to obtain unique solutions for

0 ≤ x ≤ L we need two initial conditions and boundary conditions in both ends of u . E.g.

• u (x, 0) specified initially on 0 ≤ x ≤ L

• ∂(x,0)∂t specified initially on 0 ≤ x ≤ L

• u (0, t) specified on the boundary x = 0

• ∂(L,t)∂x free or open boundary on x = L

The behaviour of the solutions, the proper initial and/or boundary conditions, and the numerical methods

that can be used to find the solutions depend essentially on the type of PDE that we are dealing with.

Although non-linear multidimensional PDEs cannot in general be reduced to these canonical forms, we

need to study these prototypes of the PDEs to develop an understanding of their properties, and then

apply similar methods to the more complicated equations.

Exercises:

a) Solve the following equation by separation of variables:

∂u

∂t= −c∂u

∂x

with the initial condition

u (x, 0) = −Aeikx

b) a) Show that the advection equation∂u

∂t= −c∂u

∂x

has the general solution

u = f(x− ct)

Page 15: Numerical Methods

2.3. HYPERBOLIC 15

where f is an arbitrary solution.

b) Interpret the equation geometrically in the xt-plane.

c) Solve the equation with the following initial condition: u (x, 0) = g(x).

c) Derive the wave equation from the system

∂V

∂t= −g∇h

∂h

∂t= −H∇ (hV )

where g and H are constants.

Page 16: Numerical Methods

16 CHAPTER 2. PARTIAL DIFFERENTIAL EQUATIONS (PDE)

Page 17: Numerical Methods

Chapter 3

Finite differences

3.1 The grid point method

Let us study a function with one independent variable.

u = u (x)

Suppose we have an interval L which is covered with N + 1 equally spaced grid points. The grid length

is then ∆x = L/N and the grid points are at xj = j∆x where j = 0, 1, 2, ...N are integers. Let the

value of u at xj be represented by uj .

3.2 Finite difference schemes

We are now going to derive expressions which can be used to give an approximate value of a derivative

at a grid point in terms of grid-point values. The finite differences can be constructed between values of

uj over the grid length ∆x. The first derivative of u (x) can be approximated with

• forward difference:(dudx

)j→ uj+1−uj

∆x

• centred difference:(dudx

)j→ uj+1−uj−1

2∆x

• backward difference:(dudx

)j→ uj−uj−1

∆x

The is the same as the formal mathematical definition of a derivative of the function u(x)

du

dx= lim

∆x→0

u (x+ ∆x)− u (x)

∆x

with the difference that ∆x does not tend to zero.

This difference introduces an error that one can estimate by deriving the finite differences in a more

rigourous way by using a Taylor expansion. The Taylor series for f (y) about y = a is

f (y) = f (a) + (y − a) f ′ (a) +1

2(y − a) 2f ′′ (a) + ...+

1

n!(y − a)n f (n) (a)

17

Page 18: Numerical Methods

18 CHAPTER 3. FINITE DIFFERENCES

x

secant line

f(x)

f(x+h)

x+h

Figure 3.1: The purple secant line becomes the derivative of f at the point x when h→ 0.

Substituting f(y) by u(x), a by xj and y by xj+1, we obtain the Taylor expansion of the function u (x)

in the point j + 1.

uj+1 = uj+∆x

(du

dx

)j

+1

2(∆x) 2

(d2u

dx2

)j

+1

6(∆x) 3

(d3u

dx3

)j

+1

24(∆x)4

(d4u

dx4

)j

+1

120(∆x)5

(d5u

dx5

)j

+...

(3.1)

The forward difference can now be expressed as

uj+1 − uj∆x

=

(du

dx

)j

+1

2(∆x)

(d2u

dx2

)j

+1

6(∆x) 2

(d3u

dx3

)j

+1

24(∆x)3

(d4u

dx4

)j

+1

120(∆x)4

(d5u

dx5

)j

+...

(3.2)

The difference between this expression and the approximated derivative(dudx

)j

is

ε =1

2(∆x)

(d2u

dx2

)j

+1

6(∆x) 2

(d3u

dx3

)j

+1

24(∆x)3

(d4u

dx4

)j

+1

120(∆x)4

(d5u

dx5

)j

+ ...

Page 19: Numerical Methods

3.2. FINITE DIFFERENCE SCHEMES 19

u

xj∆x (j+1)∆x(j-1)∆x∆x

ujuj-1uj+1

centred

forwardbackwa

rdreal

Figure 3.2: The backward, forward and centred finite differences of a function u (x), definedin the grid points x = j∆x so that uj = uj (j∆x), where ∆x is the grid length andj = 0, 1, 2, ... are integers.

which is called the truncation error of the derivative approximation. These are the terms that have been

truncated (erased). Hence we have an accuracy of the first order with

ε = O (∆x)

which is the lowest order of accuracy that is acceptable.

The accuracy of the centred difference can be obtained from 3.1 and a Taylor expansion in x of the

function u (x) at the point j − 1

uj−1 = uj−∆x

(du

dx

)j

+1

2(∆x) 2

(d2u

dx2

)j

−1

6(∆x) 3

(d3u

dx3

)j

+1

24(∆x)4

(d4u

dx4

)j

− 1

120(∆x)5

(d5u

dx5

)j

+...

(3.3)

so that

uj+1 − uj−1

2∆x→(du

dx

)j

+1

6(∆x) 2

(d3u

dx3

)j

+1

120(∆x)4

(d5u

dx5

)j

+ ...

The truncation error is of the second order:

ε =1

6(∆x) 2

(d3u

dx3

)j

+ ... = O((∆x) 2

)A scheme with fourth order accuracy can be obtained if we do a Taylor expansion for uj+2:

uj+2 = uj+2∆x

(du

dx

)j

+1

2(2∆x) 2

(d2u

dx2

)j

+1

6(2∆x) 3

(d3u

dx3

)j

+1

24(2∆x)4

(d4u

dx4

)j

+1

120(2∆x)5

(d5u

dx5

)j

+...

Page 20: Numerical Methods

20 CHAPTER 3. FINITE DIFFERENCES

and

uj−2 = uj−2∆x

(du

dx

)j

+1

2(2∆x) 2

(d2u

dx2

)j

−1

6(2∆x) 3

(d3u

dx3

)j

+1

24(2∆x)4

(d4u

dx4

)j

− 1

120(2∆x)5

(d5u

dx5

)j

+...

so thatuj+2 − uj−2

4∆x→(du

dx

)+

4

6(∆x) 2

(d3u

dx3

)j

+16

120(∆x)4

(d5u

dx5

)j

+ ...

This scheme is as the previous centred scheme accurate at the second order but if we combine the two

centred schemes so that

4

3

uj+1 − uj−1

2∆x− 1

3

uj+2 − uj−2

4∆x→(du

dx

)− 1

30(∆x)4

(d5u

dx5

)j

+ ... (3.4)

we get an accuracy of the fourth order i.e. ε = O(

(∆x)4)

.

3.3 Finite time differences

The time schemes that are used for the PDEs are relatively simple, usually of the second and sometimes

even only of the first order of accuracy. There are several reasons for this. First, it is a general experience

that schemes constructed so as to have a high order of accuracy are mostly not very successful when

solving PDEs. This is in contrast to the experience with ordinary differential equations, where very

accurate schemes, such as the Runge-Kutta method, are extremely rewarding. There is a basic reason

for this difference. With an ordinary differential equation, the equation and a single initial condition is

all that is required for an exact solution. Thus, the error of the numerical solution is entirely due the

inadequacy of the scheme. With a PDE , the error of the numerical solution is brought about both by

the inadequacy of the scheme and by insufficient information about the initial conditions, since they are

known only at discrete space points. Thus, an increase in accuracy of the scheme improves only one of

these two components, and the result is not too impressive.

Another reason for not requiring a scheme of high accuracy for approximations to the time derivative

terms is that, in order to meet a stability requirement of the type discussed in the next chapter, it is usually

necessary to choose a time step significantly smaller than that required for adequate accuracy. With the

time step usually chosen, other errors, for example in the space differencing, are much greater that those

due to the time differencing. Thus, computation effort is better spent in reducing these errors, and not in

increasing the accuracy of the time differencing schemes. This, of course, does not mean that it is not

necessary to consider carefully the properties of various possible time differencing schemes. Accuracy,

is only one important consideration in choosing a scheme.

To define some schemes, we consider the equation:

du

dt= f (u, t) where u = u (t)

The independent variable t is the time. f is a function of u and t, e.g. the advection equation where

Page 21: Numerical Methods

3.3. FINITE TIME DIFFERENCES 21

f = −c∂u∂xIn order to discretise the equation we will divide the time axis into segments of equal length ∆t. The

approximated value of u (t) at time t = n∆t is un. In order to compute un+1 we need to know at least

un and often also un−1. There are many different time schemes.

3.3.1 Two-level-schemes

These are schemes that use two different time levels: n and n+ 1 and that the time integration becomes

un+1 = un +

∫ (n+1)∆t

n∆tf (u, t) dt

The problem now is that f only exists as discrete values fn and fn+1.

Euler or forward scheme

un+1 = un + ∆t fn

The truncation error of this scheme isO (∆t), i.e. a first order accurate scheme. The scheme is said to be

uncentred since the time derivative is at time level n + 1/2 and the function at time level n. In general,

uncentred schemes are accurate to the first order and centred to the second order.

Backward scheme

un+1 = un + ∆t fn+1

The backward scheme is uncentred in time and of O (∆t). If, as here, a value of f is taken at time level

n+1 and that f depends of u, i.e. un+1then the scheme is said to be implicit. For an ordinary differential

equation, it may be simple to solve for un+1.

But for a PDE it will require solving a set of simultaneous equations, with one equation for each of

the grid points of the computation region. If no value of f depends of un+1 on the right hand side the

scheme is said to be explicit.

In the very simple cases when f only depends on t such as e.g. du/dt = −γu then the discretised

equation becomes un+1 = un + ∆t (−γun+1), which can be rearranged to un+1 = un/(1 + γ∆t) so

that all there are no terms of n + 1 on the right hand side and the discretised equation can be easily

integrated despite that it is still implicit.

Trapezoidal scheme

If we approximate f by an average between time level n+ 1 and n we obtain the trapezoidal scheme

un+1 = un +1

2∆t(fn + fn+1

)This scheme is also implicit , its truncation error is however O

((∆t) 2

).

Page 22: Numerical Methods

22 CHAPTER 3. FINITE DIFFERENCES

Matsuno or Euler-backward scheme

To increase the accuracy we can construct iterative schemes such as the Matsuno scheme that first uses

an Euler forward time step.

un+1 ∗ = un + ∆t fn

Then the value of the obtained un+1 is used for an approximation of fn+1, which is then used to

make a backward step to obtain a final un+1.

un+1 = un + ∆t fn+1 ∗

This scheme is explicit and of O (∆t).

3.3.2 Three-level-schemes

These schemes use the the time at three levels and the time integration becomes

un+1 = un−1 +

∫ (n+1)∆t

(n−1)∆tf (u, t) dt

The simplest three level scheme is to take for f a constant value equal to that at the middle of the interval

2∆t. This gives the leapfrog scheme :

un+1 = un−1 + 2∆t fn

which is of O((∆t) 2

). This is the most widely used scheme in atmospheric and ocean models.

Exercises:

a) Determine the order of accuracy of the leapfrog scheme,

un+1j − un−1

j

2∆t+ c

unj+1 − unj−1

2∆x= 0

for the advection equation∂u

∂t+ c

∂u

∂x= 0

b) Determine the order of accuracy of the Euler forward scheme for the heat equation:

∂u

∂t= A

∂2u

∂x2where A > 0

un+1j − unj

∆t= A

unj+1 − 2unj + unj−1

(∆x)2

Page 23: Numerical Methods

Chapter 4

Numerical stability of the advectionequation (hyperbolic)

In this chapter we will study differential equations with one dependent variable and two independent

variables, that is PDE. More specifically we shall consider various simplified forms of the advection

equation, describing advection of a dependent variable. This is considered in practice to be the most

important part of the hydrodynamic equations for the ocean and the atmosphere.

We will use the advection equation, which is one of the dominating hyperbolic equations in geophys-

ical hydrodynamics, to investigate what is required of the numerical schemes to be give stable solutions

to the PDE, i.e. so that the small perturbations do not grow in time.

4.1 The advection equation with leap-frog-scheme, i.e. O [(∆x)] 2

∂u

∂t+ c

∂u

∂x= 0

where u = u (x, t) and c is phase speed. Analytical solutions are of the form u(x, t) = u0eik(x−ct) with

c ≡ ω/k.

Let us now consider one among many possible discretisations of the advection equation using a

centred difference both in time (leap frog) and in space so that

un+1j − un−1

j

2∆t+ c

unj+1 − unj−1

2∆x= 0 (4.1)

In a model we need to rewrite this so that

un+1j = un−1

j − c∆t

∆x

(unj+1 − unj−1

)(4.2)

Note that all the grid points for the leap-frog scheme, which are shown by the green dots in Figure 4.1,

are located around the "here and now" point j, n shown as the black dot in the same figure.

We also need initial and boundary conditions in order to integrate Eq. 4.2 forward in time on a grid

such as the one in Figure 4.1. The initial condition is that all the u0j values (red dots in Figure 4.1) have

tp be set, i.e. the variable u has to have values at the time step n = 0. The boundary conditions imply

23

Page 24: Numerical Methods

24 CHAPTER 4. NUMERICAL STABILITY OF THE ADVECTION EQUATION (HYPERBOLIC)

that values for all the un0 and unJ (blue dots in Figure 4.1) have to be prescribed, i.e. the variable u has to

have values at all time steps on the two walls located at j = 0 and j = J , where J is the total number of

grid cells. Furthermore we need to be able to integrate a first time step, which will not be possible to do

with a three level time scheme. We therefore use first an Euler Forward time step and then continue with

the leap-frog scheme for the rest of the integration.

xj j+1j-1

∆x

nn-1

n+1

∆t

00

1 J

1

Nt

Figure 4.1: A finite difference grid in time and space. The grid points used by the leap-frogscheme are shown in green . The red points are the necessary initial condition points andthe blue points illustrate here two boundaries of the domain, which have to be prescribed.

4.2 Stability of the the advection equation with leap-frog-scheme

In order to study the stability we will use the so called von Neumann method, which is generally not

possible to use on non linear equations and one is therefore limited to study the linearised version of

the equations in a numerical model. A solution to a linear equation can be expressed as a Fourier series

where each Fourier component is a solution. Thus, we can test the stability with one single Fourier

component of the form

unj = u0eik(j∆x−CDn∆t)

Note that the phase speed CD, has an index D for finite difference, which is an approximation of the

phase speed c of the differential equation. It is this CD that has been obtained as a solution to 4.1, and

which will here be investigated. We observe that

Page 25: Numerical Methods

4.2. STABILITY OF THE THE ADVECTION EQUATION WITH LEAP-FROG-SCHEME 25

Figure 4.2: The Courant-Fredrichs-Lewy (CFL) stability criterion for centred schemes intime and space.

un+1j = u0e

ik[j∆x−CD(n+1)∆t] = unj e−ikCD∆t = unj λ where λ ≡ e−ikCD∆t

we can in the same way write for n− 1:

un−1j = unj λ

−1

that can be generalised as

un+mj = unj λ

m

and

unj = λnu0eikj∆x

From this we can deduce that if |u| is not going to “blow up” when integrating in time then one needs to

require that

|λ| =∣∣∣e−ikCD∆t

∣∣∣ ≤ 1 (4.3)

and reversely if |λ| > 1 then it is unstable and it “blows up”. For that the condition 4.3 is fulfilled then

CD has to be real. This method based on studying the amplification factor λ is called the von Neumann

method.

Page 26: Numerical Methods

26 CHAPTER 4. NUMERICAL STABILITY OF THE ADVECTION EQUATION (HYPERBOLIC)

amplitude

j

0.1.2.3.4.5.6.7.8.9

1.0

0 10 20 30 40 50 60 70 80 90 100

Figure 4.3: The advection equation integrated numerically with leap-frog and centredscheme in space 4.1. The first time step has been integrated with an Euler (forward) scheme.The initial value is un=0

j = cos(π20j)

for −10 ≤ j ≤ 10 and un=0j = 0 for the rest. The

CFL-number is CFL ≡ c∆t∆x = 1. Curves are plotted for the time steps n=0, 5, 10, 15, 20.

We also need to have an expression for the Fourier component for the spatial derivative:

unj+1 = u0eik[(j+1)∆x−CDn∆t] = eik∆xunj

and

unj−1 = u0eik[(j−1)∆x−CDn∆t] = e−ik∆xunj

Let us now return to 4.1 and use λ so that

λ2 + 2ic∆t

∆xsin (k∆x)λ− 1 = 0 (4.4)

Since eiα − e−iα = 2i sinα and x2+αx+ β = 0 ⇒ x = −α/2±√α2/4− β

The quadratic Equation 4.4 has the solution:

λ = −ic∆t∆x

sin (k∆x)±

√1−

(c∆t

∆xsin (k∆x)

)2

Reminder: the absolute value of the complex number: a+ ib is√a2 + b2

Page 27: Numerical Methods

4.2. STABILITY OF THE THE ADVECTION EQUATION WITH LEAP-FROG-SCHEME 27

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

Figure 4.4: The advection equation integrated numerically with leap-frog and centredscheme in space 4.1. The first time step has been integrated with an Euler (forward) scheme.The initial value is un=0

j = cos(π20j)

for −10 ≤ j ≤ 10 and un=0j = 0 for the rest. The

CFL-number is CFL ≡ c∆t∆x = 1 at the top panel, which gives a stable nice solution but the

solution "blows up" with CFL = 1.1 in the bottom panel. Note also that cyclic boundaryconditions have been applied.

Page 28: Numerical Methods

28 CHAPTER 4. NUMERICAL STABILITY OF THE ADVECTION EQUATION (HYPERBOLIC)

If [c∆t

∆xsin (k∆x)

]2

≤ 1 (4.5)

then

|λ|2 =

[c∆t

∆xsin (k∆x)

]2

+

1−[c∆t

∆xsin (k∆x)

]2

2

= 1

i.e. this scheme is stable if 4.5 is true and can also be written as

c∆t

∆x|sin (k∆x)| ≤ 1

and since |sin (k∆x)| ≤ 1 we have granted stability if

c ≤ ∆x

∆t(4.6)

It can be similarly shown that when on the other side c > ∆x∆t then |λ| > 1 and the solution is therefore

unstable. The Leap-frog is thus conditionally stable with the so called Courant-Fredrichs-Lewy or CFL

criterion. For a given spatial resolution (∆x) we need a time step (∆t) not exceeding ∆xc so that 4.6

is valid for the fastest possible phase speed in the system. In the ocean this is set by the deepest depth

HMAX and the speed for long gravity waves so that for a chosen resolution ∆x we get ∆t = ∆xc =

∆x√gHMAX

.

4.3 The advection equation with Euler (forward) scheme in time and centred scheme inspace

Let us now use another numerical scheme for the advection equation so that instead of 4.1 we have

un+1j − unj

∆t+ c

unj+1 − unj−1

2∆x= 0 (4.7)

Now we get

λ = 1− ic∆t∆x

sin (k∆x)

As before the criterion is that |λ| ≤ 1for stability and the absolute value of λ is now

|λ|2 = 1 +

[c∆t

∆xsin (k∆x)

]2

which is always |λ| > 1. Thus, the solution grows with time independently of how we choose the time

step. This scheme is unconditionally unstable.

Page 29: Numerical Methods

4.4. THE UPSTREAM OR UPWIND SCHEME 29

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

Figure 4.5: The advection equation integrated with Euler forward and a centred scheme inspace. The CFL-number is CFL ≡ c∆t

∆x = 0.5.

4.4 The upstream or upwind scheme

Let us now use a third numerical scheme for the advection equation

un+1j − unj

∆t+ c

unj − unj−1

∆x= 0 if c > 0 (4.8)

un+1j − unj

∆t+ c

unj+1 − unj∆x

= 0 if c < 0

The scheme is called upstream or upwind since it looks for information from where the wind or stream

is coming in point j − 1. If c > 0 then one should use a backward scheme in space in order to have an

upstream scheme.

The von Neumann stability analysis gives us

Page 30: Numerical Methods

30 CHAPTER 4. NUMERICAL STABILITY OF THE ADVECTION EQUATION (HYPERBOLIC)

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

Figure 4.6: The advection Equation integrated numerically with the upstream scheme(Equation 4.8). Stable solution in the top panel where CFL ≡ c∆t

∆x = 1 , but unstablein the bottom panel when CFL = −1, where a downstream scheme should instead be used.

Page 31: Numerical Methods

4.5. THE ADVECTION EQUATION WITH AN O[(∆X)4

]SCHEME 31

λ = 1− c∆t

∆x[1− cos (k∆x) + i sin (k∆x)]

and

|λ|2 =

1− c∆t

∆x[1− cos (k∆x)]

2

+

[c∆t

∆xsin (k∆x)

]2

= 1 + 2c∆t

∆x[1− cos (k∆x)]

(c∆t

∆x− 1

)For |λ|2 < 1 then we must have 0 ≤ c∆t

∆x ≤ 1 which implies that c has to be positive to have stability.

The scheme is hence conditionally stable. The criterion is otherwise similar to the one for the Leap frog

scheme.

The upwind advection scheme was used in early numerical weather models due to its good stability

properties, and it still finds use in idealised ocean box models as well as some general circulation mod-

els. When using upwind, however, one should realise that it is highly diffusive. The upwind scheme

uses backward space differences if the velocity is in the positive x direction, and forward space differ-

ences for negative velocities. The name upwind denotes the use of upwind, or upstream, information in

determining the form for the finite difference; downstream information is ignored.

4.5 The advection equation with an O[(∆x)4]scheme

Let us now study one final scheme of advection scheme which uses the forth order accurate spatial

scheme 3.4.

un+1j − un−1

j

2∆t+ c

(4

3

unj+1 − unj−1

2∆x− 1

3

unj+2 − unj−2

4∆x

)= 0 (4.9)

The von Neumann method gives

λ2 + ic∆t

3∆x[8 sin (k∆x)− sin (2k∆x)]λ− 1 = 0

which has the solution

λ = −i c∆t6∆x

[8 sin (k∆x)− sin (2k∆x)]±

√1−

[c∆t

6∆x[8 sin (k∆x)− sin (2k∆x)]

]2

If

[c∆t

6∆x[8 sin (k∆x)− sin (2k∆x)]

]2

< 1 (4.10)

then

Page 32: Numerical Methods

32 CHAPTER 4. NUMERICAL STABILITY OF THE ADVECTION EQUATION (HYPERBOLIC)

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.

80.

75.

70.

65.

60.

55.

50.

45.

40.

35.

30.

25.

20.

15.

10.

5.

0.0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.

Figure 4.7: The advection equation integrated with the 4th order spatial numerical scheme4.9. Stable solution in the top panel where CFL ≡ c∆t

∆x = 0.72 , but unstable in the bottompanel when CFL = 0.74.

Page 33: Numerical Methods

4.5. THE ADVECTION EQUATION WITH AN O[(∆X)4

]SCHEME 33

|λ|2 =

[c∆t

6∆x[8 sin (k∆x)− sin (2k∆x)]

]2

+

1−[c∆t

6∆x[8 sin (k∆x)− sin (2k∆x)]

]2

2

= 1

i.e. this scheme is stable if 4.10 is fulfilled which can also be expressed as∣∣∣∣ c∆t6∆x[8 sin (k∆x)− sin (2k∆x)]

∣∣∣∣ < 1

or

c∆t

∆x<

6

8 sin (k∆x)− sin (2k∆x)

which has a minimum for k∆x ≈ 1 so that the scheme is stable when c∆t∆x < 0.73

Page 34: Numerical Methods

34 CHAPTER 4. NUMERICAL STABILITY OF THE ADVECTION EQUATION (HYPERBOLIC)

Exercises:

a) Consider the leapfrog scheme for the advection equation,

un+1j − un−1

j

2∆t+ c

unj+1 − unj−1

2∆x= 0

Use

unj = λnu0eikj∆x

and show that the amplification factor is

λ = −ic∆t∆x

sin (k∆x)±

√1−

(c∆t

∆xsin (k∆x)

)2

b) Show that for c∆t∆x > 1 in the previous exercise, we will have one of the solutions to the differential

equation superior to one for at least some wave lengths, i.e. that the solution “blows up” .

c) Discretise the advection equation with Euler forward in both time and space. Show that for c > 0

(down stream scheme), the amplitude of the solutions will grow in time (unstable). But for c < 0

(up stream scheme) the amplitude will decrease in time, i.e. stable.

d) Make a stability analysis of the following discretisation of the advection equation

un+1j − 1

2

(unj+1 + unj−1

)∆t

+ cunj+1 − unj−1

2∆x= 0

Page 35: Numerical Methods

Chapter 5

The numerical mode

We shall in this chapter study some of the consequences of that the partial differential equations have

been approximated with finite differences.

5.1 The numerical mode of the three level schemes

One problem with three level scheme such as the leap-frog-scheme is that they require more than one

initial condition to start the numerical integration. From a physical standpoint a single initial condition

for un=0 should have been sufficient. However in addition to the physical initial condition, three level

schemes require a computational initial condition for un=1. This value cannot be calculated by a three

level scheme, and, therefore, it will usually have to be obtained using two level schemes.

Consider the oscillation equation:

du

dt= iωu where u = u (t)

which has the solution

u = u0eiωt

The leap-frog scheme can be written as

un+1 = un−1 + 2iω∆tun (5.1)

If we now study the amplification roots like in the previous chapter we get

λ2 − 2iω∆tλ− 1 = 0

which has the solution

λ1,2 = iω∆t±√

1− (ω∆t)2

Thus there are two solutions of the form un+1 = λun.

Since we are solving a linear equation its solution will be a linear combination of the two solutions

35

Page 36: Numerical Methods

36 CHAPTER 5. THE NUMERICAL MODE

un1 = λn1u01 and un2 = λn2u

02

so that

un = aλn1u01 + bλn2u

02

where a and b are constants. If un+1 = λun should represent the approximation of the true solution then

λ → 1 when ∆t → 0 .λ1 does this but λ2 → −1. λ1 is called the physical mode and λ2 is called the

computational mode, which has been introduced by the numerical scheme . This computational mode

changes sign for each even and odd n.

A simple way to illustrate the computational mode is to study the simple case when ω = 0 so that

du

dt= 0

which has the true solution

u(t) = const

The Leap-frog scheme gives

un+1 = un−1

For a given physical initial condition un=0, we consider two special choices of un=1

a) Suppose calculating of un=1 happened to give the true value un=0 then we get for all n

un+1 = un (5.2)

or

un+1 = λ1un

in this case we have obtained a numerical solution that is equal to the true solution and consists of

the physical mode only.

b) Suppose now instead that when calculating un=1 we obtain un=1 = −un=0. Then we obtain for

all n

un+1 = −un (5.3)

or

un+1 = λ2un

The numerical solution now consists entirely of the computational mode.

Page 37: Numerical Methods

5.2. SUPPRESSION OF THE COMPUTATIONAL MODE 37

n

1

!t

u

-1

01 765432

Figure 5.1: The physical mode in blue from Equation 5.2 and the numerical (or computa-tional) mode in red from Equation 5.3. The initial physical condition is set to un=0 = 1 andthe computation initial condition is set to un=1 = 1 in order to generate a constant physicalmode and to un=1 = −1 in order to illustrate a computational mode that changes sign atevery time step.

5.1.1 The computational initial condition

A good choice of the computational initial condition is of vital importance for obtaining a satisfactory

numerical solution for short simulations, where the initial condition is crucial which is the case for

weather forecast predictions but less for long climate simulations. The computational initial condition

(un=1), which is one ∆t ahead of the physical condition (un=0) can be computed with a single Euler

forward time step. Although this scheme is computationally unstable it can be used in a single time step

since it requires many time steps before the solution grows and "blows up".

The computational initial condition for our academic case of the oscillation equation is then with an

Euler forward time step:

un=1 = un=0 + iω∆tun=0 (5.4)

An alternative computational initial condition, when the solution is not so sensitive to the initial

condition is just simply to set the same values to both time steps (un=1 = un=0) but as shown above this

can trigger emediatly a computational mode.

5.2 Suppression of the computational mode

The computational mode which is introduced by the leap frog scheme can be suppressed in two different

ways.

5.2.1 Euler forward or backward at regular intervals

The problem can be solved by integrating with an Euler forward or backward at regular intervals of a

certain number of time steps (50 time steps or so is often used). This would imply that in the example of

Page 38: Numerical Methods

38 CHAPTER 5. THE NUMERICAL MODE

the previous paragraph that un+1 = un every 50 time steps, which eliminate the computational mode so

that a = 1 and b = 0.

5.2.2 Robert-Asselin filter

Another way, which is the most common way in atmospheric models, is to use a Robert-Asselin filter

(Robert,1966; Asselin,1972). First one applies the leap frog integration to obtain the solution at time

level n+ 1:

un+1 = un−1f + 2∆t F (un)

then the filter is applied as a time smoothing between the time levels n− 1, n and n+ 1 so that

unf = un + γ(un−1f − 2un + un+1

)(5.5)

where the index f indicates the smoothed values and γ is the Asselin coefficient, which is usually chosen

to be between 0.01 and 0.2. The next frog jump will be

un+2 = unf + 2∆t F(un+1

)Note that the added term is like smoothing in time, an approximation of an ideally time-centred smoother

is

unf = un + γ(un−1 − 2un + un+1

)(5.6)

In our particular case of the discretised oscillation Equation 5.4 we can estimated the damping effect of

the Robert-Asselin filter by introducing its discretised solution un = u0eiωn∆t into the smoother (Eq.

5.6) with the exception that un−1 is taken as an unfiltered value. This results in

unf = un[1− 4γsin2 (ω∆t/2)

](5.7)

The computational mode, whose period is 2∆t is hence reduced by (1 − 4γ) every time step. Because

the field at n − 1 is replaced by an already filtered value, the Rober-Asselin filter introduces a slight

different compared to this simplified filter.

5.2.3 The Robert-Asselin-Williams filter

Williams (2009) showed that, when used with the leapfrog scheme, it is this nonmean-conserving feature

of the Robert-Asselin filter that degrades the numerical accuracy. In the same work, the author tackled

this problem by introducing an extra step in the filtering process, in order to include the possibility of

conserving the mean value. The resulting filter is implemented in leapfrog integrations as follows:

un+1 = un−1ff + 2∆t F

(unf)

(5.8)

unff = unf +γα

2

(un+1 − 2unf + un−1

ff

)(5.9)

Page 39: Numerical Methods

5.2. SUPPRESSION OF THE COMPUTATIONAL MODE 39

un+1f = un+1 − γ(1− α)

2

(un+1 − 2unf + un−1

ff

)(5.10)

The Robert-Asselin-Williams filter introduces an extra operation that is simple and does not represent

a considerable computational expense with respect to the Robert-Asselin filter. It also introduces a new

parameter, α, which must be 0 < α < 1. A value of α = 1 corresponds to the traditional Robert-Asselin

filter filter. Williams (2009) showed that a value of α = 0.53 minimises the spurious, numerical impacts

on the physical solution and obtain the closest match to the exact solution over a broad frequency range.

Page 40: Numerical Methods

40 CHAPTER 5. THE NUMERICAL MODE

Page 41: Numerical Methods

Chapter 6

Accuracy of the numerical phase speed

We will now investigate the accuracy of the numerical phase speed due to both the discretisation in space

and time.

6.1 Dispersion due to the spatial discretisation

Let us first examine the advection equation with centred scheme in space

∂u

∂t+ c

unj+1 − unj−1

2∆x= 0

by substituting wave solutions

uj (t) = u0eik(j∆x−CDt)

we get

CD = csin (k∆x)

k∆x

where CD is the numerical phase speed and c. the true phase speed. The ratio should ideally be as close

as possible to one but isCDc

=sin (k∆x)

k∆x

The numerical group speed is

CDg =d (ωD)

dk=d (kCD)

dk= c cos (k∆x)

6.2 Dispersion due to the time discretisation

The effects of the centred scheme is analysed in the same way as the effects of the centred scheme in

space.

un+1j − un−1

j

2∆t+ c

∂u

∂x= 0

41

Page 42: Numerical Methods

42 CHAPTER 6. ACCURACY OF THE NUMERICAL PHASE SPEED

CD/c

kDx/pi

0

.2

.4

.6

.8

1.0

-.2

-.4

-.6

-.8

-1.0.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

c=cg c=cg c=cgCD/c

CD/c

CD/c

CDg/c

CDg/c

CDg/c

CDg/c

Figure 6.1: The numerical phase speed due to the centred finite difference in space com-pared to the analytical phase speed. The black line is the solution of the continuous equa-tions which is the non dispersive analytical case, i.e. the phase speed is the same as thegroup velocity c = cg. The blue line is the numerical phase speed normalised by dividingwith c. Note that when the wave number increases (wave length decreases) then the nu-merical phase speed deviates from the analytical phase speed. The phase speed is clearlydispersive since the waves propagate at different speeds depending on their wave lengths.The red line shows the computational group velocity CDg which at wave lengths shorterthan 4 grid cells (k∆x < π/2) propagate in the wrong direction.

Substituting the wave solutions

un (x) = u0eik(x−CDn∆t)

we get

CD =arcsin (ω∆t)

k∆t

where CD is the numerical phase speed and c. the true phase speed. The ratio should ideally be as close

as possible to one but isCDc

=arcsin (ω∆t)

ω∆t

The computational and physical group speeds differ also so that

CDgcg

=d (ωD)

cgdk=d (kCD)

cgdk=

1√1− (ω∆t)2

The computation phase speed and group velocity is presented in Figure 6.2 where it is plotted nor-

malised with c as a function of ω∆t.

Page 43: Numerical Methods

6.3. DISPERSION DUE TO BOTH THE SPATIAL AND TIME DISCRETISATION 43

CD/c

omega*Dt

1.01.11.21.31.41.51.61.71.81.92.0

.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0CD/c CD/c

CD/c

CD/c

CDg/cg

CDg/cg

CDg/cg

CDg/

cg

Figure 6.2: The numerical phase speed due to the centred finite difference in time comparedto the analytical phase speed. The black line is the solution of the continuous equationswhich is the non dispersive analytical case, i.e. the phase speed is the same as the groupvelocity c = cg. The blue line is the numerical phase speed normalised by dividing withc. Note that when the time step increases compared to the wave frequency (ω) then thenumerical phase speed increases and deviates from the analytical phase speed. The red lineshows the computational group velocity CDg.

6.3 Dispersion due to both the spatial and time discretisation

Let us now investigate the effects of the leap-frog on the phase and group velocities by the advection

equation with centred schemes in both time and space.

un+1j − un−1

j

2∆t+ c

unj+1 − unj−1

2∆x= 0

by substituting wave solutions

unj = u0eik(j∆x−CDn∆t)

we get

CD =1

k∆tarcsin

[c∆t

∆xsin (k∆x)

]where CD is the numerical phase speed and c. the true phase speed. The ratio should ideally be as close

as possible to one but is

CDc

=1

CFLk∆xarcsin [CFL sin (k∆x)]

Page 44: Numerical Methods

44 CHAPTER 6. ACCURACY OF THE NUMERICAL PHASE SPEED

where the CFL-number is defined as CFL = c∆t∆x .

CD/c

kDx/pi

0.1.2.3.4.5.6.7.8.9

1.0

.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

1.0 1.0 1.00.90.9

0.9

0.9

0.8

0.8

0.8

0.8

0.7

0.7

0.7

0.7

0.6

0.6

0.6

0.6

0.5

0.5

0.5

0.5

0.4

0.4

0.4

0.4

0.99 0.99

0.99

0.99

Figure 6.3: Numerical dispersion of the leap frog scheme. The lines show the ratio CD/c asa function of the normalised wave number k∆x

π . The different lines correspond to differentCFL-numbers

(CFL = c∆t

∆x

), where these are indicated on the lines. The ideal solution is

CD/c = 1. Note that when the wave number increases (wave length decreases) then thenumerical phase speed deviates from the analytical phase speed. The phase speed is clearlydispersive since the waves propagate at different speeds depending on their wave lengths.

This phase speed is a function of the wave number k. Thus, the finite differencing in space causes a

computational dispersion. As k∆x increases, the computational phase speedCD decreases from c to zero

when k∆x = π, which corresponds to the shortest possible wave length of two grid cells (λ = 2∆x).

Thus, all waves propagate at a speed that is less than the true phase speed c, with this decelerating effect

increasing as the wave length decreases. The two grid wave is stationary. Note that if CFL = 1, which is

the limit of stability for the advection equation then the the computation phase speed is the same as the

analytical one (CD = c).

The reason for the two grid wave to be stationary is obvious when we look at the wave illustrated in

Figure 6.4. For this wave we have uj+1 = uj−1 at all grid points which gives ∂uj∂t = 0 in the advection

equation.

We have encountered two effects in this section:

a) The advection speed is slower than the true advection speed.

b) The advection speed changes with the wave number.

Page 45: Numerical Methods

6.3. DISPERSION DUE TO BOTH THE SPATIAL AND TIME DISCRETISATION 45

j4321

!1

1

uj

Figure 6.4: The two-grid-interval wave with a wave length of λ = 2∆x.

Exercises

Derive the numerical phase speed :

CD =1

k∆tarcsin

[c∆t

∆xsin (k∆x)

]

Page 46: Numerical Methods

46 CHAPTER 6. ACCURACY OF THE NUMERICAL PHASE SPEED

Page 47: Numerical Methods

Chapter 7

Diffusion and friction terms (parabolic)

In this chapter we will investigate the discretisation of the friction and diffusion terms and how they

affect the stability of the equation. Diffusion and friction terms are included in most models from the

very simple shallow water models to the most complex ocean-atmosphere general circulation models.

7.1 Rayleigh friction

We will start by studying the simplest type of friction parameterisation, the Rayleigh friction:

∂u

∂t= −γu where γ > 0 (7.1)

which has the solution

u (t) = u0e−γt (7.2)

For centred time differences (leap-frog), which are the most common in equations with advection terms,

the discretisation of Equation 7.1 is

un+1j − un−1

j

2∆t= f = −γuj (7.3)

If a stability analysis is performed in analogy with that of the advection equation in the previous chapter

with un+mj = unj λ

m one finds that

a) if the right hand side of Equation 7.3 is taken at the time step n, that is fn = −γunj then λ1,2 =

−γ∆t±√

1 + (γ∆t)2 , which has at least one root that is always greater than one for any γ∆t > 0.

The scheme is hence unconditionally unstable.

b) if the right hand side of Equation 7.3 is taken at the time step n − 1, that is fn−1 = −γun−1j

then λ2 = 1 − 2γ∆t. The scheme is conditionally stable since λ2 6 1 if γ∆t 6 1. But since

λ2 < 0 for 1/2 < γ∆t < 1, the roots of λ will be purely imaginary and the solution of u will

oscillate and change sign for every second time step. If for instance γ∆t = 1 then λ1,2 = ±i and

un = in = 1, 0,−1, 0, 1, ...

47

Page 48: Numerical Methods

48 CHAPTER 7. DIFFUSION AND FRICTION TERMS (PARABOLIC)

20.

16.

12.

8.

4.

0.

20.

16.

12.

8.

4.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

10.

9.

8.

6.

5.

4.

3.

1.

0.

10.

9.

8.

6.

5.

4.

3.

1.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

Figure 7.1: The Rayleigh friction equation 7.3 integrated analytically (left figure) andnumerically (right figure) with equation 7.3 and the right hand side at time step n (case 1)with γ∆t = 0.5, which clearly gives un unstable solution

20.

18.

15.

13.

10.

8.

5.

3.

0.

20.

18.

15.

13.

10.

8.

5.

3.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

20.

18.

15.

13.

10.

8.

5.

3.

0.

20.

18.

15.

13.

10.

8.

5.

3.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

Figure 7.2: The Rayleigh friction equation 7.3 integrated with (2) i.e. the right hand sideat time step n− 1. Left figure with γ∆t = 0.95 and right figure with γ∆t = 0.2.

Page 49: Numerical Methods

7.1. RAYLEIGH FRICTION 49am

plitude

j

0

.1

.2

.3

.4

.5

.6

.7

.8

.9

1.0

0 10 20 30 40 50 60 70 80 90 100

20.

18.

15.

13.

10.

8.

5.

3.

0.

20.

18.

15.

13.

10.

8.

5.

3.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

Figure 7.3: The Rayleigh friction equation 7.3 integrated with the Crank-Nicholson scheme,i.e. the right hand side at time step n− 1 and n+ 1 with γ∆t = 0.2.

For a more strict condition γ∆t < 1/2 then λwill be real and uwill have a more realistic evolution

with no numerical oscillation.

c) if the right hand side of Equation 7.3 is taken as an average of n− 1 and n+ 1 so that,

un+1j − un−1

j

2∆t= −γ

2

(un+1j + un−1

j

)

This scheme, which is called Crank-Nicholson is said to be implicit because it includes a term

n + 1 on the right hand side of Equation 7.3. This alternative gives the best approximation of

Equation 7.2. The stability analysis gives λ2 = 1−γ∆t1+γ∆t < 1 for all values of γ∆t. The scheme is

hence absolute stable. But for the same reasons as in the previous alternative one needs γ∆t < 1

in order to have realistic evolution. Implicit schemes are often complicated to solve since they

include values on the right hand side that one needs to solve simultaneously on the left hand side

of the equation. But not in this particular case since the right hand side is in the same spatial grid

point j as the left hand side of un+1and the equation can be rearranging so that:

un+1j =

1− γ∆t

1 + γ∆tun−1j

When using the Crank-Nicholson scheme as in this case with only a time integration on should

use a two time step integration with Euler forward so that only two time steps are used and the

equation now becomes

un+1j =

1− γ∆t/2

1 + γ∆t/2unj

Page 50: Numerical Methods

50 CHAPTER 7. DIFFUSION AND FRICTION TERMS (PARABOLIC)

7.2 The heat equation

A somewhat more realistic friction parameterisation is the Laplace friction which is included in the heat

equation

∂u

∂t= A

∂2u

∂x2where A > 0 (7.4)

which has the solution

u(x, t) = u0e±ikx−Ak2t (7.5)

A centred fintite difference of the of the Laplace operator (second order differential) can be obtianed by

combining the two Taylor series we used in section 3.2:

uj+1 = uj + ∆x

(du

dx

)j

+1

2(∆x) 2

(d2u

dx2

)j

+1

6(∆x) 3

(d3u

dx3

)j

+1

24(∆x)4

(d4u

dx4

)j

+ ... (7.6)

uj−1 = uj −∆x

(du

dx

)j

+1

2(∆x) 2

(d2u

dx2

)j

− 1

6(∆x) 3

(d3u

dx3

)j

+1

24(∆x)4

(d4u

dx4

)j

− ... (7.7)

We obtain by suming these two equations and dividing by (∆x)2:

uj+1 − 2uj + uj−1

(∆x)2 =d2u

dx2+

1

12(∆x)2

(d4u

dx4

)j

(7.8)

This finite difference of the second order derivative is hence accurate to the second O[(∆x)2

], which is

the same as to say it has a truncation error of the second order.

The heat equation (7.4) can now be approximated by integrating in time with leap frog as

un+1j − un−1

j

2∆t= A

uj+1 − 2uj + uj−1

(∆x)2 (7.9)

A stability analysis with the von Neumann method can be obtianed by setting unj = u0λneikj∆x into

Equation (7.9). Depending on the time step of the right hand side we choose to have. Let us study the

same three different cases as for the Rayleigh friction equation:

a) If the right hand side of Equation 7.9 is taken at the time step n then the equation for the amplifi-

cation factor becomes

λ2 +8A∆t

(∆x)2sin2

(k∆x

2

)λ− 1 = 0

which has the roots λ1,2 = −a±√

1 + a2, where a ≡ 4A∆t(∆x)2

sin2(k∆x

2

). The second root will be

λ2 < −1 for any A∆t(∆x)2

> 0, which implies that the scheme is unconditionally unstable.

b) If the right hand side of Equation 7.9 is taken at the time step n − 1 then the equation for the

Page 51: Numerical Methods

7.2. THE HEAT EQUATION 51

500.

400.

300.

200.

100.

0.

500.

400.

300.

200.

100.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

500.

400.

300.

200.

100.

0.

500.

400.

300.

200.

100.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

Figure 7.4: The heat equation integrated numerically using Equation (7.9) with the righthand side at time step n and with A∆t

(∆x)2= 0.01 (left figure) and in the right figure with the

right hand side at time step at n− 1 and A∆t(∆x)2

= 0.125.

amplification factor becomes

λ2 = 1− 8A∆t

(∆x)2sin2

(k∆x

2

)the scheme is stable if −1 6 λ2 6 1, which is the case if A∆t

(∆x)2< 1/4. The scheme is hence

conditionally stable. However for the same reasons as for the Rayleigh equation we recommend

the stricter condition A∆t(∆x)2

< 1/8. In order to have λ2 > 0 and avoiding time oscillations of the

solution.

c) If the right hand side of Equation 7.9 is taken as an average of n− 1 and n+ 1 (Crank-Nicholson

scheme) then we have

un+1j − un−1

j

2∆t=A

2

(un+1j+1 − 2un+1

j + un+1j−1

(∆x)2 +un−1j+1 − 2un−1

j + un−1j−1

(∆x)2

)(7.10)

The scheme is implicit as it includes terms at time step n+ 1 on the right hand. The equation can

not be solved so easily as for the Rayleigh equation case since the n+1 terms on the right hand are

at several spatial grid points (j−1, j, j+1). It is however possible to use algorithms that eliminates

these terms. We can nevertheless perform a stability analysis and calculate the amplification factor

that becomes

λ2 =1− 4A∆t

(∆x)2sin2

(k∆x

2

)1 + 4A∆t

(∆x)2sin2

(k∆x

2

) (7.11)

which is always smaller than one and the is hence absolute stable. But in order to avoid imaginary

Page 52: Numerical Methods

52 CHAPTER 7. DIFFUSION AND FRICTION TERMS (PARABOLIC)

roots that leads to oscillating solutions one should use A∆t(∆x)2

< 1/4.

In most cases for the modelling of the atmosphere and the ocean γ and A are of such size that the

stability criterion in the present chapter enables ∆t to be much larger (5-10 times) than the CFL criterion

c < ∆x∆t . The most common mistake is however to use the unconditionally unstable scheme with the

friction taken at time step n when writing a code.

Note that the schemes in case 2 and 3 are in fact two level schemes since we do not use any values

at time step n but only in n − 1 and n + 1. There is therefore no reason to use leap-frog here and we

can instead use an Euler forward in time and replace all the n − 1 by n. The stability analysis remains

the same but since the time step is halved we should replace ∆t by ∆t/2. It is nevertheless easier to

demonstrate the differences between the three cases by using leap-frog for all cases.

7.3 Advection-diffusion equation

-1.00

-0.90

-0.80

-0.70

-0.60

-0.50

-0.40

-0.30

-0.20

-0.10

0.00

0.10

0.20

0.30

0.40

0.50

0.60

0.70

0.80

0.90

1.00

0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

a

0.0

0.25

0.5

0.75

1.0

1.25

1.5

1.75

2.0

b

Unstable

Stable & smooth

Stable but oscillating

Figure 7.5: The stability function λ2 as a function of a ≡ c∆t∆x sin (k∆x) and b ≡

8A∆t(∆x)2

sin2(k∆x

2

). The region in dark blue is where λ2 < −1 and corresponds to unsta-

ble solutions. The green - light blue region where −1 < |λ|2 < 0 is for stable solutions butoscillating ones. The yellow-red-brown region is for 0 < λ2 < 1, which correspond stablesolutions and no oscillations.

Let us now study an equation with both advection and diffusion terms so that

∂u

∂t+ c

∂u

∂x= A

∂2u

∂x2(7.12)

which has the analytical solution

u (x, t) = u0e±ik(x−ct)−Ak2t (7.13)

Page 53: Numerical Methods

7.3. ADVECTION-DIFFUSION EQUATION 53

We have previously seen that a stable discretisation scheme for the advection equation is both centred in

time and in space while for the diffusion equation the Laplace operator must be at time step n − 1. Let

us now combine these schemes so that

un+1j − un−1

j

2∆t+ c

unj+1 − unj−1

2∆x= A

un−1j+1 − 2un−1

j + un−1j−1

(∆x)2 (7.14)

Let us now perform a stability analysis by setting unj = λneikj∆x into Equation (7.14) which after

some calculation becomes

λ2 + 2iaλ+ b− 1 = 0 (7.15)

100.

80.

60.

40.

20.

0.

100.

80.

60.

40.

20.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

100.

80.

60.

40.

20.

0.

100.

80.

60.

40.

20.

0.

0. 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.

Figure 7.6: The heat-diffusion equation (7.16) integrated numerically using Equation (7.16)with the right hand side at time step n− 1 and 2A∆t

(∆x)2= 1

8 with c∆t∆x = 0.7 in the left figure

and c∆t∆x = 0.8 in the right figure.

where a ≡ c∆t∆x sin (k∆x) and b ≡ 8A∆t

(∆x)2sin2

(k∆x

2

).

The solution of equation (7.15) is

λ = −ia±√

1− b− a2

If 1− b− a2 > 0 then |λ|2 = a2 + 1− b− a2 = 1− b < 1 (the scheme is stable for this root)

If 1− b− a2 < 0 then λ = −i(a∓√a2 + b− 1

)⇒ λ2 = −

(2a2 + b− 1∓

√a2 + b− 1

)This second root is not obvious to see when stable so we have plotted λ2 as a function of a and b. in

Figure 7.5.

Let us know integrate equation (7.14) so that

Page 54: Numerical Methods

54 CHAPTER 7. DIFFUSION AND FRICTION TERMS (PARABOLIC)

un+1j = un−1

j − c∆t

∆x

(unj+1 − unj−1

)+

2A∆t

(∆x)2

(un−1j+1 − 2un−1

j + un−1j−1

)(7.16)

From Figure 7.5 we can see that if A 6= 0then we need to have a CFL-number(c∆t∆x

)well under 1. If we

choose 2A∆t(∆x)2

= 18 then b = 1

2 and we can see in Figure 7.5 that |λ|2 < 1 for a up to approximately 0.72.

Let us therefore integrate Equation (7.16) and test if it is stable. It should be stable when c∆t∆x = 0.7 and

unstable when c∆t∆x = 0.8.

Page 55: Numerical Methods

7.3. ADVECTION-DIFFUSION EQUATION 55

Exercises

a) Perform a stability analysis for the Rayleigh friction equation with the right hand side of Equation

7.3 taken at the time step n

b) Same as previous but taken at the time step n− 1

c) Same as previous but taken at the time step n+ 1

d) Calculate the stability criterion for

∂u

∂t= A

∂2u

∂x2where A > 0

withun+1j − unj

2∆t= A

unj+1 − 2unj + unj−1

(∆x)2

Estimate an upper limit for ∆t for

a) A = 106m2/s, ∆x = 400km (large scale horizontal diffusion)

b) A = 1m2/s, ∆x = 10m(vertical diffusion in a boundary layer)

e) The diffusion equation is solved by the Crank-Nicholson scheme:

Tn+1j − Tnj

∆t=A

2

[Tnj+1 − 2Tnj + Tnj−1

(∆x)2 +Tn+1j+1 − 2Tn+1

j + Tn+1j−1

(∆x)2

]

Examine the stability of this scheme.

Page 56: Numerical Methods

56 CHAPTER 7. DIFFUSION AND FRICTION TERMS (PARABOLIC)

Page 57: Numerical Methods

Chapter 8

The shallow water equations

In this chapter we consider the equations describing the horizontal propagation of gravity and inertia-

gravity waves. These equations are often referred to as the linearised shallow water equations. Mathe-

matically, this means that we will be dealing with a system of two or three partial differential equations

of the first order. Thus, we will now have two or three dependent variables (one or two velocities and

pressure/hight). The system of equations will always be equivalent to a single differential equation but

of a higher order. This equation can be obtained from the system by elimination of dependent variables.

8.1 One-dimensional gravity waves with centred space differencing

For simplicity we shall start with the simplest case of gravity waves

∂u

∂t= −g∂h

∂xand

∂h

∂t= −H∂u

∂x

where g is the gravity and H the depth/height. We seek solutions of the form

u (x, t) = Re[u0e

i(kx−ωt)]

and h (x, t) = Re[h0e

i(kx−ωt)]

giving the frequency equation

ω2 = gHk2

so that the phase speed is

c =ω

k= ±

√gH

showing that the gravity waves can propagate along the x-axis in both directions with a speed of√gH .

This speed is not a function of the wave number and consequently there is no dispersion of the waves.

Consider now the differential-difference equations with centred scheme

∂uj∂t

= −ghj+1 − hj−1

2∆xand

∂hj∂t

= −Huj+1 − uj−1

2∆x(8.1)

We seek solutions of the form

57

Page 58: Numerical Methods

58 CHAPTER 8. THE SHALLOW WATER EQUATIONS

uj = u0ei(jk∆x−ωDt) and hj = h0e

i(jk∆x−ωDt)

which are substituted in Equation (8.1) and gives the frequency equation

cD =ωDk

= ±√gH

sin (k∆x)

k∆x

and the numerical group speed is

CDg =d (kCD)

dk= ±

√gH cos (k∆x)

This phase speed is function of the wave number, and thus, we see that the space differencing again

results in computational dispersion. It is the same as the one obtained for the advection equation with

centred schemes.

There are two types of possible grids for these types of equations as illustrated by Figure 8.1. We

can have the two dependent variables in the same points as in Equation 8.1 or we can alternate them in

space.

∂uj∂t

= −ghj − hj−1

∆xand

∂hj∂t

= −Huj+1 − uj∆x

(8.2)

This is called a staggered grid. The phase speed becomes now

cD =ωDk

= ±√gH

sin(k∆x

2

)(k∆x

2

) (8.3)

and

CDg =d (ωD)

dk=d (kCD)

dk= ±

√gH cos

(k∆x

2

)The staggered grid has hence the advantage that

• the computational time is half as long or the number of grid points is halved

• the truncation error is half as big with ∆x→ ∆x/2

• waves with k∆x > π/2, which are the waves shorter than 4 grid cells, are eliminated They are the

ones that have a big error in the phase speed.

Page 59: Numerical Methods

8.2. TWO-DIMENSIONAL GRAVITY WAVES WITH CENTRED SPACE DIFFERENCING 59

x

x

uj-1uj-2uj-3 uj+3uj+2uj+1ujhj-1hj-2hj-3 hj+3hj+2hj+1hj

x

uj-1uj-2 uj+1ujhj-1 hj+1hj

x

Figure 8.1: Top: unstaggered grid with two dependent variables that are both located atevery grid point. Bottom: staggered grid with two dependent variables that are located atalternate grid points.

8.2 Two-dimensional gravity waves with centred space differencing

We now consider two dimensional gravity waves.

∂u

∂t= −g∂h

∂x∂v

∂t= −g∂h

∂y(8.4)

∂h

∂t= −H

(∂u

∂x+∂v

∂y

)Substituting the wave solutions

u (x, y, t) = Re[u0e

i(kx+ly−ωt)]

v (x, y, t) = Re[v0e

i(kx+ly−ωt)]

h (x, y, t) = Re[h0e

i(kx+ly−ωt)]

(8.5)

we now obtain

ω2 = gH(k2 + l2

)There are now several possible grids that usually are identified with the letters A to E according to

Arakawa (1972). The three most common ones are illustrated in Figure 8.3.

Page 60: Numerical Methods

60 CHAPTER 8. THE SHALLOW WATER EQUATIONS

CD/c

kDx/pi

0

.2

.4

.6

.8

1.0

-.2

-.4

-.6

-.8

-1.0.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

CD/cA-grid

CD/c

A-grid

CD/c

CDg/cg

A-grid

CDg/cg

A-grid

CDg/cg

A-grid

CD/c BC-grid CD/cBC-grid

CD/c

CDg/cgBC-grid

CDg/cg

BC-grid

CDg/cg

Figure 8.2: The numerical phase speed CD due to the centred finite difference in spacecompared to the analytical phase speed c for one dimesnion shallow water equations (Eq.8.1). The black line is the solution of the continuous equations which is the non dispersiveanalytical case, i.e. the phase speed is the same as the group velocity c = cg. The blueline is the numerical phase speed normalised by dividing with c. Note that when the wavenumber increases (wave length decreases) then the numerical phase speed deviates fromthe analytical phase speed. The phase speed is clearly dispersive since the waves propagateat different speeds depending on their wave lengths. The red line shows the computationalgroup velocityCDg which at wave lengths shorter than 4 grid cells (k∆x < π/2) propagatein the wrong direction. The green and orange lines are for the staggered BC-grid.

Page 61: Numerical Methods

8.2. TWO-DIMENSIONAL GRAVITY WAVES WITH CENTRED SPACE DIFFERENCING 61

i i+1

B!gridj

j!1

j+1

i!1

A!grid

i

j

j!1

j+1

i!1 i+1

h

h

h

hj+1

j

i i+1

u,v

u,vu,v

u,v

u,v

u,vu,v

u,v u,v

i!1

C!grid

j

j!1

j+1

u

i i+1

u

u u

uu

i

h h

hh

i+1

j

j+1

u,v,h

u,v,h u,v,h

u,v,h

u,v,h

u,v,h

u,v,h u,v,h

u,v,h

v v

v v

v v

Figure 8.3: The three most common grids: A, B and C.

Page 62: Numerical Methods

62 CHAPTER 8. THE SHALLOW WATER EQUATIONS

8.3 The linearised shallow water equations without friction

let us now consider one of the simplest possible sets of the Navier-Stokes equations in the atmosphere or

the ocean. The linearised shallow water equations or the gravity-inertia wave equations.

∂u

∂t− fv = −g∂h

∂x

∂v

∂t+ fu = −g∂h

∂y

∂h

∂t+H

(∂u

∂x+∂v

∂y

)= 0 (8.6)

where f is Coriolis acceleration and is here assumed to be constant. We seek as before solutions of the

wave form (8.5) and we obtain

ω2 = f2 + gH(k2 + l2

)For each of the three grids we use the simplest centred approximations for the space derivative and the

Coriolis terms. We do not need to study the time differencing since it has been studied previously and is

the same as before.

A-grid:

∂ui,j∂t

= −ghi+1,j − hi−1,j

2∆x+ fvi,j

∂vi,j∂t

= −ghi,j+1 − hi,j−1

2∆y− fui,j

∂hi,j∂t

= −H(ui+1,j − ui−1,j

2∆x+vi,j+1 − vi,j−1

2∆y

)(8.7)

B-grid:

∂ui,j∂t

= −ghi+1,j + hi+1,j+1 − hi,j − hi,j+1

2∆x+ fvi,j

∂vi,j∂t

= −ghi,j+1 + hi+1,j+1 − hi,j − hi+1,j

2∆y− fui,j

∂hi,j∂t

= −H(ui,j + ui,j−1 − ui−1,j − ui−1,j−1

2∆x+vi,j + vi−1,j − vi,j−1 − vi−1,j−1

2∆y

)(8.8)

C-grid:∂ui,j∂t

= −ghi+1,j − hi,j∆x

+f

4(vi,j + vi+1,j + vi+1,j−1 + vi,j−1)

∂vi,j∂t

= −ghi,j+1 − hi,j∆y

− f

4(ui,j + ui,j+1 + ui−1,j+1 + ui−1,j)

Page 63: Numerical Methods

8.3. THE LINEARISED SHALLOW WATER EQUATIONS WITHOUT FRICTION 63

∂hi,j∂t

= −H(ui,j − ui−1,j

∆x+vi,j − vi,j−1

∆y

)(8.9)

For simplicity we shall first study the quasi-one-dimensional case where u, v and h do not depend

on y so that the shallow water equations 8.6 are reduced to

∂u

∂t− fv = −g∂h

∂x

∂v

∂t+ fu = 0

∂h

∂t+H

∂u

∂x= 0 (8.10)

Substituting the wave solutions in equation 8.10, we obtain the frequency equation

f

)2

= 1 +gH

f2k2 (8.11)

Let us now look at the effect of the finite differencing in space in this case. As the variables are assumed

not to depend on y, the system for the A-grid (8.7) is reduced to

∂ui,j∂t

= −ghi+1,j − hi−1,j

2∆x+ fvi,j

∂vi,j∂t

= −fui,j

∂hi,j∂t

= − H

2∆x(ui+1,j − ui−1,j) (8.12)

and for the B-grid:

∂ui,j∂t

= −ghi+1,j + hi+1,j+1 − hi,j − hi,j+1

2∆x+ fvi,j

∂vi,j∂t

= −fui,j

∂hi,j∂t

= − H

2∆x(ui,j + ui,j−1 − ui−1,j − ui−1,j−1) (8.13)

and the C-grid:

∂ui,j∂t

= −ghi+1,j − hi,j∆x

+f

4(vi,j + vi+1,j + vi+1,j−1 + vi,j−1)

∂vi,j∂t

= −f4

(ui,j + ui,j+1 + ui−1,j+1 + ui−1,j)

Page 64: Numerical Methods

64 CHAPTER 8. THE SHALLOW WATER EQUATIONS

om

eg

a/f

kDx/pi

0

.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

4.5

5.0

5.5

6.0

.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

True

True

True

True

A

AA

AB

B

B

B

C

C

C

C

R=2!xo

me

ga

/f

kDx/pi

0

.2

.4

.6

.8

1.0

1.2

1.4

.1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

TrueTrue

True

AA A

ABB

BB

CC

C

C

R=!x/3

Figure 8.4: The function ω/f from (8.11) where at the top panel gH/ (f∆x)2 =4, i.e. the Rossby radius set to two gridcells

(√gH/f = 2∆x

)and at the bottom

panel gH/ (f∆x)2 = 1/9, i.e. the Rossby radius is set to a third of a grid cell(√gH/f = ∆x/3

). The black line corresponds to the true analytical solution, the blue

line to the A-grid, the red line to the B-grid and the green line to the C-grid. NB: TheB and C grid give similar results when the Rossby radius is well resolved but the C-griddegenerates when the grid resolution is coarse.

Page 65: Numerical Methods

8.4. BOUNDARY CONDITIONS 65

∂hi,j∂t

= − H

∆x(ui,j − ui−1,j) (8.14)

Substituting the wave solutions with no j dependency (ui, vi, hi) = (u0, v0, h0)eI(ik∆x−ωDt) into these

systems (8.12,8.13 and 8.14) gives the frequency equations:

A:(ωDf

)2= 1 + gH

f2sin2(k∆x)

(∆x)2

B:(ωDf

)2= 1 + gH

f2sin2(k∆x/2)

(∆x/2)2

C:(ωDf

)2= cos2

(k∆x

2

)+ gH

f2sin2(k∆x/2)

(∆x/2)2

The non-dimensional frequency ω/f is now seen to depend on two parameters k∆x and gH/f2

(Rossby radius to the square) and is plotted in Figure 8.4 and validated against the non-discretised case

of equation 8.11.

One can summarise the advantages and disadvantages of the grids by

• Grid A: The frequency reaches a maximum at k∆x = π/2, i.e. a wave length of 4 grids. Thus ,

the group velocity is zero for this wave length. If gravity-inertia waves of approximately that wave

number are excited near a point inside the computational region, for example by non-linear effects

or forcing through heating or ground topography, the wave energy stays near that point. Beyond

this maximum value, for π/2 < k∆x < π, the frequency decreases as the wave number increases.

Thus, for these waves the group velocity has wrong sign. Finally, the two-grid-interval wave with

k∆x = π behaves like a pure inertia oscillation, and its group velocity is again zero.

• Grid B: The frequency increases monotonically throughout the range 0 < k∆x < π. However

it reaches a maximum at the end of the range, so that the group velocity is zero for the two-grid-

interval wave with k∆x = π.

• Grid C: The frequency increases monotonically in a similar way to the one for the B-grid if

gH/ (f∆x)2 > 1/4 i.e. when the Rossby radius is longer than a half grid(√gH/f > ∆x

2

).

If however the Rossby radius is exactly a half grid(√gH/f = ∆x

2

)then the group velocity is

zero and for shorter Rossby radii then the frequency will decrease in an unrealistic way with in-

creasing wave number throughout 0 < k∆x < π. The advantage of the C-grid is however not seen

here, but lies in that the velocities are perpendicular on the walls of the grid-box, which makes the

differencing straightforward of 1) the scalar transport in the tracer equation and 2) the continuity

equation.

8.4 Boundary conditions

There are two types of boundary conditions. Closed boundary conditions, which correspond to the

boundary between land points and ocean points. Open boundary conditions, which is where your model

grid will end but the ocean/atmosphere continues.

Page 66: Numerical Methods

66 CHAPTER 8. THE SHALLOW WATER EQUATIONS

8.4.1 Closed boundary conditions

The B-staggering suits more naturally the no-slip boundary condition, since the velocity points are lo-

cated at the corners of the computational cell. Unlike the C-grid, there are no ambiguities in the way the

dynamical boundary condition is imposed at tips of the continents as shown in Figure 8.5.

The B-grid has, however, a better dispersion relationship than the C-grid since it resolves better the

Rossby Radius at for coarse resolutions (Batteen and Han, 1981). This makes this staggering technique

more suitable for coarsely-resolved models.

8.4.2 Open boundary conditions

An open boundary condition have two main purposes. 1) It should be able to let waves propagate out

from the model domain without being reflected back into the model domain. 2) It should be possible

to force the inner solution with external fields, which can e.g. be obtained from observations or models

with bigger grids.

Open boundary conditions also need to conserve mass so that the average of h remains constant.

The global energy budget should also be treated accurately allowing the correct amount of energy flux

through the open boundaries.

There are many different sort of sophisticated radiative open boundary conditions based on the wave

equation. We will here, however, only present the simplest possible boundary condition, which is the

"sponge" boundary conditions. In the sponge conditions all field variables are first updated using the

standard interior leapfrog schemes. The field values in the sponge zone are then relaxed to the externally

given values hEi,j according to

hn+1 = (1− µ)hn+1 + µhE (8.15)

The non-uniformity of hEi,j in the sponge zone is taken into account by letting it decay as we leave

the boundary. This can have an e-folding shape or a cosine-shaped relaxation factor such as

µ = 0.5

[1 + cos

(πi

IS

)], (8.16)

where IS are the number of grid points of the sponge zone, which is typically 10 to 30 grid points.

8.4.3 Cyclic boundary conditions

Cyclic boundary conditions are e.g. when the values on the easter wall equals the values on the western,

which is the case for a global models of the Earth. This can then for instance be located at the Greenwich

meridian where the longitude can be expressed as 0 or 360. When computing u, v and h next to the

eastern (i = 1) or western (i = NX) you will need values, which are for i = 0 and i = NX + 1.

This can be coded in two ways. 1) By having extra grid values "outside" you grid at (i = 0) or western

(i = NX + 1) and then setting these values to u0,j = uNX,j , uNX+1,j = u1,j , etc. 2) Alternativly one

can use in the model code’s i-loops im = i − 1 and when im = 0 then you set it to im = NX . Same

procedure for the eastern wall with ip = i+ 1 and when ip = NX + 1 which is repoaced by ip = 1.

Page 67: Numerical Methods

8.4. BOUNDARY CONDITIONS 67

u v hB-grid

u v hC-grid

u v hB-grid

Figure 8.5: Ilustation of how a narrow strait is resolved with a B-grid (top left panel) andC-grid (top right panel). Land cells in yellow, ocean cells in white with corresponding u, vand h points in colour. The only way to enable velocity points in this B-grid would be to"dig" out (two cells in green) so the strait is at least two grid cells wide (bottom left panel).

Page 68: Numerical Methods

68 CHAPTER 8. THE SHALLOW WATER EQUATIONS

8.5 Conservation of mass, energy and enstrophy

There are several reasons why numerical schemes for models are often formulated to respect conserva-

tion proper-ties of the governing equations. An important practical consideration is that satisfaction of

conservation properties helps to ensure the computational stability of a model. Apart from this, the direct

physical realism of a conservation property may be a desirable feature. For example, ensuring conserva-

tion of mass prevents the surface pressure from drifting to highly unrealistic values in long-term integra-

tions of atmospheric models. Advection schemes which satisfy an appropriate dynamical conservation

property may help to ensure the realism of a model’s energy spectrum. There are, however, considera-

tions other than conservation that might influence the choice of numerical scheme. Shape-preservation

(avoidance of the generation of spurious maxima or minima) may be considered an important feature of

an advection scheme, and the economy of a method (especially the ability to take long time steps) may

be a critical factor. Indeed, semi-Lagrangian advection schemes, generally without formal conservation

properties, are increasingly being developed for numerical weather prediction.

8.5.1 The shallow water equations with non-linear advection terms

Let us take the the shallow water momentum equation with the non-linear advection terms included

∂V

∂t+ V · ∇V + fk×V = −g∇h

which can be rewritten as

∂V

∂t+ ξk× (hV) = −∇

(gh+

1

2V ·V

)The continuity equation with the non-linear terms is

∂h

∂t+∇ (hV) = 0

where V is the horizontal velocity vector, f ≡ 2Ω sin (Φ) the Coriolis parameter, ξ ≡(f + ∂v

∂x −∂u∂y

)/h

the horizontal absolute potential vorticity, k is the unit vector normal to the plane domain S and h the

total water or air column and H ≡ gh+ 12

(u2 + v2

)= gh+ 1

2V ·V.

The equations can also be written on scalar form

∂u

∂t− ξhv = −∂H

∂x

∂v

∂t+ ξhu = −∂H

∂y

∂h

∂t+∂ (hu)

∂x+∂ (hv)

∂y= 0

It can be verified that these equations are such that the following conservation relations hold:

a) Total mass: M =∫S hdS

Page 69: Numerical Methods

8.5. CONSERVATION OF MASS, ENERGY AND ENSTROPHY 69

b) Total Energy: E =∫S

12 (gh+ V ·V)hdS

c) Absolute potential enstrophy:Z =∫S

12ξ

2hdS

Enstrophy is the integral of the vorticity and can be interpreted as a quantity directly related to the

kinetic energy that corresponds to dissipation effects.

8.5.2 Discretisation

The discretisation is on a C-grid illustrated in Figure 13.3.

The space differencing operators are

δxu =1

∆x

(ui+1/2,j − ui−1/2,j

)→ ui,j − ui−1,j

∆x

δyv =1

∆y

(vi,j+1/2 − vi,j−1/2

)→ vi,j − vi,j−1

∆y

ux =1

2

(ui+1/2,j + ui−1/2,j

)→ 1

2(ui,j + ui−1,j)

vy =1

2

(vi,j+1/2 + vi,j−1/2

)→ 1

2(vi,j + vi,j−1)

The mass fluxes U and V are defined at the points where the velocity components u and v are located:

Ui,j ≡ hxu = ui,j

1

2(hi,j + hi+1,j)

Vi,j ≡ hyv = vi,j

1

2(hi,j + hi,j+1)

The gradient operator will act on a quantity Hdefined at the locations where h is defined:

H ≡ gh+1

2

(u2x

+ v2y)

= ghi,j +1

2

[1

2

(u2i,j + u2

i−1,j

)+

1

2

(v2i,j + v2

i,j−1

)]The potential absolute vorticity is redefined and located in the corners of the C-grid

ξi,j =f + δxv − δyu

hxy

=f +

vi+1,j−vi,j∆x − ui,j+1−ui,j

∆y14(hi,j + hi+1,j + hi,j+1 + hi+1,j+1)

Simple expressions are chosen for

a) Total mass: M =∑h

b) Total energy: E = 12

∑((gh)2 + hu2

x+ hv2

y)

c) Absolute potential enstrophy:Z = 12

∑ξ2h

xy

Page 70: Numerical Methods

70 CHAPTER 8. THE SHALLOW WATER EQUATIONS

uu

u

u

u u

v

v

v

v

v

v

h

h h

h

i i+1i

j

i-1 i+1

j

j+1

j-1

j+1

Figure 8.6: C-grid with points for the zonal velocity u,meridional velocity v, water or aircolumn height h and vorticity ξ.

the symbol∑

referring to a summation over all grid points of same species. Note that due to symmetry:∑abx

=∑

bax

and that due to skew-symmetry

∑aδxb = −

∑bδxa

The time derivative of the total energy is

dE

dt=∑(

U∂u

∂t+ V

∂v

∂t+H

∂h

∂t

)(8.17)

A simple energy-conserving model can be defined as

∂u

∂t− ξV xy

+ δxH = 0

∂v

∂t+ ξU

yx+ δyH = 0

∂h

∂t+ δxU + δyV = 0

Page 71: Numerical Methods

8.5. CONSERVATION OF MASS, ENERGY AND ENSTROPHY 71

This can also be written in a longer way with indices as

∂ui,j∂t

=1

2

[ξi,j

1

2(Vi,j + Vi+1,j) + ξi,j−1

1

2(Vi,j−1 + Vi+1,j−1)

]− Hi+1,j −Hi,j

∆x(8.18)

∂vi,j∂t

=1

2

[ξi,j

1

2(Ui,j + Ui,j+1) + ξi−1,j

1

2(Ui−1,j + Ui−1,j+1)

]− Hi,j+1 −Hi,j

∆y(8.19)

∂hi,j∂t

= −Ui+1,j − Ui,j∆x

− Vi,j+1 − Vi,j∆y

(8.20)

The energy conservation can be obtained from Equation (8.17) and we have

dE

dt=∑(

UξVxy − V ξUy

x)+∑

(−UδxH −HδxU) +∑

(−V δyH −HδyV ) = 0

where each of the three summations cancel due to the symmetry or skew symmetry of the operators.

An absolute potential enstrophy model can be defined as

∂u

∂t− ξyV xy

+ δxH = 0

∂v

∂t+ ξ

xUyx

+ δyH = 0

∂h

∂t+ δxU + δyV = 0

In the corresponding vorticity equation, the discrete gradient vanishes δxδy = δyδx, so that

∂t

(ξh

xy)

+ δx

(ξxUyx)

+ δy

(ξyVxy)

= 0

which when combined with the average continuity equation

∂t

(hx

y)

+ δx

(Uyx)

+ δy

(Vxy)

= 0

yields the conservative potential enstrophy equation

∂t

(ξ2h

xy)

+ δx

(ξ2xUyx)

+ δy

(ξ2yVxy)

= 0

Page 72: Numerical Methods

72 CHAPTER 8. THE SHALLOW WATER EQUATIONS

Page 73: Numerical Methods

Chapter 9

Implicit and semi-implicit schemes

The time step permitted by the economical explicit schemes, twice that prescribed by the CFL criterion,

is still considerably shorter than that required for accurate integration of the quasi-geostrophic motions.

Thus we consider implicit schemes which are stable for any choice of time step.

9.1 Implicit versus explicit schemes, simple example

For implicit schemes, the spatial terms are evaluated, at least partially, at the unknown time level.

Let us consider one of the simplest example possible with the one-dimensional diffusion equation also

known as the heat conduction equation:

∂T

∂T− α∂

2T

∂x2= 0

Discretisation of this equation is done on a A-grid using finite difference and a forward-Euler-time

centered-space scheme.

The traditional explicit form writes:

Tn+1i = Tni + α

∆t

∆x2

[Tni−1 − 2Tni + Tni+1

]which simplifies into:

Tn+1i = sTni−1 + (1− 2s)Tni + sTni+1 with s = α

∆t

∆x2

This equation is explicit in terms of Tn+1i , which is the value at the unknown time level, and therefore is

trivial.

Similarly, but evaluating the spatial term at the unknown time level yields the fully implicit form:

Tn+1i = Tni + α

∆t

∆x2

[Tn+1i−1 − 2Tn+1

i + Tn+1i+1

]which simplifies into:

−sTn+1i−1 + (1 + 2s)Tn+1

i − sTn+1i+1 = Tni with s = α

∆t

∆x2

73

Page 74: Numerical Methods

74 CHAPTER 9. IMPLICIT AND SEMI-IMPLICIT SCHEMES

To solve this equation one needs to consider all the nodes i. In the present case, since the equation of

heat is linear, it is possible to express the problem as a linear system A · X = B where X is the vector

containing unknown values of T at time n+ 1 and B the vector containing known values of T

(1 + 2s) −s−s (1 + 2s) −s... ... ...

... ... ...

−s (1 + 2s) −s... ... ...

... ...

−s (1 + 2s)

·

Tn+12

Tn+13

...

...

Tn+1i

...

...

Tn+1I−1

=

Tn2 + sTn+11

Tn3...

...

Tni...

...

TnI−1 + sTn+1I

(9.1)

where Tn+11 and Tn+1

I are known from the Dirichlet boundary conditions. The solution at time n+ 1 is

known by solving this system of equation. The implicit method is therefore very demanding in terms of

computer power compared to the explicit method, but since it is unconditionally stable, a property that

will be shown in the next section, one can use larger time steps that does not necessarily need to respect

the CFL criterion.

Depending on the shape of the matrix, different algorithm can be used to solve this linear system (9.1).

In the present case, the matrix is tridiagonal.

9.2 Semi-implicit scheme

Semi-implicit schemes evaluate the spatial derivative at an average of the nth and the (n+ 1)th time level

instead of only at the (n + 1)th time level as in the fully-implicit case. If F (x, y, t) is a term containing

spatial derivatives of a given scalar T (x, y, t), we can consider the following general expression for a

discretized version of the equation of the evolution of T at point (i, j):

Tn+1ij − Tnij

∆t= (1− β)Fnij + βFn+1

ij

• β = 0→ Explicit scheme

• β = 1→ Fully implicit scheme

• 0 < β < 1→ Semi implicit

9.2.1 Crank-Nicolson method with 1D difusion equation

A popular method based on an implicit scheme is the Crank-Nicolson method in which β = 0.5 and

the time derivative is still expressed with the usual forward-Euler scheme. The term containing spatial

derivatives is therefore centered on time level n + 1/2, which actually turn this scheme in a trapezoidal

implicit scheme in time. By carrying out a Taylor expansion about (i, n+ 1/2) one can easyly verify that

this scheme leads to a second-order accuracy in time, which is an appreciable improvement with regards

Page 75: Numerical Methods

9.2. SEMI-IMPLICIT SCHEME 75

to the first-order accuracy of the forward-Euler explicit scheme. It is usually associated with a centered

differencing in space so the truncation error is therefore O(∆t2,∆x2).

9.2.2 2D pure gravity waves

Let us now discretize the equations for the two-dimensional gravity waves (Eq. 8.4) in a Crank-Nicolson

fashion using finite differencing on a C-grid (with forward-Euler-time centered-space scheme).

un+1 = un − g∆t

2

(δxh

n + δxhn+1)

vn+1 = vn − g∆t

2

(δyh

n + δyhn+1)

(9.2)

hn+1 = hn − H∆t

2

(δxu

n + δyvn + δxu

n+1 + δyvn+1)

where δx the space differencing operator applied to a scalar f

δxf =1

∆x

(fi+1/2 − fi−1/2

)Substituting the wave solutions

un = λnu0ei(kx+ly)

vn = λnv0ei(kx+ly)

hn = λnh0ei(kx+ly)

we find

u0 (1− λ) = ig∆t (1 + λ)sin (k∆x/2)

∆xh0

v0 (1− λ) = ig∆t (1 + λ)sin (l∆y/2)

∆yh0

h0 (1− λ) = iH∆t (1 + λ)

[sin (k∆x/2)

∆xu0 +

sin (l∆y/2)

∆yv0

]One of the solutions, λ = 1, is associated with a neutral stationary solution. The remaining two are

obtained by eliminating u0, v0 and h0 so that

λ =1−A± 2i

√A

1 +Awhere A ≡ gH∆t2

[sin2 (k∆x/2)

∆x2+

sin2 (l∆y/2)

∆y2

]Examination of these shows that it always gives amplification factors satisfying|λ| = 1 and so the scheme

is unconditionally stable and neutral. The Crank-Nicolson example shows the power of semi-implicit

methods as it both decreases the temporal truncation error fromO(∆t) toO(∆t2) and makes the scheme

unconditionally stable and neutral.

Now, by studying the one-dimensional case, by assuming that waves are propagating along the x-axis

(l ≡ 0), using

λ = |λ| e−iω∆t

Page 76: Numerical Methods

76 CHAPTER 9. IMPLICIT AND SEMI-IMPLICIT SCHEMES

and ∆t deduced from the expression of A in the former equation, it is possible to express ω or c as a

function of A, k and ∆x. Then, it is possible to compare the phase speed of the non-stationary solutions

in the present explicit case to the phase speed found for the explicit centered space differencing case

studied in section 8.1 (Eq. 8.3):∣∣∣∣∣c[impl]D

c[expl]D

∣∣∣∣∣ ≡∣∣∣∣∣ω

[impl]D

ω[expl]D

∣∣∣∣∣ =

∣∣∣∣∣ 1

2√A

arctan

(2√A

1−A

)∣∣∣∣∣Since A ≥ 0, the right hand term is always ≤ 1 and thus c[impl]

D ≥ c[expl]D ≥

√gH . Semi-implicit time

differencing is therefore seen to result in a retardation of gravity waves even larger as that due to explicit

centered space differencing.

To solve the system (9.2), as we will do in the next section, the quantities δxun+1 and δyvn+1 can

be eliminated from the third equation by applying operators δx and δy to the first and second of these

equations and substituting the results into the third equation. This gives an equation for the height

which can be solved using a number of standard methods. As seen in the previous section, it is possible

to express and solve this equation as a linear matrix system involving each grid point of the domain.

Another possible option is to use an iterative method such as the so-called relaxation method:

a) make a first guess hn+1 which is usually hn

b) at each of the grid points the value of hn+1 has to satisfy the equation

c) the preceding step is repeated as many times as needed to make the change at every point less than

some pre-assigned small value

9.3 The semi-implicit method of Kwizak and Robert

There is no advantage in using an implicit method for advection, Coriolis, and other terms of governing

equations in atmospheric models. They are associated with slower phase speeds, and should not require

excessively small time steps for linear stability when calculated explicitly. Since the trapezoidal implicit

scheme is a two level scheme like the forward-backward scheme, it is convenient to use Adams-Bashforth

scheme for this purpose. Kwizak and Robert (1971) chose, however, to use the leapfrog scheme. The

usual procedure used for solving the semi-implicit difference system for variables at time level n+1 will

be illustrated for the shallow water equations. These equations can be written in a compact form

∂u

∂t= −g∂h

∂x+Au

∂v

∂t= −g∂h

∂y+Av (9.3)

∂h

∂t= −H

(∂u

∂x+∂v

∂y

)+Ah

where Au, Av and Ah contain terms that were omitted in the system (8.6) describing the propagation

of pure gravity waves. This time we apply the implicit differencing over a time interval 2∆t centered

Page 77: Numerical Methods

9.3. THE SEMI-IMPLICIT METHOD OF KWIZAK AND ROBERT 77

around time n for the terms containing spatial derivatives (by using β = 0.5 with time steps n − 1 and

n+ 1 rather than n and n+ 1 as we did previously). Second-order centered-space schemes are used for

spatial derivatives and the leapfrog scheme for the time derivative so the discretized system is

un+1 = un−1 − g∆t(δxh

n−1 + δxhn+1)

+ 2∆tAnu

vn+1 = vn−1 − g∆t(δyh

n−1 + δyhn+1)

+ 2∆tAnv (9.4)

hn+1 = hn−1 −H∆t(δxu

n−1 + δyvn−1 + δxu

n+1 + δyvn+1)

+ 2∆tAnh

We now apply the operator δx to the first and δy to the second of these equations, respectively and

add the results. We introduce the notation

δxxh = δx (δxh) and δyyh = δy (δyh)

We obtain

(δxu+ δyv)n+1 = (δxu+ δyv)n−1−g∆t[(δxx + δyy)h

n−1 + (δxx + δyy)hn+1]+2∆t (δxAu + δyAv)

n

Substituting the right-hand side into the third of Eqs. (9.4), and defining the “finite difference Laplacian”

by

∇2∗ ≡ δxx + δyy

we find that

hn+1 = hn−1−2H∆t (δxu+ δyv)n−1+gH∆t2(∇2∗hn−1 +∇2

∗hn+1)+2∆t [Ah −H∆t (δxAu + δyAv)]

n

Using, in addition the definitions

Fn−1 ≡ hn−1 − 2H∆t (δxu+ δyv)n−1 + gH∆t2∇2∗hn−1

Gn ≡ 2∆t [Ah −H∆t (δxAu + δyAv)]n

this can be written as

hn+1 − gH∆t2∇2∗hn+1 = Fn−1 +Gn (9.5)

The terms have been arranged to show that at time level n the right hand side is known at all space grid

points. Once the equation has been solved for the values hn+1 then un+1 and vn+1 can be obtained

directly from the first and the second of Eqs. (9.4). The algebraic system (9.5) is an elliptic PDE that

ressembles the Helmholtz equation

∇2h+ ah+ b (x, y) = 0

And there is therefore several methods available to solve it.

Page 78: Numerical Methods

78 CHAPTER 9. IMPLICIT AND SEMI-IMPLICIT SCHEMES

Page 79: Numerical Methods

Chapter 10

The semi-Lagrangian technique

In an Eulerian Advection scheme an observer watches the world evolve around him at a fixed geograph-

ical point. Such schemes work well on regular Cartesian meshes, but often lead to overly restrictive

time steps due to considerations of computational stability. In a Lagrangian advection scheme observer

watches the world evolve around himself as he travels with a fluid particle. Such schemes can often use

much larger time steps than Eulerian ones but have disadvantage that an initially regularly spaced set

of particles will generally evolve to a highly irregularly spaced set at later times and important features

of the flow may consequently not be well represented. The idea behind the semi-Lagrangian advection

schemes is to try to get the best of both worlds: the regular resolution of the Eulerian schemes and the

enhanced stability of the Lagrangian ones. This is achieved by using a different set of particles at each

time level, the set of particles being chosen such that they arrive exactly at the pints of a regular Cartesian

mesh at the end of the time step.

So far we have taken an Eulerian view and considered what was the evolution in time of a dependent

variable at fixed points in space and in the spectral and finite elements we will consider what is the time

evolution of some coefficients multiplying some basis functions also fixed in space; in other words, we

used the partial time derivative ∂/∂t .

Several attempts were made to build stable time integration schemes permitting large time steps.

Robert (1981) proposed using the quasi-Lagrangian technique for the treatment of the advective part of

the equations.

10.1 1-D Passive advection

To present the basic idea behind the semi-Lagrangian method in its simplest context let us apply the

one-dimensional advection equation

DF

Dt=∂F

∂t+∂x

∂t

∂F

∂x= 0 (10.1)

where F is the advected property and∂x

∂t= U(x, t) (10.2)

79

Page 80: Numerical Methods

80 CHAPTER 10. THE SEMI-LAGRANGIAN TECHNIQUE

Figure 10.1: Schematic for three time level advection. Actual (solid curve) and approximate(dashed line) trajectories that arrive at mesh point xm at time tn + ∆t. Here αm is thedistance the particle is displaced in x in time ∆t.

is given advection velocity. Equation (10.1) states that the scalar F is constant along a fluid path or

trajectory. In Figure 10.1, the exact trajectory in the x− t plane of the fluid particle that arrives at mesh

point xmat time tn + ∆t is denoted by the solid curve AC, and an approximate straight line trajectory

by the dashed line A′C. Let us assume that we know F (x, t) at all mesh points xm at times tn − ∆t

and tn, and that we wish to obtain values at the same mesh points at time tn + ∆t. The essence of

semi-Lagrangian advection is to approximately integrate Equation (10.1) along the approximated fluid

trajectory A′C. Thus,F (xm, t

n + ∆t)− F (xm − 2αm, tn −∆t)

2∆t= 0 (10.3)

where αm is the distance BD the particle travels in x in time ∆t, when following the approximated

space-time trajectory A′C. Thus we know αm , then the value of F at the arrival point xm at the time

tn + ∆t is just its value at the upstream point xm − 2αm at the time tn − ∆t. However, we have not

as yet determined αm; even if we had, we only know F at mesh points, and generally it still remains to

evaluate F somewhere between mesh points.

To determine αm, note that U evaluated at the point B of Figure 10.1 is just the inverse of the slope

of the straight line A′C, and this gives the following approximation to equation (10.2):

αm = ∆tU (xm − αm, tn) (10.4)

Equation (10.4) may be iteratively solved for the displacement αm, for example by

αk+1m = ∆tU

(xm − αkm, tn

)(10.5)

with some initial guess for α0m, provided U can be evaluated between the grid points. To evaluate F

and U b between mesh points, spatial interpolation is used.. The semi-Lagrangian algorithm for passive

advection in one-dimension in summary is thus:

a) Solve Equation (10.5) iteratively for the displacement αmfor all mesh points xm, using some initial

Page 81: Numerical Methods

10.2. INTERPOLATION AND STABILITY 81

Figure 10.2: Schematic for the space interpolation.

guess (usually its value at the previous time level), and an interpolation formula.

b) Evaluate F at upstream points xm − 2αm at time tn −∆t using an interpolation formula.

c) Evaluate F at arrival points xmat time tn + ∆t using Equation (10.3).

10.2 Interpolation and Stability

Let us consider the linear advection equation

DF

Dt=∂F

∂t+ U

∂F

∂x= 0

The distance traveled during the last interval by ∆t an air or water parcel arriving at point xj is U∆t,

therefore it comes from a point

x∗ = xj − U∆t

If this point lies between grid points j − p and j − p− 1, and we call α the fraction of grid length from

point x∗ to xj−p point we have

U∆t = (p+ α) ∆x

and using linear interpolation to find Fn∗ we get

Fn+1j = Fn∗ = (1− α)Fnj−p + αFnj−p−1 (10.6)

We study the stability using the von Neumann method and, therefore, assume a solution of the form

Fnj = F0λneijk∆x

substituting we get

λ =[1− α

(1− e−ik∆x

)]e−ipk∆x

Page 82: Numerical Methods

82 CHAPTER 10. THE SEMI-LAGRANGIAN TECHNIQUE

and

|λ|2 = 1− 2α (1− α) [1− cos (k∆x)]

Therefore |λ| ≤ 1 as long as α (1− α) ≥ 0 or

0 ≤ α ≤ 1

The scheme is, therefore, stable if the interpolation points are the two nearest ones to the departure point,

but it is neutral only if α = 0 or α = 1, that is to say when no interpolation is needed.

We find that heavy damping occurs for short wavelengths (i.e. large wave numbers) with a complete

extinction whencos(k∆x) = −1⇔ k∆x = (2m− 1)π m = 1, 2, 3, . . .

thus, in terms of wavelength it occurs when

L =2∆x

2m− 1m = 1, 2, 3, . . .

The modes for m > 1 do not really make sense here since it would be equivalent to consider waves with

a wavelength shorter than the spatial increment ∆x. So the total damping occurs for the shortest waves

representable on a given grid resolution: when L = 2∆x and α = 1/2.

A noteworthy feature of this scheme (peculiar to the case of constant wind) is that for a given α the

phase errors and dissipation decrease as p increases. This happens because the departure point can be

located precisely using only the wind at the arrival point.

A similar analysis to the above can be carried out for quadratic interpolation. Once again the scheme

is absolutely stable provided Fn∗ is computed by interpolation from the nearest three grid points. This

scheme has less damping than the linear interpolation, but the phase representation is not improved. It is

easy to show that when the departure point is within half a grid length from the grid point (i.e. p = 0),

this scheme becomes identical to the Lax-Wendroff scheme.

These ideas can be extended to two-dimensional flow. It has been found that bi-quadratic interpo-

lation is absolutely stable for constant flow (provided the nine grid points nearest the departure point

are used for interpolation) and that the characteristics of this scheme are superior to those of a bilinear

interpolation scheme.

Page 83: Numerical Methods

Chapter 11

Poisson and Laplace equations (elliptic)

Consider Poisson’s equation in two dimensions

∇2u =

(∂2

∂x2+

∂2

∂y2

)u = f (x, y) (11.1)

If f (x, y) = 0 then (11.1) is called the Laplace Equation.

Equation (6.8) and can be discretised as

ui−1,j − 2ui,j + ui+1,j

(∆x)2 +ui,j−1 − 2ui,j + ui,j+1

(∆y)2 = fi,j (11.2)

If we consider a square grid in such a way that ∆x = ∆y, then Equation (11.2) simplifies to

ui,j =1

4

[ui−1,j + ui+1,j + ui,j−1 + ui,j+1 − (∆x)2 fi,j

](11.3)

If the boundary values for the domain are known then it is possible to solve this by iteration.

In iterative methods we need initial values at iteration level umi,j (m = 0 initially) and the purpose is

to calculate um+1i,j .

11.1 Jacobi iteration

Values from previous iteration level are used, which results in

um+1i,j =

1

4

[umi−1,j + umi+1,j + umi,j−1 + umi,j+1 − (∆x)2 fi,j

]The method works but is inefficient and is not used in solving practical problems.

11.2 Gauss-Seidel iteration

A clear improvement in efficiency of iterative methods is obtained if we use the the newly computed

values in the iteration formula: iteration levelm+1 values are available for nodes (i− 1, j) and (i, j − 1)

when calculating u for node (i, j). Thus the Gauss-Seidel formula is:

83

Page 84: Numerical Methods

84 CHAPTER 11. POISSON AND LAPLACE EQUATIONS (ELLIPTIC)

Figure 11.1: Grid for the Poisson and Laplace equations. Boundary values required for thefour walls: i = 1, j = 1, J; i = I, j = 1, J; i = 1, I, j = 1; i = 1, I, j = J .

um+1i,j =

1

4

[um+1i−1,j + umi+1,j + um+1

i,j−1 + umi,j+1 − (∆x)2 fi,j

](11.4)

The inclusion of the two newly computed values makes Gauss-Seidel iteration more efficient than Jacobi

iteration.

11.3 Successive Over Relaxation (SOR)

Gauss-Seidel iteration method can be further improved by increasing the convergence rate using the

method of SOR (Successive Over Relaxation). The change between two successive Gauss-Seidel itera-

tions is called the residual c, which is defined as

c = um+1i,j − umi,j

In the method of SOR, the Gauss-Seidel residual is multiplied by a relaxation factor ω and new iteration

value is obtained from

um+1i,j = umi,j + ωc = umi,j + ω

(um+1i,j − umi,j

)= (1− ω)umi,j + ωum+1

i,j (11.5)

where um+1i,j denotes the new iteration value obtained from Gauss-Seidel method using Equation (11.4).

It can be easily seen that if ω = 1 , SOR reduces to Gauss-Seidel iteration method. By substituting

Equation (11.4) of the Gauss-Seidel iteration method to Equation (11.5), we obtain the equation used in

the SOR method:

um+1i,j = (1− ω)umi,j +

ω

4

[um+1i−1,j + umi+1,j + um+1

i,j−1 + umi,j+1 − (∆x)2 fi,j

](11.6)

Page 85: Numerical Methods

11.3. SUCCESSIVE OVER RELAXATION (SOR) 85

Usually the numerical value of relaxation parameter can be obtained by trial and error and optimum value

is around 1.5. In the case that 0 < ω < 1 , the method is said to be "under relaxed". According to the

selection of parameter ω, we either extrapolate ω > 1 or 0 < ω < 1 interpolate between the old iteration

value at level m and Gauss-Seidel value at level m + 1. If we extrapolate too much, i.e. ω is too high,

the iteration starts to oscillate and probably collapses.

Exercises

1) Set up a numerical model with 10 x 10 points. Start with u = 0 in the interior and with u = 1 as

boundary conditions. Test the convergence of the 3 different iterations schemes from this chapter with

f = 0.

Page 86: Numerical Methods

86 CHAPTER 11. POISSON AND LAPLACE EQUATIONS (ELLIPTIC)

Page 87: Numerical Methods

Chapter 12

Model Coordinates

12.1 Vertical ocean coordinates

The three most common vertical coordinate systems in the ocean circulation models are presented in

Figure 12.1. z-star....

Figure 12.1: a) Ocean model vertical coordinates. The real topography, b) depth levelcoordinates, c) density coordinates, d) sigma coordinates.

12.1.1 Fixed height or depth coordinates

A simple example of a vertical discretisation is the one of the continuity equation, which is used in many

OGCMs (Ocean General Circulation Model), which uses the B-grid and fixed depth levels as in Figure

87

Page 88: Numerical Methods

88 CHAPTER 12. MODEL COORDINATES

y

z

x

wi,j,k-1

wi,j,k

uvi,j,kuvi-1,1,k

uvi,j-1,kuvi-1,j-1,k

y

z

x

wi,j,k-1

Vi,j,k

ui,j,kui-1,j,k

wi,j,k

Vi,j-1,k

B-grid

B-grid

C-grid

Figure 12.2: Finite difference boxes for the B-grid and the C-grid with fixed depth levelcoordinates.

12.2. The continuity equation then becomes:

∂u

∂x+∂v

∂y+∂w

∂z= 0 (12.1)

can be discretised on a B-grid to

wi,j,k = wi,j,k−1 −∆z

[(ui,j,k + ui,j−1,k)− (ui−1,j,k + ui−1,j−1,k)

2∆x

+(vi,j,k + vi−1,j,k)− (vi,j−1,k + vi−1,j−1,k)

2∆y

] (12.2)

or on a C-grid to

wi,j,k = wi,j,k−1 −∆z

[ui,j,k − ui−1,j,k

∆x+vi,j,k − vi,j−1,k

∆y

](12.3)

Equation (12.2) is integrated from the bottom and upwards with the boundary conditionw = 0 where

k increases with depth. Equation (12.2) can be explained by that the sum of all the volume fluxes in or

out of the grid box is zero.

12.2 Atmospheric vertical coordinates

Instead of depth/height as vertical coordinate in our system of equations it is possible to use other quanti-

ties. The density varies with latitude and height/depth which make the equations sometimes less easy to

use with than an alternative system which uses other quantities such as pressure, sigma or isentropic for

Page 89: Numerical Methods

12.2. ATMOSPHERIC VERTICAL COORDINATES 89

River run-off

s (x,y or t)

z

!s

!z

"

A B

C

Figure 12.3: Schematic showing the vertical coordinate transformation.

the atmosphere and density or sigma for the ocean as the vertical coordinate. These coordinates can be

more useful for numerical techniques in solving the complete equations of motion. We can derived a sys-

tem of equations for a generalised vertical coordinate which is assumed to be related to the height/depth

by a single-valued monotonic function. When we transform the vertical coordinate a variable u(x, y, z, t)

becomes a(x, y, ζ(x, y, z, t), t). The horizontal coordinates remain the same. Let s represent x, y or t.

From Figure 12.3 we see thatC −A

∆s=B −A

∆s+C −B

∆z

∆z

∆s(12.4)

so that (∂a

∂s

=

(∂a

∂s

)z

+

(∂a

∂z

)s

(∂z

∂s

(12.5)

where∂a

∂ζ=∂a

∂z

∂z

∂ζ(12.6)

or∂a

∂z=∂a

∂ζ

∂ζ

∂z(12.7)

Substituting Eq. 12.7 in Eq. 12.5, we obtain(∂a

∂s

=

(∂a

∂s

)z

+∂a

∂ζ

∂ζ

∂z

(∂z

∂s

(12.8)

Page 90: Numerical Methods

90 CHAPTER 12. MODEL COORDINATES

Adiabatic formulation of models

Meteorological Training Course Lecture Series

! ECMWF, 2002 21

Over steep orography, the sigma levels slope appreciably even in the stratosphere (see Fig. 3 ) and the problems

with the horizontal pressure force remain. It seems, therefore, that a scheme which combines the advantage of sig-

ma coordinates near the surface and pressure coordinate in the stratosphere may prove advantageous. Such schemes

exist and are known as hybrid coordinates.

-coordinates

-coordinates

-coordinates

Figure 3Illustration of the three vertical coordinate systems.

4.3 Hybrid coordinates

There are various ways of defining a coordinate system that has the properties of sigma coordinates in the lower

atmosphere and pressure in the stratosphere. Arakawa and Lamb (1977) use the definition

(92)

where

"

#I–( )

$-----------------------=

Figure 12.4: Schematic illustration of height, pressure and sigma coordinates in the atmo-sphere..

From this relationship, if s = x, y, we can get an equation for a horizontal gradient of the scalar a in ζ

coordinates:

∇ζa = ∇za+∂a

∂ζ

∂ζ

∂z∇ζz (12.9)

and for the horizontal divergence of a vector V:

∇ζ ·V = ∇z ·V +∂V

∂ζ· ∂ζ∂z∇ζz (12.10)

The total derivative of a(x, y, ζ, t) becomes

da

dt=

(∂a

∂t

+ V · ∇ζa+ ζ∂a

∂ζ(12.11)

Page 91: Numerical Methods

12.2. ATMOSPHERIC VERTICAL COORDINATES 91

Figure 12.5: Atmospheric sigma coordinates.

12.2.1 Pressure coordinates

Pressure or isobaric coordinates can be used in atmosphere although not very often anymore in atmo-

spheric GCMs. In pressure coordinates where ∂p/∂ζ ≡ 1, the total derivative (Eq. 12.11 ) is given

by

da

dt=∂a

∂t+ V · ∇a+ ω

∂a

∂p(12.12)

where the vertical velocity is pressure coordinates is ω ≡ dp/dt. The continuity equation 12.1 can now

be written as

∇p ·V +∂ω

∂p= 0 (12.13)

Most Atmospheric GCMs today use however terrain-following vertical coordinates, which is de-

scribed beneath.

12.2.2 Atmospheric sigma coordinates

The sigma coordinate system defines the base at the model’s ground level. The surfaces in the sigma

coordinate system follow the model terrain and are steeply sloped in the regions where terrain itself is

steeply sloped. the sigma coordinate system defines the vertical position of a point in the atmosphere

as a ratio of the pressure difference between that point and the top of the domain to that of the pressure

difference between a fundamental base below the point and the top of the domain. Because it is pressure

based and normalised, it is easy to mathematically cast governing equations of the atmosphere into a

relatively simple form. The sigma coordinate is hence σ = p/pS where pS(x, y, z, t) is the pressure

at the surface of the Earth. The Boundary values are hence σ = 0 at the top of the atmosphere where

p = 0 and σ = 1 at the surface of the Earth. The relationship between pressure and sigma coordinates is

presented in Figure 12.5.

Page 92: Numerical Methods

92 CHAPTER 12. MODEL COORDINATES

Figure 12.6: Two different vertical resolution of the hybrid-coordinate model at the ECMWF(The European Centre for Medium-Range Weather Forecasts).

12.2.3 Hybrid coordinates

The hybrid coordinate system has the properties of sigma coordinates in the lower atmosphere and pres-

sure in the stratosphere.

Following Simmons and Burridge (1981) the atmosphere is divided into NLEV layers, which are

defined by the pressures at the interfaces between them and these pressures are given by

pk+1/2 = ak+1/2 + bk+1/2 pS (12.14)

for k = 0, 1, .., NLEV , with k = 0 at the top of the atmosphere and k = NLEV at the Earth’s surface.

The ak+1/2 and bk+1/2 are constants, whose values effectively define the vertical coordinate and pS is

the surface pressure. The dependent variables, which are the zonal wind (u), the meridional wind (v), the

temperature (T ) and the specific humidity (q) are defined in the middle of the layers, where the pressure

Page 93: Numerical Methods

12.3. HORIZONTAL COORDINATES 93

a (Pa) b (Pa Pa-1)

================== TOP OF MODEL ATMOSPHERE ===================== i = 1 a = 0.00000 b = 0.00000

---------------------- model level ------- (data) ---------- j = 1 a = 10.00000 b = 0.00000

========================= interface ============================ i = 2 a = 20.00000 b = 0.00000

---------------------- model level ------- (data) ---------- j = 2 a = 28.21708 b = 0.00000

========================= interface ============================ i = 3 a = 38.42530 b = 0.00000

---------------------- model level ------- (data) ---------- j - 1

========================= interface ============================ i - 1

---------------------- model level ------- (data) ---------- j

========================= interface ============================ i

---------------------- model level ------- (data) ---------- j + 1

========================= interface ============================ i = 59 a = 7.36774 b = 0.99402

---------------------- model level ------- (data) ---------- j = 59 a = 3.68387 b = 0.99582

========================= interface ============================ i = 60 a = 0.00000 b = 0.99763

---------------------- model level ------- (data) ---------- j = 60 = J a = 0.00000 b = 0.99881

======================= MODEL SURFACE ========================== i = 61 = I a = 0.00000 b = 1.00000

Figure 12.7: Model levels for the 60 layers presented in Figure 12.6, with ak and ak atinterfaces are highlighted in red.

is defined by

pk =1

2(pk−1/2 + pk+1/2) (12.15)

for k = 1, 2, .., NLEV . The vertical coordinate is η = η(p, pS) and has the boundary value η(0, pS) = 0

at the top of the atmosphere and η(pS , pS) = 1 at the Earth’s surface. Two different vertical resolutions

with hybrid coordinates are presented in Figure 12.6.

12.3 Horizontal coordinates

12.3.1 Finite differences

Most of the finite difference schemes in this compendium are made on cartesian grids, which are both

orthogonal and of constant grid sizes as illustrated in Figure 12.8.

The drawback of the cartesian grids is that they do not change in space. Ocean and atmospheric

circulation models do not have cartesian grids apart from some academic ones used in courses on numer-

ical methods like in the present compendium. A typical grid will at least have a latitude dependence of

∆x taking account that the distances between longitudes decrease with latitude. These grids are called

curvilinear, but can still be orthogonal preserve right angles between the two coordinates at every point

of interest in the grid. Figure 12.9 an example of this. The region bounded by two adjacent segments of

Page 94: Numerical Methods

94 CHAPTER 12. MODEL COORDINATES

Figure 12.8: A Cartesian grid. Simplest possible grid.

one of the curvilinear coordinates and two adjacent segments of the other curvilinear coordinates will be

transformable to a rectangle. An orthogonal curvilinear coordinate system permits the design of a grid

system in a complicated region such as that bounded by a shoreline or "bending" the north pole to a land

position. The vertical resolution ∆zk will typically have a thinner grid cells near the surface between the

ocean and the atmosphere.

12.3.2 Finite elements

In designing a numerical weather prediction model, one of the most fundamental aspects is the choice of

discretisation technique in each of the spatial dimensions. In the vertical, by far the most popular choice

is the finite difference method; while in the horizontal, both finite-difference and (especially for global

models) spectral methods are widely employed. A third possibility is the finite element method.

The essence of the finite element method can be seen by considering various ways of representing a

function u(x) on an interval a ≤ x ≤ b. In the finite-difference method the function is defined only on

a set of grid points; i.e. u(xj) is defined for a set of xj , but there is no explicit information about how

the function behaves between the grid points. In the spectral method, on the other hand, the function is

defined in terms of a finite set of basis functions:

u(x) =N∑k=0

akek (12.16)

where the basis functions ek (x) are global (e.g. Fourier series, or spherical harmonics for two-dimensional

functions on the surface of a sphere), and the ak are the spectral coefficients. Equation (12.16) defines

u(x) everywhere on the interval, and the representation is independent of any set of grid points.

Page 95: Numerical Methods

12.3. HORIZONTAL COORDINATES 95

Figure 12.9: The orthogonal curvilinear ORCA12 ocean grid for the NEMO model, whichis tripolar with two north poles in order to avoid the north pole to be an ocean point. Thecolour scale indicates the grid size in km.

In the finite-element method, the function is again in terms of a finite set of basis functions:

u(x) =

N∑k=0

akek

but this time basis functions ek (x) are local, i.e. they are non-zero only on a small-sub-interval. As in

the spectral method, the ak are the coefficients of the basis functions, and u(x) is defined everywhere;

but as in the finite-difference method, there is an underlying mesh of grid points (nodes) involved in the

representation.

Page 96: Numerical Methods

96 CHAPTER 12. MODEL COORDINATES

Figure 12.10: Finite elements for an ocean general circulation model

Figure 12.11: The ICOM finite element model with time and space adaptive mesh.

Page 97: Numerical Methods

Chapter 13

3D modelling

u u u

uu

uu

u

u

v

v

v

v v

v v

v

h h h

h h h h

hhhh

h

ii-1 ii-1 I1 1 2 2 II-1i+1 I-1i+1

h

h

h

h

h

h hhhh

hhh

v

v

vvvv v

vvvvv

u

u

u

u

u

uuu

u u u

j

j-1

j

j-1

J

1

1

2

2

J

J-1

j+1

J-1

j+1

Figure 13.1: Horizontal view (longitude-latitude) of a possible rectangular model grid withland as yellow grid boxes. Only the non-zero variables are shown. I and J are the totalnumber of grid boxes in the zonal and meridional direction respectively.

97

Page 98: Numerical Methods

98 CHAPTER 13. 3D MODELLING

The 3D models of the ocean circulation known today as Ocean General Circulation Models (OGCMs)

are increasing in complexity as modellers improve them. The numerical improvements can be such as

higher order numerical schemes, advanced model grids, etc. The improvement of the physics can be to

replace the hydrostatic equations by the non-hydrostatic, to change the mixing parameterisations of the

unresolved scales, etc. All these improvements are necessary in order to continue to make more realistic

model integrations. We will in the present chapter present a 3D model of the ocean circulation as simple

as possible but still with the core of the numerics close to the OGCMs. This in order to be able to "see" the

core of the numerics of the 3D model. OGCMs have nearly all some sort of curvilinear coordinates and

some depth dependent layer thicknesses, which make the discretised equations not so easy to understand.

We have therefore discretised the equations on a rectangular cartesian C-grid as illustrated by Figures

13.3, 13.1 and 13.2. Our model is instead of on a spherical grid with a realistic bottom bathymetry on a

rectangular ocean domain with a flat bottom. We have also replaced the two tracer equations of heat and

salt by one tracer equation for the density. A real OGCM would instead compute the density with the

equation of state from the temperature and salinity and depth (pressure).

Our simplified 3D-model makes otherwise use of the usual hypothesis such as

• Boussinesq hypothesis: density variations are neglected except in their contribution to the buoy-

ancy force, which explains the ρ0 instead of ρ in the horizontal momentum Equations 13.1 and

13.2.

• Hydrostatic hypothesis: the vertical momentum equation is reduced to a balance between the

vertical pressure gradient and the buoyancy force, which removes convective processes from the

equations. The convection is instead parameterised with an increased vertical diffusion.

• Incompressibility hypothesis: the 3D divergence of the velocity is approximated to be zero.

• turbulent closure hypothesis : the turbulent fluxes (which represent the effect of small scale pro-

cesses on the large-scale) are expressed in terms of large-scale features, which is our case simple

Laplacian diffusion and viscosity.

13.1 The Equations of motion

The equations of motion that will be used are

∂u

∂t+ u

∂u

∂x+ v

∂u

∂y+ w

∂u

∂z− fv = − 1

ρ0

∂p

∂x+AH∇2u+AV

∂2u

∂z2+ F x (13.1)

∂v

∂t+ u

∂v

∂x+ v

∂v

∂y+ w

∂v

∂z+ fu = − 1

ρ0

∂p

∂y+AH∇2v +AV

∂2v

∂z2+ F y (13.2)

0 = −∂p∂z

+ ρg (13.3)

∂u

∂x+∂v

∂y+∂w

∂z= 0 (13.4)

∂ρ

∂t+ V · ∇ρ = KH∇2ρ+KV

∂2ρ

∂z2+ C (13.5)

Page 99: Numerical Methods

13.1. THE EQUATIONS OF MOTION 99

u u u

uu

uu

u

u

w

w

w

w

w

w w

ii-1 ii-1 I1 1 2 2 II-1i+1 I-1i+1

w

w

wwww w

wwwww

u

u

u

u

u

uuu

u u u

k

k-1

k

k-1

K

1

1

2

2

K

K-1

k+1

K-1

k+1

0

w

w w w w

w w w w

w

uuuu

w

Figure 13.2: Zonal-vertical view of the model grid with land/bottom as yellow grid boxes.Only the non-zero variables are shown. K is the total number of vertical depth layers. Notethat the vertical index k is increasing with depth and hence of opposite direction to thedirection of the z-coordinate.

Page 100: Numerical Methods

100 CHAPTER 13. 3D MODELLING

Before discretising the above equations we need to rewire them on the form

∂u

∂t= ξv − w∂u

∂x− ∂E

∂x+AH∇2u+AV

∂2u

∂z2+ F x (13.6)

∂v

∂t= −ξu− w∂v

∂z− ∂E

∂y+AH∇2v +AV

∂2v

∂z2+ F y (13.7)

0 = −∂p∂z

+ ρg (13.8)

∂u

∂x+∂v

∂y+∂w

∂z= 0 (13.9)

∂ρ

∂t= −∇ · (Vρ) +KH∇2ρ+KV

∂2ρ

∂z2+ C (13.10)

where the absolute vorticity is

ξ ≡ ∂v

∂x− ∂u

∂y+ f (13.11)

and the energy function is defined as

E ≡ p

ρ0+

1

2

(u2 + v2

)(13.12)

The discretised version of these equations with centred finite difference are

un+1i,j,k = un−1

i,j,k + 2∆t

1

4

[ξni,j,k

(vni,j,k + vni+1,j,k

)+ ξni,j−1,k

(vni,j−1,k + vni+1,j−1,k

)]−(wni,j,k + wni+1,j,k + wni,j,k−1 + wni+1,j,k−1

) uni,j,k−1 − uni,j,k+1

8∆z−Eni+1,j,k − Eni,j,k

∆x

(13.13)

vn+1i,j,k = vn−1

i,j,k + 2∆t

− 1

4

[ξni,j,k

(uni,j,k + uni,j+1,k

)+ ξni−1,j,k

(uni−1,j,k + uni−1,j+1,k

)]−(wni,j,k + wni,j+1,k + wni,j,k−1 + wni,j+1,k−1

) vni,j,k−1 − vni,j,k+1

8∆z−Eni,j+1,k − Eni,j,k

∆y

(13.14)

pi,j,k =

k−1∑k′=1

gρi,j,k′∆z + gρi,j,k∆z/2 + gρi,j,1ηi,j (13.15)

wi,j,k−1 = wi,j,k −Ui,j − Ui−1,j

∆x− Vi,j − Vi,j−1

∆y(13.16)

ηn+1i,j = ηn−1

i,j + 2∆twi,j,0 (13.17)

where the absolute vorticity is located between the corners of the T-boxes as illustrated by Figures 13.3

and 13.1.

ξi,j,k ≡ f +vi+1,j,k − vi,j,k

∆x−ui,j+1,k − ui,j,k

∆y(13.18)

The fluxes U and V are defined in the same points as the velocity components u and v are located:

Ui,j,k ≡ ui,j,k1

2(hi,j,k + hi+1,j,k) (13.19)

Vi,j,k ≡ vi,j,k1

2(hi,j,k + hi,j+1,k) (13.20)

Page 101: Numerical Methods

13.2. THE TRACER EQUATION 101

The grid cell thickness is constant at all depths except for the surface layer where the sea surface elevation

is included

hi,j,k = ∆z + ηi,j for k = 1 (13.21)

hi,j,k = ∆z for k 6= 1 (13.22)

The gradient operator will act on the quantity E defined at the locations where h is defined:

E ≡pi,j,kρ0

+1

2

[1

2

(u2i,j,k + u2

i−1,j,k

)+

1

2

(v2i,j,k + v2

i,j−1,k

)](13.23)

uu

u

u

u u

v

v

v

v

v

v

h

h h

h

i i+1i

j

i-1 i+1

j

j+1

j-1

j+1

Figure 13.3: C-grid with points for the zonal velocity u,meridional velocity v, water or aircolumn height h and vorticity ξ.

13.2 The tracer Equation

The tracer equation describes the rate of change of a tracer such as e.g. potential temperature or salt in

the ocean or the water vapour in the atmosphere or any other passive tracer that is advected and diffused

in the ocean or atmosphere. This tracer equation with a simple parameterisation of the diffusion can be

expressed as

∂T

∂t+ V · ∇T = KH∇2T +KV

∂2T

∂z2+ C (13.24)

Page 102: Numerical Methods

102 CHAPTER 13. 3D MODELLING

where KH and KV are the horizontal and vertical diffusion coefficients and C a possible source term

such as the heat flux between the atmosphere and the ocean. The continuity equation is in the case of

ui,j,kui-1,j,k

vi,j-1,k

vi,j,k

Ti,j,k

Ti,j+1,k

Ti-1,j,k

Ti,j-1,k

Ti+1,j,k

∆x

∆y

Ui,j,k

wi,j,k -1

wi,j,k

Ti,j,k

Ti,j,k+1

Ti,j,k -1

∆x

∆z

Wi,j,k

Figure 13.4: Horizontal (left) and vertical (right) views of the tracer equation applied on aC-grid. The blue arrows illustrate the tracer flux Ui,j,k = ui,j,k

12 (Ti,j,k + Ti+1,j,k) ∆y∆z

and Wi,j,k ≡ wi,j,k+112 (Ti,j,k + Ti,j,k+1) ∆x∆y .

incompressibility as in the ocean

∇ ·V =∂u

∂x+∂v

∂y+∂w

∂z= 0 (13.25)

The tracer Equation 13.24 can now be rewritten by incorporating the continuity Equation 13.25 to

∂T

∂t+∇· (VT ) = KH∇2T +KV

∂2T

∂z2+ C (13.26)

13.3 Discretised on a cartesian grid

This tracer equation will now be discretised on a C-grid illustrated in Figure 13.4. Let us start with

the term ∇· (VT ) in Equation 13.26, which simply expresses the divergence of the tracer flux. The

discretised version of this term is simply the sum of all the tracer transports in and out of a grid box dived

Page 103: Numerical Methods

13.4. DISCRETISED ON AN ORTHOGONAL CURVILINEAR GRID 103

by the volume of the grid box. The tracer flux across the grid wall, where ui,j,k is located becomes

Uni,j,k ≡ uni,j,k1

2

(Tni,j,k + Tni+1,j,k

)∆y∆z

V ni,j,k ≡ vni,j,k

1

2

(Tni,j,k + Tni,j+1,k

)∆x∆z

Wni,j,k ≡ wni,j,k+1

1

2

(Tni,j,k + Tni,j,k+1

)∆x∆y

(13.27)

which leads to

∇· (VT )→(Ui,j,k − Ui−1,j,k + Vi,j,k − Vi,j−1,k +Wi,j,k−1 −Wi,j,k)

∆x∆y∆z(13.28)

The discretised tracer equation becomes with a centred leap-frog time scheme and the diffusion terms at

time step n− 1 as required by stability we get

Tn+1i,j,k = Tn−1

i,j,k + 2∆t

[

(Uni,j,k − Uni−1,j,k + V n

i,j,k − V ni,j−1,k +Wn

i,j,k−1 −Wni,j,k

)∆x∆y∆z

+KH

Tn−1i−1,j,k − 2Tn−1

i,j,k + Tn−1i+1,j,k

(∆x)2 +Tn−1i,j−1,k − 2Tn−1

i,j,k + Tn−1i,j+1,k

(∆y)2

+KV

Tn−1i,j,k−1 − 2Tn−1

i,j,k + Tn−1i,j,k+1

(∆z)2 ) + Cni,j,k

](13.29)

13.4 Discretised on an orthogonal curvilinear grid

A drawback of the above discretised tracer equation is that it requires cartesian grids, which do not

change in space. Ocean and atmospheric circulation models do not have cartesian grids apart from some

academic ones used in courses on numerical methods like in the present compendium.

It is therefore advantageously to make the finite differences directly on the diffusive tracer fluxes.

Let U, V,W now instead be the sum of the advective and diffusive fluxes so that

Uni,j,k ≡

[uni,j,k

1

2

(Tni,j,k + Tni+1,j,k

)−KH

Tn−1i+1,j,k − T

n−1i,j,k

∆x

]∆yi,j∆zk

V ni,j,k ≡

[vni,j,k

1

2

(Tni,j,k + Tni,j+1,k

)−KH

Tn−1i,j+1,k − T

n−1i,j,k

∆y

]∆xi,j∆zk

Wni,j,k ≡

[wni,j,k+1

1

2

(Tni,j,k + Tni,j,k+1

)−KV k

Tn−1i,j,k − T

n−1i,j,k+1

∆zk

]∆xi,j∆yi,j

(13.30)

Note that we have written KV k with an index k, which indicated that we can let the vertical diffusion

coefficient vary with depth. The vertical diffusion coefficient KV k can be assumed to be either constant,

or a function of the local Richardson number, or computed from a turbulent closure model (either TKE

Page 104: Numerical Methods

104 CHAPTER 13. 3D MODELLING

or KPP formulation).

The discretised tracer equation becomes now

Tn+1i,j,k = Tn−1

i,j,k − 2∆t

[Uni,j,k − Uni−1,j,k + V n

i,j,k − V ni,j−1,k +Wn

i,j,k −Wni,j,k−1

∆xi,j∆yi,j∆zk− Ci,j,k

](13.31)

Noth the horizontal indices on the grid lengths ∆xi,j and ∆yi,j in order to fit a curvilinear grid such as

the on in Figure 12.9. The vertical grid thickness ∆zk will however have a vertical index since it only

varies vertically with the exception of the bottom box that might vary in order to fit an exact depth of the

ocean.

Page 105: Numerical Methods

Chapter 14

Spherical Harmonics

In modern atmospheric general circulation models (AGCMs), the horizontal spatial representation of

scalar dynamic and thermodynamic fields is based on truncated series of spherical harmonic functions,

the nature of the underlying two-dimensional horizontal physical grid, also known as a transform grid, is

tightly coupled to the parameters of the spherical harmonic expansion itself.

14.1 Spectral methods

The numerical integration methods discussed thus far are based on the discrete representation of the data

on a grid or mesh of points covering the space over which a prediction of the variables is desired. Then

a local time derivatives of the quantities to be predicted are determined by expressing the horizontal

and vertical advection terms, sources etc., in finite difference form. Finally, the time extrapolation is

achieved by one of many possible algorithms, for example leapfrog. The finite difference technique

has a number of associated problems such as truncation error, linear and non-linear instability. Despite

these difficulties, the finite difference method has been the most practical method of producing forecasts

numerically from the dynamical equations. There is another approach called the spectral method which

avoids some of the difficulties cited previously, in particular, non-linear instability; however the method

is less versatile and the required computations are comparatively time consuming. In a general sense,

the mode of representation of data depends on the nature of the data and the shape of the region over

which the representation is desired. An alternative to depiction on a mesh or grid of discrete points is

a representation in the form of a series of orthogonal functions. This requires the determination of the

coefficients of these functions, and the representation is said to be spectral representation or a series

expansion in wave number space. When such functions are used, the space derivatives can be evaluated

analytically, eliminating the need for approximating them with finite differences.

The operational ECMWF forecast model uses a spectral technique for its horizontal discretisation.

Over the past decade or so this technique has become the most widely used method of integrating the

governing equations of numerical weather prediction over hemispheric or global domains. Following

the development of efficient transform methods by Eliasen et al. (1970) and Orszag (1970), and the

construction and testing of multi-level primitive-equation models (e.g. Bourke, 1974; Hoskins and Sim-

mons, 1975; Daley et al., 1976), spectral models were introduced for operational forecasting in Australia

105

Page 106: Numerical Methods

106 CHAPTER 14. SPHERICAL HARMONICS

and Canada during 1976. The technique has been utilized operationally in the USA since 1980, in France

since 1982, and in Japan and at ECMWF since 1983. The method is also extensively used by groups

involved in climate modelling.

A comprehensive account of the technique has been given by Machenhauer (1979), and a further

description of the method has been given by Jarraud and Simmons (1984). Reference should be made to

these or other reviews for further discussion of most of the points covered below.

Associated Legendre polynomials

In mathematics, the associated Legendre functions are the canonical solutions of the general Legendre

equationd

dx

[(1− x2)

d

dxPmn (x)

]= −n(n+ 1)Pmn (14.1)

where the indices n and m are referred to as the degree and order of the associated Legendre function

respectively. The argument can be reparameterized in terms of angles, letting x = cosθ and θ = π/2−ϕ,

which is presented in Table 14.1 and in Figure 14.1.

Table 14.1: The associated Legendre polynomials Pmn in x = cosθ, where θ = π/2− ϕ isthe colatitude.

m = 0 m = 1 m = 2 m = 3

n = 0 1n = 1 cos θ − sin θn = 2 1

2(3 cos2 θ − 1) −3 cos θ sin θ −3 sin2 θn = 3 1

2(5 cos3 θ − 3 cos θ) −32(5 cos2 θ − 1) sin θ 15 cos θ sin2 θ −15 sin3 θ

14.2 Spherical harmonics

Global atmospheric models use as basis functions spherical harmonics, which are the eigenfunctions of

the Laplace equation on the sphere:

∇2Y mn =

1

a2

[1

cos2ϕ

∂2Y mn

∂λ2+

1

cosϕ

∂ϕ

(cosϕ

∂Y mn

∂ϕ

)]= −n(n+ 1)

a2Y mn (14.2)

The spherical harmonics are products of Fourier series in longitude (λ) and associated Legendre

polynomials in latitude (ϕ):

Y mn (λ, ϕ) = Pmn (µ) eimλ (14.3)

where µ = sinϕ, m is the zonal wavenumber and n is the "total" wavenumber in spherical coordinates

(as suggested by the Laplace equation).

Page 107: Numerical Methods

14.2. SPHERICAL HARMONICS 107

P

Latitude

0

.5

1.0

1.5

2.0

2.5

-.5

-1.0

-1.5

-2.0

-2.50-20-40-60-80 20 40 60 80

00 00 00 00 00 00 00 00

01 0101

01

01

01

010102

02

02

02

0202

02

02

02

03

03

03

0303

0303

03

03

04

04

0404

04 04

04 04

04

04

11

11

1111 11 11

11

11

12

1212 12

12

12

12

1212

12

12

13

13

13 13

13

13

13

13

13

13

13

13

13

13

13

1414

14

14

14

14

14

14

14

14

14

14

14

14

14

14

14

14 14

1414

P

Latitude

0102030405060708090

100

-10-20-30

0-20-40-60-80 20 40 60 80

00 00 00 00 00 00 00 0001 01 01 01 01 01 01 0102 02 02 02 02 02 02 0203 03 03 03 03 03 03 0304 04 04 04 04 04 04 0411 11 11 11 11 11 11 1112 12 12 12 12 12 12 1213 13 13 13 13 13 13 1314 14 14 14 14 1414 1422 22 22 22 22 22 22 2223 23

23 2323

23 232324

2424

24

24

24

2424

33 3333

33 3333

333334

34

34

34

34

34

34

34

34

3444

44

44

44

44

44

44

44

44

44

44

4444

Figure 14.1: The first 15 associated Legendre polynomials Pmn . The first index on thecurves indicate the order of the polynomial and the second index the degree. The top figureshows m = 1, 2 for n = 1, 2, 3, 4. The bottom figure shows m = 1, 2, 3, 4 for n = 1, 2, 3, 4.Each colour correspond to a separate order (m) of the polynomial Pmn .

Page 108: Numerical Methods

108 CHAPTER 14. SPHERICAL HARMONICS

Figure 14.2: The triangular truncation in the (m,n) wavenumber space prescribes a tri-angular region of spherical harmonic modes indicated by the filled squares. Modes outsideof this triangle are set to (open circles).

In the usual application of the method, the basic prognostic variables are vorticity, divergence, tem-

perature, a humidity variable, and the logarithm of surface pressure. Their horizontal representation is

in terms of truncated series of spherical harmonic functions, whose variation is described by sines and

cosines in the east-west and by associated Legendre functions in the north-south. The horizontal variation

of a variable U is thus given by

U (λ, ϕ, t) =

N∑n=0

n∑m=−n

Umn (t)Y mn (λ, ϕ) (14.4)

the spatial resolution is uniform throughout the sphere. This has a major advantage over finite differences

based on a latitude-longitude grid, where the convergence of the meridians at the poles requires very

small time steps. Although there are solutions for this "pole problem" for finite differences, the natural

approach to solve the pole problem for global models is the use of spherical harmonics.

It is becoming increasingly common for the so-called "triangular" truncation of the expansion to be

used (Figure 14.2). This truncation is defined by M = N = constant , and gives uniform resolution

over the sphere. The symbol "TN" is the usual way of defining the resolution of such a truncation; being

the smallest total wave number retained in the expansion. The smallest resolved half-wavelength in any

particular direction is then πa/N (320 km for T63, 190 km for T106), although the corresponding lateral

variation is of larger scale.

Derivatives of a spectral represented variable U are known analytically

∂U

∂λ=

N∑n=0

n∑m=−n

imUmn Ymn

Page 109: Numerical Methods

14.3. THE SPECTRAL TRANSFORM METHOD 109

and∂U

∂ϕ=

N∑n=0

n∑m=−n

Umn∂Pmn∂ϕ

eimλ

14.3 The spectral transform method

In a spectral model, a variable, ξ(λ, φ), is represented by a truncated series of spherical harmonic func-

tions. This can be expressed as

ξmn =J∑j=1

ξm(φj)Pmn (φj), (14.5)

where j is the latitudinal index, ξm(φj) is obtained by a fast fourier transform of ξ(λ, φ) and Pmn (φj) is

the associated Legendre functions.

The grid point values are obtained by the inverse transform

ξm(φ) =

N(m)∑n=|m|

ξmn Pmn (φ), (14.6)

followed by an inverse fast fourier transform to obtain ξ(λ, φ).

In a spectral model, the explicit time steps and horizontal gradients are performed in spectral space.

The tendencies of the equations are however evaluated in grid point space. One benefit when repre-

senting the variables in spectral space is that horizontal derivatives are continuously represented, i.e. no

finite differencing is needed to evaluate gradients. The methods used to perform the spherical harmonic

transforms are however well out of the scope of this project. We have therefore chosen to use an already

existing library to carry out the spectral transforms.

14.4 Application to the shallow water equations on a sphere

The momentum and mass continuity equations governing the motion of a rotating, homogenous, incom-

pressible and hydrostatic fluid can be written on vector form as

dV

dt= −fk×V −∇Φ + ν∇2V, (14.7)

dt= −Φ∇ ·V, (14.8)

where V = (u, v) is the horizontal velocity vector, Φ is the geopotential height, f is the coriolis param-

eter and ν is the horizontal diffusion coefficient. Furthermore,

d

dt=

∂t+ V · ∇, (14.9)

and the∇ operator is defined in spherical coordinates as

Page 110: Numerical Methods

110 CHAPTER 14. SPHERICAL HARMONICS

∇ =1

a cosφ

∂λ+

1

a

∂φ, (14.10)

where a is the earth radius, λ is the longitude coordinate and φ is the latitude coordinate.

The above equations describe the shallow-water equations in the u, v,Φ system. In the model, we

use another form of these equations. By introducing the relative vorticity ζ and horizontal divergence δ,

the equations can be transformed into the the ζ, δ,Φ system. We do not derive these equations here since

it is relatively straightforward.

By introducing

ξ = k · (∇×V), (14.11)

and

δ = ∇ ·V, (14.12)

one can obtain the following set of equations (with µ = sinφ)

∂η

∂t= − 1

a(1− µ2)

∂λUη +

1

a

∂µV η, (14.13)

∂δ

∂t=

1

a(1− µ2)

∂λUη − 1

a

∂µV η +∇2

(Φ +

U2 + V 2

2(1− µ2)

), (14.14)

∂Φ

∂t= − 1

a(1− µ2)

∂λUΦ +

1

a

∂µV Φ, (14.15)

where now η = ξ + f (absolute vorticity including earth rotation) and (U, V ) = (u, v) cosφ.

Page 111: Numerical Methods

Chapter 15

Practical computer exercises

15.1 Exercise 1 and 2

The aim of the exercises is to concretise the theory presented in the lectures and to give a better under-

standing of basic numerical methods. The leapfrog scheme, the Euler forward scheme and the upwind

scheme will be studied applied on the advection equation, diffusion equation, and shallow-water equa-

tions.

15.2 Theory

The solution interval is in all cases 0 ≤ x < 1, with the periodic boundary condition u(0, t) = u(1, t).

The relative error is defined as ||u − v||/||v||, where v(x, t) is the analytic solution, and the norm is

defined by

||f || =

(∆x

N∑i=1

|fi|2)1/2

.

The advection equation is∂u

∂t+ c

∂u

∂x= 0,

the diffusion equation is∂u

∂t− µ∂

2u

∂x2= 0,

and the shallow-water equations in the one-dimenisonal case, are∂u

∂t= −g∂h

∂x,

∂h

∂t= −H∂u

∂x.

111

Page 112: Numerical Methods

112 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

15.3 Technical aspects

We will use Fortran 90/95 to solve the numerical exercises. Write your code in a plain text file with the

extension .f90. To run it, the computers at MISU are equipped with the gfortran compiler. If your

code is in a file named exercise1.f90, you compile the code by opening a terminal and typing

gfortran exercise1.f90

Assuming there are no error messages from the code, this creates the program a.out which can be run

by typing

./a.out

If you do get error messages, they can sometimes be quite puzzling themselves. To get better informa-

tion about where the error occurred, you may add the flags -g -traceback. Another useful flag is

-fbounds-check which checks your code for index related errors, for instance if you try to evaluate

the 6th element in a vector with only 5 elements. Putting this together:

gfortran -g -traceback -fbounds-check exercise1.f90

Note: The error checking slows the computations down. However, these exercises should not be so de-

manding.

It is convenient for everyone if we all use similar notation. I therefore recommend this variable

convention, or similar:

u velocity in x-direction

v velocity in y-direction

h the height of the field

i index in x-direction

j index in y-direction

n index in time

nx number of points in x-direction

ny number of points in y-direction

nt number of time steps

dx grid spacing in x-direction

dy grid spacing in y-direction

dt length of time step

g gravity

H mean depth

In the following examples, I use ic to denote the current i-point, and ip = ic + 1, and im =

ic - 1. Similar is applied for j and n-points.

A simple way of programming the advection equation discretized on a leapfrog scheme is as follows.

Page 113: Numerical Methods

15.4. REPORT 113

DO nc=2,NT-1

np = nc+1 ; nm = nc-1

DO ic=2,NX-1

ip = ic+1 ; im = ic-1

u(ic,np) = u(ic,nm) - cfl * (u(ip,nc) - u(im,nc))

END DO

END DO

Note that the boundary points are not included. These can be iterated seperately by including

u(1,np) = u(1,nm) - cfl * (u(2,nc) - u(nx-1,nc));

u(nx,np)= u(nx,nm) - cfl * (u(2,nc) - u(nx-1,nc));

in the time loop. Another way is to add the IF-statement

IF (ic == 1) THEN

im = NX

ELSE IF (ic == NX) THEN

ip = 1

END IF

in your loop.

For plotting, you may use software of your choice. Computers at MISU are equipped with necessary

software for MATLAB and Python. Appendix A contains a function to read a matrix from a Fortran file

into MATLAB. It may be copied from this document and used. The function, and a similar for Python,

can also be accessed from the course Mondo-page.

15.4 Report

Each student should write two reports. The first should cover Exercises 1–5 and the second Exercise 6.

The numerical experiments should be documented with selected figures of u (and, for the shallow-water

equations, h) as a function of x for appropriate fixed values of t. In some cases 3D plots with u as a

function of x, t are also useful. It should be clear what the figures show. The results should be analysed

and commented. There is no need to include any code in the report, but please explain what sort of

numerical scheme is used for what and why. The reports may be written in either Swedish or English.

Page 114: Numerical Methods

114 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

Please hand in the first report no later than Friday 9 September 2011 at 15:00, and the second no

later than Monday 16 September 2011. If you decide to send the reports via e-mail, please use the .pdf

format. Formatted Word (.docx), OpenOffice (.odt), or similar are not accepted.

Page 115: Numerical Methods

15.5. THEORETICAL EXERCISES 115

15.5 Theoretical exercises

Exercise 1 – Leapfrog

Study the leapfrog scheme for the advection equation.

a) Give the leapfrog scheme (centred scheme with 2nd order accuracy in space and time).

b) Derive the stability criterion.

c) Discuss the computational mode and how it can be avoided.

Exercise 2 – Upwind

Study the upwind scheme for the advection equation.

a) Give the upwind scheme (uncentred scheme with 1st order accuracy in space and time).

b) Derive the stability condition.

Exercise 3 – Euler forward

Study the Euler forward scheme for the diffusion equation.

a) Derive the stability criterion of the Euler forward scheme for the diffusion equation:

un+1j − unj

∆t= µ

unj+1 − 2unj + unj−1

(∆x)2.

b) Discuss how the time step should be chosen. Why is it good to choose a smaller time step than

that given by the stability criterion? Hint: Study how the amplification factor depends on the

wavelength, especially the highest frequencies.

15.6 Experimental exercises

Exercise 4 – Advection

Study the the advection equation using a simple numerical model. Write a program that can solve the

advection equation with two different schemes: the leapfrog scheme and the upwind scheme.

a) Run the program with the resolution ∆x = 0.1 and the CFL-numbers 0.9, 1.0 and 1.1. Use a

cosine wave as initial condition:

u(x, t = 0) = cos(2πx).

Solve the problem both with the leapfrog scheme and the upwind scheme, initialising the leapfrog

scheme with a single Euler forward step. Plot the results obtained with both schemes and the

analytic solution in the same figure. Comment on both the phase error and the amplitude error.

Also show how the relative error develops in time.

Page 116: Numerical Methods

116 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

b) Run the program with the resolution ∆x = 0.02 and the CFL-number 0.9. Use a cosine pulse as

initial condition:

u(x, t = 0) =

12 + 1

2 cos [10π(x− 0.5)] , for 0.4 ≤ x ≤ 0.6

0, elsewhere

Solve the problem both with the leapfrog scheme and the upwind scheme. Initialise the leapfrog

scheme both with a single Euler forward step, and with a constant step: u2j = u1

j . Try to identify

the computational mode. (For this, 3D plots of u as a function of x, t are useful.)

Exercise 5 – Diffusion

Study the diffusion equation using a simple numerical model. Write a program that can solve the diffu-

sion equation using the Euler forward scheme. Set ∆x = 0.05 and try with three different time steps:

the critical value (∆x)2/2µ permitted by the stability criterion, a value slightly larger than the critical

one, and half the critical value.

Run the program with two different inital conditions:

• rectangular pulse:

u1i =

1, for 0 ≤ x ≤ 0.5

0, for 0.5 < x < 1

• spike: u = 1 in a single grid point at x = 0.5, and u = 0 in all other grid points.

Page 117: Numerical Methods

15.6. EXPERIMENTAL EXERCISES 117

Exercise 6 – 1D Shallow-Water model

Study one-dimensional gravity waves. Gravity waves can be described by the shallow-water equations.

a) Write a program that solves the 1D shallow water equations given in the Theory section. Discretise

using the leapfrog scheme on an unstaggered grid. Set H = g = 1 (thus c =√gH = 1) to

simplify the system. Run the program with ∆x = 0.025 and the CFL-number 0.9. (The CFL-

number is defined as c ·∆t/∆x.) Initialise the leapfrog scheme with a single Euler forward step,

and use the following initial conditions which describes a travelling pulse:

h(x, t = 0) =

12 + 1

2 cos [10π(x− 0.5)] , for 0.4 ≤ x ≤ 0.6

0, elsewhere

u(x, t = 0) = h(x, t = 0)

Interpret the results physically.

b) Rewrite the program using an staggered grid, with h and u defined in different points. Run the

program and try to find the stability limit for the time step. Then choose the time step 10 % smaller

than the stability limit, and use the travelling pulse as initial condition. Use both the resolution of

the previous subexercise and half of that resolution. Compare the accuracy of the solution with

the previous solution obtained on an A-grid. Discuss the difference between the two results and

the result from the previous subexercise. Note that ∆x is the distance between two height points

(and also two velocity points).

Exercise 7

The aim of this exercise is to solve the linearised shallow water equations, 1D and 2D, with some stan-

dard numerical methods, and study atmospheric and oceanographic processes.

Theory

The linearized shallow water equations in two dimensions including rotation and physical parameterisa-

tions are

∂u

∂t= fv − g∂h

∂x+ Fu (15.1)

∂v

∂t= −fu− g∂h

∂y+ Fv (15.2)

∂h

∂t= −H

(∂u

∂x+∂v

∂y

)+ Fh, (15.3)

Physical parameterisations (so called model physics), Fu, Fv and Fh may for instance be horizontal

diffusion and/or drag forcing. Realistic values of g, H and f should be used in order to gain understand-

Page 118: Numerical Methods

118 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

ing of real atmospheric and oceanographic problems. For instance, the North Atlantic ocean is 3000

km across and 4 km deep. Diffusion or drag is to be added to the velocity fields only. The 1D case is

obtained by simply neglecting ∂/∂y-derivatives.

Technical aspects

The model is to be programmed in Fortran 90/95 standard. Try to make the code clear and well struc-

tured, and use common notations (u for zonal velocity, dt for time step, and so on). See Appendix A for

hints.

For plotting you may use a technique of your choice, e.g. MATLAB/Octave, Python, or other. In-

cluded in Appendix B you will find a MATLAB function that reads Fortran unformatted files. However,

the function may need to be tailored to fit your files.

Report

In order to complete the shallow water exercise each student should write a concise report. This report

should live up to general MISU demands (self-contained, structured, etc.). Include selected figures and

illustrations. Long mathematical derivations or parts of the code are not welcome in the report. Try to

write the report so that someone knowledgable about the course content, but has not taken the course,

might understand.

Please hand in the report no later than 30 September 2011. If you choose to send it via e-mail, please

use .pdf format, and not .docx, .odt, or similar.

Page 119: Numerical Methods

15.7. 1D SHALLOW WATER MODEL EXERCISES 119

15.7 1D Shallow water model exercises

Here you should develop a 1D shallow water model that includes rotation, relaxation zone, and Asselin

filtering on a staggered grid.

a) Write the code for the model. To do this you need to add an extra velocity variable to the 1D

model developed earlier in the course and rewrite your schemes to a staggered form. Also, the

model should have solid boundaries, and not periodic as before.

b) Run the model without rotation (f = 0) and with the following initial conditions:

u(x, 0) = 0 (15.4)

v(x, 0) = 0 (15.5)

h(x, 0) = h0e−(x/LW )2 , (15.6)

where −L/2 ≤ x ≤ L/2 and LW ≈ L/7. Describe your results.

c) Study Rossby adjustment to geostrophic balance (Holton chapter 7.6) by running the same ex-

periment with a realistic rotation (what should f be according to your total integration time,

T = NT∆t?).

d) Change your initial conditions to:

u (x, 0) = 0 (15.7)

v (x, 0) = 0 (15.8)

h (x, 0) =

h0 if |x| ≤ LW0 if |x| > LW

(15.9)

What occurs? Explain the new phenomena. What happens at the boundaries?

e) How do gravity waves affect the results? Try running the same experiment with a relaxation at the

boundaries and explain the difference. The relaxation can be parameterised in the following way:

(ud, vd) =

(1− d∆t

τ

)(u, v) (15.10)

where τ is a relaxation time-scale (s−1) and d is the damping value. Construct the function so

that d = 0 in the interior of the system, and d approaches 1 as you approach the boundaries. The

function may be either trigonometric or linear. Here, it is sufficient to set τ = ∆t for simplicity.

Give an explanation of what the relaxation might represent. Why do limited area models need

relaxation?

f) Apply the Asselin-filter to the previous experiment. Do you see any difference?

Page 120: Numerical Methods

120 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

15.8 2D Shallow water model exercises

Exercise 0: Fortran code of a 2D shallow water model

Write and program a linear 2D shallow water model with finite differences based on the following equa-

tions

∂u

∂t− f0v = −g∂h

∂x(15.11)

∂v

∂t+ f0u = −g∂h

∂y(15.12)

∂h

∂t+D0

(∂u

∂x+∂v

∂y

)= 0 (15.13)

Use Leap-frog time scheme but with an Euler forward for the first time step on an Arakawa C-grid

and an Asselin filter (with appropriate value of γ). Let use scales similar to the world oceans L ∼ 5 · 106

m, D0 ∼ 4000 m, g = 9.81 m s−2, f0 = 10−4 s−1. Set fixed ∆x and ∆y, and let ∆t be determined by

a CFL number, phase speed, and max(∆x,∆y). Let NX , NY be determined by L, and NT by Tmax,

which is the simulation period. This way you may alter the resolution without changing domain size (as

done in a real GCM). Construct the main time loop so that the model does not store the fields for every

time step. To simulate open boundaries you should implement a sponge (relaxation) zone to eliminate

gravity waves.

Exercise 1: Geostrophic adjustment

The purpose of this lab is to understand what controls the evolution of a disturbance initially at rest on

a rotating plane, more commonly known as geostrophic adjustment. To study this phenomena, you will

use shallow water model from previous exercise.

a) Implement an initial disturbance in the model, consisting of a discontinuity in h that is symmetric

in y. Starting from the linearized shallow water equations, derive the final steady state of sea

surface height and the velocities. Run the model until the system varies only very little in time

(steady state), and verify your results with what you obtained analytically. Tweak the parameters,

and discuss which are the most important.

b) Write down the analytical expressions for the total, kinetic, and potential energies. Implement a

Gaussian disturbance of the sea surface height instead of the discontinuity. Let the disturbance

be smaller than the domain, but make sure it is larger than the resolution. Study how the energies

(kinetic, potential, and total) vary in time. Study at least two cases, one shallow case (D0 ∼ 500m)

and one deep (D0 ∼ 10000m). Give a physical explanation of the results.

c) Run the model long enough so that the system comes to steady state. The system can be consid-

ered to be in steady state when the energy of the system changes very little in time. Repeat the

Page 121: Numerical Methods

15.8. 2D SHALLOW WATER MODEL EXERCISES 121

experiments for other depths and sizes of the disturbance. How do the results change? Try to

explain the changes and compare with theory.

Exercise 2: The role of solid boundaries

The aim of this assignment is to gain understanding of the influence solid boundaries have on geophysi-

cal flows. Although applicable to some situations in the atmosphere, the influence of lateral boundaries

is more important in the world oceans. In this assignment you will use a simple shallow water model

with solid boundaries, and look at how an initial disturbance evolves, and how a system initially at rest

evolves as you add a forcing to it.

a) Evolution of an initial disturbance

Use a Gaussian disturbance of reasonable size of the h-field centered at one of the boundaries so

that the disturbance is “cut” by the wall. Run the model.

(a) Describe the results and connect to theory. Do any particular kind of waves show up? How

can you identify those kinds of waves? (Phase speed, shape. . . )

(b) Compare model results with theoretical results. Look at a cross section of the wave, and

estimate its phase speed. Try different settings e.g. changing the resolution.

Try the experiments for two systems: North Atlantic (L = 5 · 107m, H = 4000m), and the Baltic

Sea (L = 5 · 106m, H = 80m).

b) Coastal upwelling

Model how the sea surface height changes as you add wind forcing at the surface to a closed ocean

basin. Use the shallow water model, and let the system be at rest initially. Implement a wind

forcing. The wind should be parallel to the coast and constant, but be zero some distance from

it. To find reasonable parameters, think of the Ekman number (in the momentum equations, the

Ekman number is the fraction of the stress and the Coriolis terms. If that fraction is large, then

wind stress is important.)

(a) Look at the evolution of the velocity and height field on short time scales (T ∼ 1/f ). Can you

identify a transport toward the coastline? Compare the results with theoretical predictions.

Think about how the Ekman spiral is represented in a barotropic model.

(b) Look at longer time scales. Describe and explain. Use theory. Does the model resemble a

real ocean basin?

Exercise 3: Topography and β-plane

In the past two assignments we have used constant depth and constant Coriolis force. The aim of this

assignment is to study and understand the kind of waves that are generated when D(y) or f(y) are

sloping planes of the kind D = D0 + αy and f = f0 + βy. For this assignment you should use a model

Page 122: Numerical Methods

122 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

with periodic boundary conditions in x and open boundaries (sponge) in y. The initial disturbance should

be in geostrophic balance to avoid gravity waves.

a) Derive phase speed and group velocity for Rossby waves in this linear system.

b) Define f and D. Run the model first with β-plane and constant D, and then with sloping topogra-

phy and constant f . Use theory to show that they give similar end results.

c) Pick one of the two cases above (f = f0 + βy, D = D0 or f = f0, D = D0 + αy). Run the

model for about 50 days. Describe and explain the evolution of the system. Connect to theory.

What kind of waves develop? Do they have any distinguishing properties? In which direction and

at what speed do the waves move? How does this compare with theory?

Try 4-5 different values of the wavenumber, and compare phase speed and group velocity to theo-

retical values. (Tip: To change wavenumber, change disturbance width).

d) Try some other surface of D or f that might be more realistic or just interesting.

Exercise 4: Depth-Integrated Ocean Circulation

The aim of this assignment is to study Stommel’s and/or Munk’s theories for barotropic large scale ocean

circulation. To do this, implement some features from the previous assignments and model the large scale

circulation in a closed basin. The model should include a wind forcing, β-plane, and bottom friction.

The wind forcing should be constant in x and sinusoidal in y. Use parameters suitable for a world ocean

basin, e.g. North Atlantic, North Pacific . . . .

Run the model without any friction and comment on the results. What effect does β = ∂f/∂y have

on the system? What effect does the wind forcing have? Do the results resemble theory? Why / why

not? Model limitations?

a) Use Rayleigh linear friction to parameterize bottom friction. Give a physical explanation of this

kind of friction. Describe and explain the circulation using Stommel’s theory.

b) Change the friction parameter, Γ, and describe how the results change.

c) Use Laplace friction to parameterize bottom friction. Give a physical explanation of this kind of

friction. Describe and explain the circulation using Munk’s theory.

d) Change the friction parameter, A, and describe how the results change.

If you wish to make the model more realistic: Use a non-rectangular grid where each grid box has

a certain resolution in (∆θ,∆φ) (lon/lat) coordinates, and ∆x = cosφ∆θ, ∆y = ∆φ. Remember that

forcing (wind, friction, diffusion . . . ) should then be weighted to the grid box area. Also let f = 2Ω sinφ.

Page 123: Numerical Methods

15.8. 2D SHALLOW WATER MODEL EXERCISES 123

General structure of the code

PROGRAM structure_of_code

!!------------------------------------------------------------------------------

!!

!!

!! General structure of a well written shallow water model in Fortran 90.

!! Features: Staggered grid, rotation, diffusion, and relaxation schemes.

!!

!! Author: Joakim Kjellsson,

!! At: Department of Meteorology, Stockholm University

!!

!! Last change: 14 July 2011

!!

!!

!! PS. It is good and common practice to always write a

!! few lines about what the code does and how at the top.

!!------------------------------------------------------------------------------

IMPLICIT NONE

!!------------------------------------------------------------------------------

!! Think about:

!! Explain each parameter in words and units.

!! Use common notation.

!! Do not write too much in one line.

!! Physical constants:

REAL*4, PARAMETER :: f = -----, & ! Coriolis parameter [s-1]

& g = ----- ! Gravity [m s-2]

!! Model parameters:

REAL*4, PARAMETER :: H = -----, & ! Mean depth [m]

& mu = ----- ! Diffusion coeff. [m2 s-1]

!! Grid

INTEGER*4, PARAMETER :: NX = -----, & ! Number of i-points

& NY = -----, & ! Number of j-points

Page 124: Numerical Methods

124 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

& NT = ----- ! Number of time steps

REAL*4, PARAMETER :: dx = -----, & ! Zonal grid spacing [m]

& dy = -----, & ! Merid. grid spacing [m]

& dt = ----- ! Time step [s]

!! Save data to file

CHARACTER*200 :: outFile = ----- ! Name of output file

!! Work variables

INTEGER*4 :: ic, ip, im, jc, jp, jm, nc, nm, np

REAL*4 :: du, dv, dh

!! Data matrices

REAL*4, DIMENSION(NX,NY,NT) :: u, v, h

!!------------------------------------------------------------------------------

!! Initial condition

!!------------------------------------------------------------------------------

!! Main loop

!! You might want to indent the code inside the loop to make it

!! easier to see where the loop starts and ends.

DO nc=------

np = nc+1

nm = nc-1

DO jc=-------

jp = jc+1

jm = jc-1

DO ic=-------

ip = ic+1

im = ic-1

Page 125: Numerical Methods

15.8. 2D SHALLOW WATER MODEL EXERCISES 125

! Reset

du = 0.

dv = 0.

dh = 0.

! Coriolis

du = du + -------------------

dv = dv + -------------------

! Sea surface height gradient

du = du + -------------------

dv = dv + -------------------

! Continuity

dh = dh + -------------------

! Diffusion

du = du + -------------------

dv = dv + -------------------

! Relaxation

du = du + -------------------

dv = dv + -------------------

! New time step

u(ic,jc,nt) = --------------------------

v(ic,jc,nt) = --------------------------

h(ic,jc,nt) = --------------------------

! Asselin filtering

u(ic,jc,nc) = --------------------------

v(ic,jc,nc) = --------------------------

h(ic,jc,nc) = --------------------------

! Update time index

END DO

! Don’t forget to take care of boundary conditions,

! zonally periodic, no-slip, or other.

Page 126: Numerical Methods

126 CHAPTER 15. PRACTICAL COMPUTER EXERCISES

END DO

END DO

!!------------------------------------------------------------------------------

!! Save the data to file

!!------------------------------------------------------------------------------

END PROGRAM

Page 127: Numerical Methods

127

Page 128: Numerical Methods

128 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

Appendix A

Exams at Stockholm University

Tentamen på Numeriska metoder inom meteorologin och oceanografin, 4p, inommeteorologi påbyggnadskurs, ME3570.

Fredagen den 17 september 1999, kl. 9.15!15.15

1. Betrakta funktionen u(x). Härled med hjälp av Taylorutveckling noggranheten avcentrerad differens. (6p).

2. Diskretisera vågekvationen

!

!

!

!

ut

c ux

+ = 0med centrerat schema i rummet och för

två olika scheman i tiden a) framåt!schema (Euler) och b) Leap!frog. (6p).

3. Utför stabilitetsanalys och ange dess CFL!villkor för Euler fallet. (7p).

4. Räkna ut den numeriska fashastighetens noggranhet och jämför med den verkliga förleap!frog fallet. För vilka våglängder är det minst respektive störst skillnad mellanden analytiska fashastigheten och den numeriska. (7p).

5. Integrerera numeriskt advektionsekvationen med centrerat schema för rummet ochleap!frog under 8 tidssteg (n=8). Integrera sen ett tidssteg med Euler och fortsättsen med ytterligare 8 tidssteg. Gör detta för två fall med Initialvilkoren för a)ujn= =0 1 och uj

n= =1 0 och b) ujn= =0 1 och uj

n= =1 1 . Beskriv de två simulationerna.(7p).

6. Diskretisera nedanstående ekvationer med centrerade scheman för A och C!gridd.Ledtråd: A!gridden ligger u v, ," i samma punkter och i C!gridden ligger u v, ," iolika punkter. Vad är det som saknas för att ekvationssystemet ska kunnas integrerasi tiden som en modell. (7p).

!!

!"!

!

!

!

!

!

!

ut

fvx

A u

ux

vy

wz

H# = # + $

+ + =

2

0

Page 129: Numerical Methods

129

Tentamen i Numeriska metoder inom meteorologin och oceanografin, ME3580.

Fredagen den 3 november 2000, kl. 9.00!15.00

1. Betrakta funktionen u(x). Härled med hjälp av Taylorutveckling noggrannheten avframåtdifferens. (6p)

2. Betrakta advektionsekvationen

!

!

!

!

ut

c ux

+ = 0

där ( )u u x t= , och c fashastigheten. Låt oss nu betrakta en av många möjligadiskretiseringar av advektionsekvationen som är

( )u u u

tcu u

x

jn

jn

jn

jn

jn

++ "

+ "" +

+"

=

11 1 1 1

12

20

# #

Utför stabilitets analys och diskutera. (6p)

3. Betrakta värmeekvationen

!

!

!

!

ut

Aux

A= >2

2 0;

diskretisera med centrerat schema i tiden och högerledet tas i tidssteget n!1. Utförstabilitetsanalys med hjälp av den analytiska lösningen och ange stabiltetsvillkorsamt ytterligare egenskaper hos schemat. (6p)

4. Diskretisera nedanstående ekvationer i rummet där u, v och h inte varierar med ymed centrerade scheman för A!grid.

!

!

!

!

!

!

!

!

!

!

ut

fv ghx

vt

fu

ht

Hux

" = "

+ =

+ =

0

0

Ansätt våglösningar av typen ( )e i kj x t# "$och härled den numeriska fashastigheten och

diskutera den och jämför med den analytiska fashastigheten. (6p)

5. Erlands Shallow water teori (6p)

Page 130: Numerical Methods

130 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

Meteorologiska institutionen Stockholms universitetKristofer Döös och Erland Källén

Tentamen i Numeriska metoder inom meteorologin och oceanografin, ME3580.

Torsdagen den 1 november 2001, kl. 9.00!15.00

1. Consider the function u(x). Derive with help of Taylor expansion the order of accuracy of the backwardscheme

(6p)

2. Consider the advection equation in two dimensions

! u! t

"c ! u! x

"c !u! y

=0

where u=u x,y,t and c the phase speed.

a) Discretise with centered scheme in time and space (leap frog).

b) Make a stability analysis and find under what condition the scheme is stable for the case when # x$# y .

c) Find the stability criterion for the case when # x=# y

Note: ei%"e&i%=2 cos % and ei%&e&i%=2 i sin %

(6p)

3. Consider the Poisson equation

' 2(=a x,ya) Discretise with a centered scheme in space of the second order accuracy

b) Discuss how the Poisson equation can be solved iteratively for a given a x,yc) What type of boundary conditions are required in order to solve the equation numerically?

(6p)

4. Discretise the following set of equations both on a B and a C!grid. Show on the grids the different schemesand discuss the advantages and disadvantages of the two grids for this discretisation.

!u! t

"u!u! x

"v! u! y

& f v=&g! h! x

"A' 2 u 1

! v! t

"u! v! x

"v! v! y

" f u=&g! h! y

"A' 2 v 2

! h! t

"u! h! x

"v! h! y

"h !u! x

"! v! y

=0 3Hint for Equation (3): rewrite before discretisation

(6p)

5. The conservation of potential vorticity for three dimensional motion can be expressed as

( ) 02=!!

"

#$$%

& '(+

)

*Ùùdtd

where * is a conserved quantity that follows the motion of the air

a) Suggest a physical quantity * that is suitable to be used in atmospheric contexts. Discuss why. (2p)

b) Show how the conservation of potential vorticity can be simplified for a barotropic atmosphere (shallow watermodel) in a front region. Assume that the Coriolis parameter is constant. (4p)

Page 131: Numerical Methods

131

Page 132: Numerical Methods

132 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

2003

Kristofer Döös och Erland Källén, Meteorolgiska institutionen, Stockholms universitet

Tentamen i numeriska metoder inom meteorologin och oceanografin, ME3580

Tosdagen den 30 oktober 2003, kl. 9.00-15.00

Betrakta ekvationssystemet:∂u

∂t= −g∂h

∂x

∂h

∂t= −H∂u

∂x

där g är gravitationen, H djupet, u hastigheten och h ytperturbationen.

a) Lös ut analytiskt en ekvation för h. (1p)

b) Ansätt våglösningar och räkna ut den analytiska fashastigheten. (1p)

c) Diskretisera ekvationerna med centrerade scheman i tid och rum för en A-gridd (u och h i samma

griddpunkter). (1p)

d) Räkna ut noggranheten på dessa scheman. (1p)

e) Räkna ut den numeriska fashastigheten och diskutera skillnaden med den analytiska fashastigheten.

(1p)

f) Utför stabilitetsanalys. (2p)

g) Vad behövs för initialvilkor och hur kan modellen integreras första tidssteget? (1p)

h) Vad krävs för randvilkor? (1p)

i) Sätt upp en numerisk modell för dessa ekvationer med IM punkter i x-led och beskriv hur den

integreras i tiden för NT tidssteg. Ledtråd: skriv en skiss ungefär som en matlab eller fortran kod.

(3p)

j) Vad förändras om modellen är på en alternerande gridd där u och h inte är i samma punkter. (3p)

k) Vad förändras om modellen dessutom är i två dimensioner? (3p)

l) Vad förändras om coriolistermen dessutom är med? (3p)

m) Vad förändras om advektionstermerna dessutom är med? (3p)

Formelsamling:

Taylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 12 (x− a) 2f ′′ (a) + ... +

1n! (x− a)n f (n) (a)

Page 133: Numerical Methods

133

eiα − e−iα = 2i sinα

Shallow water teoriuppgiften: Utgå från de horisontella rörelseekvationerna på formen

∂u

∂t+ u

∂u

∂x+ v

∂u

∂y+ w

∂u

∂z− fv = −1

ρ

∂p

∂x

∂v

∂t+ u

∂v

∂x+ v

∂v

∂y+ w

∂v

∂z+ fu = −1

ρ

∂p

∂y

samt hydrostatiskt∂p

∂z= −gρ

a) Visa att tryckgradienttermen i de horisontella rörelseekvationerna kan skrivas enbart som funtion av

höjden på en fri yta i “shallow-water” approximationen. (4p)

b) Ange det vilkor under vilket vertikaladvektionstermerna kan sättas till noll. (2p)

Page 134: Numerical Methods

134 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

2004

Tentamen i numeriska metoder inom meteorologin och oceanografin, ME3580, fredagen den 29 decem-

ber 2004, kl. 9.00-15.00 av Kristofer Döös och Erland Källén, Meteorologiska institutionen, Stockholms

universitet

De lineariserade shallow water ekvationerna kan skrivas:

∂u

∂t− fv = −g∂h

∂x(A.1)

∂v

∂t+ fu = −g∂h

∂y(A.2)

∂h

∂t+H

(∂u

∂x+∂v

∂y

)= 0 (A.3)

där g = 10m/s2, H = 10km, f = 10−4s−1.

a) Härled en dispersionsrelation för våglösningarna till systemet ovan. (3p)

b) Diskutera den relativa betydelsen av rotation och gravitation för vågrörelser. För vilken våglängd

är rotations- och gravitationseffekten jämförbara för atmosfäriska förhållanden? (3p)

c) Diskretisera ekvationerna A.26-A.28 i tid och rum med centrerade scheman på en C-grid (u, v och

h i olika punkter) (2p).

d) Vad behövs för typ av initialvillkor och hur kan den numeriska modellen integreras första tidssteget?

(1p)

e) Vad krävs för typ av randvillkor för den numeriska modellen? (1p)

f) Räkna ut noggrannheten på de finita diffenserna. Är de olika? (3p)

g) Räkna ut den numeriska dispersionsrelationen för fallet då u, v och h ej beror på y. Diskutera

skillnaden med den analytiska dispersionsrelationen från uppgift 1 då l = 0. (3p)

h) Beskriv hur en numerisk modell baserad på de diskretiserade ekvationerna från uppgift 3 ser ut

med IMT punkter i x-led , JMT punkter i y-led och beskriv hur den integreras i tiden för NT

tidssteg. Ledtråd: skriv en skiss ungefär som en matlab eller fortran kod. (3p)

i) Utför stabilitetsanalys för fallet då u, v och h ej beror på y och f = 0. (4p)

j) Inkludera de icke-linjära termerna i shallow water ekvationerna och skriv om så att de icke-linjära

termerna delas upp på den absoluta potentiella virveln och en gradient av kinetiska energin. (3p)

k) Diskretisera dessa ekvationerna på en C-gridd. Visa att det finns flera möjliga diskretiseringar.

(4p)

Page 135: Numerical Methods

135

uu

u

u

u u

v

v

v

v

v

v

h

h h

h

i i+1i

j

i-1 i+1

j

j+1

j-1

j+1

Figure A.1: C-gridd.

Formelsamling: eiα − e−iα = 2i sinα och eiα + e−iα = 2cosα och 2 sin2 (α/2) = 1− cosαTaylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 1

2 (x− a) 2f ′′ (a) + ... +1n! (x− a)n f (n) (a)

Page 136: Numerical Methods

136 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

2005

Tentamen i numeriska metoder inom meteorologin och oceanografin, ME3580, torsdagen den 3 novem-

ber 2005, kl. 9.00-15.00 av Kristofer Döös och Erland Källén, Meteorologiska institutionen, Stockholms

universitet

Consider the partial differential equation (PDE):

∂T

∂t= A∇2T where A > 0 and∇2 ≡ ∂2

∂x2+

∂2

∂y2

1) Find a solution for T (x, y, t) and describe what it could represent physically. (N.B. Nothing to do

with numerical methods!) (2p)

2) Is the PDE elliptic, hyperbolic or parabolic? Show how you determine this. Clue: use only one di-

mension in space. (2p)

3) Discretise the time derivative with centred difference and the laplace with centred difference at time

step n-1. (2p)

4) Derive the order of accuracy of the two schemes with help of Taylor series. (2p)

5) Make a stability analysis. (2p)

6) Is there a numerical mode? Why? How do you suppress it? (2p)

Consider the non-linear shallow water equations:

∂u

∂t− ξhv = −∂H

∂x(A.4)

∂v

∂t+ ξhu = −∂H

∂y(A.5)

∂h

∂t+∂ (hu)

∂x+∂ (hv)

∂y= 0 (A.6)

where ξ ≡(f + ∂v

∂x −∂u∂y

)/h and H ≡ gh+ 1

2

(u2 + v2

)7) Discretise the equations A.4-A.6 with centred schemes on a C-grid (See Figure A.2 at bottom of

the page). (4p).

8) Find a second way to discretise the terms ξhv and ξhu. (2p)

9) What type of initial condition is needed and how can one integrate the first time step? (2p)

10) What type of boundary conditions are needed? (2p)

11) Describe a numerical model code in matlab or fortran based on these discretised equations with IM

grid cells in the x direction and JM in the y direction and how it is integrated in time for NT time steps.

(2p)

12 a) Linearise eqs A.4-A.6 around a state of rest with an average shallow water depth D. (3p)

12 b) Determine the types of wave motions that can be described with the linearised system given in

12a). If you cannot solve 12a) you can get the answer to 12a), but in this case you will not be given any

points for 12a. (3p)

Page 137: Numerical Methods

137

uu

u

u

u u

v

v

v

v

v

v

h

h h

h

i i+1i

j

i-1 i+1

j

j+1

j-1

j+1

Figure A.2: C-grid.

Formulas: eiα − e−iα = 2i sinα and eiα + e−iα = 2cosα and 2 sin2 (α/2) = 1− cosαTaylorseries for f (x) about x = a is f (x) = f (a) + (x− a) f ′ (a) + 1

2 (x− a) 2f ′′ (a) + ... +1n! (x− a)n f (n) (a)

a∂2u∂x2

+ b ∂2u

∂x∂y + c∂2u∂y2

+ d∂u∂x + e∂u∂y + fu+ g = 0. If b2− 4ac < 0 then elliptic; if = 0 then parabolic;

if > 0 then hyperbolic .

Page 138: Numerical Methods

138 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

2006

Tentamen i numeriska metoder inom meteorologin och oceanografin, ME3580, torsdagen den 2 novem-

ber 2006, kl. 9.00-15.00 av Kristofer Döös och Heiner Körnich, Meteorologiska institutionen, Stock-

holms universitet. Tentamen på totalt 30 p. För godkänt krävs 15 p. och väl godkänt 22,5 p.

Betrakta grunt vattenekvationerna på formen

∂u

∂t+ u

∂u

∂x+ v

∂u

∂y− fv = −g∂h

∂x+A∇2u (A.7)

∂v

∂t+ u

∂v

∂x+ v

∂v

∂y+ fu = −g∂h

∂y+A∇2v (A.8)

∂h

∂t+∂ (hu)

∂x+∂ (hv)

∂y= 0 (A.9)

1) Linjarisera ekvationerna (A.26) - (A.28) runt ett medeldjup på D samt gör friktionsfritt. (2p)

2) Diskretisera dessa linjariserade friktonsfria rörelseekvationer med centrerade differenser i både tid och

rum på en B-grid (se figur). (2p)

3) Förenkla dessa diskretiserade ekvationer för fallet då fallet f = 0 och utan y beroende d.v.s. ∂/∂y =

0.(1p)

4) Gör en stabilitetsanalys på de diskretiserade ekvationer i uppgift 3. (4p)

5) Härled noggrannheten av den centrerade tidsdifferensen. (2p)

6) Hitta en möjlig diskretisering av de ickelinjära advektionstermerna i ekvationerna (A.26) och (A.27).

Redovisa dem var och en för sig. (3p).

7) Diskretisera även friktionstermerna i ekvationerna (A.26) och (A.27). Redovisa dem var och en för

sig. (2p).

8) Härled noggrannheten friktionstermerna. (Räcker med en dimension) (2p)

9) Finns det en beräkningsmod (numerisk mod) ? I så fall varför och hur filtreras denna bort? (1p)

10) Vad för initial- och randvillkor behövs för att ekvationerna ska kunna integreras? (1p)

11) Beskriv hur en numerisk modell bestånde av de diskretiserade ekvationerna skulle se ut. Med IM

griddceller i x-led och JM i y-led och som integreras i tiden under NT tidsteg. (4p)

12) Linjarisera friktionsfria versioner av ekvationerna (1)-(3) runt ett medeldjup på D med en kon-

stant geostrofisk bakgrund flöde ub i x-led, dvs. ~u = (ub; 0) + (u′; v′), h = D + ηb + η′. ηb är det

geostrofiskt balanserade höjd fältet med ηb << D. (3p)

13) Bestäm vilken typ av vågor som beskrivs av de linjariserade ekvationerna i uppgift 10). Hur påverkar

bakgrund fashastighet i x-led cx? (3p)

Formelsamling: eiα − e−iα = 2i sinα and eiα + e−iα = 2cosα and 2 sin2 (α/2) = 1− cosαTaylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 1

2 (x− a) 2f ′′ (a) + ... +1n! (x− a)n f (n) (a)

Page 139: Numerical Methods

139

! !"#

!!"#$%$

$!#

$"#

!!#

&!"#$%

!

$

$!#

$"#

!!# !"#

%

%

%

%$"#

$

! !"#

&'(

&'(&'(

&'(

&'(

&'(&'(

&'( &'(

!!#

'!"#$%

$

$!#

$"# )

&

! !"#

&

& &

&&

)

)

)

)

!

% %

%%

!"#

$

$"#

&'('%

&'('% &'('%

&'('%

&'('%

&'('%

&'('% &'('%

&'('%

))( ))(

))())(

))( ))(

2007

Tentamen i numeriska metoder inom meteorologin och oceanografin, ME3580, torsdagen den 1 novem-

ber 2007, kl. 9.00-15.00 av Kristofer Döös och Heiner Körnich, Meteorologiska institutionen, Stock-

holms universitet. Tentamen på totalt 30 p. För godkänt krävs 15 p. och väl godkänt 22,5 p.

Consider the shallow water equations in vector-form:

∂t~uh +∇~uh · ~uh

2+ (ξ + f)~k × ~uh = −g∇h (A.10)

∂H

∂t+∇ · (~uhH) = 0 (A.11)

with the following definitions:

the total depth H = h− hb, (A.12)

the surface elevation hb = hb(x, y), (A.13)

the relative vorticity ξ =∂v

∂x− ∂u

∂y, (A.14)

and the horizontal velocity vector ~uh =

(u

v

)(A.15)

1) Linearise the equations (A.10) and (A.11) for small amplitude motion around a mean depth D =

D(x, y). Derive the solution for the time-independent linear motion. Show that the divergence of this

motion is zero and discuss this motion for a spatially varying surface elevation hb. (4p)

2) Use the linear equations to derive the tendency equation for the total energyEtot = D|~uh|2/2+gh2/2.

Assume a closed region with no normal flow across the boundaries: ~uh ·~n = 0, where the vector ~n which

is the orthogonal unity vector on the boundary contour. Argue why the area integrated total energy is

conserved. Hint: Apply the divergence theorem (2p)∫∫AdA∇ · ~v =

∮~v · ~ndr . (A.16)

Page 140: Numerical Methods

140 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

3) Discretise the linearised shallow water equations with a flat bottom on a C-grid (see Fig. ??) with

Euler forward finite differences in time and centred finite differences in space. (3p)

4) What initial and boundary conditions are required. (1p)

5) Is there a numerical mode? How can you suppress a numerical mode? (1p)

6) Simplify the discretised equations from task 3 for the case when f = 0 and for no y dependency. i.e.

when ∂/∂y = 0. (1p)

7) Make a stability analysis on the equations from previous task. (3p).

8) Calculate the truncation error of the Euler forward finite difference. (2p)

9) Derive the frequency equation by substituting wave solutions into the linearised shallow water equa-

tions for the case when ∂/∂y = 0. Note that this is for the continuous equations with no finite differences.

(3p)

10) Same as previous task but for the discretised equations with finite differences in space on a C-grid.

Use continuous differences in time. Discuss the effects of discretisation on the phase speed. (3p)

11) Find two possible discretisations on the C-grid of the non-linear advection terms in the shallow water

momentum equations (both the zonal and the meridional momentum equations). (3p)

12) In what way is a hydrostatic 3-D model (GCM) different from a shallow water model? What extra

equations and terms are there? Discretise these extra terms and equations. (4p).

Formelsamling: eiα − e−iα = 2i sinα and eiα + e−iα = 2cosα and 2 sin2 (α/2) = 1− cosαTaylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 1

2 (x− a) 2f ′′ (a) + ... +1n! (x− a)n f (n) (a)

Page 141: Numerical Methods

141

2008

Tentamen i numeriska metoder inom meteorologin och oceanografin, ME3580, torsdagen den 30 oktober

2008, kl. 9.00-15.00 av Kristofer Döös och Heiner Körnich, Meteorologiska institutionen, Stockholms

universitet. Tentamen på totalt 30 p. För godkänt krävs 15 p. och väl godkänt 22,5 p.

Consider the linearised shallow water equations in the quasi-one-dimensional case where u, v and h

do not depend on y so that the shallow water equations are reduced to

∂u

∂t− fv = −g∂h

∂x(A.17)

∂v

∂t+ fu = 0 (A.18)

∂h

∂t+H

∂u

∂x= 0 (A.19)

1) Derive the dispersion relationship (frequency equation) by substituting wave solutions into A.17-

A.19. (2p)

2) Discretise Eqs. A.17- A.19 in space on a B-grid (see Figure on next page) and keep the continuous

derivatives in time. (1p) 3) Derive the numerical dispersion relationship for these discretised equations

in space. (3p)

4) Describe the differences between these model waves and the analytical continuous waves (2p)

5) Discretise the equations in task 2 with centred finite differences in time (leap-frog). (1p)

6) Make a stability analysis on the equations in previous task. (5p).

7) Derive the numerical dispersion relationship from the disrcetised equation from task 5 (this time with

finite differences in time). (4p)

8) What initial and boundary conditions are required? How can you start to integrate the first time step?

(1p)

9) Is there a numerical mode? Why ? How can you suppress a numerical mode? (1p)

10) Calculate the truncation error of the finite difference in space of the continuity equation from task 2.

(2p)

11) Consider the continuity equation with pressure as vertical coordinate

∂u

∂x+∂v

∂y+∂ω

∂p= 0 (A.20)

Discretise it on a B-grid and explain how it can be integrated. (2p)

12) Derive the linearised potential vorticity equation

∂t

[ξ − f

Hh

]= 0 (A.21)

from the equations A.17- A.19. Discuss the relationship between the vorticity and the surface elevation

implied by equation A.21. (3p)

13) Assume that the real part of the wave solution for η = h−H is given as

η = η0 cos(kx− σt). (A.22)

Page 142: Numerical Methods

142 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

Express the wave solution for the vorticity and the divergence in terms of the amplitude η0. Which mo-

tion type (divergence or vorticity) has a larger amplitude? Use the fact σ > f . (3p)

Formulas: eiα − e−iα = 2i sinα and eiα + e−iα = 2cosα and 2 sin2 (α/2) = 1− cosαThe Taylor series for f (x) arround x = a is f (x) = f (a) + (x− a) f ′ (a) + 1

2 (x− a) 2f ′′ (a) + ...+1n! (x− a)n f (n) (a)

! !"#

!!"#$%$

$!#

$"#

!!#

&!"#$%

!

$

$!#

$"#

!!# !"#

%

%

%

%$"#

$

! !"#

&'(

&'(&'(

&'(

&'(

&'(&'(

&'( &'(

!!#

'!"#$%

$

$!#

$"# )

&

! !"#

&

& &

&&

)

)

)

)

!

% %

%%

!"#

$

$"#

&'('%

&'('% &'('%

&'('%

&'('%

&'('%

&'('% &'('%

&'('%

))( ))(

))())(

))( ))(

Page 143: Numerical Methods

143

2010

Tentamen i numeriska metoder inom meteorologin och oceanografin, MO7004, tisdagen den 28 septem-

ber 2010, kl. 9.00-15.00 av Kristofer Döös, Meteorologiska institutionen, Stockholms universitet. Tenta-

men på totalt 100 poäng. För betyg A krävs minst 90 p., B ges mellan 89 och 80p, C: 65-79, D:55-64,

E:50-54, Fx:45-49 och under 45 p. ges betyg F.

Betrakta de linjariserade gruntvattenekvationerna på formen

∂u

∂t− fv = −g∂h

∂x(A.23)

∂v

∂t+ fu = −g∂h

∂y(A.24)

∂h

∂t+D

(∂u

∂x+∂v

∂y

)= 0 (A.25)

där D är medeldjupet.

1) Inkludera de icke-linjära termerna i ekvationerna (A.26) - (A.28). (5p)

2) Skriv om dessa icke-linjariserade gruntvattenekvationer med hjälp av

ξ ≡(f + ∂v

∂x −∂u∂y

)/h, U = uh, V = vh och E = gh+ 1

2

(u2 + v2

). (7p)

3) Diskretisera de linjariserade rörelseekvationer (A.26) - (A.28) med centrerade differenser i rum-

met på en A-grid (se figur) och Euler framåt i tiden. (7p)

4) Hitta en möjlig diskretisering på en A-grid även för de icke-linjära termerna för de tre icke-

linjariserade gruntvattenekvationerna. Redovisa separat varje term. (10p)

5) Härled dispersionsrelationen för (A.26) - (A.28) genom att ansätta våglösningar. (10p)

6) Härled den numeriska dispersionsrelationen för de diskretiserade linjariserade ekvationerna från

uppgift 3 genom att ansätta diskretiserade våglösningar. Använd kontinuerliga derivater i tiden och an-

tag att det inte finns någon variation i y-led. Diskutera skillnaden mellan den numeriska och analytiska

dispersionsrelationen från föregånde uppgift. (15p)

7) Härled noggrannheten av de finita differenserna av ekvationerna i uppgift 3. Är de alla lika exakta?

(10p)

8) Gör en stabilitetsanalys på de diskretiserade ekvationer i uppgift 3 för fallet då f=0. (16p)

Page 144: Numerical Methods

144 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

9) Finns det en beräkningsmod (numerisk mod)? Motivera! (5p)

10) Vad för initial- och randvillkor behövs för att ekvationerna ska kunna integreras? (5p)

11) Skulle du valt ha de finita differenserna i uppgift 3 om du hade satt upp en linjära gruntvatten-

modell? Skulle du föredragit en annan uppsättning? Argumentera för för- och nackdelarna mellan din

och den givna modellen i uppgift 3. (10p)

Formelsamling: eiα − e−iα = 2i sinα and eiα + e−iα = 2cosα and 2 sin2 (α/2) = 1− cosαTaylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 1

2 (x− a) 2f ′′ (a) + ... +1n! (x− a)n f (n) (a)

! !"#

!!"#$%$

$!#

$"#

!!#

&!"#$%

!

$

$!#

$"#

!!# !"#

%

%

%

%$"#

$

! !"#

&'(

&'(&'(

&'(

&'(

&'(&'(

&'( &'(

!!#

'!"#$%

$

$!#

$"# )

&

! !"#

&

& &

&&

)

)

)

)

!

% %

%%

!"#

$

$"#

&'('%

&'('% &'('%

&'('%

&'('%

&'('%

&'('% &'('%

&'('%

))( ))(

))())(

))( ))(

Page 145: Numerical Methods

145

2011

Tentamen i numeriska metoder inom meteorologin och oceanografin, MO7004, tisdagen den 27 septem-

ber 2011, kl. 9.00-15.00 av Kristofer Döös, Meteorologiska institutionen, Stockholms universitet. Tenta-

men på totalt 100 poäng. För betyg A krävs minst 90 p., B ges mellan 89 och 80p, C: 65-79, D:55-64,

E:50-54, Fx:45-49 och under 45 p. ges betyg F.

Skriv på svenska eller engelska!

Consider the shallow water equations on the form:

∂u

∂t− fv = −g∂h

∂x+A∇2u (A.26)

∂v

∂t+ fu = −g∂h

∂y+A∇2v (A.27)

∂h

∂t+D

(∂u

∂x+∂v

∂y

)= 0 (A.28)

where D är is the average depth.

a) Discretise the equations on a C-grid. Choose the finite time differencing as you would in your

favourite shallow water model. See the attached C-grid Figure on reverse page! (15p)

b) What type of boundary conditions are needed for the discretised equations? (5p)

c) What initial conditions are required for the discretised equations? How can you start to integrate

the first time step? (5p)

d) Derive the order of accuracy of the Laplacian diffusion terms. (10p)

e) Make a stability analysis for the non-rotative (f=0), inviscid (A=0) and no y-variations (∂/∂y = 0)

case. (15p)

f) Make a stability analysis for the discretised Eq. A.27 when f=0 and there is no y-variation (∂/∂y =

0). Be careful in the choice of time step of the viscous term! (10p)

g) Is there a numerical mode? Why? How do you suppress it? (5p)

h) Derive the dispersion relationship (frequency equation) by substituting wave solutions into Eq.

A.26 - A.28 for the inviscid (A=0) and no y-variations (∂/∂y = 0) case. (10p)

i) Same as previous but for the discretised case in space. Use continuous derivatives in time. Discuss

the differences with the previous non-discretised analytical case. (15p)

j) Add the non-linear terms to Eq. A.26 - A.28 and apply them on the C-grid. Use the horizontal

absolute potential vorticity ξ ≡(f + ∂v

∂x −∂u∂y

)/h and H ≡ gh+ 1

2

(u2 + v2

)(10p)

Page 146: Numerical Methods

146 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

Formelsamling:

eiα − e−iα = 2i sinα

eiα + e−iα = 2cosα

2 sin2 (α/2) = 1− cosα

Taylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 12 (x− a) 2f ′′ (a) + ... +

1n! (x− a)n f (n) (a)

x2+αx+ β = 0 ⇒ x = −α/2±√α2/4− β

uu

u

u

u u

v

v

v

v

v

v

h

h h

h

i i+1i

j

i-1 i+1

j

j+1

j-1

j+1

Figure A.3: The C-grid

Page 147: Numerical Methods

147

2012

Tentamen i numeriska metoder inom meteorologin och oceanografin, MO7004, onsdag den 3 oktober

2012, kl. 9.00-15.00 av Kristofer Döös, Meteorologiska institutionen, Stockholms universitet. Tentamen

på totalt 100 poäng. För betyg A krävs minst 90 p., B ges mellan 89 och 80p, C: 65-79, D:55-64, E:50-

54, Fx:45-49 och under 45 p. ges betyg F.

The tracer Equation can under certain circumstances be written

∂T

∂t+∇· (VT ) = KH∇2T +KV

∂2T

∂z2+ C (A.29)

a) Derive from where the second term (advection term) comes from! Which extra equation do you

need and under what conditions is this extra equation valid? (14p)

b) Discretise Equation A.29 with, centred finite differences in both time and space on a C-grid! (14p)

c) Derive the order of accuracy of the Laplacian diffusion terms in Equation A.29! (14p)

d) Simplify Equation A.29 by excluding the non-linear advection terms, no source term and only one

dimension in space. Discretise with centred finite differences in both time and space. Perform a

stability analysis! Note that this discretised equation should be completely centred! Is this a good

choice? Any better choice of the time steps? (15p)

e) The time derivative and the advection part of the equation can be simplified in one dimension if

the velocity is set to a constant phase speed so

∂T

∂t+ c

∂T

∂x= 0 (A.30)

Derrive an expression for the ratio between the phase speed c and the computational phase speed

CD. (14p)

f) Adapt and discretise Equation A.29 so it would fit into your shallow water model you have con-

structed during this course. (14p)

g) Discretise the Equation A.29 in such a way the size of the grid boxes can vary in space so that

∆xi,j , ∆yi,j and ∆zk have grid indices. Hint: Write the tracer advection and tracer diffusion on

flux form. (15p)

PTO (Please Turn Over)

Page 148: Numerical Methods

148 APPENDIX A. EXAMS AT STOCKHOLM UNIVERSITY

Formelsamling:

eiα − e−iα = 2i sinα

eiα + e−iα = 2cosα

2 sin2 (α/2) = 1− cosα

Taylorserien för f (x) runt x = a är f (x) = f (a) + (x− a) f ′ (a) + 12 (x− a) 2f ′′ (a) + ... +

1n! (x− a)n f (n) (a)

x2+αx+ β = 0 ⇒ x = −α/2±√α2/4− β

uu

u

u

u u

v

v

v

v

v

v

h

h h

h

i i+1i

j

i-1 i+1

j

j+1

j-1

j+1

Figure A.4: The C-grid

Page 149: Numerical Methods

Bibliography

Asselin, R. A., 1972: Frequency filter for time integrations. Mon.Weather Rev., 100, 487-490.

Batteen, M. L. and Han, Y.-J., 1981:On the computational noise of finite-difference schemes used in

ocean models. Tellus, 33 :387-396. 66

Fletcher, C. A. J.: Computational Techniques for Fluid Dynamics, Volume 1, second edition, Springer-

Verlag, Berlin Heidelberg, 1991.

Kalnay, Eugenia, 2003: Atmospheric Modeling, Data Assimilation and Predictability. Cambridge Uni-

versity Press, 341pp.

Mesinger and Arakawa, 1976: GARP Publication Series No. 17, WMO.

Robert, A., 1969: The integration of a spectral model of the atmosphere by the implicit method. Proc. of

the WMO/IUGG Symp. on NWP, Tokyo, Japan Meteor. Agency, VII, 19-24.

Sadourny, R., 1975: The dynamics of finite-difference models of the shallow-water equations. J. Atmos.

Sci., 32, 680-689.

Sadourny, R., 1975: Compressible model flows on the sphere. J. Atmos. Sci., 32(11):2103-2110.

Simmons, A.J. and D.M. Burridge, 1981. An Energy and Angular-Momentum Conserving Vertical

Finite-Difference Scheme and Hybrid Vertical Coordinates. Monthly Weather Review. 109, 4, 758-

766. 92

Williams, P. D., 2009: A proposed modification to the Robert-Asselin time filter. Mon. Wea. Rev., 137,

2538-2546. 38, 39

149