Lecture 17: Initial value problems Let s start with initial value problems, and consider numerical solution to the simplest PDE we can think of u/ t + c u/ x = 0 (with u a scalar) for which the solution is a wave travelling in the +x direction, u = f(x ct) (The PDE satisfied for any function f) 380
Initial value problems Create a grid in space and time, where subscripted index j labels space and superscripted index n labels time Our grid then has x j = jδx and t n = nδt Given u n j, (i.e. the spatial dependence of U at the nth time step), we wish to step forward in time and determine u j (NB n and are superscripts, not powers) 381
Finite difference equations As usual, we use finite difference equations to represent derivatives Simplest choice for the time derivative: forward Euler differencing ( u/ t) j,n = (u j u jn ) / Δt allows us to compute u j in terms of only quantities known at timestep n. 382
Finite difference equations Simple choice for the spatial derivative: ( u/ x) j,n = (u j+1n u j 1n ) / 2Δx Finite difference equation becomes (u j u jn ) / Δt + (c/2δx) (u j un 1 j ) = 0 u j = u jn (cδt /2Δx) (u j+1n u j 1n ) 383
Forward Time Center Space (FTCS) This simplest possible scheme is called Forward Time Center Space (FTCS) The error is of order (Δt) 2 (Δx) 3 second-order accurate in space, because we take the difference between positions on either side to determine ( u/ x) j,n first order accurate in time, because we approximate the derivative ( u/ t) j,n by its mean value over the range n to. 384
Forward Time Center Space (FTCS) This simple scheme is explicit (u j can be written explicitly in terms of quantities already calculated) It is also a single-level scheme (in that it only involves values at time level n) Graphical representation: n,t for / t for / x already known new point j,x 385
Stability of PDEs Stability is always a key issue in PDEs (more so than for ODEs) Q: under what circumstances is the FTCS scheme stable? Address this with the von Neumann stability analysis 386
von Neumann stability analysis Suppose we start with a sine wave of wavelength 2π/k: u jn = ξ n e ikjδx At the next step, the FTCS scheme yields u j = u jn (cδt /2Δx) (u j+1n u j 1n ) = u jn (1 (cδt /2Δx) [e ikδx e ikδx ]) = ξ n (1 i (cδt /Δx) sin(kδx) ) 387
von Neumann stability analysis So at step, our sine wave has amplitude ξ =(1 i (cδt /Δx) sin(kδx)) ξ n Define R ξ /ξ n = {1+[cΔt sin(kδx)/δx] 2 } > 1 The magnitude is therefore growing exponentially for all k (i.e. for all Fourier components of u jn ) unconditional instability for any stepsize however small! FTCS never works except over very short time periods! 388
The Lax method Amazingly, a very minor change to this scheme (introduced by Lax) fixes this unconditional instability Instead of u j = u jn (cδt /2Δx) (u j+1n u j 1n ) we use u j = ½(u n j+1 + u n j 1 ) (cδt /2Δx)(u j+1n u j 1n ) 389
The Lax method Like FTCS, the Lax scheme is isexplicit (u can be written explicitly in terms of quantities already calculated) is a single-level scheme (in that it only involves values at time level n) accurate to order (Δt) 1 (Δx) 2 Graphical representation: n,t for / t for / x already known new point j,x 390
Stability of the Lax method von Neumann stability analysis: starting again with a sine wave of wavelength 2π/k: u jn = ξ n e ikjδx At the next step, the Lax scheme yields u j = ½(u j+1 n + u j 1n ) (cδt/2δx) (u j+1n u j 1n ) = u jn (½[e ikδx + e ikδx ]) (cδt/2δx) [e ikδx e ikδx ]) = ξ n (cos(kδx) i(cδt/δx)sin(kδx) ) 391
von Neumann stability analysis Now, the amplitude growth is governed by R, where R ξ /ξ n = {cos 2 (kδx)+[cδt/δx] 2 sin 2 (kδx)} = 1 + ([cδt/δx] 2 1) sin 2 (kδx) The stability criterion is then R < 1 cδt < Δx (for any k) 392
Courant-(Friedrichs-Lewy) stability criterion This stability criterion cδt < Δx tells us that Δt must be sufficiently small that we don t require information from points beyond those sampled at step n (step too large) okay for Step ct Step n x 393
Relation of Lax to FTCS Note also that the Lax scheme applied to u/ t + c u/ x = 0 u j = ½(u j+1n +u n j 1 ) (cδt /2Δx)(u j+1n u j 1n ) can be written u j = u jn (cδt /2Δx)(u j+1n u j 1n ) + ½(u n j+1 2u jn +u j 1n ) Additional term added to FTCS recipe 394
Relation of Lax to FTCS This additional term is the finite difference expression for 2 u/ x 2 In fact, we would use just this recipe if used FTCS to solve u/ t + c u/ x [(Δx) 2 /2Δt] 2 u/ x 2 = 0 Diffusion term damps out amplitude growth 395
Upwind differencing For simple problems, an asymmetric expression for the spatial derivative can remove instability: we can force information to flow in the physical wave direction u j = u jn (cδt /Δx)(u n j+1 u jn ) c < 0 u j = u jn (cδt /Δx)(u jn u j 1n ) c > 0 396
Errors in the integration of PDEs Exponential decay is clearly preferable Short wavelength perturbations decay fastest because decay rate 1 R sin 2 (kδx) Not surprisingly, our integration does best for Fourier components that are well sampled (with kδx << 1) 397
Errors in the integration of PDEs Clearly, for this simple case, we know that the true solution is R = 1 (our wave propagates at constant amplitude along the x-axis) The FTCS method always yields R > 1 exponential growth for all k and Δt The Lax method yields R < 1 if the Courant criterion is satisfied exponential decay 398
Errors in the integration of PDEs So far, we have considered only amplitude errors For the Lax method, we had ξ = ξ n (cos(kδx) i(cδt/δx) sin(kδx) ) ξ n e i(ckδt) in the limit kδx 0 But for finite kδx, arg(ξ /ξ n ) i(ckδt) Phase errors can cause problems because they artificially introduce dispersion (wave propagation rate depends on k) 399
Staggered leapfrog We can achieve 2 nd order accuracy in time if we use ( u/ t) j,n = (u j un 1 j ) / 2Δt instead of ( u/ t) j,n = (u j u jn ) / Δt This is called staggered leapfrog 400
Staggered leapfrog This is no longer a single-level scheme (in that it now involves values at time level n and n 1) but it is still explicit Graphical representation: n,t j,x 401
Staggered leapfrog For u/ t + c u/ x = 0, staggered leapfrog yields (u j u j n 1 ) = (cδt /Δx) (u j+1 n u j 1n ) The von Neumann stability analysis gives us ξ ξ n 1 = ξ n ( 2i (cδt/δx) sin(kδx) ) R 2 1 = 2i (cδt/δx) sin(kδx) R R = i (cδt/δx) sin(kδx) ± {1 (cδt/δx) 2 sin 2 (kδx)} 402
Staggered leapfrog For any (cδt/δx) 2 sin 2 (kδx) < 1, R = 1 Thus, if the Courant condition applies, this 2 nd order method works perfectly for our simple wave equation: the amplitude neither grows nor dissipates 403
Staggered leapfrog For more complex equations, staggered leapfrog can become unstable because the odd and even gridpoints are completely uncoupled; this can lead to mesh instability (see figure 19.1.16 from Recipes) 404
Staggered leapfrog Solution: couple the two meshes by introducing a weak diffusive coupling term a(u n j+1 2un j + un j 1 ) with a << 1. This keeps them in phase. 405