Skip to content

Commit

Permalink
Fix last checkin. (#1282)
Browse files Browse the repository at this point in the history
* Fix last checkin.
  • Loading branch information
DavidSagan authored Nov 9, 2024
1 parent ca0dd7d commit 5f2f260
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 171 deletions.
2 changes: 1 addition & 1 deletion bmad/code/closed_orbit_calc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ subroutine closed_orbit_calc (lat, closed_orb, i_dim, direction, ix_branch, err_
if (maxval(amp_del(1:n_dim)) < 1d-4) then
if (printit) call out_io (s_error$, r_name, &
'Closed orbit not converging! error in closed orbit: \es10.2\ ', &
'Using branch: ' // branch_name(branch), &
'If this error is acceptable, change bmad_com%rel_tol_tracking (\es10.2\) and/or', &
'bmad_com%abs_tol_tracking (\es10.2\)', &
'Using branch: ' // branch_name(branch), &
r_array = [maxval(amp_del(1:n_dim)), bmad_com%rel_tol_tracking, bmad_com%abs_tol_tracking])
else
if (printit) call out_io (s_error$, r_name, &
Expand Down
6 changes: 4 additions & 2 deletions bmad/code/create_element_slice.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
! param -- lat_param_struct: lattice paramters.
! include_upstream_end -- Logical: Sliced_ele contains the ele's entrance end?
! include_downstream_end -- Logical: Sliced_ele contains the ele's exit end?
! old_slice -- ele_struct, optional: Previous slice. If present this saves computation
! old_slice -- ele_struct, optional: Previous slice or, if offset = 0, the previous element.
! If present this saves computation
! time of the reference energy and time at the start of the present slice.
! Also makes the ref energy continuous (there can be some small differences when
! using, say, runge_kutta tracking due to tracking tolerances).
Expand Down Expand Up @@ -63,7 +64,8 @@ recursive subroutine create_element_slice (sliced_ele, ele_in, l_slice, offset,
ele0%value(e_tot$) = old_slice%value(e_tot$)
ele0%ref_time = old_slice%ref_time
ele0%value(l$) = old_slice%value(l$)
if (allocated(old_slice%multipole_cache)) then
! Can only reuse multipole_cache if old_slice is an old slice and not the previous element in the branch.
if (allocated(old_slice%multipole_cache) .and. old_slice%name == ele_in%name) then
ele0%multipole_cache = old_slice%multipole_cache
has_mcache = .true.
endif
Expand Down
6 changes: 3 additions & 3 deletions bmad/modules/bmad_struct.f90
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ module bmad_struct
!

type wake_struct
type (wake_sr_struct) :: sr = wake_sr_struct('', null(), null(), null(), 0.0_rp, 0.0_rp, 0.0_rp, 1.0_rp, 1.0_rp, .true.) ! Short-range wake
type (wake_sr_struct) :: sr = wake_sr_struct('', wake_sr_z_struct(), null(), null(), 0.0_rp, 0.0_rp, 0.0_rp, 1.0_rp, 1.0_rp, .true.) ! Short-range wake
type (wake_lr_struct) :: lr = wake_lr_struct('', null(), 0.0_rp, 0.0_rp, 1.0_rp, 1.0_rp, .true.) ! Long-range wake
end type

Expand Down Expand Up @@ -2225,8 +2225,8 @@ module bmad_struct
real(rp) :: d_orb(6) = 1d-5 ! Orbit deltas for the mat6 via tracking calc.
real(rp) :: default_ds_step = 0.2_rp ! Default integration step for eles without an explicit step calc.
real(rp) :: significant_length = 1d-10 ! meter
real(rp) :: rel_tol_tracking = 1d-8 ! Closed orbit relative tolerance.
real(rp) :: abs_tol_tracking = 1d-11 ! Closed orbit absolute tolerance.
real(rp) :: rel_tol_tracking = 1d-9 ! Closed orbit relative tolerance.
real(rp) :: abs_tol_tracking = 1d-12 ! Closed orbit absolute tolerance.
real(rp) :: rel_tol_adaptive_tracking = 1d-8 ! Runge-Kutta tracking relative tolerance.
real(rp) :: abs_tol_adaptive_tracking = 1d-10 ! Runge-Kutta tracking absolute tolerance.
real(rp) :: init_ds_adaptive_tracking = 1d-3 ! Initial step size
Expand Down
2 changes: 1 addition & 1 deletion bmad/multiparticle/wake_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ subroutine sr_z_wake_particle (ele, bunch)
if (ele%wake%sr%amp_scale == 0) return

srz => ele%wake%sr%z
if (.not. allocated(srz%w)) return
if (srz%dz == 0) return


f0 = ele%wake%sr%amp_scale * bunch%charge_live
Expand Down
16 changes: 11 additions & 5 deletions bmad/parsing/bmad_parser_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,15 @@ subroutine parser_read_sr_wake (ele, delim, delim_found, err_flag)

if (.not. expect_one_of (', ', .false., ele%name, delim, delim_found)) return

allocate (ele%wake%sr%long(ilong))
ele%wake%sr%long = long(1:ilong)
allocate (wake_sr%long(ilong))
wake_sr%long = long(1:ilong)

allocate (ele%wake%sr%trans(itrans))
ele%wake%sr%trans = trans(1:itrans)
allocate (wake_sr%trans(itrans))
wake_sr%trans = trans(1:itrans)

if (.not. allocated(srz%w)) then
allocate (srz%w(0), srz%fw(0), srz%w_out(0), srz%fbunch(0))
endif

err_flag = .false.

Expand Down Expand Up @@ -1537,6 +1541,7 @@ subroutine parser_read_lr_wake (ele, delim, delim_found, err_flag)
if (.not. associated(ele%wake)) allocate (ele%wake)
if (.not. allocated(ele%wake%sr%long)) allocate (ele%wake%sr%long(0))
if (.not. allocated(ele%wake%sr%trans)) allocate (ele%wake%sr%trans(0))
if (.not. allocated(ele%wake%sr%z%w)) allocate (ele%wake%sr%z%w(0), ele%wake%sr%z%fw(0), ele%wake%sr%z%w_out(0), ele%wake%sr%z%fbunch(0))
if (allocated(ele%wake%lr%mode)) deallocate (ele%wake%lr%mode)

lat => ele%branch%lat
Expand Down Expand Up @@ -1679,6 +1684,7 @@ subroutine parser_read_old_format_lr_wake (ele, lr_file_name)
if (.not. associated(ele%wake)) allocate (ele%wake)
if (.not. allocated(ele%wake%sr%long)) allocate (ele%wake%sr%long(0))
if (.not. allocated(ele%wake%sr%trans)) allocate (ele%wake%sr%trans(0))
if (.not. allocated(ele%wake%sr%z%w)) allocate (ele%wake%sr%z%w(0), ele%wake%sr%z%fw(0), ele%wake%sr%z%w_out(0), ele%wake%sr%z%fbunch(0))
if (allocated(ele%wake%lr%mode)) deallocate (ele%wake%lr%mode)

! get data
Expand Down Expand Up @@ -1791,9 +1797,9 @@ subroutine parser_read_old_format_sr_wake (ele, sr_file_name)

if (.not. associated(ele%wake)) allocate (ele%wake)
if (.not. allocated(ele%wake%lr%mode)) allocate (ele%wake%lr%mode(0))
if (.not. allocated(ele%wake%sr%z%w)) allocate (ele%wake%sr%z%w(0), ele%wake%sr%z%fw(0), ele%wake%sr%z%w_out(0), ele%wake%sr%z%fbunch(0))
if (allocated(ele%wake%sr%long)) deallocate (ele%wake%sr%long)
if (allocated(ele%wake%sr%trans)) deallocate (ele%wake%sr%trans)
if (allocated(ele%wake%sr%z%w)) deallocate (ele%wake%sr%z%w, ele%wake%sr%z%fw, ele%wake%sr%z%fbunch, ele%wake%sr%z%w_out)

! Open file

Expand Down
5 changes: 2 additions & 3 deletions bmad/parsing/read_digested_bmad_file.f90
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,8 @@ subroutine read_this_ele (ele, ix_ele_in, error)
read (d_unit, err = 9800, end = 9800) wake%sr%trans(i)
enddo

read (d_unit, err = 9800, end = 9800) wake%sr%z%plane, wake%sr%z%position_dependence, wake%sr%z%dz, wake%sr%z%z0, n
allocate(wake%sr%z%w(n), wake%sr%z%fw(n), wake%sr%z%fbunch(n), wake%sr%z%w_out(n))
do i = 1, n
read (d_unit, err = 9800, end = 9800) wake%sr%z%plane, wake%sr%z%position_dependence, wake%sr%z%dz, wake%sr%z%z0
do i = 1, size(wake%sr%z%w)
read (d_unit, err = 9800, end = 9800) wake%sr%z%w(i), wake%sr%z%fw(i)
enddo

Expand Down
2 changes: 1 addition & 1 deletion bmad/parsing/write_digested_bmad_file.f90
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ subroutine write_this_ele (ele)
write (d_unit) wake%sr%trans(i)
enddo

write (d_unit) wake%sr%z%plane, wake%sr%z%position_dependence, wake%sr%z%dz, wake%sr%z%z0, size(wake%sr%z%w)
write (d_unit) wake%sr%z%plane, wake%sr%z%position_dependence, wake%sr%z%dz, wake%sr%z%z0
do i = 1, size(wake%sr%z%w)
write (d_unit) wake%sr%z%w(i), wake%sr%z%fw(i)
enddo
Expand Down
Loading

0 comments on commit 5f2f260

Please sign in to comment.