Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified manual/AcceleratorLattice.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions manual/attic/Notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ Getting the offset right can be tricky!
* End element in a branch must be a marker.

* Document Ele.pdict[:private] used in keeping track of split drifts.

* Fork elements BodyShiftParams do not affect the forked to branch.
3 changes: 3 additions & 0 deletions manual/ele-param-groups.tex
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,14 @@ \section{ForkParams}
to_line::Union{BeamLine,Branch} - Beam line to fork to
to_ele::Union{String,Ele} - Element forked to.
direction::Int - Longitudinal Direction of injected beam.
propagate_reference::Bool - Propagate reference species and energy?
\end{example}

This group is used with a \vn{Fork} element and specifies how the fork element attaches to
another branch.

Propagate will be done initially, even with \vn{propagate_reference} set to false, if the
reference species or reference energy is not set in beginning element of the forked to branch.

%---------------------------------------------------------------------------------------------------
\section{GirderParams}
Expand Down
54 changes: 35 additions & 19 deletions src/bookkeeper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{BendParams}, changed::
bg.angle = L * bg.g
end

if L != ele.L
ele.L = L
changed.this_ele_length = true
changed.s_position = true
changed.floor_position = true
end

bg.bend_field_ref = bg.g * ele.pc_ref / (C_LIGHT * charge(ele.species_ref))

if haskey(cdict, :L_chord)
Expand Down Expand Up @@ -582,17 +589,28 @@ end

function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{ForkParams},
changed::ChangedLedger, previous_ele::Ele)

fg = ele.ForkParams
rg = ele.ReferenceParams

to_ele = fg.to_ele
to_ele.ix_ele != 1 && return

if !fg.propagate_reference && !is_null(to_ele.species_ref) && (!isnan(to_ele.E_tot_ref) || !isnan(to_ele.pc_ref))
return
end

if to_ele.species_ref == Species("Null"); to_ele.species_ref = fork.species_ref; end
if to_ele.pc_ref == NaN && to_ele.E_tot_ref == NaN
to_ele.pc_ref = fork.pc_ref
to_ele.E_tot_ref = fork.pc_ref
if rg.species_ref == to_ele.species_ref && (rg.E_tot_ref == to_ele.E_tot_ref || rg.pc_ref == to_ele.pc_ref)
return
end

to_ele.pdict[:changed][:pc_ref] = to_ele.pc_ref
to_ele.species_ref = rg.species_ref
to_ele.pc_ref = rg.pc_ref

set_branch_min_max_changed!(to_ele.branch, 1)
clear_changed!(ele, ForkParams)

return
end

