Skip to content

Commit

Permalink
New BBU ramp syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Nov 18, 2024
1 parent facd4c0 commit 88c226d
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 151 deletions.
Binary file modified bmad-doc/other_manuals/bbu.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions bsim/bbu/bbu_program.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ program bbu_program
read (1, nml = bbu_params)
close (1)

do n = 1, size(bbu_param%ramp_pattern)
if (bbu_param%ramp_pattern(n) == real_garbage$) exit
enddo
bbu_param%n_ramp_pattern = n - 1

if (bbu_param%ramp_on .and. bbu_param%n_ramp_pattern < 1) then
print *, 'RAMP_ON = TRUE BUT THERE IS NO RAMP_PATTERN!'
stop
endif

! Define distance between bunches
beam_init%dt_bunch = 1 / bbu_param%bunch_freq

Expand Down
Binary file removed bsim/bbu/doc/BBU_code_description_ramping.jpg
Binary file not shown.
242 changes: 144 additions & 98 deletions bsim/bbu/doc/bbu.tex

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions bsim/bbu/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@
'lat2_filename': "''", # For DR-scan and phase-scan, LEAVE IT EMPTY
'ran_seed': 100, # Set specific seed if desired (0 uses system clock)
'ran_gauss_sigma_cut': 3, # If positive, limit ran_gauss values to within N sigma
#'current_vary%variation_on': '.true.',
'current_vary%variation_on': '.false.',
'current_vary%t_ramp_start': 0.0,
'current_vary%charge_top': 0.0,
'current_vary%charge_bottom': 1.0,
'current_vary%dt_plateau': 1,
'current_vary%ramps_period': 12,
'current_vary%dt_ramp': 0.01,
'ramp_on': '.false.',
'ramp_n_start': 0
'ramp_pattern': [1.0, 1.0],
}

###############################################################################
Expand Down
61 changes: 16 additions & 45 deletions bsim/code/bbu_track_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,10 @@ module bbu_track_mod
real(rp) rf_wavelength_max
end type

! For now the current variation is a simple ramp

type bbu_current_variation_struct
logical :: variation_on = .false.
!!logical :: variation_on = .true.
real(rp) :: t_ramp_start = 0 !! in unit of tb
real(rp) :: dt_ramp = 0 !! in unit of tb
real(rp) :: dt_plateau = 1 !! in unit of tb
real(rp) :: ramps_period = 12 !! in unit of tb
real(rp) :: charge_top = 1.0
real(rp) :: charge_bottom = 1.0
end type

type bbu_param_struct
character(500) :: lat_filename = 'erl.lat' ! Bmad lattice file name
character(500) :: lat2_filename = '' ! Bmad lattice2 file name for secondary parser
character(100) :: bunch_by_bunch_info_file = '' ! For outputting bunch-by-bunch info.
type (bbu_current_variation_struct) :: current_vary
logical :: hybridize = .true. ! Combine non-hom elements to speed up simulation?
logical :: write_digested_hybrid_lat = .false. ! For debugging purposes.
logical :: write_voltage_vs_time_dat = .false. ! For debugging purposes.
Expand Down Expand Up @@ -77,6 +63,14 @@ module bbu_track_mod
integer :: ix_ele_track_end = -1 ! Default: set to last element with a wake
logical :: regression = .false. ! Do regression test?
logical :: normalize_z_to_rf = .false. ! make starting z = mod(z, rf_wavelength)?

! Ramp parameters
logical :: ramp_on = .false.
real(rp) :: ramp_pattern(1000) = real_garbage$
integer :: ramp_n_start = 0 ! Index of start of ramp

! Internal parameters
integer :: n_ramp_pattern = -1 ! Number of valid ramp_pattern
end type

contains
Expand Down Expand Up @@ -574,7 +568,7 @@ subroutine bbu_add_a_bunch (lat, bbu_beam, bbu_param, beam_init)

integer i, ixb, ix0, ix_bunch
real(rp) r(2), t_rel, d_charge
real(rp) t0, charge_diff, slope
real(rp) charge_diff, slope

character(20) :: r_name = 'bbu_add_a_bunch'

Expand Down Expand Up @@ -605,37 +599,14 @@ subroutine bbu_add_a_bunch (lat, bbu_beam, bbu_param, beam_init)
!! Bunch pattern is achieved by multiplying bunch%charge_tot with d_charge(time)
!! The "correct" current is not computed here

if (bbu_param%current_vary%variation_on) then
!! scale the bunch time in t_b, then zero it to where ramp begins
t0 = bunch%t_center/beam_init%dt_bunch - bbu_param%current_vary%t_ramp_start
if (t0<0) then
d_charge = bbu_param%current_vary%charge_bottom
else
charge_diff = bbu_param%current_vary%charge_top - bbu_param%current_vary%charge_bottom
slope = charge_diff/bbu_param%current_vary%dt_ramp
t_rel = mod(t0, bbu_param%current_vary%ramps_period) !! in unit of tb

if (t_rel < bbu_param%current_vary%dt_ramp) then
d_charge = bbu_param%current_vary%charge_bottom + slope*t_rel
!!print *, t_rel, 'going UP'

elseif (t_rel < bbu_param%current_vary%dt_ramp + bbu_param%current_vary%dt_plateau) then
d_charge = bbu_param%current_vary%charge_top
!!print *, t_rel, 'TOP'

elseif (t_rel < bbu_param%current_vary%dt_ramp*2 + bbu_param%current_vary%dt_plateau) then
d_charge = bbu_param%current_vary%charge_bottom + &
(bbu_param%current_vary%dt_ramp*2 + bbu_param%current_vary%dt_plateau - t_rel) * slope
!!print *, t_rel, 'going DOWN'

else
d_charge = bbu_param%current_vary%charge_bottom
!!print *, t_rel, 'BOTTOM'
endif
if (bbu_param%ramp_on) then
ixb = nint(bunch%t_center/beam_init%dt_bunch)
if (ixb >= bbu_param%ramp_n_start) then
i = mod(ixb - bbu_param%ramp_n_start, max(1, bbu_param%n_ramp_pattern - 1)) + 1
d_charge = bbu_param%ramp_pattern(i)
bunch%charge_tot = bunch%charge_tot * d_charge
bunch%particle%charge = bunch%particle%charge * (d_charge / size(bunch%particle))
endif

bunch%charge_tot = bunch%charge_tot * d_charge
bunch%particle%charge = bunch%particle%charge * (d_charge / size(bunch%particle))
endif

bbu_beam%ix_bunch_end = ixb
Expand Down

0 comments on commit 88c226d

Please sign in to comment.