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

Notebooks · posts/upwind-advection-smears-by-its-modified-equation

Upwind advection smears the pulse by its modified equation

First-order upwind carries a Gaussian pulse once around a periodic domain at Courant number . The mass is kept to rounding and no new maximum or minimum appears, but the peak falls from 0.9975 to 0.5767. The scheme's modified equation adds a diffusion term with , which predicts the fall to and predicts the pulse's variance growth, , exactly.

The advection equation moves any shape at speed without changing it. On the unit interval with periodic ends, after a time the exact solution is the initial condition again, so everything a scheme does to the pulse in one transit is error.

The grid has cells of width , with . The pulse is sampled at the cell centers. A separate numpy implementation, posts/refs/upwind-advection-smears-by-its-modified-equation.py, computes the same numbers (output beside it).

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 23–38

The scheme

Upwind takes the space difference from the side the wave comes from. With that is the left, and with the Courant number the update is

The second form is the useful one. For each new value is a weighted average of two old ones with nonnegative weights, so it lies between them: no new maximum and no new minimum can appear, and a nonnegative pulse stays nonnegative. Summing over the periodic grid, the terms cancel in pairs, so (the mass) is unchanged by each step, up to rounding.

One transit takes steps at . roll(u, 1) brings each cell's left neighbor to it, with the last cell wrapping to the first.

[2]lines 59–113

The modified equation

The scheme solves some equation more accurately than it solves , and finding that equation explains the smearing. Expand and in Taylor series about , substitute into the update, and use the equation itself to trade for . What is left, to the first order in , is the modified equation

Upwind is a diffusion scheme in disguise, with a diffusion coefficient that vanishes as and also at , where the update is an exact shift by one cell.

Diffusion spreads a Gaussian and keeps it Gaussian. Its variance (the second moment of , treated as a distribution in ) grows by , and since the mass is fixed the peak falls as one over the width. The pulse has variance , and with and the variance becomes , three times larger. The predicted peak is .

For the variance the prediction is exact, not just first order. The update moves a fraction of each cell's content one cell to the right. That is one step of a random walk, which adds cells squared to the variance; steps add . The peak prediction is only first order, because the random walk's pulse is not an exact Gaussian. The measured peak is 0.57671. The Gaussian of the modified equation, read at the cell center nearest the peak (), is 0.57687. They differ by .

The variance is taken with each cell's displacement from wrapped into , so the periodic grid has no seam in the middle of the pulse.

[3]lines 151–210

Other Courant numbers

The last cell repeats the transit at six Courant numbers, each chosen so a transit is a whole number of steps. The variance growth sits on the line at every one, to rounding. The peaks follow to within 0.25%. The largest gap is at , where there is no diffusion and the peak is the initial sample 0.9975, not 1. A larger time step means less smearing, up to ; past it the scheme is unstable.

[4]lines 224–272