Tracking Methods

Every element has a tracking_method, which sets how particles are pushed through it. When you construct an element with one of the element kinds, a default tracking method is chosen for you (see the table of Element Kinds), for example MatrixKick() for a Quadrupole and BendKick() for an SBend. Any element with L = 0 uses Exact().

A bare LatElement() has no tracking method, so you must set one yourself before tracking. The default can always be overridden, either during construction or afterwards:

qf = Quadrupole(L=0.5, Kn1=0.36, tracking_method=DriftKick(order=6))
qf.tracking_method = MatrixKick()
MatrixKick(order=4, opt_scheme=true)

Since any element can contain any combination of parameters, not every tracking method can handle every element. If it can’t, tracking stops with an error telling you which tracking method to use instead. For example, DriftKick cannot track through a solenoid field:

d = Drift(L=1.0, Ksol=0.1)
bl = Beamline([d], species_ref=Species("electron"), pc_ref=1e9)
track(bl, v0=zeros(1, 6))
DriftKick is not compatible with elements with a solenoid field. Try SolenoidKick instead

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:44
  [2] fringe_body_fringe
    @ ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/driftkick_bl.jl:45 [inlined]
  [3] universal!(bunch::Bunch{…}, tm::DriftKick{…}, fullele::LatElement, universalparams::BeamTrackingBeamlinesExt._SliceUniversalParams{…}, alignmentparams::Nothing, bendparams::Nothing, bmultipoleparams::BMultipoleParams{…}, patchparams::Nothing, apertureparams::Nothing, rfparams::Nothing, beamlineparams::BeamlineParams, mapparams::Nothing, fourpotentialparams::Nothing, emultipoleparams::Nothing, emfieldparams::Nothing, ibsparams::Nothing, ref::BeamTrackingBeamlinesExt.TrackReference{…}, ::Val{…}, ::Val{…}, ::Val{…}, batch_start::Int64, sink::Vector{…}; kwargs::@Kwargs{})
    @ BeamTrackingBeamlinesExt ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/unpack_bl.jl:399
  [4] universal!(bunch::Bunch{…}, tm::DriftKick{…}, fullele::LatElement, universalparams::BeamTrackingBeamlinesExt._SliceUniversalParams{…}, alignmentparams::Nothing, bendparams::Nothing, bmultipoleparams::BMultipoleParams{…}, patchparams::Nothing, apertureparams::Nothing, rfparams::Nothing, beamlineparams::BeamlineParams, mapparams::Nothing, fourpotentialparams::Nothing, emultipoleparams::Nothing, emfieldparams::Nothing, ibsparams::Nothing, ref::BeamTrackingBeamlinesExt.TrackReference{…}, ::Val{…}, ::Val{…}, ::Val{…}, batch_start::Int64, sink::Vector{…})
    @ BeamTrackingBeamlinesExt ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/unpack_bl.jl:225
  [5] _track!(bunch::Bunch{…}, ele::LatElement, context::Context{…}, ref::BeamTrackingBeamlinesExt.TrackReference{…}, scalar_params::Bool, ramp_particle_energy_without_rf::Val{…}, ramp_update_each_particle::Val{…}, shift_time::Val{…}, rf_on::Bool, batch_start::Int64, sink::Vector{…}; kwargs::@Kwargs{})
    @ BeamTrackingBeamlinesExt ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/unpack_bl.jl:217
  [6] _track!(bunch::Bunch{…}, ele::LatElement, context::Context{…}, ref::BeamTrackingBeamlinesExt.TrackReference{…}, scalar_params::Bool, ramp_particle_energy_without_rf::Val{…}, ramp_update_each_particle::Val{…}, shift_time::Val{…}, rf_on::Bool, batch_start::Int64, sink::Vector{…})
    @ BeamTrackingBeamlinesExt ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/unpack_bl.jl:77
  [7] prepare(bunch::Bunch{…}, bl::Beamline; scalar_params::Bool, ramp_particle_energy_without_rf::Bool, ramp_update_each_particle::Bool, rf_on::Bool, batch_start::Int64, notify::Bool)
    @ BeamTrackingBeamlinesExt ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/prepared_bl.jl:190
  [8] prepare
    @ ~/.julia/packages/BeamTracking/nZtDK/ext/BeamTrackingBeamlinesExt/prepared_bl.jl:166 [inlined]
  [9] _track(bl::Beamline, bunch::Bunch{…}, config::TrackConfig, groupsize::Nothing, step_start::Int64, locations::Tuple{…}, loc_steps::Vector{…}, n_steps_turn::Int64, ::Val{…}, _start::Int64)
    @ SciBmad ~/work/SciBmad/SciBmad/julia/src/track.jl:532
 [10] track(bl::Beamline; v0::Matrix{…}, spin::Bool, q0::Nothing, weight::Nothing, callbacks::Tuple{}, species::Species, bunch::Bunch{…}, start::Int64, at::Nothing, config::TrackConfig, n_turns::Int64, save_every_n_turns::Int64, in_body_coordinates::Bool, save_reference::Bool, scalar_params::Bool, rf_on::Bool, ramp_particle_energy_without_rf::Bool, ramp_update_each_particle::Bool, batch_start::Int64, verbose::Bool, groupsize::Int64, use_cpu_multithreading::Bool, use_KA::Bool, use_explicit_SIMD::Bool)
    @ SciBmad ~/work/SciBmad/SciBmad/julia/src/track.jl:484
 [11] top-level scope
    @ In[3]:3
 [12] eval(m::Module, e::Any)
    @ Core ./boot.jl:489
