Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf ·...

112
1 Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin and Jean-Marie Beckers Numerical Exercises Solution Manual

Transcript of Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf ·...

Page 1: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

1

Introduction toGeophysical Fluid Dynamics

Physical and Numerical Aspects

Benoit Cushman-Roisin and Jean-Marie Beckers

Numerical Exercises Solution Manual

Page 2: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

February 7, 2013

This is a support for Numerical Exercises written up toFebruary 7, 2013. Please forwardany errors you might have spotted [email protected] .

Note that additional material (including corrections for MATLAB or OCTAVE codes) canbe found at

http://booksite.academicpress.com/9780120887590/ind ex.php

and that codes for solutions are found on the GHER wiki athttp://modb.oce.ulg.ac.be/mediawiki/index.php/Numer ical_problems_solutions

2

Page 3: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 1

1.1 Using the temperature measurements of Nansen (Figure 1-1 left), estimate typical ver-tical temperature gradient values and typical temperaturevalues. Compare those values tothe estimates based on a Mediterranean profile (Figure 1-1 right). Which temperature scaledo you need for the estimation of gradients in each case?

Solution

1.2 Perform a numerical differentiation ofe−ω(t+|t|) usingω∆t = 0.1, 0.01, 0.001. Com-pare the first-order forward, first-order backward and second-order centered schemes att = 1/ω. Then, repeat the derivation witht = 0.000001/ω and compare. What do youconclude?

Solution

1.3 Apply forward, backward, second-order, and fourth-order discretizations tosinh(kx) atx = 1/k for values ofk∆x covering the range[10−4, 1]. Plot errors on a logarithmic scaleand verify the convergence rates. Repeat the exercise forx = 0. What strange effect do youobserve and why?

Solution The example solution codenum ex 1 3.m shows the convergence rate of the threeproposed schemes and the green lines show first, second and fourth-order convergence slope.We see (Figure 1-2) that actual error shows that the convergene behaves as expected exceptfor small grid sizes in the case of the fourth order method. Inthis case the remaining error isjust a rounding error which cannot be eliminated and therefore the method can be consideredto have converged to the ”exact” value. Note that the important parameter in the code isk∆x,

3

Page 4: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

4 CHAPTER 1.

−2 −1.5 −1 −0.5 0 0.5 1−3000

−2500

−2000

−1500

−1000

−500

0

T

z

12 13 14 15 16 17 18 19−1000

−900

−800

−700

−600

−500

−400

−300

−200

−100

0

T

z

Figure 1-1 Temperature values measured by Nansen during his 1894 NorthPole expedition (left) anda typical temperature profile in the Mediterranean Sea (fromMedar data base, right).

10-20

10-15

10-10

10-5

100

10-4 10-3 10-2 10-1 100 101

rele

rr

k dx

Figure 1-2 Discretisation errors as a function ofk∆x

Page 5: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

5

10-20

10-15

10-10

10-5

100

10-4 10-3 10-2 10-1 100 101

rele

rr

k dx

Figure 1-3 Discretisation errors as a function ofk∆x in x = 0

a non-dimensional measure of the grid size; there is no need to specificy actual values of∆xandk only their product matters.

Whenx = 0, convergence of the forward and backward approach is fasterthen expectedand coincides with the second-order method (Figure 1-3), simply because all even derivativesare zero at the origin and hence the corresponding term in thetruncation analysis is identicallyzero (the first order methods becomes second order, but only in x = 0). Another way ofsaying this is that at the origin the finite difference on the left or on the right has the sameslope because the function satisfiesf(x) = −f(−x) and the finite difference will yield thesame value on each side.

Comments The code is of course not very general as it has hardwired thesinh functionand its derivative, as well as the discretisations. More general approaches could include pass-ing functions to subroutines which calculate the finite differences, but this is a programmingaspect rather than a numerical problem.

1.4 Establish a purely forward, finite-difference approximation of a first derivative that is of

Page 6: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

6 CHAPTER 1.

second or higher order in accuracy. How many sampling pointsare required as a function ofthe order of accuracy?

Solution

1.5 Suppose you need to evaluate∂u/∂x not at grid nodei, but at mid-distance betweennodesxi = i∆x and xi+1 = (i + 1)∆x. Establish second-order and fourth-order finitedifference approximations to do so and compare the truncation errors to the correspondingdiscretizations centered on the nodal pointi. What does this analysis suggest?

Solution

1.6 Assume that a spatial two-dimensional domain is covered by auniform grid with spacing∆x in thex-direction and∆y in they-direction. How can you discretize∂2u/∂x∂y to secondorder? Does the approximation satisfy a similar property asits mathematical counterpart∂2u/∂x∂y = ∂2u/∂y∂x ?

Solution

1.7 Determine how a wave of wavelength43∆x and period5

3∆t is interpreted in a uniformgrid of mesh∆x and time step∆t. How does the computed propagation speed resulting fromthe discrete sampling compare to the true speed?

Solution This exercise provides also a opportunity to explain what a Hovmoller diagram is .

1.8 Suppose you use numerical finite differencing to estimate derivatives of a function thatwas sampled with some noise. Assuming the noise is uncorrelated (i.e., purely randomly

Page 7: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

7

distributed, independently of the sampling interval), what do you expect would happen duringthe finite differencing of first-order derivatives, second derivatives etc.? Devise a numericalprogram that verifies your assertion, by adding a random noise of intensity10−5A to thefunctionA sin(ωt), where the frequencyω is well resolved by the numerical sampling (ω∆t =0.05). Did you correctly guess what would happen? Now plot the convergence as a functionofω∆t for noise levels of10−5A and10−4A.

Solution

Page 8: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

8 CHAPTER 1.

Page 9: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 2

2.1 When using the semi-implicit scheme (2.32a)-(2.32b) withα = 1/2, how many time stepsare required per complete cycle (period of2π/f ) to guarantee a relative error onf notexceeding 1%?

Solution

2.2 Develop an Euler scheme to calculate the position coordinatesx and y of a particleundergoing inertial oscillations from its velocity componentsu andv, themselves calculatedwith an Euler scheme. Graph the trajectory[xn, yn] for n = 1, 2, 3, ... of the particle. Whatdo you notice?

Solution

2.3 For the semi-implicit discretization of the inertial oscillation, calculate the number ofcomplete cycles it takes before the exact solution and its numerical approximation are inphase opposition (180◦ phase shift). Express this number of cycles as a function of the pa-rameterf∆t. What can you conclude for a scheme for whichf∆t = 0.1 in terms of timewindows that can be analyzed before the solution is out of phase?

Solution Phase opposition occurs aftern time steps if(f − f)n∆t = π i.e.

n =π

f∆t− arctan(

f∆t1−f2∆t2/4

) (2.1)

9

Page 10: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

10 CHAPTER 2.

The numberN of corresponding inertial periods isN = n∆t2πf−1 i.e.

N =1

2

1

1− 1f∆tarctan

(

f∆t1−f2∆t2/4

) (2.2)

For f∆t = 0.1, N = 601, which is much larger than the number of inertial oscillations asystem generally can sustain before decaying due to friction.

2.4 Devise a leapfrog scheme for inertial oscillations and analyze its stability and angularfrequency properties by searching for a numerical solutionof the following form1:

un = V n sin(fn∆t+ φ), vn = V n cos(fn∆t+ φ).

Solution Here we will make the analysis with complex numbersw = u + i v and the corre-sponding numerical discrete solutionw = u+ i v. The inertial oscillation is solution of

dw

dt= −i fw (2.3)

and the Leapfrog discretization reads

wn+1 − wn−1

2∆t= −i fwn (2.4)

and we search for a solution of the type

wn = V e−i (f tn+φ)

but entertain the possibility forf to be complex (rather than to keepρ in the solution)Insertion into the finite difference equation yields

e−i f∆t − ei f∆t = − 2i f∆t (2.5)

orsin(f∆t) = f∆t (2.6)

if |f∆t| > 1, then f must be imaginary and we have two solutions (remember thatLeapfrog has too modes)f = iωi or f = π − iωi and the solution is unstable since we canfind a real valueωi:

sinh(ωi∆t) = f∆t (2.7)

if |f∆t| ≤ 1 the two solutions forf are real and the solution is stable.

1Forn, n is an exponent, not an index.

Page 11: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

11

If we had keptρ in the solution:

ρe−i f∆t − ρ−1ei f∆t = − 2i f∆t (2.8)

which leads to the discussion of complex equation of second order (we have again two rootsas Leapforg has two modes),

ρ =−i ∆tf ±

1−∆t2f2

e−i f∆t(2.9)

and it is easy to reach the same conclusion, because if|f∆t| < 1 on the numerator wehave a real part and an imaginary part of a number whose moduleis then unit, and on thedenominator the module is also unit so that the solution is stable. However, when|f∆t| > 1,then the numerator is purely imaginary and has a module whichis larger then one because

− x±√

x2 − 1 (2.10)

take values outside of[−1, 1] when|x| > 1. By symmetry we only need to look at

− x−√

x2 − 1, x > 1 (2.11)

which is obviously smaller than−1.

2.5 Calculate the discrete solution of the explicit Euler-scheme applied to inertial oscilla-tions by searching for a solution of the same form as in Problem 2-4 where andf are againparameters to be determined. Show that the discrete solution converges to the exact solution(2.12).

Solution Substitution of the expected form of solution into the explicit Euler scheme leads,after elementary trigonometric expansion (making appear only terms insin(f tn + φ) andcos(f tn + φ)) to

ρ cos(f∆t) = 1 ρ sin(f∆t) = f∆t (2.12)

Already at this point convergence is ensured since for∆t→ 0 sin(f∆t)→ f∆t andf → f .Also ρ→ 1. Furthermore

ρ2 = 1 + f2∆t2 (2.13)

The norm increases thus (sinceρ > 1):

‖ un ‖=(

1 + f2∆t2)n/2 ‖ u0 ‖ (2.14)

but(

1 + f2∆t2)n/2 ≤ ef2∆t2n/2 ≤ ef2T∆t/2 for all n∆t < T (2.15)

Page 12: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

12 CHAPTER 2.

and for smallerf∆t and fixed simulation lengthT , the solution converges towards the exactone with a angular frequencyf given by

tan(f∆t) = f∆t (2.16)

which shows that oscillations have a lower frequency than the real one.

f − ff

=arctan(f∆t)

f∆t− 1 ∼ −f

2∆t2

3(2.17)

2.6 Prove the assertion that scheme (2.51) is of second order.

Solution

2.7 Adaptcoriolisdis.m for a discretization of inertial oscillation with a frictionalterm

du

dt= fv − c u (2.55)

dv

dt= −fu − c v, (2.56)

wherec = f k. Run the explicit discretization with increasing values ofk in [0, 1]. For whichvalue ofk does the explicit Euler discretization give you a solution with constant norm? Canyou interpret this result in view of the modified equation?

Solution We can start to copycoriolisdis.m and rename itnum ex 2 7.m . Then wecan edit and see it callsnumcorio.m so we have to copy it too from the distribution andrename itnumcorionew.m . Then of course the calls innum ex 2 7.m need to be adaptedaccordingly. Then we have to include a way to pass the friction parameterk to the subroutineand include the discretization of the friction term. The existing code solves the discretizationof

du

dt= fv

dv

dt= −fu

Page 13: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

13

discretized as

un+1 − un∆t

− f [(1− α)vn + αvn+1] = 0 (2.18a)

vn+1 − vn∆t

+ f [(1− α)un + αun+1] = 0, (2.18b)

which is solved as a linear system for the two unknownsun+1 andvn+1,

un+1 − αf∆tvn+1 = un + f∆t(1− α)vn (2.19a)

+ αf∆tun+1 + vn+1 = vn − f∆t(1− α)un (2.19b)

