next up previous
Next: Code Listing

ASTR615 Fall 2007 Problem Set #7


DCR's Solution


My code listing (shock.c) is given below. For expendiency, run parameters (integration scheme, number of grid points, run time, grid size, and number of outputs) are specified using #defines at the top of the code, rather than by command-line arguments. Both the Lax and Lax-Wendroff schemes are implemented. The grid is taken to run from 0 to 1, with the initial discontinuity at 0.5. The timestep is taken to be about one tenth of the grid spacing in order to satisfy the Courant condition (assuming $v$ never gets too big), but tweaked to make sure the comparison time $t = 0.245$ can be reached in an integer number of steps. I ran the code for a total time of 0.25, outputting every 100 steps, using 1000 grid points. The output files (one each for $\rho$, $p$, $v$, and $\varepsilon$) consist of the time and specified variable value at each grid point, one line per output. A script was written to extract a given time value from the output files for plotting. Another script generates density movies. These scripts are available upon request.

Note the use of macros (DENSITY, DENVEL, ENERGY, VELOCITY, ISE--internal specific energy, and PRESSURE) to simplify access into the component arrays. The latter three macros compute the corresponding variables based on the three component variables $\rho$, $\rho v$, and $e$. The initial and boundary conditions are set in main().

Plots at $t = 0.245$ for the Lax and Lax-Wendroff methods, respectively, are given at the end, for comparison with Fig. 11 of Stone & Norman (1992). Both methods match the overall shape of the published curves, with the Lax method having less-sharp shock features (due to its diffusive nature) and the Lax-Wendroff method showing ``ringing'' at the shock interfaces (presumably due to phase error). For smaller $N$, the match isn't as good. For larger $N$, a better match is obtained at the expense of higher CPU cost.

An animated GIF of the $\rho$ evolution (out to $t = 1$ just for fun) using the Lax method is available at:

http://www.astro.umd.edu/~dcr/Courses/ASTR615/ps7.gif



next up previous
Next: Code Listing
Derek C. Richardson 2007-12-16