Commit 3305c783 authored by Simone Liuzzo's avatar Simone Liuzzo
Browse files

Merge branch 'matching' into 'master'

Matching

See merge request !7
parents 4356fac0 28c25216
......@@ -29,7 +29,7 @@ function rcm = CantingOptics(rc,r,idnum, ploton, verbose)
[indidbc,~]=ebs.getcellstartend(rc,idnum-2);
% get target parametes (from lattice without canted beamline)
twi=atlinopt(r,0,1:indid);
[twi,~,~]=atlinopt(r,0,1:indid);
muxid=twi(end).mu(1)/2/pi;
muyid=twi(end).mu(2)/2/pi;
......@@ -70,14 +70,14 @@ v=[v,v12];
muxconstr=struct(...
'Fun',@(~,ld,~)mux(ld),...
'Weight',1e-3,...
'Weight',1e-3,...1,...
'RefPoints',(1:indidc+1),...
'Min',muxid,...
'Max',muxid);
muycontsr=struct(...
'Fun',@(~,ld,~)muy(ld),...
'Weight',1e-3,...
'Weight',1e-3,...1,...
'RefPoints',(1:indidc+1),...
'Min',muyid,...
'Max',muyid);
......@@ -96,9 +96,9 @@ rm34constr=struct(...
'Min',rm44_34a,...
'Max',rm44_34a);%
c=[ atlinconstraint(indidbc,{{'alpha',{1}}},0,0,1e-3)...
atlinconstraint(indidbc,{{'alpha',{2}}},0,0,1e-3)...
atlinconstraint(indidbc,{{'Dispersion',{2}}},0,0,1e-3)...
c=[ atlinconstraint(indidbc,{{'alpha',{1}}},0,0,1e-3)...1)...%
atlinconstraint(indidbc,{{'alpha',{2}}},0,0,1e-3)...1)...%
atlinconstraint(indidbc,{{'Dispersion',{2}}},0,0,1e-3)...1)...%
muxconstr,... % horizontal phase advance
muycontsr... % vertical phase advance
rm12constr,...
......@@ -120,7 +120,7 @@ rcm=atsetfieldvalues(rc,qd5,'PolynomB',{1,2},Kqd5-0.0);
verb=0;
if verbose, verb=3; end
rcm=atmatch(rcm,v,c,10^-15,100,verb,@lsqnonlin);
rcm=atmatch(rcm,v,c,10^-12,100,verb,@lsqnonlin);
end
......@@ -152,3 +152,24 @@ function m=muy(lindata)
m=lindata(end).mu(2)/2/pi;
end
function [r11]=RM44(lindata,ind1,ind2)
% get value of of indeces ind1 and ind2 (1 to 4) of
% M44 between two points first and last
Mlast=lindata(2).M44;
Mfirst=lindata(1).M44;
Mfirstinv=[[Mfirst(2,2),-Mfirst(1,2);-Mfirst(2,1),Mfirst(1,1)],...
zeros(2,2);...
zeros(2,2),...
[Mfirst(4,4),-Mfirst(3,4);-Mfirst(4,3),Mfirst(3,3)]];
R=Mlast*Mfirstinv;
%R=Mlast/Mfirst;
r11=R(ind1,ind2);
end
......@@ -85,25 +85,25 @@ if verbose, verb=3; end
if ~verbose, verb=0; end
famnames={...
'QF1[A,LM]\w*',...
'QD2[A,LM]\w*',...
'QD3[A,LM]\w*',...
'QF4[A,LM]\w*',...
'QF4[B,LM]\w*',...
'QD5[B,LM]\w*',...
'QF6B\w*',...
'DQ1B\w*',...
'QF8B\w*',...
'DQ2\w*',...
'QF8D\w*',...
'DQ1D\w*',...
'QF6D\w*',...
'QD5[D,LM]\w*',...
'QF4[D,LM]\w*',...
'QF4[E,LM]\w*',...
'QD3[E,LM]\w*',...
'QD2[E,LM]\w*',...
'QF1[E,LM]\w*'...
'QF1[A,LM]\w*',... 1
'QD2[A,LM]\w*',... 2
'QD3[A,LM]\w*',... 3
'QF4[A,LM]\w*',... 4
'QF4[B,LM]\w*',... 5
'QD5[B,LM]\w*',... 6
'QF6B\w*',... 7
'DQ1B\w*',... 8
'QF8B\w*',... 9
'DQ2\w*',... 10
'QF8D\w*',... 11
'DQ1D\w*',... 12
'QF6D\w*',... 13
'QD5[D,LM]\w*',... 14
'QF4[D,LM]\w*',... 15
'QF4[E,LM]\w*',... 16
'QD3[E,LM]\w*',... 17
'QD2[E,LM]\w*',... 18
'QF1[E,LM]\w*'... 19
}; %
Variab=[];
......@@ -117,14 +117,14 @@ rm44_34a=RM44(twisf,3,4);
rm12=struct(...
'Fun',@(~,ld,~)RM44(ld,1,2),...
'Weight',1,...
'Weight',1e-1,...
'RefPoints',[sfaeind(1),sfaeind(2)],...
'Min',rm44_12a,...
'Max',rm44_12a);
rm34=struct(...
'Fun',@(~,ld,~)RM44(ld,3,4),...
'Weight',1,...
'Weight',1e-1,...
'RefPoints',[sfaeind(1),sfaeind(2)],...
'Min',rm44_34a,...
'Max',rm44_34a);
......@@ -133,14 +133,14 @@ muxid=(twiend.mu(1)-twiin.mu(1))/2/pi;
muyid=(twiend.mu(2)-twiin.mu(2))/2/pi;
mx=struct(...
'Fun',@(~,ld,~)mux(ld),...
'Weight',1,...
'Weight',1e-2,...
'RefPoints',[1:length(arc)+1],...
'Min',muxid,...
'Max',muxid);
my=struct(...
'Fun',@(~,ld,~)muy(ld),...
'Weight',1,...
'Weight',1e-2,...
'RefPoints',[1:length(arc)+1],...
'Min',muyid,...
'Max',muyid);
......@@ -158,20 +158,26 @@ sf2Eopt=[...
];
midopt=[...
atlinconstraint(centind(1),{{'beta',{2}}},twimid.beta(2),twimid.beta(2),1),...
atlinconstraint(centind(1),{{'alpha',{1}}},twimid.alpha(1),twimid.alpha(1),1),...
atlinconstraint(centind(1),{{'beta',{2}}},twimid.beta(2),twimid.beta(2),10),...
atlinconstraint(centind(1),{{'alpha',{1}}},twimid.alpha(1),twimid.alpha(1),1),... % some cells are asymmetric, remove alpha zero
atlinconstraint(centind(1),{{'alpha',{2}}},twimid.alpha(2),twimid.alpha(2),1),...
atlinconstraint(centind(1),{{'Dispersion',{2}}},twimid.Dispersion(2),twimid.Dispersion(2),1),...
];
endopt=[...
atlinconstraint(length(arc)+1,{{'beta',{1}}},twiend.beta(1),twiend.beta(1),1e-1),...
atlinconstraint(length(arc)+1,{{'alpha',{1}}},twiend.alpha(1),twiend.alpha(1),1e-1),...
atlinconstraint(length(arc)+1,{{'alpha',{2}}},twiend.alpha(2),twiend.alpha(2),1e-1),...
atlinconstraint(length(arc)+1,{{'Dispersion',{1}}},twiend.Dispersion(1),twiend.Dispersion(1),1e-1),...
atlinconstraint(length(arc)+1,{{'Dispersion',{2}}},twiend.Dispersion(2),twiend.Dispersion(2),1e-1),...
atlinconstraint(length(arc)+1,{{'beta',{1}}},twiend.beta(1),twiend.beta(1),1e-2),...
atlinconstraint(length(arc)+1,{{'alpha',{1}}},twiend.alpha(1),twiend.alpha(1),1e-2),...
atlinconstraint(length(arc)+1,{{'alpha',{2}}},twiend.alpha(2),twiend.alpha(2),1e-2),...
atlinconstraint(length(arc)+1,{{'Dispersion',{1}}},twiend.Dispersion(1),twiend.Dispersion(1),1e-2),...
atlinconstraint(length(arc)+1,{{'Dispersion',{2}}},twiend.Dispersion(2),twiend.Dispersion(2),1e-2),...
];
% soft lmits
softlims=[...
atlinconstraint(1:length(arc)+1,{{'beta',{1}}},0,12,1),...
atlinconstraint(1:length(arc)+1,{{'beta',{2}}},0,20,1),...
];
Constr=[rm12,...
rm34, ...
mx, ...
......@@ -179,7 +185,9 @@ Constr=[rm12,...
sf2Aopt,...
sf2Eopt,...
midopt,...
endopt];
endopt,...
softlims...
];
% exclude magnets from matching
Variab(excludequad)=[];
......@@ -188,8 +196,9 @@ Constr(excludeconstr)=[];
%% execute least square fit
arcm=arc;
arcm=atmatch(arcm,Variab,Constr,10^-15,30,verb,@lsqnonlin,twiin);%,'fminsearch');%
%arcm=atmatch(arcm,Variab,Constr,10^-10,2000,verb,@fminsearch);%,'fminsearch');%
arcm=atmatch(arcm,Variab,Constr,10^-9,300,verb,@lsqnonlin,twiin);%,'fminsearch');%
%arcm=atmatch(arcm,Variab,Constr,10^-10,1000,verb,@fminsearch,twiin);%,'fminsearch');%
%arcm=atmatch(arcm,Variab,Constr,10^-15,100,verb,@lsqnonlin,twiin);%,'fminsearch');%
return
......
......@@ -23,7 +23,7 @@ args={pwd};
args(1:length(varargin))=varargin;
pth=args{1};
ebsmodel=ebs.model(pth);
ebsmodel=ebs.model(pth,'reduce',true,'keep','BPM.*|ID.*');
save('modellat','ebsmodel');
% file contains quadrupoles (in lttice order, quadrupoles and DQ), then sextupoles, then octupoles.
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment