10. Uncertainty quantification

No cavity is built exactly to its drawing. Uncertainty quantification asks how far the figures of merit spread when the dimensions vary within their tolerances. In cavsim2d you add a uq_config to an ordinary run, and get a mean and a standard deviation for each figure of merit instead of a single value.

In this tutorial you will:

  1. Describe the tolerances: which dimensions vary, and by how much.

  2. Run the eigenmode analysis over the perturbed shapes.

  3. Read the mean and the spread of each figure of merit.

  4. Plot them against the nominal design.

Before you start: work through Compare designs. Running the whole notebook takes about a minute.

1. The tolerances

A uq_config says what varies and how the variation is sampled:

  • variables: the dimensions that vary, by the names the cavity uses for them.

  • delta: how much each one varies, in millimetres, added to its nominal value.

  • method: how the perturbed shapes are chosen. ['Quadrature', 'Stroud3'] needs only a few solves, twice the number of independent dimensions. With it, each dimension varies evenly between -delta and +delta, a uniform spread whose standard deviation is delta divided by \(\sqrt{3}\). For a normal (Gaussian) spread with standard deviation delta, use ['normal', N], which takes N solves.

  • objectives: the figures of merit to collect, named as in an optimisation.

Here the two equator half-axes, A and B, vary by up to 0.2 mm. Each half of the cell gets its own tolerance, because in practice each half is formed separately.

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('cell_tolerances')
study.add_cavity(EllipticalCavity(1, mid_cell, beampipe='none'), names='tesla_cell')

uq_config = {
    'variables': ['A', 'B'],
    'delta': [0.2, 0.2],                              # mm
    'method': ['Quadrature', 'Stroud3'],
    'objectives': ['monopole:freq [MHz]', 'monopole:R/Q [Ohm]',
                   'monopole:Epk/Eacc []', 'monopole:Bpk/Eacc [mT/MV/m]'],
}

2. Run it

The same run_eigenmode() call as before, with the uq_config added. cavsim2d solves the nominal cell and every perturbed shape the method asks for, then combines the results.

study.run_eigenmode({'uq_config': uq_config});

3. The spread

cav.eigenmode.uq_df is a table of the statistics, one row per objective: the nominal cell’s value, the mean over the perturbed shapes, and their standard deviation, std. It also has the skew and the kurtosis of each distribution.

study['tesla_cell'].eigenmode.uq_df[['nominal', 'mean', 'std']].round(4)
nominal mean std
objective
monopole:freq [MHz] 1300.2019 1300.2005 0.5513
monopole:R/Q [Ohm] 113.4697 113.4701 0.0628
monopole:Epk/Eacc [] 1.9925 1.9930 0.0061
monopole:Bpk/Eacc [mT/MV/m] 4.1711 4.1707 0.0042

Tolerances of up to 0.2 mm on A and B spread the frequency by 0.55 MHz, one standard deviation, around a mean of 1300.20 MHz. R/Q spreads by 0.06 Ohm, Epk/Eacc by 0.006 and Bpk/Eacc by 0.004 mT/(MV/m). Every mean is within one standard deviation of the nominal value.

4. Plot it

plot_fm_scatter(uq=True) draws each figure of merit’s mean with a bar of one standard deviation either side, beside the nominal design, and writes the mean and the standard deviation in the corner of each panel. show_stats=False leaves the numbers out.

study.eigenmode.plot_fm_scatter(uq=True, qois=['freq', 'R/Q', 'Epk/Eacc', 'Bpk/Eacc']);
../_images/b74eeead81db01a144cbedd401b797e4d91295d99af1b8569436e2a1f3133de7.png

Each bar is the spread of the perturbed shapes, one standard deviation either side of the mean, and the numbers in the corners are those of the table above. The nominal design sits inside every bar.

What you learned

  • A uq_config added to a run turns each figure of merit into a mean and a standard deviation.

  • delta is added to each dimension, in millimetres; with a quadrature rule it is the half-width of a uniform spread, with ['normal', N] the standard deviation.

  • cav.eigenmode.uq_df holds the statistics, study.eigenmode.uq_df those of every cavity in the study, and plot_fm_scatter(uq=True) plots them.

  • The same uq_config works in a tune, a wakefield run and an optimisation: see the UQ guide.

Next

Beam lines: join pipes, tapers, bellows and cavities into one structure.