source: PSPA/parmelaPSPA/tags/v0.1/tank.f @ 447

Last change on this file since 447 was 101, checked in by garnier, 12 years ago

premier tag

File size: 3.2 KB
Line 
1      subroutine tank(wtp,dwtp,iend,ibeg)
2c---tank transformation.
3c---treat each cell as drift-gap-drift
4c---------------------------------------------------------------------------
5      save
6c
7      include 'param_sz.h'
8      include 'constcom.h'
9      include 'pcordcom.h'
10      include 'syscom.h'
11      include 'ucom.h'
12c
13c--------------------------------------------------------------------------
14c*
15      data fd/.45/
16      ne=rne
17      p=wtp
18      dpp=dwtp
19      pp=p+dpp
20      bz=bgz/gamma
21      dzt=bz*dcon*dpp
22      zz=z-zloc(ne)+el(1,ne)
23      e0t=el(4,ne)
24      xnct=el(5,ne)
25      xphi=el(6,ne)
26      phi=el(7,ne)
27      cl=el(8,ne)
28      hcl=.5*cl
29      xnc=aint(zz/cl)
30      fz=zz-xnc*cl
31c---dtc = dist to center of cell
32      dtc=hcl-fz
33c---dte = dist to end of cell
34      dte=hcl
35      if(dtc.lt.0.)dte=hcl+dtc
36      if(dtc.le.0.)go to 20
37c---drift to cell center, unless too far
38   10 if(dtc.gt.dzt)go to 30
39      dpp=dpp*dtc/dzt
40      call drift(dpp,iend,ibeg)
41c---update the phase
42      p=p+dpp
43      dpp=pp-p
44c---gap transformation
45      ph=amod(p+phi+xnc*xphi*180.,360.)*radian-.5*pi
46      cp=cos(ph)
47      sp=sin(ph)
48      xp=bgx/bgz
49      yp=bgy/bgz
50c---drift backward to middle of first half of cell
51      x=x-fd*hcl*xp
52      y=y-fd*hcl*yp
53c---cayrsq is (kr)**2
54      cayrsq=el(10,ne)*(x**2+y**2)
55      fi0=1.+cayrsq/4.*(1.+cayrsq/16.*(1.+cayrsq/36.))
56      fi1okr=.5*(1.+.125*cayrsq*(1.+cayrsq/24.*(1.+cayrsq/48.)))
57      g=sqrt(1.+bgz**2)
58      fg=e0t*cl*fi0/erest
59      dg=fg*(.5*cp+sp/pi)
60      gb=g+.5*dg
61      g=g+dg
62      if (g.lt.1.) go to 12
63      if(cayrsq.eq.0.)go to 11
64      bsq=1.-1./gb**2
65      bbar=sqrt(bsq)
66      ff=-pi*e0t*fi1okr/(bbar*erest)
67     1   *(cp*(1.+bsq)/pi+.5*sp*(1.-bsq))
68      bgx=bgx+ff*x
69      bgy=bgy+ff*y
70      bgz=sqrt(g**2-1.)
71      xp=bgx/bgz
72      yp=bgy/bgz
73c---drift to middle of second half of cell
74   11 x=x+2.*fd*hcl*xp
75      y=y+2.*fd*hcl*yp
76c---cayrsq is (kr)**2
77      cayrsq=el(10,ne)*(x**2+y**2)
78      fi0=1.+cayrsq/4.*(1.+cayrsq/16.*(1.+cayrsq/36.))
79      fi1okr=.5*(1.+.125*cayrsq*(1.+cayrsq/24.*(1.+cayrsq/48.)))
80      fg=e0t*cl*fi0/erest
81      dg=fg*(.5*cp-sp/pi)
82      gb=g+.5*dg
83      g=g+dg
84c-----allow particle to go backwards
85   12 if (g.lt.1.) then
86      g=2-g
87      bgz=-sqrt(g**2-1.)
88      else
89      bgz=sqrt(g**2-1.)
90      endif
91      if(gb.lt.1.)gb=2-gb
92c      if (bgz.le.0) return
93      if (cayrsq.le.0.) go to 15
94      bsq=1.-1./gb**2
95      bbar=sqrt(bsq)
96      ff= pi*e0t*fi1okr/(bbar*erest)
97     1   *(cp*(1.+bsq)/pi-.5*sp*(1.-bsq))
98      bgx=bgx+ff*x
99      bgy=bgy+ff*y
100      xp=bgx/bgz
101      yp=bgy/bgz
102      x=x-.5*hcl*xp
103      y=y-.5*hcl*yp
104   15 gamma=sqrt(1.+bgx**2+bgy**2+bgz**2)
105c---calculate new drift dist
106      bz=bgz/gamma
107      dzt=bz*dcon*dpp
108c---drift to end of cell, unless too far
109   20 if(dte.gt.dzt)go to 30
110      dpp=dpp*dte/dzt
111      call drift(dpp,iend,ibeg)
112c---update the phase
113      p=p+dpp
114      dpp=pp-p
115      dzt=dzt-dte
116      dtc=hcl
117      dte=hcl
118      xnc=xnc+1.
119      if(xnc.lt.xnct)go to 10
120c---end of tank
121      dwtp=p-wtp
122      z=zloc(ne)
123      return
124c---drift and exit
125   30 continue
126      call drift(dpp,iend,ibeg)
127      p=p+dpp
128      dwtp=p-wtp
129      return
130      end
131c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
Note: See TracBrowser for help on using the repository browser.