1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of twissring</title> |
---|
6 | <meta name="keywords" content="twissring"> |
---|
7 | <meta name="description" content="TWISSRING calculates linear optics functions for an UNCOUPLED ring"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../../index.html">Home</a> > <a href="../index.html">at</a> > <a href="index.html">atphysics</a> > twissring.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for at/atphysics <img alt=">" border="0" src="../../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>twissring |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
24 | <div class="box"><strong>TWISSRING calculates linear optics functions for an UNCOUPLED ring</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function [TD, varargout] = twissring(RING,DP,varargin); </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">TWISSRING calculates linear optics functions for an UNCOUPLED ring |
---|
31 | |
---|
32 | [TwissData, tune] = TWISSRING(LATTICE,DP) calculates twiss parameters |
---|
33 | and closed orbit coordinates at the RING entrance assuming |
---|
34 | constant energy deviation DP. |
---|
35 | |
---|
36 | [TwissData, tune] = TWISSRING(LATTICE,DP,REFPTS) calculates Twiss parameters |
---|
37 | and closed orbit coordinates at specified reference points REFPTS. |
---|
38 | |
---|
39 | Note: REFPTS is an array of increasing indexes that |
---|
40 | select elements from range 1 to length(LATTICE)+1. |
---|
41 | See further explanation of REFPTS in the 'help' for FINDSPOS |
---|
42 | |
---|
43 | [TwissData, tune, chrom] = TWISSRING(...,'chrom', DDP) also calculates |
---|
44 | linear dispersion and chromaticity. Dispersion is returned as one |
---|
45 | of the fields in TwissData. |
---|
46 | !!! Last argument DDP is a momentum deviation on top |
---|
47 | of DP (the second argument) used to calculate and normalize |
---|
48 | dispersion and chromaticity. If not supplied |
---|
49 | the default value of 1e-8 is used. |
---|
50 | |
---|
51 | Note: To resolve the integer part of the tune |
---|
52 | and the uncertainty of acos(trace(M)/2) it is necessary to |
---|
53 | supply sufficient number of REFPTS properly spaced in betatron phase. |
---|
54 | |
---|
55 | TwisData is a 1-by-REFPTS (1-by-1) structure array with fields |
---|
56 | (Some are the same as in the output of LINOPT) |
---|
57 | ElemIndex - integer (element number) in the RING |
---|
58 | SPos - longitudinal position [m] |
---|
59 | ClosedOrbit - closed orbit column vector with |
---|
60 | components x, px, y, py (momentums, NOT angles) |
---|
61 | Dispersion - dispersion orbit position 4-by-1 vector with |
---|
62 | components [eta_x, eta_prime_x, eta_y, eta_prime_y]' |
---|
63 | calculated with respect to the closed orbit with |
---|
64 | momentum deviation DP |
---|
65 | M44 - 4x4 transfer matrix M from the beginning of RING |
---|
66 | to the entrance of the element for specified DP [2] |
---|
67 | beta - [betax, betay] horizontal and vertical Twiss parameter beta |
---|
68 | alpha - [alphax, alphay] horizontal and vertical Twiss parameter alpha |
---|
69 | mu - [mux, muy] horizontal and vertical betatron phase |
---|
70 | !!! NOT 2*PI normalized |
---|
71 | |
---|
72 | Use MATLAB function CAT to get the data from fields of TwissData into MATLAB arrays. |
---|
73 | Example: |
---|
74 | >> TD = twissring(THERING,0,1:length(THERING)); |
---|
75 | >> BETA = cat(1,TD.beta); |
---|
76 | >> S = cat(1,TD.SPos); |
---|
77 | >> plot(S,BETA(:,1)) |
---|
78 | |
---|
79 | See also <a href="twissline.html" class="code" title="function [TD, varargout] = twissline(LINE,DP,TWISSDATAIN,varargin);">TWISSLINE</a>, <a href="linopt.html" class="code" title="function [LinData, varargout] = linopt(RING,DP,varargin);">LINOPT</a>, <a href="tunechrom.html" class="code" title="function [tune, varargout] = tunechrom(RING,DP,varargin)">TUNECHROM</a>.</pre></div> |
---|
80 | |
---|
81 | <!-- crossreference --> |
---|
82 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
83 | This function calls: |
---|
84 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
85 | <li><a href="findm44.html" class="code" title="function [M44, varargout] = findm44(LATTICE,DP,varargin)">findm44</a> FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice</li><li><a href="findspos.html" class="code" title="function spos = findspos(LINE,REFPTS)">findspos</a> FINDSPOS returns longitudinal positions of accelerator lattice elements.</li><li><a href="twissring.html" class="code" title="function [TD, varargout] = twissring(RING,DP,varargin);">twissring</a> TWISSRING calculates linear optics functions for an UNCOUPLED ring</li></ul> |
---|
86 | This function is called by: |
---|
87 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
88 | <li><a href="plotbeta.html" class="code" title="function varargout = plotbeta(varargin)">plotbeta</a> PLOTBETA plots UNCOUPLED! beta-functions</li><li><a href="twissring.html" class="code" title="function [TD, varargout] = twissring(RING,DP,varargin);">twissring</a> TWISSRING calculates linear optics functions for an UNCOUPLED ring</li></ul> |
---|
89 | <!-- crossreference --> |
---|
90 | |
---|
91 | <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
92 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
93 | <li><a href="#_sub1" class="code">function UP = BetatronPhaseUnwrap(P)</a></li></ul> |
---|
94 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
95 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [TD, varargout] = twissring(RING,DP,varargin);</a> |
---|
96 | 0002 <span class="comment">%TWISSRING calculates linear optics functions for an UNCOUPLED ring</span> |
---|
97 | 0003 <span class="comment">%</span> |
---|
98 | 0004 <span class="comment">% [TwissData, tune] = TWISSRING(LATTICE,DP) calculates twiss parameters</span> |
---|
99 | 0005 <span class="comment">% and closed orbit coordinates at the RING entrance assuming</span> |
---|
100 | 0006 <span class="comment">% constant energy deviation DP.</span> |
---|
101 | 0007 <span class="comment">%</span> |
---|
102 | 0008 <span class="comment">% [TwissData, tune] = TWISSRING(LATTICE,DP,REFPTS) calculates Twiss parameters</span> |
---|
103 | 0009 <span class="comment">% and closed orbit coordinates at specified reference points REFPTS.</span> |
---|
104 | 0010 <span class="comment">%</span> |
---|
105 | 0011 <span class="comment">% Note: REFPTS is an array of increasing indexes that</span> |
---|
106 | 0012 <span class="comment">% select elements from range 1 to length(LATTICE)+1.</span> |
---|
107 | 0013 <span class="comment">% See further explanation of REFPTS in the 'help' for FINDSPOS</span> |
---|
108 | 0014 <span class="comment">%</span> |
---|
109 | 0015 <span class="comment">% [TwissData, tune, chrom] = TWISSRING(...,'chrom', DDP) also calculates</span> |
---|
110 | 0016 <span class="comment">% linear dispersion and chromaticity. Dispersion is returned as one</span> |
---|
111 | 0017 <span class="comment">% of the fields in TwissData.</span> |
---|
112 | 0018 <span class="comment">% !!! Last argument DDP is a momentum deviation on top</span> |
---|
113 | 0019 <span class="comment">% of DP (the second argument) used to calculate and normalize</span> |
---|
114 | 0020 <span class="comment">% dispersion and chromaticity. If not supplied</span> |
---|
115 | 0021 <span class="comment">% the default value of 1e-8 is used.</span> |
---|
116 | 0022 <span class="comment">%</span> |
---|
117 | 0023 <span class="comment">% Note: To resolve the integer part of the tune</span> |
---|
118 | 0024 <span class="comment">% and the uncertainty of acos(trace(M)/2) it is necessary to</span> |
---|
119 | 0025 <span class="comment">% supply sufficient number of REFPTS properly spaced in betatron phase.</span> |
---|
120 | 0026 <span class="comment">%</span> |
---|
121 | 0027 <span class="comment">% TwisData is a 1-by-REFPTS (1-by-1) structure array with fields</span> |
---|
122 | 0028 <span class="comment">% (Some are the same as in the output of LINOPT)</span> |
---|
123 | 0029 <span class="comment">% ElemIndex - integer (element number) in the RING</span> |
---|
124 | 0030 <span class="comment">% SPos - longitudinal position [m]</span> |
---|
125 | 0031 <span class="comment">% ClosedOrbit - closed orbit column vector with</span> |
---|
126 | 0032 <span class="comment">% components x, px, y, py (momentums, NOT angles)</span> |
---|
127 | 0033 <span class="comment">% Dispersion - dispersion orbit position 4-by-1 vector with</span> |
---|
128 | 0034 <span class="comment">% components [eta_x, eta_prime_x, eta_y, eta_prime_y]'</span> |
---|
129 | 0035 <span class="comment">% calculated with respect to the closed orbit with</span> |
---|
130 | 0036 <span class="comment">% momentum deviation DP</span> |
---|
131 | 0037 <span class="comment">% M44 - 4x4 transfer matrix M from the beginning of RING</span> |
---|
132 | 0038 <span class="comment">% to the entrance of the element for specified DP [2]</span> |
---|
133 | 0039 <span class="comment">% beta - [betax, betay] horizontal and vertical Twiss parameter beta</span> |
---|
134 | 0040 <span class="comment">% alpha - [alphax, alphay] horizontal and vertical Twiss parameter alpha</span> |
---|
135 | 0041 <span class="comment">% mu - [mux, muy] horizontal and vertical betatron phase</span> |
---|
136 | 0042 <span class="comment">% !!! NOT 2*PI normalized</span> |
---|
137 | 0043 <span class="comment">%</span> |
---|
138 | 0044 <span class="comment">% Use MATLAB function CAT to get the data from fields of TwissData into MATLAB arrays.</span> |
---|
139 | 0045 <span class="comment">% Example:</span> |
---|
140 | 0046 <span class="comment">% >> TD = twissring(THERING,0,1:length(THERING));</span> |
---|
141 | 0047 <span class="comment">% >> BETA = cat(1,TD.beta);</span> |
---|
142 | 0048 <span class="comment">% >> S = cat(1,TD.SPos);</span> |
---|
143 | 0049 <span class="comment">% >> plot(S,BETA(:,1))</span> |
---|
144 | 0050 <span class="comment">%</span> |
---|
145 | 0051 <span class="comment">% See also TWISSLINE, LINOPT, TUNECHROM.</span> |
---|
146 | 0052 |
---|
147 | 0053 NE=length(RING); |
---|
148 | 0054 DDP_default = 1e-8; |
---|
149 | 0055 <span class="comment">% Process input arguments</span> |
---|
150 | 0056 <span class="keyword">switch</span> nargin |
---|
151 | 0057 <span class="keyword">case</span> 2 |
---|
152 | 0058 REFPTS=NE+1; |
---|
153 | 0059 CHROMFLAG=0; |
---|
154 | 0060 <span class="keyword">case</span> 3 |
---|
155 | 0061 <span class="keyword">if</span> isnumeric(varargin{1}) |
---|
156 | 0062 REFPTS = varargin{1}; |
---|
157 | 0063 CHROMFLAG = 0; |
---|
158 | 0064 <span class="keyword">elseif</span> ischar(varargin{1}) & strncmp(lower(varargin{1}),<span class="string">'chrom'</span>,5) |
---|
159 | 0065 CHROMFLAG = 1; |
---|
160 | 0066 REFPTS = NE+1; |
---|
161 | 0067 DDP = DDP_default; |
---|
162 | 0068 <span class="keyword">else</span> |
---|
163 | 0069 error(<span class="string">'Third argument must be a numeric array or string'</span>); |
---|
164 | 0070 <span class="keyword">end</span> |
---|
165 | 0071 <span class="keyword">case</span> 4 |
---|
166 | 0072 <span class="keyword">if</span> isnumeric(varargin{1}) |
---|
167 | 0073 REFPTS = varargin{1}; |
---|
168 | 0074 <span class="keyword">if</span> ischar(varargin{2}) & strncmp(lower(varargin{2}),<span class="string">'chrom'</span>,5) |
---|
169 | 0075 CHROMFLAG = 1; |
---|
170 | 0076 DDP = DDP_default; |
---|
171 | 0077 <span class="keyword">else</span> |
---|
172 | 0078 error(<span class="string">'Fourth argument - wrong type'</span>); |
---|
173 | 0079 <span class="keyword">end</span> |
---|
174 | 0080 <span class="keyword">elseif</span> ischar(varargin{1}) & strncmp(lower(varargin{1}),<span class="string">'chrom'</span>,5) |
---|
175 | 0081 CHROMFLAG = 1; |
---|
176 | 0082 REFPTS = NE+1; |
---|
177 | 0083 <span class="keyword">if</span> isnumeric(varargin{2}) |
---|
178 | 0084 DDP = varargin{2}; |
---|
179 | 0085 <span class="keyword">else</span> |
---|
180 | 0086 error(<span class="string">'Fourth argument - wrong type'</span>); |
---|
181 | 0087 <span class="keyword">end</span> |
---|
182 | 0088 <span class="keyword">end</span> |
---|
183 | 0089 <span class="keyword">case</span> 5 |
---|
184 | 0090 <span class="keyword">if</span> isnumeric(varargin{1}) |
---|
185 | 0091 REFPTS = varargin{1}; |
---|
186 | 0092 <span class="keyword">else</span> |
---|
187 | 0093 error(<span class="string">'Third argument - wrong type'</span>); |
---|
188 | 0094 <span class="keyword">end</span> |
---|
189 | 0095 <span class="keyword">if</span> ischar(varargin{2}) & strncmp(lower(varargin{2}),<span class="string">'chrom'</span>,5) |
---|
190 | 0096 CHROMFLAG = 1; |
---|
191 | 0097 <span class="keyword">else</span> |
---|
192 | 0098 error(<span class="string">'Fourth argument - wrong type'</span>); |
---|
193 | 0099 <span class="keyword">end</span> |
---|
194 | 0100 <span class="keyword">if</span> isnumeric(varargin{3}) |
---|
195 | 0101 DDP = varargin{3}; |
---|
196 | 0102 <span class="keyword">else</span> |
---|
197 | 0103 error(<span class="string">'Fifth argument - wrong type'</span>); |
---|
198 | 0104 <span class="keyword">end</span> |
---|
199 | 0105 <span class="keyword">otherwise</span> |
---|
200 | 0106 error(<span class="string">'Wrong number of arguments'</span>); |
---|
201 | 0107 <span class="keyword">end</span> |
---|
202 | 0108 |
---|
203 | 0109 <span class="comment">% Include the endpoint if it is not already in REFPTS</span> |
---|
204 | 0110 <span class="keyword">if</span> REFPTS(end)==NE+1 |
---|
205 | 0111 [M44, MS, orb] = <a href="findm44.html" class="code" title="function [M44, varargout] = findm44(LATTICE,DP,varargin)">findm44</a>(RING,DP,REFPTS); |
---|
206 | 0112 <span class="keyword">else</span> |
---|
207 | 0113 [M44, MS, orb] = <a href="findm44.html" class="code" title="function [M44, varargout] = findm44(LATTICE,DP,varargin)">findm44</a>(RING,DP,[REFPTS,NE+1]); |
---|
208 | 0114 <span class="keyword">end</span> |
---|
209 | 0115 |
---|
210 | 0116 |
---|
211 | 0117 |
---|
212 | 0118 |
---|
213 | 0119 cos_mu_x = (M44(1,1)+M44(2,2))/2; |
---|
214 | 0120 cos_mu_y = (M44(3,3)+M44(4,4))/2; |
---|
215 | 0121 |
---|
216 | 0122 sin_mu_x = sign(M44(1,2))*sqrt(-M44(1,2)*M44(2,1)-(M44(1,1)-M44(2,2))^2/4); |
---|
217 | 0123 sin_mu_y = sign(M44(3,4))*sqrt(-M44(3,4)*M44(4,3)-(M44(3,3)-M44(4,4))^2/4); |
---|
218 | 0124 |
---|
219 | 0125 |
---|
220 | 0126 ax = (M44(1,1)-M44(2,2))/2/sin_mu_x; |
---|
221 | 0127 ay = (M44(3,3)-M44(4,4))/2/sin_mu_y; |
---|
222 | 0128 |
---|
223 | 0129 bx = M44(1,2)/sin_mu_x; |
---|
224 | 0130 by = M44(3,4)/sin_mu_y; |
---|
225 | 0131 |
---|
226 | 0132 BX = squeeze((MS(1,1,:)*bx-MS(1,2,:)*ax).^2 + MS(1,2,:).^2)/bx; |
---|
227 | 0133 BY = squeeze((MS(3,3,:)*by-MS(3,4,:)*ay).^2 + MS(3,4,:).^2)/by; |
---|
228 | 0134 |
---|
229 | 0135 |
---|
230 | 0136 AX = -squeeze((MS(1,1,:)*bx-MS(1,2,:)*ax).*(MS(2,1,:)*bx-MS(2,2,:)*ax) + MS(1,2,:).*MS(2,2,:))/bx; |
---|
231 | 0137 AY = -squeeze((MS(3,3,:)*by-MS(3,4,:)*ay).*(MS(4,3,:)*by-MS(4,4,:)*ay) + MS(3,4,:).*MS(4,4,:))/by; |
---|
232 | 0138 |
---|
233 | 0139 MX = atan(squeeze( MS(1,2,:)./(MS(1,1,:)*bx-MS(1,2,:)*ax))); |
---|
234 | 0140 MY = atan(squeeze(MS(3,4,:)./(MS(3,3,:)*by-MS(3,4,:)*ay))); |
---|
235 | 0141 |
---|
236 | 0142 MX = <a href="#_sub1" class="code" title="subfunction UP = BetatronPhaseUnwrap(P)">BetatronPhaseUnwrap</a>(MX); |
---|
237 | 0143 MY = <a href="#_sub1" class="code" title="subfunction UP = BetatronPhaseUnwrap(P)">BetatronPhaseUnwrap</a>(MY); |
---|
238 | 0144 |
---|
239 | 0145 tune = [MX(end),MY(end)]/2/pi; |
---|
240 | 0146 |
---|
241 | 0147 NR = length(REFPTS); |
---|
242 | 0148 <span class="comment">% Build TD only for points originally referenced in REFPTS</span> |
---|
243 | 0149 TD = struct(<span class="string">'ElemIndex'</span>,num2cell(REFPTS),<span class="keyword">...</span> |
---|
244 | 0150 <span class="string">'SPos'</span>,num2cell(<a href="findspos.html" class="code" title="function spos = findspos(LINE,REFPTS)">findspos</a>(RING,REFPTS)),<span class="keyword">...</span> |
---|
245 | 0151 <span class="string">'ClosedOrbit'</span>,num2cell(orb(:,1:NR),1),<span class="keyword">...</span> |
---|
246 | 0152 <span class="string">'M44'</span>, squeeze(num2cell(MS(:,:,1:NR),[1 2]))',<span class="keyword">...</span> |
---|
247 | 0153 <span class="string">'beta'</span>, num2cell([BX(1:NR),BY(1:NR)],2)',<span class="keyword">...</span> |
---|
248 | 0154 <span class="string">'alpha'</span>, num2cell([AX(1:NR),AY(1:NR)],2)',<span class="keyword">...</span> |
---|
249 | 0155 <span class="string">'mu'</span>, num2cell([MX(1:NR),MY(1:NR)],2)'); |
---|
250 | 0156 |
---|
251 | 0157 |
---|
252 | 0158 <span class="keyword">if</span> CHROMFLAG |
---|
253 | 0159 [TD_DDP tune_DDP] = <a href="twissring.html" class="code" title="function [TD, varargout] = twissring(RING,DP,varargin);">twissring</a>(RING,DP+DDP,REFPTS); |
---|
254 | 0160 DORBIT = reshape(cat(1,TD_DDP.ClosedOrbit),4,[]); |
---|
255 | 0161 DISPERSION = num2cell((DORBIT-orb(:,1:NR))/DDP,1); |
---|
256 | 0162 [TD.Dispersion] = deal( DISPERSION{:}); |
---|
257 | 0163 <span class="keyword">end</span> |
---|
258 | 0164 |
---|
259 | 0165 <span class="keyword">if</span> nargout>1 |
---|
260 | 0166 varargout{1}=tune; |
---|
261 | 0167 <span class="keyword">end</span> |
---|
262 | 0168 <span class="keyword">if</span> nargout==3 & CHROMFLAG |
---|
263 | 0169 varargout{2} = (tune_DDP-tune)/DDP; |
---|
264 | 0170 <span class="keyword">end</span> |
---|
265 | 0171 |
---|
266 | 0172 <a name="_sub1" href="#_subfunctions" class="code">function UP = BetatronPhaseUnwrap(P)</a> |
---|
267 | 0173 <span class="comment">% unwrap negative jumps in betatron</span> |
---|
268 | 0174 DP = diff(P); |
---|
269 | 0175 JUMPS = [0; diff(P)] < 0; |
---|
270 | 0176 UP = P+cumsum(JUMPS)*pi; |
---|
271 | 0177 |
---|
272 | 0178</pre></div> |
---|
273 | <hr><address>Generated on Mon 21-May-2007 15:26:45 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
274 | </body> |
---|
275 | </html> |
---|