V3FIT
bootsj.f
1  SUBROUTINE bootsj(aibstot, extension, iunit_in)
2 c
3 ! The code BOOTSJ calculates the bootstrap current for 3D configurations.
4 ! The main part of the code, calculation of the geometrical factor GBSNORM,
5 ! was written by Johnny S. Tolliver of ORNL on the basis of
6 ! Ker-Chung Shaing's formulas. Other parts of the code, as well as modifications
7 ! to the Tolliver's part, were written by Paul Moroz of UW-Madison.
8 c
9 ! References:
10 c
11 ! 1. K.C. Shaing, B.A. Carreras, N. Dominguez, V.E. Lynch, J.S. Tolliver
12 ! "Bootstrap current control in stellarators", Phys. Fluids B1, 1663 (1989).
13 ! 2. K.C. Shaing, E.C. Crume, Jr., J.S. Tolliver, S.P. Hirshman, W.I. van Rij
14 ! "Bootstrap current and parallel viscosity in the low collisionality
15 ! regime in toroidal plasmas", Phys. Fluids B1, 148 (1989).
16 ! 3. K.C. Shaing, S.P. Hirshman, J.S. Tolliver "Parallel viscosity-driven
17 ! neoclassical fluxes in the banana regime in nonsymmetri! toroidal
18 ! plasmas", Phys. Fluids 29, 2548 (1986).
19 C-----------------------------------------------
20 C M o d u l e s
21 C-----------------------------------------------
22  USE parambs
23  USE safe_open_mod
24  USE trig
25  USE vmec0
26  USE fftpack, ONLY : fftfax, cftfax
27  IMPLICIT NONE
28 C-----------------------------------------------
29 C D u m m y A r g u m e n t s
30 C-----------------------------------------------
31  INTEGER :: iunit_in
32  REAL(rprec) :: aibstot
33  CHARACTER*(*) :: extension
34 C-----------------------------------------------
35 C L o c a l P a r a m e t e r s
36 C-----------------------------------------------
37  INTEGER, PARAMETER :: nfax = 13
38  INTEGER, PARAMETER :: indata0 = 7
39  INTEGER, PARAMETER :: jbs_file=59, ans_file=18, ans_dat_file=19
40  REAL(rprec) :: one = 1, p5 = .5_dp
41 C-----------------------------------------------
42 C L o c a l V a r i a b l e s
43 C-----------------------------------------------
44  INTEGER, DIMENSION(nfax) :: ifaxu, ifaxv
45  INTEGER :: ntrigu, ntrigv
46  INTEGER :: irho, irho1, ierr, iunit, ijbs, ians, ians_plot
47  REAL(rprec), DIMENSION(:), ALLOCATABLE :: cputimes
48  REAL(rprec) :: time1, timecpu, time2, r, x, al31t, gradbs1,
49  1 gradbs2, gradbs3, gradbs4, al31s
50 C-----------------------------------------------
51 C E x t e r n a l F u n c t i o n s
52 C-----------------------------------------------
53  REAL(rprec) , EXTERNAL :: al31
54 C-----------------------------------------------
55 c
56 c define the starting CPU time
57 c
58  CALL second0 (time1)
59  timecpu = time1
60  IF (lscreen) WRITE (*, 4) version_
61  4 FORMAT(/,' Start BOOTSJ: Version ', a)
62 
63 c OPEN files
64 
65  iunit = indata0
66  CALL safe_open(iunit, ierr, 'input.' // trim(extension), 'old',
67  1 'formatted')
68  IF (ierr .ne. 0) THEN
69  print *,' Error opening input file: input.', trim(extension)
70  RETURN
71  END IF
72 
73  ijbs = jbs_file
74  CALL safe_open(ijbs, ierr, 'jBbs.'//trim(extension), 'replace',
75  1 'formatted')
76 
77  ians = ans_file
78  CALL safe_open(ians, ierr, 'answers.'//trim(extension), 'replace',
79  1 'formatted')
80 
81  ians_plot = ans_dat_file
82  CALL safe_open(ians_plot, ierr, 'answers_plot.'//trim(extension),
83  1 'replace', 'formatted')
84 
85 c READ and initialize data
86 
87  CALL datain(trim(extension), iunit_in, iunit, ians)
88  CLOSE (iunit)
89 
90  ntrigu = 3*nthetah/2 + 1
91  ntrigv = 2*nzetah
92  ALLOCATE (cputimes(irup))
93  ALLOCATE (
94  1 dmn(-mbuse:mbuse,0:nbuse), fmn(-mbuse:mbuse,0:nbuse),
95  2 rfmn(-mbuse:mbuse,0:nbuse),alpha1mn(-mbuse:mbuse,0:nbuse),
96  3 trigsv(ntrigv),trigsu(ntrigu), stat=irho)
97 
98  IF (irho .ne. 0) stop 'allocation error in bootsj main'
99 c convert jlist to idx form, THEN "and" the two lists
100 c SPH: Corrected error here, writing off END of jlist error when jlist <= 1
101 c
102 
103  jlist_idx = 0
104  DO irho = 1, irup
105  IF (jlist(irho) .gt. 1) jlist_idx(jlist(irho)-1) = 1
106  idx(irho) = idx(irho)*jlist_idx(irho)
107  ENDDO
108 
109 
110  l_boot_all = .true.
111 
112 ! IF ANY of the boozer evaluation surfaces are missing, or not requested
113 ! THEN set l_boot_all=false, total current can not be calculated
114 
115  DO irho=1, irup
116  IF(idx(irho) .eq. 0) l_boot_all = .false.
117  ENDDO
118  IF(.not.l_boot_all) THEN
119  IF (lscreen) WRITE (*,*) 'partial surface evaluation'
120  WRITE (ians,*) 'partial surface evaluation'
121  ENDIF
122 
123 
124  CALL fftfax (nthetah, ifaxu, trigsu)
125  CALL cftfax (nzetah, ifaxv, trigsv)
126 
127 
128 c start main radial loop
129 
130  DO irho = 1, irup
131 
132 c initialize timing for radius step
133 
134  CALL second0 (time2)
135  timecpu = time2 - time1
136  cputimes(irho) = timecpu
137 
138 c IF there is no boozer information available, skip radial point
139 
140  IF(idx(irho) .eq. 0) cycle
141  irho1 = irho - 1
142  r = sqrt(rhoar(irho) + 1.e-36_dp)
143 
144 c initialize angle grids grid for first radial evaluation. For this
145 c and ALL subsequent radial evaluate B and related and quantites as well
146 c as plasma derivatives and the tokamak trapped fraction.
147 
148  CALL bongrid(irho, ians)
149 
150 c calculate bootstrap current for equivalent tokamak
151 
152  x = fttok(irho)/(fptok(irho)+1.e-36_dp)
153 
154  al31t = al31(x,zeff1,alphae,alphai)
155 
156 c calculate gradient factors overALL normalization inlcuding q and
157 c boozer g.
158 
159  CALL grad (gradbs1, gradbs2, gradbs3, gradbs4, irho)
160 
161  bsdenste(irho) = gradbs1*al31t !due to dens gradient
162  bsdensti(irho) = gradbs2*al31t !due to dens gradient
163  bstempte(irho) = gradbs3*al31t !due to temp gradient
164  bstempti(irho) = gradbs4*al31t !due to temp gradient
165 
166  dibst(irho) = bsdenste(irho) + bsdensti(irho) + bstempte(irho)
167  1 + bstempti(irho) !total Jbst
168 
169  IF (l_boot_all) THEN
170  IF (irho .eq. 1) THEN
171  aibst(1) = dibst(1)*d_rho(1)
172  ELSE
173  aibst(irho) = aibst(irho1)+dibst(irho)*d_rho(irho)
174  ENDIF
175  END IF
176 
177 c Now start the general evaluation.
178 c Find coefficients d(n,m) and evaluate the fraction trapped.
179 
180  CALL denmf (trigsu, trigsv, ifaxu, ifaxv, irho)
181 
182 c Evaluate R, S, and H2.
183 
184  CALL caprsh2(irho)
185 
186 c evaluate the integral term.
187 
188  CALL woflam (trigsu, trigsv, ifaxu, ifaxv, irho)
189 
190 c evaluate the summation term in w(lambda) that does not depend on lambda.
191 c note that while the paper shows an itegral, it is the fpassing integral
192 c that cancels the fpassing in the over all multiplier
193 
194  CALL othersums(irho)
195 
196 c Calculate the final answer
197 
198  amain(irho) = p5*(one - aiogar(irho)/qsafety(irho)) + p5*(one +
199  1 aiogar(irho)/qsafety(irho))*h2(irho)
200 
201  gbsnorm(irho) = amain(irho) + other1(irho) + aiterm1(irho)
202 
203 c- derivative of the enclosed bootstrap current over the normalized
204 c toroidal flux, dIbs/ds, and the enclosed Ibs (in MA)
205 
206  x = ftrapped(irho)/(fpassing(irho)+1.e-36_dp)
207  al31s = al31(x,zeff1,alphae,alphai)
208  CALL grad (gradbs1, gradbs2, gradbs3, gradbs4, irho)
209 c
210 c !due to dens gradient
211  bsdense(irho) = gbsnorm(irho)*gradbs1*al31s
212 c !due to dens gradient
213  bsdensi(irho) = gbsnorm(irho)*gradbs2*al31s
214 c !due to temp gradient
215  bstempe(irho) = gbsnorm(irho)*gradbs3*al31s
216 c !due to temp gradient
217  bstempi(irho) = gbsnorm(irho)*gradbs4*al31s
218 
219  dibs(irho) = bsdense(irho) + bsdensi(irho) + bstempe(irho) +
220  1 bstempi(irho) !total Jbst (dI/ds)
221 
222 c convert to j dot b. 2*mu0 from beta, 10**6 from ma, psimax is 1/dpsi/ds
223 c and sign_jacobian takes out the sign previously used for dpsi to da
224 ccccc flux was changed to real flux in boot vmec so that the psimax now
225 ccccc needs an additional sign_jacobian so that the two will cancel
226  ajbbs(irho) = (2.0e6_dp)*mu0*dibs(irho)*
227  1 (pres1(irho)/betar(irho))/psimax
228 
229  IF (l_boot_all) THEN
230  IF (irho .eq. 1) THEN
231  aibs(1) = dibs(1)*d_rho(1)
232  ELSE
233  aibs(irho) = aibs(irho1) + dibs(irho)*d_rho(irho)
234  ENDIF
235  END IF
236 
237 c- the ratio of bootstrap current to that in ESD (equivalent symmetric device):
238 
239  bsnorm(irho) = dibs(irho)/(dibst(irho)+1.e-36_dp)
240 
241 c get time at END of loop IF completed
242 
243  CALL second0 (time2)
244  timecpu = time2 - time1
245  cputimes(irho) = timecpu
246 c
247 
248  END DO
249 c
250 c- Output answers for BOOTSJ
251 c
252  CALL output (cputimes, aibstot, ijbs, ians, ians_plot)
253  CLOSE(ians)
254  CLOSE(ians_plot)
255  CLOSE(ijbs)
256 
257  CALL deallocate_all
258  IF (lscreen) WRITE (*,400) (cputimes(irup)-cputimes(1))
259  400 FORMAT(1x,'Finished BOOTSJ, time = ', f8.3, ' sec')
260 
261  DEALLOCATE (cputimes, trigsu, trigsv)
262  DEALLOCATE (dmn, fmn, rfmn, alpha1mn)
263 
264  END SUBROUTINE bootsj
fftpack::cftfax
Definition: fftpack.f:3
fftpack::fftfax
Definition: fftpack.f:28