Skip to content

Commit 32a8ade

Browse files
authored
Matlab ring properties (#443)
* rebased on master * Make use of the new properties * Small improvements in help * Added help in guthubsetup, githubrun. Partial tests on ubuntu * Increment version number * Added two properties: 'radiation' and 'active_cavity' * tunes pytests * More efficient search for 'radiation' * BRho * bug fix * Fix compatibility with old Matlab versions * 'all' keyword * Checks periodicity input * tuning of function helps * freeze the pydata-sphinx-theme version
1 parent 40c29fe commit 32a8ade

File tree

26 files changed

+828
-506
lines changed

26 files changed

+828
-506
lines changed

.github/workflows/matlab-tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
strategy:
2222
matrix:
23-
os: [macos-latest, windows-latest]
23+
os: [ubuntu-latest, macos-latest, windows-latest]
2424

2525
steps:
2626

@@ -39,15 +39,16 @@ jobs:
3939
- name: Atmexall
4040
uses: matlab-actions/run-command@v1
4141
with:
42-
command: run('atmat/atpath');githubsetup('InProcess');
42+
command: run('atmat/atpath');githubsetup();
4343

4444
- name: Build and install at
45-
run: python -m pip install -e "./pyat[dev]"
45+
working-directory: ./pyat
46+
run: python -m pip install .
4647

4748
- name: Run tests
4849
uses: matlab-actions/run-command@v1
4950
with:
50-
command: disp(table(assertSuccess(run(testsuite('atmat/attests')))))
51+
command: githubrun
5152
#
5253
# - name: Set up Matlab engine for python
5354
# run: python setup.py build --build-base=$(mktemp -d) install

atmat/Contents.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
% Accelerator Toolbox
2-
% Version 2.3 (atcollab) 01-Apr-2022
2+
% Version 2.4-dev443 (atcollab) 20-Jul-2022
33
%
44
% atdiag - Tests AT intallation
55
% atdisplay - checks the verbosity level in the global variable GLOBVAL

atmat/at.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
% Accelerator Toolbox
2-
% Version 2.3 (atcollab) 01-Apr-2022
2+
% Version 2.4-dev443 (atcollab) 20-Jul-2022
33
%
44
% The Accelerator Toolbox was originally created by Andrei Terebilo.
55
% Development is now continued by a multi-laboratory collaboration, <a href="matlab:web('https://github.com/atcollab')">atcollab</a>
@@ -140,4 +140,4 @@
140140
%
141141
% <a href="matlab:help symplectify">symplectify</a> - Makes a matrix more symplectic
142142
%
143-
%<a href="matlab:web('/Applications/MATLAB_R2022a.app/help/3ptoolbox/atacceleratortoolbox/doc/AT_page.html')">See documentation for AT</a>
143+
%<a href="matlab:web('/Applications/MATLAB_R2021a.app/help/3ptoolbox/atacceleratortoolbox/doc/AT_page.html')">See documentation for AT</a>

atmat/atphysics/LinearOptics/atlinopt6.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
[dpargs,varargs]=getoption(varargs,{'orbit','dp','dct'});
8787
[twiss_in,varargs]=getoption(varargs,'twiss_in',[]);
8888
[DPStep,~]=getoption(varargs,'DPStep');
89-
[cavpts,varargs]=getoption(varargs,'cavpts',[]);
89+
[cavargs,varargs]=getoption(varargs,{'cavpts'});
9090
[refpts,varargs]=getargs(varargs,1,'check',@(arg) isnumeric(arg) || islogical(arg));
9191

9292
if isempty(twiss_in) % Circular machine
@@ -122,8 +122,8 @@
122122
if get_w || get_chrom
123123
frf=get_rf_frequency(ring);
124124
DFStep=-DPStep*mcf(atradoff(ring))*frf;
125-
rgup=atsetcavity(ring,'Frequency',frf+0.5*DFStep,'cavpts',cavpts);
126-
rgdn=atsetcavity(ring,'Frequency',frf-0.5*DFStep,'cavpts',cavpts);
125+
rgup=atsetcavity(ring,'Frequency',frf+0.5*DFStep,cavargs{:});
126+
rgdn=atsetcavity(ring,'Frequency',frf-0.5*DFStep,cavargs{:});
127127
[~,o1P]=findorbit(rgup,'guess',orbitin,varargs{:});
128128
[~,o1M]=findorbit(rgdn,'guess',orbitin,varargs{:});
129129
if get_w

atmat/atphysics/LongitudinalDynamics/atsetcavity.m

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function ring = atsetcavity(ring,varargin)
2-
%ATSECAVITY Set the cavity parameters
2+
%ATSECAVITY Set the parameters of RF cavities
33
%
44
%WARNING: This function modifies the time reference,
55
%this should be avoided
@@ -46,9 +46,9 @@
4646
%===================================================
4747
%NEWRING = ATSETCAVITY(RING,RFV,RADFLAG,HARM_NUMBER)
4848
% RING Ring structure
49-
% RFV RF voltage (per cell) [V]
49+
% RFV RF voltage (full ring) [V]
5050
% RADFLAG 0/1: activate/desactivate radiation (atradon/atradoff)
51-
% HARMNUMBER Harmonic number (for 1 cell)
51+
% HARMNUMBER Harmonic number (full ring)
5252
%
5353
% NOTES
5454
% 1. This mode is deprecated and should be replaced by
@@ -66,28 +66,35 @@
6666
% Speed of light
6767
CLIGHT=PhysConstant.speed_of_light_in_vacuum.value;
6868

69-
[props,idx]=atGetRingProperties(ring);
70-
[cavpts,varargs]=getcavptsarg(varargin,ring,props);
69+
[cavpts,varargs]=getoption(varargin,'cavpts',[]);
7170
[frequency,varargs]=getoption(varargs, 'Frequency', []);
7271
[harmnumber,varargs]=getoption(varargs, 'HarmNumber',[]);
7372
[vring,varargs]=getoption(varargs, 'Voltage', []);
73+
[vcell,varargs]=getoption(varargs, 'cell_voltage', []);
7474
[timelag,varargs]=getoption(varargs, 'TimeLag', []);
7575
[dp,varargs]=getoption(varargs,'dp',NaN);
7676
[dct,varargs]=getoption(varargs,'dct',NaN);
7777

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
7983
cavities=ring(cavpts);
8084
ncavs=length(cavities);
8185
if ncavs == 0
8286
error('AT:NoCavity', 'No cavity found in the lattice');
8387
end
8488

8589
if isempty(varargs) % New syntax
90+
if isempty(harmnumber)
91+
harmcell=[];
92+
else
93+
harmcell=harmnumber/ncells;
94+
end
8695
if ~isempty(frequency)
8796
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;
9198
if (ischar(frequency) || isstring(frequency)) && strcmp(frequency, 'nominal')
9299
if isfinite(dct)
93100
frev=frev * lcell/(lcell+dct);
@@ -99,37 +106,38 @@
99106
dct=orbitout(6);
100107
frev=frev * lcell/(lcell+dct);
101108
end
102-
frequency = frev * props_harmnumber(harmnumber,props);
109+
frequency = frev * props_harmnumber(harmcell,cell_h);
103110
else
104-
harmnumber=round(frequency/frev);
111+
harmcell=round(frequency/frev);
105112
end
106113
cavities=atsetfieldvalues(cavities, 'Frequency', frequency);
107114
end
108115
if ~isempty(vring)
109116
cavities=atsetfieldvalues(cavities, 'Voltage', vring/ncells/ncavs);
110117
end
118+
if ~isempty(vcell)
119+
cavities=atsetfieldvalues(cavities, 'Voltage', vring/ncavs);
120+
end
111121
if ~isempty(timelag)
112122
cavities=atsetfieldvalues(cavities, 'TimeLag', timelag);
113123
end
114124
ring(cavpts)=cavities;
115125
else % Old syntax, for compatibility
116-
[vcell,radflag,harmnumber]=deal(varargin{:});
126+
[vring,radflag,harmnumber]=deal(varargin{:});
117127
harmcell=harmnumber/ncells;
118128
lcell=findspos(ring,length(ring)+1);
119-
gamma0=props.Energy/props.Particle.rest_energy;
120-
beta0=sqrt(1-1/gamma0/gamma0);
121129
frequency = (beta0*CLIGHT/lcell)*harmcell;
122130

123131
%now set cavity frequencies, Harmonic Number and RF Voltage
124132
cavities=atsetfieldvalues(cavities, 'Frequency', frequency);
125133
cavities=atsetfieldvalues(cavities, 'HarmNumber', harmnumber);
126-
cavities=atsetfieldvalues(cavities, 'Voltage', vcell/ncavs);
134+
cavities=atsetfieldvalues(cavities, 'Voltage', vring/ncavs);
127135
ring(cavpts)=cavities;
128136

129137
%now set phaselags in cavities
130138
if radflag
131139
U0=atgetU0(ring);
132-
timelag= (lcell/(2*pi*harmcell))*asin(U0/vcell/ncells);
140+
timelag= (lcell/(2*pi*harmcell))*asin(U0/vring);
133141
ring=atradon(ring); % set radiation on. nothing if radiation is already on
134142
else
135143
ring=atradoff(ring,'RFCavityPass'); % set radiation off. nothing if radiation is already off
@@ -139,18 +147,18 @@
139147
end
140148

141149
% 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);
145154
end
146155

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)
152159
error('AT:NoCavity','Harmonic number is unknown')
153160
end
161+
cellharm=cell_h;
154162
end
155163
end
156164
end

0 commit comments

Comments
 (0)