Skip to content

Commit

Permalink
Very minor code changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Dec 9, 2024
1 parent bd27565 commit 9a85319
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
16 changes: 8 additions & 8 deletions bmad/doc/charged-tracking.tex
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ \section{BeamBeam Tracking}
coordinates, the momentum kick $dp_z$ is
\begin{equation}
dp_{z,s} = \frac{1}{2 \, \beta_w \, (1/\beta_w + 1/\beta_s) \, (1 + p_z)}
\left( dp_x \, (dp_x - 2p_{x1}) + dp_y \, (dp_y - 2p_{y1}) \right)
\left( dp_x \, (dp_x + 2p_{x1}) + dp_y \, (dp_y + 2p_{y1}) \right)
\label{dpz12}
\end{equation}
where $dp_x$ and $dp_y$ are the transverse kicks and $p_{x1}$ and $p_{y1}$ are the initial phase
Expand Down Expand Up @@ -928,18 +928,18 @@ \section{Drift Tracking}
\bmad uses the exact map for a drift
This gives the map
\begin{align}
x_2 &= x_1 + \frac{L \, p_{x1}}{(1 + p_{z1}) \, p_l} \CRNO
x_2 &= x_1 + \frac{L \, p_{x1}}{p_l} \CRNO
p_{x2} &= p_{x1} \CRNO
y_2 &= y_1 + \frac{L \, p_{y1}}{(1 + p_{z1}) \, p_l} \CRNO
y_2 &= y_1 + \frac{L \, p_{y1}}{p_l} \CRNO
p_{y2} &= p_{y1} \\
z_2 &= z_1 + \left( \frac{\beta}{\beta_\REF} - \frac{1}{p_l} \right) \, L \CRNO
z_2 &= z_1 + \left( \frac{\beta}{\beta_\REF} - \frac{1 + p_{z1}}{p_l} \right) \, L \CRNO
p_{z2} &= p_{z1} \nonumber
\end{align}
where $\beta$ is the normalized particle velocity, $\beta_\REF$ is
the reference particle's normalized velocity, and $p_l$ is the
longitudinal momentum
where $\beta$ is the normalized particle velocity, $\beta_\REF$ is the reference particle's
normalized velocity, and $p_l$ is the normalized longitudinal momentum $P_l/P_0$ with $P_l$ being
the longitudinal momentum
\begin{equation}
p_l = \sqrt{1 - \frac{p_x^2 + p_y^2}{(1 + p_z)^2}}
p_l = \sqrt{(1 + p_z)^2 - p_x^2 + p_y^2}
\end{equation}

%---------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion bmad/doc/cover-page.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

\begin{flushright}
\large
Revision: November 14, 2024 \\
Revision: December 5, 2024 \\
\end{flushright}

