Concepts

This page collects the cross-cutting ideas that the analysis guides assume: how a project is laid out on disk, how the configuration dictionaries work, and how the quantities of interest (QOIs) are defined — including the azimuthal-mode conventions.

Objects

Two objects carry the whole workflow:

  • Study — a container for one or more cavities and the home of multi-cavity actions (run_tune, run_eigenmode, run_wakefield, run_optimisation) and the comparison plots.

  • Cavity and its subclasses (EllipticalCavity, Pillbox, RFGun, SplineCavity) — one simulatable structure.

Each analysis is reached through a namespace attached to the cavity (and, for comparisons, to the study):

cav.eigenmode     # EigenmodeSolver   -> cav.eigenmode.run(...), .qois, .plot_*
cav.wakefield     # WakefieldSolver
cav.tune          # TuneSolver
cav.multipacting  # MultipactingSolver
study.optimisation  # OptimisationSolver

Project folder layout

A study lives in a folder named after the study inside the project directory: Study(project_dir) uses <project_dir>/cavities/, and Study(project_dir, name='run1') uses <project_dir>/run1/. A standalone cavity uses cav.set_workspace(dir), or ./<cavity name>/ by default. Every cavity gets its own folder, and every analysis writes into a subfolder of it:

<project_dir>/cavities/
  <cavity_name>/
    geometry/        # geodata.geo, parameters.json, model.json
    eigenmode/
      monopole/      # qois.json, fields, Ez_0_abs.csv, mesh, geometry_stamp.json
      dipole/        # one folder per solved polarisation (m >= 1)
    wakefield/       # ABCI decks + parsed impedance / wake / QOIs
      uq/            # wakefield UQ: nodes.csv, table.csv, uq.json
    multipacting/    # tracked-particle results, field
    uq/              # eigenmode UQ: nodes.csv, table.csv, uq.json, sobol.json
    tuned/           # a *separate* cavity that hit the tune target
      geometry/  eigenmode/  tune_info/
  optimisation/      # history.csv, pareto_front.csv, candidates/

Each result folder carries a geometry_stamp.json naming the geometry it was computed for; see Keeping results consistent.

cav.tuned loads the cavity under tuned/ (its tune_info/tuned_parameters.json records the complete, self-consistent parameter set the tuner converged on).

Persistence and reloading

Results are written to disk and read back lazily: cav.eigenmode.qois, cav.wakefield.qois and cav.tuned all load from the folders above the first time you touch them, so within a session a completed analysis is never re-run.

An entire project reloads in one call. Each cavity also saves a small geometry/model.json describing its type and parameters, so:

study = Study.load('my_project')     # reconstruct every cavity + its cached results

returns a Study with every cavity reconstructed (the right model type, pointing at its existing folder). All cached results are then available with no re-simulation, and because a loaded Study behaves like any other, two studies — from different sessions, or a loaded one against a fresh one — compare directly (study.eigenmode.qois_df, study.eigenmode.plot_compare()). Custom in-notebook models whose module cannot be imported by name are passed explicitly: Study.load(dir, models={'MyCavity': MyCavity}).

Keeping results consistent

A cavity folder holds results that different analyses wrote at different times. To keep them describing one geometry, every analysis writes a geometry_stamp.json beside its results: a fingerprint of the geometry it solved (model, parameters, cell count, beam pipes, chaining, dielectric regions).

Before an analysis runs, it checks the cavity’s folder:

  • If the run would overwrite existing results, it asks first, naming what it would overwrite. Rerunning one analysis never touches another analysis’ results.

  • If the folder holds results computed for a different geometry, because the cavity changed since they were run or because a different cavity was given the same name, the same question lists them and what changed (for example Req_m 103.3 -> 104). Answering yes deletes them before the run, so the folder never holds results for two geometries. Answering no runs and deletes nothing; to keep both sets, give the cavity a new name or folder.

force=True (or overwrite=True) answers yes without asking. In a script, under nbconvert or in a test there is nobody to ask: a run that only overwrites its own results goes ahead, but one that would leave results for two geometries raises an error and changes nothing. rerun=False reuses results that match the geometry and recomputes those that do not.

