source: MML/trunk/at/atphysics/linopt.m @ 5

Last change on this file since 5 was 5, checked in by zhangj, 11 years ago

ThomX MML version on the LAL server @ 17/12/2013

File size: 4.1 KB
Line 
1function [LinData, varargout] = linopt(RING,DP,varargin);
2%LINOPT performs linear analysis of the COUPLED lattices
3%   Notation is the same as in reference [3]
4%
5%
6% LinData = LINOPT(RING,DP,REFPTS) is a MATLAB structure array with fields
7%   
8%   ElemIndex   - ordinal position in the RING
9%   SPos        - longitudinal position [m]
10%   ClosedOrbit - closed orbit column vector with
11%                 components x, px, y, py (momentums, NOT angles)                                               
12%   Dispersion  - dispersion orbit position vector with
13%                 components eta_x, eta_prime_x, eta_y, eta_prime_y
14%                 calculated with respect to the closed orbit with
15%                 momentum deviation DP
16%   M44         - 4x4 transfer matrix M from the beginning of RING
17%                 to the entrance of the element for specified DP [2]
18%   A           - 2x2 matrix A in [3]
19%   B           - 2x2 matrix B in [3]
20%   C           - 2x2 matrix C in [3]                   
21%   gamma       - gamma parameter of the transformation to eigenmodes
22%   mu          - [ mux, muy] horizontal and vertical betatron phase
23%   beta        - [betax, betay] vector
24%
25%   All values are specified at the entrance of each element specified in REFPTS.
26%   REFPTS is an array of increasing indexes that  select elements
27%   from the range 1 to length(LINE)+1.
28%   See further explanation of REFPTS in the 'help' for FINDSPOS
29%
30% [LinData,NU] = LINOPT() returns a vector of linear tunes
31%   [nu_u , nu_v] for two normal modes of linear motion [1]
32%
33% [LinData,NU, KSI] = LINOPT() returns a vector of chromaticities ksi = d(nu)/(dP/P)
34%   [ksi_u , ksi_v] - derivatives of [nu_u , nu_v]
35%
36% See also FINDSPOS TWISSRING TUNECHROM
37%
38%   [1] D.Edwars,L.Teng IEEE Trans.Nucl.Sci. NS-20, No.3, p.885-888, 1973
39%   [2] E.Courant, H.Snyder
40%   [3] D.Sagan, D.Rubin Phys.Rev.Spec.Top.-Accelerators and beams, vol.2 (1999)
41%
42%
43% Fix the bug to avoid the mirror tunes.
44% By Jianfeng Zhang @ LAL, 04/10/2013
45 
46
47NE=length(RING);
48if(nargin==2)
49   REFPTS= 1;
50else
51   REFPTS=varargin{1};
52end
53
54NR=length(REFPTS);
55 
56
57spos = findspos(RING,REFPTS);
58[M44, MS, orb] = findm44(RING,DP,REFPTS);
59
60LinData = struct('ElemIndex',num2cell(REFPTS),'SPos',num2cell(spos),...
61    'ClosedOrbit',num2cell(orb,1),'M44',squeeze(num2cell(MS,[1 2]))');
62
63% Calculate A,B,C, gamma at the first element
64M =M44(1:2,1:2);
65N =M44(3:4,3:4);
66m =M44(1:2,3:4);
67n =M44(3:4,1:2);
68
69% 2-by-2 symplectic matrix
70S = [0 1; -1 0];
71H = m + S*n'*S';
72t = trace(M-N);
73
74g = sqrt(1 + sqrt(t*t/(t*t+4*det(H))))/sqrt(2);
75G = diag([g g]);
76C = -H*sign(t)/(g*sqrt(t*t+4*det(H)));
77A = G*G*M  -  G*(m*S*C'*S' + C*n) + C*N*S*C'*S';
78B = G*G*N  +  G*(S*C'*S'*m + n*C) + S*C'*S'*M*C;
79
80
81   
82if REFPTS(1)==1 & NR>1
83    START = 2;
84    LinData(1).A=A;
85    LinData(1).B=B;
86    LinData(1).C=C;
87    LinData(1).gamma=g;
88    LinData(1).beta(1) = A(1,2)/sin(acos(trace(A/2)));
89    LinData(1).beta(2) = B(1,2)/sin(acos(trace(B/2)));
90else
91    START = 1;
92end
93
94
95     
96   
97
98
99% find  matrixes in all elements indexed by REFPTS
100for i=START:NR;
101    M12 =LinData(i).M44(1:2,1:2);
102    N12 =LinData(i).M44(3:4,3:4);
103    m12 =LinData(i).M44(1:2,3:4);
104    n12 =LinData(i).M44(3:4,1:2);
105   
106    g2 = sqrt(det(n12*C+G*N12));
107    E12 = (G*M12-m12*S*C'*S')/g2;
108    F12 = (n12*C+G*N12)/g2;
109   
110    LinData(i).gamma=g2;
111    LinData(i).C=(M12*C+G*m12)*S*F12'*S';
112    LinData(i).A=E12*A*S*E12'*S';
113    LinData(i).B=F12*B*S*F12'*S';
114    LinData(i).beta(1) = LinData(i).A(1,2)/sin(acos(trace(A/2)));
115    LinData(i).beta(2) = LinData(i).B(1,2)/sin(acos(trace(B/2)));
116 
117end
118
119
120
121if nargout > 1
122   cos_mu_x = trace(A)/2;
123   cos_mu_y = trace(B)/2;
124   varargout{1} = acos([cos_mu_x cos_mu_y])/2/pi;
125   
126   %avoid the mirror tune using the value of sin(phi)
127   % By Jianfeng Zhang @ LAL, 04/10/2013
128   if A(1,2)<0
129       varargout{1}(1) = 1 -varargout{1}(1);
130   end
131    if B(1,2)<0
132       varargout{1}(2) = 1 -varargout{1}(2);
133   end
134end
135
136if nargout == 3
137    global NUMDIFPARAMS
138
139    if isfield(NUMDIFPARAMS,'DPStep')
140        dDP = NUMDIFPARAMS.DPStep';
141    else
142        dDP =  1e-8;
143    end
144    % Calculate tunes for DP+dDP
145    [LD, TUNES] = linopt(RING,DP+dDP,1);
146    varargout{2} = (TUNES - varargout{1})/dDP;
147end
Note: See TracBrowser for help on using the repository browser.