Vibrations of a Circular Drum¶
In this notebook we find and visualize the vibrational modes of a circular drum (membrane) by solving the eigenvalue problem of the 2D Laplacian on a disk using numgrids.
Physics Background¶
The transverse displacement \(u(r, \varphi, t)\) of an ideal circular membrane satisfies the wave equation
where \(c\) is the wave speed (determined by the tension and surface density of the membrane).
Separating variables as \(u(r, \varphi, t) = U(r, \varphi)\, T(t)\) leads to the Helmholtz eigenvalue problem for the spatial part:
with the Dirichlet boundary condition \(U = 0\) on the rim of the drum at \(r = 1\) (the membrane is clamped at its edge).
Analytical solution¶
The eigenvalues are \(\lambda_{mn} = (j_{mn})^2\), where \(j_{mn}\) is the \(n\)-th positive zero of the \(m\)-th Bessel function \(J_m\). The corresponding eigenmodes are:
The eigenfrequencies of vibration are \(\omega_{mn} = c\,\sqrt{\lambda_{mn}} = c\, j_{mn}\). For simplicity we set \(c = 1\) and work with \(\sqrt{\lambda}\) directly.
[1]:
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import jn_zeros
from numgrids import *
Grid Setup¶
PolarGrid provides the polar coordinates \((r, \varphi)\) including the metric, so we never have to write down the polar form of the Laplacian ourselves.
Radial axis –
radial(30, 1.0)covers the full disk including its center. The points are the positive half of Chebyshev nodes on the diameter \([-1, 1]\), so no point sits on the singular origin, and radial derivatives are computed across the center using that \((-r, \varphi)\) is the point \((r, \varphi + \pi)\). This is spectrally accurate and needs no boundary condition at the center.Angular axis – periodic spacing on \([0, 2\pi)\) with FFT-based spectral differentiation.
The axes are automatically named r and phi.
[2]:
grid = PolarGrid(radial(30, 1.0), periodic(40))
print(grid)
print("boundary faces:", list(grid.faces)) # only the rim
PolarGrid(shape=(30, 40), ndims=2, axes=[
RadialAxis(num_points=30, low=0.0, high=1.0, periodic=False, name='r'),
EquidistantAxis(num_points=40, low=0.0, high=6.283185307179586, periodic=True, name='phi')
])
boundary faces: ['0_high']
Solving the Eigenvalue Problem¶
The Laplacian is available as a sparse Operator. We solve \(-\nabla^2 U = \lambda U\) with \(U = 0\) on the rim, i.e. on the face "r_high". eig returns the eigenvalues with the smallest magnitude, sorted, together with the eigenmodes as arrays of grid shape. Because Dirichlet points are eliminated internally, there are no spurious eigenvalues to filter out.
[3]:
n_modes = 9
lambdas, modes = (-grid.laplacian_operator()).eig(k=n_modes, bcs={"r_high": 0})
for i, lam in enumerate(lambdas):
print(f"mode {i + 1}: lambda = {lam:9.4f}, sqrt(lambda) = {np.sqrt(lam):.6f}")
mode 1: lambda = 5.7832, sqrt(lambda) = 2.404826
mode 2: lambda = 14.6820, sqrt(lambda) = 3.831706
mode 3: lambda = 14.6820, sqrt(lambda) = 3.831706
mode 4: lambda = 26.3746, sqrt(lambda) = 5.135622
mode 5: lambda = 26.3746, sqrt(lambda) = 5.135622
mode 6: lambda = 30.4713, sqrt(lambda) = 5.520078
mode 7: lambda = 40.7065, sqrt(lambda) = 6.380162
mode 8: lambda = 40.7065, sqrt(lambda) = 6.380162
mode 9: lambda = 49.2185, sqrt(lambda) = 7.015587
Drum Mode Gallery¶
grid.plot draws fields on a PolarGrid directly on the disk in Cartesian coordinates (and closes the periodic direction seamlessly).
[4]:
fig, axes = plt.subplots(3, 3, figsize=(14, 14))
fig.suptitle("Vibrational Modes of a Circular Drum", fontsize=18)
theta = np.linspace(0, 2 * np.pi, 200)
for i, (ax, lam, mode) in enumerate(zip(axes.flat, lambdas, modes)):
mode = mode / np.abs(mode).max()
grid.plot(mode, ax=ax, colorbar=False, cmap="RdBu_r", vmin=-1, vmax=1)
ax.plot(np.cos(theta), np.sin(theta), "k-", linewidth=1.5) # the rim
ax.set_xlim(-1.15, 1.15)
ax.set_ylim(-1.15, 1.15)
ax.set_title(f"Mode {i + 1}\n$\\sqrt{{\\lambda}}$ = {np.sqrt(lam):.3f}", fontsize=12)
plt.tight_layout(rect=(0, 0, 1, 0.97))
plt.show()
Comparison with Analytical Bessel Zeros¶
The exact eigenfrequencies are the Bessel zeros \(j_{mn}\). Modes with \(m > 0\) are doubly degenerate (\(\cos m\varphi\) and \(\sin m\varphi\)), so we list each of them twice.
[5]:
analytical = []
for m in range(7):
for n, z in enumerate(jn_zeros(m, 4), start=1):
analytical += [(z, m, n)] * (1 if m == 0 else 2)
analytical.sort()
print(f"{'Mode':>5s} {'(m, n)':>7s} {'Analytical':>12s} {'Numerical':>12s} {'Rel. Error':>11s}")
print("-" * 55)
for i, (lam, (z, m, n)) in enumerate(zip(lambdas, analytical)):
print(f"{i + 1:5d} ({m}, {n}) {z:12.8f} {np.sqrt(lam):12.8f} {abs(np.sqrt(lam) - z) / z:11.2e}")
Mode (m, n) Analytical Numerical Rel. Error
-------------------------------------------------------
1 (0, 1) 2.40482556 2.40482556 3.45e-14
2 (1, 1) 3.83170597 3.83170597 9.62e-15
3 (1, 1) 3.83170597 3.83170597 9.62e-15
4 (2, 1) 5.13562230 5.13562230 5.19e-16
5 (2, 1) 5.13562230 5.13562230 5.19e-16
6 (0, 2) 5.52007811 5.52007811 1.54e-14
7 (3, 1) 6.38016190 6.38016190 2.37e-15
8 (3, 1) 6.38016190 6.38016190 2.37e-15
9 (1, 2) 7.01558667 7.01558667 1.77e-15
For reference, the lowest Bessel zeros are:
Mode \((m,n)\) |
\(j_{mn}\) |
\(\lambda_{mn} = j_{mn}^2\) |
|---|---|---|
\((0,1)\) |
2.4048 |
5.7831 |
\((1,1)\) |
3.8317 |
14.682 |
\((2,1)\) |
5.1356 |
26.375 |
\((0,2)\) |
5.5201 |
30.471 |
\((3,1)\) |
6.3802 |
40.706 |
\((1,2)\) |
7.0156 |
49.218 |
Radial Profiles¶
The axisymmetric modes (\(m = 0\)) should follow \(J_0(j_{0n} r)\). We compare the numerical radial profile of the first mode – interpolated along a ray at \(\varphi = 0\), through the center, with spectral interpolation – with the Bessel function.
[6]:
from scipy.special import j0
r_line = np.linspace(0.0, 1.0, 200)
ray = np.column_stack([r_line, np.zeros_like(r_line)]) # points (r, phi = 0)
profile = grid.interpolate(modes[0], ray, method="spectral")
profile /= profile[0]
exact = j0(jn_zeros(0, 1)[0] * r_line)
exact /= exact[0]
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(r_line, exact, "k-", linewidth=2, label="$J_0(j_{01} r)$")
ax.plot(r_line[::10], profile[::10], "o", color="C3", label="numerical mode 1")
ax.set_xlabel("$r$")
ax.legend()
ax.grid(True, alpha=0.3)
plt.show()
print(f"max deviation: {np.abs(profile - exact).max():.2e}")
max deviation: 1.68e-13
Striking the Drum¶
Because the full-disk discretization has a real, negative spectrum, the wave equation can be integrated in time directly. We strike the drum off-center with a Gaussian bump and let it ring. evolve integrates the system \(\partial_t u = v\), \(\partial_t v = \nabla^2 u\) with the rim clamped (bcs=0).
[7]:
X, Y = grid.cartesian_coords
u0 = np.exp(-25 * ((X - 0.35)**2 + Y**2)) * (1 - X**2 - Y**2)
times = np.linspace(0, 1.5, 6)
result = evolve(grid, lambda t, u, v: (v, grid.laplacian(u)), (u0, np.zeros_like(u0)),
t_span=(0, times[-1]), t_eval=times, bcs=0, rtol=1e-8, atol=1e-10)
u, v = result.u
fig, axes = plt.subplots(1, 6, figsize=(20, 3.6))
vmax = np.abs(u).max()
for ax, t, ut in zip(axes, result.t, u):
grid.plot(ut, ax=ax, colorbar=False, cmap="RdBu_r", vmin=-vmax, vmax=vmax)
ax.set_title(f"t = {t:.1f}")
ax.set_axis_off()
plt.show()
The wave passes straight through the center of the drum. Energy \(E = \frac{1}{2}\int (v^2 + |\nabla u|^2)\, dA\) is conserved, which confirms that the scheme is stable:
[8]:
def energy(u, v):
gr, gphi = grid.gradient(u)
return 0.5 * grid.integrate(v**2 + gr**2 + gphi**2)
E = np.array([energy(ut, vt) for ut, vt in zip(u, v)])
print("relative energy change:", np.round(E / E[0] - 1, 8))
relative energy change: [0. 0. 0. 0. 0. 0.]
A Drum That Sounds Like a Hemisphere¶
A real membrane need not be uniform. With a surface density \(\rho(r, \varphi)\) the modes satisfy the generalized eigenvalue problem
which eig solves when we pass the density as M.
A beautiful special case: the density \(\rho = 4 / (1 + r^2)^2\) is the area element of the stereographic projection of a sphere onto the plane. The unit disk is then the image of a hemisphere, the clamped rim is the equator, and the “drum” vibrates like a hemisphere with a fixed equator. Its eigenvalues are those of the spherical harmonics \(Y_l^m\) that vanish on the equator (\(l + m\) odd): \(\lambda = l(l+1) = 2, 6, 12, 20, \dots\), with \(l\) modes for each \(l\).
[9]:
R, PHI = grid.meshed_coords
rho = 4 / (1 + R**2) ** 2
lambdas_h, modes_h = (-grid.laplacian_operator()).eig(k=10, bcs=0, M=rho)
exact = [l * (l + 1) for l in range(1, 5) for _ in range(l)]
for lam, ex in zip(lambdas_h, exact):
print(f"lambda = {lam:.10f} exact: {ex}")
lambda = 2.0000000000 exact: 2
lambda = 6.0000000000 exact: 6
lambda = 6.0000000000 exact: 6
lambda = 12.0000000000 exact: 12
lambda = 12.0000000000 exact: 12
lambda = 12.0000000000 exact: 12
lambda = 20.0000000000 exact: 20
lambda = 20.0000000000 exact: 20
lambda = 20.0000000000 exact: 20
lambda = 20.0000000000 exact: 20
[10]:
fig, axes = plt.subplots(2, 5, figsize=(15, 7.2))
fig.suptitle(r"Modes of a membrane with density $\rho = 4/(1+r^2)^2$", fontsize=15)
for ax, lam, mode in zip(axes.flat, lambdas_h, modes_h):
mode = mode / np.abs(mode).max()
grid.plot(mode, ax=ax, colorbar=False, cmap="RdBu_r", vmin=-1, vmax=1)
ax.plot(np.cos(theta), np.sin(theta), "k-", linewidth=1.5)
ax.set_title(rf"$\lambda = {lam:.4f}$", fontsize=12)
ax.set_aspect("equal")
ax.axis("off")
plt.tight_layout(h_pad=2.5)
plt.show()
The membrane is four times heavier at the center than at the rim. Its modes are the spherical harmonics of the hemisphere, seen from above the pole: the rim is the equator. Degenerate modes come out as real, orthonormal functions, as for the uniform drum.
Summary¶
We computed the vibrational modes of a circular drum with three lines of numgrids code:
grid = PolarGrid(radial(30, 1.0), periodic(40))
L = grid.laplacian_operator()
lambdas, modes = (-L).eig(k=9, bcs=0)
PolarGridwith aradialaxis covers the full disk, including the center, without a coordinate singularity; the only boundary is the rim.eigsolves the eigenvalue problem free of spurious modes; the eigenfrequencies agree with the analytical Bessel zeros to about twelve digits on a modest \(30 \times 40\) grid.grid.plotshows the modes directly on the disk, and spectral interpolation reproduces \(J_0\) through the center.The same discretization integrates the wave equation stably in time, conserving energy.
With a mass density,
eig(..., M=rho)solves the generalized eigenvalue problem \(-\nabla^2 U = \lambda \rho U\). A density from stereographic projection turns the drum into a vibrating hemisphere with eigenvalues \(l(l+1)\).