Skip to content

Commit

Permalink
Merge pull request #507 from bmad-sim/devel/step12
Browse files Browse the repository at this point in the history
Fix write_bmad_lattice_file to properly handle generalized gradient m…
  • Loading branch information
DavidSagan authored Sep 23, 2023
2 parents 8e91fad + 8517725 commit 9ace86b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 21 deletions.
5 changes: 2 additions & 3 deletions bmad/code/write_bmad_lattice_file.f90
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ subroutine write_bmad_lattice_file (bmad_file, lat, err, output_form, orbit0)
if (has_attribute (ele, 'APERTURE_TYPE') .and. (ele%aperture_type /= ele_dflt%aperture_type)) &
line = trim(line) // ', aperture_type = ' // aperture_type_name(ele%aperture_type)

if (has_attribute (ele, 'SYMPLECTIFY') .and. ele%symplectify) line = trim(line) // ', symplectify'
if (has_attribute (ele, 'SYMPLECTIFY') .and. ele%symplectify) line = trim(line) // ', symplectify = T'

if (has_attribute (ele, 'FIELD_MASTER') .and. (ele%field_master .neqv. ele_dflt%field_master)) &
write (line, '(2a, l1)') trim(line), ', field_master = ', ele%field_master
Expand Down Expand Up @@ -1802,13 +1802,12 @@ subroutine write_this_gen_grad_map_map (gg_map, ele, iu9, line)
gg => gg_map%gg(ig)
write (iu9, '(2x, a)') 'curve = {'
write (iu9, '(4x, a, i0, a)') 'm = ', gg%m, ','
write (iu9, '(4x, 3a)') 'type = ', trim(expression_op_name(gg%sincos)), ','
write (iu9, '(4x, 3a)') 'kind = ', trim(expression_op_name(gg%sincos)), ','
write (iu9, '(4x, a)') 'derivs = {'


