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')
Integrates a function using the trapezoidal rule.
Wrapper to the pspline library, making it easier to use for 1-D applications where speed is not the m...
Variables that have to do with equilibrium quantities and the grid used in the calculations:
real(dp), public r_0
independent normalization constant for nondimensionalization
real(dp), public psi_0
derived normalization constant for nondimensionalization
real(dp), public pres_0
independent normalization constant for nondimensionalization
real(dp), public b_0
derived normalization constant for nondimensionalization
Numerical utilities related to giving output.
subroutine, public lvl_ud(inc)
Increases/decreases lvl of output.
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Numerical variables used by most other modules.
integer, parameter, public dp
double precision
real(dp), parameter, public pi
character(len=max_str_ln), public eq_name
name of equilibrium file from VMEC or HELENA
integer, parameter, public max_str_ln
maximum length of strings
integer, parameter, public max_deriv
highest derivatives for metric factors in Flux coords.
integer, public norm_disc_prec_eq
precision for normal discretization for equilibrium
Operations concerning giving output, on the screen as well as in output files.
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
elemental character(len=max_str_ln) function, public r2str(k)
Convert a real (double) to string.
Operations that concern the output of VMEC.
integer function, public read_vmec(n_r_in, use_pol_flux_v)
Reads the VMEC equilibrium data.
subroutine, public normalize_vmec
Normalizes VMEC input.
Variables that concern the output of VMEC.
real(dp), dimension(:,:), allocatable, public q_saf_v
safety factor
real(dp), dimension(:,:,:), allocatable, public jac_v_c
Coeff. of in sine series (HM and FM) and norm. deriv.
real(dp), dimension(:,:,:), allocatable, public b_v_sub_c
Coeff. of B_i in sine series (r,theta,phi) (FM).
integer, dimension(:,:), allocatable, public mn_v
m and n of modes
real(dp), dimension(:,:,:), allocatable, public l_v_s
Coeff. of in cosine series (HM) and norm. deriv.
real(dp), dimension(:,:,:), allocatable, public z_v_c
Coeff. of in sine series (FM) and norm. deriv.
real(dp), dimension(:,:), allocatable, public rot_t_v
rotational transform
real(dp), public b_0_v
the magnitude of B at the magnetic axis,
real(dp), dimension(:,:,:), allocatable, public jac_v_s
Coeff. of in cosine series (HM and FM) and norm. deriv.
real(dp), dimension(:,:,:), allocatable, public r_v_c
Coeff. of in sine series (FM) and norm. deriv.
real(dp), dimension(:,:), allocatable, public pres_v
pressure
real(dp), dimension(:,:), allocatable, public j_v_sup_int
Integrated poloidal and toroidal current (FM).
real(dp), dimension(:,:,:), allocatable, public b_v_sub_s
Coeff. of B_i in cosine series (r,theta,phi) (FM).
real(dp), dimension(:,:), allocatable, public b_v_s
Coeff. of magnitude of B in cosine series (HM and FM).
real(dp), dimension(:,:), allocatable, public flux_t_v
toroidal flux
real(dp), dimension(:,:,:), allocatable, public z_v_s
Coeff. of in cosine series (FM) and norm. deriv.
real(dp), dimension(:,:,:), allocatable, public r_v_s
Coeff. of in cosine series (FM) and norm. deriv.
real(dp), dimension(:,:,:), allocatable, public l_v_c
Coeff. of in sine series (HM) and norm. deriv.
real(dp), dimension(:,:), allocatable, public b_v_c
Coeff. of magnitude of B in sine series (HM and FM).
real(dp), dimension(:,:), allocatable, public flux_p_v
poloidal flux