Commit 692fb79e authored by Simone Liuzzo's avatar Simone Liuzzo
Browse files

serveral modifications for appropriate matching

parent 1f55614f
......@@ -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
......@@ -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);
......@@ -158,7 +158,7 @@ sf2Eopt=[...
];
midopt=[...
atlinconstraint(centind(1),{{'beta',{2}}},twimid.beta(2),twimid.beta(2),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),...
......@@ -172,6 +172,12 @@ endopt=[...
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,7 +196,7 @@ Constr(excludeconstr)=[];
%% execute least square fit
arcm=arc;
arcm=atmatch(arcm,Variab,Constr,10^-15,100,verb,@lsqnonlin,twiin);%,'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');%
......
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