n = gg%n_deriv_max
write (fmt, '(a, i0, a)') '(f13.5, a, ', n+1, 'es20.12, a)'
print *, fmt
do iz = gg_map%iz0, gg_map%iz1-1
write (iu9, fmt) iz*gg_map%dz, ':', gg%deriv(iz,0:n), ','
enddo
Expand Down
4 changes: 2 additions & 2 deletions bmad/doc/attributes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ \subsection{Gen_Grad_Map}
dz = <Real>, ! Distance between sampled field points.
curve = \{ ! Generalized gradient curve
m = <Int>, ! Azimuthal m value
type = <Sin-or-Cos> ! Type of curve: sin or cos.
kind = <Sin-or-Cos> ! Type of curve: sin or cos.
derivs = \{
<z0>: <d0> <d1> <d2> ... <dN>,
<z1>: ...,
Expand All @@ -2704,7 +2704,7 @@ \subsection{Gen_Grad_Map}
See Sec.~\sref{s:fieldmap.com} for an explanation of the attributes that are common with other field
map types. In general there will be multiple \vn{curve} instances. A given \vn{curve} instance
specifies one generalized gradient with a given azimuthal \vn{m} value and a \vn{type} which
specifies one generalized gradient with a given azimuthal \vn{m} value and a \vn{kind} which
specifies if the generalized gradient is \vn{sin}-like or \vn{cos}-like. Each \vn{curve} has a table
of derivatives given by the \vn{derivs} component. Each row in the derivative table starts with the
z-position of the derivatives \vn{<z0>}, \vn{<z1>}, \vn{z2}, ... etc. The z-positions must be in
Expand Down
2 changes: 1 addition & 1 deletion bmad/doc/cover-page.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

\begin{flushright}
\large
Revision: September 11, 2023 \\
Revision: September 13, 2023 \\
\end{flushright}

\pdfbookmark[0]{Preamble}{Preamble}
Expand Down
8 changes: 6 additions & 2 deletions bmad/modules/expression_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,18 @@ subroutine push_numeric_or_var (word, err, op, i_op, stack, n_stack, var_type)

else
call pushit_stack (stack, n_stack, var_type)
stack(n_stack)%name = word
! "my_species" in "mass_of(my_species)" is considered a variable and not a species_const
if (var_type == species_const$) then
stack(n_stack)%name = word
stack(n_stack)%value = species_id(word)
if (species_id(word) == invalid$) stack(n_stack)%type = variable$
elseif (var_type == variable$) then
stack(n_stack)%name = upcase(word)
else
stack(n_stack)%name = word
endif

select case (word)
select case (downcase(word))
case ('twopi'); stack(n_stack) = expression_atom_struct(word, constant$, twopi)
case ('fourpi'); stack(n_stack) = expression_atom_struct(word, constant$, fourpi)
case ('pi'); stack(n_stack) = expression_atom_struct(word, constant$, pi)
Expand Down
4 changes: 2 additions & 2 deletions regression_tests/bookkeeper_test/output.correct
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"ele32" ABS 0 33 1 0 0 0 0
"ele33" ABS 0 34 3 0 37 1 0
"ele34" ABS 0 37 1 0 0 0 0
"Hybrid" ABS 1e-12 5.036E-14
"Hybrid" ABS 1e-12 5.038E-14
"ON_OFF_SAVE" ABS 0 0.100 0.300 0.400 0.200
"Q1#1[L]" ABS 0 1.5000
"Q1\Q4[L]" ABS 0 0.5000
Expand Down Expand Up @@ -138,7 +138,7 @@
"GR4[COMMAND]" ABS 0 8.0000
"GRN[A]" ABS 0 0.0100
"GRN[B]" ABS 0 2.0000
"GRN[string]" STR "(tan(a)+b)*(0.1/c_light)^(a+0.2)-a-(1+2)"
"GRN[string]" STR "(tan(A)+B)*(0.1/c_light)^(A+0.2)-A-(1+2)"
"Next-1" ABS 0 0
"Next-2" ABS 0 1
"Next-3" ABS 0 2
Expand Down
6 changes: 3 additions & 3 deletions regression_tests/scripts/svn_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"https://accserv.classe.cornell.edu/svn/trunk/src/open_spacecharge" : "50675",
"https://accserv.classe.cornell.edu/svn/packages/PGPLOT" : "55094", # Change from 50204
"https://accserv.classe.cornell.edu/svn/packages/fftw" : "54912", # Change from 54142
"https://accserv.classe.cornell.edu/svn/packages/fgsl" : "54914", # Change from 54143
"https://accserv.classe.cornell.edu/svn/packages/fgsl" : "55230", # Change from 54914
"https://accserv.classe.cornell.edu/svn/packages/gnu_utilities_src" : "51479",
"https://accserv.classe.cornell.edu/svn/packages/gsl" : "54913", # Change from 53177
"https://accserv.classe.cornell.edu/svn/packages/gsl" : "55228", # Change from 54913
"https://accserv.classe.cornell.edu/svn/packages/hdf5" : "55115", # Change from 54917
"https://accserv.classe.cornell.edu/svn/packages/lapack" : "54915", # Change from 53213
"https://accserv.classe.cornell.edu/svn/packages/lapack95" : "53051",
"https://accserv.classe.cornell.edu/svn/packages/openmpi" : "51988",
"https://accserv.classe.cornell.edu/svn/packages/plplot" : "55075", # Change from 54925
"https://accserv.classe.cornell.edu/svn/packages/xraylib" : "54916", # Change from 53181
"https://accserv.classe.cornell.edu/svn/trunk/util" : "55177", # Change from 55117
"https://accserv.classe.cornell.edu/svn/trunk/util" : "55221", # Change from 55177
"https://accserv.classe.cornell.edu/svn/trunk/build_system" : "54615",
}

Expand Down
19 changes: 17 additions & 2 deletions tao/code/tao_command.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ subroutine tao_command (command_line, err_flag, err_is_fatal)

type (tao_universe_struct), pointer :: u
type (lat_struct), pointer :: lat
type (tao_plot_struct), pointer :: plt

integer i, j, n, iu, ios, n_word, n_eq, stat
integer ix, ix_line, ix_cmd, which
Expand All @@ -57,7 +58,7 @@ subroutine tao_command (command_line, err_flag, err_is_fatal)
'output ']

