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

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

Initial import--MML version from SOLEIL@2013

File size: 3.1 KB
Line 
1function [M66, varargout] = findm66(RING, varargin);
2%FINDM66 numerically finds the 6x6 transfer matrix of an accelerator lattice
3%  by differentiation of LINEPASS near the closed orbit
4%  FINDM66 uses FINDORBIT6 to search for the closed orbit in 6-d
5%  In order for this to work the ring MUST have a CAVITY element
6%
7% M66 = FINDM66(RING)finds full one-turn 6-by-6
8%    matrix at the entrance of the first element
9%
10% [M66,T] = FINDM66(RING,REFPTS) in addition to M finds
11%    6-by-6 transfer matrixes  between entrances of
12%    the first element and each element indexed by REFPTS.
13%    T is 6-by-6-by-length(REFPTS) 3 dimentional array.
14%   
15%    REFPTS is an array of increasing indexes that  select elements
16%    from the range 1 to length(RING)+1.
17%    See further explanation of REFPTS in the 'help' for FINDSPOS
18%    When REFPTS is a vector FINDM44 is a 6-by-6-by-length(REFPTS) array
19%    so that the set of indexes (:,:,i) selects the 6-by-6
20%    matrix at the i-th reference point
21%   
22%    Note:
23%    When REFPTS= [ 1 2 .. ] the fist point is the entrance of the first element
24%    and T(:,:,1) - identity matrix
25%    When REFPTS= [  .. length(RING)+1] the last point is the exit of the last element
26%    and the entrance of the first element after 1 turn: T(:,:, ) = M
27%
28% [M66, T, orbit] = FINDM66(RING, REFPTS) in addition returns the closed orbit
29%    found in the process of lenearization
30%
31% See also findm44
32
33FULL = 0;
34switch nargin
35   
36    case 2
37      REFPTS = varargin{1};
38   case 1
39        REFPTS = 1;
40        otherwise
41     error('Too many input arguments')
42end
43
44
45NE = length(RING);
46NR = length(REFPTS);
47
48% See if step size for numerical differentiation
49% is set globally. Otherwise use 1e-7
50global NUMDIFPARAMS
51% Transverse
52if isfield(NUMDIFPARAMS,'XYStep')
53    dt = NUMDIFPARAMS.XYStep';
54else
55    dt =  1e-8;
56end
57% Longitudinal
58if isfield(NUMDIFPARAMS,'DPStep')
59    dl = NUMDIFPARAMS.DPStep';
60else
61    dl =  1e-8;
62end
63
64
65% Calculate closed orbit in 6 dimensions (MUST have cavity in the ring)
66reforbit = findorbit6(RING,REFPTS);
67% Build a diagonal matrix of initial conditions
68D6 = [dt*eye(4),zeros(4,2);zeros(2,4), dl*eye(2)];
69% Add to the orbit_in
70RIN = reforbit(:,1)*ones(1,12) + [D6, -D6];
71
72if nargout <= 1 % Whole ring , NO REFPTS
73    % Propagate through the ring
74    ROUT = ringpass(RING,RIN);
75    % Calculate numerical derivative
76    M66 = [(ROUT(:,1:4)-ROUT(:,7:10))./(2*dt), (ROUT(:,5:6)-ROUT(:,11:12))./(2*dl)];
77   return
78else                                   
79    % Calculate matrixes at all REFPTS. Use linepass
80    % Need to include the exit of the RING to REFPTS array
81    if(REFPTS(NR)~=NE+1)
82        REFPTS = [REFPTS NE+1];
83        NR1 = NR+1;
84    else
85        NR1 = NR;
86    end
87        TMAT = linepass(RING,RIN,REFPTS);
88        % Reshape, so that the otcome at each REFPTS is a separate page in a 3-dim array
89    TMAT3 = reshape(TMAT,6,12,NR1);
90    varargout{1} = [(TMAT3(:,1:4,1:NR)-TMAT3(:,7:10,1:NR))/(2*dt), (TMAT3(:,5:6,1:NR)-TMAT3(:,11:12,1:NR))/(2*dl)];
91    M66 = [(TMAT3(:,1:4,NR1)-TMAT3(:,7:10,NR1))/(2*dt), (TMAT3(:,5:6,NR1)-TMAT3(:,11:12,NR1))/(2*dl)];
92end
93
94% Return closed orbit if requested
95if nargout == 3
96   varargout{2} = reforbit;
97end
Note: See TracBrowser for help on using the repository browser.