Skip to content

Commit

Permalink
Small changes to write_lattice_in_julia and elegant_to_bmad.py. (#1056)
Browse files Browse the repository at this point in the history
* Fixed Tao `set particle_start` for photon energy

* Small changes to write_lattice_in_julia and elegant_to_bmad.py.
  • Loading branch information
DavidSagan committed Jul 12, 2024
1 parent 6dffb32 commit c8d13b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
46 changes: 24 additions & 22 deletions bmad/output/write_lattice_in_julia.f90
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,36 @@ subroutine write_lattice_in_julia(bmad_file, lat, julia_file)
if (.not. has_been_added) cycle

! Write element def
! The beginning element for all branches has the same name so use a unique name here.

if (ie == 0) ele%name = 'begin' // int_str(ib+1)
if (ie == branch%n_ele_track .and. ele%name == 'END') ele%name = 'end' // int_str(ib+1)
line = '@ele ' // trim(downcase(ele%name)) // ' = ' // trim(julia_name(ele%key)) // '('

if (ele%field_master) write (line, '(3a)') trim(line), ', field_master = ', jbool(ele%field_master)
if (.not. ele%is_on) write (line, '(3a)') trim(line), ', is_on = ', jbool(ele%is_on)

!

if (ele%key == beginning_ele$) then
line = trim(line) // ', pc_ref = ' // re_str(ele%value(p0c$))
line = trim(line) // ', species_ref = ' // re_str(ele%value(p0c$))
if (ele%a%beta /= 0) line = trim(line) // ', twiss.a.beta = ' // re_str(ele%a%beta)
if (ele%b%beta /= 0) line = trim(line) // ', twiss.b.beta = ' // re_str(ele%b%beta)
if (ele%a%alpha /= 0) line = trim(line) // ', twiss.a.alpha = ' // re_str(ele%a%alpha)
if (ele%b%alpha /= 0) line = trim(line) // ', twiss.b.alpha = ' // re_str(ele%b%alpha)
if (ele%x%eta /= 0) line = trim(line) // ', twiss.x.eta = ' // re_str(ele%x%eta)
if (ele%y%eta /= 0) line = trim(line) // ', twiss.y.eta = ' // re_str(ele%y%eta)
if (ele%x%etap /= 0) line = trim(line) // ', twiss.x.etap = ' // re_str(ele%x%etap)
if (ele%y%etap /= 0) line = trim(line) // ', twiss.y.etap = ' // re_str(ele%y%etap)
if (ie == 0) then
line = trim(line) // ', pc_ref = ' // re_str(ele%value(p0c$))
line = trim(line) // ', species_ref = ' // trim(species_name(ele%ref_species))
if (ele%a%beta /= 0) line = trim(line) // ', twiss.a.beta = ' // re_str(ele%a%beta)
if (ele%b%beta /= 0) line = trim(line) // ', twiss.b.beta = ' // re_str(ele%b%beta)
if (ele%a%alpha /= 0) line = trim(line) // ', twiss.a.alpha = ' // re_str(ele%a%alpha)
if (ele%b%alpha /= 0) line = trim(line) // ', twiss.b.alpha = ' // re_str(ele%b%alpha)
if (ele%x%eta /= 0) line = trim(line) // ', twiss.x.eta = ' // re_str(ele%x%eta)
if (ele%y%eta /= 0) line = trim(line) // ', twiss.y.eta = ' // re_str(ele%y%eta)
if (ele%x%etap /= 0) line = trim(line) // ', twiss.x.etap = ' // re_str(ele%x%etap)
if (ele%y%etap /= 0) line = trim(line) // ', twiss.y.etap = ' // re_str(ele%y%etap)
if (any(ele%c_mat /= 0)) line = trim(line) // ', twiss.c_mat = [' // re_str(ele%c_mat(1,1)) // ', ' // re_str(ele%c_mat(1,2)) // &
'; ' // re_str(ele%c_mat(2,1)) // ', ' // re_str(ele%c_mat(2,2)) // ']'
orb => lat%particle_start
if (any(orb%vec /= 0)) line = trim(line) // ', particle.orbit = [' // re_str(orb%vec(1)) // ', ' // re_str(orb%vec(2)) // ', ' // &
re_str(orb%vec(3)) // ', ' // re_str(orb%vec(4)) // ', ' // re_str(orb%vec(5)) // ', ' // re_str(orb%vec(6)) // ']'
if (any(orb%spin /= 0)) line = trim(line) // ', particle.spin = [' // &
re_str(orb%spin(1)) // ', ' // re_str(orb%spin(2)) // ', ' //re_str(orb%spin(3)) // ']'

endif

if (ele%field_master) write (line, '(3a)') trim(line), ', field_master = ', jbool(ele%field_master)
if (.not. ele%is_on) write (line, '(3a)') trim(line), ', is_on = ', jbool(ele%is_on)

!

if (ele%key == sbend$) then
Expand Down Expand Up @@ -299,7 +301,7 @@ subroutine write_lattice_in_julia(bmad_file, lat, julia_file)
mult_ele => mult_lat%branch(ib)%ele
in_multi_region = .false.

do ie = 1, branch%n_ele_track
do ie = 0, branch%n_ele_track
ele => branch%ele(ie)
ix_pass = m_info%branch(ib)%ele(ie)%ix_pass
if (ix_pass /= 1) cycle
Expand Down Expand Up @@ -346,13 +348,13 @@ subroutine write_lattice_in_julia(bmad_file, lat, julia_file)
write (iu, '(a)')
name = downcase(branch%name)
if (name == '') name = 'lat_line'
line = trim(name) // ' = beamline(' // quote(name) // ', ['
line = trim(name) // ' = beamline(' // quote(name) // ', [' // trim(branch%ele(0)%name) // ','

in_multi_region = .false.
do ie = 0, branch%n_ele_track
e_info => m_info%branch(ib)%ele(max(1,ie))
ele => branch%ele(max(1,ie))
if (ie == ele%branch%n_ele_track .and. ele%name == 'END' .and. ele%key == marker$) cycle
do ie = 1, branch%n_ele_track
ele => branch%ele(ie)

e_info => m_info%branch(ib)%ele(ie)

if (.not. e_info%multipass) then
call write_julia_element (line, iu, ele, lat)
Expand Down
2 changes: 1 addition & 1 deletion util_programs/elegant_to_bmad/elegant_to_bmad.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def parse_element(dlist):

# Malign -> Gkicker

if ele.bmad_type == 'malign':
if elegant_type == 'malign':
if eparam == 'dx':
bparam = 'x_kick'
elif eparam == 'dy':
Expand Down

0 comments on commit c8d13b3

Please sign in to comment.