Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug correction ptc_track: disable stochastic during closed orbit search … #565

Merged
merged 3 commits into from Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 36 additions & 12 deletions doc/latexuguide/ptc-general.tex
Expand Up @@ -90,14 +90,25 @@ \section{PTC\_CREATE\_UNIVERSE}
sector bends defining up to which order Maxwell's equation are solved
(see \cite{forest2002}~page~76-77).
The value of \texttt{SECTOR\_NMUL\_MAX} must not be smaller than
\texttt{SECTOR\_NMUL} otherwise \madx stops with an error. \\ (Default:~10)
\texttt{SECTOR\_NMUL} otherwise \madx stops with an error.
If a negative value is passed than it is identified automatically
by scanning the currently selected sequence.
\\ (Default:~-1)

\ttitem{SECTOR\_NMUL} a global variable in PTC needed for exact
sector bends defining up to which order the multipole are included in
solving Maxwell's equation up to order \texttt{SECTOR\_NMUL\_MAX}.
Multipoles of order N with N $>$ \texttt{SECTOR\_NMUL} and N $\leq$
\texttt{SECTOR\_NMUL\_MAX} are treated similar to \textit{SixTrack}. \\
(Default:~10)
\texttt{SECTOR\_NMUL\_MAX} are treated similar to \textit{SixTrack}.
If a negative value of \\
\texttt{SECTOR\_NMUL\_MAX} is passed than it is also identified automatically.
However, if multipolar parameters of the bends are to be modified inside the PTC universe,
for example with \texttt{PTC\_READ\_ERRORS},
than this parameter needs to be set to a corresponding value.
Please note that using large values (above 10) slows down the computations,
so the smallest required value should be used.
\\
(Default:-1)

\ttitem{NTPSA} invokes the Differential Algebra (DA) package
written in C++ and kindly provided by Lingyun Yang (lyyang@lbl.gov). \\
Expand Down Expand Up @@ -221,24 +232,23 @@ \section{PTC\_SETSWITCH}

\madbox{
PTC\_SETSWITCH, \=DEBUGLEVEL=integer, \\
\>MAXACCELERATION=logical,\\
\>EXACT\_MIS=logical,\\
\>TOTALPATH=logical,\\
\>RADIATION=logical,\\
\>ENVELOPE=logical,\\
\>STOCHASTIC=logical,\\
\>MODULATION=logical,\\
\>FRINGE=logical,\\
\>TIME=logical;
\>TIME=logical,\\
\>SEED=integer,\\
\>MAXACCELERATION=logical;
}

The command parameters and switches are:
\begin{madlist}
\ttitem{DEBUGLEVEL} (Default: 1)\\
Sets the level of debugging printout: 0 prints none, 4 prints everything

\ttitem{MAXACCELERATION} (Default: true)\\
Switch to set cavities phases so the reference orbit is always on
the crest, i.e. gains max energy

\ttitem{EXACT\_MIS} (Default: false)\\
Switch ensures exact misalignment treatment.

Expand Down Expand Up @@ -279,7 +289,7 @@ \section{PTC\_SETSWITCH}
The emission is calculated during map tracking therefore
\texttt{PTC\_TWISS} or \texttt{PTC\_NORMAL}
needs to be invoked before launching the tracking
(also with \ttitem{RADIATION}, \ttitem{ENVELOPE} and \ttitem{STOCHASTIC} set to true).
(also with \texttt{RADIATION}, \texttt{ENVELOPE} and \texttt{STOCHASTIC} set to true).
Every tracked ray will receive the same stochastic kicks.

\ttitem{MODULATION} (Default: false)\\
Expand Down Expand Up @@ -318,14 +328,23 @@ \section{PTC\_SETSWITCH}

\textbf{Note:} at small energy ($\beta_0 << 1$),
momentum-dependent variables like dispersion will depend strongly on
the choice of the logical input variable \ttitem{TIME}. In fact, the
the choice of the logical input variable \texttt{TIME}. In fact, the
derivative ($\frac{\partial}{\partial \delta_p}$) and
($\frac{\partial}{\partial p_t}$) are different by the
factor $\beta_0$. One would therefore typically choose
the option \ttitem{TIME=false}, which sets the fifth variable to
the option \texttt{TIME=false}, which sets the fifth variable to
the relative momentum deviation $\delta_p$.


\ttitem{SEED} (Default: 123456789)\\
Sets the seed of PTC random number generator,
which is independent from the MADX generators.

\ttitem{MAXACCELERATION} (Default: true)\\
Switch to set cavities phases so the reference orbit is always on
the crest, i.e. gains max energy.


\end{madlist}

%% \textbf{PROGRAMMERS MANUAL}
Expand Down Expand Up @@ -382,6 +401,11 @@ \section{PTC\_READ\_ERRORS}
(Default:~false)
\end{madlist}

\textbf{Note:}\\
For calculations with exact flag set to true,
\texttt{SECTOR\_NMUL} parameter of \texttt{PTC\_CREATE\_UNIVERSE}
needs to be set to a value bigger than the highest order of an error in bending magnets.

