Skip to main content

cavsim2d

Documentation PyPI Python License: MIT Status: beta

Documentation: dark-elektron.github.io/cavsim2d, with installation, a quickstart, step-by-step tutorials, a guide to every analysis and the API reference.

cavsim2d is a Python toolkit for designing and analysing axisymmetric RF cavities, such as the elliptical cavities of superconducting linacs, pillboxes, RF guns or a shape of your own. Because the structures are axisymmetric, it works on their 2D cross-section, so it runs on an ordinary computer: an eigenmode solve of a cell takes seconds.

What you can do with it

  • Eigenmodes: resonant frequencies, fields and figures of merit (R/Q, G, Q, Epk/Eacc, Bpk/Eacc, field flatness, cell-to-cell coupling) of the accelerating mode and of the dipole, quadrupole and higher-order modes, with open beam pipes for the external Q and dielectric or lossy inserts.
  • Tuning: adjust a dimension until the cavity resonates at a target frequency, tune the end cells of a multicell cavity for a flat field, or tune to a frequency and a figure of merit together.
  • Wakefields and impedance: the wake potentials, loss and kick factors and impedance spectra a bunch leaves behind, computed with the ABCI code.
  • Frequency domain: impedance, admittance and scattering matrices and the beam coupling impedance, with reduced models for fast sweeps.
  • Multipacting: track electrons at the wall to find the field levels where an electron avalanche can build up.
  • Shape optimisation: search for the best trade-offs between objectives such as the peak surface fields and R/Q.
  • Uncertainty quantification: propagate manufacturing tolerances through any of the above.
  • Beam lines: join pipes, tapers, bellows, absorbers and cavities into one structure with +.

Cavity shapes

Model What it is Parameters
EllipticalCavity Elliptical cells, single or multicell [A, B, a, b, Ri, L, Req] per half-cell, in mm
EllipticalCavityFlatTop Elliptical cells with a flat equator the same, plus the flat length l
Pillbox Cylindrical cells [L, Req, Ri, S, L_bp], in mm
SplineCavity A free-form wall through Bézier control points p0 to p5, each [z, r] in mm
RFGun A photoinjector or VHF gun named segment lengths, radii and angles, in metres and radians
Beampipe, Taper, Bellows, BLA Beam-line elements, joined with + in mm

Every model runs every analysis. To add a shape of your own, subclass Cavity and describe its wall once; see Writing a new cavity model. The parameters are explained, with figures, in the geometry guide.

Installation

pip install cavsim2d

cavsim2d needs Python 3.10 or newer. NGSolve, the finite-element library it solves with, and gmsh are installed with it. To run the example notebooks, install the Jupyter extra as well:

pip install "cavsim2d[jupyter]"

Wakefield analyses use ABCI, a free code from KEK that cavsim2d may not redistribute: download it from the ABCI page and set the CAVSIM2D_ABCI environment variable to the executable, as the installation guide describes. Everything else works without it.

A first simulation

Build one elliptical cell and solve for its modes. The examples are written for a Jupyter notebook, where the plots appear inline.

from cavsim2d import EllipticalCavity

# One elliptical cell: [A, B, a, b, Ri, L, Req] in mm
cell = [42, 42, 12, 19, 35, 57.7, 100.0]
cav = EllipticalCavity(1, cell, beampipe='none', name='my_cell')

cav.plot('geometry')                  # the cell's half cross-section

cav.eigenmode.run()                   # solve its monopole modes
qois = cav.eigenmode.qois             # figures of merit of the accelerating mode
print(f"{qois['freq [MHz]']:.1f} MHz, R/Q = {qois['R/Q [Ohm]']:.1f} Ohm, "
      f"G = {qois['G [Ohm]']:.1f} Ohm, Epk/Eacc = {qois['Epk/Eacc []']:.2f}")
1349.6 MHz, R/Q = 113.5 Ohm, G = 279.0 Ohm, Epk/Eacc = 1.99

The cell resonates above 1300 MHz. Tune its equator radius Req to bring it onto 1300 MHz:

cav.tune.run({'freqs': 1300, 'cell_type': {'mid-cell': 'Req'}})

tuned = cav.tuned                     # a new cavity, saved beside the original
tuned.eigenmode.run()
print(f"Req = {tuned.parameters['Req_m']:.2f} mm -> "
      f"{tuned.eigenmode.qois['freq [MHz]']:.1f} MHz")
Req = 103.37 mm -> 1300.0 MHz

The results are saved in ./my_cell/. In a later session, build the same cavity and call cav.load('my_cell') to reopen them without solving again. In a notebook, cav.show_fields() shows the field of the accelerating mode.

Where to go next

  • Tutorials: twelve notebooks that teach cavsim2d step by step, from a first cavity to optimisation, uncertainty quantification, beam lines and shapes of your own.
  • The guide to each analysis linked above, each ending with how-to guides for specific tasks.
  • Concepts: how studies, project folders, configurations and results fit together.
  • Configuration reference: every setting of every analysis, with its default and unit.
  • API reference and glossary.
  • Runnable scripts: one script per analysis, writing results and plots to disk.

Citing cavsim2d

If you use cavsim2d in published work, please cite it. The details are in CITATION.cff, and the "Cite this repository" button on the GitHub page gives them as BibTeX or APA.

Contributing

Bug reports and suggestions are welcome as GitHub issues. To work on the code, install it from a clone with the test tools and run the tests:

git clone https://github.com/Dark-Elektron/cavsim2d.git
cd cavsim2d
pip install -e ".[dev]"
pytest tests/ -q

Wakefield tests run only where ABCI is available. In a clone, a copy at cavsim2d/solvers/ABCI/ABCI.exe is used when CAVSIM2D_ABCI is unset; that path is ignored by git and never packaged. Changes are listed in the changelog.

License

MIT; see LICENSE.

Metadata

Release files for cavsim2d 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cavsim2d 0.2.0
File Size Uploaded Provenance Actions
cavsim2d-0.2.0.tar.gz 679.9 kB With provenance Details for cavsim2d-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cavsim2d 0.2.0
File Interpreter ABI Platform Actions
cavsim2d-0.2.0-py3-none-any.whl Python 3 none any Details for cavsim2d-0.2.0-py3-none-any.whl

Total release size: 1.3 MB

Release files / cavsim2d-0.2.0.tar.gz

Download URL cavsim2d-0.2.0.tar.gz
Size 679.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e7ea7d08cedab38468ecc9efbbfc58e0f0435b8f7cd6a0ddae4f0cbdd002c071
BLAKE2b-256 checksum
How to use checksums
735250b6b6ef0e48c4317564b52f3d5959183fb8ee3a0f170644ed91833ff2e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / cavsim2d-0.2.0-py3-none-any.whl

Download URL cavsim2d-0.2.0-py3-none-any.whl
Size 616.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7cfd09edb8b4b4a2ffce1309488e30ed6d1b3bd3e5d8e2ee9f1fd40b3575f135
BLAKE2b-256 checksum
How to use checksums
c1d791d33f89a8b24c14de8013c6638e3a1e272d7426cabd70040301feef0d41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for cavsim2d 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cavsim2d-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page