Defining a LatElement¶
To construct a LatElement,
ele = LatElement()
LatElement:
UniversalParams
kind = ""
name = ""
L = 0.0f0
tracking_method = Nothing()
n_steps = 1
n_slices = 1
fringe_at = Fringe.BothEnds
rad_damping = false
rad_fluctuations = false
As you can see, the LatElement by default comes with a “parameter group” structure
called UniversalParams. This contains a kind as a string, a name as a string, a
length L, and various settings specifying how the element should be tracked through, including the tracking_method. A bare LatElement has no tracking method set. For more details on the tracking methods available, see the Tracking Methods section of the documentation. All properties of UniversalParams and every other parameter group are defined in the last section of this page.
To set one of these parameters, use the natural syntax
ele.name = "ele"
ele.kind = "MyElementKind"
ele.L = 123
123
Alternatively, we could have set these parameters as keyword arguments during
LatElement construction:
ele = LatElement(name="ele", kind="MyElementKind", L=123)
LatElement:
UniversalParams
kind = "MyElementKind"
name = "ele"
L = 123
tracking_method = Nothing()
n_steps = 1
n_slices = 1
fringe_at = Fringe.BothEnds
rad_damping = false
rad_fluctuations = false
It would often be convenient if we can make the variable symbol (ele in this case)
automatically fill in the name field for each element. We can do exactly this by wrapping
all element definitions in
a @elements block:
@elements begin
ele1 = LatElement()
ele2 = LatElement()
end
println(ele1.name)
println(ele2.name)
ele1
ele2
In SciBmad, every element kind (Quadrupole, Sextupole, Multipole, etc.) is the same
type, LatElement. The kind only does two things: it sets the kind string, and it chooses
a suitable tracking method for the element (see Element Kinds below; a
CrabCavity also sets is_crabcavity = true):
@elements begin
qf = Quadrupole(L=0.5)
sf = Sextupole(L=0.2)
end
println(qf.kind, ": ", qf.tracking_method)
println(sf.kind, ": ", sf.tracking_method)
Quadrupole: MatrixKick(order=4, opt_scheme=true)
Sextupole: DriftKick(order=4, opt_scheme=true)
Because every element is a LatElement, any element can have any combination of
parameters. For example, there is nothing stopping you from adding a multipole to a drift:
d = Drift(L = 1.2)
d.Ks21 = -200 # Set 21st order skew multipole
-200
This flexibility makes it easy to adjust the design on the fly. For example, in the Electron Storage Ring of the Electron-Ion Collider, we need to add multipoles to the drifts in the interaction region to simulate field crosstalk from the Hadron Storage Ring. With SciBmad, one does not need to edit the lattice and change these “drifts” to “multipoles”; just set the multipole!
The drift above still uses DriftKick, which can track through any multipole except a
solenoid. If you were to add a solenoid field to this drift, you would also need to set
d.tracking_method = SolenoidKick(); if you forget, tracking will stop with an error telling
you so. Note that changing the kind string afterwards does not change the tracking method.
For details, see the Tracking Methods section of the documentation.
Element Kinds¶
Below are all of the element kinds and their default tracking methods. Any
element with L = 0 uses Exact(), and you can always set a different tracking method,
either as a keyword argument or afterwards.
Kind |
Default tracking method |
Notes |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Also sets |
|
|
For any |
|
|
For any |
|
|
For any |
|
|
For any |
A bare LatElement() has no tracking method, so you must set one yourself before tracking
through it.
Parameters¶
SciBmad supports a continually-growing list of parameters to define accelerator elements.
To see a full list of the parameters you can set, look at the docstring for the
LatElement type, reproduced below. In a Julia session it can be retrieved with Docs.doc(LatElement).
LatElement — Type.
LatElement
The basic building block which makes up a Beamline. May be something physical like a
quadrupole magnet, or something non-physical like a point in the accelerator you want
to mark. A LatElement may define a region in space distinguished by the presence of
(possibly time-varying) electromagnetic fields, materials, apertures and other possible
properties.
LatElement properties are split into “parameter groups” for convenient organization:
AlignmentParams ApertureParams BMultipoleParams
x_offset x1_limit KnX
y_offset x2_limit KsX
z_offset y1_limit BnX
x_rot y2_limit BsX
y_rot aperture_shape KnXL
tilt aperture_at KsXL
aperture_shifts_with_body BnXL
BsXL
tiltX
BeamlineParams BendParams EMFieldParams
beamline g_ref em_field
beamline_index tilt_ref em_field_params
s e1 em_field_normalized
s_downstream e2
line edge1_int
context edge2_int
branch
branch_index
EMultipoleParams FourPotentialParams IBSParams
EnX four_potential ibs_model
EsX four_potential_params
EnXL four_potential_normalized
EsXL
etiltX
IgnoreParams InitialBeamlineParams MapParams
ignore_params species_ref transport_map
E_ref transport_map_params
pc_ref
p_over_q_ref
dE_ref
dpc_ref
dp_over_q_ref
MetaParams PatchParams RFParams
alias dt rf_frequency
label dx harmon
description dy phi0
dz zero_phase
dx_rot traveling_wave
dy_rot is_crabcavity
dz_rot
UniversalParams
kind
name
L
fringe_at
n_steps
ds_step
n_slices
tracking_method
rad_damping
rad_fluctuations
To set a property, use the natural syntax:
ele = LatElement()
ele.L = 1 # Length
ele.Kn1 = 2 # Normal quadrupole strength
ele.rf_frequency = 1e6
For detailed descriptions of properties in a given parameter group, see the documentation for that parameter group.
Note that parameters are split into “parameter groups”, for organization and convenience. They are all documented below.
Parameter Groups¶
Parameter groups are automatically added to an element when a corresponding property is set.
Parameter groups can be removed from an element as a whole by setting that parameter group to
nothing; for example, to remove MapParams from an element named ele, do
ele.MapParams = nothing.
AlignmentParams¶
AlignmentParams — Type.
AlignmentParams
Describe the alignment of the element with respect to the nominal position.
Rotations are applied in order: tilt, x_rot, y_rot.
Properties
x_offset: Offset along x-axis [m]y_offset: Offset along y-axis [m]z_offset: Offset along z-axis [m]x_rot: Rotation around the x-axis [rad]y_rot: Rotation around the y-axis [rad]tilt: Rotation around the z-axis [rad]
ApertureParams¶
ApertureParams — Type.
ApertureParams
Describe a mechanical aperture.
Properties
x1_limit: Left x-axis aperture edge [m]x2_limit: Right x-axis aperture edge [m]y1_limit: Lower y-axis aperture edge [m]y2_limit: Upper y-axis aperture edge [m]aperture_shape: Shape of the aperture, seeApertureShapeaperture_at: Longitudinal aperture location(s), seeApertureAtaperture_shifts_with_body:trueif the aperture position moves with element alignment,falseotherwise. Default istrue
BMultipoleParams¶
BMultipoleParams — Type.
BMultipoleParams
Defines magnetic (B) multipoles for an element.
A given multipole can be set using any of the following:
KnX: Order X normal strength in [1/m^(X+1)] (normalized, nonintegrated)KsX: Order X skew strength in [1/m^(X+1)] (normalized, nonintegrated)BnX: Order X normal strength in [T/m^X] (unnormalized, nonintegrated)BsX: Order X skew strength in [T/m^X] (unnormalized, nonintegrated)KnXL: Order X normal strength in [1/m^X] (normalized, integrated)KsXL: Order X skew strength in [1/m^X] (normalized, integrated)BnXL: Order X normal strength in [T/m^(X-1)] (unnormalized, integrated)BsXL: Order X skew strength in [T/m^(X-1)] (unnormalized, integrated)tiltX: Tilt to only order X multipole
The solenoidal multipole can be set using any of the above with X = sol and
omitting the n/s, e.g. Ksol, Bsol, KsolL, BsolL.
Note
The last set for a given multipole defines if both the normal and skew strengths for a given multipole order are normalized and integrated. E.g.
ele = LatElement(Kn1=0.1, Ks1=0.2, L=0.4) # Order 1 is normalized, nonintegrated
ele.Kn1L = 0.3 # Order 1 independent variables are now normalized, integrated
ele.Ks1L == 0.2*0.4 # true
ele.Bn1 = 0.5 # Order 1 independent variables are now unnormalized, nonintegrated
ele.Bs1 == 0.2*0.5/0.3 # true, set so that (Bs1/Bn1)_new = (Ks1L/Kn1L)_old
BeamlineParams¶
BeamlineParams — Type.
BeamlineParams
Defines information for LatElements that are in a Beamline.
Properties
beamline:Beamlinethat thisLatElementis inbeamline_index: Index of thelinearray of theBeamlinethat this element is ats: Longitudinal position from the start of theBeamlineat the entrance of the element [m]s_downstream: Longitudinal position from the start of theBeamlineat the exit of the element [m]line: A read-only array ofLatElementsin the beamline, in ordercontext:Contextstruct containing control variables associated with the beamline. If in aBranch, this is shared by the wholeBranch(andLattice, if any), and setting it sets it for all of thembranch:Branchthat the beamline is placed in, if anybranch_index: Index of the beamline in theBranch, if in aBranch
BendParams¶
BendParams — Type.
BendParams
Defines a curvature in the reference coordinate system throught the element, as well as the edge angles of the element at the entrance and exit of the element. Does not specify any magnetic field.
Properties
g_ref: Coordinate system curvature [1 / m]tilt_ref: Tilt angle applied before the curvature, and undone after [rad]e1: Edge angle of the entrance of the element w.r.t. the entering coordinate system [rad]e2: Edge angle of the exit of the element w.r.t. the exit coordinate system [rad]edge1_int: Pole face field integral at the entrance [m]edge2_int: Pole face field integral at the exit [m]
EMFieldParams¶
EMFieldParams — Type.
EMFieldParams
Defines the electromagnetic field of an element as a function
em_field(x, y, s, t, p=nothing) where p is a tuple of parameters that may be used
inside the function.
Properties
em_field: Function with arguments (x, y, s, t, p) the returns a tuple of the EM field values (Ex, Ey, Ez, Bx, By, Bz) at the given point.em_field_params: Tuple of parameters passed to theem_fieldfunction. Default isnothingem_field_normalized: Iftrue, then EM field values returned are normalized byp_over_q_ref; default isfalse.
EMultipoleParams¶
EMultipoleParams — Type.
EMultipoleParams
Defines electric (E) multipoles for an element.
A given multipole can be set using any of the following:
EnX: Order X normal strength in [V/m^(X+1)] (nonintegrated)EsX: Order X skew strength in [V/m^(X+1)] (nonintegrated)EnXL: Order X normal strength in [V/m^X] (integrated)EsXL: Order X skew strength in [V/m^X] (integrated)etiltX: Tilt to only order X multipole
Note
The last set for a given multipole defines if both the normal and skew strengths for a given multipole order are integrated. E.g.
ele = LatElement(En1=0.1, Es1=0.2, L=0.4) # Order 1 is nonintegrated
ele.En1L = 0.3 # Order 1 independent variables are now integrated
ele.Es1L == 0.2*0.4 # true
FourPotentialParams¶
FourPotentialParams — Type.
FourPotentialParams
Defines the electromagnetic four-potential of an element as a function
four_potential(x, y, s, t, p=nothing) where p is a tuple of parameters that may be used
inside the function.
Properties:
four_potential: Function with arguments(x, y, s, t, p=nothing)that returns a two component tuple(C, D)with bothCandDbeing themselves tuples:
⠀ C = (ϕ, Ax, Ay, As)
⠀ D = (∂ϕ/∂x, ∂ϕ/∂y, ∂ϕ/∂s, ∂ϕ/∂t,
⠀ ∂Ax/∂x, ∂Ax/∂y, ∂Ax/∂s, ∂Ax/∂t,
⠀ ∂Ay/∂x, ∂Ay/∂y, ∂Ay/∂s, ∂Ay/∂t,
⠀ ∂As/∂x, ∂As/∂y, ∂As/∂s, ∂As/∂t)\four_potential_params: Tuple of parameters passed to thefour_potentialfunction. Default isnothingfour_potential_normalized: Iftrue, then potential/derivatives returned are normalized byp_over_q_ref; default isfalse.
IBSParams¶
IBSParams — Type.
IBSParams
Defines intra-beam scattering modelling.
Properties
ibs_model: AnIBSModelthat specifies which intra-beam scattering model is used
The ibs_model parameter takes an IBSModel:
IBSModel — Module.
@enumx IBSModel::Int8 None Gaussian GaussianDampingOnly GaussianFluctuationsOnly
Which intra-beam scattering model should be used.
InitialBeamlineParams¶
InitialBeamlineParams — Type.
InitialBeamlineParams
Defines the reference species and energy of the beamline. These parameters may be “set” in the
first element of the beamline or at the Beamline level, and retrieved at any element in the
beamline. If the reference species or energy is not set, then it will inherit that quantity from
an upstream beamline if in a Branch.
Properties
species_ref: Reference species of the beamlineE_ref: Total reference energy [eV]pc_ref: Reference momentum [eV/c]p_over_q_ref: A signed reference magnetic rigidity [T * m]dE_ref: Change in total reference energy w.r.t. the directly-upstream beamline [eV]dpc_ref: Change in reference momentum w.r.t. the directly-upstream beamline [eV/c]dp_over_q_ref: Change in signed reference magnetic rigidty w.r.t. the directly-upstream beamline [T * m]
MapParams¶
MapParams — Type.
MapParams
Defines any arbitrary function to transport particle coordinates’ and optionally spin quaternions. This could be a matrix, a neural network, a phase trombone, etc.
The input for the transport_map must be (v, q, p=nothing), where v is a tuple of the
input phase space coordinates (x, px, y, py, z, pz) and q is nothing is there is no
spin tracking, else q is a tuple of the input quaternion (q0, q1, q2, q3). p may be a
tuple of parameters that can be used inside of the transport_map. This might be neural
network weights, for example, or perhaps phase evolutions for a phase trombone.
For GPU compatibility, it is necessary that your function transport_map is GPU compatible:
there should be no type instabilities. You should also try to make your transport_map be
branchless, so both the CPU and GPU can vectorize it.
transport_map_params should contain the tuple that is passed into p at the time of tracking.
Properties:
transport_map: Arbitrary function that transports particles’ coordinatesv, and optionally spin quaternionsq. Must have the signature<your map name>(v, q, p=nothing)and returns the output as a tuple(v, q)transport_map_params: Parameters of the transport map that will be inputted as thepvariable intransport_map
Example
using StaticArrays
random_matrix = @SMatrix rand(6,6) # use StaticArrays for GPU compatibility
function matrix(v, q::Nothing, p) # `q::Nothing` -> no spin tracking
# Vectorizable matrix multiplication by `p`:
vx = sum(p[1,:] .* v)
vpx = sum(p[2,:] .* v)
vy = sum(p[3,:] .* v)
vpy = sum(p[4,:] .* v)
vz = sum(p[5,:] .* v)
vpz = sum(p[6,:] .* v)
return ((vx, vpx, vy, vpy, vz, vpz), q)
end
m = LatElement(transport_map=matrix, transport_map_params=random_matrix)
MetaParams¶
MetaParams — Type.
MetaParams
Defines extra String properties that may be useful for pattern matching
or storing extra information about a given element.
Properties
alias: Alternate name for the element as a stringlabel: A label stringdescription: A descriptive string
PatchParams¶
PatchParams — Type.
PatchParams
Defines properties for patches, which change the reference coordinate system.
Rotations are applied in order: dz_rot, dx_rot, dy_rot.
Properties
dt: Reference time shift [s]dx: New coordinate system offset in the x-direction [m]dy: New coordinate system offset in the y-direction [m]dz: New coordinate system offset in the z-direction [m]dx_rot: Rotation of coordinate system around the initial x-axis [rad]dy_rot: Rotation of coordinate system around the initial y-axis [rad]dz_rot: Rotation of coordinate system around the initial z-axis [rad]
RFParams¶
RFParams — Type.
RFParams
Defines parameters generally associated with radiofrequency (RF) cavities. The frequency
of the oscillating electromagnetic field may be optionally specified using the property
rf_frequency or harmon; whichever of these is set last will be the independent
variable.
Properties
rf_frequency: Frequency of the oscillating electromagnetic field [Hz]harmon: Harmonic number of the oscillating electromagnetic field w.r.t. the length of the entire containingBeamline[1]phi0: Phase offset of the oscillating field w.r.t.zero_phase[rad]zero_phase: APhaseRefthat specifies whatphi0should mean, seePhaseReftraveling_wave:trueif traveling wave,falseif standing waveis_crabcavity:trueif this is a crab cavity,falseotherwise
The zero_phase parameter takes a PhaseRef:
PhaseRef — Module.
@enumx PhaseRef::UInt8 Accelerating BelowTransition AboveTransition
Sets what zero phi0 RF phase means
Accelerating: Zero phase is the maximum accelerating phase.BelowTransition: Zero phase is at the stable zero crossing for particles below transition.AboveTransition: Zero phase is at the stable zero crossing for particles above transition.
All tracking methods for RF cavities use the same phase convention. A particle of the
reference species that arrives a time \(\Delta t\) after the reference particle gains the
energy \(|q| V \cos(\phi_0 + \phi_\mathrm{zero} + \omega \Delta t)\), where \(\omega\) is the
angular RF frequency and \(\phi_\mathrm{zero}\) is \(0\) for PhaseRef.Accelerating, \(+\pi/2\)
for PhaseRef.AboveTransition, and \(-\pi/2\) for PhaseRef.BelowTransition. So with
phi0 = 0, a particle arriving late loses energy above transition and gains energy below
transition, which is what makes the motion stable in each case.
UniversalParams¶
UniversalParams — Type.
UniversalParams
Describes the kind, name, length, and tracking method for a LatElement.
Properties
kind: String specifing the “kind”, of an element, e.g. “Quadrupole”name: The name of an element as a stringL: Length of the element [m]fringe_at: AFringethat specifies which, if any, element ends should include fringe field modelling. Default isFringe.BothEndsn_steps: Number of integrator steps to take per element slice, default is 1ds_step: Length of each integrator step to take per element slice, such thatn_steps = ceil(L / n_slices / ds_step)n_slices: Number of slices to split the element into in tracking, typically so that collective effects can be applied multiple times in an element. If no collective effects are included, then prefer to varyn_steps/ds_stepinstead for performance.tracking_method: Tracking method for the elementrad_damping:trueif the deterministic effect of synchrotron radiation is included,falseotherwise. Defaults tofalserad_fluctuations:trueif the stochastic radiation kicks are included,falseotherwise. Defaults tofalse
The fringe_at parameter takes a Fringe:
Fringe — Module.
@enumx Fringe::Int8 NoEnd BothEnds EntranceEnd ExitEnd
Defines which ends fringe field modelling should be included