1 | function [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 | |
---|
33 | FULL = 0; |
---|
34 | switch nargin |
---|
35 | |
---|
36 | case 2 |
---|
37 | REFPTS = varargin{1}; |
---|
38 | case 1 |
---|
39 | REFPTS = 1; |
---|
40 | otherwise |
---|
41 | error('Too many input arguments') |
---|
42 | end |
---|
43 | |
---|
44 | |
---|
45 | NE = length(RING); |
---|
46 | NR = length(REFPTS); |
---|
47 | |
---|
48 | % See if step size for numerical differentiation |
---|
49 | % is set globally. Otherwise use 1e-7 |
---|
50 | global NUMDIFPARAMS |
---|
51 | % Transverse |
---|
52 | if isfield(NUMDIFPARAMS,'XYStep') |
---|
53 | dt = NUMDIFPARAMS.XYStep'; |
---|
54 | else |
---|
55 | dt = 1e-8; |
---|
56 | end |
---|
57 | % Longitudinal |
---|
58 | if isfield(NUMDIFPARAMS,'DPStep') |
---|
59 | dl = NUMDIFPARAMS.DPStep'; |
---|
60 | else |
---|
61 | dl = 1e-8; |
---|
62 | end |
---|
63 | |
---|
64 | |
---|
65 | % Calculate closed orbit in 6 dimensions (MUST have cavity in the ring) |
---|
66 | reforbit = findorbit6(RING,REFPTS); |
---|
67 | % Build a diagonal matrix of initial conditions |
---|
68 | D6 = [dt*eye(4),zeros(4,2);zeros(2,4), dl*eye(2)]; |
---|
69 | % Add to the orbit_in |
---|
70 | RIN = reforbit(:,1)*ones(1,12) + [D6, -D6]; |
---|
71 | |
---|
72 | if 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 |
---|
78 | else |
---|
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)]; |
---|
92 | end |
---|
93 | |
---|
94 | % Return closed orbit if requested |
---|
95 | if nargout == 3 |
---|
96 | varargout{2} = reforbit; |
---|
97 | end |
---|