17.11.2012 Views

Numerical recipes

Numerical recipes

Numerical recipes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

842 Chapter 19. Partial Differential Equations<br />

t or n<br />

x or j<br />

staggered<br />

leapfrog<br />

Figure 19.1.5. Representation of the staggered leapfrog differencing scheme. Note that information<br />

from two previous time slices is used in obtaining the desired point. This scheme is second-order<br />

accurate in both space and time.<br />

arrives at a given point after a time interval ∆t. In the first-order method, the<br />

material always arrives from ∆x away. If v∆t ≪ ∆x (to insure accuracy), this can<br />

cause a large error. One way of reducing this error is to interpolate u between j − 1<br />

and j before transporting it. This gives effectively a second-order method. Various<br />

schemes for second-order upwind differencing are discussed and compared in [2-3].<br />

Second-Order Accuracy in Time<br />

When using a method that is first-order accurate in time but second-order<br />

accurate in space, one generally has to take v∆t significantly smaller than ∆x to<br />

achieve desired accuracy, say, by at least a factor of 5. Thus the Courant condition<br />

is not actually the limiting factor with such schemes in practice. However, there are<br />

schemes that are second-order accurate in both space and time, and these can often be<br />

pushed right to their stability limit, with correspondingly smaller computation times.<br />

For example, the staggered leapfrog method for the conservation equation<br />

(19.1.1) is defined as follows (Figure 19.1.5): Using the values of u n at time t n ,<br />

compute the fluxes F n j . Then compute new values un+1 using the time-centered<br />

values of the fluxes:<br />

u n+1<br />

j<br />

− un−1 j<br />

∆t<br />

= −<br />

∆x (F n j+1 − F n j−1) (19.1.30)<br />

The name comes from the fact that the time levels in the time derivative term<br />

“leapfrog” over the time levels in the space derivative term. The method requires<br />

that u n−1 and u n be stored to compute u n+1 .<br />

For our simple model equation (19.1.6), staggered leapfrog takes the form<br />

u n+1<br />

j<br />

− un−1 j<br />

v∆t<br />

= −<br />

∆x (unj+1 − u n j−1) (19.1.31)<br />

The von Neumann stability analysis now gives a quadratic equation for ξ, rather than<br />

a linear one, because of the occurrence of three consecutive powers of ξ when the<br />

Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)<br />

Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by <strong>Numerical</strong> Recipes Software.<br />

Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable<br />

files (including this one) to any server computer, is strictly prohibited. To order <strong>Numerical</strong> Recipes books or CDROMs, visit website<br />

http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!