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
18 changes: 9 additions & 9 deletions src/enum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ Makes list into a enum group and exports the names
""" enumit

macro enumit(str::AbstractString)
eval( Meta.parse("@enum $str") )
eval( Meta.parse("@enumx $str") )
str2 = join(split(str), ',')
eval( Meta.parse("export $str2") )
end

@enumit("ApertureType RECTANGULAR ELLIPTICAL")
@enumit("BendType SBEND RBEND")
@enumit("BodyLocation ENTRANCE_END B_CENTER EXIT_END BOTH_ENDS NOWHERE EVERYWHERE")
@enumit("Bend SECTOR RECTANGULAR")
@enumit("BodyLoc ENTRANCE_END CENTER EXIT_END BOTH_ENDS NOWHERE EVERYWHERE")
@enumit("BranchGeometry OPEN CLOSED")
@enumit("CavityType STANDING_WAVE TRAVELING_WAVE")
@enumit("ControlSlaveType DELTA ABSOLUTE CONTROL_NOT_SET")
@enumit("FieldCalcMethod FIELD_MAP FIELD_STANDARD")
@enumit("Cavity STANDING_WAVE TRAVELING_WAVE")
@enumit("SlaveControl DELTA ABSOLUTE NOT_SET")
@enumit("FieldCalc MAP STANDARD")
@enumit("Interpolation LINEAR SPLINE")
@enumit("LordStatus NOT_A_LORD SUPER_LORD MULTIPASS_LORD GOVERNOR")
@enumit("SlaveStatus NOT_A_SLAVE SUPER_SLAVE MULTIPASS_SLAVE")
@enumit("StreamLocation UPSTREAM_END CENTER INSIDE DOWNSTREAM_END")
@enumit("Lord NOT SUPER MULTIPASS GOVERNOR")
@enumit("Slave NOT SUPER MULTIPASS")
@enumit("StreamLoc UPSTREAM_END CENTER INSIDE DOWNSTREAM_END")

@enumit("TrackingMethod RUNGE_KUTTA TIME_RUNGE_KUTTA STANDARD_TRACKING")
@enumit("TrackingState PREBORN ALIVE PRETRACK LOST LOST_NEG_X LOST_POS_X LOST_NEG_Y LOST_POS_Y LOST_PZ LOST_Z")
22 changes: 11 additions & 11 deletions src/find.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ end
# ele_at_s

"""
ele_at_s(branch::Branch, s::Real; choose::StreamLocation = UPSTREAM_END, ele_near::ELE = NULL_ELE)
ele_at_s(branch::Branch, s::Real; choose::StreamLoc.T = StreamLoc.UPSTREAM_END, ele_near::ELE = NULL_ELE)
-> ele_overlap::Ele

Returns lattice element `ele_overlap` that overlaps a given longitudinal s-position.
Expand All @@ -234,8 +234,8 @@ That is, `s` will be in the interval `[ele_overlap.s, ele_overlap.s_downstream]`
- `branch` Lattice `Branch` to search.
- `s` Longitudinal position to match to.
- `choose` If there is a choice of elements, which can happen if `s` corresponds to a boundary
point between two elements, `choose` is used to pick either the `UPSTREAM_END`
element (default) or `DOWNSTREAM_END` element.
point between two elements, `choose` is used to pick either the `StreamLoc.UPSTREAM_END`
element (default) or `StreamLoc.DOWNSTREAM_END` element.
- `ele_near` If there are elements with negative drift lengths (generally this will be a
`drift` or `patch` element), there might be multiple solutions. If `ele_near`
is specified, this routine will choose the solution nearest `ele_near`.
Expand All @@ -246,9 +246,9 @@ That is, `s` will be in the interval `[ele_overlap.s, ele_overlap.s_downstream]`

