From 4ff46b7a1b449fb16e35b626b49bae3b09910bc2 Mon Sep 17 00:00:00 2001 From: David Sagan Date: Wed, 4 Oct 2023 23:32:25 -0400 Subject: [PATCH 1/2] Added kz = 0 warning to ele_to_fibre. --- bmad/doc/attributes.tex | 6 +++++- bmad/ptc/ele_to_fibre.f90 | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bmad/doc/attributes.tex b/bmad/doc/attributes.tex index b10aeef334..d1189eb0c7 100644 --- a/bmad/doc/attributes.tex +++ b/bmad/doc/attributes.tex @@ -2335,7 +2335,7 @@ \subsection{Cartesian_Map Field Map} map types. To use with PTC dependent tracking methods (\sref{s:integ}) there are a number of restrictions: - \begin{itemize} +\begin{itemize} % \item There can be only one \vn{cartesian_map} field map and there cannot be any other field maps of any @@ -2349,6 +2349,10 @@ \subsection{Cartesian_Map Field Map} % \item The transverse terms in \vn{r0} must be zero. +% +\item +Since PTC evaluates the vector potential (\sref{s:wiggler.std}), and since \vn{k_z} appears in the +denominator of some terms, \vn{k_z} must be non-negative for all terms. \end{itemize} %----------------------------------------------------------------- diff --git a/bmad/ptc/ele_to_fibre.f90 b/bmad/ptc/ele_to_fibre.f90 index bdcc7b94a8..07ae5d8e88 100644 --- a/bmad/ptc/ele_to_fibre.f90 +++ b/bmad/ptc/ele_to_fibre.f90 @@ -904,8 +904,7 @@ subroutine ele_to_fibre (ele, ptc_fibre, param, use_offsets, err_flag, integ_ord is_planar_wiggler = ((key == wiggler$ .or. key == undulator$) .and. ele2%field_calc == planar_model$) if (associated(ele2%grid_field)) then - call out_io (s_fatal$, r_name, 'PTC TRACKING IS NOT ABLE TO USE GRID_FIELDS. FOR ELEMENT: ' // ele%name) - if (global_com%exit_on_error) call err_exit + call out_io (s_error$, r_name, 'PTC TRACKING IS NOT ABLE TO USE GRID_FIELDS. FOR ELEMENT: ' // ele%name) return endif @@ -914,18 +913,22 @@ subroutine ele_to_fibre (ele, ptc_fibre, param, use_offsets, err_flag, integ_ord allocate(cm) call create_wiggler_cartesian_map(ele2, cm) else - call out_io (s_fatal$, r_name, 'NOT ABLE TO DO PTC TRACKING FOR NON-PLANAR WIGGLER WITHOUT A CARTESIAN (OR OTHER TYPE OF) MAP.', & + call out_io (s_error$, r_name, 'NOT ABLE TO DO PTC TRACKING FOR NON-PLANAR WIGGLER WITHOUT A CARTESIAN (OR OTHER TYPE OF) MAP.', & 'FOR ELEMENT: ' // ele%name) - if (global_com%exit_on_error) call err_exit return endif else cm => ele2%cartesian_map(1) endif + if (any(abs(cm%ptr%term%kz) < 1e-100_rp)) then + call out_io (s_error$, r_name, 'CARTESIAN MAP KZ VALUES MUST BE NON-ZERO (MAKE > 1E-100).', & + 'FOR ELEMENT: ' // ele%name) + return + endif + if (cm%field_type == electric$) then call out_io (s_fatal$, r_name, 'PTC IS NOT ABLE TO HANDLE CARTESIAN_MAP WITH ELECTRIC FIELDS. FOR ELEMENT: ' // ele%name) - if (global_com%exit_on_error) call err_exit return endif From 95a0eed4df4db6977b48487a78008fabfd4105eb Mon Sep 17 00:00:00 2001 From: David Sagan Date: Thu, 5 Oct 2023 02:03:56 -0400 Subject: [PATCH 2/2] Fix bookkeeping bug introduced about 1.5 years ago. --- tao/code/tao_spin_polarization_calc.f90 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tao/code/tao_spin_polarization_calc.f90 b/tao/code/tao_spin_polarization_calc.f90 index dd08604979..c95774371b 100644 --- a/tao/code/tao_spin_polarization_calc.f90 +++ b/tao/code/tao_spin_polarization_calc.f90 @@ -87,12 +87,13 @@ subroutine tao_spin_polarization_calc (branch, tao_branch, excite_zero, ignore_k if (branch%param%geometry == closed$) then tao_branch%spin%tune = 2.0_rp * atan2(norm2(q_1turn%spin_q(1:3,0)), q_1turn%spin_q(0,0)) n0 = 0 + s_vec = [0.0_rp, 0.0_rp, 1.0_rp] dn_dpz = 0 partial = 0 partial2 = 0 - else n0 = branch%lat%particle_start%spin + s_vec = [0.0_rp, 0.0_rp, 1.0_rp] dn_dpz = branch%ele(0)%value(spin_dn_dpz_x$:spin_dn_dpz_z$) partial = 0 ! Not sure this is computable. partial2 = 0 @@ -110,6 +111,7 @@ subroutine tao_spin_polarization_calc (branch, tao_branch, excite_zero, ignore_k old_n0 = n0 old_partial = partial old_partial2 = partial2 + old_s_vec = s_vec ele => branch%ele(ie)