ETS  \$Id: Doxyfile 2162 2020-02-26 14:16:09Z g2dpc $
 All Classes Files Functions Variables Pages
passing_particles.f90
Go to the documentation of this file.
1 subroutine passing_particles(a, fcirc, b02av, b0max, rav, equilibrium)
2 !----------------------------------------------------------------------
3 ! subroutine for the fraction of circulating particles
4 !----------------------------------------------------------------------
5 
6  use itm_types
7  use mod_parameter
8  use mod_dat
9  use mod_gauss
10  use mod_mesh
11  use mod_helena_io, only : iu6
13  use euitm_schemas
14 
15  implicit none
16 
17  type(type_equilibrium), intent(inout) :: equilibrium
18  real(r8), intent(in) :: a
19  real(r8), dimension(nr), intent(out) :: fcirc, b02av, b0max, rav
20 
21  integer(itm_i4), parameter :: nk = 101
22 
23  real(r8), dimension(nk) :: sumk
24  real(r8), dimension(nr) :: p0tmp, ftmp, dptmp, dftmp
25  real(r8) :: factas
26  real(r8) :: r0, b0
27  real(r8) :: radius, cpsurf
28  real(r8) :: rbscale
29  real(r8) :: r, s, ws
30  real(r8) :: sum1, sum2, sumr, sum
31  real(r8) :: b02max, b02, bm
32  real(r8) :: x, xr, xs, xrs, xrr, xss
33  real(r8) :: y, yr, ys, yrs, yrr, yss
34  real(r8) :: ps, psr, pss, psrs, psrr, psss
35  real(r8) :: xjac, bigr, gradps2, zjdchi, zlam
36  integer(itm_i4) :: i, j, k, ngs
37  integer(itm_i4) :: n1, n2, n3, n4
38  integer(itm_i4) :: ni
39 
40  factas = 2._r8
41  if (ias == 1) factas = 1._r8
42 
43  r0 = 1._r8
44  b0 = 1._r8
45  radius = eps * r0
46  cpsurf = radius**2 * b0 / alfa
47 
48  call profiles(p0tmp, ftmp, dptmp, dftmp, a)
49 
50  rbscale = b0 * r0
51 
52  do i = 1, nr
53  ftmp(i) = ftmp(i) * rbscale
54  dftmp(i) = dftmp(i) * rbscale
55  end do
56 !---------------------- find bmax and b^2 average on every surface
57  r = -1._r8
58  do i = 1, nr - 1
59  sum1 = 0._r8
60  sum2 = 0._r8
61  sumr = 0._r8
62  b02max = -1.e20_r8
63  do j = 1, np - 1
64  n1 = (i - 1) * np + j
65  n2 = n1 + 1
66  n3 = n2 + np
67  n4 = n1 + np
68 !------------------------------------- 4 point gaussian int. in s -----
69  do ngs = 1, 4
70  s = xgauss(ngs)
71  ws = wgauss(ngs)
72  call interpolation(2, xx(1, n1), xx(1, n2), xx(1, n3), xx(1, n4), &
73  r, s, x, xr, xs, xrs, xrr, xss)
74  call interpolation(2, yy(1, n1), yy(1, n2), yy(1, n3), yy(1, n4), &
75  r, s, y, yr, ys, yrs, yrr, yss)
76  call interpolation(2, psi(4 * (n1 - 1) + 1), psi(4 * (n2 - 1) + 1), &
77  psi(4 * (n3 - 1) + 1), psi(4 * (n4 - 1) + 1), r, s, ps, &
78  psr, pss, psrs, psrr, psss)
79  xjac = xr * ys - xs * yr
80  bigr = 1._r8 + eps * x
81  gradps2 = psr**2 * (xs**2 + ys**2) / xjac**2
82 !------------------------------------------------ normalisations
83  gradps2 = gradps2 * (cpsurf / radius)**2
84  xjac = xjac * radius**2
85  bigr = bigr
86  psr = cpsurf * psr
87 !---------------------------------------------------------------
88  zjdchi = bigr * xjac / abs(psr)
89  b02 = (ftmp(nr - i + 1) / bigr)**2 + gradps2 / bigr**2
90  sum1 = sum1 - ws * zjdchi
91  sum2 = sum2 - ws * zjdchi * b02
92  sumr = sumr - ws * zjdchi * bigr
93 
94  if (b02 > b02max) b02max = b02
95  end do
96  end do
97  ni = nr - i + 1
98  sum1 = factas * sum1 / (2._r8 * pi)
99  sum2 = factas * sum2 / (2._r8 * pi)
100  sumr = factas * sumr / (2._r8 * pi)
101  b02av(ni) = sum2 / sum1
102  b0max(ni) = sqrt(abs(b02max))
103  rav(ni) = sumr / sum1
104  end do
105 
106 !---------------------------------- calculate average term in integral
107  r = -1._r8
108  do i = 1, nr - 1
109  sum1 = 0._r8
110  do k = 1, nk
111  sumk(k) = 0._r8
112  end do
113  do j = 1, np - 1
114  n1 = (i - 1) * np + j
115  n2 = n1 + 1
116  n3 = n2 + np
117  n4 = n1 + np
118 !------------------------------------- 4 point gaussian int. in s -----
119  do ngs = 1, 4
120  s = xgauss(ngs)
121  ws = wgauss(ngs)
122  call interpolation(2, xx(1, n1), xx(1, n2), xx(1, n3), xx(1, n4), &
123  r, s, x, xr, xs, xrs, xrr, xss)
124  call interpolation(2, yy(1, n1), yy(1, n2), yy(1, n3), yy(1, n4), &
125  r, s, y, yr, ys, yrs, yrr, yss)
126  call interpolation(2, psi(4 * (n1 - 1) + 1), psi(4 * (n2 - 1) + 1), &
127  psi(4 * (n3 - 1) + 1), psi(4 * (n4 - 1) + 1), r, s, ps, &
128  psr, pss, psrs, psrr, psss)
129 
130  xjac = xr * ys - xs * yr
131  bigr = 1._r8 + eps * x
132  gradps2 = psr**2 * (xs**2 + ys**2) / xjac**2
133 !------------------------------------------------ normalisations
134  gradps2 = gradps2 * (cpsurf / radius)**2
135  xjac = xjac * radius**2
136  bigr = bigr
137  psr = cpsurf * psr
138 !---------------------------------------------------------------
139  zjdchi = bigr * xjac / abs(psr)
140  b02 = (ftmp(nr - i + 1) / bigr)**2 + gradps2 / bigr**2
141  b0 = sqrt(b02)
142  bm = b0max(nr - i + 1)
143  do k = 1, nk
144  zlam = dble(k - 1) / dble(nk - 1)
145  sumk(k) = sumk(k) - ws * zjdchi * sqrt(abs(1._r8 - zlam &
146  * b0 / bm))
147  end do
148  sum1 = sum1 - ws * zjdchi
149  end do
150  end do
151 !--- axis: ni = 1, boundary: ni = nr
152  ni = nr - i + 1
153 
154 !------------------------------------------ integrate over lambda
155  sum = 0._r8
156  do k = 2, nk - 1
157  zlam = dble(k - 1) / dble(nk - 1)
158  sum = sum + zlam * sum1 / sumk(k)
159  end do
160  fcirc(ni) = (sum + 0.5_r8 * sum1 / sumk(nk)) / dble(nk - 1)
161  fcirc(ni) = 0.75_r8 * fcirc(ni) * b02av(ni) / b0max(ni)**2
162 ! if (verbosity > 3) &
163 ! write(iu6, 41) i, sqrt(ps), b02av(ni), b0max(ni), fcirc(ni)
164  end do
165 
166  equilibrium%profiles_1d%ftrap(2 : nr) = 1.0_r8 - fcirc(2 : nr)
167 !--- no trapped particles on axis
168  equilibrium%profiles_1d%ftrap(1) = 0._r8
169 
170  if (verbosity > 2) write(iu6, *) ' done passing particles'
171 
172 ! 41 format(i3, 15es11.3)
173 
174  return
175 end subroutine passing_particles
subroutine profiles(p0, rbphi, dp0, drbphi, a)
Definition: profiles.f90:1
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 passing_particles(a, fcirc, b02av, b0max, rav, equilibrium)