VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
freeb_data.f90
Go to the documentation of this file.
1
3
12SUBROUTINE freeb_data (rmnc, zmns, rmns, zmnc, bmodmn, bmodmn1)
13 USE vmec_main
14 USE vacmod, only: brv, bphiv, bzv, bsqvac, potvac, mnpd, xmpot, xnpot
15 USE realspace, ONLY: r1, z1
16
17 use dbgout
18
19 IMPLICIT NONE
20
21 REAL(rprec), DIMENSION(mnmax) :: rmnc, zmns, rmns, zmnc, bmodmn, bmodmn1
22
23 INTEGER :: iprint, nzskip, l, k, lk, mn, &
24 mn0, n, nedge, iu, iv, nl, lkr
25 REAL(rprec) :: zeta, potsin, potcos
26 REAL(rprec), ALLOCATABLE, DIMENSION(:) :: rb, phib, zb
27
28 logical :: dbgout_active
29
30 ! WRITE OUT EDGE VALUES OF FIELDS TO FORT.NEDGE0 (INCLUDE REFLECTED POINT)
31 ! NOTE: BR, BPHI, BZ WERE COMPUTED IN BSS, CALLED FROM EQFOR
32 IF (ivac.le.0 .or. .not.lfreeb) RETURN
33
34
35 ALLOCATE (rb(2*nznt), phib(2*nznt), zb(2*nznt), stat=l)
36 IF (l .ne. 0) stop 'allocation error in freeb_data'
37
38 dbgout_active = open_dbg_context("freeb_data", id=0)
39
40 nedge = 0
41 lkr = nznt
42 DO iv = 1,nzeta
43 zeta = (twopi*(iv-1))/(nzeta*nfp)
44 DO iu = 1,ntheta3
45 lk = iv + nzeta*(iu-1)
46 nl = ns*lk
47 nedge = nedge+1
48
49 rb(lk) = r1(nl,0) + r1(nl,1)
50 phib(lk) = zeta
51 zb(lk) = z1(nl,0) + z1(nl,1)
52
53 ! INCLUDE -u,-v POINTS HERE BY STELLARATOR SYMMETRY
54 IF (.not.lasym .and. (iu.ne.1 .and. iu.ne.ntheta2)) THEN
55 lkr = lkr + 1
56 nedge = nedge+1
57
58 rb(lkr) = rb(lk)
59 phib(lkr) =-phib(lk)
60 zb(lkr) =-zb(lk)
61
62 bredge(lkr) = -bredge(lk)
63 bpedge(lkr) = bpedge(lk)
64 bzedge(lkr) = bzedge(lk)
65 ENDIF
66 END DO
67 END DO
68
69 ! WRITE OUT (TO THREED1 FILE) VACUUM INFORMATION
70 IF (.not.lfreeb) THEN ! TODO: should be handled by check for (... .or. .not.lfreeb) above already
71 DEALLOCATE (rb, phib, zb, stat=l)
72 RETURN
73 END IF
74
75 ! TODO: below outputs only up to ntheta2, so why compute full theta range above?
76
77 nzskip = 1 + nzeta/6
78
79 ! iprint == 1
80 WRITE (nthreed, 750)
81750 FORMAT(/,3x,'NF*PHI',7x,' Rb ',8x,' Zb ',&
82 6x,'BSQMHDI',5x,'BSQVACI', &
83 5x,'BSQMHDF',5x,'BSQVACF',/)
84 DO l = 1, nzeta, nzskip
85 zeta = (360.0_dp*(l - 1))/nzeta
86
87 DO k = 1, ntheta2
88 lk = l + nzeta*(k - 1)
89 WRITE (nthreed, 770) zeta, rb(lk), zb(lk), &
90 (bsqsav(lk,n),n=1,3), bsqvac(lk)
91770 FORMAT(1p,e10.2,6e12.4)
92 END DO
93 end do
94
95 ! iprint == 2
96 WRITE (nthreed, 760)
97760 FORMAT(/,3x,'NF*PHI',7x,' Rb ',8x,' Zb ',&
98 6x,'BR', 8x,'BPHI', 6x,'BZ', &
99 8x,'BRv',7x,'BPHIv',5x,'BZv',/)
100 DO l = 1, nzeta, nzskip
101 zeta = (360.0_dp*(l - 1))/nzeta
102 DO k = 1, ntheta2
103 lk = l + nzeta*(k - 1)
104 WRITE (nthreed, 780) zeta, rb(lk), zb(lk), &
105 bredge(lk), bpedge(lk), bzedge(lk), &
106 brv(lk), bphiv(lk), bzv(lk)
107780 FORMAT(1p,e10.2,2e12.4,6e10.2)
108 END DO
109 end do
110
111 if (dbgout_active) then
112
113 call add_real_2d("rb", nzeta, ntheta3, rb)
114 call add_real_2d("phib", nzeta, ntheta3, phib)
115 call add_real_2d("zb", nzeta, ntheta3, zb)
116
117 call add_real_2d("bsqmhdi", nzeta, ntheta3, bsqsav(:,1))
118 call add_real_2d("bsqvaci", nzeta, ntheta3, bsqsav(:,2))
119 call add_real_2d("bsqmhdf", nzeta, ntheta3, bsqsav(:,3))
120 call add_real_2d("bsqvacf", nzeta, ntheta3, bsqvac)
121
122 call add_real_2d("bredge", nzeta, ntheta3, bredge)
123 call add_real_2d("bpedge", nzeta, ntheta3, bpedge)
124 call add_real_2d("bzedge", nzeta, ntheta3, bzedge)
125
126 call add_real_2d("brv", nzeta, ntheta2, brv)
127 call add_real_2d("bphiv", nzeta, ntheta2, bphiv)
128 call add_real_2d("bzv", nzeta, ntheta2, bzv)
129
130 end if
131
132 ! allocated in eqfor
133 DEALLOCATE (rb, phib, zb, bredge, bpedge, bzedge, stat=l)
134
135 ! DIAGNO v1 input ???
136 IF (lasym) THEN
137 WRITE (nthreed, 900)
138900 FORMAT(//,3x,'nb',2x,'mb',&
139 6x,'rbc',9x,'zbs',9x,'rbs',9x,'zbc', &
140 6x,'vacpot_s', 4x,'vacpot_c', &
141 2x,'|B|_c(s=.5)',1x,'|B|_c(s=1.)'/)
142 DO mn = 1, mnmax
143 potsin = 0
144 potcos = 0
145 DO mn0 = 1, mnpd
146 IF ( (nint(xnpot(mn0)).eq.nint(xn(mn))) .and. &
147 (nint(xmpot(mn0)).eq.nint(xm(mn))) ) THEN
148 potsin = potvac(mn0)
149 potcos = potvac(mn0+mnpd)
150 EXIT
151 END IF
152 END DO
153 WRITE (nthreed, 910) nint(xn(mn)/nfp), nint(xm(mn)), &
154 rmnc(mn), zmns(mn), rmns(mn), zmnc(mn), &
155 potsin, potcos, &
156 bmodmn(mn), bmodmn1(mn)
157910 FORMAT(i5,i4,1p,10e12.4) ! TODO: only 8 real?
158 END DO
159
160 ELSE
161 WRITE (nthreed, 800)
162800 FORMAT(//,3x,'nb',2x,'mb', &
163 6x,'rbc',9x,'zbs',&
164 6x,'vacpot_s', &
165 2x,'|B|_c(s=.5)',1x,'|B|_c(s=1.)'/)
166 DO mn = 1, mnmax
167 potsin = 0
168 DO mn0 = 1, mnpd
169 IF ( (nint(xnpot(mn0)).eq.nint(xn(mn))) .and. &
170 (nint(xmpot(mn0)).eq.nint(xm(mn))) ) THEN
171 potsin = potvac(mn0)
172 EXIT
173 END IF
174 END DO
175 WRITE (nthreed, 810) nint(xn(mn)/nfp), nint(xm(mn)), &
176 rmnc(mn), zmns(mn), &
177 potsin, &
178 bmodmn(mn), bmodmn1(mn)
179810 FORMAT(i5,i4,1p,7e12.4) ! TODO: only 5 REAL ???
180 END DO
181 END IF
182
183 WRITE (nthreed, *)
184
185 if (dbgout_active) then
186
187 ! For now, skip output of geometry and potvac,
188 ! since these are contained (and checked) in wout already.
189
190 call close_dbg_out()
191 end if
192
193END SUBROUTINE freeb_data
subroutine freeb_data(rmnc, zmns, rmns, zmnc, bmodmn, bmodmn1)
Write out edge values of fields.
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, target z1
Definition realspace.f90:11
real(rprec), dimension(:,:), allocatable r1
Definition realspace.f90:8
real(rprec), dimension(:), allocatable bsqvac
Definition vacmod.f90:43
real(rprec), dimension(:), allocatable bzv
Definition vacmod.f90:41
real(rprec), dimension(:), allocatable, target potvac
Definition vacmod.f90:29
real(rprec), dimension(:), allocatable brv
Definition vacmod.f90:39
real(rprec), dimension(:), allocatable bphiv
Definition vacmod.f90:40
real(rprec), dimension(:), allocatable bredge
Definition vmec_main.f90:75
integer ivac
counts number of free-boundary iterations
real(rprec), dimension(:,:), allocatable bsqsav
Definition vmec_main.f90:73
real(rprec), dimension(:), allocatable bpedge
Definition vmec_main.f90:76
real(rprec), dimension(:), allocatable bzedge
Definition vmec_main.f90:77