1. Your first cavity: a pillbox¶
A pillbox is a closed metal cylinder: the simplest RF cavity, and one whose resonant frequencies are known exactly. That makes it a good place to learn the basic cavsim2d workflow, because you can check the answer.
In this tutorial you will:
Build a pillbox and look at its shape.
Solve for its resonant modes.
Read the figures of merit of its accelerating mode.
Check the frequency against the exact formula.
Look at the mesh and the electric field.
List every mode the solver found, and see which of them can accelerate a beam.
Before you start: install cavsim2d (see Installation). Nothing else is needed. Running the whole notebook takes about a minute.
1. Build the cavity¶
Each cavity shape is a class. Import the ones you need, here Pillbox, along with
NumPy and SciPy for the check in step 4.
import numpy as np
from scipy.constants import c
from scipy.special import jn_zeros
from cavsim2d import Pillbox
A pillbox takes the number of cells and five dimensions in millimetres,
[L, Req, Ri, S, L_bp]:
parameter |
meaning |
|---|---|
|
length of a cell along the beam axis |
|
radius of the cell |
|
radius of the opening on the axis (the iris) |
|
gap between neighbouring cells; unused for one cell |
|
length of the beam pipe added at each end |
Build one cell of radius 230 mm and length 200 mm, closed at both ends
(beampipe='none'). The geometry needs a small opening on the axis; 1 mm is far
too small to change the result. The name is also the name of the folder the
results go into.
cav = Pillbox(1, [200, 230, 1, 0, 0], beampipe='none', name='pillbox')
cav.plot('geometry');
The plot shows the upper half of the cross-section. The cavity is symmetric about the beam axis (\(r = 0\)), so this half is all cavsim2d needs to solve it.
2. Solve for the resonant modes¶
An eigenmode analysis finds the frequencies at which the cavity resonates and the
field of each of those modes. Everything about it is under cav.eigenmode.
run() meshes the cross-section and solves. Every setting you leave out keeps its
default: the accelerating (monopole) family of modes, and a mesh of triangles up
to 20 mm across. n_modes asks for the eight lowest modes; the default would be
the number of cells plus two.
cav.eigenmode.run({'n_modes': 8});
The results are saved in a folder named after the cavity, ./pillbox/, beside
this notebook. Reading them back later costs nothing; nothing is solved twice.
3. Read the figures of merit¶
cav.eigenmode.qois (the quantities of interest) holds the figures of merit of the
accelerating mode. For a single cell that is the lowest mode, called TM\(_{010}\).
qois = cav.eigenmode.qois
for key in ['freq [MHz]', 'R/Q [Ohm]', 'Q []', 'G [Ohm]']:
print(f'{key:12s} {qois[key]:10.4g}')
freq [MHz] 498.9
R/Q [Ohm] 218.7
Q [] 3.665e+04
G [Ohm] 210.7
Each key carries its unit in brackets:
quantity |
meaning |
|---|---|
|
the resonant frequency |
|
how strongly the mode exchanges energy with a beam on the axis; it depends only on the shape |
|
the quality factor: \(2\pi\) times the stored energy over the energy the walls absorb per RF period, here for copper walls |
|
the geometry factor, \(Q\) times the wall’s surface resistance, which does not depend on the wall material |
qois also holds the peak fields on the wall relative to the accelerating field,
Epk/Eacc and Bpk/Eacc. They are left for the next tutorial: the small opening
on this pillbox’s axis has sharp edges, and the field at a sharp edge keeps growing
as the mesh is refined, so its peak value here would describe the mesh rather than
the cavity. The glossary defines these and the other terms the
tutorials use.
4. Check the answer¶
For a closed cylinder of radius \(R\), the frequency of TM\(_{010}\) is \(f = c\,\chi_{01} / (2\pi R)\), where \(\chi_{01} \approx 2.405\) is the first zero of the Bessel function \(J_0\). It does not depend on the length.
R = 230e-3 # radius in metres
f_exact = c * jn_zeros(0, 1)[0] / (2 * np.pi * R) / 1e6 # MHz
f_solved = qois['freq [MHz]']
print(f'exact {f_exact:.4f} MHz')
print(f'cavsim2d {f_solved:.4f} MHz')
print(f'difference {abs(f_solved - f_exact) / f_exact:.1e} (relative)')
exact 498.8806 MHz
cavsim2d 498.8806 MHz
difference 1.3e-07 (relative)
The two agree to about one part in ten million, so the default mesh is already fine enough for this mode’s frequency. Tutorial 3 shows how to check that for any cavity and any figure of merit.
5. Look at the mesh and the field¶
In a notebook, show_mesh() and show_fields() open an interactive view that you
can pan and zoom. The mesh is made of curved triangles, which follow the wall
exactly.
cav.show_mesh();
show_fields() shows the field of the accelerating mode: the strength of the
electric field, \(|E|\), by default. For TM\(_{010}\) it is strongest on the axis,
where the beam passes, and falls to zero at the outer wall. Pass which='H' for the
magnetic field.
cav.show_fields();
6. Every mode the solver found¶
cav.eigenmode.qois_df is a table with one row per mode. The mode column numbers
the modes from 0 in order of frequency, which is also how show_fields(mode=...)
counts them.
table = cav.eigenmode.qois_df
table[['mode', 'freq [MHz]', 'R/Q [Ohm]', 'Q []']].round(2)
| mode | freq [MHz] | R/Q [Ohm] | Q [] | |
|---|---|---|---|---|
| 0 | 0 | 498.88 | 218.68 | 36651.70 |
| 1 | 1 | 900.34 | 30.85 | 32078.70 |
| 2 | 2 | 1092.50 | 0.00 | 72348.70 |
| 3 | 3 | 1145.14 | 26.67 | 55532.11 |
| 4 | 4 | 1368.60 | 87.25 | 39549.93 |
| 5 | 5 | 1579.80 | 5.16 | 42480.67 |
| 6 | 6 | 1637.03 | 0.00 | 112181.82 |
| 7 | 7 | 1696.68 | 0.00 | 72137.35 |
The R/Q column splits the modes into two kinds. Modes 0, 1, 3, 4 and 5 have an electric field along the axis, so a beam passing through can gain or lose energy in them: these are TM modes. Modes 2, 6 and 7 have no electric field along the axis, and their R/Q is zero: these are TE modes, and a beam on the axis does not feel them. The lowest mode, TM\(_{010}\), couples most strongly, with an R/Q of 218.7 Ohm.
What you learned¶
A cavity is built from its class and its dimensions in millimetres, and its results are saved in a folder named after it.
cav.eigenmode.run()solves for the resonant modes; settings you leave out keep their defaults.cav.eigenmode.qoisholds the figures of merit of the accelerating mode, andcav.eigenmode.qois_dfa table of every mode.cav.show_mesh()andcav.show_fields()show the mesh and the field.R/Q tells you which modes can accelerate a beam.
Next¶
An elliptical cavity and its figures of merit: the cell shape of most superconducting linacs, alone and as a 9-cell cavity.