1 | function updateatindex |
---|
2 | %UPDATEATINDEX - Updates the AT indices in the MiddleLayer with the present AT lattice (THERING) |
---|
3 | |
---|
4 | % |
---|
5 | % Adapted by Laurent S. Nadolski |
---|
6 | |
---|
7 | global THERING |
---|
8 | |
---|
9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
10 | % Append Accelerator Toolbox information % |
---|
11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
12 | |
---|
13 | % Since changes in the AT model could change the AT indexes, etc, |
---|
14 | % It's best to regenerate all the model indices whenever a model is loaded |
---|
15 | |
---|
16 | % Sort by family first (findcells is linear and slow) |
---|
17 | Indices = atindex(THERING); |
---|
18 | |
---|
19 | AO = getao; |
---|
20 | |
---|
21 | % CORRECTORS |
---|
22 | try |
---|
23 | %% HORIZONTAL CORRECTORS |
---|
24 | ifam = ('CH'); |
---|
25 | AO.(ifam).AT.ATType = ifam; |
---|
26 | AO.(ifam).AT.ATIndex = Indices.(ifam)(:); |
---|
27 | AO.(ifam).AT.ATIndex = AO.(ifam).AT.ATIndex(AO.(ifam).ElementList); %not all correctors used |
---|
28 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
29 | |
---|
30 | %% VERTICAL CORRECTORS |
---|
31 | ifam = ('CV'); |
---|
32 | AO.(ifam).AT.ATType = ifam; |
---|
33 | AO.(ifam).AT.ATIndex = Indices.(ifam)(:); |
---|
34 | AO.(ifam).AT.ATIndex = AO.(ifam).AT.ATIndex(AO.(ifam).ElementList); %not all correctors used |
---|
35 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
36 | catch |
---|
37 | warning('Corrector family not found in the model.'); |
---|
38 | end |
---|
39 | |
---|
40 | |
---|
41 | % QUADRUPOLES |
---|
42 | try |
---|
43 | ifam = 'QP'; |
---|
44 | AO.(ifam).AT.ATType = 'QUAD'; |
---|
45 | AO.(ifam).AT.ATIndex = eval(['Indices.' ifam '(:)']); |
---|
46 | AO.(ifam).AT.ATIndex = reshape(AO.(ifam).AT.ATIndex,2,7)'; |
---|
47 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
48 | catch |
---|
49 | warning('%s family not found in the model.',ifam); |
---|
50 | end |
---|
51 | |
---|
52 | % BEND |
---|
53 | |
---|
54 | try |
---|
55 | ifam = ('BEND'); |
---|
56 | AO.(ifam).AT.ATType = ifam; |
---|
57 | ATIndex = Indices.(ifam)(:); |
---|
58 | AO.(ifam).AT.ATIndex = buildatindex(AO.(ifam).FamilyName, sort(ATIndex)); |
---|
59 | AO.(ifam).Position = findspos(THERING, AO.(ifam).AT.ATIndex(:,1))'; |
---|
60 | catch |
---|
61 | warning('BEND family not found in the model.'); |
---|
62 | end |
---|
63 | |
---|
64 | setao(AO); |
---|
65 | |
---|
66 | % Set TwissData at the start of TL1 |
---|
67 | try |
---|
68 | % BTS twiss parameters at the input |
---|
69 | TwissData.alpha = [0 0]'; |
---|
70 | TwissData.beta = [8.1 8.1]'; |
---|
71 | TwissData.mu = [0 0]'; |
---|
72 | TwissData.ClosedOrbit = [0 0 0 0]'; |
---|
73 | TwissData.dP = 0; |
---|
74 | TwissData.dL = 0; |
---|
75 | TwissData.Dispersion = [0 0 0 0]'; |
---|
76 | |
---|
77 | setpvmodel('TwissData', '', TwissData); % Same as, THERING{1}.TwissData = TwissData; |
---|
78 | |
---|
79 | catch |
---|
80 | warning('Setting the twiss data parameters in the MML failed.'); |
---|
81 | end |
---|