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 2290543ff21e2b0f7cf1328a9c59bd92bb50d92d Mon Sep 17 00:00:00 2001 From: David Sagan Date: Sun, 14 Jul 2024 14:17:15 -0400 Subject: [PATCH 2/2] Fix Tao python `plot_lat_layout` and `floor_plan` output. --- tao/code/tao_init_data_mod.f90 | 3 --- tao/code/tao_python_cmd.f90 | 31 ++++++++++++++++++++++++++----- tao/code/tao_struct.f90 | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/tao/code/tao_init_data_mod.f90 b/tao/code/tao_init_data_mod.f90 index 0320b7c50a..ae3ac0312a 100644 --- a/tao/code/tao_init_data_mod.f90 +++ b/tao/code/tao_init_data_mod.f90 @@ -611,9 +611,6 @@ subroutine d1_data_stuffit (i_d1, u, n_d2, datum, default_merit_type, & if (tao_rad_int_calc_needed(dat%data_type, dat%data_source)) then u%calc%rad_int_for_data = .true. - if (dat%ix_branch /= 0) then - call out_io (s_error$, r_name, 'EVALUATING A DATUM OF TYPE: ' // dat%data_type, 'ON A BRANCH NOT YET IMPLEMENTED!') - endif endif if (tao_lat_sigma_calc_needed(dat%data_type, dat%data_source)) u%calc%lat_sigma_for_data = .true. diff --git a/tao/code/tao_python_cmd.f90 b/tao/code/tao_python_cmd.f90 index 552878f104..87b1280fb3 100644 --- a/tao/code/tao_python_cmd.f90 +++ b/tao/code/tao_python_cmd.f90 @@ -107,7 +107,7 @@ subroutine tao_python_cmd (input_str) type (bunch_track_struct), pointer :: bunch_params_comb(:) type (bunch_track_struct), pointer :: comb1 type (ele_pointer_struct), allocatable :: eles(:), eles2(:) -type (branch_struct), pointer :: branch +type (branch_struct), pointer :: branch, branch2 type (tao_model_branch_struct), pointer :: model_branch type (random_state_struct) ran_state type (ele_attribute_struct) attrib @@ -4256,7 +4256,7 @@ subroutine tao_python_cmd (input_str) case ('floor_plan') - call tao_find_plots (err, line, 'BOTH', graph = graphs, only_visible = .false.) + call tao_find_plots (err, line, 'BOTH', graph = graphs, blank_means_all = .true., only_visible = .false.) if (err .or. size(graphs) /= 1) then call invalid ('Bad graph name') @@ -5616,7 +5616,8 @@ subroutine tao_python_cmd (input_str) u => point_to_uni(line, .true., err); if (err) return ix_branch = parse_branch(line, u, .false., err); if (err) return - branch => u%model%lat%branch(ix_branch) + lat => u%model%lat + branch => lat%branch(ix_branch) do i = 1, branch%n_ele_track ele => branch%ele(i) @@ -5625,12 +5626,32 @@ subroutine tao_python_cmd (input_str) ix_shape_min = 1 do call tao_ele_shape_info (u%ix_uni, ele, s%plot_page%lat_layout%ele_shape, shape, label_name, y1, y2, ix_shape_min) + if (.not. associated(shape)) exit + if (.not. shape%draw) cycle y1 = y1 * s%plot_page%lat_layout_shape_scale y2 = y2 * s%plot_page%lat_layout_shape_scale + nl=incr(nl); write (li(nl), '(2(i0, a), 2(es22.14, a), (i0, a), 2a, 2(es10.2, a), 4a)') ele%ix_branch, ';', ele%ix_ele, & + ';', ele%s_start, ';', ele%s, ';', shape%line_width, ';', trim(shape%shape), ';', & + y1, ';', y2, ';', trim(shape%color), ';', trim(label_name) + enddo + enddo + + do i = lat%n_ele_track+1, lat%n_ele_max + ele => lat%ele(i) + if (ele%lord_status == multipass_lord$) cycle + branch2 => pointer_to_branch(ele) + if (branch2%ix_branch /= branch%ix_branch) cycle + + ix_shape_min = 1 + do + call tao_ele_shape_info (u%ix_uni, ele, s%plot_page%lat_layout%ele_shape, shape, label_name, y1, y2, ix_shape_min) if (.not. associated(shape)) exit if (.not. shape%draw) cycle - nl=incr(nl); write (li(nl), '(i0, 2(a, es22.14), (a, i0), 2a, 2(a, es10.2), 4a)') i, ';', ele%s_start, ';', ele%s, ';', & - shape%line_width, ';', trim(shape%shape), ';', y1, ';', y2, ';', trim(shape%color), ';', trim(label_name) + y1 = y1 * s%plot_page%lat_layout_shape_scale + y2 = y2 * s%plot_page%lat_layout_shape_scale + nl=incr(nl); write (li(nl), '(2(i0, a), 2(es22.14, a), (i0, a), 2a, 2(es10.2, a), 4a)') ele%ix_branch, ';', ele%ix_ele, & + ';', ele%s_start, ';', ele%s, ';', shape%line_width, ';', trim(shape%shape), ';', & + y1, ';', y2, ';', trim(shape%color), ';', trim(label_name) enddo enddo diff --git a/tao/code/tao_struct.f90 b/tao/code/tao_struct.f90 index f0b10c1cb8..44850fcca6 100644 --- a/tao/code/tao_struct.f90 +++ b/tao/code/tao_struct.f90 @@ -1008,8 +1008,8 @@ module tao_struct ! Keep data and plotting separate since when optimizing will only do a calc if the data needs it type tao_universe_calc_struct - logical :: rad_int_for_data = .false. ! Do the radiation integrals need to be computed for integer :: srdt_for_data = 0 ! 0 = false, 1 = 1st order, 2 = 1st & 2nd order + logical :: rad_int_for_data = .false. ! Do the radiation integrals need to be computed for logical :: rad_int_for_plotting = .false. ! data or plotting? logical :: chrom_for_data = .false. ! Does the chromaticity need to be computed for logical :: chrom_for_plotting = .false. ! data or plotting?