Configuration reference

Every analysis is driven by one dictionary. This page lists all of them and all of their keys. See Concepts for the conventions they share:

  • Complete + saved. Missing keys fall back to the analysis’ defaults, and the merged dict (defaults + your overrides) is written to config.json beside the results, so a saved run records every setting it used.

  • Keys double as kwargs. cav.eigenmode.run(mesh_config={'h': 10}) is the same as passing it in the dict; an explicit kwarg wins.

  • Truthy, not present. Features switch on for a truthy value (an empty uq_config={} does not trigger UQ).

Discovering the options

You do not have to memorise these — every default is available at runtime, from the object you are about to run:

  • cav.<solver>.config_sample returns the complete default config of that solver, every key with its default, as a fresh copy to edit and pass straight back: cfg = cav.tune.config_sample, change what you need, then cav.tune.run(cfg). cfg_sample, sample_config and sample_cfg are the same thing, and calling it, cav.tune.config_sample(), works too. The study namespaces have it as well: study.eigenmode.config_sample, study.wakefield.config_sample, study.optimisation.config_sample.

  • cav.config_sample(kind), or cav.cfg_sample(kind), prints the default for kind — 'eigenmode', 'wakefield', 'tune', 'multipacting', 'fds', 'uq' or 'optimisation' — and returns it. study.config_sample(kind) does the same and needs no cavity in the study.

  • cav.<solver>.config is different: it is the saved config of a run that has already happened.

The samples are the solvers’ own defaults — the exact dicts run() merges over — so they never drift from what a run uses. 'uq' and 'optimisation' have no defaults to merge over; their samples are complete, valid templates whose variables, bounds and objectives you replace with your own.

A sample displays with a note beside each key: what it does, its unit, and what None stands for. The display is valid Python, so you can paste it into a script and edit it there:

>>> cav.tune.config_sample
{
    'freqs': None,             # target [MHz]; None -> c/(4L) of the half cell, with a warning
    'cell_type': None,         # None -> {'mid-cell': 'Req'}, plus 'end-cell': 'L' for multicell
    'tol': 0.0001,             # stop once the frequency is this close to the target [MHz]
    ...
}

Units

Not every length is in the same unit. Geometry and mesh sizes are in millimetres, while lengths along the beam line that a solver adds (beam pipes, the wake, the PML) are in metres. The one geometry in metres is the RF gun’s (see RF gun (RFGun)):

Setting

Unit

Where

Geometry parameters (A, Req, L, …), optimisation bounds, UQ delta (additive)

mm

cavity definitions, optimisation, UQ

RF-gun lengths and radii (y1, R6, L7, …), and the bounds and UQ delta of those variables

m

RF gun

RF-gun angles (T2, T9, T10)

rad

RF gun

mesh_config['h'], pec_maxh

mm

eigenmode, multipacting, frequency domain (h)

beam['test_radius']

mm

frequency domain

bunch_length, operating-point 'sigma [mm]'

mm

wakefield

beampipe_length

m

eigenmode, wakefield, frequency domain

wakelength, mesh_config['DDR'] / ['DDZ']

m

wakefield

pml_length

m

eigenmode

xrange

m

multipacting

freqs, tol

MHz

tuning

frequencies

MHz

frequency domain

epks

V/m

multipacting

t_max

s

multipacting

v_init

eV

multipacting

conductivity

S/m

eigenmode

surface_resistance

Ohm

eigenmode

Results carry their unit in the key name instead: 'freq [MHz]', 'R/Q [Ohm]', 'Epk/Eacc []'.

Accepted spellings

A few keys have a second spelling. A run renames it to the key in this reference before it merges the defaults in, so either works:

  • tune: freq is freqs and tolerance is tol; the legacy parameters + cell_types pair becomes cell_type

  • eigenmode: nmodes is n_modes

  • optimisation: no_of_generations is no_of_generation

  • frequency domain: freqs is frequencies

  • every run(): overwrite is force

Giving both spellings with different values raises an error. Any other key a run does not recognise gives a warning that suggests the closest valid key.

Cross-cutting keys

These appear in several configs:

processes

(int, default 1) Worker processes for parallel evaluation (UQ nodes, optimisation candidates, multi-cavity studies).

rerun

(bool, default True) Re-run even if cached results exist; False reuses the results that match the cavity’s geometry and recomputes the rest.

force

(bool, default False) Answer yes to the question a run asks before it overwrites existing results or deletes results computed for a different geometry (see Keeping results consistent). overwrite is the same key.

uq_config

(dict, default None) Nest this inside an eigenmode / wakefield / tune config to turn a single run into an uncertainty sweep — see Uncertainty quantification — nested uq_config.

