Home > attrack > linepass.m

linepass

PURPOSE ^

LINEPASS tracks particles through each element of the cell array LINE

SYNOPSIS ^

function [Rout,varargout] = linepass(line,Rin,refpts,varargin)

DESCRIPTION ^

LINEPASS tracks particles through each element of the cell array LINE
 calling the element-specific tracking function specified in the
 LINE{i}.PassMethod field.

 ROUT=LINEPASS(LINE,RIN) tracks particle(s) with initial
    condition(s) RIN for NTURNS turns to the end of the LINE

   LINE        AT lattice
   RIN         6xN matrix: input coordinates of N particles

   ROUT        6xN matrix: output coordinates of N particles at
               the end of LINE

 ROUT=LINEPASS(LINE,RIN,REFPTS) also returns intermediate results
     at the entrance of each element specified in the REFPTS

    REFPTS is an array of increasing indexes that selects elements
     between 1 and length(LINE)+1.
     See further explanation of REFPTS in the 'help' for FINDSPOS
   ROUT        6x(N*length(REFPTS)) matrix: output coordinates of N particles at
               each reference point

     NOTE:
     LINEPASS(LINE,RIN,length(LINE)+1) is the same as LINEPASS(LINE,RIN)
     since the reference point length(LINE)+1 is the exit of the last element
     LINEPASS(LINE,RIN,1) is a copy of RIN since the
     reference point 1 is the entrance of the first element

 [ROUT, LOST]=LINEPASS(...)
  Return additionally an information on lost particles
    LOST    1xN logical vector, indicating lost particles
    If only one output is given, loss information is saved in
    global variable LOSSFLAG

 [ROUT, LOSS, LOSSINFO]=LINEPASS(...,'nhist',NHIST,...)
  Return additional information on lost particles
   NHIST       number elements before the loss to be traced (default: 1)
   LOSSINFO    1x1 structure with the following fields:
               lost                 1xN logical vector, indicating lost particles
               turn                 1xN vector, turn number where the particle is lost
               element              1xN vector, element number where the particle is lost
               coordinates_at_loss  6xN array, coordinates at the exit of
                                    the element where the particle is lost
                                    (sixth coordinate is inf if particle is lost in a physical aperture)
               coordinates          6xNxNHIST array, coordinates at the entrance of the
                                    LHIST elements before the loss

 ROUT=LINEPASS(...,'KeepLattice') Tracking with the 'KeepLattice' flag is
   more efficient because it reuses persistent data structures stored in
   memory in previous calls to LINEPASS.

    !!! In order to use this option, LINEPASS must first be called
    without the 'KeepLattice' flag. It then assumes that the elements in LINE
     DO NOT CHANGE between calls. Otherwise, LINEPASS must be called again
   without 'KeepLattice'.

 ROUT=LINEPASS(...,'reuse') is kept for compatibilty with previous
 versions. It has no effect.

 Rfin=LINEPASS(...,PREFUNC)
 Rfin=LINEPASS(...,PREFUNC,POSTFUNC)
 Rfin=LINEPASS(...,function_handle.empty,POSTFUNC)
    PREFUNC and POSTFUNC are function handles, PREFUNC is called
    immediately before tracking each element, POSTFUNC is called
    immediately after each element. Functions are called as:

       ROUT=FUNC(ELEMENT, RIN, NTURN, NELEMENT)

   and is allowed to modify the particle coordinates

 See also: RINGPASS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Rout,varargout] = linepass(line,Rin,refpts,varargin)
