There are three simple boundary conditions for wave equations:
Periodic (corresponding to the gl.REPEAT texture wrap mode).
The Dirichlet boundary condition
u(x) = c,
we use usually fixed c = 0 boundary values.
The Neumann boundary condition
u' = c.
For c = 0 it corresponds to the gl.CLAMP_TO_EDGE mode.
We can rewrite the wave equation
∂tt u - ∂xx u = 0,
as
(∂t +
∂x )(∂t - ∂x )u = 0.
Any functions f(x - t), g(x + t) satisfy the equations
(∂t + ∂x )f(x - t) = 0,
(∂t - ∂x )g(x + t) = 0 and therefore are solutions of the wave equation and correspond to
two waves moving in opposite directions.
To fulfill the second condition for a moving packet
(e.g. to the right on the Fig.1) one can send "negative"
packet in the opposite direction. Then we get u = 0
in the middle between them.
In a similar way we fulfill the third condition
∂x u = 0
if we send identical fictitious packet (see Fig.2).
ABC for waves
If we set at the right border point
(∂t + ∂x )u = 0,
then we get only outgoing 1D waves at the boundary (one should use
careful discretization to get stable algorithm).
Surprisingly very simple (but efficient) Liao's second-order ABC is given as:
ux+1, t+1 = 2 ux, t -
ux-1, t-1 .
They are used in the script above and in the
One slit diffraction.