|
1 | 1 | function ring = atsetcavity(ring,varargin) |
2 | | -%ATSECAVITY Set the cavity parameters |
| 2 | +%ATSECAVITY Set the parameters of RF cavities |
3 | 3 | % |
4 | 4 | %WARNING: This function modifies the time reference, |
5 | 5 | %this should be avoided |
|
46 | 46 | %=================================================== |
47 | 47 | %NEWRING = ATSETCAVITY(RING,RFV,RADFLAG,HARM_NUMBER) |
48 | 48 | % RING Ring structure |
49 | | -% RFV RF voltage (per cell) [V] |
| 49 | +% RFV RF voltage (full ring) [V] |
50 | 50 | % RADFLAG 0/1: activate/desactivate radiation (atradon/atradoff) |
51 | | -% HARMNUMBER Harmonic number (for 1 cell) |
| 51 | +% HARMNUMBER Harmonic number (full ring) |
52 | 52 | % |
53 | 53 | % NOTES |
54 | 54 | % 1. This mode is deprecated and should be replaced by |
|
66 | 66 | % Speed of light |
67 | 67 | CLIGHT=PhysConstant.speed_of_light_in_vacuum.value; |
68 | 68 |
|
69 | | -[props,idx]=atGetRingProperties(ring); |
70 | | -[cavpts,varargs]=getcavptsarg(varargin,ring,props); |
| 69 | +[cavpts,varargs]=getoption(varargin,'cavpts',[]); |
71 | 70 | [frequency,varargs]=getoption(varargs, 'Frequency', []); |
72 | 71 | [harmnumber,varargs]=getoption(varargs, 'HarmNumber',[]); |
73 | 72 | [vring,varargs]=getoption(varargs, 'Voltage', []); |
| 73 | +[vcell,varargs]=getoption(varargs, 'cell_voltage', []); |
74 | 74 | [timelag,varargs]=getoption(varargs, 'TimeLag', []); |
75 | 75 | [dp,varargs]=getoption(varargs,'dp',NaN); |
76 | 76 | [dct,varargs]=getoption(varargs,'dct',NaN); |
77 | 77 |
|
78 | | -ncells=props.Periodicity; |
| 78 | +if isempty(cavpts) |
| 79 | + [ncells,cell_h,beta0,cavpts]=atGetRingProperties(ring,'Periodicity','cell_harmnumber','beta','cavpts'); |
| 80 | +else |
| 81 | + [ncells,cell_h,beta0]=atGetRingProperties(ring,'Periodicity','cell_harmnumber','beta'); |
| 82 | +end |
79 | 83 | cavities=ring(cavpts); |
80 | 84 | ncavs=length(cavities); |
81 | 85 | if ncavs == 0 |
82 | 86 | error('AT:NoCavity', 'No cavity found in the lattice'); |
83 | 87 | end |
84 | 88 |
|
85 | 89 | if isempty(varargs) % New syntax |
| 90 | + if isempty(harmnumber) |
| 91 | + harmcell=[]; |
| 92 | + else |
| 93 | + harmcell=harmnumber/ncells; |
| 94 | + end |
86 | 95 | if ~isempty(frequency) |
87 | 96 | lcell=findspos(ring,length(ring)+1); |
88 | | - gamma0=props.Energy/props.Particle.rest_energy; |
89 | | - beta0=sqrt(1-1/gamma0/gamma0); |
90 | | - frev=beta0*CLIGHT/lcell/ncells; |
| 97 | + frev=beta0*CLIGHT/lcell; |
91 | 98 | if (ischar(frequency) || isstring(frequency)) && strcmp(frequency, 'nominal') |
92 | 99 | if isfinite(dct) |
93 | 100 | frev=frev * lcell/(lcell+dct); |
|
99 | 106 | dct=orbitout(6); |
100 | 107 | frev=frev * lcell/(lcell+dct); |
101 | 108 | end |
102 | | - frequency = frev * props_harmnumber(harmnumber,props); |
| 109 | + frequency = frev * props_harmnumber(harmcell,cell_h); |
103 | 110 | else |
104 | | - harmnumber=round(frequency/frev); |
| 111 | + harmcell=round(frequency/frev); |
105 | 112 | end |
106 | 113 | cavities=atsetfieldvalues(cavities, 'Frequency', frequency); |
107 | 114 | end |
108 | 115 | if ~isempty(vring) |
109 | 116 | cavities=atsetfieldvalues(cavities, 'Voltage', vring/ncells/ncavs); |
110 | 117 | end |
| 118 | + if ~isempty(vcell) |
| 119 | + cavities=atsetfieldvalues(cavities, 'Voltage', vring/ncavs); |
| 120 | + end |
111 | 121 | if ~isempty(timelag) |
112 | 122 | cavities=atsetfieldvalues(cavities, 'TimeLag', timelag); |
113 | 123 | end |
114 | 124 | ring(cavpts)=cavities; |
115 | 125 | else % Old syntax, for compatibility |
116 | | - [vcell,radflag,harmnumber]=deal(varargin{:}); |
| 126 | + [vring,radflag,harmnumber]=deal(varargin{:}); |
117 | 127 | harmcell=harmnumber/ncells; |
118 | 128 | lcell=findspos(ring,length(ring)+1); |
119 | | - gamma0=props.Energy/props.Particle.rest_energy; |
120 | | - beta0=sqrt(1-1/gamma0/gamma0); |
121 | 129 | frequency = (beta0*CLIGHT/lcell)*harmcell; |
122 | 130 |
|
123 | 131 | %now set cavity frequencies, Harmonic Number and RF Voltage |
124 | 132 | cavities=atsetfieldvalues(cavities, 'Frequency', frequency); |
125 | 133 | cavities=atsetfieldvalues(cavities, 'HarmNumber', harmnumber); |
126 | | - cavities=atsetfieldvalues(cavities, 'Voltage', vcell/ncavs); |
| 134 | + cavities=atsetfieldvalues(cavities, 'Voltage', vring/ncavs); |
127 | 135 | ring(cavpts)=cavities; |
128 | 136 |
|
129 | 137 | %now set phaselags in cavities |
130 | 138 | if radflag |
131 | 139 | U0=atgetU0(ring); |
132 | | - timelag= (lcell/(2*pi*harmcell))*asin(U0/vcell/ncells); |
| 140 | + timelag= (lcell/(2*pi*harmcell))*asin(U0/vring); |
133 | 141 | ring=atradon(ring); % set radiation on. nothing if radiation is already on |
134 | 142 | else |
135 | 143 | ring=atradoff(ring,'RFCavityPass'); % set radiation off. nothing if radiation is already off |
|
139 | 147 | end |
140 | 148 |
|
141 | 149 | % Update the ring properties if HarmNumber has changed |
142 | | -if ~(isempty(idx) || isempty(harmnumber) || ... |
143 | | - (isfield(props, 'HarmNumber') && harmnumber == props.HarmNumber)) |
144 | | - ring=atSetRingProperties(ring,'HarmNumber',harmnumber); |
| 150 | +idx=atlocateparam(ring); |
| 151 | +if ~(isempty(idx) || isempty(harmcell) || ... |
| 152 | + (harmcell == cell_h)) |
| 153 | + ring=atSetRingProperties(ring,'cell_harmnumber',harmcell); |
145 | 154 | end |
146 | 155 |
|
147 | | - function h=props_harmnumber(h, props) |
148 | | - if isempty(h) |
149 | | - if isfield(props,'HarmNumber') && props.HarmNumber ~= 0 |
150 | | - h=props.HarmNumber; |
151 | | - else |
| 156 | + function cellharm=props_harmnumber(cellharm, cell_h) |
| 157 | + if isempty(cellharm) |
| 158 | + if ~isfinite(cell_h) |
152 | 159 | error('AT:NoCavity','Harmonic number is unknown') |
153 | 160 | end |
| 161 | + cellharm=cell_h; |
154 | 162 | end |
155 | 163 | end |
156 | 164 | end |
0 commit comments