Skip to content

Commit

Permalink
Fix bunch size calc within space charge calc. (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan authored Jan 8, 2025
1 parent f3c2dc4 commit 91e698c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions bmad/multiparticle/beam_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,9 @@ subroutine calc_bunch_params (bunch, bunch_params, error, print_err, n_mat, is_t
if (bunch_params%n_particle_live < 6) return

call calc_emittances_and_twiss_from_sigma_matrix (bunch_params%sigma, bunch_params, error, print_err, n_mat)
if (error .and. logic_option(.true., print_err)) then
call out_io(s_blank$, r_name, 'This at element: ' // ele_full_name(ele))
endif

end subroutine calc_bunch_params

Expand Down
8 changes: 6 additions & 2 deletions bmad/space_charge/space_charge_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,12 @@ subroutine sc_step(bunch, ele, include_image, t_end, sc_field, n_emit)

! Calculate space charge field
if (space_charge_com%particle_sigma_cutoff > 0) then
call calc_bunch_params(bunch, bunch_params, error, is_time_coords=.true., ele=ele)
call sc_field_calc(bunch, ele%branch, include_image, t_end, sc_field, bunch_params)
call calc_bunch_params(bunch, bunch_params, error, .false., is_time_coords=.true., ele=ele)
if (error) then
call sc_field_calc(bunch, ele%branch, include_image, t_end, sc_field)
else
call sc_field_calc(bunch, ele%branch, include_image, t_end, sc_field, bunch_params)
endif
else
call sc_field_calc(bunch, ele%branch, include_image, t_end, sc_field)
endif
Expand Down
7 changes: 5 additions & 2 deletions tao/code/tao_show_this.f90
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ subroutine tao_show_this (what, result_id, lines, nl)
zb = -1

do
call tao_next_switch (what2, [character(16):: '-universe'], .true., switch, err)
call tao_next_switch (what2, [character(16):: '-universe', '-lattice', '-comb', '-z'], .true., switch, err)
if (err) return
if (switch == '') exit

Expand Down Expand Up @@ -357,7 +357,7 @@ subroutine tao_show_this (what, result_id, lines, nl)
return
endif

if (what_to_show == '-comb' .and. ele_name == '') then
if (what_to_show == '-comb' .and. ele_name == '') then ! -comb used without comb index.
if (.not. allocated(tao_branch%bunch_params_comb)) then
nl=nl+1; lines(nl) = 'Beam parameter comb not calculated (check comb_ds_save)'
return
Expand Down Expand Up @@ -445,6 +445,9 @@ subroutine tao_show_this (what, result_id, lines, nl)
nl=nl+1; write(lines(nl), amt) 'dump_at = ', quote(u%beam%dump_at)
nl=nl+1; write(lines(nl), amt) 'dump_file = ', quote(u%beam%dump_file)
nl=nl+1; write(lines(nl), rmt3) 'comb_ds_save = ', tao_branch%comb_ds_save, ' ! Note: -1 => Use (latice branch length)/plot_page%n_curve_pts'
if (allocated(tao_branch%bunch_params_comb)) then
nl=nl+1; write(lines(nl), amt) 'comb index range = [0, ', int_str(tao_branch%bunch_params_comb(1)%n_pt), ']'
endif
!!!! nl=nl+1; write(lines(nl), rmt) 'comb_max_ds_save = ', tao_branch%bunch_params_comb(1)%max_ds_save
nl=nl+1; write(lines(nl), amt) 'track_start = ', quote(bb%track_start), ' ! ', ele_full_name(branch%ele(bb%ix_track_start))
nl=nl+1; write(lines(nl), amt) 'track_end = ', quote(bb%track_end), ' ! ', ele_full_name(branch%ele(bb%ix_track_end))
Expand Down
2 changes: 1 addition & 1 deletion tao/version/tao_version_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
!-

module tao_version_mod
character(*), parameter :: tao_version_date = "2024/12/22 21:46:37"
character(*), parameter :: tao_version_date = "2025/01/07 00:41:27"
end module

0 comments on commit 91e698c

Please sign in to comment.