ETS  \$Id: Doxyfile 2162 2020-02-26 14:16:09Z g2dpc $
 All Classes Files Functions Variables Pages
mercier.f90
Go to the documentation of this file.
1 subroutine mercier(a, dimerc, drmerc, hh, qq, dq, geonc, zjpar)
2 !----------------------------------------------------------------------
3 ! subroutine for the ideal and resistive mercier criterion
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 : out_he
13  use mod_output
14 
15  implicit none
16 
17  real(r8), intent(in) :: a
18 
19  real(r8), dimension(nr), intent(out) :: dimerc, drmerc, hh, qq, dq
20  real(r8), dimension(nr), intent(out) :: geonc
21  real(r8), dimension(nr), intent(inout) :: zjpar
22 
23  real(r8), dimension(nr) :: p0tmp, ftmp, dptmp, dftmp
24  real(r8), dimension(nr) :: zps, zjj1, zjj2, zjj3, zjj4, zjj5, zjj6, djj5
25  real(r8), dimension(nr) :: bigg
26  real(r8) :: factas
27  real(r8) :: r0, b0
28  real(r8) :: radius, cpsurf
29  real(r8) :: rbscale
30  real(r8) :: r, s, ws
31  real(r8) :: sumq, sumj1, sumj2, sumj3, sumj4, sumj5, sumj6, sumj5r, &
32  sumqr, sumb0, sumbop, sumor2
33  real(r8) :: x, xr, xs, xrs, xrr, xss
34  real(r8) :: y, yr, ys, yrs, yrr, yss
35  real(r8) :: ps, psr, pss, psrs, psrr, psss
36  real(r8) :: xjac, xjacr, dl, bigr, gradps2, dssdr
37  real(r8) :: zjdchi, b02
38  real(r8) :: or2av, b02av, gbar
39  real(r8) :: shear
40  integer(itm_i4) :: i, j, ngs
41  integer(itm_i4) :: n1, n2 ,n3 ,n4
42  integer(itm_i4) :: ni
43 
44  factas = 2._r8
45  if (ias == 1) factas = 1._r8
46 
47  r0 = 1._r8
48  b0 = 1._r8
49  radius = eps * r0
50  cpsurf = radius**2 * b0 / alfa
51 
52  call profiles(p0tmp, ftmp, dptmp, dftmp, a)
53 
54  pscale = b0**2 * eps / alfa**2
55  rbscale = b0 * r0
56  do i = 1, nr
57  p0tmp(i) = p0tmp(i) * pscale
58  dptmp(i) = dptmp(i) * pscale
59  ftmp(i) = ftmp(i) * rbscale
60  dftmp(i) = dftmp(i) * rbscale
61  end do
62 
63  if (standard_output) then
64  write(out_he, 1)
65  write(out_he, 2)
66  write(out_he, 1)
67  write(out_he, *) '*i, ss, d_i, d_r, h,', &
68  ' q, shear, geonc *'
69  write(out_he, 1)
70  end if
71 !----------------------------------- flux surface integrals
72  r = -1._r8
73  do i = 1, nr - 1
74  sumq = 0._r8
75  sumj1 = 0._r8
76  sumj2 = 0._r8
77  sumj3 = 0._r8
78  sumj4 = 0._r8
79  sumj5 = 0._r8
80  sumj6 = 0._r8
81  sumj5r = 0._r8
82  sumqr = 0._r8
83  sumb0 = 0._r8
84  sumbop = 0._r8
85  sumor2 = 0._r8
86  do j = 1, np - 1
87  n1 = (i - 1) * np + j
88  n2 = n1 + 1
89  n3 = n2 + np
90  n4 = n1 + np
91 !------------------------------------- 4 point gaussian int. in s -----
92  do ngs = 1, 4
93  s = xgauss(ngs)
94  ws = wgauss(ngs)
95  call interpolation(2, xx(1, n1), xx(1, n2), xx(1, n3), xx(1, n4), &
96  r, s, x, xr, xs, xrs, xrr, xss)
97  call interpolation(2, yy(1, n1), yy(1, n2), yy(1, n3), yy(1, n4), &
98  r, s, y, yr, ys, yrs, yrr, yss)
99  call interpolation(2, psi(4 * (n1 - 1) + 1), psi(4 * (n2 - 1) + 1), &
100  psi(4 * (n3 - 1) + 1), psi(4 * (n4 - 1) + 1), r, s, ps, &
101  psr, pss, psrs, psrr, psss)
102 
103  xjac = xr * ys - xs * yr
104  xjacr = xrr * ys + xr * yrs - xrs * yr - xs * yrr
105 
106  dl = sqrt(xs**2 + ys**2)
107  bigr = 1._r8 + eps * x
108  gradps2 = psr**2 * (xs**2 + ys**2) / xjac**2
109  dssdr = abs(psr) / (2._r8 * sqrt(ps))
110 !------------------------------------------------ normalisations
111  gradps2 = gradps2 * (cpsurf / radius)**2
112  xjac = xjac * radius**2
113  bigr = bigr
114  dl = radius * dl
115  psr = cpsurf * psr
116  psrr = cpsurf * psrr
117  xjacr = xjacr * radius**2
118 !---------------------------------------------------------------
119 
120  zjdchi = bigr * xjac / abs(psr)
121 
122  sumj1 = sumj1 - ws * zjdchi / (gradps2 * bigr**2)
123  sumj2 = sumj2 - ws * zjdchi / gradps2
124  sumj3 = sumj3 - ws * zjdchi * bigr**2 / gradps2
125  sumj4 = sumj4 - ws * zjdchi / bigr**2
126  sumj5 = sumj5 - ws * zjdchi
127  sumj6 = sumj6 - ws * zjdchi * gradps2 / bigr**2
128  sumq = sumq - ws * xjac / (bigr * abs(psr))
129 
130  sumqr = sumqr + psrr * xjac / ((psr**2) * bigr) * ws
131  sumqr = sumqr - xjacr / (bigr * psr) * ws
132  sumqr = sumqr + xjac * eps * xr / ((bigr**2) * psr) * ws
133 
134  sumj5r = sumj5r + xjac * bigr * psrr / (psr**2) * ws
135  sumj5r = sumj5r - xjacr * bigr / psr * ws
136  sumj5r = sumj5r - xjac * eps * xr / psr * ws
137 
138 !----------------------------------------- d_nc from Hegna's
139 
140  b02 = (ftmp(nr - i + 1) / bigr)**2 + gradps2 / bigr**2
141 
142  sumb0 = sumb0 - ws * zjdchi * b02
143  sumbop = sumbop - ws * zjdchi * b02 / gradps2
144  sumor2 = sumor2 - ws * zjdchi / bigr**2
145 
146  end do
147  end do
148  ni = nr - i + 1
149  zps(ni) = sqrt(ps)
150  zjj1(ni) = factas * sumj1 / (2._r8 * pi)
151  zjj2(ni) = factas * sumj2 / (2._r8 * pi)
152  zjj3(ni) = factas * sumj3 / (2._r8 * pi)
153  zjj4(ni) = factas * sumj4 / (2._r8 * pi)
154  zjj5(ni) = factas * sumj5 / (2._r8 * pi)
155  zjj6(ni) = factas * sumj6 / (2._r8 * pi)
156 
157  djj5(ni) = factas * sumj5r / dssdr / (2._r8 * pi)
158 
159  qq(ni) = factas * ftmp(ni) * sumq / (2._r8 * pi)
160  dq(ni) = dftmp(ni) * sumq + ftmp(ni) * sumqr / dssdr
161  dq(ni) = dq(ni) * factas / (2._r8 * pi)
162 
163  or2av = factas * sumor2 / (2._r8*pi) / zjj5(ni)
164  b02av = factas * sumb0 / (2._r8*pi) / zjj5(ni)
165  gbar = factas * sumbop / (2._r8*pi)
166 
167  geonc(ni) = gbar / b02av
168 
169  zjpar(ni) = (-dptmp(ni) * ftmp(ni) - dftmp(ni) * b02av) &
170  / (2._r8 * cpsurf * sqrt(ps))
171 
172  bigg(ni) = factas * sumbop / (2._r8 * pi)
173 
174  dimerc(ni) = (dptmp(ni) * ftmp(ni) * zjj2(ni) / dq(ni) &
175  - 0.5_r8)**2 + dptmp(ni) / dq(ni)**2 * (djj5(ni) - dptmp(ni) &
176  * zjj3(ni)) * (ftmp(ni)**2 * zjj1(ni) + zjj4(ni))
177 
178  hh(ni) = ftmp(ni) * dptmp(ni) / dq(ni) * (zjj2(ni) &
179  - zjj5(ni) * (zjj4(ni) + ftmp(ni)**2 * zjj1(ni)) &
180  / (zjj6(ni) + ftmp(ni)**2 * zjj4(ni)))
181 
182  drmerc(ni) = dimerc(ni) - (hh(ni) - 0.5_r8)**2
183 
184  shear = sqrt(ps) * dq(ni) / qq(ni)
185 
186  if (standard_output) &
187  write(out_he, 3) i, sqrt(ps), -dimerc(ni), -drmerc(ni), hh(ni), &
188  qq(ni), shear, geonc(ni)
189  end do
190 
191  if (standard_output) write(out_he, 1)
192 
193 ! here previously plotted: mercier criteria dimerc(5),drmerc(5),
194 ! hh(5), qq(5)
195 
196 !----------------------- write data for analysis of Hegna's paper to file
197  if (additional_output) then
198  write(41, *) ' nr :'
199  write(41, *) nr - 2
200  write(41, *) ' di, dr, h, geonc : '
201  do i = 2, nr - 1
202  write(41, 42) i, dimerc(i), drmerc(i), hh(i), geonc(i)
203  end do
204  end if
205 
206  1 format(' ', 67('*'))
207  2 format(' * ideal and resistive mercier criterion ', 26(' '), '*')
208  3 format(i3, f10.5, 2es10.2, 3f8.3, es10.2, 2f8.3, es10.2)
209  42 format(i4, 12es12.4)
210 
211  return
212 end subroutine mercier
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 mercier(a, dimerc, drmerc, hh, qq, dq, geonc, zjpar)
Definition: mercier.f90:1