with the right-hand side calculated from the old values of the unknowns.With the frictional term discretised in an explicit way

un+1 − un∆t

− f [(1− α)vn + αvn+1] = −kfun (2.20a)

vn+1 − vn∆t

+ f [(1− α)un + αun+1] = −kf vn, (2.20b)

all we have to do is to add the termskf∆t un andkf∆t vn to the right hand side of thesystem to be solved

un+1 − αf∆tvn+1 = un + f∆t(1− α)vn − kf∆t un (2.21a)

+ αf∆tun+1 + vn+1 = vn − f∆t(1− α)un − kf∆t vn (2.21b)

and identify in the code where these right hand sides are calculated:

while time< tf,% right hand side of discretisation

ru=un+umafdt * vn;rv=vn-umafdt * un;

to adapt it with a suitable definition ofkfdt

while time< tf,% right hand side of discretisation

ru=un+umafdt * vn-kfdt * un;rv=vn-umafdt * un-kfdt * vn;

Note also how it is always the factorf∆t which appears. We can start our tests withk = 0 inwhich case we should recover the inertial oscillation with increasing amplitude because of theexplicit discretisation. When we add a loop for different values ofk around the code, we seethat with increasing values ofk, the outward spiraling solution turns into a inward spiralingsolution, corresponding of course to the damped solution tending to zero (you can try to findthe analytical solution of the damped oscillation as an additional exercise). We indeed passby a solution in which the norm remains constant. It is easy see when this happens: (2.28)shows that the explicit discretisation of the Coriolis termalone amounts to add an anti-friction

Page 14: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

14 CHAPTER 2.

−2 −1.5 −1 −0.5 0 0.5 1 1.5 2−2

−1.5

−1

−0.5

0

0.5

1

1.5

2 Critical k= 0.025

u

v

Figure 2-1 Explicit discretisation of Coriolis term with critical damping parameterk = f∆t/2

Page 15: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

15

to the system. All we have to do is to find the value ofk which just cancels this antifriction toget the solution of the inertial oscillation of constant norm: k = f∆t/2. Note that the valuedepends on the time-step. We can ckeck our analysis by running the code with this parameterand indeed we get the solution depicted in Figure 2-1

2.8 Try several time discretization methods on the following set of equations:

du

dt= fv (2.57)

dv

dt= − fu+ fk (1 − u2)v, (2.58)

with initial conditionu = 2, v = 0 at t = 0. Use two values for the parameterk: firstk = 0.1 and thenk = 1. Finally try k = 5. What do you notice?

Solution

2.9 Prove that an inertial oscillation with modified angular frequency (2.34) is the exactsolution of the semi-implicit scheme (2.32) (Hint: Insert the solution into the finite-differenceequations and find a condition onf .)

Solution

Page 16: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

16 CHAPTER 2.

Page 17: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 3

3.1 Compare values of density obtained with the full equation ofstate for seawater foundin MATLAB file ies80.m with values obtained from the linearized version (3.4), forvar-ious trial values ofT andS. Then compare density differences between two different watermasses, calculated again with both state equations. Finally, using numerical derivatives ofthe full equation of state with the help of MATLAB file ies80.m , can you provide a numer-ical estimate for the expansion coefficientsα andβ introduced in (3.4) for a Mediterraneanwater mass ofT0 = 12.8◦C,S0 = 38.4?

Solution

3.2 Generalize the finite-volume method to a two-dimensional system. In particular, whatkind of fluxes do you have to define and how do you interpret them? Is local and globalconservation still ensured?

Solution

3.3 Derive a conservative form of the momentum equations without friction in sphericalcoordinates and outline a finite-volume discretization. (Hint: Use volume conservation ex-pressed in spherical coordinates and volume integrals in spherical coordinates according to∫

V u dV =∫

r

λ

ϕu r2 cosϕ dϕ dλ dr.)

Solution

17

Page 18: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

18 CHAPTER 3.

3.4 Using the finite-volume approach of the one-dimensional temperature evolution assum-ing that only advection is present, with a flow directed towards increasingx (u > 0), dis-cretize the average fluxes. What kind of hypothesis do you need to make to obtain an algo-rithm allowing you to calculateT n+1

i knowing the values ofT at the preceding time-step?

Solution The objective here is to make students aware of the large degree of freedom theyhave in designing the flux calculation. Starting from the finite-volume approach

T n+1i − T ni +

∫ tn+1

tnqi+1/2 dt−

∫ tn+1

tnqi−1/2 dt

∆xi= 0,

the budget can be expressed in terms of time-averaged fluxesq

q =1

∆tn

∫ tn+1

tnq dt (3.1)

to yield an equation for discrete averaged quantities:

T n+1i − T ni∆tn

+qi+1/2 − qi−1/2

∆xi= 0. (3.2)

To be able to calculateT n+1i from the previous valus ofT∗, available on all grid points, we

must express the time-average fluxes using those valuesT∗. The only constraint is that when∆t→ 0 and∆x→ 0 we recover the advection equation.

For example: any interpolation at interfacei + 1/2 using T ni and T ni+1 will tend to thevalueTi+1/2 when the grid size is decreased and the finite differencing offluxes leads to thefirst derivative appearing the in the advection. So a possible choice is

qi+1/2 ≃ u(

wT ni + (1− w)T ni+1

)

(3.3)

for any weightw ∈ [0, 1]. Pluggin this into the flux budget with constant grid spacing∆xi = ∆x and time steps∆tn = ∆t for simplicity we get

T n+1i − T ni

∆t+

u(

wT ni + (1− w)T ni+1

)

− u(

wT ni−1 + (1 − w)T ni)

∆x= 0. (3.4)

or

T n+1i = T ni −

u∆t

∆x

[

(1− w)T ni+1 − wT ni−1 − (1− 2w)T ni]

(3.5)

With this form we can calculate the new value in each of the grid points knowing the tem-perature on the grid at the previous time step (the right handside can be computed). Wecan try the scheme first chosing the casew = 1/2 assuming (naively, see later) that the bestinterpolation at the interface is the average value of the surrounding boxes.

Page 19: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

19

-30

-20

-10

0

10

20

30

0 10 20 30 40 50

0

10

20

30

40

50

Figure 3-1 T as a function of grid point index ofx and time step. Observe the increase in amplitudeof the solution

T n+1i = T ni −

u∆t

2∆x

(

T ni+1 − T ni−1

)

(3.6)

and we reckognize of course the approximation of the advective derivative. To test, we canusenum ex 3 4.m . It programs the algorithm in a very naive way in the sense that it storesall time steps. Note also thatu, ∆t and∆x only appear in combination. Execution of theprogram provides the field in Figure (3-1) and shows how the solution is growing over time,in gross contradiction to the physics of the problem.

The questions is of course why it does not work. A detailed analysis will follow in chapter6, but one can already say that the local simple average at theinterface completely ignores thefact that during the time step, the whole field has been translated to the right. Hence a betteridea would be to use a larger value ofw to give more weight to the point heading towardsthe interface (the one to the left since we assumeu > 0). At the limit we can tryw = 1 andexecute again the program to now get better results in Figure(3-2)

Further adaptations The students can try to get rid of the two dimensional array tobereplaced by two one dimensional arrays, one to hold new values, one for the old values andin the time loop a copy of old values into new values once the time step if finished. Also theproblem of boundary conditions which is hidden in the exercise can be looked at (but this

Page 20: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

20 CHAPTER 3.

0

0.2

0.4

0.6

0.8

1

0 10 20 30 40 50

0

10

20

30

40

50

Figure 3-2 T as a function of grid point index ofx and time step. Observe the transport of the solution

Page 21: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

21

will be done in Chapter 6 anyway)

3.5 For flux calculations, interpolations at the cell interfaceare generally used. Analyzehow a linear interpolation using the two neighbor points behaves compared to a cubic in-terpolation using four points. To do so, sample the functionex at x = −1.5,−0.5, 0.5, 1.5and interpolate atx = 0. Compare to the exact value. What happens if you calculated theinterpolation not at the center but atx = 3 or x = −3 (extrapolation)? Redo the exercisebut add an alternating error of +0.1 and -0.1 to the four sampled values.

Solution The objective here is to look how an interpolation behaves. The question clearlystates that a cubic interpolation across 4 points be compared to a linear interpolation using twopoints. Rather than to program those interpolations explicitly we can realize more generallythat withn+1 points(xi, yi), we can (except in pathological cases) exactly define then+1coefficients appearing in a polynome of degreen (linear:n = 1, cubic,n = 3). This definesin fact the so-called Lagrange interpolationL(x):

L(x) =

n∑

j=0

yj

n∏

i=0,i6=j

x− xixj − xi

(3.7)

This defines indeed a polynome of degreen. It is easy to verify thatL(xk) = yk for allk = 0, ..., n and hence it is the polynome of degreen which passes through then samplepoints (providedxi 6= xj for all i 6= j). This function has been programmed in functionlagrange.m . Hence we can use it to interpolate the sampled exponential function. Thesolution filenum ex 3 5.m first calculates the interpolation inx = 0: a handmade linearinterpolation (average value!) compared to the call tolagrange.m and then the cubicinterpolation using the Lagrange interpolation, exhibiting a lower error than the linear inter-polation. Then the solution is extended to a list ofx coordinates for interpolation to plot howthe interpolation behaves in other points (see Figure 3-3).As expected using more points im-proves the interpolation in the center of the domain. For theextrapolation, we could calculatethe value only inx = 3 andx = −3, but with the approach used to plot Figure 3-3, we canextend the plotting easily to create Figure 3-4, showing howthe function estimate degradeswhen looking at locations outside of the domain covered by samples: Extrapolations exhibitlarge errors.

When adding the alternating noise to the sampled values, we can redo the same plottingand get Figures 3-5 and 3-6. It shows how sensitive extrapolations are with respect to smallchanges in the input values (in particular, look how the cubic function behaves inx = −3when adding the noise). Now with extrapolation also for cubic

Take-home message: Extrapolations are not robust, interpolations are betterconditioned,particularly in the center of the domain. Noise has impact exasperated in extrapolated regions.

Possible further work: Polynomial interpolations can oscillate rapidly when approach-ing boundary of data coverage but still in the regions covered by data. Also they can lead

Page 22: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

22 CHAPTER 3.

-2

0

2

4

6

8

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

y

x

Figure 3-3 Original function (in blue), sample points, linear interpolation and cubic interpolation

Page 23: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

23

-5

0

5

10

15

20

25

-3 -2 -1 0 1 2 3

y

x

Figure 3-4 Original function (in blue), sample points, linear interpolation and cubic interpolation

Page 24: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

24 CHAPTER 3.

-2

0

2

4

6

8

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

y

x

Figure 3-5 Original function (in blue), sample points with noise, linear interpolation and cubic inter-polation

Page 25: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

25

-5

0

5

10

15

20

25

-3 -2 -1 0 1 2 3

y

x

Figure 3-6 Original function (in blue), sample points with noise, linear interpolation and cubic inter-polation

Page 26: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

26 CHAPTER 3.

-2000

-1500

-1000

-500

0

500

-10 -5 0 5 10

y

x

Figure 3-7 All data points at zero except the central point at value 1. Note the very large values nearthe last data points.

to values outside of the original data range even in the interpolation region, as shown innum ex 3 5 more.m used to produce Figure 3-7.

Page 27: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 4

4.1 When air and sea surface temperatures,Tair and Tsea, are close to each other, it isacceptable to use a linearized form to express the heat flux across the air-sea heat interface,such as

− κT∂Tsea∂z

=h

ρ0Cv(Tsea − Tair) (4.55)

