Tuning¶
Tuning changes one dimension of a cavity until a mode sits at a target frequency, for example the equator radius until the accelerating mode is at 1300 MHz. Each step solves the cavity’s modes, and the tuner moves the dimension towards the target until the frequency is within a tolerance. It can also pin a figure of merit, such as R/Q, at the same time.
Tune a cell to a target frequency tunes one cell, and Tune a multicell cavity a 9-cell cavity. This page is the full reference.
Running it¶
cav.tune.run({'freqs': 1300, 'cell_type': {'mid-cell': 'Req'}})
or, for every cavity in a study, study.run_tune(...) with the same settings. A
list of frequencies in freqs gives each cavity its own target.
cell_type says which dimension to change, and in which cells. The key names the
cells:
'mid-cell': the inner cells, or the only cell of a one-cell cavity;'end-cell': both end cells;'end-cell-left'and'end-cell-right'name one end.
The value names the dimension. For an elliptical cell it is usually 'Req', but
any dimension the shape has will do: 'A' or 'L' of an elliptical cell,
'Req' of a pillbox, 'L3' of an RF gun, or a spline coordinate such as
'p2_r'. cav.tune_variables() lists them.
Reading the results¶
The tuned cavity is a separate cavity, cav.tuned, with its own folder,
<cavity>/tuned/. The original cavity is left as it was.
cav.tune.qois # the tuned dimension and the frequency reached
cav.tuned.parameters['Req_m'] # the tuned equator radius
cav.tuned.eigenmode.run() # analyse the tuned cavity like any other
cav.tuned.eigenmode.qois # its results
cav.eigenmode.qois # still the untuned cavity's results
'solve_tuned': True runs the eigenmode analysis on the tuned cavity as part of the
tune. cav.tune.plot_convergence() shows the frequency at each step.
In a study, comparisons use the tuned cavities. study.summary(),
study.eigenmode.qois_df and the study’s plots show each cavity’s tuned version,
labelled '<name> (tuned)', once that version has results; pass tuned=False to
compare the untuned cavities. A single cavity’s results always describe that cavity:
cav.eigenmode.qois is never the tuned version’s.
study.run_tune({'freqs': 1300, 'cell_type': {'mid-cell': 'Req'}})
study.tuned.run_eigenmode()
study.summary() # the tuned cavities, as 'tesla (tuned)', ...
study.summary(tuned=False) # the untuned ones
If a cavity changes after it was tuned, its tuned version belongs to the old
geometry: reading cav.tuned warns, and the study leaves it out until you tune
again.
Settings¶
cav.tune.config_sample returns every setting with its default, and notes what
each one means when it is displayed; Tuning — cav.tune.run / study.run_tune describes them.
freqs(float or list) The target frequency in MHz, or a list with one per cavity.
cell_type(dict) Which dimension to tune, in which cells; see Running it. Without it, the tuner changes the inner cells’
Req, and on a multicell elliptical cavity also the end cells’L.eigenmode_config(dict) The eigenmode settings for the solve at each step, for example
{'mesh_config': {'h': 6, 'p': 2}}.tol(float, default 1e-4) Stop once the frequency is this close to the target, in MHz.
maxiter(int, default 10) The largest number of steps.
rerun(bool, default True)
Falsekeeps a finished tune of the same geometry instead of tuning again.processes(int, default 1) How many cavities of a study to tune at once.
Multicell cavities¶
In a multicell cavity the accelerating mode is the \(\pi\)-mode, and two things must be right: its frequency, and the field, which should be the same in every cell.
The inner cells set the frequency, through the equator radius
Reqthey share.The end cells sit next to the beam pipes, which raise their frequency. Left alone, they take a smaller share of the field, so the field is not flat. Tuning them separately, usually by their length
L, brings them to the same frequency as the inner cells.
List both in one call, and the tuner works through them in order:
cav.tune.run({'freqs': 1300, 'cell_type': {'mid-cell': 'Req', 'end-cell': 'L'}})
Two-cell cavities¶
A symmetric two-cell cavity has a flat field whatever its cells look like, so there
is a whole family of two-cell designs at the target frequency, and tuning each cell
to the target is only one of them. By default a two-cell tune therefore returns
n_family members of that family (default 5), each with the shared Req
re-tuned to keep it on target. cav.tuned is the member whose cells are all at
the target frequency, and cav.tune.family holds them all. cav.tune.family_scan
traces the family for any elliptical cavity.
equal_cell_freq(bool, default False) Return the one design with every cell at the target frequency instead of the family.
n_family(int, default 5) How many members of the family to return.
family_fraction(float, default 0.03) How far the end cells’ length is varied across the family, as a fraction of its starting value.
Two-cell design family: is “each cell at the same frequency” special? compares the members.
Tuning to a figure of merit¶
A figure of merit can be pinned like the frequency. Add it to qoi_targets, and
give the tuner one more dimension to change for each target:
cav.tune.run({
'freqs': 801.58,
'cell_type': {'end-cell': ['Req', 'L']}, # two dimensions to change
'qoi_targets': {'R/Q [Ohm]': 157}, # a second target
})
cav.tune.qois # the frequency and the R/Q reached
qoi_targets takes any figure of merit of the accelerating mode, such as
'R/Q [Ohm]' or 'ff [%]'. Count the dimensions in cell_type and the targets,
the frequency included:
more targets than dimensions cannot be met, and raises an error;
as many targets as dimensions give one design;
fewer targets than dimensions give a family of designs, as a two-cell tune does.
Pin a figure of merit here rather than in an optimisation: an optimisation trades its objectives off against each other, so a target given as an objective is only approached, never met.
Cavities of more than two cells¶
In a cavity of more than two cells, the field flatness is a target of its own, so the
tuner works cell by cell. Give the R/Q of the whole cavity, one dimension for the
inner cells and two for the end cells. The _e suffix names a dimension of both end
cells at once:
cav.tune.run({
'freqs': 801.58,
'qoi_targets': {'R/Q [Ohm]': 450}, # the whole cavity
'cell_type': {'mid-cell': 'Req', # one dimension: frequency only
'end-cell': ['L_e', 'A_e']}, # two: frequency and R/Q
})
The tuner tunes the inner cells to the frequency first, measures their share of the
R/Q, and tunes the end cells to the frequency and the R/Q that remains. Every cell is
at the same frequency, so the field is flat. 'qoi_split': {'end-cell': 90} sets
the end cells’ share yourself.
Two rules apply:
Pin R/Q with a dimension of the end cells alone, such as
A_eorL_e, never withReq: the cells shareReq, so changing it for one cell detunes the others.Not every share can be reached. When a cell cannot reach its target, the tuner stops and says which cell, the share it could not reach and the closest it came;
cav.tune.plot_convergence()shows the steps.
Robust tuning¶
With a uq_config, the tuner brings the mean frequency over a set of manufacturing
variations to the target, rather than the frequency of the nominal cavity; see
Robust tuning.
Tip
An optimisation tunes every candidate to the target frequency before it evaluates the objectives; see Optimisation.