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

40
Discretization in space and time: Finite differences

Upload: others

Post on 10-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

Discretization in space and time:Finite differences

Page 2: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

computer, they must be discretized in space and time.

Page 3: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

[Figure 3-30 from Ruddiman (2001)]

Discretization in space for a three-dimensional ocean model

Page 4: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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)

Page 5: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 6: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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.

Page 7: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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)

Page 8: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

– Salt transport and spreading of tracers in the ocean

Page 9: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

Page 10: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

Advection

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

Page 11: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 12: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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⋅ ∆ ⋅ ∆= = ⋅ = ⋅

⋅ ∆ ∆

Page 13: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 14: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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“

Page 15: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

• Consider a concentration C in a fixed control volume

Advection equation

Page 16: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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

∂ − + ∆=∂ ∆

Page 17: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 18: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

Page 19: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 20: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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= ⋅ ∆ ⋅ ∆ =

Page 21: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

( )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:

Page 22: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

Page 23: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

, 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

Page 24: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

, 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)

Page 25: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

, 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τ τ

τ τ−

+ −

−= − ∆

Page 26: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

,,

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:

Page 27: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

× × ×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

Page 28: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

Page 29: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

Page 30: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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

Page 31: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

Finite differences: advantages

• Positive-definite schemes possible

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

Page 32: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

Finite differences: disadvantages

• Convergence of meridians requires small time step

Page 33: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

Other methods

• Finite elements (mostly used in engineering applications)

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

Page 34: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

Exercise: one-dimensional advection

Page 35: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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

Page 36: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

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)

Page 37: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 38: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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

Page 39: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.

Page 40: Discretization in space and time: Finite differencesapau/ecolmas_modeling2/discretization.pdf · Discretization in space for a three-dimensional ocean model. Computer modeling •

• 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.