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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.4.0"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PyFormattedStrings = "5f89f4a4-a228-4886-b223-c468a82ed5b9"
Expand Down
1 change: 1 addition & 0 deletions src/AcceleratorLattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module AcceleratorLattice
using Accessors
using LinearAlgebra
using ReferenceFrameRotations
using EnumX

import Base.Cartesian.lreplace

Expand Down
4 changes: 2 additions & 2 deletions src/bookkeeper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function elegroup_bookkeeper!(ele::Ele, group::Type{BendGroup}, changed::Changed
bg.e1_rect = bg.e1 - 0.5 * bg.angle
elseif haskey(cdict, :e1_rect)
bg.e1 = bg.e1_rect + 0.5 * bg.angle
elseif bg.bend_type == sbend
elseif bg.bend_type == BendType.SECTOR
bg.e1_rect = bg.e1 + 0.5 * bg.angle
else
bg.e1 = bg.e1_rect - 0.5 * bg.angle
Expand All @@ -333,7 +333,7 @@ function elegroup_bookkeeper!(ele::Ele, group::Type{BendGroup}, changed::Changed
bg.e2_rect = bg.e2 - 0.5 * bg.angle
elseif haskey(cdict, :e2_rect)
bg.e2 = bg.e2_rect + 0.5 * bg.angle
elseif bg.bend_type == sbend
elseif bg.bend_type == BendType.SECTOR
bg.e2_rect = bg.e2 + 0.5 * bg.angle
else
bg.e2 = bg.e2_rect - 0.5 * bg.angle
Expand Down
13 changes: 9 additions & 4 deletions src/enum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ macro enumit(str::AbstractString)
eval( Meta.parse("export $str2") )
end

@enumit("ApertureType RECTANGULAR ELLIPTICAL")
@enumit("Bend SECTOR RECTANGULAR")
@enumit("ApertureShape RECTANGULAR ELLIPTICAL")
@enumit("BendType SECTOR RECTANGULAR")
@enumit("BodyLoc ENTRANCE_END CENTER EXIT_END BOTH_ENDS NOWHERE EVERYWHERE")
@enumit("BranchGeometry OPEN CLOSED")
@enumit("Cavity STANDING_WAVE TRAVELING_WAVE")
Expand All @@ -25,5 +25,10 @@ end
@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")
@enumit("TrackingMethod RUNGE_KUTTA TIME_RUNGE_KUTTA STANDARD")
@enumit("ParticleState PREBORN ALIVE PRETRACK LOST LOST_NEG_X LOST_POS_X LOST_NEG_Y LOST_POS_Y LOST_PZ LOST_Z")

# Useful abbreviations

CLOSED::BranchGeometry.T = BranchGeometry.CLOSED
OPEN::BranchGeometry.T = BranchGeometry.OPEN
14 changes: 7 additions & 7 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 Aperture.T is a Union.
kind::Union{T, Union} where T <: DataType # Something like Aperture 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, Bend.T, "Sets how face angles varies with bend angle."),
:bend_type => ParamInfo(BendGroup, BendType.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 Down Expand Up @@ -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, TrackingMethod, "Nominal method used for tracking."),
:field_calc => ParamInfo(TrackingGroup, FieldCalc.T, "Nominal method used for calculating the EM field."),
:tracking_method => ParamInfo(TrackingGroup, TrackingMethod.T, "Nominal method used for tracking."),
: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, Aperture.T, "Type of aperture. Default is Elliptical."),
:aperture_at => ParamInfo(ApertureGroup, BodyLoc.T, "Where the aperture is. Default is BodyLoc.ENTRANCE_END."),
:aperture_type => ParamInfo(ApertureGroup, ApertureShape.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, StreamLoc.T, "Reference location on reference element. Default is StreamLoc.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 Down
16 changes: 8 additions & 8 deletions src/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ A positive `t_offset` shifts the waveform in the positive time direction.
end

@kwdef mutable struct AmpVsTimeGroup <: EleParameterGroup
interpolation::Interpolation.T = spline # Interpolation.T method between points.
interpolation::Interpolation.T = Interpolation.SPLINE # Interpolation method between points.
t_offset::Number = 0 # Time offset of the waveform.
point::Vector{AmpPoint} = Vector{AmpPoint}() # Waveform points.
end
Expand Down Expand Up @@ -319,7 +319,7 @@ Vacuum chamber aperture struct.
@kwdef mutable struct ApertureGroup <: EleParameterGroup
x_limit::Vector = [NaN, NaN]
y_limit::Vector = [NaN, NaN]
aperture_type::Aperture.T = elliptical
aperture_type::ApertureShape.T = ApertureShape.ELLIPTICAL
aperture_at::BodyLoc.T = BodyLoc.ENTRANCE_END
offset_moves_aperture::Bool = true
end
Expand Down Expand Up @@ -360,15 +360,15 @@ end
"""
Bend element parameters.

For tracking there is no distinction made between sector like (`SBend`) bends and
rectangular like (`RBend`) bends. The `bend_type` switch is only important when the
For tracking there is no distinction made between sector like (`BendType.SECTOR`) bends and
rectangular like (`BendType.RECTANGULAR`) bends. The `bend_type` switch is only important when the
bend angle or length is varied. See the documentation for details.

Whether `bend_field` or `g` is held constant when the reference energy is varied is
determined by the `field_master` setting in the MasterGroup struct.
"""
@kwdef mutable struct BendGroup <: EleParameterGroup
bend_type::Bend.T = sbend # Is e or e_rect fixed? Also is len or len_chord fixed?
bend_type::BendType.T = BendType.SECTOR # 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.
Expand Down Expand Up @@ -543,7 +543,7 @@ end
# LordSlaveGroup

@kwdef mutable struct LordSlaveGroup <: EleParameterGroup
lord_status::Lord.T = NOT_A_LORD
lord_status::Lord.T = Lord.NOT
slave_status::Slave.T = Slave.NOT
end

Expand Down Expand Up @@ -700,7 +700,7 @@ Sets the nominal values for tracking prameters.
""" TrackingGroup

@kwdef mutable struct TrackingGroup <: EleParameterGroup
tracking_method::TrackingMethod = STANDARD_TRACKING
tracking_method::TrackingMethod.T = TrackingMethod.STANDARD
field_calc::FieldCalc.T = FieldCalc.STANDARD
num_steps::Int = -1
ds_step::Number = NaN
Expand Down Expand Up @@ -808,7 +808,7 @@ end
slave_parameter = nothing
x_knot::Vector = Vector()
y_knot::Vector = Vector()
interpolation::Interpolation.T = spline
interpolation::Interpolation.T = Interpolation.SPLINE
value::Number = 0.0
type::SlaveControl.T = SlaveControl.NOT_SET
end
Expand Down
2 changes: 1 addition & 1 deletion src/tracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract type AbstractTrackPoint end
charge_weight:: Float64 = NaN
pc_ref::Float64 = NaN
beta::Float64 = NaN
state::TrackingState = ALIVE
state::ParticleState.T = ParticleState.ALIVE
direction::Int = 1
time_dir::Float64 = 1
species::Species = Species("not_set")
Expand Down
28 changes: 14 additions & 14 deletions test/find_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ using AcceleratorLattice, Test
@ele d = Drift(L = 0.4);
@ele d2 = Drift(L = -1.5);
@ele z1 = Bend(L = 1.2);
@ele z2 = Sextupole();
@ele z2 = Sextupole(type = "abc");
@ele m1 = Marker(type = "qf");


ln1 = beamline("ln1", [qf, d]);
ln2 = beamline("ln2", [qd, d, qd], geometry = closed, multipass = true);
ln2 = beamline("ln2", [qd, d, qd], geometry = CLOSED, multipass = true);


fodo = beamline("fodo", [z1, z2, -2*ln1, m1, m1, ln2, reverse(qf), reverse(ln2), d2, reverse(beamline("sub", [qd, ln1]))]);
Expand All @@ -25,23 +25,23 @@ lat = expand("mylat", [(beginning, fodo), (beginning, ln2)]);
b = lat.branch[1]

@testset "ele_at_s" begin
@test ele_at_s(b, b.ele[4].s, choose = upstream_end).ix_ele == 2
@test ele_at_s(b, b.ele[4].s, choose = downstream_end).ix_ele == 4
@test ele_at_s(b, b.ele[end].s_downstream, choose = upstream_end).ix_ele == length(b.ele)-1
@test ele_at_s(b, b.ele[end].s_downstream, choose = downstream_end).ix_ele == length(b.ele)
@test ele_at_s(b, b.ele[15].s, choose = upstream_end, ele_near = b.ele[11]).ix_ele == 14
@test ele_at_s(b, b.ele[15].s, choose = downstream_end, ele_near = b.ele[11]).ix_ele == 15
@test ele_at_s(b, b.ele[19].s, choose = upstream_end, ele_near = b.ele[21]).ix_ele == 18
@test ele_at_s(b, b.ele[19].s, choose = downstream_end, ele_near = b.ele[21]).ix_ele == 19
@test ele_at_s(b, b.ele[4].s, choose = StreamLoc.UPSTREAM_END).ix_ele == 2
@test ele_at_s(b, b.ele[4].s, choose = StreamLoc.DOWNSTREAM_END).ix_ele == 4
@test ele_at_s(b, b.ele[end].s_downstream, choose = StreamLoc.UPSTREAM_END).ix_ele == length(b.ele)-1
@test ele_at_s(b, b.ele[end].s_downstream, choose = StreamLoc.DOWNSTREAM_END).ix_ele == length(b.ele)
@test ele_at_s(b, b.ele[15].s, choose = StreamLoc.UPSTREAM_END, ele_near = b.ele[11]).ix_ele == 14
@test ele_at_s(b, b.ele[15].s, choose = StreamLoc.DOWNSTREAM_END, ele_near = b.ele[11]).ix_ele == 15
@test ele_at_s(b, b.ele[19].s, choose = StreamLoc.UPSTREAM_END, ele_near = b.ele[21]).ix_ele == 18
@test ele_at_s(b, b.ele[19].s, choose = StreamLoc.DOWNSTREAM_END, ele_near = b.ele[21]).ix_ele == 19
end

@testset "eles" begin
@test [e.ix_ele for e in eles(lat, "d")] == [4, 6, 18, 2]
@test [e.ix_ele for e in eles(lat, "Marker::*")] == [8, 9, 21, 5]
@test [e.ix_ele for e in eles(lat, "Marker::*-1")] == [7, 8, 20, 4]
# @test [e.ix_ele for e in
# @test [e.ix_ele for e in
# @test [e.ix_ele for e in
# @test [e.ix_ele for e in
# @test [e.ix_ele for e in eles(lat, "m1#2")] == [9]
# @test [e.ix_ele for e in eles(lat, "m1#2+1")] == [10]
# @test [e.ix_ele for e in ] == []
# @test [e.ix_ele for e in ] == []
end

2 changes: 1 addition & 1 deletion test/lat1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


ln1 = beamline("ln1", [qf, d])
ln2 = beamline("ln2", [qd, d, qd], geometry = closed, multipass = true, begin_ele = begin_ln2)
ln2 = beamline("ln2", [qd, d, qd], geometry = BranchGeometry.CLOSED, multipass = true, begin_ele = begin_ln2)
fodo = beamline("fodo", [z1, z2, -2*ln1, m1, m1, ln2, reverse(qf), reverse(ln2), reverse(beamline("sub", [qd, ln1]))])

lat = expand("mylat", [beamline("fodo2", [fodo], begin_ele = begin_fodo), ln2])
2 changes: 1 addition & 1 deletion test/superimpose_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end



ln2 = beamline([beginning, qd, d, qd], geometry = Closed, multipass = true);
ln2 = beamline([beginning, qd, d, qd], geometry = CLOSED, multipass = true);


fodo = beamline("fodo", [z1, z2, -2*ln1, m1, m1, ln2, reverse(qf), reverse(ln2), reverse(beamline("sub", [qd, ln1]))]);
Loading