Eigenmode — cav.eigenmode.run / study.run_eigenmode

polarisation

(str | int | list, default 'monopole' ) The azimuthal order(s) to solve: a name ('monopole', 'dipole', 'quadrupole', …), the integer m, or a list. Every m >= 1 is written to eigenmode/<pol name>/.

mesh_config

(dict, default {'h': 20, 'p': 3, 'adaptive': None} ) h maximum element size in mm; p polynomial order (>= 2); adaptive opt-in error-driven h-refinement. Pass adaptive: True for the defaults, or a dict to tune it: {'tol': 1e-12, 'max_refinements': 8, 'max_ndof': 100000, 'theta': 0.25} — refine the elements whose recovery error exceeds theta of each mode’s largest, until every requested mode’s error is below tol or a DOF/refinement cap is hit. theta: 0 refines every element: uniform, nested refinement. Adaptivity is a mode of the eigenmode solve, not a separate object: the refined mesh is the eigenmode result, so cav.show_fields, cav.show_mesh and cav.multipacting all use it directly, and cav.eigenmode.plot_convergence() plots the error/frequency-vs-DOF history the refinement records.

n_modes / nmodes

(int, default None) Number of eigenmodes to solve. None → n_cells + 2.

mode_of_interest

(int | list | dict, default None) 1-based index of the mode(s) whose QOIs are reported. None → the accelerating pi-mode (monopole) / the lowest deflecting mode (m >= 1).

boundary_conditions

(str, default 'mm' ) One letter per beam-pipe end, left then right: 'm' magnetic wall, 'e' electric wall, 'o' open (PML), 'p' waveguide port ('pp' only, monopole only). 'open' and 'port' are aliases for 'oo' and 'pp'.

n_port_modes

(int, default 3) TM0n pipe modes kept per port with boundary_conditions='port'.

beampipe_length

(float, default None) Length [m] of each beam pipe. None uses the model’s own default: twice the mid-cell length L_m for elliptical cavities.

pml_length

(float, default None) Length [m] of the absorbing layer that 'o' adds to a pipe end. None → three pipe radii.

pml_alpha

(complex, default 1j) Complex stretch of that absorbing layer.

conductivity

(float, default 5.96e7) Wall conductivity [S/m] for the loss-based Q / G.

surface_resistance

(float, default None) Fixed surface resistance [Ohm] override (e.g. for SRF), used instead of conductivity.

beta

(float, default 1) Particle velocity v/c. It sets the phase of the voltage integral, so it changes the accelerating voltage, R/Q, Eacc and the peak-field ratios (and the transverse kick for m ≥ 1), not the field or the frequency. Set it for a β < 1 structure, e.g. 0.6 for a medium-β proton cavity.

materials

(dict, default None) Overrides the properties of dielectric regions declared with cav.add_dielectric, e.g. {'quartz': {'eps_r': 3.8, 'tan_delta': 1e-4}}. Overrides merge, so {'quartz': {'tan_delta': 0.05}} sweeps the loss and leaves eps_r alone. Naming a region the cavity does not have raises.

loss_model

(str, default None) How a complex permittivity reaches Q: 'lossless' (real eigenproblem, dielectric loss added perturbatively), 'lossy' (full complex eigenproblem), or None / 'auto' — inspect the loss tangents and switch to 'lossy' above tan_delta = 1e-2. Forcing 'lossless' above that threshold is honoured, with a warning. Q is tagged 'Q model' in the QOIs.

arnoldi_vectors

(int, default 6) Krylov vectors per shift in the lossy eigensolve.

f_shift

(float, default 0) Spectral shift for the eigensolver.

pinvit_tol

(float, default 1e-8) The eigensolver stops once the relative residual of every checked mode is below this. At 1e-8 frequencies are converged to about 1e-13 and the fields, and every figure of merit computed from them, to about 3e-7: below the discretisation error of any practical mesh. A looser value is faster; see Solver settings: time against accuracy for what each value buys. Round-off sets a floor under the residual, and on meshes with very small elements near the axis that floor can lie above 1e-8. The eigensolver then stops once the residual stops falling. It warns only if the floor is above 1e-5.

pinvit_converge_modes

(int, default None) How many of the lowest modes must meet pinvit_tol. None checks all n_modes. Modes above the checked ones are still reported, but are not converged: check fewer modes only when you will not use the rest.

pinvit_padding

(int, default None) Extra vectors the eigensolver iterates on beyond n_modes. They are never reported, but they make the highest requested modes converge in far fewer iterations. None uses twice n_modes, at least 2 and at most 30.

pinvit_maxit

(int, default 1000) Iteration cap. A solve that reaches it while the residual is still falling warns.

preconditioner

