Issue 76

Beam Dynamics Newsletter

3.17 OPAL Simulation Code

Chris Rogers, ISIS, Rutherford Appleton Laboratory, United Kingdom.
Andreas Adelmann, PSI, Villigen, Switzerland.

OPAL (Object Oriented Parallel Accelerator Library)  [1] is a parallel open source tool for charged-particle optics in linear accelerators and rings, including 3D space charge. Using the MAD language with extensions, OPAL can run on a laptop as well as on the largest high performance computing systems. OPAL is built from the ground up as a parallel application exemplifying the fact that high performance computing is the third leg of science, complementing theory and experiment. The OPAL framework makes it easy to add new features in the form of new C++ classes. OPAL comes in two flavours:

  • • OPAL-cycl: tracks particles with 3D space charge including neighbouring turns in cyclotrons and FFAs with time as the independent variable.

  • • OPAL-t: models beam lines, linacs, rf-photo injectors and complete XFELs excluding the undulator.

The code is managed through the git distributed version control system. A suite of unit tests have been developed for various parts of OPAL, validating each part of the code independently. Unit tests use the google testing framework. System tests validate the overall integration of different elements. Documentation is written in asciidoc. Tools are available to readily convert asciidoc into formats such as pdf and html for display.

The OPAL code supports simulation of FFAs using analytical scaling field maps, 3D sector field maps and variable frequency RF cavities characteristic of many FFA designs. The FFA routines complement the existing cyclotron models and full three-dimensional space charge solvers including boundary conditions.

User configurable modules provide different tracking routines and field map routines. Fields are placed in a three-dimensional world and macro-particles are tracked through the field maps.

3.17.1 Field models

Several field map routines are provided that support implementation of scaling and non-scaling FFAs, both in the design and operation phase of the accelerator.

Scaling FFA Magnet Model

For a perfectly scaling sector field, fields off the midplane are calculated to arbitrary order using a recursive power series. Considering a coordinate system \( (r, \phi , z) \), the field can be written as

\{begin}{align*} B_z &= \sum _{n=0} f_{2n}(\psi ) h(r) \left (\frac {z}{r}\right )^{2n} \\
B_\phi &= \sum _{n=0} f_{2n+1}(\psi ) h(r) \left (\frac {z}{r}\right )^{2n+1} \\ B_r &= \sum _{n=0}
\left [ \frac {k-2n}{2n+1} f_{2n}(\psi ) - \tan (\delta ) f_{2n+1}(\psi )\right ] h(r) \left (\frac
{z}{r}\right )^{2n+1} \{end}{align*}

with \( \psi \) representing the azimuthal angle in spiral coordinates

\[ \psi = \phi - \tan (\delta ) \ln (r/r_0), \]

and \( h(r) \) the field dependence on radius

\[ h(r) = B_0 \left (\frac {r}{r_0}\right )^k. \]

The fringe field on the midplane is modelled using

\[ f_0(\psi )=\frac {1}{2}\left [\tanh \left (\frac {\psi +\psi _0}{\lambda }\right )-\tanh \left
(\frac {\psi -\psi _0}{\lambda } \right )\right ] \]

so that \( \psi _0 \) represents the length of the flat-top and \( \lambda \) represents the length of the field fall-off. Away from the midplane, the coefficients \( f_{n} \) are calculated by requiring that Maxwell’s equations are observed, yielding a recursion relation in terms of the derivatives of \( f_{0} \)

\[ f_{n} = \sum _{i=0} a_{i,n} \partial ^i_\psi f_{0} \]

with even and odd terms related by

\{begin}{align*} a_{i,2n+1} =& \frac {a_{i-1,2n}}{2n+1} \\ a_{i,2n+2} =& \frac {1}{2n+2}
\big ( a_{i,2n+1} 2(k-2n) \tan (\delta ) \\ &- \frac {(k-2n)^2}{2n+1} a_{i, 2n} - (1+\tan ^2(\delta ))
a_{i-1, 2n+1} \big ). \{end}{align*}

\( f_0(\psi ) \) is implemented using C++ inheritance making alternate fringe field models, for example Enge function, simple to implement so long as the function and its derivatives are continuous. The coefficients of \( f_n \) are calculated during the lattice construction to minimise overhead during stepping.

Multipole Model

Multipole models are provided to enable modelling of non-scaling FFAs. Because OPAL enables arbitrary placement of potentially overlapping fields, such multipoles can be used to represent field errors in FFA main magnets.

Rectangular and sector multipoles are enabled with soft edged fringe fields. Sector multipoles can be configured with fixed radius of curvature or in the case of dipoles and combined function magnets, a radius of curvature programmed to follow a reference trajectory.

Pillbox RF Cavity

Rectangular pillbox-style RF cavities can be tracked with hard- or soft-edged fields. In the hard-edged model, time variation of the field is given by

\[ E_s = V(t) \sin (\Omega (t) t + \Phi (t)). \]

where \( \Omega \), \( \Phi \) and \( V \) are parameters of the RF cycle whose time dependence can be programmed by the user according to a polynomial. All other components of the field are zero.