""" ele_at_s

function ele_at_s(branch::Branch, s::Real; choose::StreamLocation = UPSTREAM_END, ele_near::Ele = NULL_ELE)
function ele_at_s(branch::Branch, s::Real; choose::StreamLoc.T = StreamLoc.UPSTREAM_END, ele_near::Ele = NULL_ELE)
check_if_s_in_branch_range(branch, s)
if choose != UPSTREAM_END && choose != DOWNSTREAM_END; error("Bad `choose` argument: $choose"); end
if choose != StreamLoc.UPSTREAM_END && choose != StreamLoc.DOWNSTREAM_END; error("Bad `choose` argument: $choose"); end

# If ele_near is not set
if is_null(ele_near)
Expand All @@ -258,11 +258,11 @@ function ele_at_s(branch::Branch, s::Real; choose::StreamLocation = UPSTREAM_END
while true
if n3 == n1 + 1; break; end
n2 = div(n1 + n3, 2)
s < branch.ele[n2].s || (choose == UPSTREAM_END && branch.ele[n2].s == s) ? n3 = n2 : n1 = n2
s < branch.ele[n2].s || (choose == StreamLoc.UPSTREAM_END && branch.ele[n2].s == s) ? n3 = n2 : n1 = n2
end

# Solution is n1 except in one case.
if choose == DOWNSTREAM_END && branch.ele[n3].s == s
if choose == StreamLoc.DOWNSTREAM_END && branch.ele[n3].s == s
return branch.ele[n3]
else
return branch.ele[n1]
Expand All @@ -272,19 +272,19 @@ function ele_at_s(branch::Branch, s::Real; choose::StreamLocation = UPSTREAM_END
# If ele_near is used
ele = ele_near
if ele.branch.type <: LordBranch
choose == DOWNSTREAM_END ? ele = ele.slaves[end] : ele = ele.slaves[1]
choose == StreamLoc.DOWNSTREAM_END ? ele = ele.slaves[end] : ele = ele.slaves[1]
end


if s > ele.s_downstream || (choose == DOWNSTREAM_END && s == ele.s_downstream)
if s > ele.s_downstream || (choose == StreamLoc.DOWNSTREAM_END && s == ele.s_downstream)
while true
ele = next_ele(ele)
if s < ele.s_downstream || (s == ele.s_downstream && choose == UPSTREAM_END); return ele; end
if s < ele.s_downstream || (s == ele.s_downstream && choose == StreamLoc.UPSTREAM_END); return ele; end
end

else
while true
if s > ele.s || (choose == DOWNSTREAM_END && ele.s == s); return ele; end
if s > ele.s || (choose == StreamLoc.DOWNSTREAM_END && ele.s == s); return ele; end
ele = next_ele(ele, -1)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/lat_construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Creates a `beamline` from a vector of `BeamLineItem`s.
### Notes

Recognized beamline parameters:
- `geometry` Branch geometry. Can be: `open` (default) or `closed`.
- `geometry` Branch geometry. Can be: `BranchGeom.OPEN` (default) or `BranchGeom.CLOSED`.
- `orientation` Longitudinal orientation. Can be: `+1` (default) or `-1`.
- `multipass` Multipass line? Default is `false`.
All parameters are optional.
Expand Down
18 changes: 9 additions & 9 deletions src/manipulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end
# split!

"""
split!(branch::Branch, s_split::Real; choose::StreamLocation = UPSTREAM_END, ele_near::Ele = NULL_ELE)
split!(branch::Branch, s_split::Real; choose::StreamLoc.T = StreamLoc.UPSTREAM_END, ele_near::Ele = NULL_ELE)

