diff --git a/src/enum.jl b/src/enum.jl index 469b7ff..5c6ab97 100644 --- a/src/enum.jl +++ b/src/enum.jl @@ -13,17 +13,14 @@ macro enumit(str::AbstractString) eval( Meta.parse("export $str2") ) end -@enumit("ApertureTypeSwitch rectangular elliptical") -@enumit("BendTypeSwitch sbend rbend") -@enumit("BodyLocationSwitch entrance_end b_center exit_end both_ends nowhere everywhere") -@enumit("BoolSwitch no not_set yes") -@enumit("BranchGeometrySwitch open closed") -@enumit("CavityTypeSwitch standing_wave traveling_wave") -@enumit("ControlSlaveTypeSwitch delta absolute control_not_set") -@enumit("FieldCalcMethodSwitch field_map field_standard") -@enumit("InterpolationSwitch linear spline") -@enumit("LordStatusSwitch not_a_lord super_lord multipass_lord governor") -@enumit("SlaveStatusSwitch not_a_slave super_slave multipass_slave") -@enumit("StreamLocationSwitch upstream_end center inside downstream_end") -@enumit("TrackingMethodSwitch rungekutta time_rungekutta standard_tracking") -@enumit("TrackingStateSwitch preborn alive pretrack lost lost_neg_x lost_pos_x lostNegY LostPosY LostPz LostZ") +@enumit("ApertureType RECTANGULAR ELLIPTICAL") +@enumit("BendType SBEND RBEND") +@enumit("BodyLocation ENTRANCE_END B_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("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") diff --git a/src/find.jl b/src/find.jl index 90c5551..9dcdbe6 100644 --- a/src/find.jl +++ b/src/find.jl @@ -223,7 +223,7 @@ end # ele_at_s """ - ele_at_s(branch::Branch, s::Real; choose::StreamLocationSwitch = upstream_end, ele_near::ELE = NULL_ELE) + ele_at_s(branch::Branch, s::Real; choose::StreamLocation = UPSTREAM_END, ele_near::ELE = NULL_ELE) -> ele_overlap::Ele Returns lattice element `ele_overlap` that overlaps a given longitudinal s-position. @@ -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 `UPSTREAM_END` + element (default) or `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`. @@ -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::StreamLocationSwitch = upstream_end, ele_near::Ele = NULL_ELE) +function ele_at_s(branch::Branch, s::Real; choose::StreamLocation = 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 != UPSTREAM_END && choose != DOWNSTREAM_END; error("Bad `choose` argument: $choose"); end # If ele_near is not set if is_null(ele_near) @@ -258,11 +258,11 @@ function ele_at_s(branch::Branch, s::Real; choose::StreamLocationSwitch = upstre 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 == 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 == DOWNSTREAM_END && branch.ele[n3].s == s return branch.ele[n3] else return branch.ele[n1] @@ -272,19 +272,19 @@ function ele_at_s(branch::Branch, s::Real; choose::StreamLocationSwitch = upstre # 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 == 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 == 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 == 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 == DOWNSTREAM_END && ele.s == s); return ele; end ele = next_ele(ele, -1) end end diff --git a/src/manipulation.jl b/src/manipulation.jl index a767e25..a6cab20 100644 --- a/src/manipulation.jl +++ b/src/manipulation.jl @@ -92,7 +92,7 @@ end # split! """ - split!(branch::Branch, s_split::Real; choose::StreamLocationSwitch = upstream_end, ele_near::Ele = NULL_ELE) + split!(branch::Branch, s_split::Real; choose::StreamLocation = 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`. @@ -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` = `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 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 @@ -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::StreamLocationSwitch = upstream_end, ele_near::Ele = NULL_ELE) +function split!(branch::Branch, s_split::Real; choose::StreamLocation = 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 != UPSTREAM_END && choose != 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 == UPSTREAM_END && slave1.s > s_split-min_len + slave1 = ele_at_s(branch, slave1.s, choose = 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 == DOWNSTREAM_END && slave1.s_downstream < s_split+min_len + slave1 = ele_at_s(branch, slave1.s_downstream, choose = DOWNSTREAM_END) s_split = slave1.s end diff --git a/src/parameters.jl b/src/parameters.jl index 45115a5..d710074 100644 --- a/src/parameters.jl +++ b/src/parameters.jl @@ -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 ApertureTypeSwitch is a Union. + kind::Union{T, Union} where T <: DataType # Something like ApertureType is a Union. description::String = "" units::String = "" struct_sym::Symbol # Symbol in struct. @@ -81,7 +81,7 @@ ele_param_info_dict = Dict( :angle => ParamInfo(BendGroup, Number, "Design bend angle", "rad"), :bend_field => ParamInfo(BendGroup, Number, "Design bend field corresponding to g bending", "T"), :rho => ParamInfo(BendGroup, Number, "Design bend radius", "m"), - :g => ParamInfo(BendGroup, Number, "Design bend strength (1/rho)", "1/m"), + :g => ParamInfo(BendGroup, Number, "Design bend strength (1/rho)", "1/m"), :e1 => ParamInfo(BendGroup, Number, "Bend entrance face angle.", "rad"), :e2 => ParamInfo(BendGroup, Number, "Bend exit face angle.", "rad"), :e1_rect => ParamInfo(BendGroup, Number, "Bend entrance face angles relative to a rectangular geometry.", "rad"), @@ -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, BendTypeSwitch, "Sets how face angles varies with bend angle."), + :bend_type => ParamInfo(BendGroup, BendType, "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"), @@ -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, BodyLocationSwitch, "Patch coords with respect to entrance_end or exit_end?"), + :ref_coords => ParamInfo(PatchGroup, BodyLocation, "Patch coords with respect to ENTRANCE_END or EXIT_END?"), :voltage => ParamInfo(RFFieldGroup, Number, "RF voltage.", "volt"), :gradient => ParamInfo(RFFieldGroup, Number, "RF gradient.", "volt/m"), @@ -120,10 +120,10 @@ ele_param_info_dict = Dict( :multipass_phase => ParamInfo(RFGroup, Number, "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, CavityTypeSwitch, "Type of cavity."), - :n_cell => ParamInfo(RFGroup, Int, "Number of RF cells."), + :frequency => ParamInfo(RFGroup, Number, "RF frequency.", "Hz"), + :harmon => ParamInfo(RFGroup, Number, "RF frequency harmonic number.", ""), + :cavity_type => ParamInfo(RFGroup, CavityType, "Type of cavity."), + :n_cell => ParamInfo(RFGroup, Int, "Number of RF cells."), :voltage_ref => ParamInfo(LCavityGroup, Number, "Reference RF voltage.", "volt"), :voltage_err => ParamInfo(LCavityGroup, Number, "RF voltage error.", "volt"), @@ -143,13 +143,13 @@ ele_param_info_dict = Dict( :do_auto_phase => ParamInfo(RFMasterGroup, Bool, "Autoscale phase?"), :do_auto_scale => ParamInfo(Nothing, Bool, "Used to set do_auto_amp and do_auto_phase both at once.", ""), - :tracking_method => ParamInfo(TrackingGroup, TrackingMethodSwitch, "Nominal method used for tracking."), - :field_calc => ParamInfo(TrackingGroup, FieldCalcMethodSwitch, "Nominal method used for calculating the EM field."), + :tracking_method => ParamInfo(TrackingGroup, TrackingMethod, "Nominal method used for tracking."), + :field_calc => ParamInfo(TrackingGroup, FieldCalcMethod, "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, ApertureTypeSwitch, "Type of aperture. Default is Elliptical."), - :aperture_at => ParamInfo(ApertureGroup, BodyLocationSwitch, "Where the aperture is. Default is entrance_end."), + :aperture_type => ParamInfo(ApertureGroup, ApertureType, "Type of aperture. Default is Elliptical."), + :aperture_at => ParamInfo(ApertureGroup, BodyLocation, "Where the aperture is. Default is 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"), @@ -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, StreamLocationSwitch, "Reference location on reference element. Default is Center."), + :origin_ele_ref_pt => ParamInfo(GirderGroup, StreamLocation, "Reference location on reference element. Default is 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), @@ -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, SlaveStatusSwitch, "Slave status."), - :lord_status => ParamInfo(LordSlaveGroup, LordStatusSwitch, "Lord status."), + :slave_status => ParamInfo(LordSlaveGroup, SlaveStatus, "Slave status."), + :lord_status => ParamInfo(LordSlaveGroup, LordStatus, "Lord status."), :spin => ParamInfo(InitParticleGroup, Vector{Number}, "Initial particle spin"), :orbit => ParamInfo(InitParticleGroup, Vector{Number}, "Initial particle position."), diff --git a/src/query.jl b/src/query.jl index 9883094..d8927e6 100644 --- a/src/query.jl +++ b/src/query.jl @@ -2,7 +2,7 @@ # machine_location """ - machine_location(loc::BodyLocationSwitch, orientation::Int) -> StreamLocationSwitch + machine_location(loc::BodyLocation, orientation::Int) -> StreamLocation Given a location with respect to an element's `local` orientation and the element's `orientation`, return the equivalent location in machine coordinates. @@ -12,23 +12,23 @@ 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: `ENTRANCE_END`, `B_CENTER`, or `EXIT_END` - `orientation` Element orientation. Possible values: -1 or +1. ### Output - - Returns: `upstream_end`, `center`, or `downstream_end` (a `StreamLocationSwitch` value). + - Returns: `UPSTREAM_END`, `CENTER`, or `DOWNSTREAM_END` (a `StreamLocation` value). """ machine_location -function machine_location(loc::BodyLocationSwitch, orientation::Int) - if loc == b_center; return center; end +function machine_location(loc::BodyLocation, orientation::Int) + if loc == B_CENTER; return 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 == ENTRANCE_END + orientation == 1 ? (return UPSTREAM_END) : return DOWNSTREAM_END + elseif loc == EXIT_END + orientation == 1 ? (return DOWNSTREAM_END) : return 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 `ENTRANCE_END`, `B_CENTER`, or `EXIT_END`. Not: {loc}") end end @@ -36,7 +36,7 @@ end # body_location """ - body_location(loc::StreamLocationSwitch, orientation::Int) -> BodyLocationSwitch + body_location(loc::StreamLocation, orientation::Int) -> BodyLocation Given an element location with respect to machine coordinates, along with the element's orientation with respect to machine coordinates, @@ -46,21 +46,21 @@ The reverse function is machine_location. ### Input - - `loc` Possible values: `upstream_end`, `b_center`, or `downstream_end` . + - `loc` Possible values: `UPSTREAM_END`, `B_CENTER`, or `DOWNSTREAM_END` . - `orientation` Possible values: -1 or +1. ### Output - - Returns: `entranc_end`, `b_center`, `exit_end`. + - Returns: `entranc_end`, `B_CENTER`, `EXIT_END`. """ body_location -function body_location(loc::StreamLocationSwitch, orientation::Int) - if loc == center; return b_enter; end +function body_location(loc::StreamLocation, orientation::Int) + if loc == 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 == UPSTREAM_END + orientation == 1 ? (return ENTRANCE_END) : return EXIT_END + elseif loc == DOWNSTREAM_END + orientation == 1 ? (return EXIT_END) : return ENTRANCE_END else error(f"ConfusedError: Should not be here! Please report this!") end diff --git a/src/struct.jl b/src/struct.jl index d44f583..fc2128f 100644 --- a/src/struct.jl +++ b/src/struct.jl @@ -278,7 +278,7 @@ A positive `t_offset` shifts the waveform in the positive time direction. end @kwdef mutable struct AmpVsTimeGroup <: EleParameterGroup - interpolation::InterpolationSwitch = spline # Interpolation method between points. + interpolation::Interpolation = spline # Interpolation method between points. t_offset::Number = 0 # Time offset of the waveform. point::Vector{AmpPoint} = Vector{AmpPoint}() # Waveform points. end @@ -319,8 +319,8 @@ Vacuum chamber aperture struct. @kwdef mutable struct ApertureGroup <: EleParameterGroup x_limit::Vector = [NaN, NaN] y_limit::Vector = [NaN, NaN] - aperture_type::ApertureTypeSwitch = elliptical - aperture_at::BodyLocationSwitch = entrance_end + aperture_type::ApertureType = elliptical + aperture_at::BodyLocation = ENTRANCE_END offset_moves_aperture::Bool = true end @@ -344,7 +344,7 @@ end @kwdef mutable struct BeamBeamGroup <: EleParameterGroup n_slice::Number = 1 - z0_crossing::Number = 0 # Weak particle phase space z when strong beam center passes + z0_crossing::Number = 0 # Weak particle phase space z when strong beam CENTER passes # the BeamBeam element. repetition_freq:: Number = 0 # Strong beam repetition rate. twiss::Twiss = Twiss() # Strong beam Twiss. @@ -368,7 +368,7 @@ Whether `bend_field` or `g` is held constant when the reference energy is varied determined by the `field_master` setting in the MasterGroup struct. """ @kwdef mutable struct BendGroup <: EleParameterGroup - bend_type::BendTypeSwitch = sbend # Is e or e_rect fixed? Also is len or len_chord fixed? + bend_type::BendType = sbend # Is e or e_rect fixed? Also is len or len_chord fixed? angle::Number = 0.0 rho::Number = Inf g::Number = 0.0 # Note: Old Bmad dg -> K0. @@ -478,7 +478,7 @@ Girder parameter struct. """ @kwdef mutable struct GirderGroup <: EleParameterGroup origin_ele::Ele = NullEle - origin_ele_ref_pt::StreamLocationSwitch = center + origin_ele_ref_pt::StreamLocation = CENTER dr::Vector = [0.0, 0.0, 0.0] dtheta::Number = 0.0 dphi::Number = 0.0 @@ -543,8 +543,8 @@ end # LordSlaveGroup @kwdef mutable struct LordSlaveGroup <: EleParameterGroup - lord_status::LordStatusSwitch = not_a_lord - slave_status::SlaveStatusSwitch = not_a_slave + lord_status::LordStatus = NOT_A_LORD + slave_status::SlaveStatus = NOT_A_SLAVE end #--------------------------------------------------------------------------------------------------- @@ -584,7 +584,7 @@ Patch element parameters. pc_exit::Number = NaN # Reference momentum at exit end flexible::Bool = false user_sets_length::Bool = false - ref_coords::BodyLocationSwitch = exit_end + ref_coords::BodyLocation = EXIT_END end #--------------------------------------------------------------------------------------------------- @@ -623,7 +623,7 @@ See also RFMasterGroup, RFFieldGroup, and LCavityGroup structures. multipass_phase::Number = 0.0 frequency::Number = 0.0 harmon::Number = 0.0 - cavity_type::CavityTypeSwitch = standing_wave + cavity_type::CavityType = STANDING_WAVE n_cell::Int = 1 end @@ -701,7 +701,7 @@ Sets the nominal values for tracking prameters. @kwdef mutable struct TrackingGroup <: EleParameterGroup tracking_method::TrackingMethodSwitch = standard_tracking - field_calc::FieldCalcMethodSwitch = field_standard + field_calc::FieldCalcMethod = FIELD_STANDARD num_steps::Int = -1 ds_step::Number = NaN end @@ -796,7 +796,7 @@ abstract type ControlSlave end exp_str::String = "" exp_parsed = nothing value::Number = 0.0 - type::ControlSlaveTypeSwitch = control_not_set + type::ControlSlaveType = CONTROL_NOT_SET end #--------------------------------------------------------------------------------------------------- @@ -808,9 +808,9 @@ end slave_parameter = nothing x_knot::Vector = Vector() y_knot::Vector = Vector() - interpolation::InterpolationSwitch = spline + interpolation::Interpolation = spline value::Number = 0.0 - type::ControlSlaveTypeSwitch = control_not_set + type::ControlSlaveType = CONTROL_NOT_SET end #--------------------------------------------------------------------------------------------------- @@ -822,7 +822,7 @@ end slave_parameter = nothing func = nothing value::Number = 0.0 - type::ControlSlaveTypeSwitch = control_not_set + type::ControlSlaveType = CONTROL_NOT_SET end #--------------------------------------------------------------------------------------------------- @@ -843,12 +843,12 @@ end #--------------------------------------------------------------------------------------------------- # ctrl -function ctrl(type::ControlSlaveTypeSwitch, eles, parameter, expr::AbstractString) +function ctrl(type::ControlSlaveType, eles, parameter, expr::AbstractString) if typeof(eles) == String; eles = [eles]; end return ControlSlaveExpression(eles = eles, slave_parameter = parameter, exp_str = expr, type = type) end -function ctrl(type::ControlSlaveTypeSwitch, eles, parameter, x_knot::Vector, +function ctrl(type::ControlSlaveType, eles, parameter, x_knot::Vector, y_knot::Vector, interpolation = Spline) if typeof(eles) == String; eles = [eles]; end return ControlSlaveKnot(eles = eles, slave_parameter = parameter, x_knot = x_knot, y_knot = y_knot, type = type) diff --git a/src/superimpose.jl b/src/superimpose.jl index 55e2d9e..91f0f5f 100644 --- a/src/superimpose.jl +++ b/src/superimpose.jl @@ -2,8 +2,8 @@ # superimpose! """ - function superimpose!(super_ele::Ele, ref; ele_origin::BodyLocationSwitch = b_center, - offset::Real = 0, ref_origin::BodyLocationSwitch = b_center, + function superimpose!(super_ele::Ele, ref; ele_origin::BodyLocation = B_CENTER, + offset::Real = 0, ref_origin::BodyLocation = B_CENTER, wrap::Bool = true) where T <: Union{Branch, Ele, Vector{Branch}, Vector{Ele}} Superimpose a copy (or copies) of the element `super_ele` on a lattice. @@ -33,10 +33,10 @@ downstream edge after the branch start edge. If `wrap` = false, extend the latti ### Notes -- Valid `BodyLocationSwitch` values are: - - entrance_end - - b_center - - exit_end +- Valid `BodyLocation` values are: + - ENTRANCE_END + - B_CENTER + - EXIT_END - Zero length elements in the superposition region will be left alone. @@ -48,14 +48,14 @@ Thus, a positive `offset` will displace the superposition location downstream if a normal orientation and vice versa for a reversed orientation. - When `offset` = 0, for zero length `super_ele` elements the superposition location is at the -entrance end of `ref` except if `ref_origin` is set to `downstream_end` in which case the +entrance end of `ref` except if `ref_origin` is set to `DOWNSTREAM_END` in which case the superposition location is at the exit end of `ref`. - The superimposed element will inherit the orientation of the `ref` element. """ superimpose! -function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocationSwitch = b_center, - offset::Real = 0, ref_origin::BodyLocationSwitch = b_center, +function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocation = B_CENTER, + offset::Real = 0, ref_origin::BodyLocation = B_CENTER, wrap::Bool = true) where {E <: Ele, T <: Union{Branch, Ele, Vector{Branch}, Vector{E}}} if typeof(ref) == Branch ref_ele = ref.ele[1] @@ -87,11 +87,11 @@ function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocationSwitch = b # Insertion of zero length element with zero offset at edge of an element. if L_super == 0 && offset == 0 - if machine_ref_origin == upstream_end || (machine_ref_origin == center && ref_ele.L == 0) + if machine_ref_origin == UPSTREAM_END || (machine_ref_origin == CENTER && ref_ele.L == 0) ix_insert = max(ref_ix_ele, 2) insert!(branch, ix_insert, super_ele) continue - elseif machine_ref_origin == downstream_end + elseif machine_ref_origin == DOWNSTREAM_END ix_insert = min(ref_ix_ele+1, length(ref_ele.branch.ele)) insert!(branch, ix_insert, super_ele) continue @@ -100,19 +100,19 @@ function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocationSwitch = b # Super_ele end locations: s1 and s2. if branch.type <: LordBranch - if machine_ref_origin == upstream_end; s1 = ref_ele.slaves[1].s - elseif machine_ref_origin == center; s1 = 0.5 * (ref_ele.slaves[1].s + ref_ele.slaves[end].s_downstream) + if machine_ref_origin == UPSTREAM_END; s1 = ref_ele.slaves[1].s + elseif machine_ref_origin == CENTER; s1 = 0.5 * (ref_ele.slaves[1].s + ref_ele.slaves[end].s_downstream) else; s1 = ref_ele.slaves[end].s_downstream end else # Not a lord branch - if machine_ref_origin == upstream_end; s1 = ref_ele.s - elseif machine_ref_origin == center; s1 = 0.5 * (ref_ele.s + ref_ele.s_downstream) + if machine_ref_origin == UPSTREAM_END; s1 = ref_ele.s + elseif machine_ref_origin == CENTER; s1 = 0.5 * (ref_ele.s + ref_ele.s_downstream) else; s1 = ref_ele.s_downstream end end - if machine_ele_origin == upstream_end; s1 = s1 + offset - elseif machine_ele_origin == center; s1 = s1 + offset - 0.5 * L_super + if machine_ele_origin == UPSTREAM_END; s1 = s1 + offset + elseif machine_ele_origin == CENTER; s1 = s1 + offset - 0.5 * L_super else; s1 = s1 + offset - L_super end @@ -120,7 +120,7 @@ function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocationSwitch = b # If super_ele has zero length just insert it. if L_super == 0 - machine_ref_origin == downstream_end ? choose = upstream_end : choose = downstream_end + machine_ref_origin == DOWNSTREAM_END ? choose = UPSTREAM_END : choose = DOWNSTREAM_END ele_at, _ = split!(branch, s1, choose = choose, ele_near = ref_ele) insert!(branch, ele_at.ix_ele, super_ele) continue @@ -149,8 +149,8 @@ function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocationSwitch = b # Split points are chosen to avoid creating elements with non-zero length below the minimum. # And super_lord length will be adjusted accordingly. - ele1 = ele_at_s(branch, s1, choose = upstream_end, ele_near = ref_ele) - ele2 = ele_at_s(branch, s2, choose = downstream_end, ele_near = ref_ele) + ele1 = ele_at_s(branch, s1, choose = UPSTREAM_END, ele_near = ref_ele) + ele2 = ele_at_s(branch, s2, choose = DOWNSTREAM_END, ele_near = ref_ele) min_len = min_ele_length(branch.lat) @@ -173,8 +173,8 @@ function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLocationSwitch = b # `choose` is set to minimize number of elements in the superposition region. # The superposition region is from beginning of ele1 to the beginning of ele2. - ele2, _ = split!(branch, s2, choose = upstream_end) # Notice that s2 split must be done first! - ele1, _ = split!(branch, s1, choose = downstream_end) + ele2, _ = split!(branch, s2, choose = UPSTREAM_END) # Notice that s2 split must be done first! + ele1, _ = split!(branch, s1, choose = DOWNSTREAM_END) # If there are just drifts here then no superimpose needed. # Note: In this case there cannot be wrap around. diff --git a/src/tracking.jl b/src/tracking.jl index 75453cd..f8cf380 100644 --- a/src/tracking.jl +++ b/src/tracking.jl @@ -6,6 +6,10 @@ Abstract base type for describing a particle at a given point in space. """ abstract type AbstractTrackPoint 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") + + @kwdef mutable struct SingleTrackPoint <: AbstractTrackPoint vec::Vector{Float64} = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] s::Float64 = NaN @@ -14,9 +18,9 @@ abstract type AbstractTrackPoint end charge_weight:: Float64 = NaN pc_ref::Float64 = NaN beta::Float64 = NaN - state::TrackingStateSwitch = alive + state::TrackingState = ALIVE direction::Int = 1 time_dir::Float64 = 1 species::Species = Species("not_set") - location::StreamLocationSwitch = upstream_end + location::StreamLocation = UPSTREAM_END end diff --git a/src/traversal.jl b/src/traversal.jl index 925b8b1..f506496 100644 --- a/src/traversal.jl +++ b/src/traversal.jl @@ -61,8 +61,8 @@ function Base.iterate(x::Region) x.start_ele.lord_status == super_lord ? start_ele = x.start_ele.slaves[1] : start_ele = x.start_ele x.end_ele.lord_status == super_lord ? end_ele = x.end_ele.slaves[1] : end_ele = x.end_ele if !(start_ele.branch === end_ele.branch); error("Start and end elements are not in the same branch"); end - if start_ele.lord_status != not_a_lord; error("Start element may not be a non-super_lord lord."); end - if end_ele.lord_status != not_a_lord; error("End element may not be a non-super_lord lord."); end + if start_ele.lord_status != NOT_A_LORD; error("Start element may not be a non-super_lord lord."); end + if end_ele.lord_status != NOT_A_LORD; error("End element may not be a non-super_lord lord."); end return (start_ele, start_ele) end