Waves of one frequency¶
A wave that oscillates everywhere with one frequency obeys the Helmholtz equation, \(\nabla^2 u + k^2 u = -f\), with the wave number \(k\). This page says what its solution means in free space, in a medium, between walls and on a shape.
import numpy as np
import sympy as sp
import pdemagic as pm
from pdemagic import curves
x, y = sp.symbols("x y", real=True)
w = sp.Function("w")(x, y)
In free space: waves that go out¶
Two small sources in the plane, a little apart:
def spot(centre):
return sp.exp(-8 * ((x - centre) ** 2 + y**2))
antennas = pm.Problem(
sp.Eq(pm.laplacian(w) + 36 * w, -(spot(-1.5) + spot(1.5))),
domain=pm.FreeSpace(x, y),
)
waves = pm.solve(antennas)
assert waves[w].dtype == complex
waves.plot(part="real")
The waves of the two sources reinforce each other in some directions and cancel in others.
In free space this equation has many solutions. pdemagic returns the one
in which the sources send waves out and nothing comes in from infinity,
the radiation condition. That solution is complex: its magnitude is the
amplitude of the wave and its argument the phase. With the time
dependence exp(-i*omega*t), the real part of
waves[w] * exp(-i*omega*t) is the wave at the time t.
The planner leaves two wavelengths of room around the sources and gives every wavelength at least six grid points, so that the waves can be seen.
In a medium¶
Where waves travel more slowly, the wave number is larger. A lens is a region with a larger index of refraction \(n\), and the equation is \(\nabla^2 u + k^2 n^2 u = 0\). A wave that comes in from far away is not a source inside a box, so it is split off: the unknown is what the lens adds to the incoming wave, and the incoming wave becomes its source.
k = 4
denser = sp.Rational(3, 5) * sp.exp(-(x**2 + y**2) / 2) # n² − 1
incoming = sp.exp(sp.I * k * x)
lens = pm.Problem(
sp.Eq(pm.laplacian(w) + k**2 * (1 + denser) * w, -(k**2) * denser * incoming),
domain=pm.FreeSpace(x, y),
)
scattered = pm.solve(lens)
gx, gy = scattered.mesh()
total = scattered[w] + np.exp(1j * k * gx)
# Behind the lens the wave is stronger than it came in.
assert abs(total[(gx > 1) & (abs(gy) < 0.5)]).max() > 1.5
scattered.plot(part="real")
The plot shows what the lens adds: almost nothing in front of it, and a beam behind it. The index of refraction must settle to a constant away from the lens, and it must be smooth: an obstacle with a sharp surface is not handled. The equation is solved by an iteration, as every equation with coefficients that vary in free space.
Between walls¶
On a box or a round domain with boundary conditions the walls reflect the waves, and nothing is said about infinity. The solution is real if everything given is real. A string that is held at one end and shaken at the other, with the wave number 7:
v = sp.Function("v")(x)
string = pm.Box({x: (0, 1)})
shaken = {(x, 0): sp.Eq(v, 0), (x, 1): sp.Eq(v, 1)}
swinging = pm.solve(
pm.Problem(sp.Eq(v.diff(x, 2) + 7**2 * v, 0), domain=string, boundary=shaken)
)
(xs,) = swinging.axes
assert abs(swinging[v] - np.sin(7 * xs) / np.sin(7)).max() < 1e-12
At some wave numbers the domain rings by itself: the string with fixed ends does at every multiple of \(\pi\). There the equation has no unique solution, and the problem is refused:
resonant = pm.Problem(
sp.Eq(v.diff(x, 2) + (2 * sp.pi) ** 2 * v, 0), domain=string, boundary=shaken
)
try:
pm.solve(resonant)
except pm.InvalidProblemError as error:
message = str(error)
assert "The box resonates at this equation" in message
Close to such a wave number the solution exists and is large. The wave numbers themselves are the modes of the domain, which an eigenproblem finds.
A wall can also let waves out. The condition \(\partial u/\partial n - i k u = 0\) does that for a wave that meets the wall head-on, and makes the solution complex: Boundary conditions has the example.
On a shape¶
A region of the plane takes the same equation, with a condition on each piece of its boundary. A hall with an elliptic wall that reflects sound, and a loudspeaker near one end:
k = 4
hall = pm.Region(x, y, curves.Ellipse((0, 0), (1.5, 1)))
speaker = sp.exp(-12 * ((x + 1) ** 2 + y**2))
sound = pm.Problem(
sp.Eq(pm.laplacian(w) + k**2 * w, -speaker),
domain=hall,
boundary=sp.Eq(pm.normal_derivative(w), 0),
)
standing = pm.solve(sound)
assert standing[w].dtype == float
standing.plot()
A shape resonates as a box does, and is refused there in the same way.
With sp.Eq(pm.normal_derivative(w) - sp.I * k * w, 0) on a piece of the
boundary that piece is open, and the solution is complex. A medium works
on a shape as well: write the index of refraction into the equation.
What does not work yet¶
The Helmholtz equation in free space in more than three dimensions.
A wave number that is complex far away.
Scattering by bodies with sharp surfaces. An obstacle must be smooth on the scale of the grid.
An incoming wave cannot be stated by itself: a scattering problem is written for the scattered wave, as above.
A wall that lets waves out in a problem in time.
See also¶
Reference: what is solved in free space, on boxes and on shapes.
Gallery: two antennas, waves through a lens, a room with an open window, a harbour.
Methods: the Helmholtz equation in free space and equations whose coefficients vary in space.
Complex unknowns, and modes of cavities, drums and waveguides.
Recipe: a wall that lets waves out.