Home > pubtools > LatticeTuningFunctions > correction > DispersionFreeSteering > testdispersionfreesteering.m

testdispersionfreesteering

PURPOSE ^

test errors and correction functions

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 test errors and correction functions

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % test errors and correction functions
0002 close all
0003 clear all
0004 addpath('/mntdirect/_machfs/liuzzo/CODE/LatticeTuningFunctions');
0005 addpath('/mntdirect/_machfs/liuzzo/CODE/LatticeTuningFunctions/correction/');
0006 addpath('/mntdirect/_machfs/liuzzo/CODE/LatticeTuningFunctions/errors/');
0007 
0008 % load lattice
0009 load ESRFLattice.mat
0010 
0011 %% get RM
0012 speclab='DFSESRF';
0013 
0014 modelrmfile=fullfile(pwd,['RMmodel' speclab '.mat']);%
0015 
0016 if ~exist([modelrmfile],'file')
0017     
0018     ModelRM...
0019         =getresponsematrices(...
0020         ring,...
0021         indBPM,...
0022         indHCor,...
0023         indVCor,...
0024         indSCor,...
0025         indQCor,...
0026         [],...
0027         [0 0 0 0 0 0]',...
0028         [1 2 3 7 8 9]); % orbit, dpp and dispersion rm to steerers
0029     
0030     save([modelrmfile],'ModelRM');
0031 else
0032     load([modelrmfile],'ModelRM');
0033 end
0034 
0035 % set errors
0036 ind=find(atgetcells(ring,'Class','Quadrupole','Sextupole'));
0037 dx=5e-6*randn(size(ind));
0038 dy=5e-6*randn(size(ind));
0039 dr=5e-6*randn(size(ind));
0040 
0041 rerr=atsetshift(ring,ind,dx,dy);
0042 rerr=atsettilt(rerr,ind,dr);
0043 
0044 %% apply correction
0045 inCOD=[0 0 0 0 0 0]';
0046 [l,~,~]=atlinopt(ring,0,indBPM);
0047 refdispersion=zeros(2,length(indBPM));
0048 refdispersion(1,:)=arrayfun(@(a)a.Dispersion(1),l);
0049 refdispersion(2,:)=arrayfun(@(a)a.Dispersion(3),l);
0050 
0051 % steerers limited, increase eigenvectors number
0052 [rcor,inCOD,hs,vs]=atdispersionfreesteering(...
0053     rerr,...
0054     indBPM,...
0055     indHCor,...
0056     indVCor,...
0057     inCOD,...
0058     [... several correction iterations with different number of eigenvector
0059     [20 20];...
0060     [40 40];...
0061     [60 60];...
0062     [80 80];...
0063     [97 96];...
0064     [97 96];...
0065     [97 96]...
0066     ],...
0067     [true false],...
0068     1.0,...
0069     0.9,...
0070     ModelRM,...
0071     zeros(2,length(indBPM)),...
0072     refdispersion,...
0073     [],...
0074     true);
0075 
0076 
0077 o=findorbit6Err(rerr,indBPM,inCOD);
0078 oxe=o(1,:);
0079 oye=o(3,:);
0080 
0081 o=findorbit6Err(rcor,indBPM,inCOD);
0082 oxc=o(1,:);
0083 oyc=o(3,:);
0084 
0085 sBPM=findspos(rcor,indBPM);
0086 figure;subplot(2,1,1);
0087 plot(sBPM,oxe,'.-');hold on; plot(sBPM,oxc,'.-');
0088 legend('before','after');
0089 xlabel('s [m]');
0090 ylabel('hor. orbit');
0091 subplot(2,1,2);
0092 plot(sBPM,oye,'.-');hold on; plot(sBPM,oyc,'.-');
0093 legend('before','after');
0094 xlabel('s [m]');
0095 ylabel('ver. orbit');
0096 saveas(gca,'OrbCor.fig');
0097  export_fig('OrbCor.jpg','-r300');
0098 
0099  
0100 alpha=mcf(rerr);
0101 indrfc=find(atgetcells(rerr,'Frequency'));
0102      delta=1e-4;
0103 % get initial dispersion
0104 o=finddispersion6Err(rerr,indBPM,indrfc,alpha,delta,inCOD);
0105 oxe=o(1,:);
0106 oye=o(3,:);
0107 
0108 o=finddispersion6Err(rcor,indBPM,indrfc,alpha,delta,inCOD);
0109 oxc=o(1,:);
0110 oyc=o(3,:);
0111 
0112 sBPM=findspos(rcor,indBPM);
0113 figure;subplot(2,1,1);
0114 plot(sBPM,oxe-refdispersion(1,:),'.-');hold on; plot(sBPM,oxc-refdispersion(1,:),'.-');
0115 legend('before','after');
0116 xlabel('s [m]');
0117 ylabel('hor. disp');
0118 subplot(2,1,2);
0119 plot(sBPM,oye,'.-');hold on; plot(sBPM,oyc,'.-');
0120 legend('before','after');
0121 xlabel('s [m]');
0122 ylabel('ver. disp');
0123 saveas(gca,'DispCor.fig');
0124  export_fig('DispCor.jpg','-r300');
0125  
0126  % steerers limited, increase eigenvectors number, no dispersion correction
0127 [rcor,inCOD,hs,vs]=atdispersionfreesteering(...
0128     rerr,...
0129     indBPM,...
0130     indHCor,...
0131     indVCor,...
0132     inCOD,...
0133     [... several correction iterations with different number of eigenvector
0134     [20 20];...
0135     [40 40];...
0136     [60 60];...
0137     [80 80];...
0138     [97 96];...
0139     [97 96];...
0140     [97 96]...
0141     ],...
0142     [true false],...
0143     1.0,...
0144     0.0,...  dispersion weigth set to 0.0, no dispersion correction
0145     ModelRM,...
0146     zeros(2,length(indBPM)),...
0147     refdispersion,...
0148     [],...
0149     true);
0150 
0151 
0152 o=findorbit6Err(rerr,indBPM,inCOD);
0153 oxe=o(1,:);
0154 oye=o(3,:);
0155 
0156 o=findorbit6Err(rcor,indBPM,inCOD);
0157 oxc=o(1,:);
0158 oyc=o(3,:);
0159 
0160 sBPM=findspos(rcor,indBPM);
0161 figure;subplot(2,1,1);
0162 plot(sBPM,oxe,'.-');hold on; plot(sBPM,oxc,'.-');
0163 legend('before','after');
0164 xlabel('s [m]');
0165 ylabel('hor. orbit');
0166 subplot(2,1,2);
0167 plot(sBPM,oye,'.-');hold on; plot(sBPM,oyc,'.-');
0168 legend('before','after');
0169 xlabel('s [m]');
0170 ylabel('ver. orbit');
0171 saveas(gca,'OrbCorNoDisp.fig');
0172  export_fig('OrbCorNoDisp.jpg','-r300');
0173 
0174  
0175 alpha=mcf(rerr);
0176 indrfc=find(atgetcells(rerr,'Frequency'));
0177      delta=1e-4;
0178 % get initial dispersion
0179 o=finddispersion6Err(rerr,indBPM,indrfc,alpha,delta,inCOD);
0180 oxe=o(1,:);
0181 oye=o(3,:);
0182 
0183 o=finddispersion6Err(rcor,indBPM,indrfc,alpha,delta,inCOD);
0184 oxc=o(1,:);
0185 oyc=o(3,:);
0186 
0187 sBPM=findspos(rcor,indBPM);
0188 figure;subplot(2,1,1);
0189 plot(sBPM,oxe-refdispersion(1,:),'.-');hold on; plot(sBPM,oxc-refdispersion(1,:),'.-');
0190 legend('before','after');
0191 xlabel('s [m]');
0192 ylabel('hor. disp');
0193 subplot(2,1,2);
0194 plot(sBPM,oye,'.-');hold on; plot(sBPM,oyc,'.-');
0195 legend('before','after');
0196 xlabel('s [m]');
0197 ylabel('ver. disp');
0198 saveas(gca,'DispCorNoDisp.fig');
0199  export_fig('DispCorNoDisp.jpg','-r300');
0200  
0201

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005