FINDORBIT6 finds closed orbit in the full 6-d phase space by numerically solving for a fixed point of the one turn map M calculated with RINGPASS (X, PX, Y, PY, DP, CT2 ) = M (X, PX, Y, PY, DP, CT1) with constraint % CT2 - CT1 = C*HarmNumber(1/Frf - 1/Frf0) IMPORTANT!!! FINDORBIT6 is a realistic simulation 1. The Frf frequency in the RF cavities (may be different from Frf0) imposes the synchronous condition CT2 - CT1 = C*HarmNumber(1/Frf - 1/Frf0) 2. The algorithm numerically calculates 6-by-6 Jacobian matrix J6. In order for (J-E) matrix to be non-singular it is NECESSARY to use a realistic PassMethod for cavities with non-zero momentum kick (such as ThinCavityPass). 3. FINDORBIT6 can find orbits with radiation. In order for the solution to exist the cavity must supply adequate energy compensation. In the simplest case of a single cavity, it must have 'Voltage' field set so that Voltage > Erad - energy loss per turn 4. FINDORBIT6 starts the search from [ 0 0 0 0 0 0 ]', unless the third argument is specified: FINDORBIT6(RING,REFPTS,GUESS) There exist a family of solutions that correspond to different RF buckets They differ in the 6-th coordinate by C*Nb/Frf. Nb = 1 .. HarmNum-1 5. The value of the 6-th coordinate found at the cavity gives the equilibrium RF phase. If there is no radiation the phase is 0; FINDORBIT6(RING) is 6x1 vector - fixed point at the entrance of the 1-st element of the RING (x,px,y,py,dp,ct) FINDORBIT6(RING,REFPTS) is 6-by-Length(REFPTS) array of column vectors - fixed points (x,px,y,py,dp,ct) at the entrance of each element indexed REFPTS array. REFPTS is an array of increasing indexes that select elements from the range 1 to length(RING)+1. See further explanation of REFPTS in the 'help' for FINDSPO FINDORBIT6(RING,REFPTS,GUESS) - same as above but the search for the fixed point starts at the initial condition GUESS GUESS must be a 6-by-1 vector; [ORBIT, FIXEDPOINT] = FINDORBIT6( ... ) The optional second return parameter is a 6-by-1 vector of initial conditions on the close orbit at the entrance to the RING. See also FINDORBIT4, FINDSYNCORBIT.
0001 function [orbit,fixedpoint] = findorbit6(RING,varargin) 0002 %FINDORBIT6 finds closed orbit in the full 6-d phase space 0003 % by numerically solving for a fixed point of the one turn 0004 % map M calculated with RINGPASS 0005 % 0006 % (X, PX, Y, PY, DP, CT2 ) = M (X, PX, Y, PY, DP, CT1) 0007 % 0008 % with constraint % CT2 - CT1 = C*HarmNumber(1/Frf - 1/Frf0) 0009 % 0010 % IMPORTANT!!! FINDORBIT6 is a realistic simulation 0011 % 1. The Frf frequency in the RF cavities (may be different from Frf0) 0012 % imposes the synchronous condition 0013 % CT2 - CT1 = C*HarmNumber(1/Frf - 1/Frf0) 0014 % 2. The algorithm numerically calculates 0015 % 6-by-6 Jacobian matrix J6. In order for (J-E) matrix 0016 % to be non-singular it is NECESSARY to use a realistic 0017 % PassMethod for cavities with non-zero momentum kick 0018 % (such as ThinCavityPass). 0019 % 3. FINDORBIT6 can find orbits with radiation. 0020 % In order for the solution to exist the cavity must supply 0021 % adequate energy compensation. 0022 % In the simplest case of a single cavity, it must have 0023 % 'Voltage' field set so that Voltage > Erad - energy loss per turn 0024 % 4. FINDORBIT6 starts the search from [ 0 0 0 0 0 0 ]', unless 0025 % the third argument is specified: FINDORBIT6(RING,REFPTS,GUESS) 0026 % There exist a family of solutions that correspond to different RF buckets 0027 % They differ in the 6-th coordinate by C*Nb/Frf. Nb = 1 .. HarmNum-1 0028 % 5. The value of the 6-th coordinate found at the cavity gives 0029 % the equilibrium RF phase. If there is no radiation the phase is 0; 0030 % 0031 % FINDORBIT6(RING) is 6x1 vector - fixed point at the 0032 % entrance of the 1-st element of the RING (x,px,y,py,dp,ct) 0033 % 0034 % FINDORBIT6(RING,REFPTS) is 6-by-Length(REFPTS) 0035 % array of column vectors - fixed points (x,px,y,py,dp,ct) 0036 % at the entrance of each element indexed REFPTS array. 0037 % REFPTS is an array of increasing indexes that select elements 0038 % from the range 1 to length(RING)+1. 0039 % See further explanation of REFPTS in the 'help' for FINDSPO 0040 % 0041 % FINDORBIT6(RING,REFPTS,GUESS) - same as above but the search 0042 % for the fixed point starts at the initial condition GUESS 0043 % GUESS must be a 6-by-1 vector; 0044 % 0045 % [ORBIT, FIXEDPOINT] = FINDORBIT6( ... ) 0046 % The optional second return parameter is 0047 % a 6-by-1 vector of initial conditions 0048 % on the close orbit at the entrance to the RING. 0049 % 0050 % See also FINDORBIT4, FINDSYNCORBIT. 0051 0052 if ~iscell(RING) 0053 error('First argument must be a cell array'); 0054 end 0055 0056 L0 = findspos(RING,length(RING)+1); % design length [m] 0057 C0 = PhysConstant.speed_of_light_in_vacuum.value; % speed of light [m/s] 0058 0059 T0 = L0/C0; 0060 0061 CavityIndex = find(atgetcells(RING,'Frequency'),1); 0062 0063 if isempty(CavityIndex) 0064 error('findorbit6: The lattice does not have Cavity element') 0065 end 0066 0067 cavity1=RING{find(atgetcells(RING,'Frequency'),1)}; 0068 0069 Frf = cavity1.Frequency; 0070 HarmNumber = cavity1.HarmNumber; 0071 theta = [0 0 0 0 0 C0*(HarmNumber/Frf - T0)]'; 0072 0073 d = 1e-6; % step size for numerical differentiation 0074 dps = 1e-12; % convergence threshold 0075 %dps=eps; % convergence threshold 0076 max_iterations = 20; 0077 0078 if nargin >= 3 % Check if guess argument was supplied 0079 if isnumeric(varargin{2}) && all(eq(size(varargin{2}),[6,1])) 0080 Ri=varargin{2}; 0081 else 0082 error('The last argument GUESS must be a 6-by-1 vector'); 0083 end 0084 else 0085 Ri = zeros(6,1); 0086 end 0087 D = [d*eye(6) zeros(6,1)]; 0088 %D = [0.5*d*eye(6) -0.5*d*eye(6) zeros(6,1)]; 0089 0090 args={}; 0091 change=Inf; 0092 itercount = 0; 0093 while (change > dps) && (itercount < max_iterations) 0094 RMATi= Ri(:,ones(1,7)) + D; 0095 %RMATi= Ri(:,ones(1,13)) + D; 0096 RMATf = linepass(RING,RMATi,args{:}); 0097 % compute the transverse part of the Jacobian 0098 J6 = (RMATf(:,1:6)-RMATf(:,7*ones(1,6)))/d; 0099 %J6 = (RMATf(:,1:6)-RMATf(:,7:12))/d; 0100 Rf = RMATf(:,end); 0101 Ri_next = Ri + (eye(6)-J6)\(Rf-Ri-theta); 0102 change = norm(Ri_next - Ri); 0103 Ri = Ri_next; 0104 itercount = itercount+1; 0105 args={'KeepLattice'}; 0106 end 0107 0108 if itercount == max_iterations 0109 warning('Maximum number of iterations reached. Possible non-convergence') 0110 end 0111 0112 if (nargin<2) || (isscalar(varargin{1}) && (varargin{1}==(length(RING)+1))) 0113 % return only the fixed point at the entrance of RING{1} 0114 orbit=Ri; 0115 else % 2-nd input argument - vector of reference points along the Ring 0116 % is supplied - return orbit 0117 orbit = linepass(RING,Ri,varargin{1},'KeepLattice'); 0118 end 0119 0120 if nargout >= 2 0121 fixedpoint=Ri; 0122 end