#---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -671,7 +689,8 @@ end
`ReferenceParams` bookkeeping.
"""

function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{ReferenceParams}, changed::ChangedLedger, previous_ele::Ele)
function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{ReferenceParams},
changed::ChangedLedger, previous_ele::Ele)
rg = ele.ReferenceParams
cdict = ele.changed

Expand All @@ -690,20 +709,14 @@ function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{ReferenceParams}, chan
if !changed.reference; return; end
if rg.species_ref == Species(); error("Species not set for first element in branch: $(ele_name(ele))"); end

if count([haskey(cdict, :pc_ref), haskey(cdict, :E_tot_ref), haskey(cdict, :β_ref), haskey(cdict, :γ_ref)]) > 1
error("Beginning element has more than one of pc_ref, E_tot_ref, β_ref, and γ_ref set in $(ele_name(ele))")
if haskey(cdict, :pc_ref) && haskey(cdict, :E_tot_ref)
error("Beginning element has both pc_ref and E_tot_ref set in $(ele_name(ele))")
elseif haskey(cdict, :E_tot_ref)
rg.pc_ref = calc_pc(rg.species_ref, E_tot = rg.E_tot_ref)
elseif haskey(cdict, :pc_ref)
rg.E_tot_ref = calc_E_tot(rg.species_ref, pc = rg.pc_ref)
elseif haskey(cdict, :β_ref)
rg.pc_ref = calc_pc(rg.species_ref, β = rg.γ_ref)
rg.E_tot_ref = calc_E_tot(rg.species_ref, pc = rg.pc_ref)
elseif haskey(cdict, :γ_ref)
rg.pc_ref = calc_pc(rg.species_ref, β = rg.γ_ref)
rg.E_tot_ref = calc_E_tot(rg.species_ref, pc = rg.pc_ref)
else
error("Neither pc_ref E_tot_ref, β_ref, nor γ_ref set for: $(ele_name(ele))")
error("Neither pc_ref nor E_tot_ref set for: $(ele_name(ele))")
end

clear_changed!(ele, ReferenceParams)
Expand All @@ -718,7 +731,8 @@ function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{ReferenceParams}, chan
rg.species_ref = previous_ele.species_ref

if ele.static_energy_ref
if isnan(rg.pc_ref) && isnan(rg.E_tot_ref); error("With static_energy_ref set true, either pc_ref or E_tot_ref must be set in $(ele_name(ele))"); end
isnan(rg.pc_ref) && isnan(rg.E_tot_ref) &&
error("With static_energy_ref set true, either pc_ref or E_tot_ref must be set in $(ele_name(ele))")
if haskey(cdict, :E_tot_ref) || isnan(rg.pc_ref)
rg.pc_ref = calc_pc(rg.species_ref, E_tot = rg.E_tot_ref)
else
Expand All @@ -728,12 +742,14 @@ function ele_paramgroup_bookkeeper!(ele::Ele, group::Type{ReferenceParams}, chan
elseif previous_ele.dE_ref == 0
rg.pc_ref = previous_ele.pc_ref
rg.E_tot_ref = previous_ele.E_tot_ref
rg.time_ref = previous_ele.time_ref + previous_ele.extra_dtime_ref + previous_ele.L * previous_ele.E_tot_ref / (C_LIGHT * previous_ele.pc_ref)
rg.time_ref = previous_ele.time_ref + previous_ele.extra_dtime_ref +
previous_ele.L * previous_ele.E_tot_ref / (C_LIGHT * previous_ele.pc_ref)

else
rg.pc_ref, rg.E_tot_ref = calc_changed_energy(previous_ele.species_ref, previous_ele.pc_ref, previous_ele.dE_ref)
rg.pc_ref, rg.E_tot_ref = calc_changed_energy(previous_ele.species_ref,
previous_ele.pc_ref, previous_ele.dE_ref)
rg.time_ref = previous_ele.time_ref + previous_ele.extra_dtime_ref + previous_ele.L *
(previous_ele.E_tot_ref + rg.E_tot_ref) / (C_LIGHT * (previous_ele.pc_ref + rg.pc_ref))
(previous_ele.E_tot_ref + rg.E_tot_ref) / (C_LIGHT * (previous_ele.pc_ref + rg.pc_ref))
end

# End stuff
Expand Down
9 changes: 5 additions & 4 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ ELE_PARAM_INFO_DICT = Dict(
:to_line => ParamInfo(ForkParams, Union{BeamLine, Nothing}, "Beamline forked to."),
:to_ele => ParamInfo(ForkParams, Union{String,Ele}, "Lattice element forked to."),
:direction => ParamInfo(ForkParams, Int, "Direction (forwards or backwards) of injection."),
:propagate_reference => ParamInfo(ForkParams, Bool, "Propagate reference species and energy?"),

:supported => ParamInfo(GirderParams, Vector{Ele}, "Array of elements supported by a Girder."),

Expand Down Expand Up @@ -614,9 +615,9 @@ end

Table of what element parameter groups are associated with what element types.
Order is important. Bookkeeping routines rely on:
- `LengthParams` being first (except for a `Bend` where BendParams is `first`).
- `BendParams` after `ReferenceParams` and `MasterParams` (in case the reference energy is changing).
- `BMultipoleParams` and `EMultipoleParams` after `MasterParams` (in case the reference energy is changing).
- `ReferenceParams` before anything that depends upon the reference energy like `BMultipoleParams`.
- `BendParams` before `LengthParams` in case the length is modified by the User setting, say, `angle` and `g`.
- `LengthPrams` before anything that depends upon the length like `BMultipoleParams`.
- `RFCommonParams` comes last (triggers autoscale/autophase and `ReferenceParams` correction).
""" PARAM_GROUPS_LIST

