6. Compare designs: studies, sweeps and saved results¶
Design work means comparing many cavities. A Study holds several cavities in one project folder, runs an analysis on all of them at once, and compares the results. A sweep builds a study from one cavity by varying its dimensions. Everything is saved as it is computed, so a project can be reopened later without solving anything again.
In this tutorial you will:
Put three cells with different iris radii in a study and solve them together.
Compare their figures of merit.
Sweep two dimensions over a grid of values.
Plot the figures of merit against a swept dimension.
Reopen a saved project without solving again.
Before you start: work through An elliptical cavity. Running the whole notebook takes about a minute.
1. A study of three cells¶
Study('iris_study') creates a project folder, ./iris_study/. add_cavity puts
cavities in it, each under the name you give it; each cavity’s results go into a
folder of that name, under ./iris_study/cavities/. Here are three TESLA cells that differ only in their iris radius
Ri, the fifth dimension.
from cavsim2d import Study, EllipticalCavity
mid_cell = [42, 42, 12, 19, 35, 57.7, 103.353] # A, B, a, b, Ri, L, Req [mm]
study = Study('iris_study')
for Ri in (30, 35, 40):
cell = list(mid_cell)
cell[4] = Ri
study.add_cavity(EllipticalCavity(1, cell, beampipe='none'), names=f'Ri_{Ri}')
study.run_eigenmode();
study.run_eigenmode() solves every cavity in the study, with the same settings
cav.eigenmode.run() takes. Each cavity is still reachable on its own:
study['Ri_35'] is the second one.
2. Compare the figures of merit¶
study.summary() puts every result of each cavity’s accelerating mode in one table,
with the figures of merit first. Pass it the columns you want to see. A name can
leave its unit out: 'R/Q' is the column 'R/Q [Ohm]', and 'freq' is
'freq [MHz]'. study.eigenmode.plot_fm_scatter() draws the same figures side by
side.
study.summary(['freq', 'R/Q', 'G', 'Epk/Eacc', 'Bpk/Eacc']).round(3)
| freq [MHz] | R/Q [Ohm] | G [Ohm] | Epk/Eacc [] | Bpk/Eacc [mT/MV/m] | |
|---|---|---|---|---|---|
| Ri_30 | 1280.905 | 127.917 | 264.391 | 1.846 | 3.933 |
| Ri_35 | 1300.202 | 113.470 | 271.066 | 1.992 | 4.171 |
| Ri_40 | 1323.745 | 100.159 | 279.578 | 2.307 | 4.449 |
study.eigenmode.plot_fm_scatter(qois=['freq', 'R/Q', 'Epk/Eacc', 'Bpk/Eacc']);
Opening the iris from 30 to 40 mm raises the frequency from 1280.9 to 1323.7 MHz, lowers R/Q from 127.9 to 100.2 Ohm, and raises both peak-field ratios. The iris size is a trade-off between the opening the beam passes through and the cell’s performance.
3. A sweep¶
Building variants by hand is fine for three. study.sweep() builds them for you: give
it a template cavity and the values of each dimension to vary. By default it builds
every combination, here 3 x 3 = 9 cells. It returns a new study, kept in a sweep
folder inside the project.
template = EllipticalCavity(1, mid_cell, beampipe='none')
sweep = study.sweep(template, {'Req': [101, 103.353, 105], 'Ri': [33, 35, 37]})
sweep.run_eigenmode()
print('saved in', sweep.projectDir)
saved in iris_study\cavities\sweep
sweep.results() is the same table with the swept values in front, one row per
cell, and it takes the same column names:
sweep.results(['Req', 'Ri', 'freq', 'R/Q', 'Epk/Eacc']).round(3)
| Req | Ri | freq [MHz] | R/Q [Ohm] | Epk/Eacc [] | |
|---|---|---|---|---|---|
| Req101_Ri33 | 101.000 | 33 | 1325.933 | 119.109 | 1.918 |
| Req101_Ri35 | 101.000 | 35 | 1334.513 | 113.522 | 1.983 |
| Req101_Ri37 | 101.000 | 37 | 1343.787 | 108.119 | 2.136 |
| Req103p353_Ri33 | 103.353 | 33 | 1291.983 | 119.135 | 1.920 |
| Req103p353_Ri35 | 103.353 | 35 | 1300.202 | 113.470 | 1.992 |
| Req103p353_Ri37 | 103.353 | 37 | 1309.103 | 107.987 | 2.085 |
| Req105_Ri33 | 105.000 | 33 | 1269.147 | 119.069 | 1.922 |
| Req105_Ri35 | 105.000 | 35 | 1277.116 | 113.356 | 1.985 |
| Req105_Ri37 | 105.000 | 37 | 1285.755 | 107.825 | 2.085 |
Each row is named after its values. Each millimetre of Req lowers the frequency
by about 14 MHz and leaves R/Q almost unchanged; Ri changes R/Q and the peak
fields as well.
4. Plot against a swept dimension¶
sweep.plot_sweep() draws each figure of merit against one swept dimension, with one
line for each value of the other.
sweep.plot_sweep('Req', ['freq', 'R/Q', 'Epk/Eacc']);
The frequency falls along a straight line as Req grows, by about the same amount
for every iris. R/Q and Epk/Eacc depend far more on the iris than on Req: the
three lines are well apart and close to flat.
5. Reopen a saved project¶
Every cavity saved its geometry and results as it went. Study.load() rebuilds a
project from its folder, with every result read back from disk: nothing is solved
again. This is how you pick up a project in a later session.
reopened = Study.load(sweep.projectDir)
reopened.summary(['freq', 'R/Q']).round(3)
| freq [MHz] | R/Q [Ohm] | |
|---|---|---|
| Req101_Ri33 | 1325.933 | 119.109 |
| Req101_Ri35 | 1334.513 | 113.522 |
| Req101_Ri37 | 1343.787 | 108.119 |
| Req103p353_Ri33 | 1291.983 | 119.135 |
| Req103p353_Ri35 | 1300.202 | 113.470 |
| Req103p353_Ri37 | 1309.103 | 107.987 |
| Req105_Ri33 | 1269.147 | 119.069 |
| Req105_Ri35 | 1277.116 | 113.356 |
| Req105_Ri37 | 1285.755 | 107.825 |
The reopened study has the same nine cells and the same results, read from
./iris_study/cavities/sweep/.
What you learned¶
A
Studykeeps several cavities in one project folder;add_cavity()adds them under names you choose.study.run_eigenmode()solves them all, andstudy.summary()andstudy.eigenmode.plot_fm_scatter()compare them.A result is named with or without its unit:
'R/Q'or'R/Q [Ohm]'.study.sweep()builds a study over a grid of dimensions;results()andplot_sweep()read it.Study.load()reopens a saved project without solving again.
Next¶
Wakefields and impedance: what a bunch of charge leaves behind as it passes through a cavity.