whereh is an exchange coefficient in W m−2 K−1. The coefficient multiplying the temperaturedifferenceTsea−Tair has the units of a velocity and, for this reason, is sometimescalled pistonvelocity in the context of gas exchange between air and water. Implement this boundarycondition for a finite-volume ocean model. How would you calculateTsea involved in theflux in order to maintain second-order accuracy of the standard second derivative within theocean domain?

Solution The fact that a finite-volume ocean model is under investigation suggests that thatthe surface boundary has been placed where the air-sea fluxesare to be described, in otherword at the air-sea interface, whereas the temperature field, the grid-cell average, is thereforefound below the air-sea interface at a distance∆z/2. If Ts is the value of the model tempera-ture at this grid point, it is not exactly on the sea-surface,which we need to evaluate the heatflux from (4.55) which we can rewrite

∂Tsea∂z

= − 1

d(Tsea − Tair) d =

ρ0CvκTh

(4.1)

Approach 1: Adding a virtual point with temperatureT ∗ at distance∆z/2 above the sea-surface we can to second order write the following discretisation:

T ∗ − Ts∆z

= − 1

d

[

(T ∗ + Ts)

2− Tair

]

(4.2)

from which we can deduce the virtual temperature to put on thenumerical grid

T ∗ =(1− r

2 )Ts + rTair

1 + r2

(4.3)

or directly the estimation of the sea-surface temperatureTsea = (T ∗ + Ts)/2:

Tsea =Ts +

r2Tair

1 + r2

(4.4)

27

Page 28: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

28 CHAPTER 4.

and also the gradient (proportional to the flux needed in the finite-volume budget)

T ∗ − Ts∆z

= − 1

d

(Ts − Tair)1 + r

2

(4.5)

Approach 2: We can directly try to estimate the temperature at the surface by a Taylordevelopment ofT at the surface

Ts = Tsea −∆z

2

∂Tsea∂z

+O(∆z2) (4.6)

which solving forTsea and injecting into the boundary condition provides the following rela-tionship

∂Tsea∂z

= − 1

d

(

Ts − Tair +∆z

2

∂Tsea∂z

)

(4.7)

from which we can extract the gradient (and hence later the flux):

∂Tsea∂z

= − 1

d

(Ts − Tair)1 + r

2

(4.8)

which is the same as the one found before in its discretised form.Further comments: In reality, the ocean surface is generally well mixed so that the

approximationTsea = Ts is quite usual. This can be incorporated in the flux formulation wefound by adding a tuning parameterǫ

∂Tsea∂z

= − 1

d

(Ts − Tair)1 + ǫr

2

(4.9)

whereǫ ∈ [0, 1] controls to which extend on wishes to make this approximation based on theknowledge of the ocean under investigation and the grid size.

4.2 In some cases, particularly analytical and theoretical studies, the unknown field can beassumed to be periodic in space. How can periodic boundary conditions be implementedin a numerical one-dimensional model, for which the discretization scheme uses one pointon each side of every calculation point? How would you adapt the scheme if the interiordiscretization needs two points on each side instead? Can you imagine what the expressionhalo used in this context refers to?

Solution

Page 29: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

29

4.3 How do you generalize periodic boundary conditions (see preceding problem) to twodimensions? Is there an efficient algorithmic scheme that ensures periodicity without partic-ular treatment of corner points? (Hint: Think about a method/order of copying rows/columnsthat ensure proper values in corners.)

Solution

4.4 Assume you implemented a Dirichlet condition for temperature along a boundary onwhich a grid node exists but would like to diagnose the heat flux across the boundary. Howwould you determine the turbulent flux at that point with third-order accuracy?

Solution

4.5 Models can be used on parallel machines by distributing workamong different proces-sors. One of the possibilities is the so-called domain decomposition in which each processoris dedicated to a portion of the total domain. The model of each sub-domain can be inter-preted as an open-boundary model. Assuming that the numerical scheme for a single variableusesq points on each side of the local node, how would you subdividea one-dimensional do-main into sub-domains and design data exchange between these subdomains to avoid theintroduction of new errors? Can you imagine the problems youare likely to encounter intwo dimensions? (Hint: Think how periodic boundary conditions were handled in the haloapproach of the preceding two problems.)

Solution

4.6 Develop a MATLAB program to automatically calculate finite-difference weightingcoefficientsai for an arbitrary derivative of orderp usingl points to the left andm points tothe right of the point of interest:

dpu

dtp

tn

≃ a−lun−l + ...+ a−1un−1 + a0u

n + a1un+1 + ...+ amu

n+m. (4.56)

Page 30: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

30 CHAPTER 4.

The step is taken constant. Test your program on the fourth-order approximation of thefirst derivative. (Hint: Construct the linear system to be solved by observing that∆t shouldcancel out in all terms except for the relevant derivative sothat∆tpai can be chosen as theunknowns.)

Solution We can start as in Chapter 1 p 30, by expanding allu∗ in the right-hand side aroundtn by Taylor Series and then collecting all terms with the same order of derivative1. Since wehavel +m + 1 coefficients to be determined, we will need to go up to derivatives of orderl +m.

dpu

dtp

tn

≃ (a−l + ....+ a−1 + a0 + a1 + ...+ am) un

+ (−la−l − ....− a−1 + a0 + a1 + ...+mam)∆tdu

dt

tn

+ (l2a−l − ....+ a−1 + a0 + a1 + ...+m2am)∆t2

2

d2u

dt2

tn

+ (−l3a−l − ....− a−1 + a0 + a1 + ...+m3am)∆t3

6

d3u

dt3

tn...

+ ((−l)pa−l − ....+ (−1)pa−1 + a0 + a1 + ...+mpam)∆tp

p!

dpu

dtp

tn...

+ ((−l)(l+m)a−l − ....+ (−1)(l+m)a−1 + a0 + a1 + ...+m(l+m)am)∆t(l+m)

(l +m)!

d(l+m)u

dt(l+m)

tn

(4.10)

From here it is clear that we must ensurep ≤ l + m to be able to reach the derivativewe want to approximate. To find the approximation, one needs to enforce all lines up tothe one containing the desired derivative to be zero. Ifp < l + m the lines after the onecontaining the desired derivative can also be forced to zeroto lead to higher orders: Theorder of approximation will then be at leastl +m+ 1− p.

A =

1 ... 1 1 1 ... 1−l ... −1 1 1 ... ml2 ... 1 1 1 ... m2

−l3 ... −1 1 1 ... m3

... ... ... ... ... ... ...(−l)p ... (−1)p 1 1 ... mp

... ... ... ... ... ... ...(−l)(l+m) ... (−1)(l+m) 1 1 ... m(l+m)

(4.11)

1To make the recollection easy, you can write the developmentvertically on a blackboard and then read horizon-tally line by line the terms to be regrouped.

Page 31: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

31

x =

a−l...a−1

a0a1...am

∆tp

p!(4.12)

So that the coefficients can be found by solving

Ax = ep+1 (4.13)

whereep+1 is a vector with zeros everywhere except for itsp+ 1th component whose valueis 1. This has been implemented in functiondiscretise.m called from example filenum ex 4 6.m . For convenience, the code also provides as second result a number, whichwhen multiplied with the coefficients provides integer values (so that the coefficients appearas fractions). For the fourth-order approximation of the first derivative this demands to calldiscretise(2,2,1) which yields

ans= (1 -8 0 8 -1) / 12which can be compared to the content of tables in Appendix C. Also the factor∆tp must

of course be included in the final discretisation.

4.7 Imagine that you perform a series of simulations of the same model with time steps of8∆t, 4∆t, 2∆t and∆t. The numerical discretization scheme is of orderm. Which combina-tion of the different solutions would best approximate the exact solution, and what truncationorder would the combined solution have?

Solution

4.8 For a grid node placed on the boundary, show that using the value

Tm =2

3

(

−∆x qb

κT− 1

2Tm−2 + 2Tm−1

)

. (4.57)

allows us to impose a flux condition at nodem with second-order accuracy.

Solution

Page 32: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

32 CHAPTER 4.

Page 33: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 5

5.1 Cure the unstable versionfirstdiffusion.m by adapting the time step and verifythat below the limit (5.35) the scheme is indeed stable and provides accurate solutions (Figure5-1).

Solution

5.2 For a 1D Euler scheme with implicit factorα, constant grid size and constant diffusioncoefficient, prove that the stability condition is(1− 2α)D ≤ 1/2.

Solution

5.3 Implement periodic boundary conditions in the 1D diffusionproblem (i.e.,ctop = cbottomandqtop = qbottom). Then, search the internet for a tridiagonal matrix inversion algorithmadapted to periodic boundary conditions and implement it.

Solution

5.4 Implement the 1D finite-volume method with an implicit factor α and variable diffusioncoefficient. Set the problem with the same initial and boundary conditions as in the beginningof Section 5.3.Verify your solution against the exact solution (5.19).

33

Page 34: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

34 CHAPTER 5.

36 36.2 36.4 36.6 36.8 37 37.2 37.4 37.6 37.8 38−100

−90

−80

−70

−60

−50

−40

−30

−20

−10

0

z

c

Figure 5-1 With a time step such thatD = 0.1, the initial condition (sin-gle line) of the 1D diffusion problemhas been damped after 500 time stepsand the numerical solution of the ex-plicit scheme (open circles) is almostindistinguishable from the exact solu-tion (shown as a line crossing the cir-cles), even with only 30 grid pointsacross the domain.

Solution

5.5 Apply the code developed in Section 5.6 to the Analytical Problem 5-6. Start with anarbitrary initial condition and march in time until the solution becomes stationary. Estimatea priorithe permitted time step and the minimum total number of time steps, depending on theimplicit factor. Take∆z = 2, track convergence during the calculations and compare yourfinal solution with the exact solution. Also try to implementthe naive discretization

∂z

(

κ∂c

∂z

)∣

zk

= κ∂2c

∂z2

zk

+∂κ

∂z

zk

∂c

∂z

zk

∼ κk (ck+1 − 2ck + ck−1)

∆z2

+(κk+1 − κk−1)

2∆z

(ck+1 − ck−1)

2∆z. (5.58)

Solution

Page 35: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

35

5.6 The Dufort-Frankel scheme approximates the diffusion equation by

cn+1k = cn−1

k + 2D[

cnk+1 − (cn+1k + cn−1

k ) + cnk−1

]

. (5.59)

Verify the consistency of this scheme. What relation must beimposed between∆t and∆zwhen each approaches zero to ensure consistency? Then, analyze numerical stability usingthe amplification-factor method.

Solution

Page 36: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

36 CHAPTER 5.

Page 37: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 6

6.1 Prove the assertion that a forward-in-time, central-in-space approximation to the ad-vection equation is unconditionnaly unstable.

Solution

6.2 Use advleap.m with different initialization techniques for the first timestep of theleapfrog scheme. What happens if an inconsistent approach is used (for example zero val-ues)? Can you eliminate the spurious mode totally by a cleverinitialization of the auxiliaryinitial conditionc1 when a pure sinusoidal signal is being advected?

Solution

6.3 Use the stability analysis under the form (5.31) using an amplification factor. Verify thatthe stability condition is|C| ≤ 1.

Solution

6.4 Verify numerically that the leapfrog scheme conserves variance of the concentrationdistribution when∆t → 0. Compare with the Lax-Wendroff scheme behavior for the sametime steps.

37

Page 38: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

38 CHAPTER 6.

Solution

6.5 Analyze the numerical phase speed of the upwind scheme. Whathappens forC = 1/2?Which particular behavior is observed whenC = 1?

Solution

6.6 Design a fourth-order spatial difference and explicit timestepping for the 1D advectionproblem. What is the CFL condition of this scheme? Compare tothe Von Neumann stabilitycondition. Simulate the standard advection test case.

