Full API

Documentation for Beamlines.

Beamlines.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]
source
Beamlines.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, see ApertureShape
  • aperture_at: Longitudinal aperture location(s), see ApertureAt
  • aperture_shifts_with_body: true if the aperture position moves with element alignment, false otherwise. Default is true
source
Beamlines.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
source
Beamlines.Beamline — Type
Beamline

Structure containing a vector of LatElements in an ordered sequence, and optionally a Context struct containing conrol variables associated with the beamline for convenience. The reference species (specified as species_ref and reference energy (specified as one of E_ref, pc_ref, p_over_q_ref, dE_ref, dpc_ref, or dp_over_q_ref) is uniform over the entire beamline. The most-recently specified of these reference energy quantites will be stored as the independent variable, in the first LatElement of the Beamline.

Properties

  • line: A read-only array of LatElements in the beamline, in order
  • context: Context struct containing control variables associated with the beamline. If in a Branch, this is shared by the whole Branch (and Lattice, if any), and setting it sets it for all of them
  • branch: Branch that the beamline is placed in, if any
  • branch_index: Index of the beamline in the Branch, if in a Branch
source
Beamlines.Beamline — Method
Beamline(line; kwargs...)

Constructs a Beamline out of the LatElements in the vector line. The LatElements in the Beamline will be automatically constructed as children of those LatElements in line, inheriting all of their properties.

The reference energy of the beamline may be optionally specified using one of the keyword arguments: E_ref, pc_ref, p_over_q_ref, dE_ref, dpc_ref, or dp_over_q_ref. Whichever of these is specified will be the independent variable. The species of the beamline may be optionally specified using the species_ref keyword argument. Specifying either of these keyword arguments will permanently override both the reference species and energy defined in the first LatElement – see the warning below.

Examples

qf = Quadrupole(Kn1=0.36, L=0.5)
d = Drift(L=1)
qd = Quadrupole(Kn1=-0.36, L=0.5)

fodo = Beamline([qf, d, qd, d], species_ref=Species("electron"), E_ref=18e9)

Alternatively, one can specify the reference species/energy in the first element:

qf = Quadrupole(Kn1=0.36, L=0.5, species_ref=Species("electron"), E_ref=18e9)
d = Drift(L=1)
qd = Quadrupole(Kn1=-0.36, L=0.5)

fodo = Beamline([qf, d, qd, d])

Keyword arguments

  • context: A Context struct containing variables that can be stored in the beamline for convenience. If the Beamline is put in a Branch, this is merged into the Context shared by the whole Branch – see Branch.
  • species_ref: Reference species of the beamline.
  • E_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 in units [eV]
  • dpc_ref: Change in reference momentum w.r.t. the directly-upstream beamline in units [eV/c]
  • dp_over_q_ref: Change in signed reference magnetic rigidty w.r.t. the directly upstream beamline [T * m]
Warning

Keyword arguments specified to the Beamline constructor will permanently override any corresponding properties specified in the first LatElement of the beamline. E.g.,

beg = Marker(species_ref=Species("electron"), E_ref=18e9)

a = Beamline([beg])
b = Beamline([beg], species_ref=Species("proton"), E_ref=1e9)

a.E_ref == beg.E_ref == 18e9 # true
b.E_ref == 1e9               # true
b.E_ref != beg.E_ref         # true

# If `beg` is reset:
beg.species_ref = Species("positron")

# `a` will still inherit it, but `b` will not:
a.species_ref == beg.species_ref   # true
b.species_ref == Species("proton") # true
b.species_ref != beg.species_ref   # true
source
Beamlines.BeamlineParams — Type
BeamlineParams

Defines information for LatElements that are in a Beamline.

Properties

  • beamline: Beamline that this LatElement is in
  • beamline_index: Index of the line array of the Beamline that this element is at
  • s: Longitudinal position from the start of the Beamline at the entrance of the element [m]
  • s_downstream: Longitudinal position from the start of the Beamline at the exit of the element [m]
  • line: A read-only array of LatElements in the beamline, in order
  • context: Context struct containing control variables associated with the beamline. If in a Branch, this is shared by the whole Branch (and Lattice, if any), and setting it sets it for all of them
  • branch: Branch that the beamline is placed in, if any
  • branch_index: Index of the beamline in the Branch, if in a Branch
source
Beamlines.BendKick — Type
BendKick(; order=4, opt_scheme=true)

Symplectic integrator using a bend-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
source
Beamlines.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]
source
Beamlines.Branch — Type
Branch

Structure containing a vector of Beamlines, where currently each follows in-order, one after the other.

