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 whose speed depends on wavelength (dispersive)

The Korteweg-de Vries equation

Method
Fourier pseudo-spectral in space; Strang splitting in time, with the dispersive step exact
Checked
a soliton against its exact solution: shape, speed, conserved mass, and the measured order

Shallow-water waves, and the equation solitons were discovered in. Nonlinearity steepens a hump; third-order dispersion spreads it; and for exactly one family of shapes the two cancel: . Taller solitons are narrower and faster — the speed is twice the height.

is the hard part for finite differences: an explicit scheme needs . In Fourier space it is trivial — each mode just turns, , exactly, for any . So split: half a dispersive step, a full step of the nonlinear part (spectral derivative, fourth-order Runge-Kutta), half a dispersive step.

The Nyquist mode is zeroed in the derivative. On an even grid it has no well-defined sign, and leaving it in makes the derivative of a real field complex.

What the run shows

A soliton of speed 2: it moves, and nothing else happens
t = 0t = 2, computedt = 2, exact
00.51.0−20−10010xu
Two solitons collide and pass through each other
t
x
41 × 128 grid
  • the soliton keeps its shape
  • it moves at c, twice its height
  • mass is conserved to rounding: a spectral derivative has exactly zero mean
  • the splitting is second order
  • after the collision the two solitons are Hirota's exact solution, phase shifts included
shape_error
3.89994e-06
mass_drift
5.55112e-16
speed
2
order
2.01469
collision_error
0.00031525

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

The program

163 lines, 6 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.

soliton
The soliton of speed C at time t.
nonlinear_rate
The nonlinear rate, -3 d/dx (u^2), with the derivative taken in Fourier space.
disperse
The dispersive step, exact: every mode turns by exp(i k^3 dt).
march
March the soliton to t_end in `steps` Strang steps.
center
Where the hump is: its center of mass. A sum over a periodic grid is spectrally accurate for a pulse that has decayed before the edges, so this locates it far below the spacing (a parabola through the top three points is off by 2e-4 here, and no time step fixes that).
two_solitons
Hirota's exact two-soliton solution on the grid X at time t.
Viv [1]

Open in the workbench The atlas Download kdv_soliton.viv