2-Numerical Methods for the Advection Equation

∂q ∂q + a =0 ∂t ∂x The Advection Equation: Theory

‰ 1st order partial (PDE) in (x,t): ∂q(x, t) ∂q(x, t) + a(x, t) =0 ∂t ∂x ‰ Hyperbolic PDE: information propagates across the domain at finite speed Æ method of characteristics ‰ Characteristic are the solutions of the equation dx = a(x, t) dt ‰ So that, along each characteristic, the solution satisfies ∂q dx ∂q dq = + =0 dt ∂t dt ∂x The Advection Equation: Theory ∂q dx ∂q dx dq = + =0, with = a dt ∂t dt ∂x dt

‰ The solution is constant along the characteristic curves. The solution at the Physical domain of dependence point (x,t) is found by tracing the characteristic back to t q(x,t) some inital point (x,0). ∆t ‰ This defines the physical domain of dependence q(x-at,0) a∆t x The Advection Equation: Theory

‰ If a is constant: characteristics are straight parallel lines and the solution to the PDE is a uniform translation of the initial profile: q(x, t)=φ(x − at) where φ ( x )= q ( x, 0) is the initial condition Numerical Methods for the Linear Advection Equation ∂q ∂q + a =0 ∂t ∂x ‰ 2 popular methods for performing :

¾ Finite Differences ¾ Finite Volume

‰ For some problems, the resulting look identical, but they are distinct approaches. ‰ We begin using finite-difference as it will allow us to quickly learn some important ideas Linear Advection Equation:

‰ A finite-difference method stores the solution at specific points in space and time.

‰ Associated with each grid point is a function value,

qi = q(x i )

‰ We replace the in out PDEs with differences between neighboring points. Linear Advection Equation: Finite Volumes

‰ In a finite volume discretization, the unknown is the average value of the function: 1 x i+1/2 hqi i = q(x)dx ∆x x i 1/2 Z − where x i 1 / 2 is the position of the left edge zone i −

‰ Solving out conservation laws involves computing fluxes through the boundaries of these control volumes. Linear Advection Equation:

‰ We start with the linear advection equation ∂q(x, t) ∂q(x, t) + a =0 ∂t ∂x

‰ with initial conditions (i.c.) q(x, 0) = q 0 (x)

q(0,t)=q l (t) ‰ and boundary conditions (b.c.) (t ) ⎧ q(L, t)=qr ⎨ ‰ Actually, only one b.c. is needed since⎩ this is a 1st order equation. Which boundary depends on the sign of a. Linear Advection Equation:

‰ We use a finite difference mesh:

‰ We discretize the function q(x,t) by storing its value at each point in the finite-difference grid n n q i = q(x i ,t ) ‰ Subscript “i” Æ grid location ‰ Superscript “n” Æ time level ‰ In addition to discretizing in space, we introduce time discretization. Thus ∆t n = t n+1 − t n Linear Advection Equation:

‰ We need to approximate the derivatives in our PDE ∂q(x, t) ∂q(x, t) + a =0 ∂t ∂x ∂q(x, t) q n+1 − q n ‰ In time, we use fwd ≈ i i ∂t ∆t since we want to use information from the previous time level ‰ In space, we use centered derivative, since it is more accurate: q n − q n ∂q(x, t) ≈ i+1 i 1 ∂x 2∆x − Linear Advection Equation:

q n+1 − q n q n − q n ‰ Putting all together: i i + a i+1 i 1 =0 ∆t 2∆x − µ ¶ n+1 ‰ and solving with respect to q i : C q n+1 = q n − q n − q n i i 2 i+1 i 1 ∆t − where C = a is called the¡ Courant number or the ∆x ¢ Courant-Friedrichs-Lewy (CFL) number. ‰ We call this method FTCS for forward in time, center in space. ‰ The value at the new time level depends only on quantities at the old time step Æ explicit method Linear Advection Equation:

‰ At t = 0, we prescribe a square pulse:

‰ and prescribe periodic b.c. Linear Advection Equation:

‰ After one period, the solution looks like:

‰ Oops!! Something isn’t right… WHY ?? Linear Advection Equation: stability analysis

‰ Let’s perform an analysis of FTCS by expressing the solution as a Fourier series. Since the equation is linear, we only need to examine the behavior of a single mode. Consider a trial solution of the form: n n Iiθ 1/2 q i = A e ,I =(−1) , θ = k∆x ‰ This is a spatial Fourier expansion. Plugging in the difference formula:

