VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
greenf.f90
Go to the documentation of this file.
1
3
9SUBROUTINE greenf(delgr, delgrp, ip)
10 USE vacmod
11
12! use dbgout
13
14 IMPLICIT NONE
15
16 INTEGER, INTENT(in) :: ip
17 REAL(rprec), DIMENSION(nuv), INTENT(out) :: delgr, delgrp
18
19 INTEGER, DIMENSION(2) :: ilow, ihigh
20 INTEGER :: ivoff, iskip, iuoff, i, kp, nloop, ivoff0
21 REAL(rprec):: xip, yip, ftemp, htemp ! xper, yper, sxsave, sysave
22
23 REAL(rprec), dimension(nvper) :: xper, yper, sxsave, sysave
24 integer, dimension(nvper,nuv) :: idx_tanu, idx_tanv
25 REAL(rprec), dimension(nvper,nuv) :: all_tanu, all_tanv
26
27
28 ! ON ENTRANCE, IP IS THE INDEX OF THE PRIMED MESH POINT (lies in 1st field period)
29 !
30 ! ON EXIT:
31 ! DELGR IS THE DIFFERENCE OF "GREEN'S FUNCTION" AND ANALYTIC APPROXIMATION, SUMMED OVER ALL FIELD PERIODS
32 ! DELGRP IS THE DIFFERENCE OF DERIVATIVE OF "GREEN'S FUNCTION" AND ANALYTIC APPROXIMATION.
33 !
34 ! BOTH THESE QUANTITIES ARE COMPUTED FOR ALL UNPRIMED U,V POINTS IN ONE FIELD PERIOD,
35 ! FOR THIS FIXED PRIMED POINT (IP).
36
37 ! COMPUTE OFFSETS FOR U,V ANGLE DIFFERENCES AND CONSTANTS
38
39 ! first round: up before singularity
40 ilow(1) = 1
41 ihigh(1) = ip - 1
42
43 ! second round: from after singularity onwards
44 ilow(2) = ip + 1
45 ihigh(2) = nuv
46
47 ivoff0 = nuv - (ip - 1)
48
49 iskip = (ip - 1)/nv ! implicit floor by conversion to integer
50 iuoff = nuv - nv*iskip
51
52 ! x == r*COS(ip), in 1st field period
53 xip = rcosuv(ip)
54
55 ! y == r*SIN(ip), in 1st field period
56 yip = rsinuv(ip)
57
58 delgr = 0
59 delgrp = 0
60
61 ! COMPUTE FIELD-PERIOD INVARIANT VECTORS
62 ! NOTE: |x - x'|**2 = gsave - 2*[x*x' + y*y']
63 DO i = 1, nuv
64 gsave(i) = rzb2(ip) + rzb2(i) - 2*z1b(ip)*z1b(i)
65 dsave(i) = drv(ip) + z1b(i)*snz(ip)
66 END DO
67
68 ! SUM OVER FIELD-PERIODS (NVPER=NFPER) OR INTEGRATE OVER NV (NVPER=64) IF NV == 1
69 !
70 ! NOTE THE SURFACE NORMAL SNORM == Xu cross Xv = NP*[SNR, SNV, SNZ]
71 ! IS PERIODIC ON EACH FIELD PERIOD: NOTE THE LOOP OVER KP IS A REDUCTION ON delgr, delgrp
72 DO kp = 1, nvper
73 ! add in offset due to toroidal module
74 ivoff = ivoff0 + 2*nu*(kp-1)
75
76 ! x(ip) in field period kp
77 xper(kp) = xip*cosper(kp) - yip*sinper(kp)
78
79 ! y(ip) in field period kp
80 yper(kp) = xip*sinper(kp) + yip*cosper(kp)
81
82 sxsave(kp) = (snr(ip)*xper(kp) - snv(ip)*yper(kp))/r1b(ip)
83 sysave(kp) = (snr(ip)*yper(kp) + snv(ip)*xper(kp))/r1b(ip)
84
85 IF (kp.EQ.1 .OR. nv.EQ.1) THEN
86 ! Tokamak: always
87 ! Stellarator: first toroidal module
88!
89 ! INITIALIZE ANALYTIC APPROXIMATIONS GA1, GA2
90 DO i = 1, nuv
91
92 idx_tanu(kp, i) = i+iuoff
93 idx_tanv(kp, i) = i+ivoff
94 all_tanu(kp, i) = tanu(i+iuoff)
95 all_tanv(kp, i) = tanv(i+ivoff)
96
97 ga1(kp,i) = tanu(i+iuoff)*( guu_b(ip)*tanu(i+iuoff) + guv_b(ip)*tanv(i+ivoff)) &
98 + gvv_b(ip)*tanv(i+ivoff)*tanv(i+ivoff)
99 ga2(kp,i) = tanu(i+iuoff)*( auu(ip)*tanu(i+iuoff) + auv(ip)*tanv(i+ivoff)) &
100 + avv(ip)*tanv(i+ivoff)*tanv(i+ivoff)
101 END DO
102
103 DO nloop = 1, 2
104 IF (kp.GT.1 .AND. nloop.EQ.2) then
105 ! Tokamak (kp>1): only need to skip exactly singular point if in same module
106 ! --> first round already goes to nuv, since ihigh(1) was updated below
107 cycle
108 end if
109
110 ! loop over grid points; ilow, ihigh used to skip point at which exact singularity occurs: ip==i
111 DO i = ilow(nloop), ihigh(nloop)
112 ga2(kp,i) = ga2(kp,i)/ga1(kp,i)
113 ga1(kp,i) = one/sqrt(ga1(kp,i))
114 ftemp = one/(gsave(i) - 2*(xper(kp)*rcosuv(i) + yper(kp)*rsinuv(i)))
115 htemp = sqrt(ftemp)
116 delgrp(i) = delgrp(i) + ftemp*htemp*(rcosuv(i)*sxsave(kp) + rsinuv(i)*sysave(kp) + dsave(i)) - ga2(kp,i)*ga1(kp,i)
117 delgr(i) = delgr(i) + htemp - ga1(kp,i)
118 END DO
119 END DO
120
121 ! update the upper bound of the first loop
122 ! --> in Tokamak case, skip exact singularity only if in first toroidal "module"
123 ihigh(1) = nuv
124
125 ELSE
126 ! Tokamak: never
127 ! Stellarator: all toroidal modules after first one
128
129 DO i = 1,nuv
130 ftemp = one/(gsave(i) - 2*(xper(kp)*rcosuv(i) + yper(kp)*rsinuv(i)))
131 htemp = sqrt(ftemp)
132 delgrp(i) = delgrp(i) + ftemp*htemp*(rcosuv(i)*sxsave(kp) + rsinuv(i)*sysave(kp) + dsave(i))
133 delgr(i) = delgr(i) + htemp
134 END DO
135 ENDIF
136 END DO
137
138 IF (nv.EQ.1) THEN
139 ! Tokamak: toroidal summation is actually an integration
140 ! --> need to divide by step length!
141 delgrp = delgrp/nvper
142 delgr = delgr /nvper
143 END IF
144
145! if (open_dbg_context("vac1n_greenf", id=icall)) then
146!
147! call add_real_1d("xper", nvper, xper)
148! call add_real_1d("yper", nvper, yper)
149! call add_real_1d("sxsave", nvper, sxsave)
150! call add_real_1d("sysave", nvper, sysave)
151!
152! call add_int_2d("idx_tanu", nvper, nuv, idx_tanu)
153! call add_int_2d("idx_tanv", nvper, nuv, idx_tanv)
154! call add_real_2d("all_tanu", nvper, nuv, all_tanu)
155! call add_real_2d("all_tanv", nvper, nuv, all_tanv)
156!
157! call close_dbg_out()
158! end if
159
160
161END SUBROUTINE greenf
subroutine greenf(delgr, delgrp, ip)
Compute the regularized evaluation of the Green's function and the source term.
Definition greenf.f90:10
real(rprec), dimension(:), allocatable auu
Definition vacmod.f90:56
real(rprec), dimension(:), allocatable r1b
Definition vacmod.f90:45
real(rprec), dimension(:), allocatable z1b
Definition vacmod.f90:48
real(rprec), dimension(:), allocatable gsave
Definition vacmod.f90:145
real(rprec), dimension(:), allocatable snz
Definition vacmod.f90:62
real(rprec), dimension(:), allocatable snr
Definition vacmod.f90:60
real(rprec), dimension(:,:), allocatable ga2
Definition vacmod.f90:147
real(rprec), dimension(:), allocatable rzb2
Definition vacmod.f90:70
real(rprec), dimension(:), allocatable rsinuv
Definition vacmod.f90:73
real(rprec), dimension(:,:), allocatable ga1
Definition vacmod.f90:146
real(rprec), dimension(:), allocatable dsave
Definition vacmod.f90:148
real(rprec), dimension(:), allocatable snv
Definition vacmod.f90:61
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), dimension(:), allocatable guv_b
Definition vacmod.f90:67
real(rprec), dimension(:), allocatable rcosuv
Definition vacmod.f90:72
real(rprec), dimension(:), allocatable drv
Definition vacmod.f90:64