Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf ·...

Post on 10-Mar-2020

11 views 0 download

Transcript of Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf ·...

Discretization in space and time:Finite differences

To find a numerical solution to the fundamental equations on a digital

computer, they must be discretized in space and time.

[Figure 3-30 from Ruddiman (2001)]

Discretization in space for a three-dimensional ocean model

Computer modeling

• Volume occupied by water divided into “boxes” by a grid

• Rate of change of flow through sides of each box calculated using fundamental equations (or “equations of motion” next lecture)

• We take the transport of a conservative property (such as salt) along a one-dimensional, narrow channel as a prototype problem for discretization.

• For simplicity, we use a Cartesian ccordinate system throughout, with primary directions x, y, z.

Suggested reading• Washington, Warren M. and Parkinson, Claire L.: An

Introduction to Three-Dimensional Climate Modeling. 2nd edition. University Science Books, Sausalito, California, 2005.– Chapter 4 (e.g. Sections on “Finite Differences” and “Finite

Differencing in two dimensions”).

• In German: Stocker, Thomas (2008), Einführung in die Klimamodellierung (lecture notes, 146 pp), http://www.climate.unibe.ch/~stocker/papers/skript08EKM.pdf.

– Chapter 3, e.g. Sections 3.1, 3.4, 3.5, 3.8.

In the following, I mainly adhere to the notation of the lecture notes by T. Stocker.

Transport processes

• Advection– associated with fluid flow that transports matter and

energy

• Diffusion– stochastic process

• Convection– caused by unstable stratification (heavy fluid overlies

light fluid)

• Transport processes are crucial in the climate system– Heat transport in the atmosphere

– Salt transport and spreading of tracers in the ocean

Advection

• Fluid (gas, air, water) flows with velocity u(x,t) through control area A(x)

• Transported quantitiy (mass, energy, momentum, “partial mass” or tracer) is given as concentration C(x,t), i.e . refers to a unit volume

Advection

One-dimensional flow along x axis (Figure 3.1 from Stocker 2004)

• During time interval ∆t, let the flow cover a volume .A x⋅ ∆

• Then the total quantity transported is:

.A x C⋅ ∆ ⋅

Note: The symbol ∆ (as used to denote the time step ∆t or the grid step ∆x) indicates a small but finite (non-zero) quantity.

• The flow of the quantity, relative to the area A and time interval ∆t, is called a flux density:

.A x C xF C u CA t t⋅ ∆ ⋅ ∆= = ⋅ = ⋅

⋅ ∆ ∆

• In three dimensions, the advective flux density of a scalar quantity C in a flow with velocity u(x,t) is

.C=F u

• The flux density is a vector in the direction of the flow.

Advective flux densityFormulaQuantity

x-component of momentum

Salt flux

Heat flux

Mass

General scalar C=F u

ρ=F u

cTρ=F u

S=F u

xu=F u

“Partial mass“

Spatially varying flux density in one dimension (Figure 3.3 from Stocker 2005).

• Consider a concentration C in a fixed control volume

Advection equation

• Conservation of mass or amount is described by:

( ) ( ) ( )C V F x A F x x At

∂ ∆ = ⋅ − + ∆ ⋅∂

inflow outflow

Devide by ∆V = A∆x :

( ) ( )C F x F x xt x

∂ − + ∆=∂ ∆

• Partial derivative - similar to ordinary derivative, but for function of more than one variable, with all variables kept fixed except for one:

Ct

∂∂

partial derivative of the concentration C(x,t) with respect to time t, at a fixed point in space x.

Cx

∂∂

partial derivative of the concentration C(x,t) with respect to location x (i.e., concentration gradient), at a fixed instant in time x.

Change order of fluxes:( ) ( ) .C F x x F x

t x∂ + ∆ −= −∂ ∆

Take limit 0 :x∆ →

.C Ft x

∂ ∂= −∂ ∂

With finite-volume method, this minus sign appears “naturally”.

Flux form of one-dimensional advection equation.

Divergence of flux in x-direction

• For discretizing the advection-diffusion-equation, I generally prefer to start from the flux form, which in combination with the finite-volume method ensures the conservation of any scalar variable C in a natural manner.

• Temporal discretization:, 0,1, 2,t n t n= ⋅ ∆ = K

Numerical solution of the advection equation

• Spatial discretization:, 0,1, 2,x i x i= ⋅ ∆ = K

• Solution at space-time grid points:

,( , ) ( , ) i nC x t C i x n t C= ⋅ ∆ ⋅ ∆ =

( )1 tτ − ⋅ ∆

• In most climate models, only two or three time levels are retained to save computer memory:

( )1 tτ + ⋅ ∆presentfuture

tτ ⋅ ∆– two time levels:

( )1 tτ + ⋅ ∆

present

future

tτ ⋅ ∆past

( ), 1n τ τ= +

( )1, , 1n τ τ τ= − +

– three time levels:

• To solve the one-dimensional advection equation numerically, we need to replace the temporal and spatial derivatives by finite-difference representations.