Solution

6.7 Design a higher-order finite-volume approach by using higher-order polynomials to cal-culate the flux integrals. Instead of a linear interpolationas in the Lax-Wendroff scheme, usea parabolic interpolation.

Solution

6.8 Show that the Von Neumann stability condition of the Beam-Warming scheme is0 ≤C ≤ 2.

Solution

Page 39: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

39

0 10 20 30 40 50 60 70 80 90−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

1.2

i

c

Figure 6-1 Standard test case with thetrapezoidal scheme and centered spa-tial derivatives.

6.9 Implement the trapezoidal scheme with centered space difference using the tridiagonalalgorithmthomas.m . Apply it to the standard problem of the top-hat signal advection andverify that you find the result shown in Figure 6-1. Provide aninterpretation of the result interms of the numerical dispersion relation. Verify numerically that the variance is conservedexactly.

Solution

6.10 Show that the higher-order method for flux calculation at an interface using a linearinterpolation on a non-uniform grid with spacing∆xi between interfaces of celli leads tothe following flux, irrespective of the sign of the velocity

qi−1/2 = u(∆xi−1 − u∆t)cni + (∆xi + u∆t)cni−1

∆xi +∆xi−1. (6.77)

Solution

Page 40: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

40 CHAPTER 6.

6.11 Use a leapfrog centered scheme for advection with diffusion. Apply it to the standardtop-hat for different values of the diffusion parameter andinterpret your results.

Solution

6.12 Find an explanation for why the2∆x mode is stationary in all discretizations of ad-vection. Hint: Use a sinusoidal signal of wavelength2∆x and zero phase, then sample it.Change the phase (corresponding to a displacement) by different values less thanπ and re-sample. What do you observe?

Solution

6.13 Prove that (6.54) is the sufficient stability condition of scheme (6.51).Hint: Rewrite||2 as(φ−2C2ξ)2+4C2ξ(1−ξ) and observe that as a function ofφ the amplification factorreaches its maxima at the locations of the extrema ofφ, itself constrained by (6.54).

Solution

6.14 Consider the one-dimensional advection-diffusion equation with Euler time discretiza-tion. For advection, use a centered difference with implicit factor α, and for diffusion thestandard second-order difference with implicit factorβ. Show that numerical stability re-quires(1 − 2α)C2 ≤ 2D and(1 − 2β)D ≤ 1/2. Verify that, without diffusion, the explicitcentered advection scheme is unstable.

Solution

Page 41: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

41

6.15 Usetvdadv2D.m with different parameters (splitting or not, pseudo-mass conserva-tion or not) under different conditions (sheared velocity field or solid rotation) and initial con-ditions (smooth field or strong gradients) with different flux limiters (upwind, Lax-Wendroff,TVD, etc.) to get a feeling of the range of different numerical solutions an advection schemecan provide compared to the analytical solution.

Solution

Page 42: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

42 CHAPTER 6.

Page 43: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 7

7.1 An atmospheric pressure fieldp over a flat bottom is given on a rectangular grid accord-ing to

pi,j = PH exp(−r2/L2) + pǫ ξi,j r2 = (xi − xc)2 + (yj − yc)2 (7.66)

whereξ is a normal (Gaussian) random variable of zero mean and unit standard deviation.The high pressure anomaly is ofPH = 40 hPa and its radiusL = 1000 km. For the noiselevel, takepǫ = 5 hPa. Use a rectangular grid centered aroundxc, yc with a uniform gridspacing∆x = ∆y = 50 km. Calculate and plot the associated geostrophic currentsfor f =10−4 s−1. To which extent is volume conservation satisfied in your finite-difference scheme?What happens ifpǫ = 10 hPa or∆x = ∆y = 25 km? Can you interpret your finding?

Solution

7.2 Open filemadt oer merged h 18861.nc and use the sea surface height recon-structed from satellite data to calculate geostrophic ocean currents around the Gulf Stream.Data can be read withtopexcirculation.m . For conversion from latitude and longi-tude to local Cartesian coordinates, 1◦ latitude = 111 km and 1◦ longitude = 111 km× cos(latitude). [Altimeter data are products of the CLS Space Oceanography Division; see alsoDucet et al. (2000)].

Solution First make sure you can read the netCDF file by executingtopexcirculation.mand you should get a figure like Figure (7-1). If it does not work, make sure you triedtrync.m in the ../nc folder, which tries to identify which netCDF interface yoursys-tem uses.

Once the sea-surface height is read and for each grid point the coordinates known, we canimmediately proceed to the discretisation of the geostrophic equilibrium near the surface:

0 = +fv − g ∂η∂x

(7.1)

0 = −fu − g ∂η∂y

(7.2)

43

Page 44: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

44 CHAPTER 7.

50

100

150

200

Sea surface height anomaly

260 280 300 320 340 360

10

20

30

40

50

60

70

80

Figure 7-1 Sea surface height from altimeters; be aware of units

Page 45: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

45

Because the grid spacing is not uniform (in fact in the south-north direction grid spacing∆y changes as can bee seen by plotting the coordinates retrieved from the netcdf file). AlsoCoriolis parameter changes with latitude and we discretise, aligning i with longitude andjwith latitude

vi,j = +g

fj

(ηi+1,j − ηi−1,j)

(xi+1,j − xi−1,j)(7.3)

ui,j = − g

fj

(ηi,j+1 − ηi,j−1)

(yi,j+1 − yi,j−1)(7.4)

where the distances must be calculated in meters using the grid values of longitudeλ andlatitudeϕ provided in degress:

xi+1,j − xi−1,j = 111000 (λi+1,j − λi−1,j) cos(ϕi,j π/180) (7.5)

yi,j+1 − yi,j−1 = 111000 (ϕi,j+1 − ϕi,j−1) (7.6)

This provides the requested velocity field shown in Figure (7-2) and Figure (7-3). Note thesignal of the Gulf Stream and the presence of eddies.

Further work The fields are a little bit noisy (remember that finite differencing of a fieldincreases the noise level). A possible extension is the filtering of the elevation field beforecalculating the geostrophic current. In this case, the landmask should be taken into account.

7.3 Use the meteorological pressure field at sea level to calculate geostrophic winds overEurope. First use the December 2000 monthly average sea-level pressure, then look at dailyvariations. Era40.m will help you read the data. Take care of using the local Coriolisparameter value. Geographical distances can be calculatedfrom the conversion factors givenin Numerical Exercise 7-2.

What happens if you redo your calculations in order to plan your sailing trip in thenorthern part of Lake Victoria? (ECMWF ERA-40 data were obtained from the ECMWFdata server.)

Solution

7.4 Use the red-black approach to calculate the numerical solution of (7.48) inside the basindepicted in Figure 7-4, withqi,j = −1 on the right-hand side of the equation andψi,j = 0along all boundaries. Implement a stopping criterion basedon a relative measure of theresidual compared tob.

Page 46: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

46 CHAPTER 7.

10

20

30

40

50

60

70

80

260 280 300 320 340 360

Geostrophic velocity field

Figure 7-2 Geostrophic velocity field

Page 47: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

47

0

0.2

0.4

0.6

0.8

1

1.2

1.4

velocity norm

260 280 300 320 340 360

10

20

30

40

50

60

70

80

Figure 7-3 Module of the velocity field

Page 48: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

48 CHAPTER 7.

40

0km

500 km

100 km

100 km

100 km

10

0km

ψ = 0

ψ = 0

Figure 7-4 Geometry of the idealizedbasin mentioned in Numerical Exercise7-4.

Solution

7.5 Use the conjugate-gradient implementation called intestpcg.m to solve the problemof Numerical Exercise 7-4 with improved convergence.

Solution

7.6 Redo Numerical Exercise 7-4 with the Gauss-Seidel approachusing over-relaxation andseveral values ofω between 0.7 and 1.999. For each value ofω, start from zero and convergeuntil reaching a preset threshold for the residual. Plot therequired number of iterationsuntil convergence as a function ofω. Design a numerical tool to find the optimal value ofωnumerically. Then repeat the problem by varying the spatialresolution, taking successively20, 40, 60, 80 and 100 grid points in each direction. Look at the number of iterations and theoptimal value ofω as functions of resolution.

Solution

Page 49: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

49

7.7 Prove that the parameterα given by (7.55) leads to a minimum ofJ defined in (7.52),for a given starting point and fixed gradientr. Also prove that at the next iteration of thesteepest-descent method, the new residual is orthogonal tothe previous residual. Implementthe steepest-descent algorithm to find the minimum of (7.52)with

A =

(

3 11 1

)

, b =

(

62

)

(7.67)

starting at the origin of the axes. Observe the successive approximations obtained by themethod. Hint: In the plane defined by the two unknowns, plot isolines ofJ and plot theline connecting the successive approximations to the solution. Make several zooms near thesolution point.

Solution

7.8 Write a general solver for the Poisson equation as a Matlab function. Provide formasked grids and a variable rectangular grid such that∆x depends oni and ∆y on j.Also permit variable coefficients in the Laplacian operator, as found in (7.44) and apply tothe following situation.

In shallow, wind-driven basins, such as small lakes and lagoons, the flow often strikesa balance between the forces of surface wind, pressure gradient and bottom friction. Upondefining a streamfunctionψ and eliminating the pressure gradient, one obtains for steadyflow (Matthieu et al., 2002):

∂x

(

2νEh3

∂ψ

∂x

)

+∂

∂y

(

2νEh3

∂ψ

∂y

)

=∂

∂y

(

τx

ρ0h

)

− ∂

∂x

(

τy

ρ0h

)

, (7.68)

whereνE is the vertical eddy viscosity,h(x, y) is the local bottom depth, and (τx, τy) thecomponents of the surface wind stress. In the application, takeνE = 10−2 m2/s,ρ0 = 1000kg/m3, h(x, y) = 50− (x2+4y2/10) (in m, withx andy in km),τx = 0.1 N/m2, andτy = 0within the elliptical domainx2 + 4y2 ≤ 400 km2.

Solution NOTE: h(x, y) = 50− (x2 +4y2/10) should readh(x, y) = 50− (x2 +4y2)/10

∂x

(

αx∂ψ

∂x

)

+∂

∂y

(

αy∂ψ

∂y

)

= F (7.7)

Page 50: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

50 CHAPTER 7.

Is easily translated into a finite difference code on a regular grid wherex andy only vary withi andj respectively:

αxi+1/2

ψi+1−ψxi+1−xi

− αxi−1/2

ψ−ψi−1

xi−xi−1

xi+1−xi−1

2

+αyj+1/2

ψj+1−ψyj+1−yj

− αyj−1/2

ψ−ψj−1

yj−yj−1

yj+1−yj−1

2

= Fi,j

(7.8)where unwritten subscripts are as usuali or j. In the computer code, indexi + 1/2 is notallowed and by convention, we can store the value in either locationI or I + 1 of an array(note how this is explained in the code).

This translated easily into an overrelaxation method.

ri,j = Fi,j−αxi+1/2

ψi+1−ψxi+1−xi

− αxi−1/2

ψ−ψi−1

xi−xi−1

xi+1−xi−1

2

−αyj+1/2

ψj+1−ψyj+1−yj

− αyj−1/2

ψ−ψj−1

yj−yj−1

yj+1−yj−1

2(7.9)

ψi,j ← ψi,j − ωri,jsi,j

(7.10)

Car must be taken to scale the coefficient multiplying the residual bysi,j by collectingthe coefficients multiplyingψi,j

si,j =αxi+1/2

1xi+1−xi

+ αxi−1/21

xi−xi−1

xi+1−xi−1

2

+αyj+1/2

1yj+1−yj

+ αyj−1/2

1yj−yj−1

yj+1−yj−1

2(7.11)

