834 Chapter 19.Partial Differential Equations engineering;these methods allow considerable freedom in putting computational elements where you want them,important when dealing with highly irregular geome- tries.Spectral methods [13-15]are preferred for very regular geometries and smooth functions;they converge more rapidly than finite-difference methods(cf.$19.4),but they do not work well for problems with discontinuities. CITED REFERENCES AND FURTHER READING: Ames,W.F.1977,Numerical Methods for Partial Differential Equations,2nd ed.(New York: Academic Press).[1] Richtmyer,R.D.,and Morton,K.W.1967,Difference Methods for Initial Value Problems,2nd ed. (New York:Wiley-Interscience).[2] Roache,P.J.1976,Computational Fluid Dynamics(Albuquerque:Hermosa).[3] Mitchell,A.R.,and Griffiths,D.F.1980,The Finite Difference Method in Partial Differential Equa- tions (New York:Wiley)[includes discussion of finite element methods].[4] Dorr,F.W.1970,S/AM Review,vol.12,pp.248-263.[5] Meijerink,J.A..and van der Vorst,H.A.1977,Mathematics of Computation,vol.31,pp.148- 162.[6] RECIPES van der Vorst,H.A.1981,Journal of Computational Physics,vol.44,pp.1-19 [review of sparse iterative methods].[7] 9 Kershaw.D.S.1970,Journal of Computational Physics,vol.26,pp.43-65.[8] Stone,H.J.1968,SIAM Journal on Numerical Analysis,vol.5,pp.530-558.[9] Jesshope,C.R.1979,Computer Physics Communications,vol.17,pp.383-391.[10] Strang.G..and Fix,G.1973.An Analysis of the Finite Element Method(Englewood Cliffs,NJ: Prentice-Hall).[11] 是 Burnett,D.S.1987,Finite Element Analysis:From Concepts to Applications (Reading,MA: Addison-Wesley).[12] IENTIFIC Gottlieb,D.and Orszag.S.A.1977,Numerical Analysis of Spectral Methods:Theory and Appli- cations(Philadelphia:S.I.A.M.).[13] 6 Canuto,C.,Hussaini,M.Y.,Quarteroni,A,and Zang,T.A.1988,Spectra/Methods in Fluid Dynamics (New York:Springer-Verlag).[14] Boyd,J.P.1989,Chebyshev and Fourier Spectral Methods(New York:Springer-Verlag).[15] Numerica 10.621 19.1 Flux-Conservative Initial Value Problems 4312 Recipes A large class of initial value(time-evolution)PDEs in one space dimension can (outside be cast into the form of a flx-conservative equation, North Ou OF(u) dt=- (19.1.1) Ox where u and F are vectors,and where(in some cases)F may depend not only on u but also on spatial derivatives of u.The vector F is called the conserved flux. For example,the prototypical hyperbolic equation,the one-dimensional wave equation with constant velocity of propagation v 03=v202u 82u (19.1.2) 0x2
834 Chapter 19. Partial Differential Equations Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). engineering; these methods allow considerable freedom in putting computational elements where you want them, important when dealing with highly irregular geometries. Spectral methods [13-15] are preferred for very regular geometries and smooth functions; they converge more rapidly than finite-difference methods (cf. §19.4), but they do not work well for problems with discontinuities. CITED REFERENCES AND FURTHER READING: Ames, W.F. 1977, Numerical Methods for Partial Differential Equations, 2nd ed. (New York: Academic Press). [1] Richtmyer, R.D., and Morton, K.W. 1967, Difference Methods for Initial Value Problems, 2nd ed. (New York: Wiley-Interscience). [2] Roache, P.J. 1976, Computational Fluid Dynamics (Albuquerque: Hermosa). [3] Mitchell, A.R., and Griffiths, D.F. 1980, The Finite Difference Method in Partial Differential Equations (New York: Wiley) [includes discussion of finite element methods]. [4] Dorr, F.W. 1970, SIAM Review, vol. 12, pp. 248–263. [5] Meijerink, J.A., and van der Vorst, H.A. 1977, Mathematics of Computation, vol. 31, pp. 148– 162. [6] van der Vorst, H.A. 1981, Journal of Computational Physics, vol. 44, pp. 1–19 [review of sparse iterative methods]. [7] Kershaw, D.S. 1970, Journal of Computational Physics, vol. 26, pp. 43–65. [8] Stone, H.J. 1968, SIAM Journal on Numerical Analysis, vol. 5, pp. 530–558. [9] Jesshope, C.R. 1979, Computer Physics Communications, vol. 17, pp. 383–391. [10] Strang, G., and Fix, G. 1973, An Analysis of the Finite Element Method (Englewood Cliffs, NJ: Prentice-Hall). [11] Burnett, D.S. 1987, Finite Element Analysis: From Concepts to Applications (Reading, MA: Addison-Wesley). [12] Gottlieb, D. and Orszag, S.A. 1977, Numerical Analysis of Spectral Methods: Theory and Applications (Philadelphia: S.I.A.M.). [13] Canuto, C., Hussaini, M.Y., Quarteroni, A., and Zang, T.A. 1988, Spectral Methods in Fluid Dynamics (New York: Springer-Verlag). [14] Boyd, J.P. 1989, Chebyshev and Fourier Spectral Methods (New York: Springer-Verlag). [15] 19.1 Flux-Conservative Initial Value Problems A large class of initial value (time-evolution) PDEs in one space dimension can be cast into the form of a flux-conservative equation, ∂u ∂t = −∂F(u) ∂x (19.1.1) where u and F are vectors, and where (in some cases) F may depend not only on u but also on spatial derivatives of u. The vector F is called the conserved flux. For example, the prototypical hyperbolic equation, the one-dimensional wave equation with constant velocity of propagation v ∂2u ∂t2 = v2 ∂2u ∂x2 (19.1.2)
19.1 Flux-Conservative Initial Value Problems 835 can be rewritten as a set of two first-order equations Or Os Ot Ox Os or (19.1.3) Ot where Ou T三U Ox Ou 8三 t (19.1.4) In this case r and s become the two components of u,and the flux is given by the linear matrix relation ICAL F(u) 0 (19.1.5) RECIPES (The physicist-reader may recognize equations(19.1.3)as analogous to Maxwell's equations for one-dimensional propagation of electromagnetic waves.) We will consider,in this section,a prototypical example of the general flux- conservative equation(19.1.1),namely the equation for a scalar u, du du Ot (19.1.6) dx es9&超 9 9 with v a constant.As it happens,we already know analytically that the general IENTIFIC( solution of this equation is a wave propagating in the positive -direction, 6 u=f(x-vt) (19.1.7) where f is an arbitrary function.However,the numerical strategies that we develop will be equally applicable to the more general equations represented by (19.1.1).In some contexts,equation (19.1.6)is called an advective equation,because the quantity u is transported by a "fluid flow"with a velocity v. Recipes Numerical 10621 How do we go about finite differencing equation(19.1.6)(or,analogously, 19.1.1)?The straightforward approach is to choose equally spaced points along both 431 the t-and z-axes.Thus denote Recipes x5=x0+j△x,j=0,1,.,J (19.1.8) tn=to+n△t, n=0,1,..,N Let u"denote u(tn,)We have several choices for representing the time derivative term.The obvious way is to set ou Ot g1-+0(△) (19.1.9) li.n △t This is called forward Euler differencing(cf.equation 16.1.1).While forward Euler is only first-order accurate in At,it has the advantage that one is able to calculate
19.1 Flux-Conservative Initial Value Problems 835 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). can be rewritten as a set of two first-order equations ∂r ∂t = v ∂s ∂x ∂s ∂t = v ∂r ∂x (19.1.3) where r ≡ v ∂u ∂x s ≡ ∂u ∂t (19.1.4) In this case r and s become the two components of u, and the flux is given by the linear matrix relation F(u) = 0 −v −v 0 · u (19.1.5) (The physicist-reader may recognize equations (19.1.3) as analogous to Maxwell’s equations for one-dimensional propagation of electromagnetic waves.) We will consider, in this section, a prototypical example of the general fluxconservative equation (19.1.1), namely the equation for a scalar u, ∂u ∂t = −v ∂u ∂x (19.1.6) with v a constant. As it happens, we already know analytically that the general solution of this equation is a wave propagating in the positive x-direction, u = f(x − vt) (19.1.7) where f is an arbitrary function. However, the numerical strategies that we develop will be equally applicable to the more general equations represented by (19.1.1). In some contexts, equation (19.1.6) is called an advective equation, because the quantity u is transported by a “fluid flow” with a velocity v. How do we go about finite differencing equation (19.1.6) (or, analogously, 19.1.1)? The straightforward approach is to choose equally spaced points along both the t- and x-axes. Thus denote xj = x0 + j∆x, j = 0, 1,...,J tn = t0 + n∆t, n = 0, 1,...,N (19.1.8) Let un j denote u(tn, xj ). We have several choices for representing the time derivative term. The obvious way is to set ∂u ∂t j,n = un+1 j − un j ∆t + O(∆t) (19.1.9) This is called forward Euler differencing (cf. equation 16.1.1). While forward Euler is only first-order accurate in ∆t, it has the advantage that one is able to calculate
836 Chapter 19.Partial Differential Equations 个 0 FTCS x orj Figure 19.1.1.Representation of the Forward Time Centered Space(FTCS)differencing scheme.In this and subsequent figures,the open circle is the new point at which the solution is desired;filled circles are known points whose function values are used in calculating the new point;the solid lines connect points that are used to calculate spatial derivatives;the dashed lines connect points that are used to calculate time derivatives.The FTCS scheme is generally unstable for hyperbolic problems and cannot usually be used. nted for quantities at timestep n+1 in terms of only quantities known at timestep n.For the space derivative,we can use a second-order representation still using only quantities known at timestep n: Ou 0加 u吲+1-1+0(△x2)) RECIPES (19.1.10) 2△x 令 The resulting finite-difference approximation to equation(19.1.6)is called the FTCS representation (Forward Time Centered Space), ,为 u+1-吗 /u+1-u-1 At (19.1.11) 2△x which can easily be rearranged to be a formula for u+in terms of the other IENTIFIC quantities.The FTCS scheme is illustrated in Figure 19.1.1.It's a fine example of 6 an algorithm that is easy to derive,takes little storage,and executes quickly.Too bad it doesn't work!(See below.) The FTCS representation is an explicit scheme.This means thatfor each jcan be calculated explicitly from the quantities that are already known.Later we shall meet implicit schemes,which require us to solve implicit equations coupling the u for various j.(Explicit and implicit methods for ordinary differential 10.621 equations were discussed in 816.6.)The FTCS algorithm is also an example of a single-level scheme,since only values at time level n have to be stored to find E喜 43106 values at time level n+1. (outside von Neumann Stability Analysis North Software. Unfortunately,equation(19.1.11)is of very limited usefulness.It is an unstable method,which can be used only (if at all)to study waves for a short fraction of one oscillation period.To find alternative methods with more general applicability,we must introduce the von Neumann stability analysis. The von Neumann analysis is local:We imagine that the coefficients of the difference equations are so slowly varying as to be considered constant in space and time.In that case,the independent solutions,or eigenmodes,of the difference equations are all of the form un=gneikjAr (19.1.12)
836 Chapter 19. Partial Differential Equations Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). t or n x or j FTCS Figure 19.1.1. Representation of the Forward Time Centered Space (FTCS) differencing scheme. In this and subsequent figures, the open circle is the new point at which the solution is desired; filled circles are known points whose function values are used in calculating the new point; the solid lines connect points that are used to calculate spatial derivatives; the dashed lines connect points that are used to calculate time derivatives. The FTCS scheme is generally unstable for hyperbolic problems and cannot usually be used. quantities at timestep n + 1 in terms of only quantities known at timestep n. For the space derivative, we can use a second-order representation still using only quantities known at timestep n: ∂u ∂x j,n = un j+1 − un j−1 2∆x + O(∆x2) (19.1.10) The resulting finite-difference approximation to equation (19.1.6) is called the FTCS representation (Forward Time Centered Space), un+1 j − un j ∆t = −v un j+1 − un j−1 2∆x (19.1.11) which can easily be rearranged to be a formula for u n+1 j in terms of the other quantities. The FTCS scheme is illustrated in Figure 19.1.1. It’s a fine example of an algorithm that is easy to derive, takes little storage, and executes quickly. Too bad it doesn’t work! (See below.) The FTCS representation is an explicit scheme. This means that un+1 j for each j can be calculated explicitly from the quantities that are already known. Later we shall meet implicit schemes, which require us to solve implicit equations coupling the un+1 j for various j. (Explicit and implicit methods for ordinary differential equations were discussed in §16.6.) The FTCS algorithm is also an example of a single-level scheme, since only values at time level n have to be stored to find values at time level n + 1. von Neumann Stability Analysis Unfortunately, equation (19.1.11) is of very limited usefulness. It is an unstable method, which can be used only (if at all) to study waves for a short fraction of one oscillation period. To find alternative methods with more general applicability, we must introduce the von Neumann stability analysis. The von Neumann analysis is local: We imagine that the coefficients of the difference equations are so slowly varying as to be considered constant in space and time. In that case, the independent solutions, or eigenmodes, of the difference equations are all of the form un j = ξneikj∆x (19.1.12)
19.1 Flux-Conservative Initial Value Problems 837 ,0 Lax x or/ Figure 19.1.2.Representation of the Lax differencing scheme,as in the previous figure.The stability criterion for this scheme is the Courant condition. where k is a real spatial wave number(which can have any value)and =(k)is a complex number that depends on k.The key fact is that the time dependence of a single eigenmode is nothing more than successive integer powers of the complex nted for number Therefore,the difference equations are unstable (have exponentially growing modes)if (k)>1 for some k.The number g is called the amplification factor at a given wave number k. To find (k),we simply substitute (19.1.12)back into (19.1.11).Dividing by gr,we get 2 )=1-i Ar sinkAr (19.1.13) whose modulus is 1 for allk:so the FTCS scheme is unconditionally unstable. If the velocity v were a function of t and r,then we would write v in equation (19.1.11).In the von Neumann stability analysis we would still treat v as a constant, the idea being that for v slowly varying the analysis is local.In fact,even in the SCIENTIFIC( case of strictly constant v,the von Neumann analysis does not rigorously treat the end effects atj=0 and j=N. More generally,if the equation's right-hand side were nonlinear in u,then a von Neumann analysis would linearize by writing u=uo+ou,expanding to linear order in ou.Assuming that the uo quantities already satisfy the difference equation 是 exactly,the analysis would look for an unstable eigenmode of ou. Despite its lack ofrigor,the von Neumann method generally gives valid answers Numerica 10.621 and is much easier to apply than more careful methods.We accordingly adopt it exclusively.(See,for example,[1]for a discussion of other methods of stability 431 analysis.) (outside Recipes Lax Method North Software. The instability in the FTCS method can be cured by a simple change due to Lax. One replaces the term u?in the time derivative term by its average(Figure 19.1.2): 1 u巧一2(+1+u-) (19.1.14 This turns (19.1.11)into 吗1-+-小-器-- (19.1.15)
19.1 Flux-Conservative Initial Value Problems 837 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). t or n x or j Lax Figure 19.1.2. Representation of the Lax differencing scheme, as in the previous figure. The stability criterion for this scheme is the Courant condition. where k is a real spatial wave number (which can have any value) and ξ = ξ(k) is a complex number that depends on k. The key fact is that the time dependence of a single eigenmode is nothing more than successive integer powers of the complex number ξ. Therefore, the difference equations are unstable (have exponentially growing modes) if |ξ(k)| > 1 for some k. The number ξ is called the amplification factor at a given wave number k. To find ξ(k), we simply substitute (19.1.12) back into (19.1.11). Dividing by ξn, we get ξ(k)=1 − i v∆t ∆x sin k∆x (19.1.13) whose modulus is > 1 for all k; so the FTCS scheme is unconditionally unstable. If the velocity v were a function of t and x, then we would write v n j in equation (19.1.11). In the von Neumann stability analysis we would still treat v as a constant, the idea being that for v slowly varying the analysis is local. In fact, even in the case of strictly constant v, the von Neumann analysis does not rigorously treat the end effects at j = 0 and j = N. More generally, if the equation’s right-hand side were nonlinear in u, then a von Neumann analysis would linearize by writing u = u0 + δu, expanding to linear order in δu. Assuming that the u0 quantities already satisfy the difference equation exactly, the analysis would look for an unstable eigenmode of δu. Despite its lack of rigor, the von Neumann method generally gives valid answers and is much easier to apply than more careful methods. We accordingly adopt it exclusively. (See, for example, [1] for a discussion of other methods of stability analysis.) Lax Method The instability in the FTCS method can be cured by a simple change due to Lax. One replaces the term un j in the time derivative term by its average (Figure 19.1.2): un j → 1 2 un j+1 + un j−1 (19.1.14) This turns (19.1.11) into un+1 j = 1 2 un j+1 + un j−1 − v∆t 2∆x un j+1 − un j−1 (19.1.15)
838 Chapter 19.Partial Differential Equations stable unstable or n △x x or (a) (b) 一2 83 Figure 19.1.3.Courant condition for stability of a differencing scheme.The solution of a hyperbolic 鱼 19881992 problem at a point depends on information within some domain of dependency to the past,shown here shaded.The differencing scheme (19.1.15)has its own domain of dependency determined by the choice 1.800 of points on one time slice (shown as connected solid dots)whose values are used in determining a new point (shown connected by dashed lines).A differencing scheme is Courant stable if the differencing domain of dependency is larger than that of the PDEs,as in (a),and unstable if the relationship is the from NUMERICAL RECIPESI reverse,as in (b).For more complicated differencing schemes,the domain of dependency might not be determined simply by the outermost points. 令 Substituting equation(19.1.12),we find for the amplification factor ξ=cosk△x-i v△t Press. sink△x (19.1.16) △x The stability condition 2<1 leads to the requirement Programs lv△t ≤1 (19.1.17) SCIENTIFIC △x This is the famous Courant-Friedrichs-Lewy stability criterion, often 61 called simply the Courant condition.Intuitively,the stability condition can be understood as follows(Figure 19.1.3):The quantity u in equation(19.1.15)is computed from information at points j-1 and j+1 at time n.In other words, j-1 and j+are the boundaries ofthe spatial region that is allowed to communicate information to Now recall that in the continuum wave equation,information Fuurggoglrion Numerical Recipes 10621 actually propagates with a maximum velocity v.If the point u is outside of the shaded region in Figure 19.1.3,then it requires information from points more 4310 distant than the differencing scheme allows.Lack of that information gives rise to g an instability.Therefore,At cannot be made too large. (outside The surprising result,that the simple replacement(19.1.14)stabilizes the FTCS scheme,is our first encounter with the fact that differencing PDEs is an art as much North Software. as a science.To see if we can demystify the art somewhat,let us compare the FTCS and Lax schemes by rewriting equation(19.1.15)so that it is in the form of equation (19.1.11)with a remainder term: -()+(m+ (19.1.18) △t △t But this is exactly the FTCS representation of the equation 0u0u,(△x)2 72u (19.1.19) 2△t
838 Chapter 19. Partial Differential Equations Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). t or n ∆t x or j ∆t ∆x ∆x stable unstable (a) (b) Figure 19.1.3. Courant condition for stability of a differencing scheme. The solution of a hyperbolic problem at a point depends on information within some domain of dependency to the past, shown here shaded. The differencing scheme (19.1.15) has its own domain of dependency determined by the choice of points on one time slice (shown as connected solid dots) whose values are used in determining a new point (shown connected by dashed lines). A differencing scheme is Courant stable if the differencing domain of dependency is larger than that of the PDEs, as in (a), and unstable if the relationship is the reverse, as in (b). For more complicated differencing schemes, the domain of dependency might not be determined simply by the outermost points. Substituting equation (19.1.12), we find for the amplification factor ξ = cos k∆x − i v∆t ∆x sin k∆x (19.1.16) The stability condition |ξ| 2 ≤ 1 leads to the requirement |v|∆t ∆x ≤ 1 (19.1.17) This is the famous Courant-Friedrichs-Lewy stability criterion, often called simply the Courant condition. Intuitively, the stability condition can be understood as follows (Figure 19.1.3): The quantity u n+1 j in equation (19.1.15) is computed from information at points j − 1 and j + 1 at time n. In other words, xj−1 and xj+1 are the boundaries of the spatial region that is allowed to communicate information to un+1 j . Now recall that in the continuum wave equation, information actually propagates with a maximum velocity v. If the point u n+1 j is outside of the shaded region in Figure 19.1.3, then it requires information from points more distant than the differencing scheme allows. Lack of that information gives rise to an instability. Therefore, ∆t cannot be made too large. The surprising result, that the simple replacement (19.1.14) stabilizes the FTCS scheme, is our first encounter with the fact that differencing PDEs is an art as much as a science. To see if we can demystify the art somewhat, let us compare the FTCS and Lax schemes by rewriting equation (19.1.15) so that it is in the form of equation (19.1.11) with a remainder term: un+1 j − un j ∆t = −v un j+1 − un j−1 2∆x + 1 2 un j+1 − 2un j + un j−1 ∆t (19.1.18) But this is exactly the FTCS representation of the equation ∂u ∂t = −v ∂u ∂x + (∆x)2 2∆t ∇2u (19.1.19)
19.1 Flux-Conservative Initial Value Problems 839 where V2 =82/0x2 in one dimension.We have,in effect,added a diffusion term to the equation,or,if you recall the form of the Navier-Stokes equation for viscous fluid flow,a dissipative term.The Lax scheme is thus said to have numerical dissipation, or numerical viscosity.We can see this also in the amplification factor.Unless vAt is exactly equal to Ax,<1 and the amplitude of the wave decreases spuriously. Isn't a spurious decrease as bad as a spurious increase?No.The scales that we hope to study accurately are those that encompass many grid points,so that they have kAx<1.(The spatial wave number k is defined by equation 19.1.12.)For these scales.the amplification factor can be seen to be very close to one,in both the stable and unstable schemes.The stable and unstable schemes are therefore about equally 8 accurate.For the unstable scheme,however,short scales with kAx1,which we are not interested in,will blow up and swamp the interesting part of the solution. Much better to have a stable scheme in which these short wavelengths die away innocuously.Both the stable and the unstable schemes are inaccurate for these short 大分 wavelengths,but the inaccuracy is of a tolerable character when the scheme is stable. When the independent variable u is a vector,then the von Neumann analysis is slightly more complicated.For example,we can consider equation (19.1.3). RECIPES I rewritten as 9 「r (19.1.20) Oxvr The Lax method for this equation is 9 +1= *1+-)+ 2△x (s+1-s-1) v△t (19.1.21) IENTIFIC +1 1+s号-)+a+--) The von Neumann stability analysis now proceeds by assuming that the eigenmode is of the following (vector)form, (19.1.22) Numerica 10621 Here the vector on the right-hand side is a constant(both in space and in time) 431 eigenvector,and is a complex number,as before. Substituting (19.1.22)into (19.1.21),and dividing by the power "gives the homogeneous vector equation (outside Recipes (cosk△x)-E -sink△a 0 North v△ (19.1.23) sink△x (cosk△x)-& 0 △x This admits a solution only if the determinant of the matrix on the left vanishes,a condition easily shown to yield the two roots g S=coskA士iVAt sink△x (19.1.24) △x The stability condition is that both roots satisfy<1.This again turns out to be simply the Courant condition (19.1.17)
19.1 Flux-Conservative Initial Value Problems 839 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). where ∇2 = ∂2/∂x2 in one dimension. We have, in effect, added a diffusion term to the equation, or, if you recall the form of the Navier-Stokes equation for viscous fluid flow, a dissipative term. The Lax scheme is thus said to have numerical dissipation, or numerical viscosity. We can see this also in the amplification factor. Unless |v|∆t is exactly equal to ∆x, |ξ| < 1 and the amplitude of the wave decreases spuriously. Isn’t a spurious decrease as bad as a spurious increase? No. The scales that we hope to study accurately are those that encompass many grid points, so that they have k∆x 1. (The spatial wave number k is defined by equation 19.1.12.) For these scales, the amplification factor can be seen to be very close to one, in both the stable and unstable schemes. The stable and unstable schemes are therefore about equally accurate. For the unstable scheme, however, short scales with k∆x ∼ 1, which we are not interested in, will blow up and swamp the interesting part of the solution. Much better to have a stable scheme in which these short wavelengths die away innocuously. Both the stable and the unstable schemes are inaccurate for these short wavelengths, but the inaccuracy is of a tolerable character when the scheme is stable. When the independent variable u is a vector, then the von Neumann analysis is slightly more complicated. For example, we can consider equation (19.1.3), rewritten as ∂ ∂t r s = ∂ ∂x vs vr (19.1.20) The Lax method for this equation is rn+1 j = 1 2 (rn j+1 + rn j−1) + v∆t 2∆x(sn j+1 − sn j−1) sn+1 j = 1 2 (sn j+1 + sn j−1) + v∆t 2∆x(rn j+1 − rn j−1) (19.1.21) The von Neumann stability analysis now proceeds by assuming that the eigenmode is of the following (vector) form, rn j sn j = ξneikj∆x r0 s0 (19.1.22) Here the vector on the right-hand side is a constant (both in space and in time) eigenvector, and ξ is a complex number, as before. Substituting (19.1.22) into (19.1.21), and dividing by the power ξ n, gives the homogeneous vector equation (cos k∆x) − ξ i v∆t ∆x sin k∆x i v∆t ∆x sin k∆x (cos k∆x) − ξ · r0 s0 = 0 0 (19.1.23) This admits a solution only if the determinant of the matrix on the left vanishes, a condition easily shown to yield the two roots ξ ξ = cos k∆x ± i v∆t ∆x sin k∆x (19.1.24) The stability condition is that both roots satisfy |ξ| ≤ 1. This again turns out to be simply the Courant condition (19.1.17)
840 Chapter 19.Partial Differential Equations Other Varieties of Error Thus far we have been concerned with amplitude error,because of its intimate connection with the stability or instability of a differencing scheme.Other varieties of error are relevant when we shift our concern to accuracy,rather than stability. Finite-difference schemes for hyperbolic equations can exhibit dispersion,or phase errors.For example,equation (19.1.16)can be rewritten as ξ=e-ik△x+i -》 sink△z (19.1.25) 81 An arbitrary initial wave packet is a superposition of modes with different k's. At each timestep the modes get multiplied by different phase factors(19.1.25). B depending on their value of k.If At =Ax/v,then the exact solution for each mode ofa wave packet f(r-vt)is obtained if each mode gets multiplied by exp(-ikAr). For this value of At,equation (19.1.25)shows that the finite-difference solution gives the exact analytic result.However,if vAt/Ax is not exactly 1,the phase relations of the modes can become hopelessly garbled and the wave packet disperses. Note from (19.1.25)that the dispersion becomes large as soon as the wavelength 9 becomes comparable to the grid spacing Ar. A third type of error is one associated with nonlinear hyperbolic equations and is therefore sometimes called nonlinear instability.For example,a piece of the Euler or Navier-Stokes equations for fluid flow looks like 9 di =-v (19.1.26) The nonlinear term in v can cause a transfer of energy in Fourier space from 6 long wavelengths to short wavelengths.This results in a wave profile steepening until a vertical profile or "shock"develops.Since the von Neumann analysis suggests that the stability can depend on kAz,a scheme that was stable for shallow profiles can become unstable for steep profiles.This kind of difficulty arises in a differencing scheme where the cascade in Fourier space is halted at the shortest 同g今 wavelength representable on the grid,that is,at k~1/Ax.If energy simply Numerica 10621 accumulates in these modes,it eventually swamps the energy in the long wavelength 431 modes of interest. Recipes Nonlinear instability and shock formation is thus somewhat controlled by numerical viscosity such as that discussed in connection with equation (19.1.18) above.In some fluid problems,however,shock formation is not merely an annoyance, North but an actual physical behavior of the fluid whose detailed study is a goal.Then, numerical viscosity alone may not be adequate or sufficiently controllable.This is a complicated subject which we discuss further in the subsection on fluid dynamics, below. For wave equations,propagation errors(amplitude or phase)are usually most worrisome.For advective equations,on the other hand,transport errors are usually of greater concern.In the Lax scheme,equation(19.1.15),a disturbance in the advected quantity u at mesh point j propagates to mesh pointsj+1 andj-1 at the next timestep.In reality,however,if the velocity v is positive then only mesh point j+1 should be affected
840 Chapter 19. Partial Differential Equations Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). Other Varieties of Error Thus far we have been concerned with amplitude error, because of its intimate connection with the stability or instability of a differencing scheme. Other varieties of error are relevant when we shift our concern to accuracy, rather than stability. Finite-difference schemes for hyperbolic equations can exhibit dispersion, or phase errors. For example, equation (19.1.16) can be rewritten as ξ = e−ik∆x + i 1 − v∆t ∆x sin k∆x (19.1.25) An arbitrary initial wave packet is a superposition of modes with different k’s. At each timestep the modes get multiplied by different phase factors (19.1.25), depending on their value of k. If ∆t = ∆x/v, then the exact solution for each mode of a wave packet f(x−vt) is obtained if each mode gets multiplied by exp(−ik∆x). For this value of ∆t, equation (19.1.25) shows that the finite-difference solution gives the exact analytic result. However, if v∆t/∆x is not exactly 1, the phase relations of the modes can become hopelessly garbled and the wave packet disperses. Note from (19.1.25) that the dispersion becomes large as soon as the wavelength becomes comparable to the grid spacing ∆x. A third type of error is one associated with nonlinear hyperbolic equations and is therefore sometimes called nonlinear instability. For example, a piece of the Euler or Navier-Stokes equations for fluid flow looks like ∂v ∂t = −v ∂v ∂x + ... (19.1.26) The nonlinear term in v can cause a transfer of energy in Fourier space from long wavelengths to short wavelengths. This results in a wave profile steepening until a vertical profile or “shock” develops. Since the von Neumann analysis suggests that the stability can depend on k∆x, a scheme that was stable for shallow profiles can become unstable for steep profiles. This kind of difficulty arises in a differencing scheme where the cascade in Fourier space is halted at the shortest wavelength representable on the grid, that is, at k ∼ 1/∆x. If energy simply accumulates in these modes, it eventually swamps the energy in the long wavelength modes of interest. Nonlinear instability and shock formation is thus somewhat controlled by numerical viscosity such as that discussed in connection with equation (19.1.18) above. In some fluid problems,however, shock formation is not merely an annoyance, but an actual physical behavior of the fluid whose detailed study is a goal. Then, numerical viscosity alone may not be adequate or sufficiently controllable. This is a complicated subject which we discuss further in the subsection on fluid dynamics, below. For wave equations, propagation errors (amplitude or phase) are usually most worrisome. For advective equations, on the other hand, transport errors are usually of greater concern. In the Lax scheme, equation (19.1.15), a disturbance in the advected quantity u at mesh point j propagates to mesh points j + 1 and j − 1 at the next timestep. In reality, however, if the velocity v is positive then only mesh point j + 1 should be affected.
19.1 Flux-Conservative Initial Value Problems 841 0 ● upwind tor n http://www.nr. 1" -800472 co granted for (including this one) xor /Cambridge NUMERICAL RECIPES IN Figure 19.1.4.Representation of upwind differencing schemes.The upper scheme is stable when the advection constantis negative,as shown,the lower scheme is stable when the advection constantis (North server positive,also as shown.The Courant condition must,of course,also be satisfied. America users to make one paper computer UnN电.t THE The simplest way to model the transport properties"better"is to use upwind differencing (see Figure 19.1.4): 9 Progra u吗-u吲-1 >0 OF SCIENTIFIC -明 -vn △x u+1-4吗 (19.1.27) 61 △x 吲<0 Note that this scheme is only first-order,not second-order,accurate in the COMPUTING (ISBN calculation of the spatial derivatives.How can it be "better"?The answer is 188810920 one that annoys the mathematicians:The goal of numerical simulations is not always“accuracy”in a strictly mathematical sense,but sometimes“fidelity”to the Numerical Recipes 10-621 underlying physics in a sense that is looser and more pragmatic.In such contexts, some kinds of error are much more tolerable than others.Upwind differencing 4310-5 generally adds fidelity to problems where the advected variables are liable to undergo sudden changes of state,e.g.,as they pass through shocks or other discontinuities. (outside You will have to be guided by the specific nature of your own problem. Software. For the differencing scheme(19.1.27),the amplification factor(for constant v)is 首 =1- a-mska)- sink△z 19.1.28 =1-2(-a -cosk△x) (19.1.29) So the stability criterion 2<1 is (again)simply the Courant condition(19.1.17). There are various ways of improving the accuracy of first-order upwind differencing.In the continuum equation,material originally a distance vAt away
19.1 Flux-Conservative Initial Value Problems 841 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). t or n x or j v upwind v Figure 19.1.4. Representation of upwind differencing schemes. The upper scheme is stable when the advection constant v is negative, as shown; the lower scheme is stable when the advection constant v is positive, also as shown. The Courant condition must, of course, also be satisfied. The simplest way to model the transport properties “better” is to use upwind differencing (see Figure 19.1.4): un+1 j − un j ∆t = −vn j un j − un j−1 ∆x , vn j > 0 un j+1 − un j ∆x , vn j < 0 (19.1.27) Note that this scheme is only first-order, not second-order, accurate in the calculation of the spatial derivatives. How can it be “better”? The answer is one that annoys the mathematicians: The goal of numerical simulations is not always “accuracy” in a strictly mathematical sense, but sometimes “fidelity” to the underlying physics in a sense that is looser and more pragmatic. In such contexts, some kinds of error are much more tolerable than others. Upwind differencing generally adds fidelity to problems where the advected variables are liable to undergo sudden changes of state, e.g., as they pass through shocks or other discontinuities. You will have to be guided by the specific nature of your own problem. For the differencing scheme (19.1.27), the amplification factor (for constant v) is ξ = 1 − v∆t ∆x (1 − cos k∆x) − i v∆t ∆x sin k∆x (19.1.28) |ξ| 2 = 1 − 2 v∆t ∆x 1 − v∆t ∆x (1 − cos k∆x) (19.1.29) So the stability criterion |ξ| 2 ≤ 1 is (again) simply the Courant condition (19.1.17). There are various ways of improving the accuracy of first-order upwind differencing. In the continuum equation, material originally a distance v∆t away
842 Chapter 19.Partial Differential Equations 0 staggered leapfrog 83 granted for x or j 1100 Figure 19.1.5.Representation of the staggered leapfrog differencing scheme.Note that information from two previous time slices is used in obtaining the desired point.This scheme is second-order NUMERICAL RECIPES I accurate in both space and time. arrives at a given point after a time interval At.In the first-order method,the material always arrives from Ax away.If vAtAx (to insure accuracy),this can cause a large error.One way of reducing this error is to interpolate u between i-1 2 and j before transporting it.This gives effectively a second-order method.Various schemes for second-order upwind differencing are discussed and compared in [2-3]. 9」 Second-Order Accuracy in Time IENTIFIC When using a method that is first-order accurate in time but second-order accurate in space,one generally has to take vAt significantly smaller than Ax to achieve desired accuracy,say,by at least a factor of 5.Thus the Courant condition is not actually the limiting factor with such schemes in practice.However,there are schemes that are second-order accurate in both space and time,and these can often be pushed right to their stability limit,with correspondingly smaller computation times. For example,the staggered leapfrog method for the conservation equation 10.621 (19.1.1)is defined as follows(Figure 19.1.5):Using the values of u at time t", Recipes Numerica compute the fluxesF".Then compute new values u+using the time-centered 431 values of the fluxes: Recipes 1-g写1=-g1-厚) (19.1.30 North The name comes from the fact that the time levels in the time derivative term "leapfrog"over the time levels in the space derivative term.The method requires that u"-1 and u"be stored to compute un+1. For our simple model equation(19.1.6),staggered leapfrog takes the form v△t +1-u-1=- (19.1.31) △x u+1-u巧-1) The von Neumann stability analysis now gives a quadratic equation for rather than a linear one,because of the occurrence of three consecutive powers ofg when the
842 Chapter 19. Partial Differential Equations Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). staggered leapfrog t or n x or j Figure 19.1.5. Representation of the staggered leapfrog differencing scheme. Note that information from two previous time slices is used in obtaining the desired point. This scheme is second-order accurate in both space and time. arrives at a given point after a time interval ∆t. In the first-order method, the material always arrives from ∆x away. If v∆t ∆x (to insure accuracy), this can cause a large error. One way of reducing this error is to interpolate u between j − 1 and j before transporting it. This gives effectively a second-order method. Various schemes for second-order upwind differencing are discussed and compared in [2-3]. Second-Order Accuracy in Time When using a method that is first-order accurate in time but second-order accurate in space, one generally has to take v∆t significantly smaller than ∆x to achieve desired accuracy, say, by at least a factor of 5. Thus the Courant condition is not actually the limiting factor with such schemes in practice. However, there are schemes that are second-order accurate in both space and time, and these can often be pushed right to their stability limit, with correspondingly smaller computation times. For example, the staggered leapfrog method for the conservation equation (19.1.1) is defined as follows (Figure 19.1.5): Using the values of u n at time tn, compute the fluxes F n j . Then compute new values un+1 using the time-centered values of the fluxes: un+1 j − un−1 j = − ∆t ∆x(F n j+1 − F n j−1) (19.1.30) The name comes from the fact that the time levels in the time derivative term “leapfrog” over the time levels in the space derivative term. The method requires that un−1 and un be stored to compute un+1. For our simple model equation (19.1.6), staggered leapfrog takes the form un+1 j − un−1 j = −v∆t ∆x (un j+1 − un j−1) (19.1.31) The von Neumann stability analysis now gives a quadratic equation for ξ, rather than a linear one, because of the occurrence of three consecutive powers of ξ when the
19.1 Flux-Conservative Initial Value Problems 843 form (19.1.12)for an eigenmode is substituted into equation (19.1.31), 2-1=-20At △E ink△x (19.1.32) whose solution is w△t 2 △t ξ=-i sink△z (19.1.33) △x Thus the Courant condition is again required for stability.In fact,in equation (19.1.33),2 =1 for any vAt<Ar.This is the great advantage of the staggered leapfrog method:There is no amplitude dissipation. Staggered leapfrog differencing of equations like(19.1.20)is most transparent if the variables are centered on appropriate half-mesh points: r+1/2三 .Oun +1-吗 RECIPES =U- 0zlj+1/2 △x (19.1.34) 9 0u/n+1/2 巧+1-吗 at\i △t This is purely a notational convenience:we can think of the mesh on which r and s are defined as being twice as fine as the mesh on which the original variable u is 8。孕是今 defined.The leapfrog differencing of equation(19.1.20)is IENTIFIC 61 △t △x (19.1.35) 2-s2=42--2 △t △x If you substitute equation(19.1.22)in equation (19.1.35),you will find that once 10.621 again the Courant condition is required for stability,and that there is no amplitude 三 Numerical dissipation when it is satisfied. 43126 If we substitute equation(19.1.34)in equation (19.1.35),we find that equation (19.1.35)is equivalent to 1-2g+="1-2%+ North (△t)2 (△x)2 (19.1.36) This is just the "usual"second-order differencing of the wave equation(19.1.2).We see that it is a two-level scheme,requiring both un and u"-1 to obtain un+1.In equation(19.1.35)this shows up as both s-1/2 and rn being needed to advance the solution. For equations more complicated than our simple model equation,especially nonlinear equations,the leapfrog method usually becomes unstable when the gradi- ents get large.The instability is related to the fact that odd and even mesh points are completely decoupled,like the black and white squares of a chess board,as shown
19.1 Flux-Conservative Initial Value Problems 843 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). form (19.1.12) for an eigenmode is substituted into equation (19.1.31), ξ2 − 1 = −2iξ v∆t ∆x sin k∆x (19.1.32) whose solution is ξ = −i v∆t ∆x sin k∆x ± 1 − v∆t ∆x sin k∆x 2 (19.1.33) Thus the Courant condition is again required for stability. In fact, in equation (19.1.33), |ξ| 2 = 1 for any v∆t ≤ ∆x. This is the great advantage of the staggered leapfrog method: There is no amplitude dissipation. Staggered leapfrog differencing of equations like (19.1.20) is most transparent if the variables are centered on appropriate half-mesh points: rn j+1/2 ≡ v ∂u ∂x n j+1/2 = v un j+1 − un j ∆x s n+1/2 j ≡ ∂u ∂t n+1/2 j = un+1 j − un j ∆t (19.1.34) This is purely a notational convenience: we can think of the mesh on which r and s are defined as being twice as fine as the mesh on which the original variable u is defined. The leapfrog differencing of equation (19.1.20) is rn+1 j+1/2 − rn j+1/2 ∆t = s n+1/2 j+1 − s n+1/2 j ∆x s n+1/2 j − s n−1/2 j ∆t = v rn j+1/2 − rn j−1/2 ∆x (19.1.35) If you substitute equation (19.1.22) in equation (19.1.35), you will find that once again the Courant condition is required for stability, and that there is no amplitude dissipation when it is satisfied. If we substitute equation (19.1.34) in equation (19.1.35), we find that equation (19.1.35) is equivalent to un+1 j − 2un j + un−1 j (∆t)2 = v2 un j+1 − 2un j + un j−1 (∆x)2 (19.1.36) This is just the “usual” second-order differencing of the wave equation (19.1.2). We see that it is a two-level scheme, requiring both un and un−1 to obtain un+1. In equation (19.1.35) this shows up as both s n−1/2 and rn being needed to advance the solution. For equations more complicated than our simple model equation, especially nonlinear equations, the leapfrog method usually becomes unstable when the gradients get large. The instability is related to the fact that odd and even mesh points are completely decoupled, like the black and white squares of a chess board, as shown