Expand Down Expand Up @@ -684,7 +685,7 @@ ELE_PARAM_GROUP_INFO = Dict(
EMultipoleParams => EleParamsInfo("Electric multipoles.", false),
EMultipole => EleParamsInfo("Electric multipole of given order. Substructure contained in `EMultipoleParams`.", false),
FloorParams => EleParamsInfo("Global floor position and orientation.", true),
ForkParams => EleParamsInfo("Fork element parameters", false),
ForkParams => EleParamsInfo("Fork element parameters", true),
GirderParams => EleParamsInfo("Girder parameters.", false),
InitParticleParams => EleParamsInfo("Initial particle position and spin.", false),
LengthParams => EleParamsInfo("Length and s-position parameters.", true),
Expand Down
4 changes: 4 additions & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ show_column2 = Dict{Type{T} where T <: BaseEleParams, Dict{Symbol,Symbol}}(
:eta => :etap,
),

ForkParams => Dict{Symbol,Symbol}(
:direction => :propagate_reference
),

GirderParams => Dict{Symbol,Symbol}(
:origin_ele => :origin_ele_ref_pt,
:dr => :dq,
Expand Down
79 changes: 52 additions & 27 deletions src/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ abstract type EleParams <: BaseEleParams end
abstract type EleParameterSubParams <: BaseEleParams end

#---------------------------------------------------------------------------------------------------
# BMultipole subgroup
# BMultipole subparams

"""
mutable struct BMultipole <: EleParameterSubParams
Expand Down Expand Up @@ -321,7 +321,7 @@ Used by `BMultipoleParams`.
end

#---------------------------------------------------------------------------------------------------
# Dispersion subgroup
# Dispersion subparams

"""
Dispersion parameters for a single axis.
Expand All @@ -335,7 +335,7 @@ Dispersion parameters for a single axis.
end

#---------------------------------------------------------------------------------------------------
# EMultipole subgroup
# EMultipole subparams

"""
mutable struct EMultipole <: EleParameterSubParams
Expand All @@ -362,7 +362,7 @@ Used by `EMultipoleParams`.
end

#---------------------------------------------------------------------------------------------------
# Twiss subgroup.
# Twiss subparams.

"""
mutable struct Twiss <: EleParameterSubParams
Expand All @@ -378,7 +378,7 @@ Twiss parameters for used for BeamBeam element to describe the strong beam.
end

#---------------------------------------------------------------------------------------------------
# Twiss1 subgroup
# Twiss1 subparams

"""
mutable struct Twiss1 <: EleParameterSubParams
Expand All @@ -398,53 +398,74 @@ Twiss parameters for a single mode.
end

#---------------------------------------------------------------------------------------------------
# Vertex1 subgroup
# VertexSubParams

"""
struct Vertex1 <: EleParameterSubParams
abstract type VertexSubParams <: EleParameterSubParams

Single vertex. An array of vertices can be used to construct an aperture.
If `radius_x`, and `radius_y` )and possibly `tilt`) are set, this specifies the shape of the elliptical arc
of the chamber wall from the vertex point to the next vertex point.
If not set, the chamber wall from the vertex to the next vertex is a straight line.
Abstract type that Vertex1 and VertexEllipse inherit from.
"""

abstract type VertexSubParams <: EleParameterSubParams end

#---------------------------------------------------------------------------------------------------
# Vertex1 subparams

"""
struct Vertex1 <: VertexSubParams <: EleParameterSubParams

