source: MML/trunk/at/doc_html/at/atphysics/twissring.html @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 16.8 KB
Line 
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 &copy; 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> &gt;  <a href="../index.html">at</a> &gt; <a href="index.html">atphysics</a> &gt; twissring.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for at/atphysics&nbsp;<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     &gt;&gt; TD = twissring(THERING,0,1:length(THERING));
75     &gt;&gt; BETA = cat(1,TD.beta);
76     &gt;&gt; S = cat(1,TD.SPos);
77     &gt;&gt; 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>
83This 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>
86This 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>
960002 <span class="comment">%TWISSRING calculates linear optics functions for an UNCOUPLED ring</span>
970003 <span class="comment">%</span>
980004 <span class="comment">% [TwissData, tune]  = TWISSRING(LATTICE,DP) calculates twiss parameters</span>
990005 <span class="comment">%    and closed orbit coordinates at the RING entrance assuming</span>
1000006 <span class="comment">%    constant energy deviation DP.</span>
1010007 <span class="comment">%</span>
1020008 <span class="comment">% [TwissData, tune]  = TWISSRING(LATTICE,DP,REFPTS) calculates Twiss parameters</span>
1030009 <span class="comment">%    and closed orbit coordinates at specified reference points REFPTS.</span>
1040010 <span class="comment">%</span>
1050011 <span class="comment">%    Note: REFPTS is an array of increasing indexes that</span>
1060012 <span class="comment">%    select elements from range 1 to length(LATTICE)+1.</span>
1070013 <span class="comment">%    See further explanation of REFPTS in the 'help' for FINDSPOS</span>
1080014 <span class="comment">%</span>
1090015 <span class="comment">% [TwissData, tune, chrom]  = TWISSRING(...,'chrom', DDP) also calculates</span>
1100016 <span class="comment">%    linear dispersion and chromaticity. Dispersion is returned as one</span>
1110017 <span class="comment">%    of the fields in TwissData.</span>
1120018 <span class="comment">%    !!! Last argument DDP is a momentum deviation on top</span>
1130019 <span class="comment">%    of DP (the second argument) used to calculate and normalize</span>
1140020 <span class="comment">%    dispersion and chromaticity. If not supplied</span>
1150021 <span class="comment">%    the default value of 1e-8 is used.</span>
1160022 <span class="comment">%</span>
1170023 <span class="comment">%    Note: To resolve the integer part of the tune</span>
1180024 <span class="comment">%    and the uncertainty of acos(trace(M)/2) it is necessary to</span>
1190025 <span class="comment">%    supply sufficient number of REFPTS properly spaced in betatron phase.</span>
1200026 <span class="comment">%</span>
1210027 <span class="comment">% TwisData is a 1-by-REFPTS (1-by-1) structure array with fields</span>
1220028 <span class="comment">%       (Some are the same as in the output of LINOPT)</span>
1230029 <span class="comment">%       ElemIndex   - integer (element number) in the RING</span>
1240030 <span class="comment">%       SPos        - longitudinal position [m]</span>
1250031 <span class="comment">%       ClosedOrbit - closed orbit column vector with</span>
1260032 <span class="comment">%                     components x, px, y, py (momentums, NOT angles)</span>
1270033 <span class="comment">%       Dispersion  - dispersion orbit position 4-by-1 vector with</span>
1280034 <span class="comment">%                     components [eta_x, eta_prime_x, eta_y, eta_prime_y]'</span>
1290035 <span class="comment">%                     calculated with respect to the closed orbit with</span>
1300036 <span class="comment">%                     momentum deviation DP</span>
1310037 <span class="comment">%       M44         - 4x4 transfer matrix M from the beginning of RING</span>
1320038 <span class="comment">%                     to the entrance of the element for specified DP [2]</span>
1330039 <span class="comment">%       beta        - [betax, betay] horizontal and vertical Twiss parameter beta</span>
1340040 <span class="comment">%       alpha       - [alphax, alphay] horizontal and vertical Twiss parameter alpha</span>
1350041 <span class="comment">%       mu          - [mux, muy] horizontal and vertical betatron phase</span>
1360042 <span class="comment">%                     !!! NOT 2*PI normalized</span>
1370043 <span class="comment">%</span>
1380044 <span class="comment">% Use MATLAB function CAT to get the data from fields of TwissData into MATLAB arrays.</span>
1390045 <span class="comment">%     Example:</span>
1400046 <span class="comment">%     &gt;&gt; TD = twissring(THERING,0,1:length(THERING));</span>
1410047 <span class="comment">%     &gt;&gt; BETA = cat(1,TD.beta);</span>
1420048 <span class="comment">%     &gt;&gt; S = cat(1,TD.SPos);</span>
1430049 <span class="comment">%     &gt;&gt; plot(S,BETA(:,1))</span>
1440050 <span class="comment">%</span>
1450051 <span class="comment">% See also TWISSLINE, LINOPT, TUNECHROM.</span>
1460052
1470053 NE=length(RING);
1480054 DDP_default = 1e-8;
1490055 <span class="comment">% Process input arguments</span>
1500056 <span class="keyword">switch</span> nargin
1510057 <span class="keyword">case</span> 2
1520058     REFPTS=NE+1;
1530059     CHROMFLAG=0;
1540060 <span class="keyword">case</span> 3
1550061     <span class="keyword">if</span> isnumeric(varargin{1})
1560062         REFPTS = varargin{1};
1570063         CHROMFLAG = 0;
1580064     <span class="keyword">elseif</span> ischar(varargin{1}) &amp; strncmp(lower(varargin{1}),<span class="string">'chrom'</span>,5)
1590065         CHROMFLAG = 1;
1600066         REFPTS = NE+1;
1610067         DDP = DDP_default;
1620068     <span class="keyword">else</span>
1630069         error(<span class="string">'Third argument must be a numeric array or string'</span>);
1640070     <span class="keyword">end</span>
1650071 <span class="keyword">case</span> 4
1660072     <span class="keyword">if</span> isnumeric(varargin{1})
1670073         REFPTS = varargin{1};
1680074         <span class="keyword">if</span> ischar(varargin{2}) &amp; strncmp(lower(varargin{2}),<span class="string">'chrom'</span>,5)
1690075             CHROMFLAG = 1;
1700076             DDP = DDP_default;
1710077         <span class="keyword">else</span>
1720078             error(<span class="string">'Fourth argument - wrong type'</span>);
1730079         <span class="keyword">end</span>
1740080     <span class="keyword">elseif</span> ischar(varargin{1}) &amp; strncmp(lower(varargin{1}),<span class="string">'chrom'</span>,5)
1750081         CHROMFLAG = 1;
1760082         REFPTS = NE+1;
1770083         <span class="keyword">if</span> isnumeric(varargin{2})
1780084             DDP = varargin{2};
1790085         <span class="keyword">else</span>
1800086             error(<span class="string">'Fourth argument - wrong type'</span>);
1810087         <span class="keyword">end</span>
1820088     <span class="keyword">end</span>
1830089 <span class="keyword">case</span> 5
1840090     <span class="keyword">if</span> isnumeric(varargin{1})
1850091         REFPTS = varargin{1};
1860092     <span class="keyword">else</span>
1870093         error(<span class="string">'Third argument - wrong type'</span>);
1880094     <span class="keyword">end</span>
1890095     <span class="keyword">if</span> ischar(varargin{2}) &amp; strncmp(lower(varargin{2}),<span class="string">'chrom'</span>,5)
1900096          CHROMFLAG = 1;
1910097     <span class="keyword">else</span>
1920098          error(<span class="string">'Fourth argument - wrong type'</span>);
1930099     <span class="keyword">end</span>
1940100     <span class="keyword">if</span> isnumeric(varargin{3})
1950101         DDP = varargin{3};
1960102     <span class="keyword">else</span>
1970103         error(<span class="string">'Fifth argument - wrong type'</span>);
1980104     <span class="keyword">end</span>
1990105 <span class="keyword">otherwise</span>
2000106     error(<span class="string">'Wrong number of arguments'</span>);
2010107 <span class="keyword">end</span>
2020108
2030109 <span class="comment">% Include the endpoint if it is not already in REFPTS</span>
2040110 <span class="keyword">if</span> REFPTS(end)==NE+1
2050111     [M44, MS, orb] = <a href="findm44.html" class="code" title="function [M44, varargout]  = findm44(LATTICE,DP,varargin)">findm44</a>(RING,DP,REFPTS);
2060112 <span class="keyword">else</span>
2070113     [M44, MS, orb] = <a href="findm44.html" class="code" title="function [M44, varargout]  = findm44(LATTICE,DP,varargin)">findm44</a>(RING,DP,[REFPTS,NE+1]);
2080114 <span class="keyword">end</span>
2090115
2100116
2110117
2120118
2130119 cos_mu_x = (M44(1,1)+M44(2,2))/2;
2140120 cos_mu_y = (M44(3,3)+M44(4,4))/2;
2150121
2160122 sin_mu_x = sign(M44(1,2))*sqrt(-M44(1,2)*M44(2,1)-(M44(1,1)-M44(2,2))^2/4);
2170123 sin_mu_y = sign(M44(3,4))*sqrt(-M44(3,4)*M44(4,3)-(M44(3,3)-M44(4,4))^2/4);
2180124
2190125
2200126 ax = (M44(1,1)-M44(2,2))/2/sin_mu_x;
2210127 ay = (M44(3,3)-M44(4,4))/2/sin_mu_y;
2220128
2230129 bx = M44(1,2)/sin_mu_x;
2240130 by = M44(3,4)/sin_mu_y;
2250131
2260132 BX = squeeze((MS(1,1,:)*bx-MS(1,2,:)*ax).^2 + MS(1,2,:).^2)/bx;
2270133 BY = squeeze((MS(3,3,:)*by-MS(3,4,:)*ay).^2 + MS(3,4,:).^2)/by;
2280134
2290135
2300136 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;
2310137 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;
2320138
2330139 MX = atan(squeeze( MS(1,2,:)./(MS(1,1,:)*bx-MS(1,2,:)*ax)));
2340140 MY = atan(squeeze(MS(3,4,:)./(MS(3,3,:)*by-MS(3,4,:)*ay)));
2350141
2360142 MX = <a href="#_sub1" class="code" title="subfunction UP = BetatronPhaseUnwrap(P)">BetatronPhaseUnwrap</a>(MX);
2370143 MY = <a href="#_sub1" class="code" title="subfunction UP = BetatronPhaseUnwrap(P)">BetatronPhaseUnwrap</a>(MY);
2380144
2390145 tune = [MX(end),MY(end)]/2/pi;
2400146
2410147 NR = length(REFPTS);
2420148 <span class="comment">% Build TD only for points originally referenced in REFPTS</span>
2430149 TD = struct(<span class="string">'ElemIndex'</span>,num2cell(REFPTS),<span class="keyword">...</span>
2440150     <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>
2450151     <span class="string">'ClosedOrbit'</span>,num2cell(orb(:,1:NR),1),<span class="keyword">...</span>
2460152     <span class="string">'M44'</span>, squeeze(num2cell(MS(:,:,1:NR),[1 2]))',<span class="keyword">...</span>
2470153     <span class="string">'beta'</span>, num2cell([BX(1:NR),BY(1:NR)],2)',<span class="keyword">...</span>
2480154     <span class="string">'alpha'</span>, num2cell([AX(1:NR),AY(1:NR)],2)',<span class="keyword">...</span>
2490155     <span class="string">'mu'</span>, num2cell([MX(1:NR),MY(1:NR)],2)');
2500156
2510157
2520158 <span class="keyword">if</span> CHROMFLAG
2530159     [TD_DDP tune_DDP] = <a href="twissring.html" class="code" title="function [TD, varargout] = twissring(RING,DP,varargin);">twissring</a>(RING,DP+DDP,REFPTS);
2540160     DORBIT = reshape(cat(1,TD_DDP.ClosedOrbit),4,[]);
2550161     DISPERSION = num2cell((DORBIT-orb(:,1:NR))/DDP,1);
2560162     [TD.Dispersion] = deal( DISPERSION{:});
2570163 <span class="keyword">end</span>
2580164     
2590165 <span class="keyword">if</span> nargout&gt;1
2600166     varargout{1}=tune;
2610167 <span class="keyword">end</span>
2620168 <span class="keyword">if</span> nargout==3 &amp; CHROMFLAG
2630169     varargout{2} = (tune_DDP-tune)/DDP;
2640170 <span class="keyword">end</span>
2650171
2660172 <a name="_sub1" href="#_subfunctions" class="code">function UP = BetatronPhaseUnwrap(P)</a>
2670173 <span class="comment">% unwrap negative jumps in betatron</span>
2680174     DP = diff(P);
2690175     JUMPS = [0; diff(P)] &lt; 0;
2700176     UP = P+cumsum(JUMPS)*pi;
2710177
2720178</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> &copy; 2003</address>
274</body>
275</html>
Note: See TracBrowser for help on using the repository browser.