0002 %LINEPASS tracks particles through each element of the cell array LINE
0003 % calling the element-specific tracking function specified in the
0004 % LINE{i}.PassMethod field.
0005 %
0006 % ROUT=LINEPASS(LINE,RIN) tracks particle(s) with initial
0007 %    condition(s) RIN for NTURNS turns to the end of the LINE
0008 %
0009 %   LINE        AT lattice
0010 %   RIN         6xN matrix: input coordinates of N particles
0011 %
0012 %   ROUT        6xN matrix: output coordinates of N particles at
0013 %               the end of LINE
0014 %
0015 % ROUT=LINEPASS(LINE,RIN,REFPTS) also returns intermediate results
0016 %     at the entrance of each element specified in the REFPTS
0017 %
0018 %    REFPTS is an array of increasing indexes that selects elements
0019 %     between 1 and length(LINE)+1.
0020 %     See further explanation of REFPTS in the 'help' for FINDSPOS
0021 %   ROUT        6x(N*length(REFPTS)) matrix: output coordinates of N particles at
0022 %               each reference point
0023 %
0024 %     NOTE:
0025 %     LINEPASS(LINE,RIN,length(LINE)+1) is the same as LINEPASS(LINE,RIN)
0026 %     since the reference point length(LINE)+1 is the exit of the last element
0027 %     LINEPASS(LINE,RIN,1) is a copy of RIN since the
0028 %     reference point 1 is the entrance of the first element
0029 %
0030 % [ROUT, LOST]=LINEPASS(...)
0031 %  Return additionally an information on lost particles
0032 %    LOST    1xN logical vector, indicating lost particles
0033 %    If only one output is given, loss information is saved in
0034 %    global variable LOSSFLAG
0035 %
0036 % [ROUT, LOSS, LOSSINFO]=LINEPASS(...,'nhist',NHIST,...)
0037 %  Return additional information on lost particles
0038 %   NHIST       number elements before the loss to be traced (default: 1)
0039 %   LOSSINFO    1x1 structure with the following fields:
0040 %               lost                 1xN logical vector, indicating lost particles
0041 %               turn                 1xN vector, turn number where the particle is lost
0042 %               element              1xN vector, element number where the particle is lost
0043 %               coordinates_at_loss  6xN array, coordinates at the exit of
0044 %                                    the element where the particle is lost
0045 %                                    (sixth coordinate is inf if particle is lost in a physical aperture)
0046 %               coordinates          6xNxNHIST array, coordinates at the entrance of the
0047 %                                    LHIST elements before the loss
0048 %
0049 % ROUT=LINEPASS(...,'KeepLattice') Tracking with the 'KeepLattice' flag is
0050 %   more efficient because it reuses persistent data structures stored in
0051 %   memory in previous calls to LINEPASS.
0052 %
0053 %    !!! In order to use this option, LINEPASS must first be called
0054 %    without the 'KeepLattice' flag. It then assumes that the elements in LINE
0055 %     DO NOT CHANGE between calls. Otherwise, LINEPASS must be called again
0056 %   without 'KeepLattice'.
0057 %
0058 % ROUT=LINEPASS(...,'reuse') is kept for compatibilty with previous
0059 % versions. It has no effect.
0060 %
0061 % Rfin=LINEPASS(...,PREFUNC)
0062 % Rfin=LINEPASS(...,PREFUNC,POSTFUNC)
0063 % Rfin=LINEPASS(...,function_handle.empty,POSTFUNC)
0064 %    PREFUNC and POSTFUNC are function handles, PREFUNC is called
0065 %    immediately before tracking each element, POSTFUNC is called
0066 %    immediately after each element. Functions are called as:
0067 %
0068 %       ROUT=FUNC(ELEMENT, RIN, NTURN, NELEMENT)
0069 %
0070 %   and is allowed to modify the particle coordinates
0071 %
0072 % See also: RINGPASS
0073 
0074 % Check input arguments
0075 if size(Rin,1)~=6
0076     error('Matrix of initial conditions, the second argument, must have 6 rows');
0077 end
0078 
0079 if (nargin < 3)
0080     refpts = length(line)+1;
0081 elseif islogical(refpts)
0082     refpts = find(refpts);
0083 elseif ~isnumeric(refpts)
0084     refpts = length(line)+1;
0085 end
0086 [keeplattice,args]=getflag(varargin, 'KeepLattice');
0087 [dummy,args]=getflag(args,'reuse');    %#ok<ASGLU> % Kept for compatibility and ignored
0088 funcargs=cellfun(@(arg) isa(arg,'function_handle'), args);
0089 nhist=getoption(struct(args{~funcargs}), 'nhist',1);
0090 
0091 newlattice = double(~keeplattice);
0092 
0093 [prefunc,postfunc]=parseargs({function_handle.empty,function_handle.empty},...
0094     args(funcargs));
0095 
0096 try
0097     [Rout,lossinfo] = atpass(line,Rin,newlattice,1,refpts,prefunc,postfunc,nhist);
0098     
0099     if nargout>1
0100         if nargout>2, varargout{2}=lossinfo; end
0101         varargout{1} = lossinfo.lost;
0102     else % if no output arguments - create LOSSFLAG, for backward compatibility with AT 1.2
0103         evalin('base','clear LOSSFLAG');
0104         evalin('base','global LOSSFLAG');
0105         assignin('base','LOSSFLAG',lossinfo.lost);
0106     end
0107 catch err
0108     if strcmp(err.identifier,'MATLAB:unassignedOutputs')
0109         error('Atpass:obsolete',['linepass is now expecting 2 output arguments from atpass.\n',...
0110             'You may need to call "atmexall" to install the new version']);
0111     else
0112         rethrow(err)
0113     end
0114 end
0115 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005