source: MML/trunk/mml/getenergy.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 3.5 KB
Line 
1function [Energy, HCMEnergy] = getenergy(varargin)
2%GETENERGY - Returns the beam energy base on the bend magnet
3%  [Energy, HCMEnergy] = getenergy(Keyword)
4%
5%  Keyword can be:
6%  'Production'         - Energy of the production lattice
7%  'Injection'          - Energy of the injection lattice
8%  'Model' or Simulator - Energy based on the model bend magnet (bend2gev('Model'))
9%  'Online'             - Energy based on the online bend magnet (bend2gev('Online'))
10%  'Present'            - Energy based on the present bend magnet mode (bend2gev)   {Default}
11%
12%  OUTPUTS
13%  1. Energy - Main storage ring energy (usually based on the BEND magnet) [GeV]
14%  2. HCMEnergy - Energy change due to all the horizontal corrector magnets [dE/E]
15%                 Algorithm:  dE/E = sum(-HCM * DxHCM / getmcf / L)
16%
17%  See also plotcm
18
19%
20%  Written by Gregory J. Portmann
21
22
23for i = length(varargin):-1:1
24    if strcmpi(varargin{i},'Production')
25       
26        Energy = getfamilydata('Energy');
27
28        if nargout >= 2
29            FamilyCell = findmemberof('HCM');
30            if isempty(FamilyCell)
31                Family = gethcmfamily;
32            else
33                Family = FamilyCell{1};
34            end
35            SP = getproductionlattice;
36            HCMEnergy = gethcmenergylocal(SP.(Family).Setpoint);
37        end
38        return
39
40    elseif strcmpi(varargin{i},'Injection')
41       
42        Energy = getfamilydata('InjectionEnergy');
43
44        if nargout >= 2
45            FamilyCell = findmemberof('HCM');
46            if isempty(FamilyCell)
47                Family = gethcmfamily;
48            else
49                Family = FamilyCell{1};
50            end
51            SP = getinjectionlattice;
52            HCMEnergy = gethcmenergylocal(SP.(Family).Setpoint);
53        end
54        return
55   
56    elseif strcmpi(varargin{i},'Present')
57       
58        Energy = bend2gev;
59
60        if nargout >= 2
61            HCMEnergy = gethcmenergylocal(SP.(Family));
62        end
63        return
64   
65    elseif strcmpi(varargin{i},'Model') | strcmpi(varargin{i},'Simulator')
66       
67        Energy = bend2gev('Model');
68
69        if nargout >= 2
70            FamilyCell = findmemberof('HCM');
71            if isempty(FamilyCell)
72                Family = gethcmfamily;
73            else
74                Family = FamilyCell{1};
75            end
76            HCMEnergy = gethcmenergylocal(getsp(Family, 'Model', 'Struct'));
77        end
78        return
79   
80    elseif strcmpi(varargin{i},'Online')
81   
82        Energy = bend2gev('Online');
83
84        if nargout >= 2
85            FamilyCell = findmemberof('HCM');
86            if isempty(FamilyCell)
87                Family = gethcmfamily;
88            else
89                Family = FamilyCell{1};
90            end
91            HCMEnergy = gethcmenergylocal(getsp(Family, 'Online', 'Struct'));
92        end
93        return
94   
95    end
96end
97
98% Default
99Energy = bend2gev;
100%Energy = getfamilydata('Energy');
101Energy = Energy(1);
102
103if nargout >= 2
104    HCMEnergy = gethcmenergylocal;
105end
106
107
108
109function HCMEnergy = gethcmenergylocal(HCMStruct);
110
111if nargin == 0
112    % Get the energy change of the horizontal correctors
113    FamilyCell = findmemberof('HCM');
114    if isempty(FamilyCell)
115        Family = gethcmfamily;
116    else
117        Family = FamilyCell{1};
118    end
119
120    HCMStruct = getsp(Family, 'Struct');
121end
122
123% Compute the energy change due to the correctors
124L = getfamilydata('Circumference');
125
126HCM = hw2physics(HCMStruct);
127HCM = HCM.Data;
128
129[DxHCM, DyHCM] = modeldisp([], HCMStruct.FamilyName, HCMStruct.DeviceList, 'Physics');
130HCMEnergyChange = -1 *HCM.*DxHCM / getmcf / L;
131HCMEnergy = sum(HCMEnergyChange);
Note: See TracBrowser for help on using the repository browser.