Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added error checking to symp_lie_bmad. #596

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dcs16_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: gh pr create -B main -H ${{ github.ref_name }} --title "${{ github.ref_name }}" --body "${{ github.event.head_commit.message }}"
- run: gh pr create -B main -H ${{ github.ref_name }} --title "${{ github.event.head_commit.message }}" --body "${{ github.event.head_commit.message }}"
env:
GITHUB_TOKEN: ${{ secrets.DCS_PUSH }}
20 changes: 14 additions & 6 deletions bmad/code/write_lattice_in_foreign_format.f90
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ subroutine write_lattice_in_foreign_format (out_type, out_file_name, lat, ref_or
character(2) continue_char, eol_char, comment_char, separator_char

logical, optional :: use_matrix_model, include_apertures, err
logical init_needed, mad_out, err_flag
logical init_needed, mad_out, err_flag, monopole
logical parsing, warn_printed, converted, ptc_exact_model

! SAD translation
Expand Down Expand Up @@ -288,9 +288,18 @@ subroutine write_lattice_in_foreign_format (out_type, out_file_name, lat, ref_or
endif

! If there is a multipole component then put multipole elements at half strength
! just before and just after the element.
! just before and just after the element. Exception: With Elegant if there is only one multipole for a quad, sextupole, or octupole

if (ele%key /= multipole$ .and. ele%key /= ab_multipole$ .and. ele%key /= null_ele$ .and. ele%key /= sad_mult$) then
monopole = .false.
if (out_type == 'ELEGANT') then
select case (ele%key)
case (quadrupole$, sextupole$, octupole$) ! Elegant
call multipole_ele_to_kt(ele, .true., ix_pole_max, knl, tilts, magnetic$, include_kicks$)
if (count(knl /= 0) == 1 .and. all(knl(0:3) == 0)) monopole = .true.
end select
endif

if (.not. monopole .and. ele%key /= multipole$ .and. ele%key /= ab_multipole$ .and. ele%key /= null_ele$ .and. ele%key /= sad_mult$) then
call multipole_ele_to_ab (ele, .true., ix_pole_max, ab_ele%a_pole, ab_ele%b_pole)
if (ix_pole_max > -1) then
ab_ele%a_pole = ab_ele%a_pole / 2
Expand Down Expand Up @@ -661,10 +670,8 @@ subroutine write_lattice_in_foreign_format (out_type, out_file_name, lat, ref_or
select case (ele%key)
case (quadrupole$, sextupole$, octupole$) ! Elegant
call multipole_ele_to_kt(ele, .true., ix_pole_max, knl, tilts, magnetic$, include_kicks$)
knl = knl / ele%value(l$)

if (count(knl /= 0) == 1 .and. all(knl(0:3) == 0)) then
n = find_location(knl /= 0, .true.)
n = find_location(knl /= 0, .true.) - 1
write (line_out, '(2a)') trim(ele%name) // ': mult'
call value_to_line(line_out, knl(n), 'knl', 'R')
write (line_out, '(2a, i0)') trim(line_out), ', order = ', n
Expand All @@ -676,6 +683,7 @@ subroutine write_lattice_in_foreign_format (out_type, out_file_name, lat, ref_or
call pointer_to_attribute (ele, upcase(bmad_params(i)), .true., a_ptr, err_flag)
call value_to_line (line_out, a_ptr%r, elegant_params(i), 'R')
enddo
call write_line(line_out)
cycle
endif
end select
Expand Down
11 changes: 11 additions & 0 deletions bmad/low_level/symp_lie_bmad.f90
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ subroutine symp_lie_bmad (ele, param, orbit, track, mat6, make_matrix, offset_el

field_ele => pointer_to_field_ele(ele, 1, z_offset)

if (associated(field_ele%cylindrical_map) .or. associated(field_ele%gen_grad_map) .or. &
associated(field_ele%grid_field)) then
call out_io (s_fatal$, r_name, 'ELEMENT: ' // ele%name, 'CYLINDRICAL, GEN_GRAD OR GRID_FIELD MAP BUT SYMP_LIE_PTC CAN ONLY HANDLE CARTESIAN.')
if (global_com%exit_on_error) call err_exit
orbit%state = lost$
return
endif


if (.not. associated(field_ele%cartesian_map)) then ! Only if wiggler or undulator
allocate (ct_map)
call create_wiggler_cartesian_map(field_ele, ct_map)
Expand All @@ -161,6 +170,7 @@ subroutine symp_lie_bmad (ele, param, orbit, track, mat6, make_matrix, offset_el
if (size(field_ele%cartesian_map) > 1) then
call out_io (s_fatal$, r_name, 'ELEMENT: ' // ele%name, 'HAS MULTIPLE CARTESIAN MAPS. SYMP_LIE_PTC CAN ONLY HANDLE ONE.')
if (global_com%exit_on_error) call err_exit
orbit%state = lost$
return
endif
ct_map => field_ele%cartesian_map(1)
Expand All @@ -169,6 +179,7 @@ subroutine symp_lie_bmad (ele, param, orbit, track, mat6, make_matrix, offset_el
if (ct_map%field_type /= magnetic$) then
call out_io (s_fatal$, r_name, 'ELEMENT: ' // ele%name, 'HAS A CARTESIAN MAP THAT IS NOT MAGNETIC. SYMP_LIE_PTC CAN NOT HANDLE THIS.')
if (global_com%exit_on_error) call err_exit
orbit%state = lost$
return
endif

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 = "2023/10/25 18:25:06"
character(*), parameter :: tao_version_date = "2023/10/27 01:26:49"
end module
Loading