Skip to content

Commit

Permalink
Begin implementing Quadrupole.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtabell committed Oct 14, 2024
1 parent 045d2f3 commit d2ccac7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
38 changes: 36 additions & 2 deletions src/symplectic/Symplectic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end # function track!(::Drift, ::Beam, ::Beam)
"""
track "linear" quadrupole
"""
function trackQL!(ele::Quadrupole, statef::Beam, statei::Beam)
function track(ele::Quadrupole, statef::Beam, statei::Beam)
@assert !(statef === statei) "Aliasing statef === statei not allowed!"
L = ele.L
zi = statei.z
Expand All @@ -62,7 +62,41 @@ function trackQL!(ele::Quadrupole, statef::Beam, statei::Beam)
@. zf[6] = zi[6]
end
return statef
end # function track(Drift)
end # function track!(::Quadrupole)

"""
track "matrix part" of quadrupole
"""
function trackQuadMf!(statef::Beam, statei::Beam, s::Float64, κnum::Float64)
zi = statei.z
zf = statef.z

tilde_m = massof(ele.species_ref) / ele.pc_ref
β0 = ele.pc_ref / ele.E_tot_ref

begin
p_red = 1 + zi[6] # reduced Pz
κ = κnum / p_red
κs = κ * s
cx = cos(κs)
sx = sin(κs)
cy = cosh(κs)
sy = sinh(κs)
sx2 = sinc(2κs)
sy2 = sinch(2κs)
xp = px / p_red
yp = py / p_red
@. zf[1] = zi[1] * cx + xp * sx / κ
@. zf[2] = zi[2] * cx - p_red * κ * zi[1]
@. zf[3] = zi[3] * cy + yp * sy / κ
@. zf[4] = zi[4] * cy + p_red * κ * zi[3]
@. zf[5] = (zi[5] - (s / 4.) * (xp^2 * (1. + sx2) + yp^2 * (1 + sy2)
+* x)^2 * (1 - sx2) +* y)^2 * (1 - sy2))
+ (x * xp * sx^2 - y * yp * sy^2) / 2.)
@. zf[6] = zi[6]
end
return statef
end # function trackQ!M::Quadrupole()


end # module Symplectic
Expand Down
5 changes: 3 additions & 2 deletions test/element_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using Test
@ele d1 = Drift(L = 2.);

# define beamlines
bl_drift = BeamLine([ start, d1 ]);
bl_drift = BeamLine("bl_drift", [ start, d1 ]);

# expand beamlines
lat_drift = expand([ bl_drift ])
Expand All @@ -16,7 +16,8 @@ lat_drift = expand([ bl_drift ])
@testset "element_tests" begin
# drift
@test lat_drift["d1"][1].L == 2.0
#@test track!(d1, zf, zi) == [xz, pxf, yf, pyf, zf, pzf]
#@test track!(lat_drift["d1"][1].L, zf, zi);
# zf == [ x_f, px_f, y_f, py_f, z_f, pz_f ]

# quadrupole

Expand Down

0 comments on commit d2ccac7

Please sign in to comment.