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)

The advection equation

Method
upwind (first order) and Lax-Wendroff (second order), on a periodic grid
Checked
that one trip around the ring returns the pulse to where it started; and both measured orders

The simplest wave equation: whatever shape you start with slides along at speed , unchanged. On a ring of length 1 it is back where it began after a time , which makes the exact answer the initial condition itself.

It is also the equation that teaches humility about finite differences. Upwind takes the difference from the side the wave is coming from; it is stable for and first order, and what it does to the error is diffuse it: the pulse spreads and sinks. Lax-Wendroff adds the second-order term of the Taylor series in time, , and is second order: the pulse keeps its height and grows a small oscillating wake instead.

Periodic boundaries are where roll earns its place: a neighbor is a circular shift, and each scheme is one line.

What the run shows

One trip around the ring
exact (the starting pulse)upwind: it diffusesLax-Wendroff: it keeps its height
00.51.000.20.40.60.8xu
  • upwind is first order (measured between n = 1600 and 3200: it gets there slowly)
  • Lax-Wendroff is second order
  • at the same resolution Lax-Wendroff is more than ten times closer
order_upwind
0.972834
order_lw
1.99629
up_coarse
0.0332305
lw2
0.00107067

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

The program

73 lines, 4 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.

pulse
A smooth pulse on the ring.
upwind_lap
Carry the pulse once around the ring with the upwind scheme; return what comes back.
lax_wendroff_lap
The same trip with Lax-Wendroff.
lap_error
L2 distance between what came back and what set out.
Viv [1]

Open in the workbench The atlas Download advection_1d.viv