Beam coupling impedance: frequency domain against ABCI¶
cav.fds computes the beam coupling impedance directly at the frequencies you
ask for. Each frequency is one driven solve with the beam as the source. The
pipe ends are terminated in their own pipe modes, so waves leave the model as
they would leave through an infinitely long pipe, and the impedance includes
the part of the field beyond the end of the model. The result therefore does
not depend on how much pipe is meshed.
ABCI gets the same quantity from the wake potential of a short bunch. The cavity example compares the two for a TESLA cell with a 100 m wake. This one uses a structure without trapped modes: a collimator, a short narrowing between two equal beam pipes. Its wake dies out within a few metres, so both codes can be run on two meshes each to see how converged they are.
This example needs ABCI, downloaded from KEK (see the installation guide).
import os
import tempfile
import time
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from cavsim2d import Assembly, Beampipe, Taper
from cavsim2d.utils.style import apply_style
apply_style()
pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 160)
workspace = tempfile.mkdtemp()
def collimator(name, pipe=80):
"""A 40 mm pipe narrowing to a 15 mm aperture over a 60 mm taper, and back.
*pipe* is the straight pipe on each side [mm]."""
cav = Assembly([Taper(40, 15, pipe + 60, straight_left=pipe), Beampipe(R=15, L=40),
Taper(15, 40, pipe + 60, straight_right=pipe)], name=name)
cav.set_workspace(os.path.join(workspace, name))
return cav
1. The collimator¶
Pipes of 40 mm radius on both sides, a 15 mm aperture 40 mm long, and 60 mm
tapers between them, built as an Assembly of two tapers and a pipe.
coll = collimator('collimator')
coll.plot('geometry');
2. Frequency-domain sweep¶
polarisation=[0, 1] solves the monopole, which gives the longitudinal
impedance, and the dipole, which gives the transverse impedance. beam=True
adds the beam; the default is a beam at the speed of light. n_port_modes is
the number of TM and TE pipe modes carried at each port. Every mode that
propagates below the highest frequency has to be carried, and the solver warns
when one is missing.
t0 = time.time()
coll.fds.run(frequencies=[100, 12000, 120], polarisation=[0, 1], beam=True,
n_port_modes=4, mesh_config={'h': 6, 'p': 3}, progress=False)
print(f'frequency-domain sweep: {time.time() - t0:.0f} s')
coll.fds.result(polarisation=0)
frequency-domain sweep: 149 s
SweepResult(fom, m=0, 120 frequencies 100.0-12000.0 MHz, 16 port modes, beam)
3. ABCI¶
A bunch of 8 mm rms length resolves the spectrum to 12 GHz. A wake of 4 m is enough for this structure. ABCI’s mesh step is a fraction of the bunch length, here 5 % of it (0.4 mm).
t0 = time.time()
coll.wakefield.run({'MROT': 2, 'bunch_length': 8, 'wakelength': 4, 'cutoff': 12,
'DDR_SIG': 0.05, 'DDZ_SIG': 0.05})
print(f'ABCI: {time.time() - t0:.0f} s')
ABCI: 69 s
4. Longitudinal impedance¶
cav.fds.plot_impedance takes the same arguments as
cav.wakefield.plot_impedance and plots in the same unit, so the two overlay
directly. component chooses the real or the imaginary part.
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
for ax, part in zip(axes, ('real', 'imag')):
coll.fds.plot_impedance('longitudinal', ax=ax, unit='', component=part, show=False,
label='frequency domain')
coll.wakefield.plot_impedance('longitudinal', ax=ax, unit='', component=part, show=False,
label='ABCI', ls='--')
ax.set_xlim(0, 12000)
ax.legend()
plt.tight_layout()
plt.show()
Below the cutoff of the 40 mm pipe (2869 MHz for \(\mathrm{TM}_{01}\)) no wave can leave, and the real part is zero in both: the impedance is purely inductive, with an imaginary part that grows in proportion to the frequency. Above the cutoff the two codes follow the same curve, including the dip near 8.2 GHz. ABCI shows small spikes at the cutoffs, and its imaginary part lies a few per cent higher over most of the band. Section 6 puts numbers on the difference.
5. Transverse impedance¶
The transverse impedance is the dipole’s, \(Z_\perp = (c/\omega)\,\hat Z_1\), in Ω/m. It is the same quantity as ABCI’s transverse impedance, per unit offset of the driving bunch.
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
for ax, part in zip(axes, ('real', 'imag')):
coll.fds.plot_impedance('transverse', ax=ax, unit='', component=part, show=False,
label='frequency domain')
coll.wakefield.plot_impedance('transverse', ax=ax, unit='', component=part, show=False,
label='ABCI', ls='--')
ax.set_xlim(0, 12000)
ax.legend()
plt.tight_layout()
plt.show()
zt_fd = coll.fds.impedance('transverse', unit='')
zt_ab = coll.wakefield.impedance('transverse', unit='')
def at_t(frame, f):
i = int(np.argmin(np.abs(frame['f [MHz]'].to_numpy() - f)))
return complex(frame['Re(Z) [Ohm/m]'].iloc[i], frame['Im(Z) [Ohm/m]'].iloc[i])
rows = []
for f in (500, 4000, 8000):
a, b = at_t(zt_fd, f), at_t(zt_ab, f)
rows.append({'f [MHz]': f, 'frequency domain [Ohm/m]': f'{a.real:7.1f} {a.imag:+7.1f}j',
'ABCI [Ohm/m]': f'{b.real:7.1f} {b.imag:+7.1f}j',
'difference': f'{100 * abs(a - b) / abs(a):.1f} %'})
pd.DataFrame(rows).set_index('f [MHz]')
| frequency domain [Ohm/m] | ABCI [Ohm/m] | difference | |
|---|---|---|---|
| f [MHz] | |||
| 500 | 0.0 +1651.4j | -0.6 +1752.1j | 6.1 % |
| 4000 | 255.1 +1898.1j | 257.4 +2002.4j | 5.4 % |
| 8000 | 1336.8 +1687.4j | 1361.1 +1900.9j | 10.0 % |
Below the cutoff of the \(\mathrm{TE}_{11}\) mode of the 40 mm pipe (2196 MHz) the real part is zero in both codes. Above it, the real parts agree to 1 % to 2 % (255.1 against 257.4 Ω/m at 4 GHz, 1336.8 against 1361.1 Ω/m at 8 GHz). As in the longitudinal case, ABCI’s imaginary part is higher: by 6 % at 500 MHz (1752 against 1651 Ω/m) and by 13 % at 8 GHz, where the two codes differ by 10 % in all.
6. How converged are the two?¶
The longitudinal impedance at five frequencies, from two meshes of each code: the frequency-domain solve at element sizes of 6 mm and 3 mm, and ABCI at mesh steps of 10 % and 5 % of the bunch length.
f_check = [500, 2000, 4000, 6000, 10000]
def at(frame, f):
"""The complex impedance of *frame* [Ohm] at the frequency nearest *f* [MHz]."""
i = int(np.argmin(np.abs(frame['f [MHz]'].to_numpy() - f)))
return complex(frame['Re(Z) [Ohm]'].iloc[i], frame['Im(Z) [Ohm]'].iloc[i])
columns = {}
for h in (6, 3):
cav = collimator(f'fd_h{h}')
cav.fds.run(frequencies=f_check, beam=True, n_port_modes=4,
mesh_config={'h': h, 'p': 3}, progress=False)
z = cav.fds.impedance('longitudinal', unit='')
columns[f'frequency domain, h = {h} mm'] = [at(z, f) for f in f_check]
for ratio in (0.1, 0.05):
if ratio == 0.05:
z = coll.wakefield.impedance('longitudinal', unit='')
else:
cav = collimator('abci_coarse')
cav.wakefield.run({'MROT': 0, 'bunch_length': 8, 'wakelength': 4, 'cutoff': 12,
'DDR_SIG': ratio, 'DDZ_SIG': ratio})
z = cav.wakefield.impedance('longitudinal', unit='')
columns[f'ABCI, step = {ratio:g} sigma'] = [at(z, f) for f in f_check]
table = pd.DataFrame(columns, index=pd.Index(f_check, name='f [MHz]'))
table.map(lambda v: f'{v.real:8.3f} {v.imag:+8.3f}j')
| frequency domain, h = 6 mm | frequency domain, h = 3 mm | ABCI, step = 0.1 sigma | ABCI, step = 0.05 sigma | |
|---|---|---|---|---|
| f [MHz] | ||||
| 500 | -0.000 +5.443j | -0.000 +5.442j | -0.000 +5.665j | 0.000 +5.682j |
| 2000 | -0.000 +23.760j | -0.000 +23.756j | 0.003 +24.719j | 0.002 +24.798j |
| 4000 | 14.530 +42.445j | 14.531 +42.437j | 14.986 +43.960j | 15.408 +43.796j |
| 6000 | 34.577 +66.278j | 34.575 +66.255j | 35.638 +70.880j | 35.144 +69.776j |
| 10000 | 120.296 +81.809j | 120.286 +81.774j | 135.360 +70.537j | 124.680 +91.567j |
fd, ab = columns['frequency domain, h = 3 mm'], columns['ABCI, step = 0.05 sigma']
change = pd.DataFrame({
'frequency domain, h 6 -> 3 mm': [abs(a - b) / abs(b) for a, b in
zip(columns['frequency domain, h = 6 mm'], fd)],
'ABCI, step 0.1 -> 0.05 sigma': [abs(a - b) / abs(b) for a, b in
zip(columns['ABCI, step = 0.1 sigma'], ab)],
'ABCI vs frequency domain': [abs(a - b) / abs(b) for a, b in zip(ab, fd)],
}, index=table.index)
change.map(lambda v: f'{100 * v:.2f} %')
| frequency domain, h 6 -> 3 mm | ABCI, step 0.1 -> 0.05 sigma | ABCI vs frequency domain | |
|---|---|---|---|
| f [MHz] | |||
| 500 | 0.02 % | 0.31 % | 4.41 % |
| 2000 | 0.02 % | 0.32 % | 4.39 % |
| 4000 | 0.02 % | 0.98 % | 3.61 % |
| 6000 | 0.03 % | 1.55 % | 4.77 % |
| 10000 | 0.03 % | 15.25 % | 7.38 % |
Halving the element size changes the frequency-domain result by 0.02 % to 0.03 % at every frequency. Halving ABCI’s mesh step changes its result by 0.3 % at 500 MHz and up to 15 % at 10 GHz. The two codes differ by 3.6 % to 7.4 %, with ABCI higher in the imaginary part at low frequency (5.68 Ω against 5.44 Ω at 500 MHz). At low frequency the difference is more than ten times ABCI’s own change between its two meshes, and refining ABCI’s mesh moved its value away from the frequency-domain one (5.665 Ω to 5.682 Ω), so the gap is not one that ABCI’s mesh refinement closes at these levels.
7. The field beyond the pipe ends¶
Above the pipe cutoff (2.87 GHz for the 40 mm pipe) the structure radiates into the pipes. The waves leaving through the ports still act on the beam beyond the end of the model. The solver adds that contribution in closed form, from the amplitude of each pipe mode at the port (“tails”). Without it, the impedance depends on where the model ends.
The same collimator with 80 mm and 200 mm of pipe on each side, with and without the tails:
long = collimator('long_pipes', pipe=200)
long.fds.run(frequencies=[100, 12000, 120], beam=True, n_port_modes=4,
mesh_config={'h': 6, 'p': 3}, progress=False)
fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True)
for cav, pipe, ls in ((coll, 80, '-'), (long, 200, '--')):
for ax, tails in zip(axes, (True, False)):
cav.fds.plot_impedance('longitudinal', ax=ax, unit='', component='real', tails=tails,
show=False, ls=ls, label=f'{pipe} mm of pipe')
for ax, title in zip(axes, ('with the tails', 'without the tails')):
ax.set_title(title)
ax.set_xlim(0, 12000)
ax.legend()
plt.tight_layout()
plt.show()
def complex_z(frame):
return frame['Re(Z) [Ohm]'].to_numpy() + 1j * frame['Im(Z) [Ohm]'].to_numpy()
scale = np.abs(complex_z(long.fds.impedance('longitudinal', unit=''))).max()
for name, tails in (('with the tails', True), ('without the tails', False)):
d = np.abs(complex_z(coll.fds.impedance('longitudinal', unit='', tails=tails))
- complex_z(long.fds.impedance('longitudinal', unit='', tails=tails)))
print(f'{name:18s}: largest difference between the two pipe lengths '
f'{d.max():7.3f} Ohm ({100 * d.max() / scale:.2f} % of max |Z|)')
with the tails : largest difference between the two pipe lengths 0.229 Ohm (0.16 % of max |Z|)
without the tails : largest difference between the two pipe lengths 213.835 Ohm (145.53 % of max |Z|)
With the tails, the two pipe lengths give the same impedance to 0.23 Ω, or 0.16 % of the largest \(|Z_\parallel|\). Without them, the impedance above cutoff depends on how much pipe is modelled: the two curves differ by up to 214 Ω, 1.5 times the largest \(|Z_\parallel|\). The real part even turns negative just above the cutoff, which no passive structure allows. Below the cutoff the tails change nothing visible, because every pipe mode decays there.
Summary¶
For a structure whose wake ABCI resolves in a short run, the two codes give the same impedance spectrum, longitudinal and transverse, to within 3.6 % to 7.4 % (longitudinal) and 5 % to 10 % (transverse), with ABCI’s imaginary part higher. The frequency-domain result changes by at most 0.03 % when the mesh is refined, and by 0.16 % when the pipes are made 2.5 times longer. ABCI’s result changes by 0.3 % to 15 % between its two meshes.
Both runs, the frequency-domain sweep of both orders at 120 frequencies and the ABCI run of both orders, take minutes (the timings are printed above). For cavities with high-Q modes the frequency domain needs no long wake: a trapped mode is a pole of the impedance at its exact frequency, and the eigenmodes of the same model locate it (see the eigenmode comparison).