Impedance spectrum of a cavity: frequency domain against ABCI¶
The beam coupling impedance of a TESLA cell, computed in two ways. ABCI tracks a
Gaussian bunch through the cavity, records its wake over 100 m, and Fourier
transforms it. The frequency-domain solver, cav.fds, solves for the impedance
at each frequency directly, with the beam pipes terminated in their own pipe
modes. Its reduced model is then evaluated on ABCI’s frequency grid, so the two
spectra can be compared point by point, longitudinal and transverse.
This example needs ABCI, downloaded from KEK (see the installation guide). The ABCI run takes several minutes.
import os
import tempfile
import time
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from cavsim2d import EllipticalCavity
from cavsim2d.utils.style import apply_style
apply_style()
pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 180)
workspace = tempfile.mkdtemp()
TESLA_MID = [42, 42, 12, 19, 35, 57.652, 103.3536] # A, B, a, b, Ri, L, Req [mm]
C0 = 299792458.0
def tesla(name):
cav = EllipticalCavity(1, TESLA_MID, TESLA_MID, TESLA_MID, beampipe='both', name=name)
cav.set_workspace(os.path.join(workspace, name))
return cav
def complex_z(frame):
re = next(c for c in frame.columns if c.startswith('Re('))
im = next(c for c in frame.columns if c.startswith('Im('))
return frame[re].to_numpy() + 1j * frame[im].to_numpy()
1. The cavity¶
A TESLA mid-cell with beam pipes of 35 mm radius. The pipe’s \(\mathrm{TE}_{11}\) mode propagates above 2510 MHz and its \(\mathrm{TM}_{01}\) mode above 3278 MHz; below these cutoffs the modes of the cell are trapped.
cav = tesla('tesla')
cav.plot('geometry');
2. Frequency-domain run¶
The monopole gives the longitudinal impedance, the dipole the transverse one.
reduce builds a reduced model from 40 solves across the band, which is then
swept on ABCI’s frequency grid.
t0 = time.time()
cav.fds.run(frequencies=[200, 6000, 59], polarisation=[0, 1], beam=True, n_port_modes=3,
mesh_config={'h': 8, 'p': 3}, reduce={'tol': 1e-9, 'n_snapshots': 40},
progress=False)
print(f'frequency domain, both orders: {time.time() - t0:.0f} s')
print(cav.fds.rom_of(0))
print(cav.fds.rom_of(1))
frequency domain, both orders: 166 s
ReducedModel('tesla (ROM)', m=0, rank 148, band 202.2-5997.8 MHz, 12 port modes, beam)
ReducedModel('tesla (ROM)', m=1, rank 153, band 202.2-5997.8 MHz, 12 port modes, beam)
3. ABCI with a 100 m wake¶
A bunch of 15 mm rms length resolves the spectrum to about 6 GHz. MROT=2
computes the longitudinal and the transverse wake.
t0 = time.time()
cav.wakefield.run({'MROT': 2, 'bunch_length': 15, 'wakelength': 100, 'cutoff': 6})
print(f'ABCI, both orders: {time.time() - t0:.0f} s')
grid = cav.wakefield.impedance('longitudinal', unit='')['f [MHz]'].to_numpy()
grid = grid[(grid > 250) & (grid < 5900)]
print(f'{len(grid)} ABCI frequencies from {grid[0]:.1f} to {grid[-1]:.1f} MHz, '
f'step {grid[1] - grid[0]:.2f} MHz')
ABCI, both orders: 396 s
587 ABCI frequencies from 259.6 to 5894.2 MHz, step 9.61 MHz
4. Longitudinal impedance¶
The reduced model is evaluated at ABCI’s frequencies (frequencies=), so both
curves share one grid.
def overlay(kind, wake=None, wake_label='ABCI, 100 m wake'):
wake = wake or cav
fig, axes = plt.subplots(3, 1, figsize=(12, 10), sharex=True)
for ax, part in zip(axes, ('abs', 'real', 'imag')):
cav.fds.plot_impedance(kind, ax=ax, unit='', component=part, frequencies=list(grid),
show=False, label='frequency domain', lw=2)
wake.wakefield.plot_impedance(kind, ax=ax, unit='', component=part, show=False,
label=wake_label, ls='--')
if part == 'abs':
ax.set_yscale('log')
ax.axvline(2510, ls=':', color='k', lw=1)
ax.axvline(3278, ls=':', color='k', lw=1)
ax.set_xlim(0, 6000)
ax.legend(loc='upper right')
axes[-1].set_xlabel('f [MHz]')
plt.tight_layout()
plt.show()
def band_differences(kind, wake=None):
wake = wake or cav
fd = complex_z(cav.fds.impedance(kind, unit='', frequencies=list(grid)))
ab_frame = wake.wakefield.impedance(kind, unit='')
ab_frame = ab_frame[(ab_frame['f [MHz]'] > 250) & (ab_frame['f [MHz]'] < 5900)]
ab = complex_z(ab_frame)
rows = []
for lo, hi in ((250, 2500), (2500, 3300), (3300, 5900)):
sel = (grid > lo) & (grid < hi)
g = ab_frame['f [MHz]'].to_numpy()
rel = np.abs(fd[sel] - np.interp(grid[sel], g, ab.real)
- 1j * np.interp(grid[sel], g, ab.imag)) / np.abs(fd[sel])
rows.append({'band [MHz]': f'{lo}-{hi}', 'points': int(sel.sum()),
'median |dZ|/|Z|': f'{np.median(rel):.3f}',
'90th percentile': f'{np.percentile(rel, 90):.3f}'})
return pd.DataFrame(rows).set_index('band [MHz]')
overlay('longitudinal')
band_differences('longitudinal')
| points | median |dZ|/|Z| | 90th percentile | |
|---|---|---|---|
| band [MHz] | |||
| 250-2500 | 233 | 0.009 | 0.063 |
| 2500-3300 | 83 | 0.006 | 0.016 |
| 3300-5900 | 270 | 0.050 | 0.137 |
On ABCI’s grid the two agree over the whole band: the median difference is 0.9 % below 2500 MHz, 0.6 % between 2500 and 3300 MHz, and 5 % above the \(\mathrm{TM}_{01}\) cutoff, with the 90th percentile at 6 %, 2 % and 14 %. The largest differences sit at the two trapped monopole modes, near 1287 MHz and 2415 MHz. There the frequency-domain impedance has a pole, while the 100 m wake gives ABCI a peak of finite height whose real part swings by a few kΩ either way. Above the cutoff the resonance near 3850 MHz, which radiates into the pipes, has the same height and width in both.
5. Transverse impedance¶
ABCI’s transverse impedance of this cavity depends on the wake length. Below the \(\mathrm{TE}_{11}\) cutoff no wave can leave a lossless structure, so the real part must vanish there. Three low frequencies, with a 20 m and the 100 m wake:
short = tesla('tesla_abci_20m')
short.wakefield.run({'MROT': 1, 'bunch_length': 15, 'wakelength': 20, 'cutoff': 6})
f_low = [500, 1000, 1500]
fd = complex_z(cav.fds.impedance('transverse', unit='', frequencies=f_low))
def at(frame, f):
i = int(np.argmin(np.abs(frame['f [MHz]'].to_numpy() - f)))
return complex_z(frame.iloc[[i]])[0]
table = pd.DataFrame({
'frequency domain': fd,
'ABCI, 20 m wake': [at(short.wakefield.impedance('transverse', unit=''), f) for f in f_low],
'ABCI, 100 m wake': [at(cav.wakefield.impedance('transverse', unit=''), f) for f in f_low],
}, index=pd.Index(f_low, name='f [MHz]'))
table.map(lambda v: f'{v.real:9.0f} {v.imag:+9.0f}j Ohm/m')
| frequency domain | ABCI, 20 m wake | ABCI, 100 m wake | |
|---|---|---|---|
| f [MHz] | |||
| 500 | 0 +1582j Ohm/m | 0 +1588j Ohm/m | 10020 +5546j Ohm/m |
| 1000 | -0 +1892j Ohm/m | 0 +1900j Ohm/m | 4099 +7555j Ohm/m |
| 1500 | -0 +3276j Ohm/m | -0 +3291j Ohm/m | -18469 +27540j Ohm/m |
With the 20 m wake, ABCI’s transverse impedance is purely imaginary at these frequencies, as it must be, and within 0.5 % of the frequency-domain value (\(1588j\) against \(1582j\) Ω/m at 500 MHz). With the 100 m wake it has real parts of 4 to 18 kΩ/m and imaginary parts 3.5 to 8 times too large. ABCI’s longitudinal impedance from the same 100 m run (section 4) is not affected. The transverse spectrum is therefore compared with the 20 m run.
The frequency-domain transverse impedance against ABCI with the 20 m wake. For the differences, ABCI’s spectrum is interpolated onto the frequencies of the frequency-domain curve.
overlay('transverse', wake=short, wake_label='ABCI, 20 m wake')
band_differences('transverse', wake=short)
| points | median |dZ|/|Z| | 90th percentile | |
|---|---|---|---|
| band [MHz] | |||
| 250-2500 | 233 | 0.005 | 0.062 |
| 2500-3300 | 83 | 0.152 | 0.604 |
| 3300-5900 | 270 | 0.081 | 0.430 |
Below 2500 MHz the median difference is 0.5 % (90th percentile 6 %); the largest differences are at the trapped dipole modes near 1727 MHz and 1847 MHz, where ABCI again gives finite peaks. Between the \(\mathrm{TE}_{11}\) cutoff and 3300 MHz the difference is larger (median 15 %), and ABCI’s curve ripples around the frequency-domain one. Just above a cutoff the field leaves the cavity slowly, so the 20 m wake has presumably not yet decayed there. Above 3300 MHz the median difference is 8 %.
6. The trapped modes¶
Below the pipe cutoffs a mode of the cell cannot radiate. For lossless walls its impedance is a pole on the real frequency axis, of infinite height, which a wake of finite length turns into a peak of finite height and width. What both methods must agree on is where the poles are. The frequency-domain impedance also gives each pole’s strength: near a pole
with the linac \(R/Q\) and the transverse \(R/Q_t\) of the eigenmode solver and \(Z_\perp = (c/\omega)\hat Z_1\). Below, the R/Q read from the impedance next to each pole is compared with the eigenmode solver’s, solved with absorbing (PML) pipe ends of 150 mm length, so that each mode sees the same infinite pipe as the terminated ports.
pml = tesla('tesla_pml')
pml.beampipe_length = 0.15 # [m]
pml.eigenmode.run({'n_modes': 4, 'polarisation': [0, 1], 'boundary_conditions': 'oo',
'mesh_config': {'h': 8, 'p': 3}})
open_modes = pml.eigenmode.qois_df
rows = []
for m, kind in ((0, 'longitudinal'), (1, 'transverse')):
loaded = cav.fds.eigenmodes(source='rom', loaded=True, polarisation=m, fmax=2600)
# the dipole's ABCI peaks from the 20 m wake (section 5)
abci = (cav if m == 0 else short).wakefield.impedance(kind, unit='')
for f_n in loaded.loc[np.isinf(loaded['Q_L []']), 'f [MHz]']:
# the strength of the pole, from the impedance just beside it
f = f_n * (1 + np.array([-1e-6, 1e-6]))
z = complex_z(cav.fds.impedance(kind, unit='', frequencies=list(f)))
w, wn = 2 * np.pi * f * 1e6, 2 * np.pi * f_n * 1e6
if m == 0:
rq = np.mean(2 * z.imag * (wn ** 2 - w ** 2) / (w * wn))
else:
zhat = z * w / C0
rq = np.mean(2 * zhat.imag * (wn ** 2 - w ** 2) / (w * wn * (wn / C0) ** 2))
near = abci[np.abs(abci['f [MHz]'] - f_n) < 30]
ref = open_modes[open_modes['m'] == m]
j = int(np.argmin(np.abs(ref['freq [MHz]'].to_numpy() - f_n)))
col = 'R/Q [Ohm]' if m == 0 else next(c for c in ref.columns if c.startswith('R/Q_t'))
if ref[col].iloc[j] < 1e-3:
continue # a TE mode: the beam does not see it
rows.append({'m': m, 'frequency-domain pole [MHz]': round(f_n, 3),
'ABCI peak [MHz]': round(near['f [MHz]'].iloc[int(np.argmax(np.abs(complex_z(near))))], 1),
'R/Q from the impedance': rq,
'eigenmode solver (PML) [MHz]': round(ref['freq [MHz]'].iloc[j], 3),
'eigenmode solver R/Q': ref[col].iloc[j]})
trapped = pd.DataFrame(rows)
trapped['R/Q difference'] = (trapped['R/Q from the impedance'] / trapped['eigenmode solver R/Q']
- 1).map(lambda v: f'{v:.1e}')
trapped
| m | frequency-domain pole [MHz] | ABCI peak [MHz] | R/Q from the impedance | eigenmode solver (PML) [MHz] | eigenmode solver R/Q | R/Q difference | |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 1287.176 | 1288.5 | 117.743915 | 1287.176 | 117.739466 | 3.8e-05 |
| 1 | 0 | 2415.357 | 2413.5 | 35.581759 | 2415.357 | 35.614633 | -9.2e-04 |
| 2 | 1 | 1727.444 | 1730.8 | 10.946828 | 1727.444 | 10.946803 | 2.2e-06 |
| 3 | 1 | 1847.167 | 1846.2 | 24.305568 | 1847.167 | 24.305606 | -1.6e-06 |
| 4 | 1 | 2505.871 | 2500.0 | 1.249243 | 2508.775 | 1.957069 | -3.6e-01 |
Every ABCI peak lies within 6 MHz of a frequency-domain pole, which is less than one step of ABCI’s frequency grid. The R/Q read from the frequency-domain impedance agrees with the eigenmode solver’s to \(4\times10^{-5}\) and \(9\times10^{-4}\) for the two monopole modes, and to \(2\times10^{-6}\) for the first two dipole modes. The eigenmode solver computes R/Q from its own field and voltage integral, so this checks the normalisation of the frequency-domain impedance of both orders independently of ABCI.
The exception is the dipole mode at 2505.9 MHz, 4 MHz below the \(\mathrm{TE}_{11}\) cutoff. Its field decays only slowly along the pipe, so 150 mm of absorbing pipe presumably do not yet stand in for an infinite pipe for this mode; the eigenmode solver places it 2.9 MHz higher, with a larger R/Q.
Summary¶
With a 100 m wake, ABCI’s longitudinal spectrum of the TESLA cell matches the frequency-domain impedance point by point on ABCI’s grid: about 1 % below the pipe cutoff and 5 % above it. The transverse spectrum matches to 0.5 % below the cutoff with a 20 m wake. With the 100 m wake ABCI’s transverse result for this cavity is not usable. The trapped modes, which a wake of any finite length shows only as peaks, are poles of the frequency-domain impedance at the eigenmode solver’s frequencies, with its R/Q.