Reading results computed for a different geometry, for example after changing cav.parameters without rerunning, gives a warning that says what changed.

overwrite=True on Study(...) and cav.save(...) only replaces a folder that cavsim2d created; anything else raises an error instead of being deleted.

Parameter sweeps

study.sweep(template, {var: values}, mode='tensor'|'hadamard') builds one cavity per parameter combination ('tensor' = the full grid; 'hadamard' = element-wise, requiring equal-length value lists), each in its own folder. It returns a Study, so any analysis runs on the whole family at once; sw.results() joins the swept values with the QOIs into a single comparison table, and sw.sweep_table records which cavity is which, and sw.plot_sweep(...) plots the figures of merit against the swept dimension. Compare designs: studies, sweeps and saved results runs a sweep.

Configuration dictionaries

Every run_* call takes one dictionary. Missing keys fall back to that analysis’ documented defaults, and the merged dict (defaults + your overrides) is saved to config.json beside the results — so a saved run always records every setting it used, not just the keys you passed. Config keys double as keyword arguments. Truthy values (never mere presence) switch features on.

Eigenmode (cav.eigenmode.run / study.run_eigenmode):

{
  'polarisation': 'monopole',   # 'monopole'|'dipole'|... , an m, or a list
  'n_modes': None,              # None -> n_cells + 2
  'mode_of_interest': None,     # 1-based; None -> the accelerating pi-mode
  'boundary_conditions': 'mm',  # magnetic/electric on the two end planes
  'conductivity': 5.96e7,       # [S/m]; or set 'surface_resistance' for SRF
  'mesh_config': {'h': 20, 'p': 3, 'adaptive': None},  # h in mm, p order >= 2
  'uq_config': None,            # attach to propagate geometry uncertainty
}

Setting mesh_config['adaptive'] refines the eigenmode mesh where the solver’s own error estimate is largest. It is a mode of the eigenmode solve — the refined mesh is the eigenmode result, so show_fields/show_mesh/multipacting use it directly and cav.eigenmode.plot_convergence() shows the error-vs-DOF history. Because the wakefield below runs on the ABCI backend (its own deck, meshed from cav.profile()), adaptivity applies to eigenmode/multipacting only.

Wakefield (cav.wakefield.run / study.run_wakefield) — ABCI backend:

{
  'MROT': 2,               # 0 longitudinal, 1 transverse, 2 both
  'wakelength': 50,        # [m]
  'bunch_length': 25,      # [mm]
  'beampipe_length': None, # [m]; None -> 3x the axial length
  'save_fields': None,     # True/{'nshot': N} -> E-field-line snapshots
  'operating_points': None,
  'uq_config': None,
}

Tune (cav.tune.run / study.run_tune):

{
  'freqs': 1300.0,                       # target [MHz] (list for many cavities)
  'cell_type': {'mid-cell': 'Req'},      # {cell block: handle}; schedule several
  'eigenmode_config': {...},             # the solve used at each tuning step
}

See Tuning for the cell-block keys and the multicell mid/end recipe.

UQ (uq_config, nested inside an eigenmode/wakefield/tune config):

{
  'variables': ['Req', 'Ri'],   # geometry variables to perturb
  'delta': [0.05, 0.05],        # spread per variable, added to it [mm; m for an RF gun]
  'method': ['Quadrature', 'Stroud3'],  # uniform +/- delta; ['normal', N]: std delta
  'cell_complexity': 'simplecell',       # or 'multicell' (per-half-cell perturb)
}

Optimisation (study.run_optimisation) — see Optimisation for the full list of GA controls, bounds, objectives and the nested tune_config.

Quantities of interest and mode conventions

