19.3 Initial Value Problems in Multidimensions 853 The correct way to difference Schrodinger's equation [1.2]is to use Cayley's formfor the finite-difference representation ofwhich is second-order accurate and unitary: e-illt 1-2iH△t (19.2.35) 1+2iH△t In other words, ((1+iH△t)+1=(1-iH△t)吗 (19.2.36) On replacing H by its finite-difference approximation in z,we have a complex 是言e2 tridiagonal system to solve.The method is stable,unitary,and second-order accurate in space and time.In fact,it is simply the Crank-Nicolson method once again! ICAL CITED REFERENCES AND FURTHER READING: RECIPES Ames,W.F.1977,Numerical Methods for Partial Differential Equations,2nd ed.(New York: Academic Press),Chapter 2. 9 Goldberg,A.,Schey,H.M.,and Schwartz,J.L.1967,American Journal of Physics,vol.35, pp.177-186.[1] Galbraith,I.,Ching,Y.S.,and Abraham,E.1984,American Journal of Physics,vol.52,pp.60- 68.2] 、2。 IENTIFIC 19.3 Initial Value Problems in Multidimensions 6 The methods described in $19.1 and $19.2 for problems in 1+1 dimension (one space and one time dimension)can easily be generalized to N+1 dimensions. However,the computing power necessary to solve the resulting equations is enor- mous.If you have solved a one-dimensional problem with 100 spatial grid points, solving the two-dimensional version with 100 x 100 mesh points requires at least Recipes Numerica 10.621 100 times as much computing.You generally have to be content with very modest spatial resolution in multidimensional problems. 4310 Recipes Indulge us in offering a bit of advice about the development and testing of multidimensional PDE codes:You should always first run your programs on very small grids,e.g.,8 x 8,even though the resulting accuracy is so poor as to be useless.When your program is all debugged and demonstrably stable,then you can increase the grid size to a reasonable one and start looking at the results.We have actually heard someone protest,"my program would be unstable for a crude grid, but I am sure the instability will go away on a larger grid."That is nonsense of a most pernicious sort,evidencing total confusion between accuracy and stability.In fact,new instabilities sometimes do show up on larger grids;but old instabilities never (in our experience)just go away. Forced to live with modest grid sizes,some people recommend going to higher- order methods in an attempt to improve accuracy.This is very dangerous.Unless the solution you are looking for is known to be smooth,and the high-order method you
19.3 Initial Value Problems in Multidimensions 853 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). The correct way to difference Schrodinger’s equation ¨ [1,2] is to use Cayley’s form for the finite-difference representation of e −iHt, which is second-order accurate and unitary: e−iHt 1 − 1 2 iH∆t 1 + 1 2 iH∆t (19.2.35) In other words, 1 + 1 2 iH∆t ψn+1 j = 1 − 1 2 iH∆t ψn j (19.2.36) On replacing H by its finite-difference approximation in x, we have a complex tridiagonal system to solve. The method is stable, unitary, and second-order accurate in space and time. In fact, it is simply the Crank-Nicolson method once again! CITED REFERENCES AND FURTHER READING: Ames, W.F. 1977, Numerical Methods for Partial Differential Equations, 2nd ed. (New York: Academic Press), Chapter 2. Goldberg, A., Schey, H.M., and Schwartz, J.L. 1967, American Journal of Physics, vol. 35, pp. 177–186. [1] Galbraith, I., Ching, Y.S., and Abraham, E. 1984, American Journal of Physics, vol. 52, pp. 60– 68. [2] 19.3 Initial Value Problems in Multidimensions The methods described in §19.1 and §19.2 for problems in 1+1 dimension (one space and one time dimension) can easily be generalized to N + 1 dimensions. However, the computing power necessary to solve the resulting equations is enormous. If you have solved a one-dimensional problem with 100 spatial grid points, solving the two-dimensional version with 100 × 100 mesh points requires at least 100 times as much computing. You generally have to be content with very modest spatial resolution in multidimensional problems. Indulge us in offering a bit of advice about the development and testing of multidimensional PDE codes: You should always first run your programs on very small grids, e.g., 8 × 8, even though the resulting accuracy is so poor as to be useless. When your program is all debugged and demonstrably stable, then you can increase the grid size to a reasonable one and start looking at the results. We have actually heard someone protest, “my program would be unstable for a crude grid, but I am sure the instability will go away on a larger grid.” That is nonsense of a most pernicious sort, evidencing total confusion between accuracy and stability. In fact, new instabilities sometimes do show up on larger grids; but old instabilities never (in our experience) just go away. Forced to live with modest grid sizes, some people recommend going to higherorder methods in an attempt to improve accuracy. This is very dangerous. Unless the solution you are looking for is known to be smooth, and the high-order method you
854 Chapter 19.Partial Differential Equations are using is known to be extremely stable,we do not recommend anything higher than second-order in time(for sets of first-order equations).For spatial differencing, we recommend the order of the underlying PDEs,perhaps allowing second-order spatial differencing for first-order-in-space PDEs.When you increase the order of a differencing method to greater than the order of the original PDEs,you introduce spurious solutions to the difference equations.This does not create a problem if they all happen to decay exponentially;otherwise you are going to see all hell break loose! Lax Method for a Flux-Conservative Equation As an example,we show how to generalize the Lax method (19.1.15)to two dimensions for the conservation equation 豆8之合N ai=-V.F=- ∂Fx (19.3.1) RECIPES Use a spatial grid with è xj=x0+j△ (19.3.2) =0+l△ 。 We have chosen△x=△y≡△for simplicity.Then the Lax scheme is 1=吗+1+吗-1++1+- IENTIFIC (19.3.3) 6 △t -2公(野1-學1u+野+1-鄂-) Note that as an abbreviated notation Fj+and Fj-1 refer to F,while F+and F1-1 refer to Fy. Let us carry out a stability analysis for the model advective equation(analog of 19.1.6)with Numerical 10621 431 FT=vru, Fy=vyu (19.3.4) Recipes This requires an eigenmode with two dimensions in space,though still only a simple dependence on powers of g in time, uhl EneikzjneikulA (19.3.5) Substituting in equation (19.3.3),we find 、1 f=2(cosk&△+cosk△)-ia:sink:△-ioy sin kyA (19.3.6) where ar VrAt (19.3.7) △
854 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). are using is known to be extremely stable, we do not recommend anything higher than second-order in time (for sets of first-order equations). For spatial differencing, we recommend the order of the underlying PDEs, perhaps allowing second-order spatial differencing for first-order-in-space PDEs. When you increase the order of a differencing method to greater than the order of the original PDEs, you introduce spurious solutions to the difference equations. This does not create a problem if they all happen to decay exponentially; otherwise you are going to see all hell break loose! Lax Method for a Flux-Conservative Equation As an example, we show how to generalize the Lax method (19.1.15) to two dimensions for the conservation equation ∂u ∂t = −∇ · F = − ∂Fx ∂x + ∂Fy ∂y (19.3.1) Use a spatial grid with xj = x0 + j∆ yl = y0 + l∆ (19.3.2) We have chosen ∆x = ∆y ≡ ∆ for simplicity. Then the Lax scheme is un+1 j,l = 1 4 (un j+1,l + un j−1,l + un j,l+1 + un j,l−1) − ∆t 2∆(F n j+1,l − F n j−1,l + F n j,l+1 − F n j,l−1) (19.3.3) Note that as an abbreviated notation Fj+1 and Fj−1 refer to Fx, while Fl+1 and Fl−1 refer to Fy. Let us carry out a stability analysis for the model advective equation (analog of 19.1.6) with Fx = vxu, Fy = vyu (19.3.4) This requires an eigenmode with two dimensions in space, though still only a simple dependence on powers of ξ in time, un j,l = ξneikxj∆eikyl∆ (19.3.5) Substituting in equation (19.3.3), we find ξ = 1 2 (cos kx∆ + cos ky∆) − iαx sin kx∆ − iαy sin ky∆ (19.3.6) where αx = vx∆t ∆ , αy = vy∆t ∆ (19.3.7)
19.3 Initial Value Problems in Multidimensions 855 The expression for 2 can be manipulated into the form p-1-(in kA+sin k) (19.3.8) -4(cosk△-cos△)2-(oy sin k△-a红sink△2 The last two terms are negative,and so the stability requirement 2<1 becomes 1 三 2-(a2+a)≥0 (19.3.9) or △t≤ △ (19.3.10) √2(2+)/2 ICAL This is an example of the general result for the N-dimensional Courant condition:If is the maximum propagation velocity in the problem,then RECIPES △t≤ (19.3.11) 9 VNu 众入 ress. is the Courant condition. Diffusion Equation in Multidimensions Let us consider the two-dimensional diffusion equation, IENTIFIC Ou 乎u 6 =D x2+ 02 (19.3.12) ot An explicit method,such as FTCS,can be generalized from the one-dimensional case in the obvious way.However,we have seen that diffusive problems are usually best treated implicitly.Suppose we try to implement the Crank-Nicolson scheme in Recipes Numerical 105211 two dimensions.This would give us 43106 =+(吗+叫+叫+叫) (19.3.13) E喜 Here DAt 42 △≡△x=△y (19.3.14) 2.三u吲+1,1-2u.+u-1,1 (19.3.15) and similarly forThis is certainly a viable scheme;the problem arises in solving the coupled linear equations.Whereas in one space dimension the system was tridiagonal,that is no longer true,though the matrix is still very sparse.One possibility is to use a suitable sparse matrix technique(see $2.7 and $19.0). Another possibility,which we generally prefer,is a slightly different way of generalizing the Crank-Nicolson algorithm.It is still second-order accurate in time and space,and unconditionally stable,but the equations are easier to solve than
19.3 Initial Value Problems in Multidimensions 855 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). The expression for |ξ| 2 can be manipulated into the form |ξ| 2 = 1 − (sin2 kx∆ + sin2 ky∆) 1 2 − (α2 x + α2 y) − 1 4 (cos kx∆ − cos ky∆)2 − (αy sin kx∆ − αx sin ky∆)2 (19.3.8) The last two terms are negative, and so the stability requirement |ξ| 2 ≤ 1 becomes 1 2 − (α2 x + α2 y) ≥ 0 (19.3.9) or ∆t ≤ ∆ √ 2(v2 x + v2 y)1/2 (19.3.10) This is an example of the general result for the N-dimensional Courant condition: If |v| is the maximum propagation velocity in the problem, then ∆t ≤ ∆ √ N|v| (19.3.11) is the Courant condition. Diffusion Equation in Multidimensions Let us consider the two-dimensional diffusion equation, ∂u ∂t = D ∂2u ∂x2 + ∂2u ∂y2 (19.3.12) An explicit method, such as FTCS, can be generalized from the one-dimensional case in the obvious way. However, we have seen that diffusive problems are usually best treated implicitly. Suppose we try to implement the Crank-Nicolson scheme in two dimensions. This would give us un+1 j,l = un j,l + 1 2 α δ2 xun+1 j,l + δ2 xun j,l + δ2 yun+1 j,l + δ2 yun j,l (19.3.13) Here α ≡ D∆t ∆2 ∆ ≡ ∆x = ∆y (19.3.14) δ2 xun j,l ≡ un j+1,l − 2un j,l + un j−1,l (19.3.15) and similarly for δ2 yun j,l. This is certainly a viable scheme; the problem arises in solving the coupled linear equations. Whereas in one space dimension the system was tridiagonal, that is no longer true, though the matrix is still very sparse. One possibility is to use a suitable sparse matrix technique (see §2.7 and §19.0). Another possibility, which we generally prefer, is a slightly different way of generalizing the Crank-Nicolson algorithm. It is still second-order accurate in time and space, and unconditionally stable, but the equations are easier to solve than
856 Chapter 19.Partial Differential Equations (19.3.13).Called the alternating-direction implicit method (ADI),this embodies the powerful concept of operator splitting or time splitting,about which we will say more below.Here,the idea is to divide each timestep into two steps of size At/2. In each substep,a different dimension is treated implicitly: 啦=喷+(医时P+ (19.3.16) 时=e+(G2+y') The advantage of this method is that each substep requires only the solution of a simple tridiagonal system. Operator Splitting Methods Generally 行 The basic idea of operator splitting,which is also called time splitting or the method of fractional steps,is this:Suppose you have an initial value equation of the form g.af 2 =Cu (19.3.17) Ot where C is some operator.While C is not necessarily linear,suppose that it can at 4、● 9 least be written as a linear sum of m pieces,which act additively on u, Cu=C1u+C2u+…+Cmu (19.3.18) Finally,suppose that for each of the pieces,you already know a differencing scheme for updating the variable u from timestep n to timestep n+1,valid if that piece of the operator were the only one on the right-hand side.We will write these updatings symbolically as un+1=l4(n,△t) Numerical 10521 un+1=2(u”,△t) 431 (19.3.19) (outside Recipes un+1=lun(u”,△t) North Software. Now,one form of operator splitting would be to get from n to n+1 by the following sequence of updatings: un+(1/m)=4(u”,△t) un+(2/m)=u(un+(1/m),At) (19.3.20) n+1=4n(un+(m-1)/m,△t)
856 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). (19.3.13). Called the alternating-direction implicit method (ADI), this embodies the powerful concept of operator splitting or time splitting, about which we will say more below. Here, the idea is to divide each timestep into two steps of size ∆t/2. In each substep, a different dimension is treated implicitly: un+1/2 j,l = un j,l + 1 2 α δ2 xun+1/2 j,l + δ2 yun j,l un+1 j,l = un+1/2 j,l + 1 2 α δ2 xun+1/2 j,l + δ2 yun+1 j,l (19.3.16) The advantage of this method is that each substep requires only the solution of a simple tridiagonal system. Operator Splitting Methods Generally The basic idea of operator splitting, which is also called time splitting or the method of fractional steps, is this: Suppose you have an initial value equation of the form ∂u ∂t = Lu (19.3.17) where L is some operator. While L is not necessarily linear, suppose that it can at least be written as a linear sum of m pieces, which act additively on u, Lu = L1u + L2u + ··· + Lmu (19.3.18) Finally, suppose that for each of the pieces, you already know a differencing scheme for updating the variable u from timestep n to timestep n + 1, valid if that piece of the operator were the only one on the right-hand side. We will write these updatings symbolically as un+1 = U1(un, ∆t) un+1 = U2(un, ∆t) ··· un+1 = Um(un, ∆t) (19.3.19) Now, one form of operator splitting would be to get from n to n + 1 by the following sequence of updatings: un+(1/m) = U1(un, ∆t) un+(2/m) = U2(un+(1/m) , ∆t) ··· un+1 = Um(un+(m−1)/m, ∆t) (19.3.20)
19.4 Fourier and Cyclic Reduction Methods 857 For example,a combined advective-diffusion equation,such as Ou oi=-v 02u +D (19.3.21) Ox 0x2 might profitably use an explicit scheme for the advective term combined with a Crank-Nicolson or other implicit scheme for the diffusion term. The alternating-direction implicit (ADI)method,equation(19.3.16),is an example of operator splitting with a slightly different twist.Let us reinterpret (19.3.19)to have a different meaning:Let i now denote an updating method that 8 includes algebraically all the pieces of the total operator C,but which is desirably stable only for the Ci piece;likewise U2,...Um.Then a method of getting from un to un+1 is B un+1/m=h(u”,△t/m) ICAL un+2/m =U(un+1/m,At/m) (19.3.22) un+1=Um(un+(m-1)/m,At/m) 8 9 The timestep for each fractional step in(19.3.22)is now only 1/m ofthe full timestep, because each partial operation acts with all the terms of the original operator. Equation(19.3.22)is usually,though not always,stable as a differencing scheme 》 9 for the operator C.In fact,as a rule of thumb,it is often sufficient to have stable i's only for the operator pieces having the highest number of spatial derivatives-the other i's can be unstable-to make the overall scheme stable! 6 It is at this point that we turn our attention from initial value problems to boundary value problems.These will occupy us for the remainder of the chapter. CITED REFERENCES AND FURTHER READING: Ames,W.F.1977,Numerical Methods for Partial Differential Equations,2nd ed.(New York: Academic Press). 3四三a Numerica 10.621 4312 (outside Recipes 19.4 Fourier and Cyclic Reduction Methods for North Boundary Value Problems As discussed in $19.0,most boundary value problems(elliptic equations,for example)reduce to solving large sparse linear systems of the form A·u=b (19.4.1) either once,for boundary value equations that are linear,or iteratively,for boundary value equations that are nonlinear
19.4 Fourier and Cyclic Reduction Methods 857 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). For example, a combined advective-diffusion equation, such as ∂u ∂t = −v ∂u ∂x + D ∂2u ∂x2 (19.3.21) might profitably use an explicit scheme for the advective term combined with a Crank-Nicolson or other implicit scheme for the diffusion term. The alternating-direction implicit (ADI) method, equation (19.3.16), is an example of operator splitting with a slightly different twist. Let us reinterpret (19.3.19) to have a different meaning: Let U1 now denote an updating method that includes algebraically all the pieces of the total operator L, but which is desirably stable only for the L1 piece; likewise U2,... Um. Then a method of getting from un to un+1 is un+1/m = U1(un, ∆t/m) un+2/m = U2(un+1/m, ∆t/m) ··· un+1 = Um(un+(m−1)/m, ∆t/m) (19.3.22) The timestep for each fractional step in (19.3.22) is now only 1/m of the full timestep, because each partial operation acts with all the terms of the original operator. Equation (19.3.22) is usually, though not always, stable as a differencing scheme for the operator L. In fact, as a rule of thumb, it is often sufficient to have stable U i’s only for the operator pieces having the highest number of spatial derivatives — the other Ui’s can be unstable — to make the overall scheme stable! It is at this point that we turn our attention from initial value problems to boundary value problems. These will occupy us for the remainder of the chapter. CITED REFERENCES AND FURTHER READING: Ames, W.F. 1977, Numerical Methods for Partial Differential Equations, 2nd ed. (New York: Academic Press). 19.4 Fourier and Cyclic Reduction Methods for Boundary Value Problems As discussed in §19.0, most boundary value problems (elliptic equations, for example) reduce to solving large sparse linear systems of the form A · u = b (19.4.1) either once, for boundary value equations that are linear, or iteratively, for boundary value equations that are nonlinear