Toroid 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 toroidal cavity.
The script is located at scripts/interactive/toroid_cavity.py.
Problem Statement
This script computes electromagnetic eigenmodes for a toroidal cavity (2D cross-section with periodic boundary in toroidal direction). 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 toroidal domain - \(\mathbf{n}\) is the outward unit normal vector on the boundary
Toroidal Geometry
The toroidal domain is parameterized by: - Minor radius: \(a=1\) - Major radius: \(R_0=2.1\) - Aspect ratio: \(\epsilon = a/R_0 \approx 0.476\)
The mapping from logical coordinates \((r, \chi, \zeta)\) to physical coordinates is:
Boundary Conditions
Radial direction: Clamped (perfect conductor boundary)
Poloidal direction: Periodic (rotational symmetry)
Toroidal direction: Constant (2D cross-section)
The script demonstrates:
Computing eigenvalues and eigenmodes for toroidal cavities
Visualizing eigenmodes
Analyzing cavity resonances
Usage:
python scripts/interactive/toroid_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}\) is used.
The double curl operator is constructed as:
This represents the curl-curl operator \(\nabla \times (\nabla \times)\) for electromagnetic modes.
Eigenvalue Problem
The eigenvalue problem is:
where \(C \in \mathbb{R}^{N_1 \times N_1}\) is the double curl matrix, \(M_1 \in \mathbb{R}^{N_1 \times N_1}\) is the mass matrix, \(\mathbf{v} \in \mathbb{R}^{N_1}\) is the eigenvector, and \(\lambda = k^2\) is the eigenvalue.
Toroidal Curvature Effects
The toroidal geometry introduces curvature through: - Jacobian determinant: \(J(x) = \det(DF(x)) = \epsilon (R_0 + \epsilon r \cos(2\pi\chi))\) - Metric tensor: \(G(x) = DF(x)^T DF(x)\) (accounts for non-orthogonal coordinates) - Inverse metric: \(G^{-1}(x)\) (used in mass matrix computation)
These geometric factors modify the eigenmode structure compared to cylindrical cavities.
Code Walkthrough
Block 1: Imports and Configuration (lines 1-21)
Imports modules and sets up output directory. Configures discretization parameters: \(n=8\) elements, \(p=3\) polynomial degree, creating a 2D toroidal cross-section.
Block 2: Domain Setup (lines 23-38)
Defines toroidal geometry:
Minor radius: \(a=1\)
Major radius: \(R_0=2.1\)
Aspect ratio: \(\epsilon = a/R_0 \approx 0.476\)
Uses
toroid_mapfor coordinate transformation
Block 3: DeRham Sequence and Operators (lines 40-56)
Sets up finite element spaces:
Boundary conditions: clamped in radial, periodic in poloidal, constant in toroidal
Assembles mass matrices: \(M_0, M_1, M_2, M_3\)
Constructs gradient operator: \(D_0 = \nabla_h\) (strong gradient)
Builds double curl matrix:
This represents the curl-curl operator \(\nabla \times (\nabla \times)\) for electromagnetic modes.
Block 4: Eigenvalue Computation (lines 58-68)
Solves generalized eigenvalue problem:
Extracts real eigenvalues and eigenvectors
Filters finite eigenvalues
Sorts in ascending order
Block 5: Visualization (lines 70-215)
Generates plots:
Eigenvalue spectrum: First 40 eigenvalues normalized by \(\pi^2\)
Eigenmode visualization: Plots pushforward of eigenvectors on 2D cross-section (\(\zeta=0.5\)) showing field magnitude as contour plots
Creates grid of eigenmode plots (first 25 modes) using
plot_eigenvectors_grid()
The toroidal geometry introduces curvature effects that modify the eigenmode structure compared to cylindrical cavities, making this a more complex test case for the electromagnetic solver.