\textbf{Note:}\\
Because of the way the table is read in memory, a warning will always be
issued by default in the form:
Expand Down
4 changes: 4 additions & 0 deletions doc/latexuguide/ptc-track.tex
Expand Up @@ -178,6 +178,7 @@ \section{PTC\_TRACK}
\>MAXAPER=real\_array, \\
\>NORM\_NO=integer, NORM\_OUT=logical, \\
\>FILE[=string], EXTENSION=string, FFILE=integer, \\
\>X=real, PX=real, Y=real, PY=real, T=real, PT=real, \\
\>RADIATION=logical, RADIATION\_MODEL1=logical, \\
\>RADIATION\_ENERGY\_LOSS=logical, \\
\>RADIATION\_QUAD=logical, \\
Expand Down Expand Up @@ -286,6 +287,9 @@ \section{PTC\_TRACK}
\ttitem{FFILE} defines the periodicity \texttt{n} of the printout:
coordinates are printed every n turns. \\ (Default: 1)

\ttitem{X, PX, Y, PY, T, PT} the initial
\hyperref[subsec:tables-canon]{canonical} coordinates for the closed orbit search. \\ (Default: 0.0) \\

\ttitem{RADIATION}\label{opt:radiation} a logical flag to turn on
the synchrotron radiation calculated by an internal procedure of
\ptc. \\
Expand Down
3 changes: 3 additions & 0 deletions src/mad_dict.c
Expand Up @@ -747,6 +747,9 @@ const char *const_command_def =
"ffile = [i, 1], "
"rootntuple = [l, false, true], "/*writes all the tracks in ROOT NTuple -> works only if program is dynamically linked and RPLOT plugin is present */
"maxaper= [r, {0.1, 0.01, 0.1, 0.01, 1., 0.1}], "
"x = [r, 0], px = [r, 0], " /*initial guess for closed orbit search*/
"y = [r, 0], py = [r, 0], "
"t = [r, 0], pt = [r, 0], "
"norm_out = [l, false, true], "
"norm_no = [i, 1]; "
" "
Expand Down
48 changes: 38 additions & 10 deletions src/madx_ptc_track_run.f90
Expand Up @@ -296,13 +296,18 @@ SUBROUTINE ptc_track_run(max_obs)
ENDIF warn_coordinate_system_changed

! initialize the closed orbit coordinates at START of the ring
x_coord_co(:)=zero
if (ptc_track_debug) then
print *, " x_coord_co(:)=zero = ",x_coord_co
endif

! Closed_orbit_at_START:
IF(closed_orbit) CALL Find_Closed_Orbit ! Calculates x_coord_co(1:6)
IF(closed_orbit) then
CALL Find_Closed_Orbit ! Calculates x_coord_co(1:6)

if ( .not. check_stable) then
write(whymsg,*) 'DA got unstable during closed orbit search: PTC msg: ',messagelost(:len_trim(messagelost))
call fort_warn('ptc_track: ',whymsg(:len_trim(whymsg)))
call seterrorflag(10,"ptc_track ",whymsg);
return
endif

endif

! needed to transfrom coordinates in case closed_orbit=true AND element_by_element=false
Normal_forms: IF(closed_orbit) THEN !-----------------------!
Expand Down Expand Up @@ -802,14 +807,21 @@ END SUBROUTINE Call_my_state_and_update_states
SUBROUTINE Find_Closed_Orbit
! USE madx_ptc_module, ONLY: dp, zero, find_orbit, my_ring,default
implicit none
logical isstochastic
!
!====================================================================!
! initialize the closed orbit coordinates !
! x0(:)=zero !
x_coord_co(:)=zero !

x_coord_co(1)=get_value('ptc_track ','x ')
x_coord_co(2)=get_value('ptc_track ','px ')
x_coord_co(3)=get_value('ptc_track ','y ')
x_coord_co(4)=get_value('ptc_track ','py ')
x_coord_co(6)=-get_value('ptc_track ','t ') ! swap of t sign
x_coord_co(5)=get_value('ptc_track ','pt ')

if (ptc_track_debug) THEN !---------------------------! !
print *, " x_coord_co(:)=zero = " ! !
CALL write_closed_orbit(nvariables,x_coord_co) ! !
print *, "Start point for closed orbit search: " ! !
CALL write_closed_orbit(nvariables,x_coord_co) ! !
end if !----------------------------------------------! !
! !
if(nvariables.ge.5) THEN !------------------------! !
Expand All @@ -825,17 +837,33 @@ SUBROUTINE Find_Closed_Orbit
print *, " if(icase.eq.5) ,x_coord_co(5)=deltap" ! !
print *, " ,x_coord_co(5),deltap=", & ! !
x_coord_co(5),deltap ! !
global_verbose = .true.
end if !--------------------------------------------! !
! !
if(closed_orbit) then !------------------------------------! !

! temporarly disbale stochastic, otherwise the search is doomed to fail
isstochastic = MYSTATE%stochastic
MYSTATE%stochastic = .false.

CALL FIND_ORBIT_x(my_ring,x_coord_co,MYSTATE,c_1d_7,fibre1=1) !
! call find_orbit(my_ring,x_coord_co,1,MYSTATE,c_1d_7) !

if ( .not. check_stable) then
! the routine which calls this function should also
! check the flag and report the eventual error
return
endif

MYSTATE%stochastic = isstochastic

print*,"===== ptc_track ============================" ! !
CALL write_closed_orbit(nvariables,x_coord_co) ! !
print*,"============================================" ! !
endif !---------------------------------------------------! !
! !
if (ptc_track_debug) then
global_verbose = .false.
print*,"After closed_orbit"; print *; !
endif !
! !
Expand Down