Installation¶
cavsim2d needs Python 3.10 or newer. Install it from PyPI:
pip install cavsim2d
This also installs NGSolve, the finite-element library cavsim2d solves with, gmsh, and the packages that draw NGSolve’s interactive views in a notebook.
The tutorials and how-to guides are Jupyter notebooks. To run them, install the
jupyter extra as well, which adds JupyterLab:
pip install "cavsim2d[jupyter]"
VS Code users need only the Jupyter kernel, which VS Code offers to install.
Check the installation¶
Run this in Python or a notebook:
from cavsim2d import EllipticalCavity
cav = EllipticalCavity(1, [42, 42, 12, 19, 35, 57.7, 103.353], beampipe='none', name='check')
cav.eigenmode.run()
print(f"{cav.eigenmode.qois['freq [MHz]']:.1f} MHz")
It solves one elliptical cell in a few seconds and prints
1300.2 MHz
The results are in a new folder, check, in the working directory; delete it
afterwards.
ABCI, for wakefields¶
The wakefield analysis runs ABCI, a time-domain code by Yong Ho Chin at KEK. ABCI is free to use but not open source, and KEK asks that it be obtained from its own page, so cavsim2d does not include it. Every other analysis works without it.
Download ABCI from the ABCI page at KEK. For 64-bit Windows this is
ABCI_MP64_12_5.zipat the time of writing.Unzip it anywhere. ABCI needs no installation.
Set the
CAVSIM2D_ABCIenvironment variable to the executable (for exampleABCI_MP64_12_5.exe), or to the folder that holdsABCI.exe. On Windows,setxkeeps it for new terminals and notebooks:setx CAVSIM2D_ABCI "C:\ABCI\ABCI_MP64_12_5.exe"On Linux or macOS:
export CAVSIM2D_ABCI="$HOME/abci/ABCI_MP64_12_5.exe"Or set it from Python, before the first wakefield run:
import os os.environ['CAVSIM2D_ABCI'] = r'C:\ABCI\ABCI_MP64_12_5.exe'
ABCI is a Windows program. On Linux and macOS it runs through wine, which must be installed. If ABCI or wine is missing, a wakefield run stops at once and says where to get it. If someone else wants ABCI, point them to the KEK page rather than passing on a copy.
Installing from the source¶
To follow development or change the code, clone the repository and install it in editable mode:
git clone https://github.com/Dark-Elektron/cavsim2d.git
cd cavsim2d
pip install -e ".[jupyter]"
Interactive views¶
cav.show_mesh(), cav.show_fields() and the other show_* methods open
NGSolve’s interactive viewer in a notebook (JupyterLab, Jupyter Notebook 7 or VS
Code). The viewer loads its JavaScript from cdn.jsdelivr.net, so the notebook needs
internet access for it. Outside a notebook, or when the viewer cannot load, these
methods draw a static matplotlib figure instead and say why.