Modes of cavities, drums and waveguides

On a domain with a boundary an eigenproblem asks for the modes of the domain: the tones of a room, of a drum, of a ball, the waves that a pipe carries. This page shows the modes of boxes, of round domains and of shapes in the plane, and the potentials that may stand in the equation.

import numpy as np
import sympy as sp
import pdemagic as pm
from pdemagic import curves

x, y, z = sp.symbols("x y z", real=True)
E = sp.Symbol("E")

The modes of a box

The problem is stated as any eigenproblem, with eigenvalue=, and each face has its condition, as always. The condition gives zero: of the value, of the slope, or of a mix of both. A room with hard walls, where the pressure has no slope along the normal:

p = sp.Function("p")(x, y, z)

room = pm.Problem(
    sp.Eq(-pm.laplacian(p), E * p),
    domain=pm.Box({x: (0, 1), y: (0, 1), z: (0, 1)}),
    boundary=sp.Eq(pm.normal_derivative(p), 0),
    eigenvalue=(E, 4),
)
tones = pm.solve(room)
assert np.allclose(tones.eigenvalues, [0, np.pi**2, np.pi**2, np.pi**2], atol=1e-8)
assert tones.plan.method.kind == "collocation_modes"

The lowest mode is the constant. The next three share one eigenvalue, and are returned as three functions that are orthogonal to each other.

On a box the second derivatives have constant coefficients, \(-\sum_i a_i\,\partial_i^2\). The modes are then products of modes of the single axes, which are computed in milliseconds. A string and a plate are the same in one and two dimensions.

The modes of a ball

A round domain works the same way, with \(-a\nabla^2\) as the operator. A ball that is held on its surface has the squares of the zeros of the spherical Bessel functions, \(\pi\) once and 4.4934 three times:

r, theta, alpha = sp.symbols("r theta alpha", real=True)
v = sp.Function("v")(r, theta, alpha)

ball = pm.Problem(
    sp.Eq(-pm.laplacian(v), E * v),
    domain=pm.Ball(r, theta, alpha),
    boundary=sp.Eq(v, 0),
    eigenvalue=(E, 4),
)
exact = np.array([np.pi, 4.4934095, 4.4934095, 4.4934095]) ** 2
assert np.allclose(pm.solve(ball).eigenvalues, exact, atol=1e-6)

Disks, rings, shells and cylinders work the same way. The modes that turn around an axis come in pairs of one eigenvalue, and are returned as real functions: a cosine and a sine around the axis.

Hydrogen, and other potentials that separate

A potential may stand beside the derivatives where it leaves the modes products: in a disk, a ring, a ball or a shell a potential of the radius alone, and between walls a sum of potentials of the single coordinates.

That solves hydrogen, \(-\tfrac12\nabla^2\psi - \psi/r = E\,\psi\). Its potential has a singularity at the centre, which no uniform grid resolves, and in free space it is refused. In spherical coordinates the states are smooth functions of the radius. The ball must be large enough for them to have faded on its surface:

atom = pm.Problem(
    sp.Eq(-pm.laplacian(v) / 2 - v / r, E * v),
    domain=pm.Ball(r, theta, alpha, radius=40),
    boundary=sp.Eq(v, 0),
    eigenvalue=(E, 5),
)
levels = pm.solve(atom).eigenvalues
assert np.allclose(levels, [-1 / 2, -1 / 8, -1 / 8, -1 / 8, -1 / 8], atol=1e-10)

The second level has its four states, 2s and three 2p. A state of the level \(n\) reaches about \(2n^2\) and fades slowly beyond: with the radius 40 the first two levels are right to twelve digits and the third to six. The surface is a wall, and a state that reaches it is squeezed.

Between walls the oscillator is of this kind: its potential, \((x^2 + y^2)/2\), is a sum over the axes.

A potential that couples the coordinates, such as \(xy\), has modes that are no products. So have a medium, a density that varies, a mixed derivative, and a plate. You state such a problem in the same way. Its modes are found from the stationary solve of the operator, which takes a second where sorting takes milliseconds:

