5 #include <PB3D_macros.h>
11 use read_wout_mod,
only: read_wout_file, read_wout_deallocate, &
18 &bsubumns, bsubumnc, bsubvmns, bsubvmnc, bsubsmns, bsubsmnc, &
21 &lmns, lmnc, rmns, rmnc, zmns, zmnc, &
33 integer function read_vmec(n_r_in,use_pol_flux_V)
result(ierr)
37 character(*),
parameter :: rout_name =
'read_VMEC'
40 integer,
intent(inout) :: n_r_in
41 logical,
intent(inout) :: use_pol_flux_v
45 real(dp),
allocatable :: r_v(:)
46 real(dp),
allocatable :: l_c_h(:,:,:)
47 real(dp),
allocatable :: l_s_h(:,:,:)
48 real(dp),
allocatable :: jac_c_h(:,:,:)
49 real(dp),
allocatable :: jac_s_h(:,:,:)
50 character(len=max_str_ln) :: err_msg
51 character(len=8) :: flux_name
52 real(dp),
allocatable :: b_v_sub_c_m(:,:,:), b_v_sub_s_m(:,:,:)
54 real(dp),
allocatable :: b_v_c_h(:,:), b_v_s_h(:,:)
60 call writo(
'Reading data from VMEC output "' &
66 &
call writo(
'There seems to be a dot "." in "'//trim(
eq_name)//&
67 &
'". This can create problems.', alert=.true.)
68 call read_wout_file(
eq_name,ierr)
69 chckerr(
'Failed to read the VMEC file')
87 if (use_pol_flux_v)
then
88 flux_name =
'poloidal'
90 flux_name =
'toroidal'
92 b_0_v = sum(1.5*bmnc(:,2)-0.5_dp*bmnc(:,3))
94 call writo(
'VMEC version is ' // trim(
r2str(vmec_version)))
96 call writo(
'Free boundary VMEC')
98 call writo(
'Fixed boundary VMEC')
101 call writo(
'No stellarator symmetry')
103 call writo(
'Stellarator symmetry')
105 call writo(
'VMEC has '//trim(
i2str(mpol_v))//
' poloidal and '&
106 &//trim(
i2str(ntor_v))//
' toroidal modes,')
107 if (ntor_v.gt.0)
call writo(
'(basic toroidal field period NFP = '//&
108 &trim(
i2str(nfp_v))//
')')
109 call writo(
'defined on '//trim(
i2str(n_r_in))//
' '//flux_name//&
112 call writo(
'Running tests')
114 if (mnmax_v.ne.((ntor_v+1)+(2*ntor_v+1)*(mpol_v-1)))
then
115 err_msg =
'Inconsistency in ntor_V, mpol_V and mnmax_V'
121 call writo(
'Updating variables')
122 allocate(
mn_v(mnmax_v,2))
123 mn_v(:,1) = nint(xm(1:mnmax_v))
124 mn_v(:,2) = nint(xn(1:mnmax_v))
127 call writo(
'Data from VMEC output successfully read')
129 call writo(
'Saving VMEC output to PB3D')
141 allocate(l_c_h(mnmax_v,n_r_in,0:0))
142 allocate(l_s_h(mnmax_v,n_r_in,0:0))
143 allocate(jac_c_h(mnmax_v,n_r_in,0:0))
144 allocate(jac_s_h(mnmax_v,n_r_in,0:0))
147 r_v_c(:,:,0) = rmnc(1:mnmax_v,:)
148 z_v_s(:,:,0) = zmns(1:mnmax_v,:)
149 l_s_h(:,:,0) = lmns(1:mnmax_v,:)
150 jac_c_h(:,:,0) = gmnc(1:mnmax_v,:)
152 r_v_s(:,:,0) = rmns(1:mnmax_v,:)
153 z_v_c(:,:,0) = zmnc(1:mnmax_v,:)
154 l_c_h(:,:,0) = lmnc(1:mnmax_v,:)
155 jac_s_h(:,:,0) = gmns(1:mnmax_v,:)
166 allocate(r_v(n_r_in))
167 r_v = [((kd-1._dp)/(n_r_in-1),kd=1,n_r_in)]
191 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
192 &jac_c_h(id,2:n_r_in,0),r_v,
jac_v_c(id,:,kd),&
196 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
197 &jac_s_h(id,2:n_r_in,0),r_v,
jac_v_s(id,:,kd),&
228 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
229 &l_s_h(id,2:n_r_in,0),r_v,
l_v_s(id,:,kd),&
233 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
234 &l_c_h(id,2:n_r_in,0),r_v,
l_v_c(id,:,kd),&
250 allocate(b_v_sub_c_m(mnmax_v,n_r_in,3)); b_v_sub_c_m = 0._dp
251 allocate(b_v_sub_s_m(mnmax_v,n_r_in,3)); b_v_sub_s_m = 0._dp
253 allocate(b_v_c_h(mnmax_v,n_r_in)); b_v_c_h = 0._dp
254 allocate(b_v_s_h(mnmax_v,n_r_in)); b_v_s_h = 0._dp
258 b_v_sub_s_m(:,:,1) = bsubsmns(1:mnmax_v,:)
259 b_v_sub_c_m(:,:,2) = bsubumnc(1:mnmax_v,:)
260 b_v_sub_c_m(:,:,3) = bsubvmnc(1:mnmax_v,:)
262 b_v_sub_c_m(:,:,1) = bsubsmnc(1:mnmax_v,:)
263 b_v_sub_s_m(:,:,2) = bsubumns(1:mnmax_v,:)
264 b_v_sub_s_m(:,:,3) = bsubvmns(1:mnmax_v,:)
266 b_v_sub_c_m(:,:,1) = 0._dp
267 b_v_sub_s_m(:,:,2) = 0._dp
268 b_v_sub_s_m(:,:,3) = 0._dp
271 b_v_c_h(:,:) = bmnc(1:mnmax_v,:)
273 b_v_s_h(:,:) = bmns(1:mnmax_v,:)
283 allocate(
b_v_c(mnmax_v,n_r_in))
284 allocate(
b_v_s(mnmax_v,n_r_in))
291 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
292 &b_v_sub_c_m(id,2:n_r_in,kd),r_v,
b_v_sub_c(id,:,kd),&
295 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
296 &b_v_sub_s_m(id,2:n_r_in,kd),r_v,
b_v_sub_s(id,:,kd),&
303 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
304 &b_v_c_h(id,2:n_r_in),r_v,
b_v_c(id,:),&
307 ierr =
spline(-0.5_dp/n_r_in+r_v(2:n_r_in),&
308 &b_v_s_h(id,2:n_r_in),r_v,
b_v_s(id,:),&
317 call read_wout_deallocate()
320 call writo(
'Conversion complete')