22SUBROUTINE mercier(gsqrt, bsq, bdotj, iotas, wint, &
24 bsubu, vp, phips, pres, ns, nznt)
36 REAL(rprec),
DIMENSION(ns,nznt),
INTENT(in) :: gsqrt
37 REAL(rprec),
DIMENSION(ns,nznt),
INTENT(in) :: bsq
38 REAL(rprec),
DIMENSION(ns,nznt),
INTENT(inout) :: bdotj
39 REAL(rprec),
DIMENSION(ns),
INTENT(in) :: iotas
40 REAL(rprec),
DIMENSION(ns*nznt),
INTENT(in) :: wint
41 REAL(rprec),
DIMENSION(ns,nznt,0:1),
INTENT(in) :: r1
42 REAL(rprec),
DIMENSION(ns,nznt,0:1),
INTENT(in) :: rt
43 REAL(rprec),
DIMENSION(ns,nznt,0:1),
INTENT(in) :: rz
44 REAL(rprec),
DIMENSION(ns,nznt,0:1),
INTENT(in) :: zt
45 REAL(rprec),
DIMENSION(ns,nznt,0:1),
INTENT(in) :: zz
46 REAL(rprec),
DIMENSION(ns*nznt),
INTENT(in) :: bsubu
47 REAL(rprec),
DIMENSION(ns),
INTENT(in) :: vp
48 REAL(rprec),
DIMENSION(ns),
INTENT(in) :: phips
49 REAL(rprec),
DIMENSION(ns),
INTENT(in) :: pres
50 INTEGER,
INTENT(in) :: ns
51 INTEGER,
INTENT(in) :: nznt
53 REAL(rprec),
PARAMETER :: p5 = 0.5_dp, two = 2.0_dp
56 REAL(rprec) :: sign_jac, hs, sqs, denom
57 REAL(rprec),
DIMENSION(:,:),
ALLOCATABLE :: gpp, gsqrt_full, b2
58 REAL(rprec),
DIMENSION(nznt) :: gtt, rtf, ztf, &
59 rzf, zzf, r1f, jdotb, ob2, b2i
60 REAL(rprec),
DIMENSION(ns) :: vp_real, phip_real, &
61 shear, vpp, presp, torcur, ip, sj, tpp, tjb, tbb, tjj
62 CHARACTER(LEN=120) mercier_file
66 CALL safe_open (nmerc, imercier0, mercier_file,
'replace',
'formatted')
67 IF (imercier0 .ne. 0)
RETURN
69 ALLOCATE (gpp(ns,nznt), gsqrt_full(ns,nznt), b2(ns,nznt), stat=i)
70 IF (i .ne. 0) stop
'allocation error in Mercier'
96 IF (ns1 .le. 0)
RETURN
101 IF (gsqrt(ns,1) .ne. zero)
then
102 sign_jac = abs(gsqrt(ns,1))/gsqrt(ns,1)
104 IF (sign_jac .eq. zero)
RETURN
109 phip_real = twopi * phips * sign_jac
112 vp_real(2:ns) = sign_jac*(twopi*twopi)*vp(2:ns)/phip_real(2:ns)
116 torcur(i)=sign_jac*twopi*sum(bsubu(i:
nrzt:ns)*wint(i:
nrzt:ns))
121 phip_real(i) = p5*(phip_real(i+1) + phip_real(i))
122 denom = one/(hs*phip_real(i))
124 shear(i) = (iotas(i+1) - iotas(i))*denom
125 vpp(i) = (vp_real(i+1) - vp_real(i))*denom
126 presp(i) = (pres(i+1) - pres(i))*denom
127 ip(i) = (torcur(i+1) - torcur(i))*denom
133 gsqrt_full(i,:) = p5*(gsqrt(i,:) + gsqrt(i+1,:))
134 bdotj(i,:) = bdotj(i,:)/gsqrt_full(i,:)
135 gsqrt_full(i,:) = gsqrt_full(i,:)/phip_real(i)
137 sj(i) = hs*(i-1.0_dp)
140 rtf(:) = rt(i,:,0) + sqs*rt(i,:,1)
141 ztf(:) = zt(i,:,0) + sqs*zt(i,:,1)
142 rzf(:) = rz(i,:,0) + sqs*rz(i,:,1)
143 zzf(:) = zz(i,:,0) + sqs*zz(i,:,1)
144 r1f(:) = r1(i,:,0) + sqs*r1(i,:,1)
146 gtt(:) = rtf(:)*rtf(:) + ztf(:)*ztf(:)
148 gpp(i,:) = gsqrt_full(i,:)**2.0_dp &
149 / ( gtt(:)*r1f(:)**2.0_dp &
150 + (rtf(:)*zzf(:) - rzf(:)*ztf(:))**2.0_dp)
156 b2(i,:) = two*(bsq(i,:) - pres(i))
160 b2i(:) = p5*(b2(i+1,:) + b2(i,:))
162 ob2(:) = gsqrt_full(i,:)/b2i(:)
163 tpp(i) = sum(ob2(:)*wint(i:
nrzt:ns))
165 ob2(:) = b2i(:) * gsqrt_full(i,:) * gpp(i,:)
166 tbb(i) = sum(ob2(:)*wint(i:
nrzt:ns))
168 jdotb(:) = bdotj(i,:) * gpp(i,:) * gsqrt_full(i,:)
169 tjb(i) = sum(jdotb(:)*wint(i:
nrzt:ns))
171 jdotb(:) = jdotb(:) * bdotj(i,:) / b2i(:)
172 tjj(i) = sum(jdotb(:)*wint(i:
nrzt:ns))
18690
FORMAT(6x,
'S',10x,
'PHI',9x,
'IOTA',8x,
'SHEAR',7x,
' VP ',8x,
'WELL', &
187 8x,
'ITOR',7x,
'ITOR''',7x,
'PRES',7x,
'PRES''',/,120(
'-'))
191 sqs = p5*(vp_real(i) + vp_real(i+1))*sign_jac
192 IF (sqs .eq. zero) cycle
196 hs*sum(phip_real(2:i)), &
197 p5*(iotas(i+1)+iotas(i)), &
201 p5*(torcur(i) + torcur(i+1)), &
203 p5*(pres(i) + pres(i+1)), &
206100
FORMAT(1p,10e12.4)
209190
FORMAT(/,6x,
'S',8x,
'DMerc',8x,
'DShear',7x,
'DCurr',7x,
'DWell',7x,
'Dgeod',/,100(
'-'))
212 tpp(i) = tpp(i) * (twopi*twopi)
213 tjb(i) = tjb(i) * (twopi*twopi)
214 tbb(i) = tbb(i) * (twopi*twopi)
215 tjj(i) = tjj(i) * (twopi*twopi)
217 dshear(i) = shear(i) * shear(i)/4.0_dp
218 dcurr(i) =-shear(i) * (tjb(i) - ip(i) *tbb(i))
219 dwell(i) = presp(i) * (vpp(i) - presp(i) *tpp(i))*tbb(i)
220 dgeod(i) = tjb(i) *tjb(i) - tbb(i) *tjj(i)
240 call add_real(
"sign_jac", sign_jac)
242 call add_real_1d(
"phip_real", ns-1, phip_real(2:ns))
243 call add_real_1d(
"vp_real", ns-1, vp_real(2:ns))
244 call add_real_1d(
"torcur", ns-1, torcur(2:ns))
246 call add_real_1d(
"shear", ns-2, shear(2:ns1))
247 call add_real_1d(
"vpp", ns-2, vpp(2:ns1))
248 call add_real_1d(
"presp", ns-2, presp(2:ns1))
249 call add_real_1d(
"ip", ns-2, ip(2:ns1))
251 call add_real_3d(
"gsqrt_full", ns-2,
nzeta,
ntheta3, gsqrt_full(2:ns1,:))
253 call add_real_3d(
"gpp", ns-2,
nzeta,
ntheta3, gpp(2:ns1,:))
254 call add_real_3d(
"b2", ns-1,
nzeta,
ntheta3, b2(2:ns,:))
256 call add_real_1d(
"tpp", ns-2, tpp(2:ns1))
257 call add_real_1d(
"tbb", ns-2, tbb(2:ns1))
258 call add_real_1d(
"tjb", ns-2, tjb(2:ns1))
259 call add_real_1d(
"tjj", ns-2, tjj(2:ns1))
261 call add_real_1d(
"sj", ns , sj)
262 call add_real_1d(
"Dshear", ns-2,
dshear(2:ns1))
263 call add_real_1d(
"Dcurr", ns-2,
dcurr(2:ns1))
264 call add_real_1d(
"Dwell", ns-2,
dwell(2:ns1))
265 call add_real_1d(
"Dgeod", ns-2,
dgeod(2:ns1))
266 call add_real_1d(
"DMerc", ns-2,
dmerc(2:ns1))
271 DEALLOCATE (gpp, gsqrt_full, b2, stat=i)
subroutine mercier(gsqrt, bsq, bdotj, iotas, wint, r1, rt, rz, zt, zz, bsubu, vp, phips, pres, ns, nznt)
Evaluate the Mercier stability criterion.