Skip to content

Commit

Permalink
Merge pull request #852 from tpersson/impaverage
Browse files Browse the repository at this point in the history
Calculate average of all particles in tracking without writing it to file or table
  • Loading branch information
madcern committed Nov 8, 2019
2 parents f7ff0aa + 4e303c0 commit d326d0a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
6 changes: 4 additions & 2 deletions doc/latexuguide/thintrack.tex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ \section{Overview of Thin-Lens Tracking} % Module (thintrack)}
TRACK, \>DELTAP=real, ONEPASS=logical, DAMP=logical; \\
\>QUANTUM=logical, SEED=real, UPDATE=logical, \\
\>ONETABLE=logical, RECLOSS=logical, FILE=filename, \\
\>APERTURE=logical; \\
\>APERTURE=logical,ONLY\_AVERAGE=logical; \\
xxxx\=xxxxxxx\= \kill
\>\ldots \\
\>START, X=real, PX=real, Y=real, PY=real, T=real, PT=real; \\
Expand Down Expand Up @@ -131,7 +131,9 @@ \section{Overview of Thin-Lens Tracking} % Module (thintrack)}
Tracking creates a number of internal tables and can create files on disk:
\texttt{TRACKSUMM, TRACKLOSS}, and \texttt{TRACKONE} or
\texttt{TRACK.OBS\$\$\$\$.P\$\$\$\$} (depending on the attribute
\texttt{ONETABLE} of the \texttt{RUN} command).
\texttt{ONETABLE} of the \texttt{RUN} command)
\texttt{ONLY\_AVERAGE} when used with ONETABLE it will only output
the average of all the particles.

