This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

PDE solvers · Waves and transport (hyperbolic)

A shock and a rarefaction in inviscid Burgers' equation

Method
Godunov's method: the exact Riemann solution at every cell face
Checked
the shock speed, exact conservation, and the rarefaction fan u = x/t

Take the viscosity away and smooth data stops being enough: characteristics cross, the derivative blows up in finite time, and the solution continues as a shock. A finite difference of a discontinuity means nothing, so the method has to be built on the integral form instead — what flows into a cell minus what flows out.

Godunov's answer: at each face the two neighboring cells pose a Riemann problem, which for Burgers has a closed-form solution; use its flux. For that flux is .

The same two states, in opposite orders, give opposite behavior. is a shock, moving at . is a rarefaction: the jump opens into the fan . A scheme that gets the first right by conserving, and the second right by not inventing an expansion shock, has earned the name entropy-satisfying.

What the run shows

Two Riemann problems for Burgers' equation at t = 1.2
uL=1, uR=0: a shock at x=t/2uL=0, uR=1: a rarefaction, computedthe fan u = x/t, exact
00.51.0−0.500.51.01.5xu
  • conservation is exact: the mass is what flowed in, to rounding
  • so the shock sits at x = t/2, the Rankine-Hugoniot speed
  • the shock is captured in at most three cells, with no overshoot
  • the rarefaction opens into the fan u = x/t, not an expansion shock
mass
1.6
position
0.6
fan_error
0.0181747

Computed when this page was built, by the same interpreter that runs it in your browser: 4 of 4 tests, under 0.1 s. The numbers above are the program's show lines.

The program

85 lines, 2 functions. It is editable: change it and press Run (or ⌘/Ctrl + Enter). The tests at the bottom run too, so if your change breaks the solver, a test fails.

godunov_flux
Godunov's flux at every face between a cell and its right neighbor.
march
March n cells to t_end from a step (left state, right state) at x = 0.
Viv [1]

Open in the workbench The atlas Download burgers_shock.viv