Skip to content

Commit

Permalink
Merge pull request #3 from bmad-sim/main
Browse files Browse the repository at this point in the history
Pulling in latest from bmad-sim
  • Loading branch information
MichaelEhrlichman authored Dec 4, 2023
2 parents f2cfbcb + 8c2b939 commit ab9d314
Show file tree
Hide file tree
Showing 72 changed files with 2,152 additions and 1,490 deletions.
Binary file modified bmad-doc/other_manuals/long_term_tracking.pdf
Binary file not shown.
20 changes: 16 additions & 4 deletions bmad/code/attribute_bookkeeper.f90
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ subroutine attribute_bookkeeper (ele, force_bookkeeping)
val(gradient$) = val(voltage$) / val(l$)
endif

if (val(e_tot$) /= 0) then
beta = ele%value(p0c$) / ele%value(e_tot$)
time = branch%param%total_length / (c_light * beta)
if (time /= 0) then
if (is_true(val(harmon_master$))) then
val(rf_frequency$) = val(harmon$) / time
else
val(harmon$) = val(rf_frequency$) * time
endif
endif
endif

if (val(rf_frequency$) /= 0) then
val(rf_wavelength$) = c_light / val(rf_frequency$)
else
Expand Down Expand Up @@ -551,7 +563,7 @@ subroutine attribute_bookkeeper (ele, force_bookkeeping)
beta = ele%value(p0c$) / ele%value(e_tot$)
time = branch%param%total_length / (c_light * beta)
if (time /= 0) then
if (ele%value(rf_frequency$) <= 0) then
if (is_true(val(harmon_master$))) then
val(rf_frequency$) = val(harmon$) / time
else
val(harmon$) = val(rf_frequency$) * time
Expand Down Expand Up @@ -590,7 +602,7 @@ subroutine attribute_bookkeeper (ele, force_bookkeeping)
beta = ele%value(p0c$) / ele%value(e_tot$)
time = branch%param%total_length / (c_light * beta)
if (time /= 0) then
if (ele%value(rf_frequency$) <= 0) then
if (is_true(val(harmon_master$))) then
val(rf_frequency$) = val(harmon$) / time
else
val(harmon$) = val(rf_frequency$) * time
Expand Down Expand Up @@ -819,8 +831,8 @@ subroutine attribute_bookkeeper (ele, force_bookkeeping)
if (associated(ele%rad_map)) ele%rad_map%stale = .true. ! Forces recalc

if (allocated(ele%multipole_cache)) then
ele%multipole_cache%ix_pole_mag_max = invalid$ ! Forces recalc
ele%multipole_cache%ix_pole_elec_max = invalid$ ! Forces recalc
ele%multipole_cache%mag_valid = .false.
ele%multipole_cache%elec_valid = .false.
endif

! Set old_value = value
Expand Down
2 changes: 1 addition & 1 deletion bmad/code/ele_order_calc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

subroutine ele_order_calc (lat, order)

use pointer_to_ele_mod, dummy => ele_order_calc
use bmad_routine_interface, dummy => ele_order_calc

implicit none

Expand Down
6 changes: 3 additions & 3 deletions bmad/code/em_field_calc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ recursive subroutine em_field_calc (ele, param, s_pos, orbit, local_ref_frame, f
! The crab cavity is modeled as a TM110 traveling wave mode
if (ele%value(l$) /= 0) then
voltage = e_accel_field(ele, voltage$) / ref_charge
k_rf = twopi * ele%value(rf_frequency$) / c_light
if (present(rf_time)) then
time = rf_time
else
time = particle_rf_time(orbit, ele, .true., s_body)
time = particle_rf_time(orbit, ele, .false., s_body)
endif
phase = twopi * (ele%value(phi0$) + ele%value(phi0_multipass$) + ele%value(phi0_autoscale$) - &
(time - rf_ref_time_offset(ele)) * ele%value(rf_frequency$)) + k_rf * s_body
(time - rf_ref_time_offset(ele) - s_body/c_light) * ele%value(rf_frequency$))

k_rf = twopi * ele%value(rf_frequency$) / c_light
field%B(2) = -voltage * sin(phase) / (c_light * ele%value(l$))
field%E(3) = voltage * k_rf * orbit%beta * orbit%vec(1) * cos(phase) / ele%value(l$)
endif
Expand Down
2 changes: 1 addition & 1 deletion bmad/code/find_element_ends.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

subroutine find_element_ends (ele, ele1, ele2, ix_multipass)

use pointer_to_ele_mod, except_dummy => find_element_ends
use bmad_routine_interface, except_dummy => find_element_ends

implicit none

Expand Down
9 changes: 4 additions & 5 deletions bmad/code/lat_compute_reference_energy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,11 @@ subroutine track_this_ele (orb_start, orb_end, ref_time_start, is_inside, error)
call zero_errors_in_ele (ele, changed)
call init_coord (orb_start, ele%time_ref_orb_in, ele, upstream_end$, shift_vec6 = .false.)
if (is_inside) orb_start%location = inside$ ! To avoid entrance kick in time RK tracking

ele%value(dispatch$) = no_misalignment$
call track1 (orb_start, ele, param, orb_end, ignore_radiation = .true.)
ele%value(dispatch$) = 0

if (.not. particle_is_moving_forward(orb_end)) then
call out_io (s_fatal$, r_name, 'PARTICLE LOST IN TRACKING: ' // ele%name, &
'CANNOT COMPUTE REFERENCE TIME & ENERGY.')
Expand Down Expand Up @@ -866,11 +870,6 @@ recursive subroutine zero_errors_in_ele (ele, changed)
enddo
endif

if (ele_has_nonzero_offset(ele)) then
call zero_ele_offsets (ele)
has_changed = .true.
endif

if (ele_has_nonzero_kick(ele)) then
call zero_ele_kicks (ele)
has_changed = .true.
Expand Down
Loading

0 comments on commit ab9d314

Please sign in to comment.