so that the overrelaxtion parameter is as usual∈]0, 2[. Since this scalesi,j is independentof the solution it can be calculated outside of the iterativeloop only once. This iterativeinversion has been implemented intoinversepoisson.m .

For the implementation of the present problem,αx andαy are readily calculated as aver-ages ofν/h3 at the interfaces and the right-hand side can be calculated by finite differencesor analytical derivations innum ex 7 8.m . Care must also be taken with units (note thatquestion mixes m.k.s units and kilometers). This program then calls the iterative solver. Thesolution should look like Figure7-5.

Further comments: If the students had applied the original function forh, they wouldhave obtained negative depth values. When applying the iterative solution techniques, the so-lution would rapidly diverge. This is easily explained by the fact that in this case, the pseudotime stepping amounts to solve a diffusion equation with negative diffusion coefficient, aphysically unstable situation.

Other tests: thetest.m can also be used to check simple exammples and see the effectof putting for exampleαx = 0.

7.9 Use the tool developed in Numerical Exercise 7-8 to simulatethe stationary flow acrossthe Bering Sea, assuming the right-hand side of (7.68) is zero. Useberingtopo.m to read

Page 51: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

51

-4000

-2000

0

2000

4000

Streamfunction; remaining error 8.9261e-008

-30000 -20000 -10000 0 10000 20000 30000

-15000

-10000

-5000

0

5000

10000

15000

Figure 7-5 Streamfunction solution after convergence

Page 52: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

52 CHAPTER 7.

Figure 7-6 Model of the Bering Seafor Numerical Exercise 7-9. For thecalculation of the streamfunction, as-sume that West of -169◦ longitude allland points have a prescribed stream-functionΨ1 = 0 and those to the EastΨ2 = 0.8 Sv (1 Sv = 106 m3/s). Forconvenience, you may consider clos-ing the western and eastern boundarycompletely and imposing a zero normalderivative ofΨ along the open bound-aries.

the topography of Figure7-6. To pass from latitude and longitude to Cartesian coordinates,use the conversion factors given in Numerical Exercise 7-2 but with cos (latitude) taken ascos(66.5◦N) to obtain a rectangular grid. Compare your solution to thecase of uniformaverage depth in place of the real topography, maintaining the same land mask.

Solution

7.10 Prove that matrixA arising from the discretization of (7.48) is symmetric and positivedefinite if we change the sign of each side. Show also that the latter property ensureszTAz >0 for anyz 6= 0.

Solution

7.11 Calculate the amplification factor of Gauss-Seidel iterations including over-relaxation.Can you infer the optimal over-relaxation coefficient for Dirichlet conditions? Hint: Theoptimal parameter will ensure that the slowest damping is accomplished as fast as possible.

Solution

Page 53: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

53

Page 54: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

54 CHAPTER 7.

Page 55: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 8

8.1 How can we obtain initial conditions foraj andbj in the expansions (8.40) from initialconditions on the physical variablesu = u0(z) andv = v0(z)? Hint: Investigate a least-square approach and an approach in which the initial error isforced to vanish in the senseof (8.42). When do the two approaches lead to the same result?

Solution The question is thus to find the coefficientsaj andbj at t = 0

u(z, t) = a1(t)φ1(z) + a2(t)φ2(z) + ...+ aN(t)φN (z)

=N∑

j=1

aj(t)φj(z) (8.1a)

v(z, t) = b1(t)φ1(z) + b2(t)φ2(z) + ...+ bN (t)φN (z)

=

N∑

j=1

bj(t)φj(z). (8.1b)

knowing the profile att = 0: u = u0(z) andv = v0(z). Here there is no question ofdynamics hence the problem foru andv are two separate problems which can be treatedindividually and in exactly the same way. So we only look at the problem foru.

If we want to find the best coefficients in theleast-square approach we must chose thecoefficientsaj(0) such as to minimizeJ :

J =

∫ h

0

(u(z, 0)− u0(z)))2 dz =

∫ h

0

N∑

j=1

aj(0)φj(z)− u0(z)

2

dz (8.2)

TheN independent coefficients are easily determined by expressing extremal (and minimum)conditions ofJ :

∂J

∂ai(0)= 0 →

∫ h

0

N∑

j=1

aj(0)φj(z)− u0(z)

φi(z) dz (8.3)

which provides a linear system to solve when collecting all unkownsai(0) in a and defining

Mij =

∫ h

0

φiφj dz, gi =

∫ h

0

u0(z)φi dz. (8.4)

55

Page 56: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

56 CHAPTER 8.

Ma = g (8.5)

and we reckognize the mass matrix and the projection ofu0 on the basis functions. Note thatif basis functions are orthonormal, the inversion is particularly easy.

If the intention is to setweighted residuals to zero, we would need to impose

∫ h

0

wi

N∑

j=1

aj(0)φj(z)− u0(z)

dz = 0, (8.6)

and solve

Mij =

∫ h

0

wiφj dz, gi =

∫ h

0

u0(z)wi dz. (8.7)

Ma = g (8.8)

Obviously the two initialization procedures are identicalwheneverwi = φi, ie when aGalerkin method is used, the projection method is equivalent to a least-square fit.

In practice one would of course choose the method which is coherent with the one usedfor the dynamical model and chose the weightswi and base functionsφj as for the dynamicalmodel.

8.2 Usespectralekman.m to calculate numerically the stationary solutions of Analyt-ical Problem 8-12. Compare the exact and numerical solutions for h/d = 4 and assess theconvergence rate as a function of1/N , whereN is the number of eigenfunctions retained inthe trial solution. Compare the convergence rate of both cases (with and without stress at thetop) and comment.

Solution

8.3 Usespectralekman.m to explore how the solution changes as a function of the ratioh/d and how the numberN of modes affects your resolution of the boundary layers.

Solution

Page 57: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

57

8.4 Modify spectralekman.m to allow for time evolution, but maintaining constantwind stress and pressure gradient. Use a trapezoidal methodfor time integration. Startfrom rest and observe the temporal evolution. What do you observe?

Solution

8.5 Use a finite-volume approach with time splitting for the Coriolis terms and an explicitEuler method to discretize diffusion in (8.39a) and (8.39b). Verify your program in the caseof uniform eddy viscosity by comparing with the steady analytical solution. Then use theviscosity profileνE(z) = Kz(1− z/h)u∗. In this case, can you find the eigenfunctions of thediffusion operator and outline the Galerkin method? (Hint: Look for Legendre polynomialsand their properties.)

Solution

8.6 Assume that your vertical grid spacing in a finite-difference scheme is large comparedto the roughness lengthz0 and that your first point for velocity calculation is found atthedistance∆z/2 above the bottom. Use the logarithmic profile to deduce the bottom stress as afunction of the computed velocity at level∆z/2. Then use this expression in the finite-volumeapproach of Numerical Exercise 8-5 to replace the no-slip condition by a stress condition atthe lowest level of the grid.

Solution

Page 58: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

58 CHAPTER 8.

Page 59: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 9

9.1 Establish the numerical stability condition of schemes (9.53) and (9.54). Can you pro-vide an interpretation for the parameterc∆t/∆x? Compare to the CFL criterion.

Solution

9.2 Spell out the spatial discretization on the B–, C– and D–grids of Equations (9.4a)through (9.5).

Solution

9.3 Implement the C–grid in Matlab for equations (9.4a) through(9.5) with a variable fluidthickness given on a grid at the same location asη. Use a time discretization as in (9.54)and a fractional-step approach for the Coriolis term. Then use your code to simulate a pureKelvin wave for different values of∆x/R andk2xR

2 by initializing with the exact solution.(Hint: Use a periodic domain in thex–direction and a second impermeable boundary in they–direction, to be justified, aty = 10R. Start fromshallow.m .)

Solution

9.4 Analyze the way geostrophic equilibrium is represented in discrete Fourier modes on theB– and C–grids.

59

Page 60: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

60 CHAPTER 9.

Solution

9.5 Investigate group-velocity errors for the different Arakawa grids using the numericaldispersion relation given in (9.66). Use∆x = ∆y and distinguish two types of waves:kx 6= 0, ky = 0 andkx = ky. Vary the resolution by takingR/∆x = 0.2, 1, 5, whereR isthe deformation radius.

Solution

9.6 Design the ideal staggering strategy for a model in which theeddy viscosityνE is chosenproportional to|∂u/∂z|l2m, wherelm is a specified mixing length and velocityu is determinednumerically from a governing equation that includes vertical turbulent diffusion.

Solution

9.7 Assume you need to calculate the vertical component of relative vorticity from a discretevelocity field provided on the two-dimensional C–grid. Where is the most natural node tocalculate the relative vorticity? Can you see an advantage to using a D–grid here?

Solution

9.8 Can you think of possibilities to include bottom topographic variations as those inducingtsunamis in shallow-water equations?

Solution

Page 61: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

61

9.9 Take the variable depth implementation of Numerical Exercise 9-3 and apply it to thefollowing topography

h = H0 +∆H

[

1 + tanh

(

x− L2

D

)]

withH0 = 50 m,D = L/8 and∆H = 5H0. Use a solid wall atx = 0 andx = L = 100km and periodic boundary conditions in they–direction across a domain of length5L. Startwith zero velocities and a Gaussian sea surface elevation ofwidthL/4 and height of 1 m inthe center of the basin. Use linear bottom friction with friction coefficientr = 10−4 m/s.Trace the evolution of the sea surface elevation forf = 10−4 s−1.

Solution

9.10 Perform a storm-surge simulation with the implementation of Numerical Exercise 9-3by using a uniform wind stress over a square basin with a uniform topography and then withthe topography given in Numerical Exercise 9-9. Use the quadratic law (9.77) for bottomfriction.

Solution

Page 62: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

62 CHAPTER 9.

Page 63: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 10

10.1 Redo the analysis of nonlinear aliasing for a cubic term likedu/dt = −u3 in thegoverning equation foru. Why do you think aliasing is less of a concern in this particularcase?

Solution

10.2 An elliptic vortex patch with uniform vorticity inside and zero vorticity outside is calleda Kirchhoff vortex. Usecontourdyn.m with itest=1 to study the evolution of Kirch-hoff vortices of aspect ratios 2:1 and 4:1. What do you observe? Implement another time-integration scheme (among which the explicit Euler scheme)and analyze how it behaves witha circular eddy. (Hint: Love (1893) provides a stability analysis of the Kirchhoffvortex.)

Solution

10.3 Experiment withcontourdyn.m usingitest=4 in which two identical eddies areplaced at various distances. Start withdist=1.4 and then try the value1.1 . What hap-pens? Which numerical parameters would you adapt to improvethe numerical simulation?

Solution

63

Page 64: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

64 CHAPTER 10.

10.4 Simulate the eddy separation shown in Figure?? usingcontourdyn.m .

Solution

10.5 Discretize a circular eddy with vorticity varying linearlyfrom zero at the rim to amaximum at the center by usingM different vorticity values in concentric annuli. Thensimulate its evolution withM = 3.

Solution

10.6 Verify your findings of Analytical Problem 10-6 by adaptingshearedflow.m tosimulate the evolution of the most unstable periodic perturbation (for details on the numericalaspects, see Section??).

Solution

10.7 Adaptshearedflow.m to investigate the so-called Bickley jet with profile given by

u(y) = U sech2( y

L

)

(−∞ < y < +∞). (10.63)

Solution

Page 65: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 11

11.1 Use medprof.m to read average Mediterranean temperature and salinity verticalprofiles and calculateN2 for various levels of vertical resolution (averaging data withincells). What do you conclude? (Hint: Useies80.m for the state equation.)

Solution