n+1 n C n n n+1 n C n Iθ Iθ qi = qi − qi+1 − qi 1 → A = A − A e − q− 2 − 2 ¡ ¢ ¡ ¢ Linear Advection Equation: stability analysis n+1 ‰ Defining the amplification factor A one obtains A n A n+1 C =1− e Iθ − e Iθ A n 2 − =1− IC sin θ n+1 ‰ A method is well-behaved¡ or stable¢ if A A n ≤ 1 n+1 ¯ ¯ A ¯ 2 2¯ ‰ But for FTCS one gets n =1+C¯ sin ¯ θ ≥ 1 A ¯ ¯ ¯ ¯ ¯ ¯ ‰ Indipendently of the CFL¯ number¯ all Fourier modes increase in magnitude as time advances.¯ ¯

‰ This method is unconditional unstable!!. Linear Advection Equation:

‰ Let’s try a different approach. Consider the backward derivative: q n − q n ∂q(x, t) ≈ i i 1 ∂x ∆x −

‰ Let’s apply the von Neumann stability analysis on the resulting discretized equation:

q n+1 − q n q n − q n i i + a i i 1 =0 with q n = A n e Iiθ ∆t ∆x − i µ ¶ ‰ Solving for the amplification factor gives A n+1 =1− C + C cos θ − I sin θ A n Linear Advection Equation:

n+1 ‰ Taking the norm, A A n =1− 2C(1 − C)(1 − cos θ) ¯ ¯ n+1 ¯ ¯ A ‰ Recall that for stability¯ one ¯needs A n ≤ 1 ¯ ¯ ¯ ¯ ¯ ¯ ‰ But so the stability¯ condition¯ is met 1 − cos θ ≥ 0 ¯ ¯ when 2C(1 − C) ≥ 0 ∆t ‰ Recalling the definition C = a , one has for a > 0 ∆x ∆t 0 ≤ a ≤ 1 ∆x Condition for stability Linear Advection Equation:

‰ Since the advection speed a is a parameter of the equation, Δx is fixed from the grid, this is a constraint on the time step: ∆x ∆t ≤ a

‰ Δt cannot be arbitrarily large.

‰ In the case of nonlinear equations, the speed can vary in the domain and the maximum of a should be considered. Linear Advection Equation:

‰ Repeating the argument for the fwd derivative,

q n+1 − q n q n − q n i i + a i+1 i =0 with q n = A n e Iiθ ∆t ∆x i µ ¶ ‰ Gives

A n+1 A n =1+2C(1 − C)(1 − cos θ) ¯ ¯ ¯ ¯ ¯ ¯ ‰ If a ¯> 0, the¯ method will always be unstable ‰ However, if a is negative, then this method is stable and the previous is unstable. Linear Advection Equation: What Have We Learned ?

‰ The stable method is the one with the difference that makes use of the grid point where information is coming from.

‰ This type of discretization goes under the name “upwind”:

n+1 n a∆t n n ¾ For a > 0 we want q = q − q − q i i ∆x i i 1 a∆t − q n+1 = q n − ¡q n − q n ¾ The a < 0 we want i i ∆x i+1 i ¢ ¡ ¢ ‰ This is the first-order Godunov Method. Linear Advection Equation:

‰ After one period, the solution looks like:

‰ Much better now… ‰ But we still see some smearing… Equivalent Advection/Diffusion Equation ‰ A discretized P.D.E gives the exact solution to an equivalent equation with a diffusion term: ∂q ∂q + a =0,a>0 ‰ Consider ∂t ∂x q n+1 − q n q n − q n ‰ discretize w/ upwind i i + a i i 1 =0 ∆t ∆x −

n+1 n ‰ do Taylor expansion on q i and q i 1 − ‰ The solution to the discretized equation is also the solution of ∂q ∂q a∆x ∆t ∂ 2 q + a = 1 − a + H.O.T. ∂t ∂x 2 ∆x ∂x 2 µ ¶ Linear Advection Equation: Linear Advection Equation: Conservative Form

‰ Godunov method can be cast in conservative form, i.e. ∆t n+1 n F n n q i = q i − i+1/2 − F i 1/2 ∆x − by defining the “flux” function³ ´ a |a| F n = q n + q n q n − q n i+1/2 2 i+1 i − 2 i+1 i ¡ ¢ ¡ a∆t ¢ n+1 n q n n ‰ In fact for a > 0, one has q i = q i − i − q i 1 ∆x − a∆t ¡ ‰ and for a < 0 q n+1 = q n − q n − q n¢ i i ∆x i+1 i ¡ ¢ C Implementation

‰ Look Æ advection.c