Solved fields are reduced to scalar QOIs (written to qois.json). The azimuthal order m sets both which mode is reported and how the QOIs are defined.

  • Monopole (m = 0) — the accelerating family. The reported mode defaults to the pi-mode (mode_of_interest = n_cells, the highest of the fundamental passband). QOIs include freq [MHz], R/Q [Ohm], G [Ohm], Q [], Epk/Eacc [], Bpk/Eacc [mT/MV/m], and — for multicell cavities — the cell-to-cell coupling kcc [%] and field flatness ff [%].

  • m >= 1 (dipole, quadrupole, …) — the deflecting / higher-order-mode families. The reported mode defaults to the lowest of the deflecting passband (mode_of_interest = 1); the accelerating voltage is evaluated off-axis because E_z ~ r^m vanishes on axis. Vacc, Eacc and R/Q then hold the transverse values, and R/Q_t [Ohm/m^(2(m-1))] is normalised so that it does not depend on the radius the voltage is read at (for the dipole it equals R/Q). kcc [%] reuses the monopole passband formula, so it means little for a deflecting passband.

R/Q convention. cavsim2d reports the linac (accelerator) definition \(R/Q = V^2/(\omega U)\). This is twice the circuit definition \(V^2/(2\omega U)\) used in some references (e.g. the TESLA report’s 518 Ohm per cell is the circuit value; cavsim2d reports ~1036 Ohm for the same cell).

Impedance. The eigenmode impedance spectrum sums the contribution of every solved m-pole mode: the longitudinal spectrum is the monopole modes, and the transverse spectrum spans every m >= 1 multipole. Solve the polarisations you want represented before reading the impedance.

Tip

Because the merged config is saved next to every result, the fastest way to see exactly what a run used is to open <cavity>/<analysis>/config.json.

Mode numbering

Within each polarisation, modes are numbered in order of frequency. Where you choose which modes are reported, the numbering counts from 1; everywhere else it counts from 0:

  • From 1: mode_of_interest and the mode field of an objective name ('dipole:2:freq [MHz]' is the second dipole mode; see Objective names). mode_of_interest=1 is the lowest mode, and the monopole default, n_cells, is the pi-mode at the top of the fundamental passband.

  • From 0: cav.show_fields(mode=...), the mode column of cav.eigenmode.qois_df and the multipacting mode setting.

So the accelerating pi-mode of a 9-cell cavity is mode_of_interest=9, the objective 'monopole:9:R/Q [Ohm]', and cav.show_fields(mode=8).

Where modes of several polarisations sit in one table, the key '<m>-<mode>' names a mode: the azimuthal order first, then the mode counted from 0. The mode_index column of cav.eigenmode.qois_df, the keys of cav.eigenmode_qois_all_modes and the per-mode UQ statistics all use it, so '0-0' is the lowest monopole mode and '1-0' the lowest dipole mode.

Objective names

Monopole and m-pole results share QOI names (freq [MHz], R/Q [Ohm], G [Ohm], …), so every UQ and optimisation objective names its polarisation, and can also name a mode:

monopole:R/Q [Ohm]              # the polarisation's (first) mode of interest
dipole:R/Q_t [Ohm/m^(2(m-1))]   # a QOI that only m >= 1 reports
dipole:2:freq [MHz]             # dipole, mode 2 (counting from 1)
1:freq [MHz]                    # the azimuthal order m instead of its name

The separator is :. A bare 'freq [MHz]' raises an error, and so does an objective naming a QOI or a mode the run does not produce; the message lists what is available. Naming a polarisation is enough to have it solved: a UQ run adds it to eigenmode_config['polarisation']. Wakefield objectives (ZL, ZT) take no polarisation.

The same names read a single result: cav.eigenmode.qoi('dipole:2:freq [MHz]') returns the frequency of the second dipole mode. There the unit can be left out ('dipole:2:freq'), as everywhere results are read. An objective in a uq_config or an optimisation names its quantity in full.

mode_of_interest can be an int, a list, or a dict keyed by polarisation:

'mode_of_interest': 9                                        # every polarisation
'mode_of_interest': [1, 2, 3]                                # three, for every one
'mode_of_interest': {'monopole': [1, 2, 3, 4], 'dipole': 1}  # different counts

The first mode listed is the primary one, reported in qois.json. Every listed mode is written to qois_moi.json and can be used as an objective ('monopole:4:freq [MHz]').