From cf2d8b4e46401c40e0742e7f68ef6dad8ecc5830 Mon Sep 17 00:00:00 2001 From: David Sagan Date: Wed, 10 Jul 2024 16:18:32 -0400 Subject: [PATCH 1/2] Fixed Tao `set particle_start` for photon energy --- tao/code/tao_change_mod.f90 | 2 +- tao/code/tao_interface.f90 | 3 ++- tao/code/tao_lattice_calc_mod.f90 | 10 +++++++++- tao/code/tao_set_flags_for_changed_attribute.f90 | 11 +++++++++-- tao/code/tao_set_mod.f90 | 2 +- tao/doc/command-list.tex | 8 ++++++++ tao/doc/cover-page.tex | 2 +- tao/version/tao_version_mod.f90 | 2 +- 8 files changed, 32 insertions(+), 8 deletions(-) diff --git a/tao/code/tao_change_mod.f90 b/tao/code/tao_change_mod.f90 index 316f7e9322..1a2155bf18 100644 --- a/tao/code/tao_change_mod.f90 +++ b/tao/code/tao_change_mod.f90 @@ -346,7 +346,7 @@ subroutine tao_change_ele (ele_name, attrib_name, num_str, update, err_flag) delta = m_ptr(i)%r - old_value(i) - call tao_set_flags_for_changed_attribute(u, e_name, eles(i)%ele, m_ptr(i)%r) + call tao_set_flags_for_changed_attribute(u, e_name, eles(i)%ele, m_ptr(i)%r, who = a_name) max_val = max(abs(old_value(i)), abs(m_ptr(i)%r), abs(d_ptr(1)%r)) str = real_num_fortran_format(max_val, 14, 2) diff --git a/tao/code/tao_interface.f90 b/tao/code/tao_interface.f90 index b11d21dcc1..70d3ca39d9 100644 --- a/tao/code/tao_interface.f90 +++ b/tao/code/tao_interface.f90 @@ -704,13 +704,14 @@ subroutine tao_set_data_useit_opt (data) type (tao_data_struct), optional :: data(:) end subroutine -subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr) +subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr, who) import implicit none type (tao_universe_struct), target :: u type (ele_struct), pointer, optional :: ele_ptr real(rp), pointer, optional :: val_ptr character(*) ele_name + character(*), optional :: who end subroutine subroutine tao_set_var_model_value (var, value, print_limit_warning) diff --git a/tao/code/tao_lattice_calc_mod.f90 b/tao/code/tao_lattice_calc_mod.f90 index 6b1b4f569a..f22e1a226c 100644 --- a/tao/code/tao_lattice_calc_mod.f90 +++ b/tao/code/tao_lattice_calc_mod.f90 @@ -749,6 +749,7 @@ subroutine tao_inject_particle (u, model, ix_branch) type (coord_struct), pointer :: orb_out, orb_in type (branch_struct), pointer :: branch, branch_from +real(rp) e_photon integer ix_branch, i_ele_from, i_br_from character(*), parameter :: r_name = "tao_inject_particle" @@ -798,7 +799,14 @@ subroutine tao_inject_particle (u, model, ix_branch) orb_in => branch%lat%particle_start endif -call init_coord (orb_out, orb_in, branch%ele(0), downstream_end$, default_tracking_species(branch%param), 1, orb_in%p0c) +e_photon = 0 +if (branch%ele(0)%ref_species == photon$) then + e_photon = branch%ele(0)%value(p0c$) * (1.0_rp + orb_in%vec(6)) + if (orb_in%p0c /= 0) e_photon = orb_in%p0c +endif + +call init_coord (orb_out, orb_in, branch%ele(0), downstream_end$, & + default_tracking_species(branch%param), 1, e_photon = e_photon) end subroutine tao_inject_particle diff --git a/tao/code/tao_set_flags_for_changed_attribute.f90 b/tao/code/tao_set_flags_for_changed_attribute.f90 index 18aaeb3467..408b237876 100644 --- a/tao/code/tao_set_flags_for_changed_attribute.f90 +++ b/tao/code/tao_set_flags_for_changed_attribute.f90 @@ -1,5 +1,5 @@ !+ -! Subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr) +! Subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr, who) ! ! Routine to set flags in the model lattice indicating that a parameter value has changed. ! Call this routine *after* setting the variable. @@ -10,9 +10,10 @@ ! ele_ptr -- ele_struct, pointer, optional: Pointer to the element. ! May be null, for example, if ele_name = "PARTICLE_START". ! val_ptr -- real(rp):, pointer, optional: Pointer to the attribute that was changed. +! who -- character(*), optional: Name of changed attribute. Only used with PARTICLE_START. !- -subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr) +subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr, who) use tao_interface, dummy => tao_set_flags_for_changed_attribute use bookkeeper_mod, only: set_flags_for_changed_attribute @@ -28,6 +29,7 @@ subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr) logical err character(*) ele_name +character(*), optional :: who ! If the beginning element is modified, need to reinit any beam distribution. @@ -38,6 +40,11 @@ subroutine tao_set_flags_for_changed_attribute (u, ele_name, ele_ptr, val_ptr) if (lat%branch(0)%param%geometry == closed$) then u%model%tao_branch(0)%orb0%vec(6) = lat%particle_start%vec(6) endif + ! For photon bookkeeping + select case (who) + case ('PZ'); lat%particle_start%p0c = 0 + case ('E_PHOTON'); lat%particle_start%vec(6) = 0 + end select return endif diff --git a/tao/code/tao_set_mod.f90 b/tao/code/tao_set_mod.f90 index 5f9a9cd49f..b0ebd76287 100644 --- a/tao/code/tao_set_mod.f90 +++ b/tao/code/tao_set_mod.f90 @@ -1348,7 +1348,7 @@ subroutine tao_set_particle_start_cmd (who, value_str) a_ptr(1)%r = set_val(1) endif - call tao_set_flags_for_changed_attribute (u, 'PARTICLE_START') + call tao_set_flags_for_changed_attribute (u, 'PARTICLE_START', who = who2) enddo end subroutine tao_set_particle_start_cmd diff --git a/tao/doc/command-list.tex b/tao/doc/command-list.tex index 9e0e6cf661..589908335b 100644 --- a/tao/doc/command-list.tex +++ b/tao/doc/command-list.tex @@ -1521,12 +1521,20 @@ \subsection{set particle_start} For photons, \vn{} may also be: \begin{example} field_x, field_y, phase_x, phase_y + e_photon \end{example} The \vn{*} coordinate denotes the phase space vector $(x, p_x, y, p_y, z, p_z)$. For closed lattices only the \vn{pz} parameter is applicable. For lattices that have an \vn{e_gun} (which necessarily implies that the lattice has an open geometry), the time \vn{t} coordinate must be varied instead of \vn{pz}. +For photons, the photon energy can be set by setting \vn{e_photon} which sets the photon energy in +eV or by setting \vn{pz} which sets the relative difference between the photon energy and the +reference energy: +\begin{example} + photon_energy = reference_energy * (1 + pz) +\end{example} + To see the values for \vn{particle_start} use the command \vn{show element 0}. Also see the commands: \vn{set beam} (\sref{s:set.beam}), \vn{set beam_init} (\sref{s:set.beam.init}), diff --git a/tao/doc/cover-page.tex b/tao/doc/cover-page.tex index 5ee535a859..fa3f7eac9e 100644 --- a/tao/doc/cover-page.tex +++ b/tao/doc/cover-page.tex @@ -2,7 +2,7 @@ \begin{flushright} \large -Revision: June 28, 2024 \\ +Revision: July 10, 2024 \\ \end{flushright} \vfill diff --git a/tao/version/tao_version_mod.f90 b/tao/version/tao_version_mod.f90 index 1fa62973b8..0b4f8cb73e 100644 --- a/tao/version/tao_version_mod.f90 +++ b/tao/version/tao_version_mod.f90 @@ -6,5 +6,5 @@ !- module tao_version_mod -character(*), parameter :: tao_version_date = "2024/07/08 18:14:10" +character(*), parameter :: tao_version_date = "2024/07/10 02:33:58" end module From 19302009077ca3a8b82ab121294dfa2a964b78b3 Mon Sep 17 00:00:00 2001 From: David Sagan Date: Thu, 11 Jul 2024 22:32:03 -0400 Subject: [PATCH 2/2] Doc devel. --- bmad/doc/cover-page.tex | 2 +- bmad/doc/elements.tex | 2 +- bmad/doc/synchrotron-radiation.tex | 4 ++-- regression_tests/nonlin_test/small_ring.bmad | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bmad/doc/cover-page.tex b/bmad/doc/cover-page.tex index 276100828a..cb2d88b02f 100644 --- a/bmad/doc/cover-page.tex +++ b/bmad/doc/cover-page.tex @@ -3,7 +3,7 @@ \begin{flushright} \large - Revision: July 7, 2024 \\ + Revision: July 10, 2024 \\ \end{flushright} \pdfbookmark[0]{Preamble}{Preamble} diff --git a/bmad/doc/elements.tex b/bmad/doc/elements.tex index 8864443d22..54da59077f 100644 --- a/bmad/doc/elements.tex +++ b/bmad/doc/elements.tex @@ -1266,7 +1266,7 @@ \section{Crystal} \index{follow_diffracted_beam}\index{thickness} Attributes specific to a \vn{crystal} element are: \begin{example} - b_param = ! b parameter + b_param = ! b parameter for photons with the reference energy. crystal_type = ! Crystal material (\sref{s:cryst.list}) and reflection plane. psi_angle = ! Rotation of H-vector about the surface normal. thickness = ! Thickness of crystal for Laue diffraction. diff --git a/bmad/doc/synchrotron-radiation.tex b/bmad/doc/synchrotron-radiation.tex index 933ec7ca60..0c4b74fe1b 100644 --- a/bmad/doc/synchrotron-radiation.tex +++ b/bmad/doc/synchrotron-radiation.tex @@ -247,9 +247,9 @@ \section{Synchrotron Radiation Integrals} \label{s:synch.ints} \index{synchrotron radiation!integrals} -the synchrotron radiation integrals can be used to compute emittances, the energy spread, +The synchrotron radiation integrals can be used to compute emittances, the energy spread, etc. However, using the 6D damped and stochastic transport matrices (\sref{s:map.rad}) has -a number of advantages +a number of advantages: \begin{itemize} % \item diff --git a/regression_tests/nonlin_test/small_ring.bmad b/regression_tests/nonlin_test/small_ring.bmad index 8bb24d6fd6..2f3e3ab54e 100644 --- a/regression_tests/nonlin_test/small_ring.bmad +++ b/regression_tests/nonlin_test/small_ring.bmad @@ -1,6 +1,7 @@ parameter[p0c] = 1e9 bmad_com[radiation_damping_on] = f bmad_com[radiation_fluctuations_on] = f +bmad_com[spin_tracking_on] = T q1: quad, l = 0.5, k1 = 0.6, tilt = 0.05 q2: quad, l = 0.5, k1 = -0.5