\pdfbookmark[0]{Preamble}{Preamble}
Expand Down
52 changes: 26 additions & 26 deletions bmad/low_level/track_a_drift.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,80 +34,80 @@ subroutine track_a_drift (orb, length, mat6, make_matrix, ele_orientation, inclu

real(rp), optional :: mat6(6,6), time
real(rp) matd(6,6), e_tot_ref, e_particle, rel_len, dt
real(rp) length, rel_pc, dz, px, py, ps, delta, pxy2, mc2, beta_ref
real(rp) length, rel_pc, dz, px_rel, py_rel, ps_rel, delta, pxy2, mc2, beta_ref

integer, optional :: ele_orientation
integer rel_z_vel
logical, optional :: make_matrix, include_ref_motion

! If the element orientation is opposite the particle direction, px and py are reversed.
! If the element orientation is opposite the particle direction, px_rel and py_rel are reversed.

if (length == 0) return
delta = orb%vec(6)
rel_pc = 1 + delta
rel_z_vel = integer_option(orb%direction, ele_orientation) * orb%direction

px = rel_z_vel * orb%vec(2) / rel_pc
py = rel_z_vel * orb%vec(4) / rel_pc
pxy2 = px**2 + py**2
px_rel = rel_z_vel * orb%vec(2) / rel_pc ! Relative to the actual momentum, not the reference momentum.
py_rel = rel_z_vel * orb%vec(4) / rel_pc
pxy2 = px_rel**2 + py_rel**2
if (pxy2 >= 1) then
orb%state = lost_pz$
return
endif
ps = sqrt(1 - pxy2)
ps_rel = sqrt(1 - pxy2)

orb%vec(1) = orb%vec(1) + length * px / ps
orb%vec(3) = orb%vec(3) + length * py / ps
orb%vec(1) = orb%vec(1) + length * px_rel / ps_rel
orb%vec(3) = orb%vec(3) + length * py_rel / ps_rel

! Length is the length in body coordinates

if (orb%beta > 0) then
if (logic_option(.true., include_ref_motion)) then
mc2 = mass_of(orb%species)
! dz = length * ([beta/beta_ref - 1] - [1/ps - 1])
! dz = length * ([beta/beta_ref - 1] - [1/ps_rel - 1])
if (orb%direction == 1) then
dz = length * (sqrt_one((mc2**2 * (2*delta+delta**2))/((orb%p0c*rel_pc)**2 + mc2**2)) + sqrt_one(-pxy2)/ps)
dz = length * (sqrt_one((mc2**2 * (2*delta+delta**2))/((orb%p0c*rel_pc)**2 + mc2**2)) + sqrt_one(-pxy2)/ps_rel)
else
beta_ref = orb%p0c / sqrt(orb%p0c**2 + mc2**2)
dz = length * ((-orb%beta/beta_ref - 1.0_rp) - (1.0_rp / ps - 1.0_rp))
dz = length * ((-orb%beta/beta_ref - 1.0_rp) - (1.0_rp / ps_rel - 1.0_rp))
endif
orb%s = orb%s + orb%direction * length
else
dz = -length /ps
dz = -length /ps_rel
endif

dt = rel_z_vel * length / (orb%beta * ps * c_light)
dt = rel_z_vel * length / (orb%beta * ps_rel * c_light)
orb%t = orb%t + dt
if (present(time)) time = time + dt

else
if (logic_option(.true., include_ref_motion)) then
dz = length * (1 - 1/ps)
dz = length * (1 - 1/ps_rel)
orb%s = orb%s + orb%direction * length
else
dz = -length /ps
dz = -length /ps_rel
endif
endif

orb%vec(5) = orb%vec(5) + rel_z_vel * dz

if (logic_option(.false., make_matrix)) then
call mat_make_unit(matd)
rel_len = length / (rel_pc * ps)
matd(1,2) = rel_len * (px**2 / ps**2 + 1)
matd(3,4) = rel_len * (py**2 / ps**2 + 1)
matd(1,4) = rel_len * px*py / ps**2
matd(3,2) = rel_len * px*py / ps**2
matd(1,6) = -rel_len * px / ps**2
matd(3,6) = -rel_len * py / ps**2
matd(5,2) = -rel_len * px / ps**2
matd(5,4) = -rel_len * py / ps**2
rel_len = length / (rel_pc * ps_rel)
matd(1,2) = rel_len * (px_rel**2 / ps_rel**2 + 1)
matd(3,4) = rel_len * (py_rel**2 / ps_rel**2 + 1)
matd(1,4) = rel_len * px_rel*py_rel / ps_rel**2
matd(3,2) = rel_len * px_rel*py_rel / ps_rel**2
matd(1,6) = -rel_len * px_rel / ps_rel**2
matd(3,6) = -rel_len * py_rel / ps_rel**2
matd(5,2) = -rel_len * px_rel / ps_rel**2
matd(5,4) = -rel_len * py_rel / ps_rel**2
if (logic_option(.true., include_ref_motion)) then
e_tot_ref = sqrt(orb%p0c**2 + mass_of(orb%species)**2)
e_particle = orb%p0c * (1 + orb%vec(6)) / orb%beta
matd(5,6) = rel_len * (px**2 + py**2) / ps**2 + length * mass_of(orb%species)**2 * e_tot_ref / e_particle**3
matd(5,6) = rel_len * (px_rel**2 + py_rel**2) / ps_rel**2 + length * mass_of(orb%species)**2 * e_tot_ref / e_particle**3
else
matd(5,6) = rel_len * (px**2 + py**2) / ps**2
matd(5,6) = rel_len * (px_rel**2 + py_rel**2) / ps_rel**2
endif

mat6 = matmul(matd, mat6)
Expand Down
2 changes: 1 addition & 1 deletion bsim/code/set_tune_3d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function set_tune_3d (branch, target_tunes, quad_mask, use_phase_trombone, z_tun
ele => branch%ele(1)
n = branch%n_ele_track
do i = 1, 20
call twiss_and_track(branch%lat, co, status, branch%ix_branch)
call twiss_and_track(branch%lat, co, status, branch%ix_branch, print_err = print_err)
if (status == ok$) then
dQ_a = target_tunes(1) - branch%ele(n)%a%phi/twopi
dQ_b = target_tunes(2) - branch%ele(n)%b%phi/twopi
Expand Down
2 changes: 1 addition & 1 deletion tao/version/tao_version_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
!-

module tao_version_mod
character(*), parameter :: tao_version_date = "2024/12/02 15:05:24"
character(*), parameter :: tao_version_date = "2024/12/04 22:29:10"
end module

0 comments on commit 9a85319

Please sign in to comment.