11.2 Use the diffusion-equation solver of Numerical Exercise 5-4 with a turbulent diffusioncoefficient that changes from 10−4 m2/s to 10−2 m2/s wheneverN2 is negative. Simulate theevolution of a 50 m high water column with an initially stablevertical temperature gradient of0.3◦C/m subsequently cooled at the surface by a heat loss of100W/m2. Salinity is unchanged.Study the effect of changes in∆z and∆t.

Solution

11.3 Implement the algorithm outlined in Section??, to remove any gravitational instabilityinstantaneously. Keep the turbulent diffusivity constantat 10−4 m2/s and simulate the sameproblem as in Numerical Exercise 11-2.

Solution

65

Page 66: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

66 CHAPTER 11.

Page 67: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 12

12.1 Adapt the shallow-water equation model developed in Numerical Exercise 9-3 to sim-ulate seiches in a lake with a reduced-gravity model.

Solution

12.2 Discretize the linearized two-layer model in time and with ahorizontal Arakawa gridof your choice. Use a discretization that does not require the solution of a linear system.Provide a stability analysis neglecting the Coriolis force.

Solution

12.3 Implement the discretization of Numerical Exercise 12-2 and reproduce numericallythe solution of Section??.

Solution

12.4 Explore the implicit treatment of surface elevation in the barotropic component of thelayer equations and the corresponding equation forv. Use an Arakawa C-grid and implicittreatment of both the divergence term in volume conservation and pressure gradient in the

67

Page 68: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

68 CHAPTER 12.

momentum equations. Neglect the Coriolis force. Eliminatethe yet unknown velocity compo-nents from the equations to arrive at an equation forηn+1. Compare the approach with thepressure calculation used in conjunction with the rigid-lid approximation of Section?? andinterpret what happens when you take very long time steps.

Solution

12.5 Use different time-integration techniques to calculate trajectories associated with thefollowing 2D current field:

u = − cos(πt) y, v = + cos(πt) x (12.59)

from t = 0 to t = 1 and interpret the results. Prove that the trapezoidal scheme is reversiblein time.

Solution

12.6 Implement a random walk into the calculation of the trajectories of Numerical Exercise12-5 and verify the dispersive nature of the random walk. (Hint: Start with a dense cloud ofparticles in the middle of the domain.)

Solution

12.7 Use a large number of particles to advect the tracer field of Figure?? by distributingthem initially on a regular grid. Look attvdadv2D.m to see how the velocity field andinitial concentration distribution are defined. Which problem do you face when you need tocalculate the concentration at an arbitrary position at a later moment?

Solution

Page 69: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

69

12.8 Implement (12.56) without advection in a periodic domain betweenx = −10L andx = 10L and with diffusion given by

A = A0 tanh2x

L. (12.60)

Start with a uniform distribution of particles in the left half of the domain (x < 0) and noparticles in the other half (x > 0). Simulate the evolution with and without the term∂A/∂xand discuss your findings. TakeL = 1000 km andA0 = 1000 m2/s. (Hint: Periodicity ofthe domain can be ensured by proper repositioning of particles when they cross a boundary.Modulo is an interesting and useful function here.)

Solution

Page 70: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

70 CHAPTER 12.

Page 71: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 13

13.1 Use the dispersion relation of pure internal waves (13.4) toillustrate the superpositionof two waves by an animation in the (x, z) plane of sizeLx, H . Can you see the groupvelocity when using two waves of equal amplitude and the two wavenumber vectors(kx =35/Lx, kz = 10/H) and(kx = 40/Lx, kz = 12/H)?

Solution The dispersion relation for a wave in the(x, z) plane reads

ω2 = N2 k2xk2x + k2z

(13.1)

which in terms of non-dimensional wave numberskx = kxLx andkz = kzH reads

ω2

N2= δ2

kx2

δ2kx2+ kz

2 (13.2)

where the aspect ratioδ = H/Lx is given. Then we simply have to plot the superpositionof two waves in the(x, z) plane since the non-dimensional wavenumbers are fixed and allowto calculate the non-dimensional frequency using the dispersion relation for a given aspectration.

num ex 13 1.m implements this with choices of amplitudes of the two waves and thesuperposition of a background stratification. Keeping the baseline stratification we see essen-tially the propagation of the interface perturbations (Figure13-1)

Then one can deactivate the background and look at the propagation of one wave or thesuperposition of two (Figure13-2). In particular, the interference of the two waves show apropagation downward (along the phase lines), as to be expected from the analysis of thegroup velocity. This can be seen nicely in the animations.

13.2 For the matrices and eigenvalues of problem (13.33), prove that

λmin ≤xTBx

xTCx≤ λmax. (13.52)

71

Page 72: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

72 CHAPTER 13.

Figure 13-1 Vertical section with background stratification

Page 73: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

73

Figure 13-2 Vertical section without background stratification

Page 74: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

74 CHAPTER 13.

To prove these so-called Rayleigh-Ritz inequalities (13.52) for symmetric positive definitematricesB andC:

• assume that all eigenvalues are different,

• demonstrate that(

wi)T

Bwj = δij and(

wi)T

Cwj = δij ,

• prove that all eigenvectorswi, i = 1, .... are linearly independent, and

• write any vectorx as a weighted sum of those independent vectors and use this expres-sion in the Rayleigh-Ritz quotient to prove the Rayleigh-Ritz inequalities.

Adapt then the codeiwave.m to provide estimates of the upper and lower bound using aseries of random vectorsx to calculate the Rayleigh-Ritz estimator(xTBx)/(xTCx) and storethe minima and maxima of the calculated quotient. Seek how the bounds become increasinglyprecise as you choose additional random vectors.

Solution

13.3 By substitution ofω2 = (1 + λ)f2 into (13.32) and redefiningB, show that all eigen-valuesωi satisfyω2

i ≥ f2. Incidentally show that you can recast the problem into a standardeigenvalue problem.

By substitution ofω2 = (1− λ)N2max into (13.32) and redefiningB, show that all eigen-

valuesωi satisfyω2i ≤ N2

max.

Solution

13.4 Adapt iwavemed.m to read temperature and salinity profiles from oceanographicdata bases, such as the Levitus climatology1, and calculate the radius of deformation for theGulf Stream region. To read a climatological atlas, you can use levitus.m and select alocation.

Solution

1See http://www.cdc.noaa.gov/cdc/data.nodc.woa94.html

Page 75: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

75

13.5 Assess numerically the convergence rate for eigenvalues and eigenfunctions in the caseof uniform stratification by adaptingiwave.m .

Solution

13.6 Discretize the eigenvalue problem of the sheared-flow instability (10.9) using the sametechniques as in Section??. What can you say about the positive-definite nature of the ma-trices involved? Try finding the numerical eigenvalues and growth rates of profiles you thinkare probably unstable in Analytical Problem 10-2.

Solution

Page 76: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

76 CHAPTER 13.

Page 77: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 14

14.1 Assuming the turbulent kinetic energy budget is dominated by local production anddissipation, how would you define a staggered grid for a one-dimensional model of a watercolumn?

Solution

14.2 Implement a numerical method that keeps the turbulent kinetic energyk positive fordecaying turbulence in a homogeneousk–ǫ model.

Solution

14.3 Show that for turbulence in statistical equilibrium, stability functions depend only onthe Richardson number.

Solution

14.4 Revisit the estimate of the computing power needed to simulate geophysical fluid dy-namics down to the dissipation range, with microscale in mind and for a typical value ofǫ = 10−3 W/kg.

77

Page 78: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

78 CHAPTER 14.

Solution

14.5 What to you think that the requirement should be on the vertical grid spacing∆zcompared tolm?

Solution

14.6 Implement a 1D model including ak–ǫ closure scheme. If help is needed, look atkepsmodel.m , but do not cheat.

Solution

14.7 Use the program developed in Numerical Exercise 14-6 orkepsmodel.m to simulatethe case of wind induced mixing of Analytical Problem 14-4. In particular, consider thetemporal evolution of the surface velocity in hodograph form (u, v axes), with or withoutCoriolis force. Then repeat the exercise but do not allow thewind to stop. Again, comparethe situations with or without Coriolis force. To do so, trace in both cases the mixed-layerdepth evolution as shown in Figure14-1.

Solution

14.8 Prove that (14.100) is the sufficient condition to ensure that the numerical solutionobtained with (14.98) converges toward the equilibrium valuec∗, remains positive, and nevercrosses the valuec = c∗.

Solution

Page 79: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

79

−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1−120

−100

−80

−60

−40

−20

0

20

Density anomaly

zWithout rotation

With rotation

Figure 14-1 A uniform stratification being erased by a constant surface wind. In the absence of rota-tion, the mixed layer deepens (two profiles are shown in dashed lines). With rotation, the mixed layerstabilizes (two profiles in solid lines), and the pycnoclineis sharper. See Numerical Exercise 14-7.

14.9 Simulate a convection case in the ocean with a uniform initial stratification ofN =0.015 s−1. Then apply a destabilizing heat loss of 200 W/m2 at the surface. Translate theheat flux into density anomaly flux and use the 1D model withoutrotation. Start from rest.Implement a method to detect the mixed-layer depth and traceits evolution over time. Dothe same for the wind-mixing case of Numerical Exercise 14-7. Compare to the theoreticalresults of Section??

Solution

Page 80: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

80 CHAPTER 14.

Page 81: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 15

15.1 By looking intoupwelling.m , guess which governing equations are being discretized.Then use the program to simulate coastal upwelling and see ifthe outcropping condition(15.40) is realistic. Examine the algorithmflooddry.m used to deal with the outcroppingand explore what happens when you deactivate it.

Solution We can first simply run the programupwelling.m to see what happens. Theprogram starts from Figure15-1. If we the push a key to launch the calculation, the lowerand upper line move and at one moment the red crosses disappear (Figure15-2)

The we have a look at the code

t=0;% Time loopfor n=0:ntot

% Equation for depthfor i=1:M

hn(i)=h(i)-dt/dx * (hu(i+1)-hu(i));hn(i)=max(hn(i),hmin);

endh=hn;

% Equation for hufor i=2:M

hun(i)=hu(i)+f * dt * hv(i)-1/2 * gprime * dt/dx * (h(i)ˆ2-h(i-1)ˆ2)+dt * ah/(dx * dx) * (hu(i+1)+hu(i-1)-2 * hu(i));endhun(1)=0;hun(M+1)=0;hu=hun;% Apply correction when outcropping ariveshu=flooddry(hun,h,hmin);

% Equation for hvfor i=2:M

hvn(i)=hv(i)-f * dt * hu(i)+dt * windstress(t)/1024+dt * ah/(dx * dx) * (hv(i+1)+hv(i-1)-2 * hv(i));endhv=hvn;

and with the comments provided in the beginning, it should bequite clear that we aretrying to solve:

∂h

∂t= − ∂

∂x(hu) (15.1)

∂t(hu) = f hv − g′

2

∂h2

∂x+ A ∂2

∂x2(hu) (15.2)

∂t(hv) = − f hu +

τ

ρ0+ A ∂2

∂x2(hv) (15.3)

81

Page 82: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

82 CHAPTER 15.

0 2 4 6 8 10 12

x 104

−100

−80

−60

−40

−20

0

To start press any key

Figure 15-1 Screenshot of starting

0 2 4 6 8 10 12

x 104

−100

−80

−60

−40

−20

0

Time : 6.281e+05

Figure 15-2 Screenshot at the end of the simulation

Page 83: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

83

i.e. the coastal upwelling equations (15.25) slighlty modified. Momentum equations havebeen multiplied byh to yield from (15.25) the conservative form:

∂t(hu) +

∂x(huu) − f hv = − g′ h∂h

∂x(15.4a)

∂t(hv) +

∂x(huv) + f hu =

τ

ρ0(15.4b)

∂h

∂t+

