[5] | 1 | function updateatindex |
---|
| 2 | %UPDATEATINDEX - Updates the AT indices in the MiddleLayer with the |
---|
| 3 | %present AT lattice (THERING), depends on the Lattice |
---|
| 4 | % element types which are defined in thomxinit.m |
---|
| 5 | % |
---|
| 6 | % |
---|
| 7 | % Modified for ThomX machine by Jianfeng Zhang @ LAL, 21/06/2013 |
---|
| 8 | % |
---|
| 9 | % |
---|
| 10 | % Adapted by Laurent S. Nadolski |
---|
| 11 | % Modified 21 November Nanoscopium S11/S12 missing Atgroupparameter |
---|
[27] | 12 | % |
---|
| 13 | % |
---|
| 14 | % |
---|
| 15 | % Needs to be modified when the ThomX machine & Tango is ready... |
---|
| 16 | % Needs to be carefully tested...by Zhang @ LAL, 02/2014. |
---|
| 17 | % |
---|
| 18 | % |
---|
| 19 | % |
---|
| 20 | %24/02/2014 by Jianfeng Zhang @ LAL |
---|
| 21 | % Fix the bug to set/get value of the individual sextupole family member. |
---|
| 22 | % |
---|
[5] | 23 | |
---|
| 24 | global THERING |
---|
| 25 | |
---|
| 26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 27 | % Append Accelerator Toolbox information % |
---|
| 28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 29 | |
---|
| 30 | % Since changes in the AT model could change the AT indexes, etc, |
---|
| 31 | % It's best to regenerate all the model indices whenever a model is loaded |
---|
| 32 | |
---|
| 33 | % Sort by family first (findcells is linear and slow) |
---|
| 34 | Indices = atindex(THERING); |
---|
| 35 | |
---|
| 36 | AO = getao; |
---|
| 37 | |
---|
| 38 | %% BPMS |
---|
| 39 | try |
---|
| 40 | ifam = 'BPMx'; |
---|
| 41 | AO.(ifam).AT.ATType = 'X'; |
---|
| 42 | AO.(ifam).AT.ATIndex = Indices.BPMx(:); % findcells(THERING,'FamName','BPM')'; |
---|
| 43 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex)'; |
---|
| 44 | |
---|
| 45 | ifam = 'BPMz'; |
---|
| 46 | AO.(ifam).AT.ATType = 'Z'; |
---|
| 47 | AO.(ifam).AT.ATIndex = Indices.BPMz(:); % findcells(THERING,'FamName','BPM')'; |
---|
| 48 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex)'; |
---|
| 49 | |
---|
| 50 | catch err |
---|
| 51 | warning('MML:wrongfamily', '%s family not found in the model.', ifam); |
---|
| 52 | fprintf('Message: %s\n', err.message); |
---|
| 53 | end |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | %% CORRECTORS |
---|
| 57 | try |
---|
| 58 | ifam = 'HCOR'; |
---|
| 59 | %% Horizontal correctors are at every AT corrector |
---|
| 60 | AO.(ifam).AT.ATType = ifam; |
---|
| 61 | AO.(ifam).AT.ATIndex = buildatindex(AO.(ifam).FamilyName, Indices.HCOR); |
---|
| 62 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
| 63 | |
---|
| 64 | %% Vertical correctors are at every AT corrector |
---|
| 65 | ifam = 'VCOR'; |
---|
| 66 | AO.(ifam).AT.ATType = ifam; |
---|
| 67 | AO.(ifam).AT.ATIndex = buildatindex(AO.(ifam).FamilyName, Indices.VCOR); |
---|
| 68 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | %% PX2 tuner correctors |
---|
| 72 | if isfield(AO,'PX2C') && isfield(Indices,'PX2C') |
---|
| 73 | ifam = 'PX2C'; |
---|
| 74 | AO.(ifam).AT.ATType = 'HCOR'; |
---|
| 75 | AO.(ifam).AT.ATIndex = buildatindex(AO.(ifam).FamilyName, Indices.PX2C); |
---|
| 76 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
| 77 | end |
---|
| 78 | |
---|
| 79 | catch err |
---|
| 80 | warning('MML:wrongfamily', 'Corrector family %s not found in the model.',ifam); |
---|
| 81 | fprintf('Message: %s\n', err.message); |
---|
| 82 | end |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | %% QUADRUPOLES |
---|
| 86 | try |
---|
| 87 | for k = 1:6, |
---|
| 88 | ifam = ['QP' num2str(k)]; |
---|
| 89 | if(k==5), ifam = 'QP31'; end; |
---|
| 90 | if(k==6), ifam = 'QP41'; end; |
---|
| 91 | AO.(ifam).AT.ATType = 'QUAD'; |
---|
| 92 | AO.(ifam).AT.ATIndex = buildatindex(AO.(ifam).FamilyName, Indices.(ifam)); |
---|
| 93 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
| 94 | end |
---|
| 95 | ifam = 'Qall'; |
---|
| 96 | AO.(ifam).AT.ATType = 'QUAD'; |
---|
| 97 | AO.(ifam).AT.ATIndex = [AO.QP1.AT.ATIndex; AO.QP2.AT.ATIndex; AO.QP3.AT.ATIndex; AO.QP31.AT.ATIndex; AO.QP41.AT.ATIndex;AO.QP4.AT.ATIndex]; |
---|
| 98 | AO.(ifam).Position = [AO.QP1.Position; AO.QP2.Position; AO.QP3.Position; AO.QP31.Position; AO.QP41.Position;AO.QP4.Position]; |
---|
| 99 | |
---|
| 100 | ifam = 'Qall'; |
---|
| 101 | %sort all s-position, mandatory for plotfamily |
---|
| 102 | [t idx] = sort(AO.(ifam).Position); |
---|
| 103 | AO.(ifam).Position = AO.(ifam).Position(idx); |
---|
| 104 | AO.(ifam).Setpoint.TangoNames = AO.(ifam).Setpoint.TangoNames(idx); |
---|
| 105 | AO.(ifam).Monitor.TangoNames = AO.(ifam).Monitor.TangoNames(idx); |
---|
| 106 | AO.(ifam).DeviceName = AO.(ifam).DeviceName(idx); |
---|
| 107 | AO.(ifam).Status = AO.(ifam).Status(idx); |
---|
| 108 | catch err |
---|
| 109 | warning('MML:wrongfamily', '%s family not found in the model.',ifam); |
---|
| 110 | fprintf('Message: %s\n', err.message); |
---|
| 111 | end |
---|
| 112 | |
---|
| 113 | %% SEXTUPOLES |
---|
| 114 | try |
---|
| 115 | for k = 1:3, |
---|
| 116 | ifam = ['SX' num2str(k)]; |
---|
| 117 | AO.(ifam).AT.ATType = 'SEXT'; |
---|
| 118 | AO.(ifam).AT.ATIndex = buildatindex(AO.(ifam).FamilyName, Indices.(ifam)); |
---|
| 119 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
[27] | 120 | % AO.(ifam).AT.ATParameterGroup{1} = mkparamgroup(THERING,AO.(ifam).AT.ATIndex,'K2'); |
---|
[5] | 121 | end |
---|
| 122 | ifam = 'Sall'; % take first element |
---|
| 123 | AO.(ifam).Position = [AO.SX1.Position(1); AO.SX2.Position(1); ... |
---|
| 124 | AO.SX3.Position(1)]; |
---|
| 125 | |
---|
| 126 | % ifam = 'Sall'; |
---|
| 127 | %sort all s-position, mandatory for plotfamily |
---|
| 128 | % Does not work for indivual sextupoles |
---|
| 129 | % [t idx] = sort(AO.(ifam).Position); |
---|
| 130 | % AO.(ifam).Position = AO.(ifam).Position(idx); |
---|
| 131 | % AO.(ifam).Setpoint.TangoNames = AO.(ifam).Setpoint.TangoNames(idx); |
---|
| 132 | % AO.(ifam).Monitor.TangoNames = AO.(ifam).Monitor.TangoNames(idx); |
---|
| 133 | % AO.(ifam).DeviceName = AO.(ifam).DeviceName(idx); |
---|
| 134 | % AO.(ifam).Status = AO.(ifam).Status(idx); |
---|
| 135 | catch err |
---|
| 136 | warning('MML:wrongfamily', 'Sextupole %s families not found in the model.', ifam); |
---|
| 137 | fprintf('Message: %s\n', err.message); |
---|
| 138 | end |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | %% BEND |
---|
| 142 | |
---|
| 143 | try |
---|
| 144 | % Combined BEND |
---|
| 145 | AO.BEND.AT.ATType = 'BEND'; |
---|
| 146 | ATIndex = Indices.BEND(:); |
---|
| 147 | AO.BEND.AT.ATIndex = buildatindex(AO.BEND.FamilyName, sort(ATIndex)); |
---|
| 148 | AO.BEND.Position = findspos(THERING, AO.BEND.AT.ATIndex(:,1))'; |
---|
| 149 | catch err |
---|
| 150 | warning('MML:wrongfamily', 'BEND family not found in the model.'); |
---|
| 151 | fprintf('Message: %s\n', err.message); |
---|
| 152 | end |
---|
| 153 | |
---|
| 154 | %% RF CAVITY |
---|
| 155 | try |
---|
| 156 | AO.RF.AT.ATType = 'RF Cavity'; |
---|
| 157 | AO.RF.AT.ATIndex = findcells(THERING,'Frequency')'; |
---|
| 158 | AO.RF.Position = findspos(THERING, AO.RF.AT.ATIndex(:,1))'; |
---|
| 159 | catch err |
---|
| 160 | warning('MML:wrongfamily', 'RF cavity not found in the model.'); |
---|
| 161 | fprintf('Message: %s\n', err.message); |
---|
| 162 | end |
---|
| 163 | |
---|
| 164 | setao(AO); |
---|
| 165 | |
---|
| 166 | %% Set TwissData at the start of the storage ring |
---|
| 167 | try |
---|
| 168 | |
---|
| 169 | % BTS twiss parameters at the input for transfer line |
---|
| 170 | TwissData.alpha = [0 0]'; |
---|
| 171 | TwissData.beta = [3.7 1.803]'; |
---|
| 172 | TwissData.mu = [0 0]'; |
---|
| 173 | TwissData.ClosedOrbit = [0 0 0 0]'; |
---|
| 174 | TwissData.dP = 0; |
---|
| 175 | TwissData.dL = 0; |
---|
| 176 | TwissData.Dispersion = [.01 0 0 0]'; |
---|
| 177 | |
---|
| 178 | setpvmodel('TwissData', '', TwissData); % Same as, THERING{1}.TwissData = TwissData; |
---|
| 179 | |
---|
| 180 | catch err |
---|
| 181 | warning('MML:wrongfamily','Setting the twiss data parameters in the MML failed.'); |
---|
| 182 | fprintf('Message: %s\n', err.message); |
---|
| 183 | end |
---|