Network matrices of an axisymmetric structure

The frequency-domain solver, cav.fds, treats the ends of the beam pipes as ports. Each port carries the modes of its pipe; for the monopole these are the \(\mathrm{TM}_{0n}\) and \(\mathrm{TE}_{0n}\) modes. A modal current \(I_n\) drives mode \(n\) at one port, and the solve gives the modal voltages \(V\) of every mode at every port. The ratios form the impedance matrix \(\mathbf Z\), with \(\mathbf V = \mathbf Z\,\mathbf I\), and from it follow the admittance matrix \(\mathbf Y = \mathbf Z^{-1}\) and the scattering matrix \(\mathbf S\). The modes are normalised over the whole port disk, so these are the matrices of the three-dimensional structure for one azimuthal order and polarisation.

The pipeline has stages: the full-order model (run), a reduced model of it (reduce), and, for an Assembly, its elements joined through their port modes (concatenate). Each stage keeps its results in the cavity’s folder.

import os
import tempfile
import time

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from cavsim2d import Pillbox
from cavsim2d.utils.style import apply_style

apply_style()
pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 160)
folder = os.path.join(tempfile.mkdtemp(), 'pillbox')

1. A pillbox with beam pipes

A cell 100 mm long and 100 mm in radius, with pipes of 40 mm radius and 60 mm length. The \(\mathrm{TM}_{01}\) mode of the pipe propagates above 2869 MHz.

cav = Pillbox(1, [100, 100, 40, 0, 60], beampipe='both')
cav.set_workspace(folder)
cav.plot('geometry');
../../_images/d6a3db817b15972a4242533d8219e543330007dc9a326955a402e0ce2eb6c274.png

2. Full-order sweep

n_port_modes=3 carries three TM and three TE modes at each port, which gives twelve port modes in all. beam=True adds the beam as one more excitation, used in section 6; it leaves the port matrices unchanged. The result’s labels name the port and then the mode.

t0 = time.time()
cav.fds.run(frequencies=[1000, 5000, 161], n_port_modes=3, beam=True,
            mesh_config={'h': 8, 'p': 3}, progress=False)
print(f'full-order sweep: {time.time() - t0:.0f} s')
fom = cav.fds.result(source='fom')
print(fom)
print(fom.labels)
full-order sweep: 79 s
SweepResult(fom, m=0, 161 frequencies 1000.0-5000.0 MHz, 12 port modes, beam)
['1(TM01)', '1(TE01)', '1(TM02)', '1(TE02)', '1(TM03)', '1(TE03)', '2(TM01)', '2(TE01)', '2(TM02)', '2(TE02)', '2(TM03)', '2(TE03)']

3. Impedance and admittance

The structure is lossless and reciprocal, so \(\mathbf Z\) must be symmetric and purely imaginary at every frequency.

Z, Y = fom.Z, fom.Y
print(f'asymmetry      max|Z - Z^T| / max|Z| = {np.max(np.abs(Z - np.swapaxes(Z, 1, 2))) / np.max(np.abs(Z)):.1e}')
print(f'real part      max|Re Z|    / max|Z| = {np.max(np.abs(Z.real)) / np.max(np.abs(Z)):.1e}')
print(f'inverse        max|Y Z - 1|          = {np.max(np.abs(Y @ Z - np.eye(Z.shape[1]))):.1e}')
i = int(np.argmin(np.abs(fom.frequencies - 3000e6)))
print(f'\nZ at {fom.frequencies[i] * 1e-6:.0f} MHz, TM01 and TE01 block [Ohm]:')
pick = [fom.labels.index(l) for l in ('1(TM01)', '2(TM01)', '1(TE01)', '2(TE01)')]
pd.DataFrame(Z[i][np.ix_(pick, pick)], index=[fom.labels[k] for k in pick],
             columns=[fom.labels[k] for k in pick]).map(lambda v: f'{v.imag:+.4g}j')
asymmetry      max|Z - Z^T| / max|Z| = 2.7e-13
real part      max|Re Z|    / max|Z| = 0.0e+00
inverse        max|Y Z - 1|          = 2.7e-14

Z at 3000 MHz, TM01 and TE01 block [Ohm]:
1(TM01) 2(TM01) 1(TE01) 2(TE01)
1(TM01) +44.45j +75.52j +0j +0j
2(TM01) +75.52j +44.45j +0j +0j
1(TE01) +0j +0j +327.8j -0.005461j
2(TE01) +0j +0j -0.005461j +327.8j