Properties

  • name: Name of the Branch. Default is "" if not in a lattice and if in a lattice, the default is "bN" where N is the index of the branch in lattice.branches
  • beamlines: Vector of the beamlines in the Branch
  • lattice: Lattice that the branch is placed in, if any
  • lattice_index: Index of the branch in the Lattice, if in a Lattice
  • context: Context shared by the Branch and all of its Beamlines, and by the whole Lattice if the Branch is in one. Setting the context of any of them sets it for all of them.

Branch(beamlines; name = "", context = Context())

Constructs a Branch given the vector of beamlines beamlines. The Branch holds copies (see copy(::Beamline)) of the Beamlines, whose LatElements are children of those of the corresponding Beamline in beamlines. The Beamlines in beamlines are not modified, so a Beamline may appear more than once and may also be used in other Branches. The contexts of the Beamlines and context are merged into a single Context shared by the Branch and all of its Beamlines. Variables in context take precedence over those in the Beamlines.

Example

ele = LatElement()
bl1 = Beamline([ele], E_ref=2e9, species_ref=Species("electron"))
bl2 = Beamline([ele], dE_ref=1e9)

branch = Branch([bl1, bl2])

Branch(elements; species_ref0 = Species(), E_ref0 = nothing, pc_ref0 = nothing, 
       p_over_q_ref0 = nothing, name = "", context = Context())

Constructs a Branch given the vector elements, which may contain LatElements, Beamlines, and Branches, in any combination:

  • Consecutive LatElements are made into Beamlines. A new Beamline is started at each LatElement that sets a reference species or energy (has an InitialBeamlineParams), so each Beamline has a uniform reference species and energy.
  • A Beamline is included as a copy (see Branch(beamlines)) whose LatElements are children of those of the Beamline. The same Beamline may appear more than once.
  • For a Branch, each of its Beamlines is included as a copy whose LatElements are children of those in the Branch (as with copy(::Branch)). The same Branch may appear more than once.

The reference species and energy of the first Beamline can be set with species_ref0 and one of E_ref0, pc_ref0, or p_over_q_ref0. These are only allowed if elements starts with a LatElement.

Example

beginning = Marker(E_ref=10e9, species_ref=Species("electron"))
rf0 = RFCavity(dE_ref=1e9)
next = LatElement()

branch = Branch([beginning, rf0, next]) # Partitioned into 2 `Beamline`s

arc = Beamline([Drift(L=1.0), SBend(L=2.0)])
cell = Branch([Quadrupole(L=0.5), Drift(L=1.0)])
branch2 = Branch([beginning, arc, cell, cell, Marker()]) # 5 `Beamline`s
source
Beamlines.Context — Type
Context{T}

A "scope" of variables that can be used when evaluating DefExprs. Contexts serve as a single structure that stores all (control) variables associated with beamline parameters. Contexts essentially act as structures with arbitrary field names. The type parameter T can be specified as the variables' return type, or Union of return types, to improve performance.

If a "get" is made of a variable not included in a given Context, then the "get" will fall-back to the global stack of contexts GLOBAL_CONTEXTS. The first instance from the top of the GLOBAL_CONTEXTS stack of the variable will be used as the variable value. This makes it easy to "push" and "pop" parameter settings one may be testing in an interactive environment.

Examples

julia> c1 = Context(a = 1, b = 2, c = 3);

julia> push!(GLOBAL_CONTEXTS, c1);

julia> c2 = Context(a = 4);

julia> d = DefExpr(c -> c.a + c.b);

julia> d() # Uses c1.a and c1.b from the GLOBAL_CONTEXTS
3

julia> d(c2) # Uses c2.a, but falls-back to c1.b from GLOBAL_CONTEXTS
6

julia> push!(GLOBAL_CONTEXTS, c2);

julia> d() # Now uses c2.a and c1.b both from GLOBAL_CONTEXTS
6

julia> pop!(GLOBAL_CONTEXTS);

julia> d() 
3

Beamlines also store a context, which is passed to all DefExprs when getting parameters from LatElements that are in a beamline:

julia> c3 = Context(Kn1=0.36);

julia> qf = Quadrupole(Kn1=DefExpr(c -> c.Kn1), L=0.5);

julia> bl = Beamline([qf], context=c3);

julia> bl[qf][1].Kn1
0.36

Notice that trying to access the value of Kn1 directly from qf does not work since c3 is not stored where it can be found:

julia> qf.Kn1
ERROR: Variable Kn1 is not defined in the local Context nor in GLOBAL_CONTEXTS

julia> push!(GLOBAL_CONTEXTS, c3)    # Make c3 available globally

julia> qf.Kn1                        # Now this works
0.36
source
Beamlines.Controller — Type
Controller