Some type information was truncated. Use `show(err)` to see complete types.
d.tracking_method = SolenoidKick()
track(bl, v0=[1e-3 0 0 0 0 0]).v[turn=1, particle=1]
6-element Vector{Float64}:
  0.0009975020826327734
 -2.4958354192800923e-6
 -4.991670838560185e-5
  1.248958683613353e-7
 -1.2500000023437503e-9
  0.0

Integration Steps and Slices

The tracking method decides how each integration step is taken. How many steps are taken, and a few other settings, are set in the element’s UniversalParams:

  • n_steps or ds_step: the number of integration steps, or the largest length of each step. Setting one of these sets the other (n_steps = ceil(L / n_slices / ds_step), and the steps all have the length L / n_slices / n_steps).

  • n_slices: the number of slices to split the element into, each with n_steps integration steps. Collective effects (see Collective Effects) and a ramping reference energy are recomputed and applied once per slice. If you only need more accuracy, increase n_steps instead, which is faster.

  • fringe_at: which ends of the element include fringe fields. Fringe fields are only included at the ends of the whole element, not between its slices.

  • rad_damping: true if tracking should include the deterministic damping effect of radiation

  • rad_fluctuations: true if tracking should include the stochastic kicks of radiation

sf = Sextupole(L=0.2, Kn2=1.2, n_steps=4, rad_damping=true)
LatElement:
  UniversalParams                       BMultipoleParams
   kind             = "Sextupole"        Kn2   = 1.2
   name             = ""
   L                = 0.2
   tracking_method  = DriftKick(
     order      = 4,
     opt_scheme = true,
   )
   n_steps          = 4
   n_slices         = 1
   fringe_at        = Fringe.BothEnds
   rad_damping      = true
   rad_fluctuations = false

Patches, maps, and elements tracked with SaganCavity (see Sagan Cavity below, whose kicks are set by n_cells) are always tracked in one step, so n_steps must be 1 for them. Elements with a patch or a map, and presently elements tracked with SaganCavity, also cannot be sliced.

Symplectic Integrators

DriftKick, MatrixKick, BendKick, SolenoidKick, and Implicit are the various symplectic integrators provided in SciBmad. The first four split the motion through the element into a simple part that can be solved directly, and “kicks” with the rest in between. They differ in how the motion is split:

  • DriftKick: drifts exactly, and kicks with all of the multipoles. This works for any straight element without a solenoid field, including RF cavities.

  • MatrixKick: tracks an approximate energy-dependent quadrupole, and kicks with its corrections and other multipoles. This is usually the best choice for straight, aligned elements with a strong quadrupole field.

  • SolenoidKick: tracks through the solenoid field exactly, and kicks with the rest of the multipoles. This works for any straight element, with or without a solenoid field, including RF cavities.

  • BendKick: tracks through a bending coordinate system and dipole strength exactly, and kicks with the rest of the multipoles. This is the usual choice for elements that bend the reference trajectory (see BendParams).

  • Implicit: an implicit integrator for arbitrary electromagnetic fields defined by a four-potential (see FourPotentialParams). All fields in the element must be included in the four-potential.

All of these take the same two settings:

DriftKick — Type.

DriftKick(; order=4, opt_scheme=true)

Symplectic integrator using a drift-kick Hamiltonian split.

Properties

  • order: Order of the integrator, supported are orders 2, 4, 6, 8, and 10. Default is 4

  • opt_scheme: If true, uses an optimized integration scheme, else uses the standard Yoshida scheme. Default is true

Implicit also has use_newton specifying if a Newton iteration should be used for implicit solve (default is false, to use fixed point iteration):

Implicit — Type.

Implicit(; order=4, opt_scheme=true, use_newton=false)

Implicit symplectic integrator for arbitrary electromagnetic potentials.

Properties

  • order: Order of the integrator, supported are orders 2, 4, 6, 8, and 10. Default is 4

  • opt_scheme: If true, uses an optimized integration scheme, else uses the standard Yoshida scheme. Default is true

  • use_newton: If true, Newton’s method is used to solve the implicit step, else fixed point iteration is used. Default is false

A higher order integrator is more accurate per step, but each step takes longer: with the optimized schemes, an order 4 step is made of 5 second order steps, and an order 6 step of 13. Whether you get more accuracy for the same speed by increasing the order or by increasing the number of steps depends on the element, so it is worth checking for your lattice.

If an element is a pure drift, a pure bend, or a pure solenoid, it is tracked through exactly, and the order and number of steps don’t change the result. The exception is when radiation is included, because the radiation is applied at each integration step. The steps are still taken in any case, so callbacks (e.g. used by twiss to compute its results inside elements) are executed at every step.

Exact

Exact — Type.

Exact()

Tracking method specifying “exact” transformations, e.g. patches, custom maps, thin multipoles, etc.

Exact is used for elements that are not integrated in steps: patches, maps, markers, and thin (zero length) multipoles. It can also track exactly through a nonzero length element with no field (a drift), only a solenoid field, only a dipole field (also in a bend), or only an electric dipole field (EMultipoleParams). Setting the length of an element to zero switches its tracking method to Exact automatically.

Runge Kutta

RK4 — Type.

RK4()

Fourth order Runge Kutta integrator, not symplectic.

RK4 integrates the equations of motion through an arbitrary electromagnetic field, defined as a function of the particle position and time in EMFieldParams, together with any multipoles and bend in the element. It is not symplectic, and does not support spin tracking at the moment.

Sagan Cavity

SaganCavity — Type.

SaganCavity(; n_cells = -1, L_active = -1.0)

Integrator for RF cavities using the Sagan Cavity model.

Properties

  • n_cells: Number cells in the cavity. If negative, then the approximate half wavelength between cells is used, and if zero then a single kick is applied. Default is -1

  • L_active: Active length of the cavity. If negative, then the element length is used. Default is -1

See SaganCavity Tracking for how to use it, and SaganCavity Physics for the model.