Skip to content

Commit

Permalink
Bug fix in atgeometry (#667)
Browse files Browse the repository at this point in the history
Bug fix for the 'centered' option, added refpts input in pyat.
  • Loading branch information
lfarv authored Oct 26, 2023
1 parent 79fd464 commit 52298a9
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 76 deletions.
2 changes: 1 addition & 1 deletion atmat/Contents.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Accelerator Toolbox
% Version 2.4.1 (#657) 18-Sep-2023
% Version 2.4.1 (#667) 05-Oct-2023
%
% atdiag - Tests AT intallation
% atdisplay - checks the verbosity level in the global variable GLOBVAL
Expand Down
2 changes: 1 addition & 1 deletion atmat/at.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Accelerator Toolbox
% Version 2.4.1 (#657) 18-Sep-2023
% Version 2.4.1 (#667) 05-Oct-2023
%
% The Accelerator Toolbox was originally created by Andrei Terebilo.
% Development is now continued by a multi-laboratory collaboration, <a href="matlab:web('https://github.com/atcollab')">atcollab</a>
Expand Down
47 changes: 32 additions & 15 deletions atmat/lattice/survey/atgeometry.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,53 @@
%
%[POSDATA,RADIUS]=ATGEOMETRY(RING,REFPTS)
% Outputs the machine radius at the beginning of the lattice.
% Meaningful if RING is a cell of a periodic lattice.
%
%POSDATA=ATGEOMETRY(RING,REFPTS,OFFSET)
% Start at x=offset(1), y=offset(2)
% a scalar offset value is equivalent to [0 OFFSET]
% Note: this is different from the radius usually defined as
% circumference/2/pi
%
%POSDATA=ATGEOMETRY(...,'centered')
% The offset is set as [0 RADIUS 0]
% The offset is set so that the origin is at the centre of the ring
%
%POSDATA=ATGEOMETRY(RING,REFPTS,OFFSET)
% Start at x=offset(1), y=offset(2). Ignored if 'centered' is set.
% A scalar offset value is equivalent to [0 OFFSET].
%
%POSDATA=ATGEOMETRY(...,'Hangle',h_angle)
% Set the initial trajectory angle
%
%
%See also: ATGEOMETRY3

[thetac,args]=getoption(varargin,'Hangle',0);
centered=getflag(args,'centered');
[refpts,offset]=parseargs({1:length(ring)+1,[0 0]},args);
epsil=1.e-3;
[centered,args]=getflag(varargin,'centered');
[theta0,args]=getoption(args,'Hangle',0);
[refpts,offset]=getargs(args,1:length(ring)+1,[0 0]);
xc=0;
yc=0;
thetac=theta0;
if isscalar(offset)
yc=offset;
else
xc=offset(1);
yc=offset(2);
offset=[0 offset];
end
[xx,yy,txy,lg,tr]=cellfun(@incr,[{struct()};ring]); % Add a dummy element to get the origin
radius=-(yc+xc/tan(thetac));
dff=mod(thetac+epsil, 2*pi)-epsil;
if abs(dff) < epsil % Full ring
xcenter=mean(xx);
ycenter=mean(yy);
elseif abs(dff-pi) < epsil % Half ring
xcenter=0.5*xc;
ycenter=0.5*yc;
else % Single cell
num=cos(thetac)*xc + sin(thetac)*yc;
den=sin(thetac-theta0);
xcenter=-num*sin(theta0)/den;
ycenter= num*cos(theta0)/den;
end
radius=sqrt(xcenter*xcenter+ycenter*ycenter);
if centered
yy=yy+radius;
xx=xx-xcenter;
yy=yy-ycenter;
else
xx=xx+offset(1);
yy=yy+offset(2);
end
posdata=struct('x',num2cell(xx(refpts)),'y',num2cell(yy(refpts)),...
'angle',num2cell(txy(refpts)),'long',num2cell(lg(refpts)),...
Expand Down
Loading

0 comments on commit 52298a9

Please sign in to comment.