Solution (source code)

= Solution

For one-dimensional homentropic flow,
$$
\rho_t+u\rho_x+\rho u_x=0,
\qquad
u_t+uu_x+\frac1\rho p_x=0,
$$
and $dp=c^2d\rho$. For a perfect gas, $dc/c=(\gamma-1)d\rho/(2\rho)$. Combining the two equations therefore shows that the <Riemann invariant>[Riemann invariants]
$$
\boxed{R_\pm=u\pm\frac{2c}{\gamma-1}}
$$
satisfy
$$
\boxed{
\left(\partial_t+(u\pm c)\partial_x\right)R_\pm=0}.
$$
Their characteristic curves are parametrized by
$$
\boxed{
\frac{dx_\pm}{dt}=u(x_\pm(t),t)\pm c(x_\pm(t),t)},
$$
and $R_\pm$ is constant along the corresponding curve until characteristic intersection creates a shock.