logical quit_tao, err, err_is_fatal, silent, gang, abort, err_flag, ok
logical include_wall, update, exact, include_this, lord_set, listing
logical include_wall, update, exact, include_this, lord_set, listing, found

! blank line => nothing to do

Expand Down Expand Up @@ -831,8 +832,22 @@ subroutine tao_command (command_line, err_flag, err_is_fatal)
return
endif

if (s%global%plot_on) then
found = .false.
do i = 1, size(s%plot_page%region)
if (.not. s%plot_page%region(i)%visible) cycle
plt => s%plot_page%region(i)%plot
if (.not. allocated(plt%graph)) cycle
do j = 1, size(plt%graph)
if (plt%graph(j)%type == 'key_table') found = .true.
enddo
enddo
if (.not. found) call out_io(s_blank$, r_name, '[Note: Use the "place" command in line mode if you want to see the key_table.]')
endif

s%com%single_mode = .true.
call out_io (s_blank$, r_name, 'Entering Single Mode...')
call out_io (s_blank$, r_name, 'Entering Single Mode. Waiting for your input...')

return

!--------------------------------
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/09/18_23:06:36"
character(*), parameter :: tao_version_date = "2023/09/21_11:20:54"
end module
2 changes: 1 addition & 1 deletion util_programs/generalized_gradient_fit/DOC
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ are. The name of this file is given by the out_file parameter with a ".deriv_at_
attached. The data blocks in this file might look like:

# m = 3
# type = sin
# kind = sin
# Iz z_pos Deriv * r_max^(m+d-1) * (d+m) * m! / ((d/2)! * (d/2+m)!)
10 0.0200 3.07486025E-01 1.07290432E+00 -2.07656736E-01 -2.59055645E-01
11 0.0220 3.32020880E-01 9.37495727E-01 -3.12597302E-01 -2.10447354E-01
Expand Down
8 changes: 4 additions & 4 deletions util_programs/generalized_gradient_fit/gg_fit_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ subroutine write_gg_info()
write (1, *)
endif
write (1, '(a, i2)') '# m =', gg%m
write (1, '(2a)') '# type = ', sincos_name(gg%sincos)
write (1, '(2a)') '# kind = ', sincos_name(gg%sincos)
write (1, '(a, i2)') '# Iz z_pos Init_RMS RMS/RMS0 Derivs...'
write (1, '(a, i2)') '# Iz z_pos Derivs'

Expand Down Expand Up @@ -886,7 +886,7 @@ subroutine write_gg_info()
write (1, *)
endif
write (1, '(a, i2)') '# m =', gg%m
write (1, '(2a)') '# type = ', sincos_name(gg%sincos)
write (1, '(2a)') '# kind = ', sincos_name(gg%sincos)
write (1, '(a, i2)') '# Iz z_pos Deriv * r_max^(m+d-1) * (d+m) * m! / ((d/2)! * (d/2+m)!)'

do iz = iz_min, iz_max
Expand Down Expand Up @@ -916,7 +916,7 @@ subroutine write_gg_info()
write (1, *)
endif
write (1, '(a, i2)') '# m =', gg%m
write (1, '(2a)') '# type = ', sincos_name(gg%sincos)
write (1, '(2a)') '# kind = ', sincos_name(gg%sincos)
write (1, '(a, i2)') '# Iz z_pos Deriv - left_extrapolated_deriv'

do iz = iz_min+1, iz_max
Expand Down Expand Up @@ -948,7 +948,7 @@ subroutine write_gg_info()
write (1, *)
endif
write (1, '(a, i2)') '# m =', gg%m
write (1, '(2a)') '# type = ', sincos_name(gg%sincos)
write (1, '(2a)') '# kind = ', sincos_name(gg%sincos)
write (1, '(a, i2)') '# Iz z_pos Deriv - right_extrapolated_deriv'

do iz = iz_min, iz_max-1
Expand Down

0 comments on commit 9ace86b

Please sign in to comment.