∂x(hu) = 0, (15.4c)

Then we neglected the advection term but added a diffusion term with diffusion coeffi-cientA before we proceeded to the discretisation programmed inupwelling.m . The restdeals with time discretisation (look at how newest values are used when proceeding to thenext equation to yield stable results), plotting and ensuringh remains positive. Also note thatthe windstress is specified in an independant filewindstress.m .

Then we are asked to look atflooddry.m which is quite short piece of code

function [hulimited] = flooddry(hu,h,hmin)

Ms=size(h);M=Ms(2);myhmin=hmin;hulimited=hu;

% Whenever the layer depth is too small, force transport to ze ro if in the% direction that could cause problems (empying an already em pty box)for i=2:M

if h(i-1) < hmin * 3hulimited(i)=min(hu(i),0);

endif h(i) < hmin * 3

hulimited(i)=max(hu(i),0);end

end

As it says, the code tries to avoid fluxeshu which will lead potentially to empty boxes bysome crude tests. Students should try to find a better criterium using∆t and∆x as additionalparameter, knowing that the problem will arise when updating h via volume conservation inthe next time step. When deactivating the routine, at the beginning of the simulation nothingchanges, but the adjusted final position is sensitive to the presence or absence of this limiting,because at one moment the front outcropped. This shows how tapering with the solution nearthe front can have dramatic effects on the final solution.

15.2 Add a discretization of momentum advection toupwelling.m and redo NumericalExercise 15-1. Then diagnose

I ≃ 1

ρ0

event

τ

hdt (15.120)

during the simulation withupwelling.m and compare to the estimate (15.35). (Hint:Remember thatI is calculated for an individual water parcel.)

Page 84: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

84 CHAPTER 15.

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

x 104

0.8

1

1.2

1.4

1.6

1.8

2

Figure 15-3 Upwind advection ofa triangular distribution with fixedgrid (most diffusive solution) andan adaptive grid with or withoutadded Lagrangian-type advection. Thebest solution is obtained with theLagrangian-type advection. See Nu-merical Exercise 15-4.

Solution

15.3 Useadaptive.m and see how the linearly interpolated function using a uniform oradapted grid approximates the original functionfunctiontofollow.m . Quantify theerror by sampling the linear interpolations on a very high resolution grid and calculate therms error between this interpolation and the original function. Show how this error behavesduring the grid-adaptation process.

Solution

15.4 Analyze fileadaptiveupwind.m used to simulate an advection problem with up-wind discretization and optional adaptive grid (Figure15-3). Explain how the grid sizechanges and how grid velocities must be discretized in a consistent way. Verify your analysisby using a constant value forc. Modify the parameters involved in the grid adaptation. Trytoimplement a Lagrangian approach by moving the grid nodes with the physical velocity. Whatproblem appears in a fixed domain?

Solution

Page 85: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

85

15.5 Redo Numerical Exercise 15-4 but define and move the grid nodes at the interface andcalculate concentration-point positions at the center.

Solution

15.6 Prove that the Beam-Warming scheme of Section?? can be recovered using a flux-limiter functionΦ = r. Implement the scheme and apply it to the standard problem ofthetop-hat signal advection. How does the solution compare to the Lax-Wendroff solution ofFigure???

Solution

15.7 Apply the Superbee TVD scheme to the advection of the top-hatsignal and then tothe advection of a sinusoidal signal. What do you observe? Can you explain the behaviorand verify that your explanation is correct by choosing another limiter? Experiment withtvdadv1D.m .

Solution

15.8 Write out the flux-limiter scheme in the 1D case foru ≤ 0 by exploiting symmetries ofthe problem.

Solution

15.9 Implement a leapfrog advection scheme on a non-uniform gridwith scalarc defined atthe center of the cells of variable width. The domain of interest spansx = −10L tox = 10L.For initialization and downstream boundaries, use an Eulerupwind scheme. Use a spatial

Page 86: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

86 CHAPTER 15.

grid spacing of∆x for x < 0 and r∆x for x > 0. Use a constant velocityu = 1 m/s.Simulate a time window of15L/u and show the solution at every time step. Use a maximumvalue ofC = 0.5. Advect a Gaussian distribution of widthL initially located atx = −5L:

c(x, t = 0) = exp[

−(x+ 5L)2/L2]

. (15.121)

Use all combinations of∆x = L/4, L/8, L/16 with r = 1, 1/2, 2, 1/10, 10. In particu-lar, observe what happens when the patch crossesx = 0.

Solution

Page 87: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 16

16.1 Verify numerical conservation (16.72) by adaptingqgmodel.m in a closed two-di-mensional domain of sizeL. Compare leapfrog and explicit Euler time discretizations. Ini-tialize with a streamfunction given by

ψ = ω0L2 sin

(πx

L

)

sin(πy

L

)

. (16.90)

On all four sides,x = 0, x = L, y = 0 andy = L, the boundaries are impermeable, and thestreamfunction is kept zero. Useω0 = 10−5 s−1 andL = 100 km. For simplicity, also usezero vorticity along the perimeter.

Solution

16.2 Start withqgmodelrun.m and generalize the code to allow dynamics on the two-di-mensionalβ–plane. Also add superviscosity (biharmonic diffusion) asshown in Section??.Redo the simulation of Numerical Exercise 16-1 including the beta term. Takeβ0 = 2×10−11

m−1 s−1 andL = 3000 km. Observe the evolution of the streamfunction. (Hint: Keep relativevorticity as the dynamic variable and express the beta effect as a forcing term in the governingequation for relative vorticity, for example within the Jacobian operator.)

Solution

16.3 Simulate the evolution of an eddy on thef–plane. Begin with an eddy centered at theorigin with its streamfunction given by

ψ = −ω0L2 (r + 1) e−r, r =

x2 + y2

L, (16.91)

87

Page 88: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

88 CHAPTER 16.

Figure 16-1 Evolution of a perturbed vorticity patch within a quasi-geostrophic framework.

withL = 100 km andω0 = 10−5 s−1, and then perturb it by multiplyingr used in the initialcalculation ofψ by1+ ǫ cos(2θ), whereθ is the azimuthal angle andǫ a small parameter, forexample∼ 0.03. Perform the calculations in the square domain[−10L, 10L]× [−10L, 10L]with zero values forψ along the perimeter.

Solution

16.4 Redo Numerical Exercise 16-3 with an initial eddy defined by

ω =

−ω0 for 0 < r/L < 1/√2

+ω0 for 1/√2 ≤ r/L < 1

0 for 1 ≤ r/L(16.92)

and verify that you obtain the evolution shown in Figure16-1.

Solution

Page 89: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

89

16.5 Adaptqgmodel.m to simulate the instability of the barotropic flow of Section?? oranalyzeshearedflow.m . Initialize with the basic flow perturbed by an unstable wave.Instead of an infinite domain in they–direction, prescribe zero values for the streamfunctionat y = ±10L. Apply periodic boundary conditions in thex–direction. What boundaryconditions do you use for the potential vorticityq? Which problem related to boundaryconditions do you encounter if you want to use biharmonic diffusion (Section??)? In anycase, take a weak diffusion for the simulations. (Hint: Expect to have time for a cup of coffeeduring the simulation.)

Solution

16.6 Implement a more efficient Poisson-equation solver using a conjugate-gradient ap-proach (see Section??) by using MATLAB routinepcg, and redo Numerical Exercise 16-5.Search the worldwide web for a multigrid version of the Poisson equation solver to furtherreduce calculation times if necessary.

Solution

16.7 Adapt the over-relaxation parameter to decrease the computation time of simulationsin Numerical Exercise 16-5. Then simulate the schematized atmospheric jet stream of An-alytical Problem 10-4 with a long wave-like perturbation. In a second experiment, reducethe intensity of the jet stream by a factor 4. In a third experiment, keep the lower velocitybut disable the beta term. Discuss the stability in the context of the solution to AnalyticalProblem 10-4.

Solution

Page 90: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

90 CHAPTER 16.

16.8 Simulate the evolution of the triangular jet of Analytical Problem 10-5 withL =50 kmandU =1 m/s. (Hint: Perturb the zonal flow by a rather long wave in a sufficiently longdomain).

Solution

Page 91: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 17

17.1 Program (17.43) and plot, as a function of∆U , the wavenumber corresponding to themaximum growth rate and the growth rate itself for differentvalues ofβ0 andR.

Solution

17.2 Usebaroclinic.m to see what happens if instead of boundary condition (17.75),the initial value ofψ is kept on the boundaries.

Solution

17.3 Explore withbaroclinic.m the effect of changing the domain width.

Solution

17.4 Usebaroclinic.m and add theβ term to the discretization. Apply the new programto a wide domain and analyze the impact of the beta effect by placing yourself in situationsallowing to verify that (17.45) corresponds to the stability limit. If necessary, use the programyou constructed for solving Numerical Exercise 17-1.

Solution

91

Page 92: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

92 CHAPTER 17.

17.5 Include the possibility of more general interfacial profiles in baroclinic.m andanalyze a localized baroclinic jet where the interface displacement around mid-depth is

a =f0UR

g′tanh

( y

R

)

, (17.78)

whereR is the internal deformation radius,U the jet velocity andy the cross-channel coor-dinate, centered in the middle of the channel.

Solution

17.6 Include diagnostics of energy evolution and transfers of energy intobaroclinic.m .Check to which extent the numerical discretization conserves energy. Verify if another timediscretization can improve the simulation.

Solution

Page 93: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 18

18.1 Useqgspectral.m to experiment with different eddy fields. Then include the betaeffect and higher-order dissipation using sixth-order derivatives.

Solution

18.2 Include diagnostics on energy, enstrophy and wavelength into qgspectral.m andsimulate with different eddy viscosity values. Also include diagnostics on

ke =

k |kΨk|2 dk∫

|kΨk|2 dk(18.44)

ko =

k |Qk|2 dk∫

|Qk|2 dk, (18.45)

where integrals are performed over all wavenumbersk =√

k2x + k2y. Look at the time

evolution of these quantities and provide an interpretation.

Solution

18.3 Generalizeqgspectral.m to a two-layer system with equations given in (17.31). Inparticular, mind the vertical coupling in (17.32) and solvethe coupled problem in spectralspace exactly. Vary the parameterR to explore the effect of vertical stratification.

Solution

93

Page 94: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

94 CHAPTER 18.

Page 95: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 19

19.1 What is the spatial resolution (in km) along the equator for aT256 spectral model?How many grid points must the underlying Gaussian grid have in order to avoid aliasing inthe advection terms?

Solution

19.2 Usespherical.m to consider other basis functionsYm,n than those of figure??.

Solution

19.3 Estimate the numerical cost of the forward and inverse transform associated with spec-tral harmonics.

Solution

19.4 In addition to the problem of decreasing grid spacing near the poles, which other prob-lem can you identify at the poles for models that do not work with a spectral decomposition?(Hint: Think about boundary conditions for an AGCM, for longitude first and then for lati-tude.)

95

Page 96: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

96 CHAPTER 19.

Solution

19.5 Exploiting properties of Legendre polynomials, given for example in Abramowitz andStegun (1972), find the spectral coefficients of spatial derivatives, knowing the spectral coef-ficients of the function to be differentiated.

Solution

Page 97: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 20

20.1 Take the density data used iniwavemed.m and calculate the geostrophic velocities.Work in z coordinates withz levels corresponding to the data. First assume a level of nomotion at 500 m and calculate currents at the surface and 2000m down. Then repeat withlevel of no motion at 1500 m.

Solution

20.2 Experiment withbolus.m to see the flattening of isopycnals in a vertical section withflat bottom. Then implement a sigma-coordinate change in a vertical section with flat surfaceand topography given by

h(x) = h0 + αx, (20.61)

