Skip to content

Commit

Permalink
Merge pull request #733 from bmad-sim/devel/89
Browse files Browse the repository at this point in the history
Fix linear beambeam spin tracking.
  • Loading branch information
DavidSagan committed Jan 12, 2024
2 parents 20dc617 + 68a84e1 commit e613605
Show file tree
Hide file tree
Showing 6 changed files with 762 additions and 687 deletions.
16 changes: 16 additions & 0 deletions bmad/low_level/track1_spin_bmad.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ subroutine track1_spin_bmad (start_orb, ele, param, end_orb)

real(rp) spline_x(0:3), spline_y(0:3), omega(3), s_edge_track
real(rp) voltage, k_rf, phase
real(rp) fc, dxp, dyp, om(3), quat(0:3)

integer key, dir

character(*), parameter :: r_name = 'track1_spin_bmad'
Expand All @@ -40,6 +42,20 @@ subroutine track1_spin_bmad (start_orb, ele, param, end_orb)

if (ele%key == patch$) return

! Beambeam

if (ele%key == beambeam$) then
fc = start_orb%p0c / ((1.0_rp + start_orb%beta**2) * charge_of(start_orb%species))
dxp = (end_orb%vec(2) - start_orb%vec(2)) * fc
dyp = (end_orb%vec(4) - start_orb%vec(4)) * fc
field%E = [dxp, dyp, 0.0_rp]
field%B = [dyp, -dxp, 0.0_rp] / c_light
om = spin_omega (field, end_orb, +1)
quat = omega_to_quat(om)
end_orb%spin = quat_rotate(quat, start_orb%spin)
return
endif

! crab_cavity

if (ele%key == crab_cavity$) then
Expand Down
2 changes: 1 addition & 1 deletion bmad/low_level/track_a_beambeam.f90
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ subroutine track_a_beambeam (orbit, ele, param, track, mat6, make_matrix)

if (bmad_com%spin_tracking_on) then
ff = 1.0_rp + orbit%beta**2
field%E = [ k0_x, k0_y, 0.0_rp] * (coef * orbit%p0c / (ff * charge_of(orbit%species)))
field%E = [k0_x, k0_y, 0.0_rp] * (coef * orbit%p0c / (ff * charge_of(orbit%species)))
field%B = [k0_y, -k0_x, 0.0_rp] * (coef * orbit%p0c * orbit%beta / (ff * c_light * charge_of(orbit%species)))
om = spin_omega (field, orbit, +1)
quat = omega_to_quat(om)
Expand Down
26 changes: 18 additions & 8 deletions bsim/modules/lt_tracking_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module lt_tracking_mod
character(100) :: exclude_from_maps = 'beambeam::*'
character(40) :: ele_start = ''
character(40) :: ele_stop = ''
character(40) :: ele_extract = ''
character(200) :: lat_file = ''
character(200) :: beam_binary_output_file = ''
character(200) :: custom_output_file = ''
Expand Down Expand Up @@ -239,25 +240,33 @@ subroutine ltt_read_params(ltt, ltt_com)

if (ltt%master_output_file /= '') then
call out_io (s_info$, r_name, &
'Note: The master_output_file is no longer created since data in this file is written to other files.')
'Note: The master_output_file is no longer created since data in this file is written to other files.', &
'Please correct the init file. Will stop here.')
stop
endif

if (ltt%sigma_matrix_output_file /= '') then
call out_io (s_info$, r_name, &
'Note: ltt%sigma_matrix_output_file is no longer used and will be ignored.', &
'Note: ltt%sigma_matrix_output_file is no longer used.', &
' Essentially now ltt%averages_output_file sets the name of the sigma matrix file.', &
' See manual for details.')
' See manual for details.', &
' Please correct the init file. Will stop here.')
stop
endif

if (ltt%averaging_window /= 1) then
call out_io (s_info$, r_name, &
'Note: ltt%averaging_window is no longer used and will be ignored.', &
'Note: ltt%averaging_window is no longer used.', &
' Reason: The advantage of averaging over multiple turns was not worth the complications', &
' to the program internal bookkeeping')
' to the program internal bookkeeping', &
'Please correct the init file. Will stop here.')
stop
endif

if (ltt%mpi_runs_per_subprocess /= 4) then
call out_io (s_info$, r_name, 'Note: ltt%mpi_runs_per_subprocess is no longer used and will be ignored.')
call out_io (s_info$, r_name, 'Note: ltt%mpi_runs_per_subprocess is no longer used.', &
'Please correct the init file. Will stop here.')
stop
endif

if (any(ltt%core_emit_cutoff > 1.00000001_rp .or. &
Expand All @@ -268,8 +277,9 @@ subroutine ltt_read_params(ltt, ltt_com)

if (ltt%particle_output_file /= '') then
call out_io (s_error$, r_name, 'Note: ltt%particle_output_file replaced by ltt%phase_space_output_file.', &
' Also see ltt%action_angle_output_file.')
ltt%phase_space_output_file = ltt%particle_output_file
' Also see ltt%action_angle_output_file.', &
'Please correct the init file. Will stop here.')
stop
endif

end subroutine ltt_read_params
Expand Down
6 changes: 3 additions & 3 deletions regression_tests/backwards_time_track_test/output.correct
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@
"BEAMBEAM1: Bmad_Standard-c*dt,dp0c,ds,dbeta" ABS 2e-12 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00
"BEAMBEAM1: Bmad_Standard-Merit" ABS 2e-12 2.6114488350E-10
"BEAMBEAM1: Linear-end" ABS 2e-12 1.0000000000E-03 2.3545039161E-03 3.0000000000E-03 4.3424403052E-03 5.0000000000E-03 6.0000000000E-03 6.9608944983E-01
"BEAMBEAM1: Linear-dendSpin" ABS 2e-12 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00
"BEAMBEAM1: Linear-dendSpin" ABS 2e-12 1.5942634489E-04 1.5383726718E-04 -2.1882258667E-04
"BEAMBEAM1: Linear-dOrb" ABS 2e-12 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00
"BEAMBEAM1: Linear-dSpin" ABS 2e-12 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00
"BEAMBEAM1: Linear-dSpin" ABS 2e-12 2.2063673111E-10 2.1293194985E-10 -3.0272701013E-10
"BEAMBEAM1: Linear-c*dt,dp0c,ds,dbeta" ABS 2e-12 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00
"BEAMBEAM1: Linear-Merit" ABS 2e-12 0.0000000000E+00
"BEAMBEAM1: Linear-Merit" ABS 2e-12 3.0272701013E-10
"BEAMBEAM1: Taylor-end" ABS 2e-12 1.0000000000E-03 2.3055627573E-03 3.0000000000E-03 4.2942285396E-03 5.0000000000E-03 6.0000000000E-03 6.9608944983E-01
"BEAMBEAM1: Taylor-dendSpin" ABS 2e-12 1.2526671792E-04 1.2047877699E-04 -1.7160270672E-04
"BEAMBEAM1: Taylor-dOrb" ABS 2e-12 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 8.6736173799E-19 0.0000000000E+00 0.0000000000E+00
Expand Down
Loading

0 comments on commit e613605

Please sign in to comment.