9. Shape optimisation

Lowering one figure of merit usually raises another: a cell shape with a lower peak electric field tends to have a higher peak magnetic field. An optimisation searches the shapes for the best trade-offs, the Pareto front, so you can choose among designs that cannot be improved in one figure of merit without losing in another.

In this tutorial you will:

  1. Say which dimensions may vary and which figures of merit to minimise.

  2. Run a small search, with every candidate tuned to 1300 MHz.

  3. Read and plot the Pareto front.

  4. Follow how the search progressed.

Before you start: work through Tune a cell to a target frequency and Compare designs. Running the whole notebook takes a few minutes.

An optimisation runs on a study, using the cavity in it as the template: every candidate is a copy with different dimensions.

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

The configuration says three things:

  • bounds: the dimensions that may vary, each with its range in millimetres. The rest keep the template’s values. Choose ranges that give a valid cell throughout: here A + a stays below the half-cell length L, 57.7 mm, so the two ellipses always fit side by side.

  • objectives: what to minimise or maximise. Each is ['min', name] or ['max', name], and a figure of merit’s name starts with its polarisation, 'monopole:', because the dipole modes have figures of merit with the same names.

  • tune_config: every candidate is tuned to 1300 MHz through its equator radius before its figures of merit are read, so the candidates are compared at the same frequency. That is why Req is not among the bounds.

The search starts from initial_points random candidates, then breeds new ones from the best for no_of_generation generations. mutation_factor, crossover_factor and chaos_factor are the numbers of new candidates made each generation by mutation, by crossing two parents, and at random.

config = {
    'bounds': {'A': [40, 44], 'B': [40, 46], 'a': [10, 13], 'b': [17, 21]},
    'objectives': [['min', 'monopole:Epk/Eacc []'],
                   ['min', 'monopole:Bpk/Eacc [mT/MV/m]']],
    'tune_config': {'freqs': 1300, 'cell_type': {'mid-cell': 'Req'}},
    'initial_points': 10,
    'no_of_generation': 2,
    'mutation_factor': 3, 'crossover_factor': 3, 'chaos_factor': 2,
    'elites_for_crossover': 2,
    'method': {'LHS': {'seed': 5}},        # the initial candidates, repeatably
    'seed': 5,                             # and the rest of the search
}

2. Run it

study.run_optimisation(config)
opt = study.optimisation
print(f'{len(opt.history)} candidates evaluated, {len(opt.pareto)} on the Pareto front')
  0%|          | 0/2 [00:00<?, ?it/s]
 50%|█████     | 1/2 [00:36<00:36, 36.56s/it]
100%|██████████| 2/2 [00:58<00:00, 28.14s/it]
100%|██████████| 2/2 [00:58<00:00, 29.41s/it]
18 candidates evaluated, 8 on the Pareto front

Of the 18 candidates evaluated, 8 make up the Pareto front.

3. The Pareto front

A candidate is on the Pareto front when no other candidate is better in both objectives at once. plot_pareto() draws the front in objective space.

opt.plot_pareto(kind='scatter', normalise=False);
../_images/3a25a4c3b89946a837e92eb6eca43aad170cfe3fe79f29e2a71779fa3e3aad9c.png

Moving along the front trades one peak field for the other. At one end Epk/Eacc is 1.967 with Bpk/Eacc 4.224; at the other, 1.998 with 4.095. Which design is best depends on what limits your cavity, the electric field or the magnetic one.

opt.pareto is a table of the front: each design’s dimensions, the tuned equator radius, and its objectives.

columns = ['A', 'B', 'a', 'b', 'Req'] + opt.objective_vars
opt.pareto[columns].sort_values('monopole:Epk/Eacc []').round(3)
A B a b Req monopole:Epk/Eacc [] monopole:Bpk/Eacc [mT/MV/m]
6 41.000 41.500 12.250 20.000 103.723 1.967 4.224
5 40.921 40.609 12.696 17.616 103.320 1.968 4.203
7 41.000 40.900 12.850 17.200 103.254 1.977 4.201
3 42.776 45.171 12.324 17.657 103.341 1.988 4.167
4 42.985 45.743 12.259 17.675 103.360 1.991 4.164
2 43.000 45.700 12.250 17.600 103.344 1.993 4.163
0 43.400 41.500 12.550 18.800 102.470 1.997 4.101
1 43.497 41.277 12.542 18.972 102.403 1.998 4.095

Every design on the front was tuned to 1300 MHz, each to its own equator radius, from 102.40 to 103.72 mm.

4. How the search progressed

opt.history holds every candidate evaluated; plot_history() draws them all, coloured by the generation they belong to.

opt.plot_history(color_by_gen=True, normalise=False);
../_images/63ac85eca8e8c9187bd60a12f9d635f180879e8c891d71ecc076b7e908ba024e.png

The initial candidates (generation 0) spread widely. Most of those bred from the best of them (generation 1) land close to the front, at the low-field side of the plot. A real search runs for more generations, with more candidates in each.

What you learned

  • study.run_optimisation() searches the dimensions in bounds for the best trade-offs between the objectives.

  • tune_config keeps every candidate at the target frequency, so they are compared fairly.

  • opt.pareto and opt.plot_pareto() give the Pareto front; opt.history and opt.plot_history() every candidate.

  • Objectives are named 'monopole:<figure of merit>'.

Next

Uncertainty quantification: how manufacturing tolerances spread a design’s figures of merit.