where the domain extends fromx = −L/2 to x = L/2 and whereαL = h0. Start fromthe same physical density distribution as in the flat-bottomcase. (Hint: Express the bolusadvection term as a Jacobian in the vertical plane. Then use the rules of change of variablesto express this Jacobian in the new coordinate system. Do notforget to calculate the slopesusing the rules of changes of variables.)

Solution

20.3 Obtain a density section from somewhere and calculate bolusvelocity usingbolus.m .Which problems do you expect near boundaries? (Hint: You might considerκ as a calibrationparameter that varies in space.)

97

Page 98: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

98 CHAPTER 20.

Solution

20.4 Usepgerror.m to explore the pressure-gradient error for a fixed density anomalyprofile depending only onz according to

ρ = ∆ρ tanh

(

z +D

W

)

, (20.62)

in whichD andW control the position and thickness of the pycnocline. Bottom topographyis given by

h(x) = H0 + ∆H tanh( x

L

)

, (20.63)

whereL and∆H control the steepness of the slope. Calculate the error and associatedgeostrophic velocity forf = 10−4 s−1. Vary the number of vertical grid points, horizontalgrid points, the position of the pycnocline, its depth and strength. What happens if youincrease only the number of vertical grid points? Implementthe discretization of anotherpressure gradient expression of (20.55) inbcpgr.m and compare.

Solution

20.5 Bottom topography is generally smoothed before it is used ina model, by the repeatedapplication of a Laplacian-type diffusion. In view of the hydrostatic consistency constraint,which adapted filter technique would you advocate? (Hint: Remember that a Laplacian filterapplied to a functionF decreases the norm of the gradient

∫ ∫ [

(∂F/∂x)2 + (∂F/∂y)2]

dx dyover the domain.)

Solution

Page 99: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 21

21.1 Design a numerical solver for the delayed oscillator equation (21.30). Find the solu-tion with a−1 = 50 days,δ = 400 days andb−1 = 90 days for different initial conditions.Then change toa−1 = 100 days andb−1 = 180 days.

Solution

21.2 Design a numerical version of the linear reduced-gravity model (21.6), to which aspatially-varying zonal wind stress is added, of the form

τ = τ0e−(x2+y2)/L2

. (21.31)

Use a finite-difference approach on the Arakawa C-grid and time stepping of your choice.Start with a situation at rest and then apply the wind stress for 30 days. For the wind-stressamplitude and length scale, takeτ0 = 0.1 N/m2 (directed eastward) andL = 300 km. Thereduced-gravity model’s parameters are∆ρ/ρ0 = 0.002 with a thermocline depthH = 100m. For a first simulation, use a closed domain with boundariesatx = −3000 km,x = 10000km andy = ±2000 km. Simulate the evolution for 600 days.

Solution

21.3 For the conditions set in Numerical Exercise 21-2 with closed southern and northernboundaries, the perturbation eventually propagates alongthese boundaries. Which physicalprocess is responsible for this? Modify the southern and northern boundary conditions byopening the domain and applyv = ±√g′H h there. Choose a physically reasonable sign foreach boundary by considering a physical interpretation of such boundary conditions.

99

Page 100: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

100 CHAPTER 21.

Solution

21.4 Change the topology of the domain in Numerical Exercise 21-3by adding land points inthe southwestern (lower left) and northeastern (upper right) corners to represent continentson each side of the Pacific Ocean and redo the simulations. Canyou identify the modes thatare now present compared to the symmetric case?

Solution

21.5 Search for a spatial discretization of the Coriolis term on the Arakawa C-grid that doesnot create mechanical work in the sense that, after multiplying the evolution equation forui−1/2,j by itself and adding a similar product of thevi,j−1/2 equation by itself, the Coriolisterms cancel out. (Hint: Analyze which products ofu andv appear, similar to the analysisof the Arakawa Jacobian performed in Section?? and find how to average by taking intoaccount the variation ofy.)

Solution

21.6 Using the Sea-Surface Temperature (SST) anomalies and Southern Oscillation Index(SOI) values from 1991 to 2005 included insoi.m , perform a linear regression over datawindows and look how the extrapolation of these regressionsis able or unable to predictthe SST or SOI at later times. First use a data window of 4 months and try to extrapolatefor the next month. Plot the prediction error over time when applying the method over allpossible data windows. To decide whether the prediction is useful, compare to the predictionerror corresponding to simple persistence (constant anomaly). Then try to change your datawindow and lead time to improve the prediction. Instead of a linear regression you mightalso try higher-order polynomial fits.

Solution

Page 101: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

101

21.7 Do the same as in Numerical Exercise 21-6, but try to calibrate the delayed oscillatormodel (21.30) for the temperature anomaly. Use the calibrated model for the extrapolation.If necessary, use data windows of several years.

Solution

Page 102: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

102 CHAPTER 21.

Page 103: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Chapter 22

22.1 Implement a nudging method and solve numerically Analytical Problem 22-1. Whenyou decreaseτ , what specific action do you need to take during time stepping? Investigatewhat happens when you add noise to the “observations”u0 andv0 and decrease the samplingrate of the “pseudo-data”.

Solution

22.2 Work with an optimal interpolation scheme on a one-dimensional gravity-wave prob-lem already discretized inoigrav.m with 61 interior calculation points in a 61 km longand 100m deep domain. Perfom a twin experiment with a reference simulation starting fromrest with a sinusoidal elevation of 40 cm amplitude and wavelength equal to the domain size.From this simulation you can extract pseudo data in order to compare at least two assimila-tion strategies:

• A sampling point for surface elevationη located near the left boundary, at one third ofthe total domain length, sampled and assimilated every 10 seconds.

• An observation of the surface elevation at all grid points sampled and assimilated everyten minutes.

In both cases, add random noise to your “data” with a standarddeviation representative ofaltimetric precision (2 cm). Assume the noise is uncorrelated in time and space. For theassimilation experiment, start from initial conditions atrest and zero sea-level height.

Prescribe the forecast covariance as a function of distancebetween pointsxi and xj ,proportional to the following correlation function

c(xi, xj) = exp[

−(xi − xj)2/R2]

(22.65)

whereR is a correlation length. The covariance is obtained by multiplying this correlationfunction by the estimated variance of the forecast.

103

Page 104: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

104 CHAPTER 22.

The observational error covariance can be specified according to the perturbation added.Look at the evolution of the simulations and quantify the error individually onη and velocity.

Which variance of the background field would you advocate in view of the initial condi-tions? Change the value and assess the effect on the assimilation behavior. Then change thevalue of correlation length and finally try other combinations of space-time coverage.

(Hint: For ease of programming, the two simulations (reference runand assimilation run)may be advanced simultaneously, and you can diagnose the error as you go, always beforeassimilating however.)

Solution

22.3 Experiment withkalmanupwadv.m by changing the error specifications, samplingrate and sampling locations.

Solution

22.4 Develop an adjoint method for Numerical Exercise 22-3 and optimize the initial condi-tion using the same “observations” as for the Kalman filter ofNumerical Exercise 22-3. Usethe exact advection velocity withC = U∆t/∆x = 0.2 and thenC = 1 in order to witness theeffect of model errors, remembering thatC = 1 corresponds to perfect dynamics because theupwind scheme is exact in this case. What is the effect of reducing the number of observationsand disregarding the background initial conditions? (Hint: Think about underdetermined andoverdetermined problems.)

Solution

22.5 Estimate the computer memory needed to storeP for today’s weather-forecast systems.

Solution

Page 105: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

105

22.6 Implement an ensemble Kalman filter for the Lorenz equations(22.2) and the assim-ilation of observations ofx(t) only. Investigate the effect of the observation frequency byperforming assimilation steps at 0.001, 0.01, 0.1 and 1 timeintervals.

Solution

22.7 Work to improve the optimal interpolation of Numerical Exercise 22-2 by calculatingand using covariance functions estimated from an ensemble run in which you perturb theinitial condition.

Solution

22.8 Improve the assimilation scheme of Numerical Exercise 22-2by implementing the fullKalman filter with an updated covariance matrix. For ease of programming, you might con-sider constructing explicitly the transition matrixM.

Solution

Page 106: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

106 CHAPTER 22.

Page 107: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Appendix A

22.9 Plot the velocity and vorticity fields of Analytical ProblemA-2.

Solution

107

Page 108: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

108 APPENDIX A

Page 109: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Appendix B

22.10 Using animated graphics, display a time sequence (t = 0 to 10π by steps ofπ/4) ofthe double wave

a (x, t) = A1 cos(k1x − ω1t) + A2 cos(k2x − ω2t)

withA1 = A2 = 1, k1 = 1.9,k2 = 2.1,ω1 = 2.1,ω2 = 1.9, and forx ranging from 0 to 100. Asuggested step inx is 0.25. Notice how the short waves [of wavelength =4π/(k1+ k2) = π]travel toward increasingx at the speedc = (ω1 + ω2)/(k1 + k2) = +1, while the waveenvelope [of wavelength =2π/(k2 − k1) = 10π] travels in the opposite direction at speedcg = (ω1 − ω2)/(k1 − k2) = −1. This unequivocally demonstrates the nonintuitive fact thatthe energy propagation may well propagate in the direction opposite to the advancing crestsand troughs. In other words, it is not impossible for energy to be transported up-wave.Variations of this exercise can include uneven amplitudes (e.g.,A1 = 1 andA2 = 0.5) andmodified values for the wavenumbers and frequencies.

Solution

22.11 Using animated graphics, use the same function as in exercise B-1 withk1 = 0.35,k2= 0.5,ω1 = 0.5, andω2 = 0.35 the other values unchanged. Show the evolution ofa and thenof a2/2. Can you explain the apparently shorter waves?

Solution

22.12 Given a dispersion relation

ω =k

(k2 + 1)

109

Page 110: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

110 APPENDIX B

analyze now the signal composed of two waves

a (x, t) = A1 cos(k1x − ω(k1)t) + A2 cos(k2x − ω(k2)t),

whereω is calculated using the dispersion relation. As before, show the evolution forA1 =A2 = 1 in the following situations

• k1 = k2 = 0.5,

• k1 = k2 = 2

• k1 = 1.95,k2 = 2.05

• k1 = 0.45,k2 = 0.55

Can you explain the behaviour? (Hint: Plot the dispersion relation.)Redo exercise B-1 withk1 = 1, A1 = 1, A2 = 0 andω1 = 1. Then change the step inx to

π/4 andπ/2. Finally when using a step of4π/3, what do you observe?

Solution

Page 111: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

Appendix C

22.13 Compare the behavior of the second-order Adams-Bashforthsmethod and leapfrog-trapezoidal method in the numerical simulation of an inertial oscillation.

Solution

22.14 Discretize the functionu(x, y) = sin(2πx/L) cos(2πy/L) on a regular grid in theplane(x, y). Calculate the numerical Jacobian between

• u andu,

• u andu2,

• u andu3,

and interpret your results.

Solution

22.15 Perform an FFT onf(x) = sin(2πx/L) betweenx = 0 andx = L, by sampling with10, 20 or 40 points. Using the spectral coefficients obtainedfrom the FFT, plot the Fourierseries using very fine resolution inx (say, 200 points) and verify that you recover the initialfunction. Then repeat with the functionf(x) = x. What do you observe?

Solution

111

Page 112: Introduction to Geophysical Fluid Dynamics - GHERmodb.oce.ulg.ac.be/wiki/upload/Solutions.pdf · Introduction to Geophysical Fluid Dynamics Physical and Numerical Aspects Benoit Cushman-Roisin

112 APPENDIX C

22.16 Redo Numerical Exercise C-3 using the padding technique instead of the brute-forceevaluation to plot the Fourier series expansion.

Solution