first-order-wave-equation
Nothing too interesting here. Just wasting time trying to figure out what it means to carry things all the way through and actually use scijs. So this repo implements a simple simulation of the first-order wave equation,
The equation permits a very simple solution,
That is, any smooth function simply translates ("is advected") to the right. The Courant-Friedrichs-Lewy (CFL) number is defined by
and measures how far the solution moves in a single time step relative to the grid spacing. CFL = 1 indicates the solution moves a full grid step in each time step and defines a baseline limit of stability, though the individual methods differ.
Demos
The demos below should show a wave traveling uniformly to the right. The extent to which the high-frequency waves move more slowly than the low-frequency waves is error calledd dispersion. The tendency for the high-frequency waves to get damped out is error called dissipation. The most accurate method is RK4 + Spectral.
- Euler, Upwind, CFL = 0.2 (dissipative)
- Euler, Downwind, CFL = 0.2 (unstable)
- Euler, Second order central, CFL = 0.2 (unstable)
- Midpoint, Second order central, CFL = 0.2 (dispersive)
- RK4, Sixth-order compact, CFL = 0.2 (stable)
- RK4, Eigth-order compact, CFL = 0.2 (dissipative)
- RK4, Spectral, CFL = 0.2 (exact wavenumber resolution)
- RK4, Spectral, CFL = 0.5 (exact wavenumber resolution; dissipative?)
Methods
This repo implements solutions using the following methods in time:
- First order Euler integration
- Second order midpoint integration
- Fourth order RK-4 integration
and in space:
- Explicit first order upwind finite difference
- Explicit first order downwind finite difference (always unstable)
- Explicit central second order finite difference
- Implicit sixth order compact scheme [1]
- Implicit eighth order compact scheme [1]
- Spectral (= FFT), resolves wavenumber exactly)
As a brief aside, compact schemes are similar to more common explicit finite differences, except they achieve a higher order of accuracy for a smaller stencil by solving for all derivatives simultaneously. The general form is [1]
This is a tridiagonal system that can be solved periodically to avoid dealing with boundary conditions.
References
Lele, S. K. (1992). Compact Finite Difference Schemes with Spectral-like Resolution. Journal of Computational Physics, 103, 16-42.
License
© 2016 Ricky Reusser. MIT License.