source: PSPA/parmelaPSPA/trunk/trwfield.f @ 315

Last change on this file since 315 was 12, checked in by lemeur, 12 years ago

parmela pspa initial

File size: 6.9 KB
Line 
1      subroutine trwfield
2c--parmela subroutine for the definition of
3c--background field from a series of traveling waves
4c----------------------------------------------------------------------
5      save
6c
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'
16c
17      real ez(16,nbtrw),cf(11,nbtrw)
18      integer ngap
19c--------------------------------------------------------------------------
20c*
21c----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/
24c        each cavity has gradient, beta, length, freq.,
25c        phase and, in the middle, a gap. This code creates the expansion
26c        for the E and B fields using the field in a traveling wave
27c        accelerator described in 'LINEAR ACCELERATORS' edited by
28c        Lopostolle and Septier pages 44 to 95.
29
30c---the data for the traveling wave accelerators is on the trwave cards
31c---in the following order.
32c---trwave L, APER, IOUT, PHI, WE, NC, DWTMAX, FREQ, GAP, NMIN, NMAX,
33C---PSHIFT, NW, NPRINT, Z1, Z2, R1, R2, DPHI, EZ(0-15)
34C---the first 9 paramaters must be on all trwave cards. nc is the traveling
35c---wave accelerator tank number. nc must be a number from one to seven
36c---each trwave card must have then same nc in a tank. each tank must have
37c---a unique number. NW is the total number of trwave cards in a tank. each
38c---trwave card contains the data for one cell of the traveling wave
39c---accelerator. The first trwave card must have the first 13 parameters at
40c---least.
41c---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
96c --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)
101cliu       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
104cliu       if(abs(wk3(nm,i,nc)).lt.abs(cay))
105cliu       wk1(nm,i,nc)=sqrt(cay**2-wk3(nm,i,nc)**2)
106           wk1(nm,i,nc)=cay**2-wk3(nm,i,nc)**2     
107c---will use fields from superfish to determin wa's.
108c--- start of superfish coefficents determination
109c---integrate Ez squared.
110cliu       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.
118c---the first cell starts at the center of the cell. a cell card
119c---provids the fields for the first half.
120cliu           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
129c---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
139c--- end of determination of coefficents from superfish fields.
140   10 continue
141C--------------------------- 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
14877    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)
15378        format(i4,3e13.3)
15479        continue
15580        continue
156      endif
157c--- phases should now be made to account for phase shifts in
158c     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
210c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
Note: See TracBrowser for help on using the repository browser.