Skip to content

Commit d20dba8

Browse files
authored
New BBU ramp syntax. (bmad-sim#1301)
1 parent facd4c0 commit d20dba8

File tree

6 files changed

+173
-151
lines changed

6 files changed

+173
-151
lines changed

bmad-doc/other_manuals/bbu.pdf

-186 KB
Binary file not shown.

bsim/bbu/bbu_program.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ program bbu_program
5050
read (1, nml = bbu_params)
5151
close (1)
5252

53+
do n = 1, size(bbu_param%ramp_pattern)
54+
if (bbu_param%ramp_pattern(n) == real_garbage$) exit
55+
enddo
56+
bbu_param%n_ramp_pattern = n - 1
57+
58+
if (bbu_param%ramp_on .and. bbu_param%n_ramp_pattern < 1) then
59+
print *, 'RAMP_ON = TRUE BUT THERE IS NO RAMP_PATTERN!'
60+
stop
61+
endif
62+
5363
! Define distance between bunches
5464
beam_init%dt_bunch = 1 / bbu_param%bunch_freq
5565

-180 KB
Binary file not shown.

bsim/bbu/doc/bbu.tex

Lines changed: 144 additions & 98 deletions
Large diffs are not rendered by default.

bsim/bbu/test_run.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@
2020
'lat2_filename': "''", # For DR-scan and phase-scan, LEAVE IT EMPTY
2121
'ran_seed': 100, # Set specific seed if desired (0 uses system clock)
2222
'ran_gauss_sigma_cut': 3, # If positive, limit ran_gauss values to within N sigma
23-
#'current_vary%variation_on': '.true.',
24-
'current_vary%variation_on': '.false.',
25-
'current_vary%t_ramp_start': 0.0,
26-
'current_vary%charge_top': 0.0,
27-
'current_vary%charge_bottom': 1.0,
28-
'current_vary%dt_plateau': 1,
29-
'current_vary%ramps_period': 12,
30-
'current_vary%dt_ramp': 0.01,
23+
'ramp_on': '.false.',
24+
'ramp_n_start': 0
25+
'ramp_pattern': [1.0, 1.0],
3126
}
3227

3328
###############################################################################

bsim/code/bbu_track_mod.f90

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,10 @@ module bbu_track_mod
3030
real(rp) rf_wavelength_max
3131
end 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-
4633
type 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
8074
end type
8175

8276
contains
@@ -574,7 +568,7 @@ subroutine bbu_add_a_bunch (lat, bbu_beam, bbu_param, beam_init)
574568

575569
integer i, ixb, ix0, ix_bunch
576570
real(rp) r(2), t_rel, d_charge
577-
real(rp) t0, charge_diff, slope
571+
real(rp) charge_diff, slope
578572

579573
character(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))
639610
endif
640611

641612
bbu_beam%ix_bunch_end = ixb

0 commit comments

Comments
 (0)