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 2512a36fe89433aeb9eb858edee2727dc0e194ef Mon Sep 17 00:00:00 2001 From: David Sagan Date: Sun, 14 Jul 2024 22:02:40 -0400 Subject: [PATCH 2/2] Fix Tao `python floor_plan` command. --- tao/code/tao_plot_mod.f90 | 31 +++++++++++-- tao/code/tao_python_cmd.f90 | 90 ++++++++++++++++--------------------- tao/code/tao_struct.f90 | 6 +++ 3 files changed, 73 insertions(+), 54 deletions(-) diff --git a/tao/code/tao_plot_mod.f90 b/tao/code/tao_plot_mod.f90 index 8bef5387ef..586b507ad6 100644 --- a/tao/code/tao_plot_mod.f90 +++ b/tao/code/tao_plot_mod.f90 @@ -434,13 +434,15 @@ subroutine tao_draw_floor_plan (plot, graph) ! Draw for a particular universe +if (allocated(graph%floor_list)) deallocate(graph%floor_list) + if (graph%ix_universe == -2) then do isu = 1, size(s%u) - call draw_this_floor_plan(isu) + call draw_this_floor_plan(isu, plot, graph) enddo else isu = tao_universe_index(graph%ix_universe) - call draw_this_floor_plan(isu) + call draw_this_floor_plan(isu, plot, graph) endif ! Hook routine for more plotting if desired... @@ -452,8 +454,10 @@ subroutine tao_draw_floor_plan (plot, graph) !------------------------------------------------------------- contains -subroutine draw_this_floor_plan(isu) +subroutine draw_this_floor_plan(isu, plot, graph) +type (tao_plot_struct) :: plot +type (tao_graph_struct) :: graph type (tao_ele_shape_struct), pointer :: ele_shape, ele_shape2 type (tao_lattice_struct), pointer :: tao_lat type (tao_building_wall_point_struct) pt0, pt1 @@ -661,6 +665,7 @@ recursive subroutine tao_draw_ele_for_floor_plan (plot, graph, tao_lat, ele, ele type (coord_struct), pointer :: orbit(:) type (coord_struct) orb_here, orb_start, orb_end type (tao_shape_pattern_struct), pointer :: pat +type (tao_floor_plan_ele), allocatable :: floor_ele(:) integer, parameter :: n_bend_extra = 40, l1 = -n_bend_extra, l2 = 200 + n_bend_extra integer i, j, k, n_bend, n, ix, ic, n_mid, min1_bend, min2_bend, max1_bend, max2_bend @@ -693,6 +698,26 @@ recursive subroutine tao_draw_ele_for_floor_plan (plot, graph, tao_lat, ele, ele call find_element_ends (ele, ele1, ele2) if (.not. associated(ele1)) return +if (.not. allocated(graph%floor_list)) then + allocate(graph%floor_list(1)) + n = 1 +else + n = size(graph%floor_list) + 1 + call move_alloc(graph%floor_list, floor_ele) + allocate(graph%floor_list(n)) + graph%floor_list(:n-1) = floor_ele +endif + +graph%floor_list(n)%ele_loc = ele_loc(ele) + +if (associated(ele_shape)) then + graph%floor_list(n)%shape = ele_shape +else + graph%floor_list(n)%shape%shape = null_name$ +endif + +! + orbit => tao_lat%tao_branch(ele1%ix_branch)%orbit orb_start = orbit(ele1%ix_ele) diff --git a/tao/code/tao_python_cmd.f90 b/tao/code/tao_python_cmd.f90 index 87b1280fb3..b565590f50 100644 --- a/tao/code/tao_python_cmd.f90 +++ b/tao/code/tao_python_cmd.f90 @@ -139,6 +139,7 @@ subroutine tao_python_cmd (input_str) type (tao_ele_shape_struct), pointer :: shapes(:) type (tao_ele_shape_struct), allocatable :: shapes_temp(:) type (tao_ele_shape_struct), pointer :: shape +type (tao_ele_shape_struct) :: ashape type (tao_ele_shape_input) shape_input type (photon_element_struct), pointer :: ph type (qp_axis_struct) x_ax, y_ax @@ -4267,57 +4268,44 @@ subroutine tao_python_cmd (input_str) u => tao_pointer_to_universe(g%ix_universe, .true.) lat => u%model%lat - do ib = 0, ubound(lat%branch, 1) - branch => lat%branch(ib) - do i = 1, branch%n_ele_max - ele => branch%ele(i) - if (ele%slave_status == super_slave$) cycle - if (ele%lord_status == multipass_lord$) cycle - if (ele%key == overlay$) cycle - if (ele%key == group$) cycle - if (ele%key == girder$) cycle - - ix_shape_min = 1 - first_time = .true. - do - call tao_ele_shape_info (g%ix_universe, ele, s%plot_page%lat_layout%ele_shape, shape, label_name, y1, y2, ix_shape_min) - if (associated(shape)) then - color = shape%color - shape_shape = shape%shape - line_width = shape%line_width - else - if (.not. first_time) exit - y1 = 0 - y2 = 0 - color = '' - label_name = '' - shape_shape = '' - line_width = 0 - endif - first_time = .false. - - call find_element_ends(ele, ele1, ele2) - floor%r = [0.0_rp, 0.0_rp, 0.0_rp] - floor1 = coords_local_curvilinear_to_floor (floor, ele, .true.) - - floor%r = [0.0_rp, 0.0_rp, ele%value(l$)] - floor2 = coords_local_curvilinear_to_floor (floor, ele, .true.) - call tao_floor_to_screen_coords (g, floor1, end1) - call tao_floor_to_screen_coords (g, floor2, end2) - if (ele%key == sbend$) then - nl=incr(nl); write (li(nl), '(2(i0, a), 2a, 6(es14.7, a), (i0, a), 2a, 2(es10.2, a), 4a, 4(es14.7, a))') ib, ';', i, ';', & - trim(key_name(ele%key)), ';', end1%r(1), ';', end1%r(2), ';', end1%theta, ';', & - end2%r(1), ';', end2%r(2), ';', end2%theta, ';', & - line_width, ';', trim(shape_shape), ';', y1, ';', y2, ';', trim(color), ';', trim(label_name), ';', & - ele%value(l$), ';', ele%value(angle$), ';', ele%value(e1$), ';', ele%value(e2$) - else - nl=incr(nl); write (li(nl), '(2(i0, a), 2a, 6(es14.7, a), (i0, a), 2a, 2(es10.2, a), 4a)') ib, ';', i, ';', & - trim(key_name(ele%key)), ';', end1%r(1), ';', end1%r(2), ';', end1%theta, ';', & - end2%r(1), ';', end2%r(2), ';', end2%theta, ';', & - line_width, ';', trim(shape_shape), ';', y1, ';', y2, ';', trim(color), ';', trim(label_name) - endif - enddo - enddo + do i = 1, size(g%floor_list) + ele => pointer_to_ele(lat, g%floor_list(i)%ele_loc) + ashape = g%floor_list(i)%shape + if (ashape%shape == null_name$) then + y1 = 0 + y2 = 0 + color = '' + label_name = '' + shape_shape = '' + line_width = 0 + else + color = ashape%color + shape_shape = ashape%shape + line_width = ashape%line_width + endif + + call find_element_ends(ele, ele1, ele2) + floor%r = [0.0_rp, 0.0_rp, 0.0_rp] + floor1 = coords_local_curvilinear_to_floor (floor, ele, .true.) + + floor%r = [0.0_rp, 0.0_rp, ele%value(l$)] + floor2 = coords_local_curvilinear_to_floor (floor, ele, .true.) + call tao_floor_to_screen_coords (g, floor1, end1) + call tao_floor_to_screen_coords (g, floor2, end2) + if (ele%key == sbend$) then + nl=incr(nl); write (li(nl), '(2(i0, a), 2a, 6(es14.7, a), (i0, a), 2a, 2(es10.2, a), 4a, 4(es14.7, a))') & + ele%ix_branch, ';', ele%ix_ele, ';', & + trim(key_name(ele%key)), ';', end1%r(1), ';', end1%r(2), ';', end1%theta, ';', & + end2%r(1), ';', end2%r(2), ';', end2%theta, ';', & + line_width, ';', trim(shape_shape), ';', y1, ';', y2, ';', trim(color), ';', trim(label_name), ';', & + ele%value(l$), ';', ele%value(angle$), ';', ele%value(e1$), ';', ele%value(e2$) + else + nl=incr(nl); write (li(nl), '(2(i0, a), 2a, 6(es14.7, a), (i0, a), 2a, 2(es10.2, a), 4a)') & + ele%ix_branch, ';', ele%ix_ele, ';', & + trim(key_name(ele%key)), ';', end1%r(1), ';', end1%r(2), ';', end1%theta, ';', & + end2%r(1), ';', end2%r(2), ';', end2%theta, ';', & + line_width, ';', trim(shape_shape), ';', y1, ';', y2, ';', trim(color), ';', trim(label_name) + endif enddo !------------------------------------------------------------------------------------------------ diff --git a/tao/code/tao_struct.f90 b/tao/code/tao_struct.f90 index 44850fcca6..11ae4a083c 100644 --- a/tao/code/tao_struct.f90 +++ b/tao/code/tao_struct.f90 @@ -230,6 +230,11 @@ module tao_struct ! This is used with floor_plan drawings. +type tao_floor_plan_ele + type (lat_ele_loc_struct) :: ele_loc + type (tao_ele_shape_struct) :: shape +end type + type tao_floor_plan_struct character(2) :: view = 'zx' ! or 'xz'. real(rp) :: rotation = 0 ! Rotation of floor plan plot: 1.0 -> 360^deg @@ -260,6 +265,7 @@ module tao_struct type (tao_curve_struct), allocatable :: curve(:) type (tao_plot_struct), pointer :: p => null() ! pointer to parent plot type (tao_floor_plan_struct) :: floor_plan = tao_floor_plan_struct() + type (tao_floor_plan_ele), allocatable :: floor_list(:) ! Store what is drawn. Used by "python floor_plan" command. type (qp_point_struct) :: text_legend_origin = qp_point_struct() type (qp_point_struct) :: curve_legend_origin = qp_point_struct() type (qp_axis_struct) :: x = qp_axis_struct() ! X-axis parameters.