x, y = sp.symbols("x y", real=True)
v = sp.Function("v")(x, y)
tilted = pm.Problem(
    sp.Eq(-pm.laplacian(v) + 50 * x * y * v, E * v),
    domain=pm.Box({x: (0, 1), y: (0, 1)}),
    boundary=sp.Eq(v, 0),
    eigenvalue=(E, 2),
)
lowest = pm.solve(tilted)
assert lowest.plan.method.kind == "collocation_inverse_modes"
assert np.allclose(lowest.eigenvalues, [30.97386281, 59.7368098], atol=1e-6)

The modes of a shape

On a shape in the plane the modes are those of a membrane that is fixed along its edge, of the cross section of a waveguide, of a basin in which water sloshes. Each piece of the boundary has its condition: the value, the slope along the normal, or a mix of both, \(a\,w + b\,\partial w/\partial n = 0\) with real \(a\) and \(b\). A round drum sounds at the squares of the zeros of Bessel functions:

w = sp.Function("w")(x, y)

drum = pm.Problem(
    sp.Eq(-pm.laplacian(w), E * w),
    domain=pm.Region(x, y, curves.Circle((0, 0), 1)),
    boundary=sp.Eq(w, 0),
    eigenvalue=(E, 3),
)
skin = pm.solve(drum)

assert np.allclose(skin.eigenvalues, [5.7831860, 14.6819706, 14.6819706], atol=1e-6)
assert skin.plan.method.kind == "element_modes"
skin.plot(state=1)
The figure that the example above draws. The figure that the example above draws.

The operator may have a medium and a potential, \(-\nabla\cdot(\varepsilon\nabla w) + V w\), and the eigenvalue a density beside it, \(E\,\rho(\mathbf{x})\,w\): a skin that is heavier on one side. Each mode has the integral of its square over the shape equal to one.

The shape may have holes, and corners. At a corner that points inwards a mode has a singularity, and the mesh shrinks towards the corner as it does for a stationary problem. The lowest mode of the L-shape, which no formula gives, comes out to nine digits:

corners = [(0, 0), (1, 0), (1, 1), (-1, 1), (-1, -1), (0, -1)]
bent = pm.Problem(
    sp.Eq(-pm.laplacian(w), E * w),
    domain=pm.Region(x, y, curves.Polygon(*corners)),
    boundary=sp.Eq(w, 0),
    eigenvalue=(E, 1),
)
assert abs(pm.solve(bent).eigenvalues[0] - 9.6397238440) < 1e-8

A waveguide

The waves that a hollow metal pipe carries are the modes of its cross section, of two kinds. In a TM wave the electric field along the pipe is a mode with the value zero on the wall. In a TE wave the magnetic field along the pipe is one with no slope along the normal. Each wave travels above its cutoff, the frequency \(c\sqrt{E}/2\pi\) for the eigenvalue \(E\) of its mode. So a waveguide is two eigenproblems:

pipe = pm.Box({x: (0, 2), y: (0, 1)})
h = sp.Function("h")(x, y)
e = sp.Function("e")(x, y)

te = pm.Problem(
    sp.Eq(-pm.laplacian(h), E * h),
    domain=pipe,
    boundary=sp.Eq(pm.normal_derivative(h), 0),
    eigenvalue=(E, 3),
)
tm = pm.Problem(
    sp.Eq(-pm.laplacian(e), E * e), domain=pipe, boundary=sp.Eq(e, 0), eigenvalue=(E, 1)
)

assert np.allclose(pm.solve(te).eigenvalues, [0, np.pi**2 / 4, np.pi**2], atol=1e-8)
assert np.isclose(pm.solve(tm).eigenvalues[0], 1.25 * np.pi**2)

The lowest mode without a slope is the constant, with the eigenvalue zero: it is no wave. The next is the wave that the pipe carries first, with the cutoff \(\pi/2\), half a wave across the wide side. The first TM wave follows at \(\pi\sqrt{1.25}\). A cross section that is no rectangle is a shape: the gallery has a pipe with a ridge.

What the planner chose

Between walls and on round domains the method is collocation_modes, or collocation_inverse_modes for modes that are no products. Both have nothing to set but the grid. On a shape it is element_modes, with the method.degree, the method.spacing and the method.layers of the elements, as for a stationary problem there. On a shape the eigenvalues are more accurate than the modes: their error is the square of that of the modes.

Not taken yet: a coefficient from an array between walls, a medium on a round domain, and a condition through which a wall feeds the modes of an operator whose modes are no products. The known limits list them all.

See also