An eagerly-evaluated controller of LatElement properties or other Controller properties. Similar to classical Bmad's "Overlay" or "Group".

Also see set!.

Tip

In SciBmad, it is generally preferred to use the lazily-evaluated DefExpr for deferred expressions.

Examples

qf = Quadrupole(Kn1=0.36, L=0.5)
qd = Quadrupole(Kn1=-0.36, L=0.5)

c1 = Controller(
  (qf, :Kn1) => (ele; x) ->  x,
  (qd, :Kn1) => (ele; x) -> -x;
  vars = (; x = 0.0,)
)

# Now we can vary both simultaneously:
c1.x = 60.
qf.Kn1 == -qd.Kn1 == 60 # true

# Controllers also include the element itself. This can 
# be useful if the current elements' values should be 
# used in the function:
c2 = Controller(
  (qf, :Kn1) => (ele; dKn1) ->  ele.Kn1 + dKn1,
  (qd, :Kn1) => (ele; dKn1) ->  ele.Kn1 - dKn1;
  vars = (; dKn1 = 0.0,)
) 

c2.dKn1 = 20
qf.Kn1 == -qd.Kn1 == 80 # true

# Controllers can also be used to control other controllers:
c3 = Controller(
  (c1, :x) => (ctrl; dx) -> ctrl.x + dx;
  vars = (; dx = 0.0,)
)
source
Beamlines.DefExpr — Type
DefExpr{T}

A lazily-evaluated deferred expression returning type T. Deferred expressions are lambda functions that "close" over a variable in the current scope. They can be used to specify inter-dependent parameters in an accelerator and guarantee that no parameter ever becomes "stale".

Also see Context.

Examples

julia> a = 0.36;

julia> qf = Quadrupole(Kn1L=DefExpr(()->a)); # captures variable a

julia> qf.Kn1L
0.36

julia> a = 0.7
0.7

julia> qf.Kn1L
0.7

Slightly better performance may be achieved by explicitly typing the captured variable:

julia> b::Float64 = 0.2;

julia> qf = Quadrupole(Kn1L=DefExpr(()->b)); # captures variable b with known type

julia> qf.Kn1L
0.2

julia> b = 0.4
0.4

julia> qf.Kn1L
0.4

Deferred expressions can be treated and operated with as regular numbers, even outside the context of Beamlines, and can be evaluated by calling it like a function with no arguments (with ()):

julia> c = 64;

julia> cd = DefExpr(()->sin(c));

julia> c = pi;

julia> cd = DefExpr(()->sin(c));

julia> cd()
0.0

julia> c = pi/2;

julia> cd()
1.0

julia> dd = cd + 5;

julia> dd()
6.0

An optional Context argument can be provided:

julia> d = DefExpr(c -> c.a + c.b);

julia> c1 = Context(a = 1, b = 2);

julia> d(c1)
3
source
Beamlines.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
source
Beamlines.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 the em_field function. Default is nothing
  • em_field_normalized: If true, then EM field values returned are normalized by p_over_q_ref; default is false.
source
Beamlines.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
source
Beamlines.Exact — Type
Exact()

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

source
Beamlines.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 both C and D being 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 the four_potential function. Default is nothing

  • four_potential_normalized: If true, then potential/derivatives returned are normalized by p_over_q_ref; default is false.
source
Beamlines.IBSParams — Type
IBSParams

Defines intra-beam scattering modelling.

Properties

  • ibs_model: A IBSModel that specifies which intra-beam scattering model is used
source
Beamlines.IgnoreParams — Type
IgnoreParams

Holds a list of parameter groups of a LatElement to be ignored, which allows parameter groups to be switched off without removing them from the element. Beamlines itself only stores the list: what ignoring a parameter group means is up to downstream code, such as tracking.

ele = Quadrupole(L=0.5, Kn1=0.3, x_offset=1e-3)
ele.ignore_params = [AlignmentParams]                   # Ignore the AlignmentParams
ele.ignore_params = [AlignmentParams, BMultipoleParams] # Also ignore the BMultipoleParams
ele.ignore_params = []                                  # Ignore nothing

ignore_params can also be set as a keyword argument, e.g. Quadrupole(L=0.5, Kn1=0.3, ignore_params=[BMultipoleParams]). The value must be a vector, even for a single parameter group, e.g. ele.ignore_params = [AlignmentParams].

Properties

  • ignore_params: List of parameter groups of the element to be ignored, e.g. [BMultipoleParams]
source
Beamlines.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

source
Beamlines.InheritParams — Type
InheritParams

