The error norms calculated when exact solutions are plotted are as follows: The error for each particle is given by
| ei = fi − fexact, (9) |
where the exact solution fexact(x) is the solution returned from the exact solution subroutines (with resolution adjustable in the exact solution options menu option) interpolated to the position of the current particle xi via a simple linear interpolation. The absolute L1 error norm is simply the average of the errors across the domain, calculated according to
| ∥ e ∥L1 = |
|
| | ei |, (10) |
where fmax is the maximum value of the exact solution in the region in which the particles lie (also only particles in the current plot are used) which is used to normalise the error estimate. A better error norm is the L2 or Root Mean Square (RMS) norm given by
| ∥ e ∥L2 = | ⎡ ⎢ ⎢ ⎣ |
| ⎛ ⎜ ⎜ ⎝ |
|
| | ei |2 | ⎞ ⎟ ⎟ ⎠ | ⎤ ⎥ ⎥ ⎦ |
| . (11) |
Finally the maximum error, or L∞ norm is calculated according to
| ∥ e ∥L∞ = |
| maxi | ei |. (12) |
which is the most stringent error norm.
The inset plot of the individual particle errors shows the fractional deviation for each particle given by
| ei,frac = (fi − fexact) / fexact. (13) |
The subroutine exact_shock plots the exact solution for a one-dimensional shock tube
(Riemann problem). The difficult bit of the problem is to determine the jump in
pressure and velocity across the shock front given the initial left and right
states. This is performed in a separate subroutine (riemannsolver) as there are
many different methods by which this can be done (see e.g. ???).
The actual subroutine exact_shock reconstructs the shock profile (consisting of
a rarefaction fan, contact discontinuity and shock, summarised in Figure
19), given the post-shock values of pressure and
velocity.
![]()
Figure 19: Example of exact solution for one-dimensional shock tube problem (red line) compared to the SPH solution (black line/particles), utilising the exact solutions incorporated in splash
The speed at which the shock travels into the ‘right’ fluid can be computed from the post shock velocity using the relation
| vshock = vpost |
| , (14) |
where the jump conditions imply
| = |
| (15) |
with
| β = |
| . (16) |
The algorithm for determining the post-shock velocity and pressure is taken from ???.
The subroutine exact_polytrope computes the exact solution for a static polytrope with
arbitrary γ. From Poisson’s equation
| ∇2 φ = 4π G ρ, (17) |
assuming only radial dependence this is given by
|
| ⎛ ⎜ ⎜ ⎝ | r2 |
| ⎞ ⎟ ⎟ ⎠ | = 4π G ρ(r). (18) |
The momentum equation assuming an equilibrium state (v = 0) and a polytropic equation of state P = Kργ gives
| = − |
|
| ⎡ ⎣ | ρ(γ −1) | ⎤ ⎦ | (19) |
Combining (18) and (19) we obtain an equation for the density profile
|
|
| ⎡ ⎢ ⎢ ⎣ | r2 |
| ⎛ ⎝ | ργ−1 | ⎞ ⎠ | ⎤ ⎥ ⎥ ⎦ | + ρ(r) = 0. (20) |
This equation can be rearranged to give
|
| ⎡ ⎣ | rργ−1 | ⎤ ⎦ | + rρ = 0. (21) |
The program solves this equation numerically by defining a variable
| E = r ργ−1 (22) |
and finite differencing the equation according to
| = |
| r | ⎛ ⎜ ⎜ ⎝ |
| ⎞ ⎟ ⎟ ⎠ |
| . (23) |
The subroutine exact_wave simply plots a sine function on a given graph.
The function is of the form
| y = sin(k x − ω t) (24) |
where k is the wavenumber and ω is the angular frequency. These parameters are set via the input values of wavelength λ = 2π/k and wave period P = 2π/ω.
λ wavelength P period
Table 4: Input parameters for the linear wave exact solution
The subroutine exact_sedov computes the self-similar Sedov solution for a blast wave.
The subroutine exact_toystar1D computes the exact solutions for the ‘Toy
Stars’ described in ???. The system is one dimensional with velocity v, density ρ, and pressure
P. The acceleration equation is
| = − |
|
| − Ω2 x, (25) |
We assume the equation of state is
| P = K ργ, (26) |
The exact solutions provided assume the equations are scaled such that Ω2 = 1.
The static structure is given by
| ρ= 1− x2, (27) |
The linear solution for the velocity is given by
| v = 0.05 Cs Gn(x) cosω t ) (28) |
density is
| ρ = ρ + η (29) |
where
| η = 0.1 Cs ω Pn+1(x) sin(ω t)) (30) |
In this case the velocity is given by
| v = A(t) x, (31) |
whilst the density solution is
| ργ −1 = H(t) − C(t) x2. (32) |
where the parameters A, H and C are determined by solving the ordinary differential equations
|
The relation
| A2 = −1 − |
| + kC |
| , (36) |
is used to check the quality of the solution of the differential equations by evaluating the constant k (which should remain close to its initial value).
These are some tabulated solutions for specific MHD shock tube problems at a given time taken from the tables given in ??? and ???.
The subroutine exact_hrho simply plots the relation between smoothing length and density, i.e.,
| h = hfact | ⎛ ⎜ ⎜ ⎝ |
| ⎞ ⎟ ⎟ ⎠ |
| (37) |
where ν is the number of spatial dimensions. The parameter hfact is output by the code into the header of each timestep. For particles of different masses, a different curve is plotted for each different mass value.