(str, default 'direct' ) The eigensolver’s preconditioner: 'direct', an exact factorisation, or 'bddc', an approximate one that is cheaper per iteration but needs more iterations to reach the same tolerance.

direct_solver

(str, default 'sparsecholesky' ) The sparse direct solver used for every factorisation in the eigensolve. Any backend your NGSolve build provides: 'sparsecholesky' is always available; 'pardiso' and 'umfpack' depend on how NGSolve was built.

normalization_length

(float, default None) Active length for the accelerating-voltage normalisation; elliptical cavities take it from L_m automatically.

Wakefield — cav.wakefield.run / study.run_wakefield

MROT

(int, default 2) 0 longitudinal, 1 transverse, 2 both.

wakelength

(float, default 50) Wake length [m].

bunch_length

(float, default 25) RMS bunch length [mm].

beampipe_length

(float, default None) Beam-pipe length [m]; None → 3× the axial length.

save_fields

(bool | dict, default None) True (or {'nshot': N}) saves electric field-line snapshots for the field animation.

operating_points

(dict, default None) Machine operating points (currents, bunch populations, bunch lengths) to fold into loss/kick-factor and HOM-power tables.

solver

(str, default 'abci' ) The wakefield backend.

MT

(int, default 10) ABCI time steps per mesh cell. Values above 19, ABCI’s limit, are clamped to 19.

DDR_SIG, DDZ_SIG

(float, default 0.1) Radial / axial mesh step as a fraction of the bunch length, capped at 1.25 mm, so a short bunch is always resolved. An explicit mesh_config={'DDR': ..., 'DDZ': ...} (metres) overrides them.

Note

Adaptive refinement does not apply to wakefield. mesh_config['adaptive'] drives the NGSolve eigenmode backend (and, through it, multipacting, which reads the eigenmode field). Wakefield uses the ABCI backend, which builds and meshes its own deck from cav.profile() and is controlled by MT/DDR_SIG/ DDZ_SIG above — it has no NGSolve mesh to refine, so the eigenmode adaptive / h / p keys are ignored there. This is a backend boundary, not a limitation of a particular geometry.

Frequency domain — cav.fds.run

See Frequency-Domain Analysis for the stages (run, reduce, concatenate) and their outputs.

frequencies

(list, required) [f_min, f_max, n] in MHz, or a list of frequencies [MHz]. freqs is accepted too.

polarisation

(str | int | list, default 'monopole' ) The azimuthal order(s), as for the eigenmode solver. The monopole gives the longitudinal impedance, the dipole the transverse one.

n_port_modes

(int | dict, default 3) Pipe modes carried at each port, per family: 3 carries three TM and three TE modes; {'TM': n, 'TE': n} sets them separately. Every mode that propagates below the highest frequency must be carried; the solver warns when one is not.

beam

(None | True | dict, default None) Adds the beam, for the generalised matrices and the beam coupling impedance: True, or {'beta': 1, 'reference': 'auto', 'test_radius': None} with test_radius in mm.

mesh_config

(dict, default {'h': 20, 'p': 3} ) Largest element size h [mm] and polynomial order p, as for the eigenmode solver.

beampipe_length

(float, default None) Pipe length [m] at each open end. None uses the model’s own default.

materials

(dict, default None) Overrides the properties of regions declared with cav.add_dielectric(), as for the eigenmode solver. A loss tangent makes the matrices complex.

strategy

(str, default 'glued' ) For an Assembly: 'glued' meshes the whole line as one model; 'coupled' solves each element on its own, to be reduced and joined through its port modes.

store_snapshots

(bool, default False) Keeps every solution of the sweep, so that reduce() uses them instead of solving at its own frequencies.

reduce

(dict, default None) {'tol': 1e-8, 'n_snapshots': 12} reduces (and, for strategy='coupled', joins) right after the sweep.

direct_solver

(str, default 'sparsecholesky' ) The sparse direct solver used at every frequency, as for the eigenmode solver.

progress

(bool, default True) Progress bar over the frequencies.

Tuning — cav.tune.run / study.run_tune

freqs

(float | list, default None) Target frequency [MHz] (a list gives a per-cavity target). None tunes an elliptical cavity to the pi-mode estimate \(c/4L\) of its half-cell length, with a warning; other models need it.

cell_type

(dict, default None) {cell block: handle}, e.g. {'mid-cell': 'Req'}. Schedule several blocks ({'mid-cell': 'Req', 'end-cell': 'L'}) to tune them in turn — see Tuning. None tunes the mid-cell Req, plus the end-cell L on a multi-cell elliptical cavity.

eigenmode_config

(dict) The eigenmode settings used for the solve at each tuning step.

solve_tuned

