@@ -30,24 +30,10 @@ module bbu_track_mod
3030 real (rp) rf_wavelength_max
3131end type
3232
33- ! For now the current variation is a simple ramp
34-
35- type bbu_current_variation_struct
36- logical :: variation_on = .false.
37- ! !logical :: variation_on = .true.
38- real (rp) :: t_ramp_start = 0 ! ! in unit of tb
39- real (rp) :: dt_ramp = 0 ! ! in unit of tb
40- real (rp) :: dt_plateau = 1 ! ! in unit of tb
41- real (rp) :: ramps_period = 12 ! ! in unit of tb
42- real (rp) :: charge_top = 1.0
43- real (rp) :: charge_bottom = 1.0
44- end type
45-
4633type bbu_param_struct
4734 character (500 ) :: lat_filename = ' erl.lat' ! Bmad lattice file name
4835 character (500 ) :: lat2_filename = ' ' ! Bmad lattice2 file name for secondary parser
4936 character (100 ) :: bunch_by_bunch_info_file = ' ' ! For outputting bunch-by-bunch info.
50- type (bbu_current_variation_struct) :: current_vary
5137 logical :: hybridize = .true. ! Combine non-hom elements to speed up simulation?
5238 logical :: write_digested_hybrid_lat = .false. ! For debugging purposes.
5339 logical :: write_voltage_vs_time_dat = .false. ! For debugging purposes.
@@ -77,6 +63,14 @@ module bbu_track_mod
7763 integer :: ix_ele_track_end = - 1 ! Default: set to last element with a wake
7864 logical :: regression = .false. ! Do regression test?
7965 logical :: normalize_z_to_rf = .false. ! make starting z = mod(z, rf_wavelength)?
66+
67+ ! Ramp parameters
68+ logical :: ramp_on = .false.
69+ real (rp) :: ramp_pattern(1000 ) = real_garbage$
70+ integer :: ramp_n_start = 0 ! Index of start of ramp
71+
72+ ! Internal parameters
73+ integer :: n_ramp_pattern = - 1 ! Number of valid ramp_pattern
8074end type
8175
8276contains
@@ -574,7 +568,7 @@ subroutine bbu_add_a_bunch (lat, bbu_beam, bbu_param, beam_init)
574568
575569integer i, ixb, ix0, ix_bunch
576570real (rp) r(2 ), t_rel, d_charge
577- real (rp) t0, charge_diff, slope
571+ real (rp) charge_diff, slope
578572
579573character (20 ) :: r_name = ' bbu_add_a_bunch'
580574
@@ -605,37 +599,14 @@ subroutine bbu_add_a_bunch (lat, bbu_beam, bbu_param, beam_init)
605599! ! Bunch pattern is achieved by multiplying bunch%charge_tot with d_charge(time)
606600! ! The "correct" current is not computed here
607601
608- if (bbu_param% current_vary% variation_on) then
609- ! ! scale the bunch time in t_b, then zero it to where ramp begins
610- t0 = bunch% t_center/ beam_init% dt_bunch - bbu_param% current_vary% t_ramp_start
611- if (t0< 0 ) then
612- d_charge = bbu_param% current_vary% charge_bottom
613- else
614- charge_diff = bbu_param% current_vary% charge_top - bbu_param% current_vary% charge_bottom
615- slope = charge_diff/ bbu_param% current_vary% dt_ramp
616- t_rel = mod (t0, bbu_param% current_vary% ramps_period) ! ! in unit of tb
617-
618- if (t_rel < bbu_param% current_vary% dt_ramp) then
619- d_charge = bbu_param% current_vary% charge_bottom + slope* t_rel
620- ! !print *, t_rel, 'going UP'
621-
622- elseif (t_rel < bbu_param% current_vary% dt_ramp + bbu_param% current_vary% dt_plateau) then
623- d_charge = bbu_param% current_vary% charge_top
624- ! !print *, t_rel, 'TOP'
625-
626- elseif (t_rel < bbu_param% current_vary% dt_ramp* 2 + bbu_param% current_vary% dt_plateau) then
627- d_charge = bbu_param% current_vary% charge_bottom + &
628- (bbu_param% current_vary% dt_ramp* 2 + bbu_param% current_vary% dt_plateau - t_rel) * slope
629- ! !print *, t_rel, 'going DOWN'
630-
631- else
632- d_charge = bbu_param% current_vary% charge_bottom
633- ! !print *, t_rel, 'BOTTOM'
634- endif
602+ if (bbu_param% ramp_on) then
603+ ixb = nint (bunch% t_center/ beam_init% dt_bunch)
604+ if (ixb >= bbu_param% ramp_n_start) then
605+ i = mod (ixb - bbu_param% ramp_n_start, max (1 , bbu_param% n_ramp_pattern - 1 )) + 1
606+ d_charge = bbu_param% ramp_pattern(i)
607+ bunch% charge_tot = bunch% charge_tot * d_charge
608+ bunch% particle% charge = bunch% particle% charge * (d_charge / size (bunch% particle))
635609 endif
636-
637- bunch% charge_tot = bunch% charge_tot * d_charge
638- bunch% particle% charge = bunch% particle% charge * (d_charge / size (bunch% particle))
639610endif
640611
641612bbu_beam% ix_bunch_end = ixb
0 commit comments