source: MML/trunk/mml/stepchro.m @ 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: 4.9 KB
Line 
1function  [DelSext, ActuatorFamily] = stepchro(varargin)
2%STEPCHRO - Incremental change in the chromaticity (Delta Tune / Delta RF)
3%  [DelSext, SextFamily] = stepchro(DeltaChromaticity, ChroResponseMatrix)
4%
5%  Step change in storage ring chromaticity using the default chromaticty correctors (findmemberof('Chromaticity Corrector'))
6%
7%  INPUTS
8%  1.                     | Change in Horizontal Chromaticity |
9%     DeltaChromaticity = |                                   |
10%                         | Change in Vertical Chromaticity   |
11%  2. ChroResponseMatrix - Chromaticity response matrix {Default: getchroresp}
12%  3. ActuatorFamily -  Sextupoles to vary, ex {'S9', 'S10'} {Default: findmemberof('Chromaticity Corrector')'}
13%  4. Optional override of the units:
14%     'Physics'  - Use physics  units
15%     'Hardware' - Use hardware units
16%  5. Optional override of the mode:
17%     'Online'    - Set/Get data online 
18%     'Model'     - Set/Get data on the simulated accelerator using AT
19%     'Simulator' - Set/Get data on the simulated accelerator using AT
20%     'Manual'    - Set/Get data manually
21%
22%
23%  OUTPUTS
24%  1. DelSext
25%  2. SextFamily - Families used (cell array)
26%
27%  ALGORITHM 
28%     SVD method
29%  DelSext = inv(CHROMATICITY_RESP_MATRIX) * DeltaChromaticity
30%
31%  NOTES
32%  1. Beware of what units you are working in.  The default units for chromaticity
33%     are physics units.  This is an exception to the normal middle layer convention.
34%     Hardware units for "chromaticity" is in tune change per change in RF frequency. 
35%     Since this is an unusual unit to work with, the default units for chromaticity
36%     is physics units.  Note that goal chromaticity is also stored in physics units.
37%  2. The actuator family comes from findmemberof('Chromaticity Corrector') or 'SF','SD' if empty
38
39%  EXAMPLES
40%  1. use default families
41%      stepchro([1 0.5])
42%  2. use 10 families
43%    Sfam = {'S1','S2','S3','S4','S5','S6','S7','S8','S9','S10'};
44%    B = measchroresp('Model','Display',Sfam);
45%    stepchro([1 0.5],'Model',B,Sfam)
46%  3. To know by how much chromaticity change
47%     getchroresp('Hardware')*[-31; 8]*getmcf*getrf
48%
49%  See Also setchro
50
51%
52%  Written by Gregory J. Portmann
53%  Modifed by Laurent S. Nadolski
54%  add ActuatorFamily as optional input
55
56ModeFlag = {};
57UnitsFlag = {'Physics'};
58
59for i = length(varargin):-1:1
60    if strcmpi(varargin{i},'Physics')
61        UnitsFlag = varargin(i);
62        varargin(i) = [];
63    elseif strcmpi(varargin{i},'Hardware')
64        UnitsFlag = varargin(i);
65        varargin(i) = [];
66    elseif strcmpi(varargin{i},'Simulator') | strcmpi(varargin{i},'Model')
67        ModeFlag = varargin(i);
68        varargin(i) = [];
69    elseif strcmpi(varargin{i},'Online')
70        ModeFlag = varargin(i);
71        varargin(i) = [];
72    elseif strcmpi(varargin{i},'Manual')
73        ModeFlag = varargin(i);
74        varargin(i) = [];
75    end       
76end
77
78
79if length(varargin) >= 1
80    DeltaChrom = varargin{1};
81else
82    DeltaChrom = [];   
83end
84if isempty(DeltaChrom)
85    answer = inputdlg({'Change the horizontal chromaticity by', 'Change the vertical chromaticity by'},'STEPCHRO',1,{'0','0'});
86    if isempty(answer)
87        return
88    end
89    DeltaChrom(1,1) = str2num(answer{1});
90    DeltaChrom(2,1) = str2num(answer{2});
91end
92DeltaChrom = DeltaChrom(:);
93if size(DeltaChrom,1) ~= 2
94    error('Input must be a 2x1 column vector.');
95end
96if DeltaChrom(1)==0 && DeltaChrom(2)==0
97    return
98end
99
100if length(varargin) >= 2
101    ChroResponseMatrix = varargin{2};
102else
103    ChroResponseMatrix = [];   
104end
105if isempty(ChroResponseMatrix)
106    ChroResponseMatrix = getchroresp(UnitsFlag{:});
107end
108if isempty(ChroResponseMatrix)
109    error('The chromaticity response matrix must be an input or available in one of the default response matrix files.');
110end
111
112if length(varargin) >= 3
113    ActuatorFamily = varargin{3};
114else
115    ActuatorFamily = findmemberof('Chromaticity Corrector')';
116    if isempty(ActuatorFamily)
117        ActuatorFamily = {'S9','S10'};
118    end
119end
120
121% 1. SVD Tune Correction
122% Decompose the chromaticity response matrix:
123[U, S, V] = svd(ChroResponseMatrix, 'econ');
124% ChroResponseMatrix = U*S*V'
125%
126% The V matrix columns are the singular vectors in the sextupole magnet space
127% The U matrix columns are the singular vectors in the chromaticity space
128% U'*U=I and V*V'=I
129%
130% CHROCoef is the projection onto the columns of ChroResponseMatrix*V(:,Ivec) (same space as spanned by U)
131% Sometimes it's interesting to look at the size of these coefficients with singular value number.
132CHROCoef = diag(diag(S).^(-1)) * U' * DeltaChrom;
133%
134% Convert the vector CHROCoef back to coefficents of ChroResponseMatrix
135DelSext = V * CHROCoef;
136
137
138% 2. Square matrix solution
139%DelSext = inv(ChroResponseMatrix) * DeltaChrom;
140
141
142SP = getsp(ActuatorFamily, UnitsFlag{:}, ModeFlag{:});
143
144if iscell(SP)
145    for i = 1:length(SP)
146        SP{i} = SP{i} + DelSext(i);
147    end
148else
149    SP = SP + DelSext;
150end
151
152
153setsp(ActuatorFamily, SP, UnitsFlag{:}, ModeFlag{:});
154
Note: See TracBrowser for help on using the repository browser.