Stores a parent LatElement through which any parameter groups NOT present in the "child" element containing the InheritParams would inherit. E.g., if the child element has its own BeamlineParams, then any property from the BeamlineParams parameter group would be read/ write to the child's BeamlineParams.

Properties:

  • parent: Parent LatElement to inherit parameter groups from for both reading and writing.
source
Beamlines.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 beamline
  • E_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]
source
Beamlines.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.

source
Beamlines.Lattice — Type
Lattice

Structure containing a vector of Branches.

Properties

  • name: Name of the Lattice. Defaults to blank "".
  • branches: Vector of the branches in the Lattice. These are copies of the Branches the Lattice was constructed with, which are left unmodified
  • context: Context shared by the Lattice, all of its Branches, and all of their Beamlines. Setting the context of any of them sets it for all of them.
source
Beamlines.Lattice — Method
Lattice(branches::Vector{Branch}; name = "", context = Context())

Constructs a Lattice given the vector of branches branches. The Lattice holds copies (see copy(::Branch)) of the Branches, whose LatElements are children of those of the corresponding Branch in branches. The Branches in branches are not modified, so a Branch may appear more than once and may also be used in other Lattices. Branches without a name are named "b<i>", where <i> is the index of the branch. The contexts of the Branches and context are merged into a single Context shared by the Lattice, all of its Branches, and all of their Beamlines. Variables in context take precedence over those in the Branches.

Example

bl1 = Beamline([Marker(E_ref=10e9, species_ref=Species("electron")), Drift(L=1)])
bl2 = Beamline([Drift(L=2)])

lattice = Lattice([Branch([bl1]), Branch([bl2])])

Lattice(beamlines::Vector{Beamline}; name = "", context = Context())

Constructs a Lattice containing a single Branch made up of the vector of Beamlines beamlines. As with Branch(beamlines), the Branch holds copies of the Beamlines and beamlines is not modified.

Example

bl1 = Beamline([Marker(E_ref=10e9, species_ref=Species("electron")), Drift(L=1)])
bl2 = Beamline([Drift(L=2)])

lattice = Lattice([bl1, bl2]) # Equivalent to Lattice([Branch([bl1, bl2])])
source
Beamlines.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' coordinates v, and optionally spin quaternions q. 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 the p variable in transport_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)
source
Beamlines.MatrixKick — Type
MatrixKick(; order=4, opt_scheme=true)

Symplectic integrator using a matrix-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
source
Beamlines.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 string
  • label: A label string
  • description: A descriptive string
source
Beamlines.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]
source
Beamlines.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 containing Beamline [1]
  • phi0: Phase offset of the oscillating field w.r.t. zero_phase [rad]
  • zero_phase: A PhaseRef that specifies what phi0 should mean, see PhaseRef
  • traveling_wave: true if traveling wave, false if standing wave
  • is_crabcavity: true if this is a crab cavity, false otherwise
source
Beamlines.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
source
Beamlines.SolenoidKick — Type
SolenoidKick(; order=4, opt_scheme=true)

Symplectic integrator using a solenoid-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
source
Beamlines.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 string
  • L: Length of the element [m]
  • fringe_at: A Fringe that specifies which, if any, element ends should include fringe field modelling. Default is Fringe.BothEnds
  • n_steps: Number of integrator steps to take per element slice, default is 1
  • ds_step: Length of each integrator step to take per element slice, such that n_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 vary n_steps/ds_step instead for performance.
  • tracking_method: Tracking method for the element
  • rad_damping: true if the deterministic effect of synchrotron radiation is included, false otherwise. Defaults to false
  • rad_fluctuations: true if the stochastic radiation kicks are included, false otherwise. Defaults to false
source
Beamlines._Branch — Type
mutable struct _Branch{T<:_AbstractBeamline} <: _AbstractBranch

_Branch exists to break a mutual type recursion since Beamline has a reference to a Branch, and Branch needs a vector of Beamlines. Julia < v1.14 has no forward declarations, so to get around this, _Branch is used.

Why not just use Branch{T} and skip defining _Branch? This could be done but in this case Branch would become a UnionAll rather than a concrete type leading to type instability.

source
Beamlines._EleAtom — Type
struct _EleAtom

