source: MML/trunk/machine/SOLEIL/common/naff/naffutils/fmap_soleilnu.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 6.6 KB
Line 
1function [nux,nuy,diffu]=fmap_soleilnu(nx,ny,ax,ay)
2% fmap_soleilnu - simulates a frequency map using the tracking
3%
4% simulates a frequency map using the tracking
5% routine's out of Andrei Terebilo's ATtoolbox and
6% Jacques Laskars NAFF algorithm
7% (calcnaff.mex or calcnaff.dll)
8%
9% INPUTS
10% 1. nx         number of horizontal amplitudes
11% 2. ny         number of vertical amplitudes
12% 3. ax         maximum horizontal amplitude [mm]
13% 4. ay         maximum vertical amplitude [mm]
14%
15% OUTPUTS
16% 1. nux    H-betatron tune value
17% 2. nuy        V-betatron tune value
18% 3. diffu      Diffusion rate
19
20%
21% Laurent Nadolski, SOLEIL 16/05/11
22
23global THERING
24
25Tymax = 1e-2;   % maximum vertical coordinates
26tunesep = 1e-3; % tune separation for h/v tunes
27TWOPI = 2*pi;
28
29%% Initialization part
30% Frequencies
31nux = zeros(nx,ny);
32nuy = zeros(nx,ny);
33
34% Amplitudes
35pampx = ones(nx,ny)*NaN;
36pampy = ones(nx,ny)*NaN;
37
38%% load lattice
39refreshthering;
40
41[BetaX, BetaY, Sx, Sy, Tune] = modelbeta;
42HtuneIntegerPart = floor(Tune(1));
43VtuneIntegerPart = floor(Tune(2));
44
45%% set 4D tracking
46setcavity('off');
47setradiation('off');
48
49% Tracking number of turns
50NT = 2*516; % multiple of 6 for NAFF efficiency
51
52% First call for next 'reuse' flag
53% Do not remove
54T = ringpass(THERING,[0;0;0;0;0;0],1);
55
56%% tracking over the set of initial conditions
57for i=1:nx, % loop over H-plane
58    ampx = ax*sqrt(i/nx); % H-amplitude
59   
60    for j=1:ny % loop over V-plane
61
62        ampy = ay*sqrt(j/ny); % V-amplitude
63               
64        fprintf('amp_x=%g mm, amp_y=%g mm\n',ampx,ampy);
65       
66        X0=[ampx/1000 0 ampy/1000 0 0 0]'; % Initial tracking coordinates in SI units
67       
68        % tracking
69        cpustart=cputime;
70        %[T LOSSFLAG] = ringpass(THERING,X0,NT,'reuse');
71        [T LOSSFLAG] = ringpass(THERING,X0,NT);
72        cpustop=cputime;
73        fprintf('track time for 2*%d turns : %g s\n', NT/2, cpustop-cpustart);
74       
75        % new varaibles with tracking coordinates
76        Tx = T(1,:); Txp = T(2,:); Ty = T(3,:); Typ = T(4,:);
77       
78        % Tymax usefulness
79        if (length(Ty)==NT) & (all(Ty<Tymax)) ...
80                & (~any(isnan(Ty))) & (LOSSFLAG==0)
81           
82            % NAFF part
83            cpustart=cputime;
84            tmpnux1=abs(calcnaff(Tx(1:NT/2),Txp(1:NT/2),1)/TWOPI);
85            tmpnuy1=abs(calcnaff(Ty(1:NT/2),Typ(1:NT/2),1)/TWOPI);
86            tmpnux2=abs(calcnaff(Tx(NT/2+1:NT),Txp(NT/2+1:NT),1)/TWOPI);
87            tmpnuy2=abs(calcnaff(Ty(NT/2+1:NT),Typ(NT/2+1:NT),1)/TWOPI);
88            cpustop=cputime;
89            fprintf('NAFF CPU time (4*%d turns) : %g s\n',NT/2, cpustop-cpustart);
90           
91            % Particle amplitudes
92            pampy(i,j)=ampx;
93            pampy(i,j)=ampy;
94           
95            % build frequency vectors  for NT/2 first turns                     
96            if ((abs(tmpnuy1(1))>tunesep) && (abs(tmpnuy1(1)-tmpnux1(1))>tunesep))
97                nuy(i,j)=tmpnuy1(1);
98            else
99                nuy(i,j)=tmpnuy1(2);
100            end
101           
102            % avoid misidentification nux=nuy
103            if (abs(tmpnux1(1))>tunesep)
104                nux(i,j)=tmpnux1(1);
105            else
106                nux(i,j)=tmpnux1(2);
107            end
108           
109            % build frequency vectors  for NT/2 last turns                     
110            if ((abs(tmpnuy2(1))>tunesep) && (abs(tmpnuy2(1)-tmpnux2(1))>tunesep))
111                nuy2=tmpnuy2(1);
112            else
113                nuy2=tmpnuy2(2);
114            end
115           
116            if (abs(tmpnux2(1))>tunesep)
117                nux2=tmpnux2(1);
118            else
119                nux2=tmpnux2(2);
120            end
121           
122           
123            if (length(nux2)==1) && (length(nuy2)==1) && ...
124                    (length(nux(i,j))==1) && (length(nuy(i,j))==1)
125                diffu(i,j)=log10(sqrt((nux2-nux(i,j))^2+(nuy2-nuy(i,j))^2)/NT*2);
126            else
127                diffu(i,j) = -3;
128            end
129           
130            if (diffu(i,j) < -10)
131                diffu(i,j) = -10;
132            end
133           
134            taxi = ax*sqrt(i/nx);
135            taxii = ax*sqrt((i-1)/nx);
136            tayj = ay*sqrt(j/ny);
137            tayjj = ay*sqrt((j-1)/ny);
138           
139            if (i>1) && (j>1)
140                xpos(:,(i-1)*(ny)+j) = [taxii;taxii;taxi;taxi];
141                ypos(:,(i-1)*(ny)+j) = [tayjj;tayj;tayj;tayjj];
142            elseif (i>1)
143                xpos(:,(i-1)*(ny)+j) = [taxii;taxii;taxi;taxi];
144                ypos(:,(i-1)*(ny)+j) = [0;tayj;tayj;0];
145            elseif (j>1)
146                xpos(:,(i-1)*(ny)+j) = [0;0;taxi;taxi];
147                ypos(:,(i-1)*(ny)+j) = [tayjj;tayj;tayj;tayjj];
148            else
149                xpos(:,(i-1)*(ny)+j) = [0;0;taxi;taxi];
150                ypos(:,(i-1)*(ny)+j) = [0;tayj;tayj;0];
151            end
152           
153            nuxpos(:,(i-1)*(ny)+j) = ...
154                [nux(i,j)-.0001;nux(i,j)-.0001;nux(i,j)+.0001;nux(i,j)+.0001];
155            nuypos(:,(i-1)*(ny)+j) = ...
156                [nuy(i,j)-.0006;nuy(i,j)+.0006;nuy(i,j)+.0006;nuy(i,j)-.0006];
157           
158            diffuvec(1:4,(i-1)*(ny)+j) = diffu(i,j);
159           
160           
161        else %particle unstable
162            nux(i,j)=0.0; nuy(i,j)=0.0;
163            pampy(i,j)=-1;pampy(i,j)=-1;
164            xpos(:,(i-1)*(ny)+j) = [0;0;0;0];
165            ypos(:,(i-1)*(ny)+j) = [0;0;0;0];
166            nuxpos(:,(i-1)*(ny)+j) = [0;0;0;0];
167            nuypos(:,(i-1)*(ny)+j) = [0;0;0;0];
168            diffu(i,j)=-10;
169            diffuvec(1:4,(i-1)*(ny)+j) = [-10;-10;-10;-10];
170        end
171       
172        if nux(i,j) && nuy(i,j)
173            fprintf('nu_x=%g, nu_y=%g\n',HtuneIntegerPart+nux(i,j),VtuneIntegerPart+nuy(i,j));
174        else
175            fprintf('particle lost\n');
176        end
177       
178    end
179   
180    save 'freqmap_new' nux nuy diffu nuxpos nuypos xpos ypos diffuvec pampy pampy
181   
182end
183
184%% PLOTS
185
186f1=figure;
187plot(HtuneIntegerPart+nux,VtuneIntegerPart+nuy,'b.');
188axis([18.2 18.5 10.0 10.5]);
189title('SOLEIL lattice, calculated frequency map (NAFF)');
190xlabel('\nu_x');
191ylabel('\nu_y');
192pause(0.1);
193
194%% Plot diffusion
195if min(size(diffu)) > 1
196   
197    figure;
198    fill(xpos,ypos,diffuvec);
199    axis([0 ax 0 ay]);
200    caxis([-10 -3]);
201    hold on;
202    shading flat;
203    colormap('jet');
204    colorbar;
205    title('SOLEIL lattice, calculated frequency map (NAFF)');
206    xlabel('x position (mm) (injection straight)');
207    ylabel('z position (mm)');
208    hold off;
209   
210    figure;
211    fill(HtuneIntegerPart+nuxpos,VtuneIntegerPart+nuypos,diffuvec);
212    axis([18.2 18.5 10.0 10.5]);
213    caxis([-10 -3]);
214    hold on;
215    shading flat;
216    colormap('jet');
217    colorbar;
218    title('SOLEIL lattice, calculated frequency map (NAFF)');
219    xlabel('\nu_x');
220    ylabel('\nu_z');
221    hold off;
222   
223end
Note: See TracBrowser for help on using the repository browser.