(bool, default False) After tuning, also run the eigenmode analysis on the tuned cavity (cav.tuned) with eigenmode_config.

tol

(float, default 1e-4) Frequency tolerance [MHz]: the secant stops once the frequency is this close to the target.

maxiter

(int, default 10) Maximum secant iterations.

Multipacting — cav.multipacting

Emission sites are set with cav.multipacting.set_emission_points(xrange, ...) (or xrange / n_points in the config); the rest are run() keys:

mode

(int, default 0) Which computed mode to track (0 = the first).

polarisation / n_modes

(default None) Solve multipacting’s own field for this polarisation / this many modes (None → reuse the monopole eigenmode field).

epks

(array, default None) Peak-field levels [V/m] to sweep (None → 0–80 MV/m, 192 steps).

phis

(array, default None) RF launch phases (None → 72 phases over [0, 2*pi]).

v_init

(float, default 2) Secondary-emission energy [eV].

t_max

(float, default 1e-7) Tracking duration [s].

loss_model

(str, default 'field' ) How escaped particles are handled.

pec_maxh

(float, default None) If set [mm], multipacting builds its own finer field on a mesh this size (with mesh_config) instead of reusing the eigenmode one.

n_points

(int, default None) Extra emission sites interpolated along the wall in-band.

proc_count

(int, default None) Worker count (None → auto).

progress

(bool, default True) Live progress bar over the field-level sweep.

Uncertainty quantification — nested uq_config

Nest inside an eigenmode / wakefield / tune config to sweep the uncertain geometry.

variables

(list of str) Geometry variables to perturb, in that model’s own names (['Req', 'Ri'] for elliptical, ['p2_r'] for spline, …).

delta

(list of float) The spread of each variable, added to it in the variable’s own unit (mm; m for an RF gun), not a fraction: delta=0.3 is a spread of 0.3 mm. With a quadrature rule or ['lhs', N] it is the half-width of a uniform spread, x - delta to x + delta (standard deviation delta / sqrt(3)); with ['normal', N] it is the standard deviation. A spread far below the solver’s numerical resolution leaves the result unchanged.

perturbation_mode

(str, default 'add' ) 'add' → x + d (in the variable’s unit); 'mul' → x * (1 + d) (d a fraction). ['add', d] or ['mul', d] gives the spread here instead of in delta.

method

(list) How the perturbed shapes are chosen: ['Quadrature', 'Stroud3'] (default) or 'Stroud5', Monte Carlo with a normal spread ['normal', N], or Latin hypercube ['lhs', N]. The method sets the distribution; there is no separate distribution key (a config that sets one is told it is not read).

cell_complexity

(str, default 'simplecell' ) 'simplecell' perturbs the mid/end-cell groups; 'multicell' makes every half-cell an independent random variable (honouring continuity). Available for eigenmode and wakefield.

independent_half_cells

(bool, default False) Multicell only: perturb every half-cell independently then weld (average) the shared seams — the WEPB015 before/after-continuity workflow.

cell

(default 'all' ) Simplecell eigenmode and wakefield UQ: 'all' varies each variable in every cell type separately ('A' -> A_m, A_el, A_er); any other value takes the variables exactly as named (['A_m']).

cell_type

(str, default 'mid-cell' ) Robust tuning: the cell type whose variables vary.

objectives

(list) The QOIs to gather: 'pol:qoi' for eigenmode ('monopole:R/Q [Ohm]'), or ['min', 'ZL', [lo, hi]] / ['min', 'ZT', ...] for wakefield impedance (the interval is a flat [lo, hi, …] GHz list defining consecutive windows).

tune_config

(dict, default None) Re-tune each perturbed variant to a target frequency before measuring, so only the shape varies at fixed frequency (the paper workflow).

Optimisation — study.run_optimisation

bounds

(dict) {variable: [lo, hi]} in that model’s own variable names (mm). A fixed variable takes equal bounds.

objectives

(list of lists) [direction, metric, ...] — direction 'min' / 'max' / 'equal'; metric a polarisation-qualified QOI ('monopole:Epk/Eacc []') or a wakefield 'ZL' / 'ZT' with a frequency-interval third element.

tune_config

(dict) Applied to every candidate so each is on-frequency before its objectives are read.

initial_points

(int) Initial candidates before the GA evolves.

no_of_generation

(int, default 100) Number of GA generations (no_of_generations also works).

method

(dict, default LHS) Initial-point sampler, e.g. {'LHS': {'seed': 5}}.

crossover_factor / mutation_factor / chaos_factor

(int) How many offspring come from crossover, mutation and random injection each generation.

elites_for_crossover

(int) Top candidates retained in the parent pool.

weights

(list) Per-objective weights.

seed

(int) Makes the run reproducible.