Single vertex point. An array of vertices can be used to construct an aperture.
Also see `VertexEllipse`.

## Fields
• `r0::Vector{Number}` - (x, y) coordinate of vertex point. \\
• `radius_x::Number` - Horizontal ellipse radius. \\
• `radius_y::Number` - Vertical ellipse radius. \\
• `tilt::Number` - Tilt of ellipse. \\
• `r0::Vector{Number}` - (x, y) coordinate of vertex point. \\
""" Vertex1

@kwdef mutable struct Vertex1 <: EleParameterSubParams
r0::Vector{Number} = [NaN, NaN]
radius_x::Number = NaN
radius_y::Number = NaN
tilt::Number = NaN
point::Vector{Number} = [NaN, NaN]
end

Vertex1(r0::Vector{Number}, rx::Number = NaN, ry::Number = NaN) =
Vertex1(r0 = r0, radius_x = rx, radius_y = ry, NaN)

#---------------------------------------------------------------------------------------------------
# Wall2D subgroup
# VertexEllipse

"""
struct VertexEllipse <: VertexSubParams <: EleParameterSubParams

Placed in between two `Vertex1` vertices in the `vertex` array of the `Wall2d` struct to indicate
that the aperture outline follows an ellipse between the vertices.

## Fields

• `radius::Vector{Number}` - Ellipse (rx, ry) ellipse radiuses. \\
• `tilt::Number` - Tilt of ellipse. \\
""" VertexEllipse

@kwdef mutable struct VertexEllipse <: EleParameterSubParams
radius::Vector{Number} = [0.0]
tilt::Number = 0.0
end

#---------------------------------------------------------------------------------------------------
# Wall2D subparams

"""
mutable struct Wall2D <: EleParameterSubParams

Vacuum chamber wall cross-section.

## Fields
• `vertex::Vector{Vertex1}` - Array of vertices. \\

• `vertex::Vector{VertexSubParams}` - Array of vertices. \\
• `r0::Vector{Number}` - Origin point. \\
""" Wall2D

@kwdef mutable struct Wall2D <: EleParameterSubParams
vertex::Vector{Vertex1} = Vector{Vertex1}()
r0::Vector{Number} = [0.0, 0.0]
absolute_vertices::Bool = false
vertex::Vector{VertexSubParams} = Vector{VertexSubParams}()
end

Wall2D(v::Vector{Vertex1}) = Wall2D(v, [0.0, 0.0])

#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
# ACKickerParams
Expand Down Expand Up @@ -480,7 +501,7 @@ Vacuum chamber aperture struct.
• `wall::Wall2D` - Aperture defined by an array of vertices. \\
• `aperture_shape::ApertureShape.T` - Aperture shape. Default is `ApertureShape.ELLIPTICAL`. \\
• `aperture_at::BodyLoc.T` - Where aperture is. Default is `BodyLoc.ENTRANCE_END`. \\
• `aperture_shifts_with_body:Bool` - Do element alignments shifts move the aperture? Default is `false`. \\
• `aperture_shifts_with_body:Bool` - Do element alignments shifts move the aperture? Default is `false`. \\
• `custom_aperture::Dict` - Custom aperture information. \\
""" ApertureParams

Expand Down Expand Up @@ -714,12 +735,16 @@ Fork element parameters.
• `to_line::Union{BeamLine,Nothing}` - Beam line to fork to. \\
• `to_ele::Union{String,Ele}` - On input: Element ID or element itself. \\
• `direction::Int` - Longitudinal Direction of injected beam. \\
• `propagate_reference::Bool` - Propagate reference species and energy? \\


""" ForkParams

@kwdef mutable struct ForkParams <: EleParams
to_line::Union{BeamLine,Nothing} = nothing
to_ele::Union{String,Ele} = ""
direction::Int = +1
propagate_reference::Bool = true
end

#---------------------------------------------------------------------------------------------------
Expand Down
Loading