These internal tables can be accessed via the
\hyperref[chap:tables]{\texttt{TABLE}}-access functions.
Expand Down
1 change: 1 addition & 0 deletions src/mad_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ const char *const_command_def =
"recloss = [l, false, true], "
"keeptrack= [l, false, true], "
"file = [s, track, track], "
"only_average = [l, false, true], "
"extension= [s, none, none]; "
" "
"dynap: track track 0 0 "
Expand Down
2 changes: 2 additions & 0 deletions src/mad_track.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ track_track(struct in_cmd* cmd)
set_option("track_dump", &k);
k = get_value(current_command->name,"onetable");
set_option("onetable", &k);
k = get_value(current_command->name,"only_average");
set_option("only_average", &k);
track_deltap=get_value(current_command->name,"deltap");
set_variable("track_deltap", &track_deltap);
if(track_deltap != 0) fprintf(prt_file, v_format("track_deltap: %F\n"),
Expand Down
59 changes: 40 additions & 19 deletions src/trrun.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ subroutine trrun(switch, turns, orbit0, rt, part_id, last_turn, last_pos, &
double precision :: theta
double precision, dimension (:), allocatable :: theta_buf
logical :: onepass, onetable, last_out, info, aperflag, doupdate, debug
logical :: run=.false.,dynap=.false., thin_foc
logical :: run=.false.,dynap=.false., thin_foc, onlyaver
logical, save :: first=.true.
logical :: bb_sxy_update, virgin_state, emittance_update
logical :: checkpnt_restart, fast_error_func, exit_loss_turn
Expand Down Expand Up @@ -116,6 +116,7 @@ subroutine trrun(switch, turns, orbit0, rt, part_id, last_turn, last_pos, &
debug = get_option('debug ') .ne. 0
thin_foc = get_option('thin_foc ').eq.1

onlyaver = get_option('only_average ') .ne. 0
call init_elements()
!-------added by Yipeng SUN 01-12-2008--------------
if (deltap .eq. zero) then
Expand Down Expand Up @@ -273,7 +274,7 @@ subroutine trrun(switch, turns, orbit0, rt, part_id, last_turn, last_pos, &
if (first) then
call track_pteigen(eigen)
call tt_putone(jmax, tot_turn, tot_segm, segment, part_id, &
z, orbit0, spos, nlm, el_name)
z, orbit0, spos, nlm, el_name, onlyaver)
endif
else
do i = 1, jmax
Expand Down Expand Up @@ -581,7 +582,7 @@ subroutine trrun(switch, turns, orbit0, rt, part_id, last_turn, last_pos, &
spos = sum
call element_name(el_name,len(el_name))
call tt_putone(jmax, tot_turn+turn, tot_segm, segment, part_id, &
z, obs_orb,spos,nlm,el_name)
z, obs_orb,spos,nlm,el_name,onlyaver)
else
if (mod(turn, ffile) .eq. 0) then
do i = 1, jmax
Expand All @@ -603,7 +604,7 @@ subroutine trrun(switch, turns, orbit0, rt, part_id, last_turn, last_pos, &
spos=sum
call element_name(el_name,len(el_name))
call tt_putone(jmax, tot_turn+turn, tot_segm, segment, part_id, &
z, orbit0,spos,nlm,el_name)
z, orbit0,spos,nlm,el_name,onlyaver)
else
do i = 1, jmax
call tt_puttab(part_id(i), turn, 1, z(1,i), orbit0, spos)
Expand Down Expand Up @@ -669,7 +670,7 @@ subroutine trrun(switch, turns, orbit0, rt, part_id, last_turn, last_pos, &
spos = sum
call element_name(el_name,len(el_name))
call tt_putone(jmax, tot_turn+turn, tot_segm, segment, part_id, &
z, orbit0,spos,nlm,el_name)
z, orbit0,spos,nlm,el_name,onlyaver)
else
do i = 1, jmax
call tt_puttab(part_id(i), turn, 1, z(1,i), orbit0,spos)
Expand Down Expand Up @@ -2805,7 +2806,7 @@ subroutine tt_ploss(npart,turn,spos,orbit,el_name)
end subroutine tt_ploss

subroutine tt_putone(npart,turn,tot_segm,segment,part_id,z,orbit0,&
spos,ielem,el_name)
spos,ielem,el_name, onlyaver)
use name_lenfi
implicit none
!----------------------------------------------------------------------*
Expand All @@ -2824,8 +2825,9 @@ subroutine tt_putone(npart,turn,tot_segm,segment,part_id,z,orbit0,&
character(len=name_len) :: el_name

logical, save :: first = .true.
logical :: onlyaver
integer :: i, j, length
double precision :: tmp, tt, ss, spos
double precision :: tmp, tt, ss, spos, tmp_v(6)
character(len=120) :: table = 'trackone', comment
character(len=4) :: vec_names(7)
data vec_names / 'x', 'px', 'y', 'py', 't', 'pt','s' /
Expand All @@ -2835,19 +2837,38 @@ subroutine tt_putone(npart,turn,tot_segm,segment,part_id,z,orbit0,&

write(comment, '(''#segment'',4i8,1X,A)') segment, tot_segm, npart, ielem, el_name
if (first) call comment_to_table_curr(table, comment, length)
if(onlyaver) then
call double_to_table_curr(table, 'turn ', tt)
ss = -1.0
call double_to_table_curr(table, 'number ', ss)
do j = 1, 6
tmp = 0
do i = 1, npart
tmp = tmp + (z(j,i) - orbit0(j))
enddo
call double_to_table_curr(table, vec_names(j), tmp/npart)
enddo

call double_to_table_curr(table,vec_names(7),spos)
call augment_count(table)
else
tt = turn
do i = 1, npart
call double_to_table_curr(table, 'turn ', tt)
ss = part_id(i)
call double_to_table_curr(table, 'number ', ss)
do j = 1, 6
tmp = z(j,i) - orbit0(j)
call double_to_table_curr(table, vec_names(j), tmp)
enddo
call double_to_table_curr(table,vec_names(7),spos)
call augment_count(table)
enddo
endif




tt = turn
do i = 1, npart
call double_to_table_curr(table, 'turn ', tt)
ss = part_id(i)
call double_to_table_curr(table, 'number ', ss)
do j = 1, 6
tmp = z(j,i) - orbit0(j)
call double_to_table_curr(table, vec_names(j), tmp)
enddo
call double_to_table_curr(table,vec_names(7),spos)
call augment_count(table)
enddo
end subroutine tt_putone

subroutine tt_puttab(npart,turn,nobs,orbit,orbit0,spos)
Expand Down

0 comments on commit d326d0a

Please sign in to comment.