NAG Library Routine Document

d03pwf (dim1_parab_euler_hll)


    1  Purpose
    7  Accuracy


d03pwf calculates a numerical flux function using a modified HLL (Harten–Lax–van Leer) Approximate Riemann Solver for the Euler equations in conservative form. It is designed primarily for use with the upwind discretization schemes d03pff, d03plf or d03psf, but may also be applicable to other conservative upwind schemes requiring numerical flux functions.


Fortran Interface
Subroutine d03pwf ( uleft, uright, gamma, flux, ifail)
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: uleft(3), uright(3), gamma
Real (Kind=nag_wp), Intent (Out):: flux(3)
C Header Interface
#include nagmk26.h
void  d03pwf_ (const double uleft[], const double uright[], const double *gamma, double flux[], Integer *ifail)


d03pwf calculates a numerical flux function at a single spatial point using a modified HLL (Harten–Lax–van Leer) Approximate Riemann Solver (see Toro (1992), Toro (1996) and Toro et al. (1994)) for the Euler equations (for a perfect gas) in conservative form. You must supply the left and right solution values at the point where the numerical flux is required, i.e., the initial left and right states of the Riemann problem defined below. In d03pff, d03plf and d03psf, the left and right solution values are derived automatically from the solution values at adjacent spatial points and supplied to the subroutine argument numflx from which you may call d03pwf.
The Euler equations for a perfect gas in conservative form are:
U t + F x =0, (1)
U= ρ m e   and  F= m m2ρ+γ-1 e-m22 ρ meρ+mργ-1 e-m22ρ , (2)
where ρ is the density, m is the momentum, e is the specific total energy and γ is the (constant) ratio of specific heats. The pressure p is given by
p=γ-1 e-ρu22 , (3)
where u=m/ρ is the velocity.
The routine calculates an approximation to the numerical flux function FUL,UR=FU*UL,UR, where U=UL and U=UR are the left and right solution values, and U*UL,UR is the intermediate state ω0 arising from the similarity solution Uy,t=ωy/t of the Riemann problem defined by
U t + F y =0, (4)
with U and F as in (2), and initial piecewise constant values U=UL for y<0 and U=UR for y>0. The spatial domain is -<y<, where y=0 is the point at which the numerical flux is required.


Toro E F (1992) The weighted average flux method applied to the Euler equations Phil. Trans. R. Soc. Lond. A341 499–530
Toro E F (1996) Riemann Solvers and Upwind Methods for Fluid Dynamics Springer–Verlag
Toro E F, Spruce M and Spears W (1994) Restoration of the contact surface in the HLL Riemann solver J. Shock Waves 4 25–34


1:     uleft3 – Real (Kind=nag_wp) arrayInput
On entry: ulefti must contain the left value of the component Ui, for i=1,2,3. That is, uleft1 must contain the left value of ρ, uleft2 must contain the left value of m and uleft3 must contain the left value of e.
  • uleft10.0;
  • Left pressure, pl0.0, where pl is calculated using (3).
2:     uright3 – Real (Kind=nag_wp) arrayInput
On entry: urighti must contain the right value of the component Ui, for i=1,2,3. That is, uright1 must contain the right value of ρ, uright2 must contain the right value of m and uright3 must contain the right value of e.
  • uright10.0;
  • Right pressure, pr0.0, where pr is calculated using (3).
3:     gamma – Real (Kind=nag_wp)Input
On entry: the ratio of specific heats, γ.
Constraint: gamma>0.0.
4:     flux3 – Real (Kind=nag_wp) arrayOutput
On exit: fluxi contains the numerical flux component F^i, for i=1,2,3.
5:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).
Note: if the left and/or right values of ρ or p (from (3)) are found to be negative, then the routine will terminate with an error exit (ifail=2). If the routine is being called from the numflx etc., then a soft fail option (ifail=1 or -1) is recommended so that a recalculation of the current time step can be forced using the numflx argument ires (see d03pff or d03plf).

Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry,gamma0.0.
On entry,the left and/or right density or derived pressure value is less than 0.0.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


d03pwf performs an exact calculation of the HLL (Harten–Lax–van Leer) numerical flux function, and so the result will be accurate to machine precision.

Parallelism and Performance

d03pwf is not thread safe and should not be called from a multithreaded user program. Please see Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
d03pwf is not threaded in any implementation.

Further Comments

d03pwf must only be used to calculate the numerical flux for the Euler equations in exactly the form given by (2), with ulefti and urighti containing the left and right values of ρ,m and e, for i=1,2,3, respectively. The time taken is independent of the input arguments.


This example uses d03plf and d03pwf to solve the Euler equations in the domain 0x1 for 0<t0.035 with initial conditions for the primitive variables ρx,t, ux,t and px,t given by
ρx,0=5.99924, ux,0=-19.5975, px,0=460.894,   for ​x<0.5, ρx,0=5.99242, ux,0=-6.19633, px,0=046.095,   for ​x>0.5.  
This test problem is taken from Toro (1996) and its solution represents the collision of two strong shocks travelling in opposite directions, consisting of a left facing shock (travelling slowly to the right), a right travelling contact discontinuity and a right travelling shock wave. There is an exact solution to this problem (see Toro (1996)) but the calculation is lengthy and has therefore been omitted.

Program Text

Program Text (d03pwfe.f90)

Program Data

Program Data (d03pwfe.d)

Program Results

Program Results (d03pwfe.r)

GnuplotProduced by GNUPLOT 5.0 patchlevel 0 0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0 0.2 0.4 0.6 0.8 1 5 10 15 20 25 30 35 Example Program Euler Equation Solution Showing Collision of Two Strong Shocks DENSITY u(x,t) gnuplot_plot_1