Skip to content

Commit

Permalink
Fixed Tao set particle_start for photon energy (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Jul 10, 2024
1 parent d318243 commit c61f448
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tao/code/tao_change_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tao/code/tao_interface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion tao/code/tao_lattice_calc_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions tao/code/tao_set_flags_for_changed_attribute.f90
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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.

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tao/code/tao_set_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tao/doc/command-list.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1521,12 +1521,20 @@ \subsection{set particle_start}
For photons, \vn{<coordinate>} 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}),
Expand Down
2 changes: 1 addition & 1 deletion tao/doc/cover-page.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

\begin{flushright}
\large
Revision: June 28, 2024 \\
Revision: July 10, 2024 \\
\end{flushright}

\vfill
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 = "2024/07/08 18:14:10"
character(*), parameter :: tao_version_date = "2024/07/10 02:33:58"
end module

0 comments on commit c61f448

Please sign in to comment.