Skip to content

Commit

Permalink
Various small code tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Jun 28, 2024
1 parent ee2e16b commit a560366
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 37 deletions.
5 changes: 3 additions & 2 deletions bmad/modules/bmad_struct.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module bmad_struct
use sim_utils
use cubic_interpolation_mod

use ptc_spin, only: genfield, fibre, layout, c_damap, c_normal_form, c_taylor, probe_8, internal_state
use ptc_spin, only: genfield, fibre, layout, c_damap, c_normal_form, c_taylor, probe_8, internal_state, c_quaternion

private next_in_branch

Expand Down Expand Up @@ -1521,7 +1521,8 @@ module bmad_struct
type (c_normal_form) normal_form ! Complex normal form
type (c_taylor) phase(3) ! Phase/chromaticity maps
type (c_taylor) path_length ! Path length map. Gives momentum compaction.
type (c_taylor) spin_tune ! Spin map
type (c_taylor) spin_tune ! Amplitude dependent spin tune
type (c_quaternion) isf ! Invariant spin field in (x, px, ...) space.
type (internal_state) state ! PTC state
logical :: valid_map = .false.
end type
Expand Down
10 changes: 7 additions & 3 deletions bmad/modules/complex_taylor_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,23 @@ subroutine type_complex_taylors (complex_taylor, max_order, lines, n_lines, file

select case (o_type)
case ('PHASE')
nl=nl+1; write (li(nl), '(a)') ' Out Re Coef Im Coef Exponents Order Reference'
nl=nl+1; write (li(nl), '(a)') ' Out Real Coef Imag Coef Exponents Order Reference'
nl=nl+1; li(nl) = ' --------------------------------------------------------------------------------------------------------'
case ('NONE')
nl=nl+1; write (li(nl), '(a)') ' Re Coef Im Coef Exponents Order'
nl=nl+1; li(nl) = ' ----------------------------------------------------------------'
fmt1 = '(' // fmt1(5:); fmt2 = '(' // fmt2(5:)
case default
nl=nl+1; write (li(nl), '(a)') ' Out Re Coef Im Coef Exponents Order'
nl=nl+1; li(nl) = ' ---------------------------------------------------------------------'
nl=nl+1; write (li(nl), '(a)') ' Out Real Coef Imag Coef Exponents Order'
nl=nl+1; li(nl) = ' ----------------------------------------------------------------------'
end select

do i = 1, nt

if (i > 1) then
nl=nl+1; li(nl) = ' ----------------------------------------------------------------------'
endif

out_str = ' ??:'
select case(o_type)
case ('')
Expand Down
2 changes: 1 addition & 1 deletion tao/code/tao_init_find_elements.f90
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ subroutine tao_init_find_elements (u, search_string, eles, attribute, found_one)

! Find elements

call tao_locate_elements (string, u%ix_uni, eles, err, print_err = s_nooutput$)
call tao_locate_elements (string, u%ix_uni, eles, err, err_stat_level = s_nooutput$)
if (size(eles) > 0 .and. present(found_one)) found_one = .true.

warn_given = .false.
Expand Down
4 changes: 2 additions & 2 deletions tao/code/tao_init_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ subroutine tao_init_beam_in_universe (u, beam_init, track_start, track_end, comb
endif

if (u%beam%dump_at /= '') then
call tao_locate_elements (u%beam%dump_at, u%ix_uni, eles, err, ignore_blank = .false.)
call tao_locate_elements (u%beam%dump_at, u%ix_uni, eles, err, ignore_blank = .false., err_stat_level = s_warn$)
if (err) then
call out_io (s_warn$, r_name, 'BAD "dump_at" ELEMENT: ' // u%beam%dump_at)
else
do k = 1, size(eles)
ele => eles(k)%ele
if (ele%lord_status == super_lord$) ele => pointer_to_slave(ele, ele%n_lord)
if (ele%lord_status == super_lord$) ele => pointer_to_slave(ele, ele%n_slave) ! Downstream end of lord
u%model_branch(ele%ix_branch)%ele(ele%ix_ele)%save_beam_to_file = .true.
enddo
endif
Expand Down
4 changes: 2 additions & 2 deletions tao/code/tao_interface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,14 @@ subroutine tao_locate_all_elements (ele_list, eles, err, ignore_blank)
end subroutine

subroutine tao_locate_elements (ele_list, ix_universe, eles, err, lat_type, ignore_blank, &
print_err, above_ubound_is_err, ix_dflt_branch, multiple_eles_is_err)
err_stat_level, above_ubound_is_err, ix_dflt_branch, multiple_eles_is_err)
import
implicit none
character(*) ele_list
integer ix_universe
type (ele_pointer_struct), allocatable :: eles(:)
logical err
integer, optional :: lat_type, print_err, ix_dflt_branch
integer, optional :: lat_type, err_stat_level, ix_dflt_branch
logical, optional :: ignore_blank, above_ubound_is_err, multiple_eles_is_err
end subroutine

Expand Down
10 changes: 5 additions & 5 deletions tao/code/tao_locate_elements.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!+
! Subroutine tao_locate_elements (ele_list, ix_universe, eles, err, lat_type, ignore_blank,
! print_err, ix_dflt_branch, multiple_eles_is_err)
! err_stat_level, ix_dflt_branch, multiple_eles_is_err)
!
! Subroutine to find the lattice elements in the lattice
! corresponding to the ele_list argument.
Expand All @@ -15,7 +15,7 @@
! lat_type -- integer, optional: model$ (default), design$, or base$.
! ignore_blank -- logical, optional: If present and true then do nothing if
! ele_list is blank. otherwise treated as an error.
! print_err -- integer, optional: Status level for error messages. If not present,
! err_stat_level -- integer, optional: Status level for error messages. If not present,
! print with level s_error$. Use s_nooutput$ to prevent printing.
! ix_dflt_branch -- integer, optional: If present and positive then use this as the branch index
! for elements specified using an integer index (EG: "43").
Expand All @@ -29,7 +29,7 @@
!-

subroutine tao_locate_elements (ele_list, ix_universe, eles, err, lat_type, ignore_blank, &
print_err, above_ubound_is_err, ix_dflt_branch, multiple_eles_is_err)
err_stat_level, above_ubound_is_err, ix_dflt_branch, multiple_eles_is_err)