Soft-edged cavities are described in Cartesian coordinates \( (x, z, s, t) \) by a series expansion off the midplane,

\{begin}{align*} E_x & = 0 \\ E_z & = V(t) \sum _n z^n g_n \sin (\Omega t + \Phi ) \\ E_s
& = V(t) \sum _n z^n f_n \sin (\Omega t + \Phi ) \\ B_x & = V(t) \sum _n y^n h_n \cos (\Omega t +
\Phi ) \\ B_y & = 0 \\ B_z & = 0. \{end}{align*}

It is assumed that variations in \( \Omega \), \( \Phi \) and \( V \) occur on a timescale much longer than the RF frequency \( \Omega \) so that they do not contribute significantly to the magnetic field. Recursion relations can be derived assuming Maxwell’s laws,

\{begin}{align*} g_{n+1} &= -\frac {1}{n+1}\partial _z f_n \\ h_{n+1} &= -\frac {\omega
}{c^2 (n+1)} f_n \\ f_{n+2} &= -\frac {\omega ^2 f_n + c^2 \partial ^2_z f_n}{c^2(n+1)(n+2)}.

Odd terms of \( f_n \) and even terms of \( g_n \) and \( h_n \) are 0.

3D Field Map

OPAL can read in a 3D magnetic field map placed on a regular grid in cylindrical polar coordinates. The field at an arbitrary point is inferred by tri-linear interpolation.

Field Map Output

Output of the field map is an essential part of the validation of a given lattice. OPAL provides methods to write out the electromagnetic field map as a four-dimensional grid in Cartesian or cylindrical polar coordinates and time. Field maps can be written over an arbitrary region in space-time.

3.17.2 Examples

To demonstrate the simulation in OPAL, a radial sector magnet with DF geometry is considered. In this lattice, protons are simulated between 3 and 30 MeV. The lattice has 8 cells and a 3 m inner diameter with a field index 3. The doublet structure in each cell can be seen by examination of the field maps. The orbit excursion is approximately 1 m. The similarity of the orbits and the radial dependence on energy can be observed in fig. 1. The orbits at different azimuthal angles are identical bar an increase in radius and a concomitant increase in beam energy, as expected from the scaling condition.

(image) (image)

Figure 1: Simulated closed orbits for a number of orbits at different energies (top) and dependence of the closed orbit radius on kinetic energy (bottom). The closed orbit demonstrates radial scaling with momentum.

In a scaling FFA both the closed orbit and the linear order transverse optics must scale with momentum. The constancy of tune with energy is shown in fig. 2. At each energy a particle has been tracked on the closed orbit and another particle has been tracked with the same energy but initially deviating from the closed orbit by 2 mm and 1 mm in horizontal and vertical space respectively. The phase advance of each particle is calculated on a cell-by-cell basis and this is converted to the fractional part of the cell tune. The tune is seen to be constant as expected.


Figure 2: Simulated cell tune for a number of different kinetic energies. The tune is constant with energy indicating the field scales correctly.

Injection Simulation

More complicated arrangements can also be simulated to support injection, extraction and acceleration studies. Consider the lattice shown in fig. 3. In this example, spiral FFA magnets have been modelled with a field index of 7.1, and a spiral angle of 41\( ^{\circ } \). Injection dipoles have been added in order to simulate a closed orbit bump onto a foil that might be used for injection. The dipole fields were chosen to return the circulating proton beam to the closed orbit following the beam bump. Several different injection dipole fields were simulated, and all of the closed orbits have been superimposed onto the same figure to demonstrate simulation of painting at injection. Very wide dipoles have been simulated in order to support optimisation of the lattice; where the bump dipoles overlap the FFA main magnets OPAL superposes the two fields. Following optimisation, the radial extent of the dipoles can be curtailed as desired by the user.


Figure 3: Simulation including bump magnets for injection.

Acceleration Simulation

An example of an acceleration cycle for the spiral FFA lattice described above is shown in fig. 4. Here a few particles have been simulated accelerating over a 0.5 ms acceleration cycle from 3 MeV to 30 MeV. Particle were simulated initially at the reference phase, but with kinetic energy deviations of up 0.5 MeV from the reference particle. The frequency was varied during the acceleration cycle to keep the synchronous phase constant despite the change in time-of-flight around the ring with energy. In this example the RF voltage was held constant during the acceleration cycle. The simulated particles were successfully accelerated except for the particle with initially 2.5 MeV energy, which was lost from the RF system.

(image)   (image)

Figure 4: Simulation of the acceleration cycle (left) particle time and energy over the full cycle and (right) particle time and energy relative to the reference particle over the full cycle.


OPAL can be used to simulate FFAs in a number of different circumstances. A number of field models are available in OPAL to support both analytical and numerical calculation of FFAs, together with injection, acceleration and extraction systems. The extensions to OPAL for FFA simulation complement the existing cyclotron models and full three-dimensional space charge solvers.

  • [1]