Routine to split an lattice element of a branch into two to create a branch that has an element
boundary at the point s = `s_split`.
Expand All @@ -113,8 +113,8 @@ than 2*`LatticeGlobal.significant_length`.
- `choose` -- logical, optional: If no splitting of an element is needed, that is,
`s_split` is at an element boundary, there can be multiple possible `ele_split` elements to
return if there exist zero length elements at the split location.
If `choose` = `DOWNSTREAM_END`, the returned `ele_split` element will be chosen to be
at the maximal downstream element. If `choose` = `UPSTREAM_END`, the returned `ele_split` element
If `choose` = `StreamLoc.DOWNSTREAM_END`, the returned `ele_split` element will be chosen to be
at the maximal downstream element. If `choose` = `StreamLoc.UPSTREAM_END`, the returned `ele_split` element
will be chosen to be the maximal upstream location.
If `s_split` is not at an element boundary, the setting of `choose` is immaterial.
- `ele_near` -- Element near the point to be split. `ele_near` is useful in the case where
Expand All @@ -127,18 +127,18 @@ than 2*`LatticeGlobal.significant_length`.
- `split_done` -- true if lat was split, false otherwise.
""" split!(branch::Branch)

function split!(branch::Branch, s_split::Real; choose::StreamLocation = UPSTREAM_END, ele_near::Ele = NULL_ELE)
function split!(branch::Branch, s_split::Real; choose::StreamLoc.T = StreamLoc.UPSTREAM_END, ele_near::Ele = NULL_ELE)
check_if_s_in_branch_range(branch, s_split)
if choose != UPSTREAM_END && choose != DOWNSTREAM_END; error("Bad `choose` argument: $choose"); end
if choose != StreamLoc.UPSTREAM_END && choose != StreamLoc.DOWNSTREAM_END; error("Bad `choose` argument: $choose"); end
slave1 = ele_at_s(branch, s_split, choose = choose, ele_near = ele_near)

# Make sure split does create an element that is less than min_len in length.
min_len = min_ele_length(branch.lat)
if choose == UPSTREAM_END && slave1.s > s_split-min_len
slave1 = ele_at_s(branch, slave1.s, choose = DOWNSTREAM_END)
if choose == StreamLoc.UPSTREAM_END && slave1.s > s_split-min_len
slave1 = ele_at_s(branch, slave1.s, choose = StreamLoc.DOWNSTREAM_END)
s_split = slave1.s_downstream
elseif choose == DOWNSTREAM_END && slave1.s_downstream < s_split+min_len
slave1 = ele_at_s(branch, slave1.s_downstream, choose = DOWNSTREAM_END)
elseif choose == StreamLoc.DOWNSTREAM_END && slave1.s_downstream < s_split+min_len
slave1 = ele_at_s(branch, slave1.s_downstream, choose = StreamLoc.DOWNSTREAM_END)
s_split = slave1.s
end

Expand Down
22 changes: 11 additions & 11 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract type Pointer end

@kwdef mutable struct ParamInfo
parent_group::T where T <: Union{DataType,Vector} # Use the parent_group function to get the parent group.
kind::Union{T, Union} where T <: DataType # Something like ApertureType is a Union.
kind::Union{T, Union} where T <: DataType # Something like Aperture.T is a Union.
description::String = ""
units::String = ""
struct_sym::Symbol # Symbol in struct.
Expand Down Expand Up @@ -95,7 +95,7 @@ ele_param_info_dict = Dict(
:hgap => ParamInfo(Nothing, Number, "Used to set hgap1 and hgap2 both at once.", ""),
:hgap1 => ParamInfo(BendGroup, Number, "Bend entrance edge pole gap height.", "m"),
:hgap2 => ParamInfo(BendGroup, Number, "Bend exit edge pole gap height.", "m"),
:bend_type => ParamInfo(BendGroup, BendType, "Sets how face angles varies with bend angle."),
:bend_type => ParamInfo(BendGroup, Bend.T, "Sets how face angles varies with bend angle."),

:offset => ParamInfo([AlignmentGroup,PatchGroup], Vector{Number}, "3-Vector of [x, y, z] element offsets.", "m"),
:x_rot => ParamInfo([AlignmentGroup,PatchGroup], Number, "X-axis element rotation.", "rad"),
Expand All @@ -112,7 +112,7 @@ ele_param_info_dict = Dict(
:pc_exit => ParamInfo(PatchGroup, Number, "Reference momentum at exit end.", "eV"),
:flexible => ParamInfo(PatchGroup, Bool, "Flexible patch?"),
:user_sets_length => ParamInfo(PatchGroup, Bool, "Does Bmad calculate the patch length?"),
:ref_coords => ParamInfo(PatchGroup, BodyLocation, "Patch coords with respect to ENTRANCE_END or EXIT_END?"),
:ref_coords => ParamInfo(PatchGroup, BodyLoc.T, "Patch coords with respect to BodyLoc.ENTRANCE_END or BodyLoc.EXIT_END?"),

:voltage => ParamInfo(RFFieldGroup, Number, "RF voltage.", "volt"),
:gradient => ParamInfo(RFFieldGroup, Number, "RF gradient.", "volt/m"),
Expand All @@ -122,7 +122,7 @@ ele_param_info_dict = Dict(
"RF phase which can differ from multipass element to multipass element.", "rad"),
:frequency => ParamInfo(RFGroup, Number, "RF frequency.", "Hz"),
:harmon => ParamInfo(RFGroup, Number, "RF frequency harmonic number.", ""),
:cavity_type => ParamInfo(RFGroup, CavityType, "Type of cavity."),
:cavity_type => ParamInfo(RFGroup, Cavity.T, "Type of cavity."),
:n_cell => ParamInfo(RFGroup, Int, "Number of RF cells."),

:voltage_ref => ParamInfo(LCavityGroup, Number, "Reference RF voltage.", "volt"),
Expand All @@ -144,12 +144,12 @@ ele_param_info_dict = Dict(
:do_auto_scale => ParamInfo(Nothing, Bool, "Used to set do_auto_amp and do_auto_phase both at once.", ""),

:tracking_method => ParamInfo(TrackingGroup, TrackingMethod, "Nominal method used for tracking."),
:field_calc => ParamInfo(TrackingGroup, FieldCalcMethod, "Nominal method used for calculating the EM field."),
:field_calc => ParamInfo(TrackingGroup, FieldCalc.T, "Nominal method used for calculating the EM field."),
:num_steps => ParamInfo(TrackingGroup, Int, "Nominal number of tracking steps."),
:ds_step => ParamInfo(TrackingGroup, Number, "Nominal distance between tracking steps.", "m"),

:aperture_type => ParamInfo(ApertureGroup, ApertureType, "Type of aperture. Default is Elliptical."),
:aperture_at => ParamInfo(ApertureGroup, BodyLocation, "Where the aperture is. Default is ENTRANCE_END."),
:aperture_type => ParamInfo(ApertureGroup, Aperture.T, "Type of aperture. Default is Elliptical."),
:aperture_at => ParamInfo(ApertureGroup, BodyLoc.T, "Where the aperture is. Default is BodyLoc.ENTRANCE_END."),
:offset_moves_aperture
=> ParamInfo(ApertureGroup, Bool, "Does moving the element move the aperture?"),
:x_limit => ParamInfo(ApertureGroup, Vector{Number}, "2-Vector of horizontal aperture limits.", "m"),
Expand All @@ -162,7 +162,7 @@ ele_param_info_dict = Dict(
:psi_floor => ParamInfo(FloorPositionGroup, Number, "Element floor psi angle orientation", "rad", :psi),

:origin_ele => ParamInfo(GirderGroup, Ele, "Coordinate reference element."),
:origin_ele_ref_pt => ParamInfo(GirderGroup, StreamLocation, "Reference location on reference element. Default is CENTER."),
:origin_ele_ref_pt => ParamInfo(GirderGroup, StreamLoc.T, "Reference location on reference element. Default is StreamLoc.CENTER."),
:dr_girder => ParamInfo(GirderGroup, Vector{Number}, "3-vector of girder position with respect to ref ele.", "m", :dr),
:dtheta_girder => ParamInfo(GirderGroup, Number, "Theta angle orientation with respect to ref ele.", "rad", :dtheta),
:dphi_girder => ParamInfo(GirderGroup, Number, "Phi angle orientation with respect to ref ele.", "rad", :dphi),
Expand All @@ -174,8 +174,8 @@ ele_param_info_dict = Dict(
:slave => ParamInfo(ControlSlaveGroup, Vector{ControlSlave}, "Controlled parameters info."),
:variable => ParamInfo(ControlVarGroup, Vector{ControlVar}, "Controller variables."),

:slave_status => ParamInfo(LordSlaveGroup, SlaveStatus, "Slave status."),
:lord_status => ParamInfo(LordSlaveGroup, LordStatus, "Lord status."),
:slave_status => ParamInfo(LordSlaveGroup, Slave.T, "Slave status."),
:lord_status => ParamInfo(LordSlaveGroup, Lord.T, "Lord status."),

:spin => ParamInfo(InitParticleGroup, Vector{Number}, "Initial particle spin"),
:orbit => ParamInfo(InitParticleGroup, Vector{Number}, "Initial particle position."),
Expand Down Expand Up @@ -681,7 +681,7 @@ Dictionary of parameters in the Branch.pdict dict.

branch_param = Dict(
:ix_branch => ParamInfo(Nothing, Int, "Index of branch in containing lat .branch[] array"),
:geometry => ParamInfo(Nothing, EleGeometrySwitch, "Open or closed Geometry"),
:geometry => ParamInfo(Nothing, EleGeometrySwitch, "BranchGeom.OPEN or BranchGeom.CLOSED Geometry"),
:lat => ParamInfo(Nothing, Pointer, "Pointer to lattice containing the branch."),
:type => ParamInfo(Nothing, BranchType, "Either LordBranch or TrackingBranch BranchType enums."),
:from_ele => ParamInfo(Nothing, Pointer, "Element that forks to this branch."),
Expand Down
42 changes: 21 additions & 21 deletions src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# machine_location

"""
machine_location(loc::BodyLocation, orientation::Int) -> StreamLocation
machine_location(loc::BodyLoc.T, orientation::Int) -> StreamLoc.T

