Skip to content

Commit

Permalink
More devel for bunch tracking between s and t.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Sep 30, 2023
1 parent ce22076 commit 68a014c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bmad/multiparticle/beam_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track)

use csr_and_space_charge_mod, only: track1_bunch_csr, track1_bunch_csr3d
use beam_utils, only: track1_bunch_hom
use space_charge_mod, only: track_bunch_to_t, track_bunch_to_s

implicit none

Expand Down Expand Up @@ -257,14 +258,16 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track)
track1_bunch_space_charge_called = .true.

elseif (ele%csr_method == steady_state_3d$) then
call track1_bunch_csr3d(bunch, ele, centroid, err, bunch_track = bunch_track)
if (bunch%drift_between_t_and_s) call correct_s_t_tracking_conversion(bunch, ele)
call track1_bunch_csr3d(bunch, ele, centroid, err, bunch_track = bunch_track)

else
if (.not. present(centroid)) then
call out_io (s_fatal$, r_name, 'BUNCH CENTROID MUST BE SUPPLIED FOR CSR CALCULATION!')
if (global_com%exit_on_error) call err_exit
return
endif
if (bunch%drift_between_t_and_s) call correct_s_t_tracking_conversion(bunch, ele)
call track1_bunch_csr (bunch, ele, centroid, err, bunch_track = bunch_track)

endif
Expand All @@ -273,6 +276,7 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track)
! Non csr / non space-charge tracking
else
err = .false.
if (bunch%drift_between_t_and_s) call correct_s_t_tracking_conversion(bunch, ele)
call track1_bunch_hom (bunch, ele, direction, bunch_track = bunch_track)
bunch%ix_ele = ele%ix_ele
endif
Expand Down Expand Up @@ -305,6 +309,22 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track)

endif

!-----------------------------------------------------------------------------------
contains

subroutine correct_s_t_tracking_conversion(bunch, ele)

type (bunch_struct) bunch
type (ele_struct) ele

!

call track_bunch_to_t(bunch, bunch%t0, ele%branch)
bunch%drift_between_t_and_s = .false.
call track_bunch_to_s(bunch, ele%s_start, ele%branch)

end subroutine correct_s_t_tracking_conversion

end subroutine track1_bunch

end module
2 changes: 2 additions & 0 deletions bmad/space_charge/track1_bunch_space_charge.f90
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ subroutine track1_bunch_space_charge (bunch, ele, err, track_to_same_s, bunch_tr
charge = count(bunch%particle%state == alive$)
if (charge /= 0) bunch%t0 = sum(bunch%particle%t, bunch%particle%state==alive$) / charge
endif

call track_bunch_to_t(bunch, bunch%t0, branch)
bunch%drift_between_t_and_s = .true. ! From now on do drifting to save time
t_now = minval(bunch%particle%t, bunch%particle%state==alive$ .or. bunch%particle%state==pre_born$)

! Convert to t-based coordinates
Expand Down

0 comments on commit 68a014c

Please sign in to comment.