VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
surface.f90
Go to the documentation of this file.
1
3
15SUBROUTINE surface(rc, rs, zs, zc, xm, xn, mnmax, lasym, signgs)
16 USE vacmod
17
18 use dbgout
20
21 IMPLICIT NONE
22
23 INTEGER, intent(in) :: mnmax
24 REAL(rprec), DIMENSION(mnmax), intent(in) :: rc, rs, zs, zc, xm, xn
25 logical, intent(in) :: lasym
26 real(rprec), intent(in) :: signgs
27
28 INTEGER :: i, mn, m, n, n1
29 REAL(rprec) :: cosmn1, sinmn1
30
31 ! THIS ROUTINE COMPUTES THE SURFACE VALUES OF R,Z AND DERIVATIVES
32 !
33 ! Compute R & Z (and their derivatives) on surface
34 !
35 ! R = SUM [RC(m,n)*COS(mu - nv) + RS(m,n)*SIN(mu - nv)]
36 ! Z = SUM [ZS(m,n)*SIN(mu - nv) + ZC(m,n)*COS(mu - nv)]
37 !
38 ! NOTE: u, v here are actual angles (0, 2pi), NOT the normalized
39 ! variables used in PKM paper
40
41 r1b = 0; rub = 0; rvb = 0; ruu = 0; ruv = 0; rvv = 0
42 z1b = 0; zub = 0; zvb = 0; zuu = 0; zuv = 0; zvv = 0
43
44 DO mn = 1, mnmax
45 m = nint(xm(mn))
46 n = nint(xn(mn)/(nfper))
47 n1 = abs(n)
48 DO i = 1, nuv2
49 cosmn1 = cosu1(i,m)*cosv1(i,n1) + csign(n)*sinu1(i,m)*sinv1(i,n1)
50 sinmn1 = sinu1(i,m)*cosv1(i,n1) - csign(n)*cosu1(i,m)*sinv1(i,n1)
51 r1b(i) = r1b(i) + rc(mn) * cosmn1
52 rub(i) = rub(i) - xm(mn) * rc(mn) * sinmn1
53 rvb(i) = rvb(i) + xn(mn) * rc(mn) * sinmn1
54 z1b(i) = z1b(i) + zs(mn) * sinmn1
55 zub(i) = zub(i) + xm(mn) * zs(mn) * cosmn1
56 zvb(i) = zvb(i) - xn(mn) * zs(mn) * cosmn1
57 ruu(i) = ruu(i) - xm(mn) * xm(mn) * rc(mn) * cosmn1
58 ruv(i) = ruv(i) + xm(mn) * xn(mn) * rc(mn) * cosmn1
59 rvv(i) = rvv(i) - xn(mn) * xn(mn) * rc(mn) * cosmn1
60 zuu(i) = zuu(i) - xm(mn) * xm(mn) * zs(mn) * sinmn1
61 zuv(i) = zuv(i) + xm(mn) * xn(mn) * zs(mn) * sinmn1
62 zvv(i) = zvv(i) - xn(mn) * xn(mn) * zs(mn) * sinmn1
63 IF (lasym) THEN
64 r1b(i) = r1b(i) + rs(mn) * sinmn1
65 rub(i) = rub(i) + xm(mn) * rs(mn) * cosmn1
66 rvb(i) = rvb(i) - xn(mn) * rs(mn) * cosmn1
67 z1b(i) = z1b(i) + zc(mn) * cosmn1
68 zub(i) = zub(i) - xm(mn) * zc(mn) * sinmn1
69 zvb(i) = zvb(i) + xn(mn) * zc(mn) * sinmn1
70 ruu(i) = ruu(i) - xm(mn) * xm(mn) * rs(mn) * sinmn1
71 ruv(i) = ruv(i) + xm(mn) * xn(mn) * rs(mn) * sinmn1
72 rvv(i) = rvv(i) - xn(mn) * xn(mn) * rs(mn) * sinmn1
73 zuu(i) = zuu(i) - xm(mn) * xm(mn) * zc(mn) * cosmn1
74 zuv(i) = zuv(i) + xm(mn) * xn(mn) * zc(mn) * cosmn1
75 zvv(i) = zvv(i) - xn(mn) * xn(mn) * zc(mn) * cosmn1
76 END IF
77 END DO
78 END DO
79
80 !print *, "max R = ", maxval(r1b)
81
82 ! COMPUTE METRIC COEFFICIENTS GIJ_B AND SURFACE NORMAL COMPONENTS
83 ! [SNR, SNV, SNZ] = NP*[Xu cross Xv]
84 !
85 ! NOTE: These should be multiplied by -signgs to point OUTWARD from vacuum INTO plasma
86 ! for either handed-ness of the coordinate system
87 !
88 ! Eq. 2.4 in PKM has wrong sign for a left-handed coordinate system
89 !
90 ! NOTE: guv = .5*np guv_b; gvv = np*np* gvv_b, where GUV, GVV are the
91 ! REAL metric elements. CAP(A), etc. defined in Eq. (2.13) of PKM paper
92 !
93 ! AUU == NP*CAP(A) = .5*Xuu dot [Xu cross Xv] * NP
94 !
95 ! AUV == 2*NP*CAP(B) = Xuv dot [Xu cross Xv] * NP
96 !
97 ! AVV == NP*CAP(C) = .5*Xvv dot [Xu cross Xv] * NP
98 DO i = 1,nuv2
99 guu_b(i) = rub(i)*rub(i) + zub(i)*zub(i)
100 guv_b(i) = (rub(i)*rvb(i)+ zub(i)*zvb(i))*onp*2
101 gvv_b(i) = (rvb(i)*rvb(i)+ zvb(i)*zvb(i)+r1b(i)*r1b(i))*onp2
102 rzb2(i) = r1b(i)*r1b(i) + z1b(i)*z1b(i)
103 snr(i) = signgs*r1b(i)*zub(i)
104 snv(i) = signgs*(rub(i)*zvb(i) - rvb(i)*zub(i))
105 snz(i) =-signgs*r1b(i)*rub(i)
106 drv(i) = -(r1b(i)*snr(i) + z1b(i)*snz(i))
107 auu(i) = p5*(snr(i)*ruu(i) + snz(i)*zuu(i))
108 auv(i) = (snr(i)*ruv(i) + snv(i)*rub(i) + snz(i)*zuv(i))*onp
109 avv(i) = (snv(i)*rvb(i) + p5*(snr(i)*(rvv(i) - r1b(i)) + snz(i)* zvv(i)))*onp2
110 END DO
111
112 IF (.NOT.lasym) THEN
113 DO i = 1 + nv, nuv2 - nv
114 rzb2(imirr(i)) = rzb2(i)
115 r1b(imirr(i)) = r1b(i)
116 z1b(imirr(i)) =-z1b(i)
117 END DO
118 END IF
119
120 DO i = 1,nuv
121 rcosuv(i) = r1b(i)*cosuv(i)
122 rsinuv(i) = r1b(i)*sinuv(i)
123 END DO
124
125 if (open_dbg_context("vac1n_surface", num_eqsolve_retries)) then
126 call add_real_2d("r1b", nv, nu, r1b) ! nu !
127 call add_real_2d("rub", nv, nu3, rub)
128 call add_real_2d("rvb", nv, nu3, rvb)
129 call add_real_2d("ruu", nv, nu3, ruu)
130 call add_real_2d("ruv", nv, nu3, ruv)
131 call add_real_2d("rvv", nv, nu3, rvv)
132
133 call add_real_2d("z1b", nv, nu, z1b) ! nu !
134 call add_real_2d("zub", nv, nu3, zub)
135 call add_real_2d("zvb", nv, nu3, zvb)
136 call add_real_2d("zuu", nv, nu3, zuu)
137 call add_real_2d("zuv", nv, nu3, zuv)
138 call add_real_2d("zvv", nv, nu3, zvv)
139
140 call add_real_2d("guu_b", nv, nu3, guu_b)
141 call add_real_2d("guv_b", nv, nu3, guv_b)
142 call add_real_2d("gvv_b", nv, nu3, gvv_b)
143
144 call add_real_2d("rzb2", nv, nu, rzb2) ! nu !
145
146 call add_real_2d("snr", nv, nu3, snr)
147 call add_real_2d("snv", nv, nu3, snv)
148 call add_real_2d("snz", nv, nu3, snz)
149
150 call add_real_2d("drv", nv, nu3, drv)
151
152 call add_real_2d("auu", nv, nu3, auu)
153 call add_real_2d("auv", nv, nu3, auv)
154 call add_real_2d("avv", nv, nu3, avv)
155
156 call add_real_2d("rcosuv", nv, nu, rcosuv) ! nu !
157 call add_real_2d("rsinuv", nv, nu, rsinuv) ! nu !
158
159 call close_dbg_out()
160 end if
161
162END SUBROUTINE surface
logical function open_dbg_context(context_name, repetition, id)
check if any output is desired for the current iteration check if the given context should be openend...
Definition dbgout.f90:17
real(rprec), dimension(:), allocatable auu
Definition vacmod.f90:56
real(rprec), dimension(:), allocatable zuu
Definition vacmod.f90:89
real(rprec), dimension(:), allocatable zvb
Definition vacmod.f90:50
real(rprec), dimension(:), allocatable r1b
Definition vacmod.f90:45
real(rprec), dimension(:), allocatable ruv
Definition vacmod.f90:87
real(rprec), dimension(:), allocatable zub
Definition vacmod.f90:49
real(rprec), dimension(:), allocatable z1b
Definition vacmod.f90:48
real(rprec), dimension(:), allocatable zvv
Definition vacmod.f90:91
real(rprec), dimension(:), allocatable snz
Definition vacmod.f90:62
real(rprec), dimension(:), allocatable snr
Definition vacmod.f90:60
real(rprec) onp2
Definition vacmod.f90:25
real(rprec), dimension(:), allocatable ruu
Definition vacmod.f90:86
real(rprec), dimension(:), allocatable rzb2
Definition vacmod.f90:70
real(rprec), dimension(:), allocatable rub
Definition vacmod.f90:46
real(rprec), dimension(:), allocatable rsinuv
Definition vacmod.f90:73
real(rprec), dimension(:), allocatable rvb
Definition vacmod.f90:47
real(rprec), dimension(:), allocatable snv
Definition vacmod.f90:61
real(rprec), dimension(:), allocatable rvv
Definition vacmod.f90:88
real(rprec), dimension(:), allocatable guu_b
Definition vacmod.f90:66
real(rprec), dimension(:), allocatable auv
Definition vacmod.f90:57
real(rprec), dimension(:), allocatable avv
Definition vacmod.f90:58
real(rprec), dimension(:), allocatable gvv_b
Definition vacmod.f90:68
real(rprec), parameter p5
Definition vacmod.f90:13
real(rprec), dimension(:), allocatable guv_b
Definition vacmod.f90:67
real(rprec), dimension(:), allocatable zuv
Definition vacmod.f90:90
real(rprec), dimension(:), allocatable rcosuv
Definition vacmod.f90:72
real(rprec) onp
Definition vacmod.f90:24
real(rprec), dimension(:), allocatable drv
Definition vacmod.f90:64
integer num_eqsolve_retries
subroutine surface(rc, rs, zs, zc, xm, xn, mnmax, lasym, signgs)
Evaluate the geometry of the LCFS and tangential derivatives.
Definition surface.f90:16