\(\mathbf Z\) is symmetric to round-off and has no real part, and \(\mathbf Y\) is its inverse. At the monopole order the TM and TE modes do not couple, so the TM–TE entries are zero. The TE\(_{01}\) modes of the two ports are almost uncoupled (\(Z\) = \(-0.0055j\) Ω between them, against \(+327.8j\) Ω on the diagonal): at 3000 MHz the TE\(_{01}\) mode is far below its cutoff (4571 MHz) and decays along the pipe.

4. Scattering matrix

plot_s draws \(|S|\) in dB. The reference impedance of each mode is its wave impedance, which is reactive below the mode’s cutoff. There, an entry of \(\mathbf S\) measures how much of a decaying field reaches the other port, not a reflected power. Above the cutoff the \(\mathrm{TM}_{01}\) wave carries power, and the block of \(\mathbf S\) that belongs to the propagating modes must be unitary, because the structure loses none.

cav.fds.plot_s([('1(TM01)', '1(TM01)'), ('2(TM01)', '1(TM01)')], source='fom')

modes = [md for p in fom.ports for md in p.modes]
worst = 0.0
for k, f in enumerate(fom.frequencies):
    prop = [n for n, md in enumerate(modes) if md.cutoff < f]
    if prop:
        Sp = fom.S[k][np.ix_(prop, prop)]
        worst = max(worst, np.max(np.abs(Sp.conj().T @ Sp - np.eye(len(prop)))))
print(f'propagating block: max|S^H S - 1| = {worst:.1e}')
../../_images/fe0319739c73b3b7e125f472b4adba648dd3763d7ea39e423e71112a662453aa.png
propagating block: max|S^H S - 1| = 1.3e-11

Below 2869 MHz both entries are small and peak at the two trapped monopole resonances near 1187 MHz and 1929 MHz, where the cavity field reaches the ports through the decaying pipe field. Above the cutoff the wave passes the cavity, with notches and peaks at the resonances that radiate into the pipes. The propagating block is unitary to about \(10^{-11}\).

5. Reduced model

reduce builds a reduced model from the solutions at a few frequencies (here 12 Chebyshev points of the band) and sweeps it over the same frequencies as the full-order run. The reduced model is a small dense system, and cav.fds.solve(..., source='rom') sweeps it again at any frequencies of its band.

t0 = time.time()
rom = cav.fds.reduce(tol=1e-9, n_snapshots=12, progress=False)
print(f'reduction (12 full-order solves + projection): {time.time() - t0:.0f} s')
print(rom)
print(f'full-order model: {cav.fds.fom.ndof} unknowns; reduced model: {rom.rank}')

ax = cav.fds.plot_s([('2(TM01)', '1(TM01)')], source='fom', show=False, lw=3, alpha=0.5,
                 label='full order')
cav.fds.plot_s([('2(TM01)', '1(TM01)')], source='rom', ax=ax, ls='--', label='reduced')

red = cav.fds.result(source='rom')
print(f'max|S_rom - S_fom| over the 161 frequencies = {np.max(np.abs(red.S - fom.S)):.1e}')
t0 = time.time()
dense = cav.fds.solve([1000, 5000, 4001], source='rom')
print(f'reduced model at 4001 frequencies: {time.time() - t0:.2f} s')
reduction (12 full-order solves + projection): 10 s
ReducedModel('pillbox (ROM)', m=0, rank 110, band 1017.1-4982.9 MHz, 12 port modes, beam)
full-order model: 12411 unknowns; reduced model: 110
../../_images/632d2fe7e6531da2b30401c962c9c92d2138d2928dc877bf545ff0ee666a9f4c.png
max|S_rom - S_fom| over the 161 frequencies = 1.4e-08
reduced model at 4001 frequencies: 3.72 s

The reduced model has 110 unknowns, against 12 411 of the full-order model, and reproduces \(\mathbf S\) at all 161 frequencies to \(1.4\times10^{-8}\). Building it costs little more than its 12 full-order solves. It then needs about 1 ms per frequency, a few hundred times less than a full-order solve (compare the timings printed above).

6. With the beam: the generalised matrices

beam=True adds the beam as one more port, with its current \(i\) and its voltage \(v\). The generalised impedance matrix

\[\begin{split}\tilde{\mathbf Z} = \begin{bmatrix}\mathbf Z & \mathbf k_Z\\ \mathbf h_Z & z_{oc}\end{bmatrix}\end{split}\]

