From c61f448bec02b451079ac5176a1e9665ce785980 Mon Sep 17 00:00:00 2001 From: David Sagan Date: Wed, 10 Jul 2024 16:37:57 -0400 Subject: [PATCH] Fixed Tao `set particle_start` for photon energy (#1052) --- 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