use tao_interface, dummy => tao_locate_elements

Expand All @@ -39,7 +39,7 @@ subroutine tao_locate_elements (ele_list, ix_universe, eles, err, lat_type, igno
type (tao_lattice_struct), pointer :: tao_lat
type (ele_pointer_struct), allocatable :: eles(:)

integer, optional :: lat_type, ix_dflt_branch, print_err
integer, optional :: lat_type, ix_dflt_branch, err_stat_level
integer ios, ix, ix_universe, num, i, i_ix_ele, n_loc, print_lev

character(*) ele_list
Expand All @@ -52,7 +52,7 @@ subroutine tao_locate_elements (ele_list, ix_universe, eles, err, lat_type, igno
!

err = .true.
print_lev = integer_option(s_error$, print_err)
print_lev = integer_option(s_error$, err_stat_level)

call re_allocate_eles (eles, 0, exact = .true.)

Expand Down
8 changes: 8 additions & 0 deletions tao/code/tao_ptc_normal_form.f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ subroutine tao_ptc_normal_form (do_calc, tao_lat, ix_branch, rf_on)
call kill(ptc_nf%phase)
call kill(ptc_nf%spin_tune)
call kill(ptc_nf%path_length)
call kill(ptc_nf%isf)
ptc_nf%valid_map = .false.
endif

Expand All @@ -63,6 +64,7 @@ subroutine tao_ptc_normal_form (do_calc, tao_lat, ix_branch, rf_on)
call alloc(ptc_nf%phase)
call alloc(ptc_nf%spin_tune)
call alloc(ptc_nf%path_length)
call alloc(ptc_nf%isf)
call alloc(beta)
call alloc(c_da)
call alloc(c_tay)
Expand All @@ -80,6 +82,12 @@ subroutine tao_ptc_normal_form (do_calc, tao_lat, ix_branch, rf_on)
beta = (1 + beta) / sqrt((1+beta)**2 + mm**2)
ptc_nf%path_length = (branch%param%total_length - ptc_nf%phase(3)) * beta / beta0

c_da%q%x = 0.0d0
c_da%q%x(2) = 1.0d0
c_da = ptc_nf%normal_form%atot*c_da*ptc_nf%normal_form%atot**(-1)
ptc_nf%isf = c_da%q


! this_rf_on = rf_is_on(branch)
! call normal_form_taylors(normal_form%m, this_rf_on, dhdj = normal_form%dhdj, &
! A = normal_form%A, A_inverse = normal_form%A_inv) ! Get A, A_inv, dhdj
Expand Down
2 changes: 1 addition & 1 deletion tao/code/tao_python_cmd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,7 @@ subroutine tao_python_cmd (input_str)
nl=incr(nl); write (li(nl), lmt) 'has#pixel;LOGIC;F;', (allocated(ele%photon%pixel%pt))
nl=incr(nl); write (li(nl), lmt) 'has#material;LOGIC;F;', &
(attribute_name(ele, material_type$) == 'MATERIAL_TYPE' .or. ele%key == crystal$)
nl=incr(nl); write (li(nl), amt) 'grid#type;LOGIC;F;', trim(surface_grid_type_name(ele%photon%grid%type))
nl=incr(nl); write (li(nl), amt) 'grid#type;ENUM;F;', trim(surface_grid_type_name(ele%photon%grid%type))

case ('material')
if (ele%key == multilayer_mirror$) then
Expand Down
43 changes: 23 additions & 20 deletions tao/code/tao_show_this.f90
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ subroutine tao_show_this (what, result_id, lines, nl)
type (track_point_struct), pointer :: tp
type (strong_beam_struct), pointer :: sb
type (c_taylor) ptc_ctaylor
type (complex_taylor_struct) bmad_ctaylor
type (complex_taylor_struct) bmad_ctaylor, ctaylor(3)
type (rad_map_ele_struct), pointer :: ri
type (grid_field_pt1_struct), pointer :: g_pt
type (tao_expression_info_struct), allocatable :: info(:)
Expand Down Expand Up @@ -4463,7 +4463,7 @@ subroutine tao_show_this (what, result_id, lines, nl)
do
call tao_next_switch (what2, [character(24):: '-element', '-n_axis', '-l_axis', &
'-g_map', '-flip_n_axis', '-x_zero', '-y_zero', &
'-z_zero', '-ignore_kinetic'], .true., switch, err)
'-z_zero', '-ignore_kinetic', '-isf'], .true., switch, err)
if (err) return

