37 real(r8),
intent(in) :: a, r0, b0
38 real(r8),
dimension(nr),
intent(in) :: rav, fcirc
39 integer(itm_i4),
intent(in) :: kkk
41 real(r8),
parameter :: zmu0 = 4.e-7_r8 * pi
42 real(r8),
parameter :: ze = itm_qe
43 integer(itm_i4),
parameter :: nrbs = 2001
45 real(r8),
dimension(nrbs) :: psibs
46 real(r8),
dimension(npts) :: oldzj, oldold, oldoldzj
48 real(r8),
dimension(nr) :: pskn1
49 real(r8),
dimension(nr) :: p0tmp, ftmp, dptmp, dftmp
51 s_spline, ff_spline, q_spline, f_spline
52 real(r8),
dimension(nr) :: zps, zjj1, zjj2, zjj3, zjj4, zjj5, zjj6, djj5
53 real(r8),
dimension(nr) :: qq, dq, zjpar
54 real(r8),
dimension(nr) :: zjbt, zjsig
55 real(r8),
dimension(3) :: abltg
57 real(r8) :: radius, cpsurf
58 real(r8) :: pscale, rbscale
60 real(r8) :: sumq, sumj1, sumj2, sumj3, sumj4, sumj5, sumj6, &
61 sumj5r, sumqr, sumb0, sumbop, sumor2
62 real(r8) :: x, xr, xs, xrs, xrr, xss
63 real(r8) :: y, yr, ys, yrs, yrr, yss
64 real(r8) :: ps, psr, pss, psrs, psrr, psss
65 real(r8) :: xjac, xjacr, dl, bigr, gradps2, dssdr
66 real(r8) :: zjdchi, b02
67 real(r8) :: or2av, b02av, gbar
68 real(r8) :: ex, ext, denom, dndpsico, dtdpsico, ztmp, defte, tefte
69 real(r8) :: conste, consde
71 real(r8) :: zni, dni, tte, ti, dtte, dti
72 real(r8) :: rr, fcsp, fsp, qsp
73 real(r8) :: zznue, zznui, zsigsp, zsigneo, zzjbt, zhjbt
74 real(r8) :: zj0, sigz0
76 real(r8) :: sumerr, sumerr2
77 real(r8) :: dps, fi, pp
78 real(r8) :: zj, bsz, sigz, zj2
79 real(r8) :: oldzjz, zjzcalc
82 integer(itm_i4) :: iscalest, iscalend
83 integer(itm_i4) :: i, j, ngs
84 integer(itm_i4) :: typ
85 integer(itm_i4) :: n1, n2, n3, n4
86 integer(itm_i4) :: ni, nint
90 iscalest = scalest * npts
91 iscalend = scaleend * npts
94 pskn1(i) = psikn(nr + 1 - i)
100 call
spline(nr, pskn1, rav, 0._r8, 0._r8, typ, r_spline)
102 call
spline(nr, pskn1, fcirc, 0._r8, 0._r8, typ, c_spline)
105 if (ias == 1) factas = 1._r8
110 cpsurf = radius**2 / alfa
112 call
profiles(p0tmp, ftmp, dptmp, dftmp, a)
114 pscale = eps / alfa**2
118 p0tmp(i) = p0tmp(i) * pscale
119 dptmp(i) = dptmp(i) * pscale
120 ftmp(i) = ftmp(i) * rbscale
121 dftmp(i) = dftmp(i) * rbscale
139 n1 = (i - 1) * np + j
147 call
interpolation(2, xx(1, n1), xx(1, n2), xx(1, n3), xx(1, n4), &
148 r, s, x, xr, xs, xrs, xrr, xss)
149 call
interpolation(2, yy(1, n1), yy(1, n2), yy(1, n3), yy(1, n4), &
150 r, s, y, yr, ys, yrs, yrr, yss)
151 call
interpolation(2, psi(4 * (n1 - 1) + 1), psi(4 * (n2 - 1) + 1), &
152 psi(4 * (n3 - 1) + 1), psi(4 * (n4 - 1) + 1), r, s, ps, &
153 psr, pss, psrs, psrr, psss)
154 xjac = xr * ys - xs * yr
155 xjacr = xrr * ys + xr * yrs - xrs * yr - xs * yrr
156 dl = sqrt(xs**2+ys**2)
157 bigr = 1._r8 + eps * x
158 gradps2 = psr**2 * (xs**2 + ys**2) / xjac**2
159 dssdr = abs(psr) / (2._r8 * sqrt(ps))
161 gradps2 = gradps2 * (cpsurf / radius)**2
162 xjac = xjac * radius**2
167 xjacr = xjacr * radius**2
170 zjdchi = bigr * xjac / abs(psr)
172 sumj1 = sumj1 - ws * zjdchi / (gradps2 * bigr**2)
173 sumj2 = sumj2 - ws * zjdchi / gradps2
174 sumj3 = sumj3 - ws * zjdchi * bigr**2 / gradps2
175 sumj4 = sumj4 - ws * zjdchi / bigr**2
176 sumj5 = sumj5 - ws * zjdchi
177 sumj6 = sumj6 - ws * zjdchi * gradps2 / bigr**2
178 sumq = sumq - ws * xjac / (bigr * abs(psr))
180 sumqr = sumqr + psrr * xjac / ((psr**2) * bigr) * ws
181 sumqr = sumqr - xjacr / (bigr * psr) * ws
182 sumqr = sumqr + xjac * eps * xr / ((bigr**2) * psr) * ws
184 sumj5r = sumj5r + xjac * bigr * psrr / (psr**2) * ws
185 sumj5r = sumj5r - xjacr * bigr / psr * ws
186 sumj5r = sumj5r - xjac * eps *xr / psr * ws
190 b02 = (ftmp(nr - i + 1) / bigr)**2 + gradps2 / bigr**2
192 sumb0 = sumb0 - ws * zjdchi * b02
193 sumbop = sumbop - ws * zjdchi * b02 / gradps2
194 sumor2 = sumor2 - ws * zjdchi / bigr**2
200 zjj1(ni) = factas * sumj1 / (2._r8 * pi)
201 zjj2(ni) = factas * sumj2 / (2._r8 * pi)
202 zjj3(ni) = factas * sumj3 / (2._r8 * pi)
203 zjj4(ni) = factas * sumj4 / (2._r8 * pi)
204 zjj5(ni) = factas * sumj5 / (2._r8 * pi)
205 zjj6(ni) = factas * sumj6 / (2._r8 * pi)
207 djj5(ni) = factas * sumj5r / dssdr / (2._r8 * pi)
209 qq(ni) = factas * ftmp(ni) * sumq / (2._r8*pi)
210 dq(ni) = dftmp(ni) * sumq + ftmp(ni) * sumqr / dssdr
211 dq(ni) = dq(ni) * factas / (2._r8 * pi)
213 or2av = factas * sumor2 / (2._r8 * pi) / zjj5(ni)
214 b02av = factas * sumb0 / (2._r8 * pi) / zjj5(ni)
215 gbar = factas * sumbop / (2._r8 * pi)
217 zjpar(ni) = (-dptmp(ni) * ftmp(ni) - dftmp(ni) * b02av) &
218 / ( 2._r8 * cpsurf * sqrt(ps))
219 zjpar(ni) = zjpar(ni) / (zmu0 * r0 / b0**2)
222 qq(nr) = 2._r8 * qq(nr - 1) - qq(nr - 2)
223 qq(1) = 2._r8 * qq(2) - qq(3)
226 cpsurf = radius**2 * b0 / alfa
230 call
profiles(p0tmp, ftmp, dptmp, dftmp, a)
232 pscale = b0**2 * eps / (zmu0 * alfa**2)
236 p0tmp(i) = p0tmp(i) * pscale
241 dptmp(i) = dptmp(i) * pscale
242 ftmp(i) = ftmp(i) * rbscale
243 dftmp(i) = dftmp(i) * rbscale
247 call
spline(nr, pskn1, dptmp, 0._r8, 0._r8, typ, pp_spline)
249 if (te%shape > 0)
then
259 if (te%shape == 0)
then
261 ps = psi(4 * (nr - i) * np + 1)
264 pwr = 1._r8 / (etaei + 1._r8)
266 zni = zn0 * (p0tmp(i) / p0tmp(1))**pwr
267 dni = zn0 * pwr * abs((p0tmp(i) / p0tmp(1)))**(pwr - 1._r8) &
268 * dptmp(i) / p0tmp(1) / (2._r8 * ss)
269 tte = rpe * p0tmp(i) / (ze * zni * 1e19_r8)
270 ti = (1._r8 - rpe) * p0tmp(i) / (ze * zni * 1e19_r8)
272 dtte = rpe / (ze * 1e19_r8) * (dptmp(i) / (2._r8 * ss * zni) &
273 - p0tmp(i) * dni / zni**2)
274 dti = (1._r8 - rpe) / (ze * 1e19_r8) * (dptmp(i) / (2._r8 &
275 * ss * zni) - p0tmp(i) * dni / zni**2)
281 call
neo_helena(fcirc(i), tte, ti, zni, zeff, ftmp(i), qq(i), rr, &
282 eps * ss, dni, dtte, dti, zznue, zznui, zsigsp, zsigneo, &
290 if (i > 2) zjsig(i) = zjsig(i) / zjsig(2)
294 zjsig(1) = 2._r8 * zjsig(2) - zjsig(3)
295 zjsig(nr) = 2._r8 * zjsig(nr - 1) - zjsig(nr - 2)
297 zjbt(nr) = zjbt(nr - 1)
298 call
spline(nr, pskn1, zjbt, 0._r8, 0._r8, typ, z_spline)
299 call
spline(nr, pskn1, zjsig, 0._r8, 0._r8, typ, s_spline)
301 call
spline(nr, pskn1, ftmp, 0._r8, 0._r8, typ, ff_spline)
302 call
spline(nr, pskn1, qq, 0._r8, 0._r8, typ, q_spline)
304 psibs(i) = dble(i - 1) / dble(nrbs)
307 if (ps >= ne%psi_0)
then
315 if (ps >= te%psi_0)
then
320 dtte = -dtte * 1000.0_r8
328 rr = r0 *
spwert(nr, ps, r_spline, pskn1, abltg, 0)
329 fcsp =
spwert(nr, ps, c_spline, pskn1, abltg, 0)
330 fsp =
spwert(nr, ps, ff_spline, pskn1, abltg, 0)
331 qsp =
spwert(nr, ps, q_spline, pskn1, abltg, 0)
334 call
neo_helena(fcsp, tte, ti, zni, zeff, fsp, qsp, rr, eps * ss, dni, &
335 dtte, dti, zznue, zznui, zsigsp, zsigneo, zzjbt, zhjbt)
347 if (i > 2) zjsig(i) = zjsig(i) / zjsig(2)
352 zjsig(1) = 2._r8 * zjsig(2) - zjsig(3)
353 zjsig(nrbs) = 2._r8 * zjsig(nrbs - 1) - zjsig(nrbs - 2)
355 zjbt(nrbs) = 2._r8 * zjbt(nrbs - 1) - zjbt(nrbs - 2)
359 call
spline(nrbs, psibs, zjbt, 0._r8, 0._r8, typ, z_spline)
360 call
spline(nrbs, psibs, zjsig, 0._r8, 0._r8, typ, s_spline)
366 zjpar(1) = 2._r8 * zjpar(2) - zjpar(3)
371 call
spline(nr, pskn1, zjpar, 0._r8, 0._r8, typ, f_spline)
373 if (iscalejz > 0)
then
374 if (verbosity > 3)
write(iu6, *)
'scaling current'
375 if (verbosity > 3)
write(iu6, *)
'scalemix = ', scalemix
392 write(iu6, *)
"flux j_tor(i)_cal j_tor(i) oldzjz ", &
393 " scalejz bsz sigz zj pp"
394 dps = 1._r8 / dble(npts - 1)
396 fi = dble(i - 1) / dble(npts - 1)
402 zj =
spwert(nr, fi, f_spline, pskn1, abltg, 0)
403 nint = int((npts - 1) * fi) + 1
404 zj2 = zjpar(nint) + (fi - dps * (nint - 1)) / dps &
405 * (zjpar(nint + 1) - zjpar(nint))
407 if (te%shape == 0)
then
408 bsz =
spwert(nr, fi, z_spline, pskn1, abltg, 0)
409 sigz =
spwert(nr, fi, s_spline, pskn1, abltg, 0)
411 bsz =
spwert(nrbs, fi, z_spline, psibs, abltg, 0)
412 sigz =
spwert(nrbs, fi, s_spline, psibs, abltg, 0)
416 pp = -
spwert(nr, fi, pp_spline, pskn1, abltg, 0)
437 j_tor(i) = sigz + j_tor(i) * scalejz
452 if (j_tor(i - 1) > j_tor(i) .and. j_tor(i - 1) > oldzjz)
then
453 j_tor(i) = j_tor(i - 1)
457 j_tor(i) = oldzjz * 2.0_r8
465 if (i > 3 * npts / 4)
then
466 sumerr = sumerr + abs(oldzjz / j_tor(i) - 1.0_r8)
467 sumerr2 = sumerr2 + abs(bsz / (zj - sigz / sigz0 * zj0) &
478 j_tor(i) = scalemix * oldzjz + (1.0_r8 - scalemix) * j_tor(i) &
482 if (i > iscalend .or. i == 1)
then
484 write(iu6, 10) fi, zjzcalc, j_tor(i), oldzjz, scalejz, bsz, &
488 oldoldzj(i) = oldzj(i)
493 write(iu6, *)
'average error in current profile vs. ', &
494 'bootstrap current: ', sumerr2 / (npts / 4)
496 if (verbosity > 3)
write(iu6, *)
'average error in current iteration: ', &
524 10
format(f6.4, 9es14.6)
subroutine profiles(p0, rbphi, dp0, drbphi, a)
subroutine interpolation(type_interp, xn1, xn2, xn3, xn4, r, s, x, xr, xs, xrs, xrr, xss, yn1, yn2, yn3, yn4, pn1, pn2, pn3, pn4, yr, ys, ps)
subroutine allocate_spline_coefficients(spline, n)
subroutine spline(N, X, Y, ALFA, BETA, TYP, A, B, C, D)
REAL *8 function spwert(N, XWERT, A, B, C, D, X, ABLTG)
subroutine neo_helena(fcirc, te, ti, zzne, z, f, q, r, eps, zdne, dte, dti, znue, znui, sigspitz, signeo, zjbt, hjbt)
subroutine deallocate_spline_coefficients(spline)
subroutine scale_current(a, r0, b0, rav, fcirc, kkk)
subroutine ne_te_profile(dt, psi, f, df, const, df_in)