API Reference

The public API is what from cavsim2d import ... exposes: the study container, the cavity models, and the analysis solver namespaces. Internal modules are documented in their own docstrings but are not part of the supported surface.

Study

Cavity models

All models inherit the run / tune / plot machinery from Cavity and add their own geometry parameterisation and tuning handles.

Beam-line elements

Devices that concatenate into a beam line with +. See Joining devices.

Analysis namespaces

Reached as cav.eigenmode, cav.wakefield, cav.fds, cav.tune, cav.multipacting and study.optimisation.

Result objects

class cavsim2d.solvers.eigenmode_result.EigenmodeResult(index, frequency, m, qois, field_data=None)[source]

Bases: object

A single eigenmode with unified azimuthal mode number.

index

Mode index within the solve.

Type:

int

frequency

Resonant frequency in MHz.

Type:

float

m

Azimuthal mode number (0 = monopole, 1 = dipole, …).

Type:

int

qois

Quantities of interest for this mode. Reads accept short names (qois['R/Q']), as QOIDict does.

Type:

dict

Reading results by name

Every result dict (cav.eigenmode.qois, cav.wakefield.qois, …) and the study tables (study.summary(), study.results()) read a quantity by its full name or a short one. These are the rules.

Names of the quantities of interest, and reading a result by a short name.

Every result dict keys its numbers by a name that carries the unit: 'R/Q [Ohm]', 'Epk/Eacc []', '|k_loss| [V/pC]'. Those are the canonical names: tables show them and the result files store them. To read a quantity, the name without its unit is enough ('R/Q', 'Epk/Eacc', 'k_loss'), in any letter case ('r/q'), and a few common short forms are understood as well (ALIASES: 'f', 'epk' for Epk/Eacc, the old attribute names 'R_Q' and 'k_cc', …).

A unit, when one is given, must be the stored one, so 'freq [GHz]' is refused instead of being read in MHz. A name that matches no key, or several, raises QOIKeyError naming the closest keys.

The lookup tries, in order, and the first step that matches decides:

  1. the name exactly as stored;

  2. the name without its unit, in the same letter case;

  3. a short form from ALIASES;

  4. the name without its unit, in any letter case.

cavsim2d.utils.qoi_names.ALIASES = {'b_pk': 'Bpk/Eacc', 'bpk': 'Bpk/Eacc', 'bpk_eacc': 'Bpk/Eacc', 'e_pk': 'Epk/Eacc', 'epk': 'Epk/Eacc', 'epk_eacc': 'Epk/Eacc', 'f': 'freq', 'field_flatness': 'ff', 'fieldflatness': 'ff', 'flatness': 'ff', 'frequency': 'freq', 'g*r/q': 'GR/Q', 'g.r/q': 'GR/Q', 'gr_q': 'GR/Q', 'grq': 'GR/Q', 'k_cc': 'kcc', 'kfm': 'k_FM', 'kkick': 'k_kick', 'kloss': 'k_loss', 'phom': 'P_HOM', 'r_q': 'R/Q', 'roq': 'R/Q', 'rq': 'R/Q'}

Short forms, in lower case without spaces or absolute-value bars, and the name (without its unit) each stands for. 'epk' and 'bpk' are the normalised peak fields e_pk = Epk/Eacc and b_pk = Bpk/Eacc of the SRF literature; 'Epk' itself is the peak field, 'Epk [MV/m]', wherever the results hold it.

cavsim2d.utils.qoi_names.FIGURES_OF_MERIT = ('freq [MHz]', 'R/Q [Ohm]', 'ff [%]', 'G [Ohm]', 'GR/Q [Ohm^2]', 'Epk/Eacc []', 'Bpk/Eacc [mT/MV/m]', 'kcc [%]', 'Q []', 'Rsh [MOhm]')

The eigenmode figures of merit a design is judged by, in the order tables list them: field flatness beside frequency and R/Q.

class cavsim2d.utils.qoi_names.QOIDict[source]

A result dict that also answers to short names.

Its keys, iteration, length and JSON form are the canonical names exactly as stored. Reading accepts the short names resolve() understands, so qois['R/Q'] is qois['R/Q [Ohm]'], qois.get('ff') and 'ff' in qois work the same way, and a name that matches nothing raises a QOIKeyError that lists the closest names.

get(key, default=None)[source]

Return the value for key if key is in the dictionary, else default.

exception cavsim2d.utils.qoi_names.QOIKeyError[source]

A quantity name that matches no key of a result, or more than one.

cavsim2d.utils.qoi_names.find(name, keys)[source]

Like resolve(), but None instead of an error.

cavsim2d.utils.qoi_names.resolve(name, keys)[source]

The key of keys that name reads (see the module notes for the rules).

Raises QOIKeyError when name matches no key, several keys, or a key in another unit.

>>> resolve('R/Q', ['freq [MHz]', 'R/Q [Ohm]'])
'R/Q [Ohm]'
cavsim2d.utils.qoi_names.resolve_many(names, keys)[source]

The keys names read, in order and without repeats. A single string is one name. Raises QOIKeyError for the first name that reads nothing.