Given a location with respect to an element's `local` orientation and the element's `orientation`,
return the equivalent location in machine coordinates.
Expand All @@ -12,31 +12,31 @@ The reverse function is body_location.
### Input

- `loc` Location with respect to an element's `local` orientation.
Possible values: `ENTRANCE_END`, `B_CENTER`, or `EXIT_END`
Possible values: `BodyLoc.ENTRANCE_END`, `BodyLoc.StreamLoc.CENTER`, or `BodyLoc.EXIT_END`
- `orientation` Element orientation. Possible values: -1 or +1.

### Output

- Returns: `UPSTREAM_END`, `CENTER`, or `DOWNSTREAM_END` (a `StreamLocation` value).
- Returns: `StreamLoc.UPSTREAM_END`, `StreamLoc.CENTER`, or `StreamLoc.DOWNSTREAM_END` (a `StreamLoc.T` value).
""" machine_location

function machine_location(loc::BodyLocation, orientation::Int)
if loc == B_CENTER; return CENTER; end
function machine_location(loc::BodyLoc.T, orientation::Int)
if loc == BodyLoc.StreamLoc.CENTER; return StreamLoc.CENTER; end

if loc == ENTRANCE_END
orientation == 1 ? (return UPSTREAM_END) : return DOWNSTREAM_END
elseif loc == EXIT_END
orientation == 1 ? (return DOWNSTREAM_END) : return UPSTREAM_END
if loc == BodyLoc.ENTRANCE_END
orientation == 1 ? (return StreamLoc.UPSTREAM_END) : return StreamLoc.DOWNSTREAM_END
elseif loc == BodyLoc.EXIT_END
orientation == 1 ? (return StreamLoc.DOWNSTREAM_END) : return StreamLoc.UPSTREAM_END
else
error(f"loc argument values limited to `ENTRANCE_END`, `B_CENTER`, or `EXIT_END`. Not: {loc}")
error(f"loc argument values limited to `BodyLoc.ENTRANCE_END`, `BodyLoc.StreamLoc.CENTER`, or `BodyLoc.EXIT_END`. Not: {loc}")
end
end

#---------------------------------------------------------------------------------------------------
# body_location

"""
body_location(loc::StreamLocation, orientation::Int) -> BodyLocation
body_location(loc::StreamLoc.T, orientation::Int) -> BodyLoc.T

