This subroutine reads a generic NetCDF equilibrium file containing the axisymmetric magnetic field geometry in flux coordinates
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(peq_type), | intent(inout) | :: | self | |||
type(geo_input_type), | intent(in) | :: | inputs |
subroutine read_and_set_peq(self, inputs)
implicit none
class(peq_type), intent(in out) :: self
type(geo_input_type), intent(in) :: inputs
# ifdef NETCDF
integer :: istatus, ncid, id, i, j, i_sym, nz1, nz2
real, allocatable, dimension(:) :: work
self%filename = trim(adjustl(inputs%eqfile))
istatus = nf90_open(self%filename, NF90_NOWRITE, ncid)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, file = self%filename)
! netcdf read scalar: nr
!
! nz2 == number of points in radial array
! nr == number of actual grid points in radial array
istatus = nf90_inq_dimid (ncid, 'z2', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, dim='z2')
istatus = nf90_inquire_dimension (ncid, id, len=nz2)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, dimid=id)
istatus = nf90_inq_dimid (ncid, 'z1', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, dim='z1')
istatus = nf90_inquire_dimension (ncid, id, len=nz1)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, dimid=id)
istatus = nf90_inq_dimid (ncid, 'npsi', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, dim='npsi')
istatus = nf90_inquire_dimension (ncid, id, len = self%nr)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, dimid=id)
istatus = nf90_inq_varid (ncid, 'nxy', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, var='nxy')
istatus = nf90_get_var (ncid, id, i_sym, start=[8])
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, id)
if (i_sym == 0) write(*,*) 'Up-down asymmetries not yet handled correctly.'
! netcdf read scalar: nt
!
! nt == number of theta grid points in theta eq grid
istatus = nf90_inq_dimid (ncid, 'nthe', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, dim='nthe')
istatus = nf90_inquire_dimension (ncid, id, len = self%nt)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, dimid=id)
call self%alloc_arrays()
! netcdf read vectors: rho_d, eqpsi, psi_bar, fp, beta, pressure
!
! rho_d(1:nr) == half diameters of flux surfaces at elevation
! of Z_mag on the radial grid
! psi is the poloidal flux
! eqpsi(1:nr) == values of psi on the radial grid
! psi_bar(1:nr) == values of psi_bar on the radial grid
! [psi_bar == (eqpsi - psi_0)/(psi_a - psi_0) if not available]
! fp(1:nr) == the function that satisfies
! B = fp grad zeta + grad zeta x grad psi
! beta(1:nr) == local beta, with the magnetic field defined
! to be vacuum magnetic field on axis
! pressure(1:nr) == pressure profile on the radial grid,
! normalized to the value at the magnetic axis.
istatus = nf90_inq_varid (ncid, 'psivec', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, var='psivec')
istatus = nf90_get_var (ncid, id, self%eqpsi, count = [self%nr])
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, id)
istatus = nf90_inq_varid (ncid, 'fvec', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, var='fvec')
istatus = nf90_get_var (ncid, id, self%fp, count = [self%nr])
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, id)
istatus = nf90_inq_varid (ncid, 'pvec', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, var='pvec')
istatus = nf90_get_var (ncid, id, self%eqpsi, count = [self%nr])
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, id)
! netcdf read 2d field: R_psi,Z_psi and B_psi (mod(B))
! R_psi(1:nr, 1:nt) -- transpose of Menard's storage ...
! Z_psi(1:nr, 1:nt)
! B_psi(1:nr, 1:nt)
allocate(work(nz1*nz2))
istatus = nf90_inq_varid (ncid, 'x', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, var='x')
istatus = nf90_get_var (ncid, id, work, count = [nz1*nz2])
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, id)
do j = 1, self%nt
do i = 1, self%nr
self%R_psi(i,j) = work(3+j-1+nz1*(i-1))
end do
end do
istatus = nf90_inq_varid (ncid, 'z', id)
if (istatus /= NF90_NOERR) call netcdf_error (istatus, var='z')
istatus = nf90_get_var (ncid, id, work, count=[nz1, nz2]) !Should this be nz1*nz2?
if (istatus /= NF90_NOERR) call netcdf_error (istatus, ncid, id)
do j = 1, self%nt
do i = 1, self%nr
self%Z_psi(i,j) = work(3+j-1+nz1*(i-1))
end do
end do
istatus = nf90_close(ncid)
if (istatus /= NF90_NOERR) call netcdf_error (istatus)
deallocate(work)
self%has_full_theta_range = .false.
call self%shared_setup(self%nt, 1)
# else
UNUSED_DUMMY(self) ; UNUSED_DUMMY(inputs)
call mp_abort('error: peq eqin is called without netcdf',.true.)
# endif
end subroutine read_and_set_peq