select case (switch)
Expand All @@ -4481,6 +4481,8 @@ subroutine tao_show_this (what, result_id, lines, nl)
endif
case ('-flip_n_axis')
flip = .true.
case ('-isf')
what_to_show = 'isf'
case ('-n_axis')
read (what2, *, iostat = ios) sm%axis_input%n0
if (ios /= 0) then
Expand Down Expand Up @@ -4522,6 +4524,25 @@ subroutine tao_show_this (what, result_id, lines, nl)

if (.not. bmad_com%spin_tracking_on) call tao_spin_tracking_turn_on

!

if (what_to_show == 'isf') then
if (branch%param%geometry == open$) then
nl=nl+1; lines(nl) = 'No ISF for an open lattice!'
return
endif

tao_branch%spin_map_valid = .false.
if (.not. u%calc%one_turn_map) call tao_ptc_normal_form (.true., u%model, branch%ix_branch)

ptc_nf => tao_branch%ptc_normal_form
do i = 1, 3
ctaylor(i) = ptc_nf%isf%x(i)
enddo
call type_complex_taylors(ctaylor)
return
endif

! what_to_show = standard

r = anomalous_moment_of(branch%param%particle) * branch%ele(1)%value(e_tot$) / mass_of(branch%param%particle)
Expand All @@ -4546,24 +4567,6 @@ subroutine tao_show_this (what, result_id, lines, nl)

!

nl=nl+1; lines(nl) = ''
nl=nl+1; lines(nl) = ' N chrom_ptc.a.N chrom_ptc.b.N spin_tune_ptc.N'

ptc_nf => tao_branch%ptc_normal_form
do i = 0, ptc_private%taylor_order_ptc-1
expo = [0, 0, 0, 0, 0, i]
z1 = real(ptc_nf%phase(1) .sub. expo)
z2 = real(ptc_nf%phase(2) .sub. expo)
s0 = real(ptc_nf%spin_tune .sub. expo)
if (i == 0) then
nl=nl+1; write (lines(nl), '(i3, 3es18.7, a)') i, z1, z2, s0, ' ! 0th order are the tunes'
else
nl=nl+1; write (lines(nl), '(i3, 3es18.7)') i, z1, z2, s0
endif
enddo

!

nl=nl+1; lines(nl) = ''
nl=nl+1; write (lines(nl), '(a, es18.7)') 'spin_tune: ', tao_branch%spin%tune / twopi
if (tao_branch%spin%valid) then
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/06/22 15:38:34"
character(*), parameter :: tao_version_date = "2024/06/28 11:20:17"
end module

0 comments on commit a560366

Please sign in to comment.