Given an element location with respect to machine coordinates,
along with the element's orientation with respect to machine coordinates,
Expand All @@ -46,21 +46,21 @@ The reverse function is machine_location.

### Input

- `loc` Possible values: `UPSTREAM_END`, `B_CENTER`, or `DOWNSTREAM_END` .
- `loc` Possible values: `StreamLoc.UPSTREAM_END`, `BodyLoc.StreamLoc.CENTER`, or `StreamLoc.DOWNSTREAM_END` .
- `orientation` Possible values: -1 or +1.

### Output

- Returns: `entranc_end`, `B_CENTER`, `EXIT_END`.
- Returns: `entranc_end`, `BodyLoc.StreamLoc.CENTER`, `BodyLoc.EXIT_END`.
""" body_location

function body_location(loc::StreamLocation, orientation::Int)
if loc == CENTER; return b_enter; end
function body_location(loc::StreamLoc.T, orientation::Int)
if loc == StreamLoc.CENTER; return b_enter; end

if loc == UPSTREAM_END
orientation == 1 ? (return ENTRANCE_END) : return EXIT_END
elseif loc == DOWNSTREAM_END
orientation == 1 ? (return EXIT_END) : return ENTRANCE_END
if loc == StreamLoc.UPSTREAM_END
orientation == 1 ? (return BodyLoc.ENTRANCE_END) : return BodyLoc.EXIT_END
elseif loc == StreamLoc.DOWNSTREAM_END
orientation == 1 ? (return BodyLoc.EXIT_END) : return BodyLoc.ENTRANCE_END
else
error(f"ConfusedError: Should not be here! Please report this!")
end
Expand Down Expand Up @@ -113,8 +113,8 @@ is_null(branch::Branch) = return (branch.name == "NULL_BRANCH")

"""
Returns the equivalent inbounds s-position in the range [branch.ele[1].s, branch.ele[end].s]
if the branch has a closed geometry. Otherwise returns s.
This is useful since in closed geometries
if the branch has a `BranchGeom.CLOSED` geometry. Otherwise returns s.
This is useful since in `Branch.Geom.CLOSED` geometries.
""" s_inbounds

function s_inbounds(branch::Branch, s::Real)
Expand Down
Loading
Loading