1 | subroutine trwfield |
---|
2 | c--parmela subroutine for the definition of |
---|
3 | c--background field from a series of traveling waves |
---|
4 | c---------------------------------------------------------------------- |
---|
5 | save |
---|
6 | c |
---|
7 | include 'param_sz.h' |
---|
8 | include 'constcom.h' |
---|
9 | include 'coordcom.h' |
---|
10 | include 'misccom.h' |
---|
11 | include 'pcordcom.h' |
---|
12 | include 'syscom.h' |
---|
13 | include 'tstepcom.h' |
---|
14 | include 'wavescom.h' |
---|
15 | include 'ucom.h' |
---|
16 | c |
---|
17 | real ez(16,nbtrw),cf(11,nbtrw) |
---|
18 | integer ngap |
---|
19 | c-------------------------------------------------------------------------- |
---|
20 | c* |
---|
21 | c----Ez data |
---|
22 | data (ez(i,1),i=1,16)/1.881,1.852,1.747,1.516,1.085,0.461,-.146, |
---|
23 | * -.548,-.762,-.869,-.921,-.943,-.945,-.929,-.901,-.884/ |
---|
24 | c each cavity has gradient, beta, length, freq., |
---|
25 | c phase and, in the middle, a gap. This code creates the expansion |
---|
26 | c for the E and B fields using the field in a traveling wave |
---|
27 | c accelerator described in 'LINEAR ACCELERATORS' edited by |
---|
28 | c Lopostolle and Septier pages 44 to 95. |
---|
29 | |
---|
30 | c---the data for the traveling wave accelerators is on the trwave cards |
---|
31 | c---in the following order. |
---|
32 | c---trwave L, APER, IOUT, PHI, WE, NC, DWTMAX, FREQ, GAP, NMIN, NMAX, |
---|
33 | C---PSHIFT, NW, NPRINT, Z1, Z2, R1, R2, DPHI, EZ(0-15) |
---|
34 | C---the first 9 paramaters must be on all trwave cards. nc is the traveling |
---|
35 | c---wave accelerator tank number. nc must be a number from one to seven |
---|
36 | c---each trwave card must have then same nc in a tank. each tank must have |
---|
37 | c---a unique number. NW is the total number of trwave cards in a tank. each |
---|
38 | c---trwave card contains the data for one cell of the traveling wave |
---|
39 | c---accelerator. The first trwave card must have the first 13 parameters at |
---|
40 | c---least. |
---|
41 | c---if nprint is nonzero then Z1 through R2 must be defined. |
---|
42 | if(nn.lt.9)then |
---|
43 | write(ndiag,*)' not enough parameters on this trwave card' |
---|
44 | return |
---|
45 | endif |
---|
46 | nc=vv(6) |
---|
47 | if(nelw(nc).eq.0)then |
---|
48 | nnw=1 |
---|
49 | else |
---|
50 | nnw=nnw+1 |
---|
51 | endif |
---|
52 | if(nnw.gt.1)then |
---|
53 | do 201 i=1,16 |
---|
54 | ez(i,nnw)=ez(i,nnw-1) |
---|
55 | 201 continue |
---|
56 | endif |
---|
57 | if(nelw(nc).eq.0.and.nn.lt.13)then |
---|
58 | write(ndiag,*)' not enough parameters on this trwave card' |
---|
59 | return |
---|
60 | endif |
---|
61 | if(nn.ge.20)then |
---|
62 | if(nn.lt.35)then |
---|
63 | write(ndiag,*) |
---|
64 | *' Not enough fields specified on this card. They are ignored.' |
---|
65 | else |
---|
66 | do 200 i=1,16 |
---|
67 | ez(i,nnw)=vv(19+i) |
---|
68 | 200 continue |
---|
69 | endif |
---|
70 | endif |
---|
71 | if(nn.ge.13.and.nelw(nc).eq.0)then |
---|
72 | nelw(nc)=nel |
---|
73 | nw(nc)=vv(13)+nel-1 |
---|
74 | pshif=vv(12) |
---|
75 | nmax=vv(11) |
---|
76 | nmin=vv(10) |
---|
77 | if(nn.ge.14.and.vv(14).ne.0)then |
---|
78 | if(nn.lt.18)then |
---|
79 | write(ndiag,*)' not enough parameters on this trwave card' |
---|
80 | return |
---|
81 | endif |
---|
82 | nprint=vv(14) |
---|
83 | z1=vv(15) |
---|
84 | z2=vv(16) |
---|
85 | r1=vv(17) |
---|
86 | r2=vv(18) |
---|
87 | endif |
---|
88 | if(nn.ge.19)dphi=vv(19) |
---|
89 | endif |
---|
90 | if(nel.lt.nw(nc))return |
---|
91 | do 10 i=1,nw(nc)-nelw(nc)+1 |
---|
92 | ii=i+nelw(nc)-1 |
---|
93 | el(4,ii)=el(4,ii)*pi/180. |
---|
94 | wavli=clight/el(8,ii) |
---|
95 | cay=twopi/wavli |
---|
96 | c --calculate coefficients of expansion |
---|
97 | do 9 n=nmin,nmax |
---|
98 | nm=n-nmin+1 |
---|
99 | phasfn=1.+2.*n/pshif |
---|
100 | wbeta=el(1,ii)*2*el(8,ii)/(clight*pshif) |
---|
101 | cliu if(ii.eq.nelw(nc))wbeta=wbeta*2. |
---|
102 | if(ii.eq.nelw(nc) .or. ii.eq.nw(nc))wbeta=wbeta*2. |
---|
103 | wk3(nm,i,nc)=phasfn*cay/wbeta |
---|
104 | cliu if(abs(wk3(nm,i,nc)).lt.abs(cay)) |
---|
105 | cliu wk1(nm,i,nc)=sqrt(cay**2-wk3(nm,i,nc)**2) |
---|
106 | wk1(nm,i,nc)=cay**2-wk3(nm,i,nc)**2 |
---|
107 | c---will use fields from superfish to determin wa's. |
---|
108 | c--- start of superfish coefficents determination |
---|
109 | c---integrate Ez squared. |
---|
110 | cliu if(ii.ne.nelw(nc))then |
---|
111 | if(ii.ne.nelw(nc).and.ii.ne.nw(nc))then |
---|
112 | sum=.5*(ez(1,i)+ez(16,i)*cos(wk3(nm,i,nc)*el(1,ii)/pshif)) |
---|
113 | else |
---|
114 | sum=.5*(ez(1,i)+ez(16,i)*cos(wk3(nm,i,nc)*el(1,ii)* |
---|
115 | * 2./pshif)) |
---|
116 | endif |
---|
117 | h=el(1,ii)/pshif/15. |
---|
118 | c---the first cell starts at the center of the cell. a cell card |
---|
119 | c---provids the fields for the first half. |
---|
120 | cliu if(ii.eq.nelw(nc))h=2*h |
---|
121 | if(ii.eq.nelw(nc) .or. ii.eq.nw(nc))h=2*h |
---|
122 | zz=0. |
---|
123 | do 1 j=2,15 |
---|
124 | zz=zz+h |
---|
125 | sum=sum+cos(wk3(nm,i,nc)*zz)*ez(j,i) |
---|
126 | 1 continue |
---|
127 | wa(nm,i,nc)=sum*h |
---|
128 | 9 continue |
---|
129 | c---normalize the wa's |
---|
130 | sum=0. |
---|
131 | do 2 n=nmin,nmax |
---|
132 | nm=n-nmin+1 |
---|
133 | sum=sum+wa(nm,i,nc)**2 |
---|
134 | 2 continue |
---|
135 | do 3 n=nmin,nmax |
---|
136 | nm=n-nmin+1 |
---|
137 | wa(nm,i,nc)=wa(nm,i,nc)/sqrt(sum) |
---|
138 | 3 continue |
---|
139 | c--- end of determination of coefficents from superfish fields. |
---|
140 | 10 continue |
---|
141 | C--------------------------- nprint ----------------------------------- |
---|
142 | if(nprint.gt.0)then |
---|
143 | open(unit=ntrw,file='trwdata',recl=132,access='sequential', |
---|
144 | * status='unknown',form='formatted') |
---|
145 | write(ntrw,*)' expansion coefficients...' |
---|
146 | do 80 i=1,nw(nc)-nelw(nc)+1 |
---|
147 | write(ntrw,77)i |
---|
148 | 77 format(' wave No.',i4,/, |
---|
149 | *' n An K1n K3n') |
---|
150 | do 79 n=nmin,nmax |
---|
151 | nm=n-nmin+1 |
---|
152 | write(ntrw,78)n,wa(nm,i,nc),wk1(nm,i,nc),wk3(nm,i,nc) |
---|
153 | 78 format(i4,3e13.3) |
---|
154 | 79 continue |
---|
155 | 80 continue |
---|
156 | endif |
---|
157 | c--- phases should now be made to account for phase shifts in |
---|
158 | c previous cavities ( integral of k(z)dz ) |
---|
159 | if(nw(nc)-nelw(nc).gt.1)then |
---|
160 | do 110 i=2,nw(nc)-nelw(nc)+1 |
---|
161 | do 100 ii=1,i-1 |
---|
162 | iii=ii+nelw(nc)-1 |
---|
163 | do 90 n=nmin,nmax |
---|
164 | nm=n-nmin+1 |
---|
165 | if(iii.ne.nelw(nc))then |
---|
166 | wpoff(nm,i,nc)=wpoff(nm,i,nc)-wk3(nm,ii,nc)*el(1,iii) |
---|
167 | else |
---|
168 | wpoff(nm,i,nc)=wpoff(nm,i,nc)-wk3(nm,ii,nc)*el(1,iii)*2. |
---|
169 | endif |
---|
170 | 90 continue |
---|
171 | 100 continue |
---|
172 | 110 continue |
---|
173 | endif |
---|
174 | if(nprint.ne.0)then |
---|
175 | dzprint=(z2-z1)/iabs(nprint) |
---|
176 | if(dphi.ne.0.)then |
---|
177 | jend=720/dphi+.999999 |
---|
178 | else |
---|
179 | jend=1 |
---|
180 | endif |
---|
181 | wt=-dphi |
---|
182 | do 20 j=1,jend |
---|
183 | wt=wt+dphi |
---|
184 | write(ntrw,7)nw(nc)-nelw(nc),nprint,r1,r2,wt |
---|
185 | do 20 i=0,iabs(nprint) |
---|
186 | zz=z1+i*dzprint |
---|
187 | call trwave(zz,r1,wez1,wer1,wbphi1,iz,wt) |
---|
188 | call trwave(zz,r2,wez2,wer2,wbphi2,iz,wt) |
---|
189 | if(iz.eq.0)then |
---|
190 | wez1=0. |
---|
191 | wer1=0. |
---|
192 | wbphi1=0. |
---|
193 | wbphi2=0. |
---|
194 | wer2=0. |
---|
195 | wez2=0. |
---|
196 | endif |
---|
197 | izz=iz+nelw(nc)-1 |
---|
198 | wbeta=el(1,izz)*2*el(8,izz)/(clight*pshif) |
---|
199 | if(izz.eq.nelw(nc) .or. izz.eq.nw(nc))wbeta=wbeta*2. |
---|
200 | write(ntrw,30)zz,wez1,wer1,wbphi1,wez2,wer2,wbphi2,float(iz) |
---|
201 | 20 continue |
---|
202 | endif |
---|
203 | 7 format(/,' nwaves=',i5,', nprint=',i5, |
---|
204 | + /,' printed at r1=',f10.3,' and r2=',f10.3,' wt=',f10.3, |
---|
205 | + /,' z Ez(r1,z) Er(r1,z) Bphi(r1,z)' |
---|
206 | + ,' Ez(r2,z) Er(r2,z) Bphi(r2,z) Er-v*Bphi') |
---|
207 | 30 format(f10.3,7f10.3) |
---|
208 | return |
---|
209 | end |
---|
210 | c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* |
---|