Skip to content

Commit

Permalink
Fix element geometry at mirror center.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Nov 6, 2024
1 parent 65b1c77 commit 88b4060
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions bmad/code/twiss_and_track_intra_ele.f90
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ recursive subroutine twiss_and_track_intra_ele (ele, param, l_start, l_end, trac
return
endif

! mirror, multilayer_mirror, and crystal are exceptional if floor coords needed

if (ele%key == mirror$ .or. ele%key == multilayer_mirror$ .or. ele%key == crystal$) then
do_downstream = (track_downstream_end .or. (orbit_start%location == downstream_end$ .and. orbit_start%ix_ele == ele%ix_ele))
if (.not. do_downstream) then ! Then must be center
if (present(orbit_end)) orbit_end = orbit_start ! Note: Orbit does not make sense here.
if (present(ele_end)) then
ele_end = ele
if (logic_option(.false., compute_floor_coords)) call ele_geometry (ele_start%floor, ele, ele_end%floor, 0.5_rp)
endif
return
endif
endif



! zero length element:
! Must ignore track_upstream_end and track_downstream_end since they do not make sense in this case.

Expand Down
8 changes: 4 additions & 4 deletions bmad/geometry/ele_geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,16 @@ recursive subroutine ele_geometry (floor_start, ele, floor_end, len_scale, ignor

!---------------------------
! General case where layout is not in the horizontal plane
! Note:

has_multipole_rot_tilt = .false.
if (key == multipole$) then
call multipole_ele_to_kt (ele, .true., ix_pole_max, knl, tilt)
if (knl(0) /= 0 .and. tilt(0) /= 0) has_multipole_rot_tilt = .true.
endif

if (((key == mirror$ .or. key == sbend$ .or. key == rf_bend$ .or. key == multilayer_mirror$) .and. &
ele%value(ref_tilt_tot$) /= 0) .or. phi /= 0 .or. psi /= 0 .or. key == patch$ .or. &
key == crystal$ .or. has_multipole_rot_tilt) then
if (phi /= 0 .or. psi /= 0 .or. key == patch$ .or. key == crystal$ .or. has_multipole_rot_tilt .or. &
((key == sbend$ .or. key == rf_bend$) .and. ele%value(ref_tilt_tot$) /= 0) .or. &
((key == mirror$ .or. key == multilayer_mirror$) .and. (ele%value(ref_tilt_tot$) /= 0 .or. abs(len_factor - 0.5) < 0.25))) then

select case (key)

Expand Down Expand Up @@ -371,6 +370,7 @@ recursive subroutine ele_geometry (floor_start, ele, floor_end, len_scale, ignor
call floor_angles_to_w_mat (theta, phi, psi, w_mat)
floor%r = floor0%r + matmul(w_mat, r_vec)

! The factor of pi/2 rotates to surface coordinates.
if (len_factor == 0.5_rp) then
if (ele%key == crystal$) then
s_mat = w_mat_for_bend_angle(angle-pi/2, ele%value(ref_tilt_tot$) + ele%value(tilt_corr$), r_vec)
Expand Down

0 comments on commit 88b4060

Please sign in to comment.