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
never gets too big), but tweaked to
make sure the comparison time
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
,
,
, and
) 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
,
, and
. The initial and
boundary conditions are set in main().
Plots at
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
, the match isn't
as good. For larger
, a better match is obtained at the expense of
higher CPU cost.
An animated GIF of the
evolution (out to
just
for fun) using the Lax method is available at:
http://www.astro.umd.edu/~dcr/Courses/ASTR615/ps7.gif