, 1 , .i iC CCt t

τ τ+ −∂ →∂ ∆

, , 1 .i iC CCt t

τ τ −−∂ →∂ ∆

, 1 , 1 .2

i iC CCt t

τ τ+ −−∂ →∂ ∆

• Approximate (partial) derivative with respect to time t by ratio of finite differences:

Euler forward or Forward in Time (FT)

Euler backward or Backward in Time (CT)

Centered in Time (CT)

Discretization in time

, 1 , .i iFC C txτ τ

τ+

∂= − ∆∂

• Insert into one-dimensional advection equation and solve for future time level, e.g.:

Euler forward or Forward in Time (FT)

, 1 , 1 2 .i iFC C txτ τ

τ+ −

∂= − ∆∂

Centered in Time (CT)

, 1, .i iF FFx x

τ τ

τ

−−∂ →∂ ∆

Discretization in space

Outflow – inflow at the present time level τ.

• Approximate (partial) derivative with respect to location x by first recovering the flux form:

• For example, the “centered-in-time” scheme becomes:

, 1,, 1 , 1 2 .i i

i i

F FC C t

xτ τ

τ τ−

+ −

−= − ∆

,,

1,

, if 0 ,, if 0 .

i i ii

i i i

u C uF

u C uτ

ττ+

>= − <

, 1,, .

2i i

i i

C CF u τ τ

τ++

=

Upstream or upwind(“Backward in Space”, BS)

Centered in Space (CS)

Where:

Or:

• Then express fluxes Fi,τ in terms of the concentrations Ci,τ and the flow velocity ui:

× × ×C1 C2 C3

x1 x2 x3

• Consider the concentration C2,τ in a grid cell centered at the grid point with x-coordinate x2, and a constant flow velocity u1=u2=u that is directed to the right:

u1 u2

To estimate the incoming flux F1,τ ,• the “upstream” or “upwind“ scheme uses the

concentration C1,τ to the left, while • the “centered-in-space” scheme uses the average of the

concentrations C1,τ and C2,τ .

x direction

CTCS (centered-in-time, centered-in-space) or “leap-frog” scheme on space-time grid. The information at two previous time levels is used to predict the solution at the future time level (Figure 3.5 from Stocker 2004).

(τ-1)·∆tτ·∆t

(τ-1)·∆t

i·∆x

Stability criterion• Courant-Friedrich-Levy criterion for stable

solution with centered differences :

xtu

∆∆ ≤“No transport faster than one grid cell per timestep”

Large current velocities (jet stream in the atmosphere, western boundary currents in the ocean) require small time steps.

1u tx

⋅ ∆ ≤∆

or

How fast is ocean transport?

• Western boundary currents transport warm and saline water from tropics to middle latitudes– Examples: Kuroshio, Gulf Stream, Brazil Current,

Agulhas Current– Strongest current velocities near 2 m s-1

• Deep western boundary currents flow from north to south at a depth of 2-3 km.– Maximum flow velocity in its core (2.5 km depth) 20

cm s-1

Finite differences: advantages

• Positive-definite schemes possible

• Adaptable to complex geometry (e.g. coastlines, bottom topography)

Finite differences: disadvantages

• Convergence of meridians requires small time step

Other methods

• Finite elements (mostly used in engineering applications)

• Spectral method (used in many atmospheric general circulation models)

Exercise: one-dimensional advection

• Make a folder somewhere on your computer, e.g. advect_1d

• Download zip-file advect_1d.zip from geo server (course web site) into this folder

Sample problem• Assume that a tracer (e.g. salt, concentration C

measured in g kg-1) is released suddenly into a narrow channel, in which water is flowing at a constant speed of u = 1 m s-1.

Initial condition: C = 10 for -1 m ≤ x ≤ 1 m, C = 0 otherwise

• Ignore any diffusion, sources or sinks.• Take a domain -30 m ≤ x ≤ 30 m, a grid size ∆x = 0.2 m

and a time step ∆t = 0.1 s. • What is the time evolution of the concentration C along

the narrow channel?See Section 3.6 by Stocker (2005)

• You are given two MATLAB programs, in which you can fill in additional code, if needed.– First study the parameter and variables

declarations sections to get an idea of the data structure used.

• From variable declarations section: – i: index for “tracer” grid points in x-direction

– τ: index that denotes present time level

– τ+1: index that denotes future time level

• From parameter declarations section: – imt: maximum number of tracer grid points in x-

direction

– ittmax: maximum number of time steps to take

• Note that in the MATLAB progam, the “tracer” concentration Ci,τ is given the variable name t(i,tau). – In our case, we consider the oceanic tracer

salinity, but it can be temperature, dissolved oxygen, dissolved inorganic carbon, phosphate, etc.

• In the variable declarations section, the tracer concentration is defined as a two-dimensional array t(i,tau), where the first index runs from 1 to imt and the second index runs from 0 (or -1 in the case of the centered-in-time-scheme) to 1.