A curved custom cavity: eigenmode, multipacting and tuning

A second custom geometry, this time with a curved wall: the whole cavity wall is a single circular arc bulging from the aperture out to the equator (Profile.arc_to). We run eigenmode, then multipacting — which reads the custom PEC wall of the eigenmode mesh as its electron-emission sites — and finally tune it. See the writing a new cavity model guide for the contract.

import os
import tempfile

import numpy as np
import matplotlib.pyplot as plt

from cavsim2d import Study
from cavsim2d.utils.style import apply_style

apply_style()

1. Define the geometry (a curved wall)

The model needs what the cone in the custom-geometry tutorial needs: its dimensions in parameters, its outline in profile(), and rebuild(). Only the outline differs: one arc_to segment replaces the cone’s straight walls, giving an exact circular wall.

from cavsim2d.geometry import Profile
from cavsim2d.models.base import Cavity


class DomeCavity(Cavity):
    """A rounded one-cell cavity whose whole wall is one circular arc, bulging from the
    opening out to the equator. dims = [L, Req, Ri] in mm."""

    def __init__(self, dims, name='dome'):
        super().__init__(name=name)
        L, Req, Ri = dims
        self.parameters = {'L': float(L), 'Req': float(Req), 'Ri': float(Ri)}

    def profile(self):
        L, Req, Ri = (self.parameters[k] * 1e-3 for k in ('L', 'Req', 'Ri'))   # m
        if Req <= Ri:
            return None                                          # not a valid dome
        p = Profile('dome')
        p.start(-L / 2, 0.0)
        p.line_to(-L / 2, Ri, 'PMC')                             # left opening
        p.arc_to(L / 2, Ri, through=(0.0, Req), boundary='PEC')  # the curved wall
        p.line_to(L / 2, 0.0, 'PMC')                             # right opening
        p.close('AXI')
        return p

    def rebuild(self, parameters, beampipe=None):
        return DomeCavity([parameters[k] for k in ('L', 'Req', 'Ri')], name=self.name)

2. Build and view it

cav = DomeCavity([90, 100, 20])
study = Study(os.path.join(tempfile.mkdtemp(), 'dome'))
study.add_cavity([cav], ['dome'])
cav.plot('geometry');
../../_images/930452ed521224afc9ae1ce18ca63e645f45c3bd78ce9fd1ab07b01d572b0f34.png

3. Eigenmode

The peak-field ratios are left out: the arc meets the opening planes at sharp corners, where the field keeps growing as the mesh is refined, so they would describe the mesh rather than the dome (the custom-geometry tutorial explains why).

study.run_eigenmode({'polarisation': 'monopole', 'mesh_config': {'h': 8, 'p': 2}})
q = cav.eigenmode.qois
print(f"frequency : {q['freq [MHz]']:.2f} MHz")
print(f"R/Q       : {q['R/Q [Ohm]']:.1f} Ohm")
print(f"G         : {q['G [Ohm]']:.1f} Ohm")
frequency : 1270.16 MHz
R/Q       : 132.7 Ohm
G         : 275.2 Ohm

The mode itself — an interactive NGSolve (webgui) view of the electric field. Drag to rotate, and use Open Controls to switch field component or clip:

cav.show_fields(which='E');   # webgui; pass which='H' for the magnetic field

4. Multipacting on the custom wall

Multipacting reuses the eigenmode field and identifies the cavity wall by its PEC label, so it works on our arc wall unchanged. We seed emission sites in a band around the equator and sweep a range of peak fields and launch phases (kept small so it runs quickly).

mp = cav.multipacting
mp.set_emission_points([-0.02, 0.02], n_points=12)   # band around the equator [m]
mp.run({'epks': np.linspace(1e6, 40e6, 24),
        'phis': np.linspace(0, 2 * np.pi, 12, endpoint=False),
        'v_init': 2, 'proc_count': 4})
mp.plot_counter();
../../_images/1acd7d03dc43e3669acbf301816558f7b90871562a8d04f1ebd6c297574984e5.png

5. Tune

study.run_tune({'freqs': 1300.0, 'cell_type': {'mid-cell': 'Req'},
                'tol': 1e-3,   # coarse demo mesh: match the secant tol to its noise floor
                'eigenmode_config': {'mesh_config': {'h': 8, 'p': 2}}})
res = cav.tune.qois['mid-cell']
print(f"tuned Req = {res['parameters']['Req']:.3f} mm  ->  {res['FREQ']:.2f} MHz")
tuned Req = 98.001 mm  ->  1300.00 MHz

6. Adaptive mesh refinement of the tuned dome

The arc wall meets the flat aperture planes at sharp corners, where the fields (and the discretisation error) concentrate. Turning on mesh_config['adaptive'] lets the solver refine the mesh where its own error estimate is largest, rather than everywhere — resolving those corners without paying for a globally fine mesh. Here it refines the tuned dome from the last section, cav.tuned.

Adaptive refinement is a mode of the eigenmode solve, not a separate object: the refined mesh is the eigenmode result. So show_mesh draws the mesh actually solved on (note how the elements bunch up at the two corners), show_fields shows the field on that same refined mesh, and — because it feeds straight through — cav.multipacting would track in the refined field too. The one property unique to an adaptive run is the convergence history: cav.eigenmode.plot_convergence() traces how the recovery error falls and the mode frequency settles as degrees of freedom are added.

study.tuned.run_eigenmode({'polarisation': 'monopole',
                           'mesh_config': {'h': 12, 'p': 2, 'adaptive': True}})
cav.tuned.show_mesh();   # interactive NGSolve (webgui) view of the refined mesh
cav.tuned.show_fields();   # the field on the refined mesh
# How the error estimate and the frequency changed as the mesh was refined
cav.tuned.eigenmode.plot_convergence();
../../_images/cfbabc2ad459cee646475ccb835d41e279617230d7ae070ae172d9bb3b46ea8a.png

A curved, from-scratch geometry running eigenmode, multipacting, tuning and adaptive refinement — no framework changes. See the cone tutorial (straight walls + wakefield) and the extending guide.