A parsed {branch>>}{kind::}name{#N} element match. index is nonzero if name is an element index, and instance is nonzero if there is a #N suffix.

source
Beamlines._NameMatcher — Type
struct _NameMatcher

Holds the information needed to turn the name parts of a match string into Regexes. is_regex is true if the match string was a Regex, in which case compile_options and match_options are the options of that Regex.

source
Beamlines._SearchLine — Type
struct _SearchLine

A line of elements searched by findelements: the elements of a Branch, or of a Beamline when a Beamline is searched, along with the name of the Branch the elements are in. The name is nothing if the elements are not in a Branch.

source
Base.copy — Method
Base.copy(bl::Beamline)

Copy of bl that is not in any Branch and has a copy of the Context of bl. Each LatElement of the copy is a new element that inherits (via InheritParams) from the corresponding element of bl and has its own BeamlineParams. Parameters are therefore shared with bl through inheritance, while the position of each element (s, beamline, etc.) is that in the copy. bl is not modified.

source
Base.copy — Method
Base.copy(branch::Branch)

Copy of branch that is not in any Lattice. The Beamlines are copied as with copy(::Beamline), so the LatElements of the copy are children of those in branch. The Context is copied.

source
Base.empty! — Method
empty!(::Beamline)

Removes BeamlineParams from all elements in the Beamline and empties the array of LatElements.

WARNING: this is irreversible.

source
Base.getindex — Method
Base.getindex(bl::Beamline, pattern::Union{AbstractString,Regex}) -> Vector{LatElement}

Same as findelements(bl, pattern). Example: bl["Quadrupole::q*"] or bl[r"q\d+"].

source
Base.getindex — Method
Base.getindex(branch::Branch, pattern::Union{AbstractString,Regex}) -> Vector{LatElement}

Same as findelements(branch, pattern). Example: branch["Quadrupole::q*"] or branch[r"q\d+"].

source
Base.getindex — Method
Base.getindex(lat::Lattice, pattern::Union{AbstractString,Regex}) -> Vector{Branch}
Base.getindex(lat::Lattice, branches, pattern::Union{AbstractString,Regex}) -> Vector{LatElement}

With one index, returns the branches of lat that match pattern, the same as findbranches(lat, pattern).

With two indexes, returns the elements that match pattern in the branches selected by branches, which is : (all branches), a branch index, or a branch pattern as used with findbranches. The elements are in the order of the branches and then their order in the branch. lat[:, pattern] is the same as findelements(lat, pattern).

The one index form always returns branches and the two index form always returns elements, so the type of the result does not depend on what is matched.

Examples

lat["ring"]           # The branches named "ring".
lat["2"]              # The second branch.
lat[r"x.*"]           # Branches whose name starts with "x".
lat[:, "q*"]          # Elements whose name starts with "q" in all branches.
lat["ring", "q*"]     # Elements whose name starts with "q" in the branches named "ring".
lat[2, "Quadrupole::*"]  # Quadrupoles in the second branch.
lat[:, "ring>>7"]     # 7th element of the branch named "ring".
source
Base.merge — Method
merge(c::Context, cs::Context...)

Construct a new Context containing the variables of all of the given Contexts. If a variable is defined in more than one of the Contexts, the value from the last one is used. The type parameter of the returned Context is the promote_type of the type parameters of the inputs, and each value is converted to it using coerce. For example, merging a Context{Float32} with a Context{Float64} gives a Context{Float64}. Only the variables stored in the given Contexts are included; variables from GLOBAL_CONTEXTS are not.

Examples

julia> c1 = Context(a = 1, b = 2);

julia> c2 = Context(c = 3, d = 4);

julia> c3 = merge(c1, c2);

julia> c3.a + c3.d
5

julia> c4 = merge(Context{Int}(a = 1), Context{Float64}(b = 2.0));

julia> typeof(c4)
Context{Float64}

julia> c4.a
1.0
source
Beamlines.BPM — Method
BPM(; L=0f0, kwargs...)

Constructs a LatElement with kind = "BPM". The default tracking_method is Exact() for any L. Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.BeamBeam — Method
BeamBeam(; L=0f0, kwargs...)

Constructs a LatElement with kind = "BeamBeam". The default tracking_method is Implicit() for any L. Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.CrabCavity — Method
CrabCavity(; L=0f0, kwargs...)

Constructs a LatElement with kind = "CrabCavity" and is_crabcavity = true. If L != 0, the default tracking_method is SolenoidKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Drift — Method
Drift(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Drift". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.HKicker — Method
HKicker(; L=0f0, kwargs...)

Constructs a LatElement with kind = "HKicker". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Kicker — Method
Kicker(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Kicker". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Map — Method
Map(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Map". The default tracking_method is Exact() for any L. Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Marker — Method
Marker(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Marker". The default tracking_method is Exact() for any L. Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Multipole — Method
Multipole(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Multipole". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Octupole — Method
Octupole(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Octupole". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Patch — Method
Patch(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Patch". The default tracking_method is Exact() for any L. Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Quadrupole — Method
Quadrupole(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Quadrupole". If L != 0, the default tracking_method is MatrixKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.RFCavity — Method
RFCavity(; L=0f0, kwargs...)

Constructs a LatElement with kind = "RFCavity". If L != 0, the default tracking_method is SolenoidKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.SBend — Method
SBend(; L=0f0, kwargs...)

Constructs a LatElement with kind = "SBend". If L != 0, the default tracking_method is BendKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Sextupole — Method
Sextupole(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Sextupole". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.Solenoid — Method
Solenoid(; L=0f0, kwargs...)

Constructs a LatElement with kind = "Solenoid". If L != 0, the default tracking_method is SolenoidKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines.VKicker — Method
VKicker(; L=0f0, kwargs...)

Constructs a LatElement with kind = "VKicker". If L != 0, the default tracking_method is DriftKick(), else Exact(). Any tracking_method in kwargs overrides the default.

See the documentation for LatElement.

source
Beamlines._context — Method
_context(bl::Beamline)

Return the Context of bl: the Context stored in the Lattice or Branch that bl is in, if any, else the Context stored in bl itself. See _context(::Branch).

source
Beamlines._context — Method
_context(branch::Branch)

Return the Context of branch: the Context stored in the Lattice that branch is in, if any, else the Context stored in branch itself.

The Context of a Lattice, or of a Branch not in a Lattice, is stored only at that highest level. The Branches and Beamlines below it store NULL_CONTEXT, which is set when they are put in the Branch or Lattice. Setting the context property at any level sets the field of the highest level only.

source
Beamlines._eval_ele_atom — Method
_eval_ele_atom(lines::Vector{_SearchLine}, a::_EleAtom) -> Vector{_EleID}

IDs of the elements in lines that match the atom a. For each line that passes the branch qualifier, the elements are selected by name (or index), then by kind, and then the #N instance is picked.

source
Beamlines._eval_ele_range — Method
_eval_ele_range(lines, a1::_EleAtom, a2::_EleAtom, nm::_NameMatcher) -> Vector{_EleID}

IDs of the elements in the range a1:a2: all elements from the element matched by a1 to the element matched by a2, inclusive. The range is evaluated separately in each line where both a1 and a2 match, and wraps around the end of the line if a2 comes before a1.

source
Beamlines._eval_match_str — Method
_eval_match_str(atom_ids::Function, nm::_NameMatcher, texts, ops) -> Vector{_EleID}

Evaluates the lexed match string texts/ops with the union (,) and intersection (&) operators, & having the lower precedence. Each piece between the ,s is evaluated by atom_ids(texts, ops) -> Vector{_EleID}, which findelements and findbranches supply and which handles a single atom or a range (:). Returned are the unique IDs, sorted so they are in lattice order. findbranches uses (1, branch index) as the ID of a branch.

source
Beamlines._lex_match_str — Method
_lex_match_str(str::AbstractString, is_regex::Bool) -> (texts, ops)

Splits the match string str at the operators in _MATCH_OPS. Returned are the vector ops of operators and the vector texts of the (whitespace stripped) strings between them, with length(texts) == length(ops) + 1. If is_regex is true, characters that are escaped or are within a group (...), character class [...], or {n,m} quantifier of the regex are never treated as operators.

source
Beamlines._name_regex — Method
_name_regex(nm::_NameMatcher, text::AbstractString) -> Regex

Regex that matches a whole name to the name part text of a match string. If the match string is a Regex, text is compiled with the flags of the match string, anchored at both ends. Otherwise text is a Bmad wild card pattern converted by _wildcard_regex.

source
Beamlines._parse_ele_atom — Method
_parse_ele_atom(nm::_NameMatcher, texts::Vector{String}, ops::Vector{String}) -> _EleAtom

Parses the texts/ops sequence of a single atom {branch>>}{kind::}name{#N}, where ops contains only >>, ::, and #, each at most once and in that order.

source
Beamlines._search_lines — Method
_search_lines(where::Union{Lattice,Branch,Beamline}) -> Vector{_SearchLine}

The lines searched by findelements: one per branch of a Lattice, the Branch itself, or the Beamline itself. Element indexes, #N instances, and ranges are all relative to a line.

source
Beamlines._split_at_op — Method
_split_at_op(texts, ops, op::String) -> Vector{Tuple{Vector{String},Vector{String}}}

Splits the texts/ops sequence returned by _lex_match_str at each occurrence of the operator op. Each returned piece is itself a (texts, ops) sequence with length(texts) == length(ops) + 1. For example, splitting a, b::c at "," gives the pieces (["a"], []) and (["b", "c"], ["::"]).

source
Beamlines._wildcard_regex — Method
_wildcard_regex(pattern::AbstractString) -> Regex

Converts pattern, which may contain the Bmad wild card characters * (matches any number of characters including zero) and % or ? (each matches any single character), to a Regex that matches whole strings. All other characters match only themselves.

source
Beamlines.deval — Function
deval(d, c::Context=NULL_CONTEXT)

Evaluates d in the Context c if it is a DefExpr, else returns d. E.g. deval(rawget(ele, :Kn1), c) for an element in a Beamline with Context c is ele.Kn1.

For a parameter group, returns a new parameter group with every DefExpr evaluated, or the parameter group itself if it contains no DefExpr.

source
Beamlines.elements — Method
elements(eles_dict)

For more Pythonic-workflows, elements receives a dictionary with key as the element name and value as the element, and sets the name attribute for each element equal to its key.

Julia users should generally use the @elements macro instead.

source
Beamlines.findbranches — Method
findbranches(lat::Lattice, pattern::Union{AbstractString,Regex}) -> Vector{Branch}

Returns all the Branches in lat that match pattern, in the order of the branches in lat. Each branch appears at most once.

pattern is built from atoms that are either a branch name or an integer index of the branch in lat. Atoms may be combined with , (union) and & (intersection). Names are matched as with findelements: a String pattern may use the Bmad wild card characters *, %, and ? while with a Regex pattern the names are Julia regular expressions that must match the whole name.

Examples

findbranches(lat, "ring")          # The branch named "ring".
findbranches(lat, "x*, 1")         # Branches whose name starts with "x" and the first branch.
findbranches(lat, r"b[0-9]+")      # Branches named "b" followed by digits.

See also findelements.

source
Beamlines.findchildren — Method
findchildren(ele::LatElement, bl::Beamline)

Finds all LatElements in the Beamline bl that inherit from ele, either directly (ele is the parent) or through a chain of parents. For example, the elements of a Beamline in a Branch are children of the elements of the Beamline used to create the Branch, which are in turn children of the elements used to create that Beamline.

source
Beamlines.findelements — Method
findelements(where::Union{Lattice,Branch,Beamline}, pattern::Union{AbstractString,Regex}) -> Vector{LatElement}

Returns all the LatElements in where that match pattern. where may be a Lattice, a Branch, or a Beamline. The returned elements are ordered by the order of the branches followed by their order in the branch, and each element appears at most once. No match is not an error, and an empty vector is returned.

Syntax

The syntax is based on Bmad's. An "atom" is of the form

  {branch>>}{kind::}name{#N}

where {...} marks an optional part and

  • branch Match only elements in a Branch whose name matches.
  • kind Match only elements whose kind is kind, e.g. Quadrupole. This must be an exact match.
  • name Element name to match, or an integer element index where the first element of a Branch (or of the Beamline when where is a Beamline) has index 1. With an index and no branch, the element with that index in each branch searched is matched.
  • #N Match only the Nth element in each branch that matches the rest of the atom.

Atoms may be combined:

  atom1:atom2    # Range: All elements from atom1 through atom2 inclusive.
  set1, set2     # Union.
  set1 & set2    # Intersection.

& has the lowest precedence, so A, B & C is the intersection of A, B with C. A range is evaluated in each branch where both atom1 and atom2 match, and it is an error if either matches more than one element in that branch. If atom2 comes before atom1, the range wraps around the end of the branch.

Name matching

If pattern is a String, the branch and element names may use the Bmad wild card characters *, which matches any number of characters (including zero), and % or ?, either of which matches any single character. There are no other wildcard characters here.

If pattern is a Regex, e.g. r"q[0-9]+", the branch and element names are Julia regular expressions. Each must match the whole name, so r"Q" does not match an element named Q1. The flags of pattern (e.g. i for case insensitive) are applied to each. Operator characters in a regex group (...), character class [...], or quantifier {n,m}, or that are escaped with a backslash, are part of the regular expression.

Matching is case sensitive unless the i flag is used with a Regex.

Examples

findelements(lat, "q*")                     # Elements whose name begins with "q".
findelements(lat, r"q.*")                   # Same as above using a regex.
findelements(lat, r"q.*"i)                  # Same as above but case insensitive, so "Q1" also matches.
findelements(lat, "Quadrupole::q%")         # Quadrupoles with a two character name starting with "q".
findelements(lat, "Quadrupole::q?")         # Same as above. "?" and "%" are equivalent.
findelements(lat, "ring>>7")                # 7th element of the branch named "ring".
findelements(lat, "b*>>bpm#2")              # 2nd element named "bpm" in each branch with a name
                                            #   starting with "b".
findelements(lat, "m1:m2")                  # Elements from "m1" through "m2" in a line.
findelements(lat, "Marker::* & m1:m2")      # Markers from "m1" through "m2".
findelements(lat, "q1, q2")                 # Elements named "q1" or "q2".
findelements(lat, r"(q|s)[0-9]{1,2}")       # Regex with operator characters in a group and quantifier.

See also findbranches.

source
Beamlines.isactive — Method
isactive(p) -> Bool

Returns true if the parameter group p should be used in tracking. isactive(nothing) is always false. By default a parameter group is active, however some parameter groups define their own criteria, e.g. RFParams is only active if voltage != 0.

The isactive function does not check the ignore_params list.

source
Beamlines.isapprox_ignoring — Method
isapprox_ignoring(a::LatElement, b::LatElement, ignore::Type{<:AbstractParams}...)

Same as isapprox(a, b) except that the parameter groups ignore are also not compared. BeamlineParams and MetaParams are never compared, and an IgnoreParams with an empty list is treated as no IgnoreParams.

This only affects the comparison: it is unrelated to the ignore_params list of IgnoreParams.

source
Beamlines.rawget — Method
rawget(p::AbstractParams, key::Symbol)
rawget(ele::LatElement, key::Symbol)

Gets the independent variable key of the parameter group p or of the element ele exactly as it is stored, without evaluating deferred expressions: e.g. a DefExpr set for Kn1 is returned as that DefExpr. Evaluating it with deval in the Context of the element's Beamline gives getproperty(ele, key).

Properties which are not independent variables but computed from them (e.g. Kn1L or Bn1 when Kn1 was set last, E_ref when p_over_q_ref was set, s) cannot be gotten raw, and give an error.

Examples

julia> a = 0.36;

julia> qf = Quadrupole(Kn1=DefExpr(()->a), L=0.5);

julia> d = rawget(qf, :Kn1);

julia> qf.Kn1 = 2*d; # Twice the stored expression, still dependent on a

julia> a = 0.4;

julia> qf.Kn1
0.8
source
Beamlines.scalarize! — Method
scalarize!(bl::Beamline)

Modifies the Beamline and its LatElements so all parameters are regular number types. This may be needed after optimizing the element's parameters using e.g. ForwardDiff, ReverseDiff, or GTPSA, which will set the parameter equal to a special number type that propagates the gradients.

source
Beamlines.scalarize! — Method
scalarize!(branch::Branch)

Modifies all Beamlines and their LatElements in the Branch so all parameters are regular number types. This may be needed after optimizing the element's parameters using e.g. ForwardDiff, ReverseDiff, or GTPSA, which will set the parameter equal to a special number type that propagates the gradients.

source
Beamlines.scalarize! — Method
scalarize!(ele::LatElement)

Modifies the LatElement so all element-level parameters are regular number types. This may be needed after optimizing the element's parameters using e.g. ForwardDiff, ReverseDiff, or GTPSA, which will set the parameter equal to a special number type that propagates the gradients.

source
Beamlines.scalarize — Method
scalarize(t)

Value of t with derivative parts removed: ForwardDiff Duals and ReverseDiff tracked values are unwrapped at every nesting level, and a TPS gives its scalar part. Arrays are processed elementwise and parameter groups fieldwise; any other value is returned unchanged.

source
Beamlines.set! — Method
set!(controller)

Resets all controlled LatElements and Controllers in controller to the most recently set values of that controller.

source
Beamlines.writebl — Method

writebl is internal, still being developed, and may change at any time. General users should NOT use it yet.

source
Beamlines.@elements — Macro
@elements ...;
@elements begin
  ...
end

Can be applied before the definition of any LatElement(s) in order to make set the element name equal to the variable symbol automatically.

Examples

julia> @elements qf = Quadrupole();

julia> qf.name
"qf"

julia> @elements begin
         my_drift = Drift(L=0.5);
         my_sextupole = Sextupole(Kn2L=3.2);
       end;

julia> my_drift.name
"my_drift"

julia> my_sextupole.name
"my_sextupole"
source
Beamlines.ApertureAt — Module
@enumx ApertureAt::UInt8 Entrance Exit BothEnds

Defines at which ends of the element the aperture should be applied

source
Beamlines.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.
source
Beamlines.RateMeaning — Module
@enumx RateMeaning::Int8 RFFrequency=false Harmon=true Indeterminate=-1

Specifies which independent variable is stored in the RFParams.

source
Beamlines.Fringe — Module
@enumx Fringe::Int8 NoEnd BothEnds EntranceEnd ExitEnd

Defines which ends fringe field modelling should be included

source
Beamlines.IBSModel — Module
@enumx IBSModel::Int8 None Gaussian GaussianDampingOnly GaussianFluctuationsOnly

Which intra-beam scattering model should be used.

source