diff --git a/src/enum.jl b/src/enum.jl index 43045d9..3715138 100644 --- a/src/enum.jl +++ b/src/enum.jl @@ -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") diff --git a/src/find.jl b/src/find.jl index 9dcdbe6..9ac3785 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::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. @@ -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`. @@ -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) @@ -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] @@ -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 diff --git a/src/lat_construction.jl b/src/lat_construction.jl index 694fcb8..bfe9981 100644 --- a/src/lat_construction.jl +++ b/src/lat_construction.jl @@ -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. diff --git a/src/manipulation.jl b/src/manipulation.jl index a6cab20..4d5b39f 100644 --- a/src/manipulation.jl +++ b/src/manipulation.jl @@ -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`. @@ -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 @@ -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 diff --git a/src/parameters.jl b/src/parameters.jl index d710074..cecabef 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 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. @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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), @@ -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."), @@ -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."), diff --git a/src/query.jl b/src/query.jl index d8927e6..98350bc 100644 --- a/src/query.jl +++ b/src/query.jl @@ -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. @@ -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: `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 @@ -36,7 +36,7 @@ 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, @@ -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 @@ -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) diff --git a/src/struct.jl b/src/struct.jl index 1ca467b..7a3e2f1 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::Interpolation = spline # Interpolation method between points. + interpolation::Interpolation.T = spline # Interpolation.T 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::ApertureType = elliptical - aperture_at::BodyLocation = ENTRANCE_END + aperture_type::Aperture.T = elliptical + aperture_at::BodyLoc.T = BodyLoc.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 StreamLoc.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::BendType = sbend # Is e or e_rect fixed? Also is len or len_chord fixed? + bend_type::Bend.T = 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::StreamLocation = CENTER + origin_ele_ref_pt::StreamLoc.T = StreamLoc.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::LordStatus = NOT_A_LORD - slave_status::SlaveStatus = NOT_A_SLAVE + lord_status::Lord.T = NOT_A_LORD + slave_status::Slave.T = Slave.NOT 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::BodyLocation = EXIT_END + ref_coords::BodyLoc.T = BodyLoc.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::CavityType = STANDING_WAVE + cavity_type::Cavity.T = Cavity.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::TrackingMethod = STANDARD_TRACKING - field_calc::FieldCalcMethod = FIELD_STANDARD + field_calc::FieldCalc.T = FieldCalc.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::ControlSlaveType = CONTROL_NOT_SET + type::SlaveControl.T = SlaveControl.NOT_SET end #--------------------------------------------------------------------------------------------------- @@ -808,9 +808,9 @@ end slave_parameter = nothing x_knot::Vector = Vector() y_knot::Vector = Vector() - interpolation::Interpolation = spline + interpolation::Interpolation.T = spline value::Number = 0.0 - type::ControlSlaveType = CONTROL_NOT_SET + type::SlaveControl.T = SlaveControl.NOT_SET end #--------------------------------------------------------------------------------------------------- @@ -822,7 +822,7 @@ end slave_parameter = nothing func = nothing value::Number = 0.0 - type::ControlSlaveType = CONTROL_NOT_SET + type::SlaveControl.T = SlaveControl.NOT_SET end #--------------------------------------------------------------------------------------------------- @@ -843,12 +843,12 @@ end #--------------------------------------------------------------------------------------------------- # ctrl -function ctrl(type::ControlSlaveType, eles, parameter, expr::AbstractString) +function ctrl(type::SlaveControl.T, 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::ControlSlaveType, eles, parameter, x_knot::Vector, +function ctrl(type::SlaveControl.T, 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 91f0f5f..8b92a7d 100644 --- a/src/superimpose.jl +++ b/src/superimpose.jl @@ -2,8 +2,8 @@ # superimpose! """ - function superimpose!(super_ele::Ele, ref; ele_origin::BodyLocation = B_CENTER, - offset::Real = 0, ref_origin::BodyLocation = B_CENTER, + function superimpose!(super_ele::Ele, ref; ele_origin::BodyLoc.T = BodyLoc.StreamLoc.CENTER, + offset::Real = 0, ref_origin::BodyLoc.T = BodyLoc.StreamLoc.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 `BodyLocation` values are: - - ENTRANCE_END - - B_CENTER - - EXIT_END +- Valid `BodyLoc.T` values are: + - BodyLoc.ENTRANCE_END + - BodyLoc.StreamLoc.CENTER + - BodyLoc.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 `StreamLoc.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::BodyLocation = B_CENTER, - offset::Real = 0, ref_origin::BodyLocation = B_CENTER, +function superimpose!(super_ele::Ele, ref::T; ele_origin::BodyLoc.T = BodyLoc.StreamLoc.CENTER, + offset::Real = 0, ref_origin::BodyLoc.T = BodyLoc.StreamLoc.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::BodyLocation = B_CENTE # 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 == StreamLoc.UPSTREAM_END || (machine_ref_origin == StreamLoc.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 == StreamLoc.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::BodyLocation = B_CENTE # 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 == StreamLoc.UPSTREAM_END; s1 = ref_ele.slaves[1].s + elseif machine_ref_origin == StreamLoc.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 == StreamLoc.UPSTREAM_END; s1 = ref_ele.s + elseif machine_ref_origin == StreamLoc.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 == StreamLoc.UPSTREAM_END; s1 = s1 + offset + elseif machine_ele_origin == StreamLoc.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::BodyLocation = B_CENTE # 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 == StreamLoc.DOWNSTREAM_END ? choose = StreamLoc.UPSTREAM_END : choose = StreamLoc.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::BodyLocation = B_CENTE # 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 = StreamLoc.UPSTREAM_END, ele_near = ref_ele) + ele2 = ele_at_s(branch, s2, choose = StreamLoc.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::BodyLocation = B_CENTE # `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 = StreamLoc.UPSTREAM_END) # Notice that s2 split must be done first! + ele1, _ = split!(branch, s1, choose = StreamLoc.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 4feb8be..ba116a3 100644 --- a/src/tracking.jl +++ b/src/tracking.jl @@ -19,5 +19,5 @@ abstract type AbstractTrackPoint end direction::Int = 1 time_dir::Float64 = 1 species::Species = Species("not_set") - location::StreamLocation = UPSTREAM_END + location::StreamLoc.T = StreamLoc.UPSTREAM_END end