Cylinder Cavity
Note
For general information about finite element discretization, basis functions, mesh parameters, polynomial degrees, boundary conditions, and matrix/operator dimensions, see Overview.
This script solves eigenvalue problems for a cylindrical cavity.
The script is located at scripts/interactive/cylinder_cavity.py.
Problem Statement
The script computes electromagnetic eigenmodes (TE and TM modes) for a cylindrical cavity. The eigenvalue problem is:
with the constraint:
and boundary conditions:
where: - \(\mathbf{E}: \Omega \to \mathbb{R}^3\) is the electric field (1-form) - \(k^2\) is the eigenvalue (square of the wavenumber) - \(\Omega\) is a cylinder of radius \(a=1\) and height \(h=1\) - \(\mathbf{n}\) is the outward unit normal vector on the boundary
Boundary Conditions
Radial direction: Clamped (perfect conductor boundary \(\mathbf{E} \times \mathbf{n} = 0\))
Azimuthal direction: Periodic (rotational symmetry)
Axial direction: Periodic (periodic boundary conditions)
Analytical Solutions
For TE modes (transverse electric):
where \(j'_{nm}\) is the \(m\)-th positive root of \(J'_n(x) = 0\) (derivative of Bessel function).
For TM modes (transverse magnetic):
where \(j_{nm}\) is the \(m\)-th positive root of \(J_n(x) = 0\) (Bessel function).
The script demonstrates:
Computing eigenvalues and eigenmodes for cylindrical cavities
Visualizing eigenmodes
Analyzing cavity resonances
Usage:
python scripts/interactive/cylinder_cavity.py
The script generates plots showing eigenvalues and eigenmode visualizations.
Finite Element Discretization
The electric field is represented as a 1-form:
where \(N_1\) is the number of 1-form DOFs.
Matrix and Operator Dimensions
The 1-form mass matrix \(M_1 \in \mathbb{R}^{N_1 \times N_1}\) and 0-form mass matrix \(M_0 \in \mathbb{R}^{N_0 \times N_0}\) are used.
The double curl operator is constructed as:
This represents the curl-curl operator \(\nabla \times (\nabla \times)\) for electromagnetic modes.
Generalized Eigenvalue Problem
The eigenvalue problem is formulated as a generalized eigenvalue problem:
where:
The block structure enforces the constraint \(\nabla \cdot \mathbf{E} = 0\) (divergence-free condition).
Code Walkthrough
Block 1: Imports and Configuration (lines 1-43)
Imports JAX, NumPy, SciPy, Matplotlib, and MRX modules. Enables 64-bit precision and creates output directory. Sets up parameters for cylinder geometry (radius \(a=1\), height \(h=1\)) and discretization (\(ns=(15,15,1)\), \(ps=(3,3,0)\)).
Block 2: DeRham Sequence Setup (lines 45-67)
Creates DeRham sequence with boundary conditions (clamped in radial direction, periodic in azimuthal and axial), assembles mass matrices \(M_0\) (0-forms) and \(M_1\) (1-forms), assembles gradient operator \(D_0\) (strong gradient), and constructs double curl matrix:
Builds block matrices \(Q\) and \(P\) for generalized eigenvalue problem:
Block 3: Eigenvalue Computation (lines 69-83)
Solves generalized eigenvalue problem:
using SciPy: - Extracts real parts of eigenvalues and eigenvectors - Filters out infinite eigenvalues - Sorts eigenvalues in ascending order
Block 4: Analytical Comparison (lines 88-225)
Defines function calculate_cylindrical_periodic_TE_TM_eigenvalues() that computes
analytical eigenvalues for comparison.
For TE modes:
where \(j'_{nm}\) is the \(m\)-th positive root of \(J'_n(x) = 0\).
For TM modes:
where \(j_{nm}\) is the \(m\)-th positive root of \(J_n(x) = 0\).
The function accounts for mode multiplicities (azimuthal and axial symmetries) and computes eigenvalues for modes \(n \in [0,7]\), \(m \in [1,7]\), \(k_{\mathrm{axial}} \in [0]\).
Block 5: Visualization (lines 227-378)
Generates plots:
Eigenvalue comparison: Computed vs. analytical eigenvalues (first 40 modes)
Eigenmode visualization: Plots norm of pushforward of first 25 eigenvectors on a 2D cross-section (\(z=0.5\)) using contour plots
Uses
plot_eigenvectors_grid()function to create a grid of eigenmode plots
The script validates the numerical method by comparing computed eigenvalues with analytical solutions for cylindrical cavity modes, demonstrating the accuracy of the finite element discretization.