has the port voltages caused by the beam in \(\mathbf k_Z\), the beam voltage caused by the port currents in \(\mathbf h_Z\), and the beam voltage of the beam with every port open in \(z_{oc}\). The CSC-BEAM matrix \(\tilde{\mathbf S}_\mathrm{CSC} = (\mathbf S, \mathbf k, \mathbf h, z_b)\) terminates every port mode in its pipe: \(\mathbf k\) holds the waves the beam sends into the pipes, and \(-z_b\) is the beam voltage per unit beam current inside the model. The beam coupling impedance \(Z_\parallel\) adds what the waves leaving through the ports still do to the beam beyond the end of the model (“tails”; see the ABCI comparison). S_tilde() and Y_tilde hold the same information with the beam as a port in waves and in admittances.

print('Z~:', fom.Z_tilde.shape, '(12 port modes and the beam)')
S, k, h, z_b = fom.S_csc
i_tm = fom.labels.index('2(TM01)')
pick = [int(np.argmin(np.abs(fom.frequencies - f * 1e6))) for f in (2000, 3300, 4000, 4500)]
pd.DataFrame({
    'f [MHz]': fom.frequencies[pick] * 1e-6,
    '|k| at 2(TM01) [sqrt(Ohm)]': np.abs(k[pick, i_tm]),
    '|z_oc| (ports open) [Ohm]': np.abs(fom.z_oc[pick]),
    '-z_b (in the model) [Ohm]': np.round(-z_b[pick], 3),
    'Z_par (with tails) [Ohm]': np.round(-fom.matched_beam_voltage()[pick], 3),
})
Z~: (161, 13, 13) (12 port modes and the beam)
f [MHz] |k| at 2(TM01) [sqrt(Ohm)] |z_oc| (ports open) [Ohm] -z_b (in the model) [Ohm] Z_par (with tails) [Ohm]
0 2000.0 0.496362 300.626170 0.000-291.661j -0.000-282.024j
1 3300.0 3.962323 52.009927 134.271-133.555j 41.860- 82.317j
2 4000.0 1.501264 34.877167 21.578+ 33.005j 3.117+ 16.429j
3 4500.0 1.905599 19.636961 42.840- 6.148j 7.401- 5.373j
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
for ax, part in zip(axes, ('real', 'imag')):
    cav.fds.plot_impedance('longitudinal', ax=ax, unit='', component=part, show=False)
    ax.axvline(2868.6, color='0.6', lw=0.8)
plt.tight_layout()
plt.show()
../../_images/8a0d9d4d84a9ac1339736f6c5ba2ed8f36fba1fe8a411a852cc8194b0fcfd822.png

Below the cutoff (2000 MHz) \(Z_\parallel\) is purely reactive, and it differs from \(-z_b\) by 3 % (\(-282.0j\) against \(-291.7j\) Ω): the decaying pipe field still reaches a little beyond the ports. Above the cutoff the difference is large: at 3300 MHz the model alone gives \(134.3 - 133.6j\) Ω and the impedance of the structure with infinite pipes is \(41.9 - 82.3j\) Ω. With the ports open, \(|z_{oc}|\) is different again, since an open port reflects the waves back. In the plots, the real part is zero below the cutoff (grey line). The peaks above it belong to resonances that radiate into the pipes. The two trapped monopole modes below the cutoff are lossless, so they appear as poles of the imaginary part only.

7. Reading the results back

Every stage is saved in the cavity’s folder. A new cavity object on the same folder reads them without solving again.

again = Pillbox(1, [100, 100, 40, 0, 60], beampipe='both')
again.set_workspace(folder)
print(again.fds.result())
print(again.fds.rom)
again.fds.eigenmodes(source='rom').head(6)
SweepResult(rom, m=0, 161 frequencies 1000.0-5000.0 MHz, 12 port modes, beam)
ReducedModel('pillbox (ROM)', m=0, rank 110, band 1017.1-4982.9 MHz, 12 port modes, beam)
mode f [MHz] R/Q [Ohm] source
0 1 1186.885808 1.351565e+02 rom
1 2 1929.285236 3.833020e+01 rom
2 3 2345.823792 7.176983e-23 rom
3 4 2691.539991 9.359152e-01 rom
4 5 3059.159458 6.319741e-01 rom
5 6 3205.561118 8.206953e+00 rom

Summary

One full-order run gives \(\mathbf Z\), \(\mathbf Y\) and \(\mathbf S\) for every pair of port modes, and with the beam the generalised matrices and the beam coupling impedance. The reduced model reproduces them to \(10^{-8}\) and sweeps thousands of frequencies in seconds. Its resonances are those of the eigenmode solver with magnetic-wall pipe ends; the next example compares them in detail.