13 USE utilities,
ONLY: gradientfull, to_full_mesh
15 USE descriptor_mod,
ONLY: iam
18 USE stel_constants,
ONLY: mu0
36 CHARACTER (LEN=*),
DIMENSION(1),
PARAMETER ::
39 CHARACTER (LEN=*),
DIMENSION(3),
PARAMETER ::
43 CHARACTER (len=*),
PARAMETER ::
vn_nsin =
'nrad'
49 CHARACTER (len=*),
PARAMETER ::
vn_nfpin =
'nfp'
51 CHARACTER (len=*),
PARAMETER ::
vn_wout =
'wout_file'
53 CHARACTER (len=*),
PARAMETER ::
vn_flags =
'state_flags'
56 CHARACTER (len=*),
PARAMETER ::
vn_jbsupss =
'JBsupssh(m,n,r)'
58 CHARACTER (len=*),
PARAMETER ::
vn_jbsupuc =
'JBsupuch(m,n,r)'
60 CHARACTER (len=*),
PARAMETER ::
vn_jbsupvc =
'JBsupvch(m,n,r)'
62 CHARACTER (len=*),
PARAMETER ::
vn_jbsupsc =
'JBsupsch(m,n,r)'
64 CHARACTER (len=*),
PARAMETER ::
vn_jbsupus =
'JBsupush(m,n,r)'
66 CHARACTER (len=*),
PARAMETER ::
vn_jbsupvs =
'JBsupvsh(m,n,r)'
68 CHARACTER (len=*),
PARAMETER ::
vn_jpresc =
'jpresch(m,n,r)'
70 CHARACTER (len=*),
PARAMETER ::
vn_jpress =
'jpressh(m,n,r)'
73 CHARACTER (len=*),
PARAMETER ::
vn_rmnc =
'rmnc(m,n,r)'
75 CHARACTER (len=*),
PARAMETER ::
vn_rmns =
'rmns(m,n,r)'
77 CHARACTER (len=*),
PARAMETER ::
vn_zmnc =
'zmnc(m,n,r)'
79 CHARACTER (len=*),
PARAMETER ::
vn_zmns =
'zmns(m,n,r)'
82 CHARACTER (len=*),
PARAMETER ::
vn_chipf =
'chipf(r)'
84 CHARACTER (len=*),
PARAMETER ::
vn_phipf =
'phipf(r)'
87 CHARACTER (len=*),
PARAMETER ::
vn_bsupsmns =
'bsupsmnsh(m,n,r)'
89 CHARACTER (len=*),
PARAMETER ::
vn_bsupsmnc =
'bsupsmnch(m,n,r)'
91 CHARACTER (len=*),
PARAMETER ::
vn_bsupumns =
'bsupumnsh(m,n,r)'
93 CHARACTER (len=*),
PARAMETER ::
vn_bsupumnc =
'bsupumnch(m,n,r)'
95 CHARACTER (len=*),
PARAMETER ::
vn_bsupvmns =
'bsupvmnsh(m,n,r)'
97 CHARACTER (len=*),
PARAMETER ::
vn_bsupvmnc =
'bsupvmnch(m,n,r)'
99 CHARACTER (len=*),
PARAMETER ::
vn_bsubsmns =
'bsubsmnsh(m,n,r)'
111 CHARACTER (len=*),
PARAMETER ::
vn_pmns =
'pmnsh(m,n,r)'
113 CHARACTER (len=*),
PARAMETER ::
vn_pmnc =
'pmnch(m,n,r)'
132 CHARACTER (len=*),
PARAMETER ::
vn_wb =
'wb'
134 CHARACTER (len=*),
PARAMETER ::
vn_wp =
'wp'
163 FUNCTION restart_read(restart_ext, wout_file, mpolin, ntorin, nfpin, &
165 USE quantities,
ONLY: jbsupsmnsh, jbsupsmnch, &
166 jbsupumnsh, jbsupumnch, &
167 jbsupvmnsh, jbsupvmnch, &
169 b_factor, p_factor, alloc_quantities
172 & gnorm => gnorm_i, rmajor =>
rmajor_i, &
174 USE vmec_info,
ONLY: rmnc => rmnc_i, zmns => zmns_i, &
175 & rmns => rmns_i, zmnc => zmnc_i, &
176 & vmec_info_construct_island
184 CHARACTER (len=*),
INTENT(in) :: restart_ext
185 CHARACTER (len=*),
INTENT(inout) :: wout_file
186 INTEGER,
INTENT(in) :: mpolin
187 INTEGER,
INTENT(in) :: ntorin
188 INTEGER,
INTENT(in) :: nsin
189 INTEGER,
INTENT(in) :: nfpin
198 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: tempmn_r
199 REAL (dp),
DIMENSION(:),
ALLOCATABLE :: temp_r
202 CHARACTER (LEN=256) :: filename
208 CALL alloc_quantities
210 filename =
'siesta_' // trim(restart_ext) //
'.nc'
211 CALL cdf_open(ncid, trim(filename),
'r', status)
212 CALL assert_eq(0, status,
'Failed to read restart file: ' //
215 CALL cdf_read(ncid,
vn_flags, flags)
219 CALL cdf_read(ncid,
vn_nsin, ns)
224 IF (nfpin .lt. 1)
THEN
230 nmin = min(ntor, ntorin)
232 CALL cdf_read(ncid,
vn_wout, wout_file)
235 ALLOCATE(tempmn_r(0:mpol,-ntor:ntor,ns))
237 CALL vmec_info_construct_island(mpolin, ntorin, nsin,
lasym)
239 ALLOCATE(chipf(nsin))
240 CALL cdf_read(ncid,
vn_chipf, temp_r)
241 CALL interpit_1d(temp_r, chipf, ns, nsin, .false., 1)
243 ALLOCATE(phipf(nsin))
244 CALL cdf_read(ncid,
vn_phipf, temp_r)
245 CALL interpit_1d(temp_r, phipf, ns, nsin, .false., 1)
248 jbsupsmnsh(:,:,1) = 0
249 CALL interpit(tempmn_r, jbsupsmnsh, ns, nsin, mpol, mpolin,
250 & ntor, ntorin, nfp, nfpin, .true.)
251 jbsupsmnsh(
m1,-nmin:nmin,1) = jbsupsmnsh(
m1,-nmin:nmin,2)
254 jbsupumnch(:,:,1) = 0
255 CALL interpit(tempmn_r, jbsupumnch, ns, nsin, mpol, mpolin,
256 & ntor, ntorin, nfp, nfpin, .true.)
257 jbsupumnch(
m1,-nmin:nmin,1) = jbsupumnch(
m1,-nmin:nmin,2)
260 jbsupvmnch(:,:,1) = 0
261 CALL interpit(tempmn_r, jbsupvmnch, ns, nsin, mpol, mpolin,
262 & ntor, ntorin, nfp, nfpin, .true.)
263 jbsupvmnch(
m0,-nmin:nmin,1) = jbsupvmnch(
m0,-nmin:nmin,2)
267 CALL interpit(tempmn_r, jpmnch, ns, nsin, mpol, mpolin,
268 & ntor, ntorin, nfp, nfpin, .true.)
269 jpmnch(
m0,-nmin:nmin,1) = jpmnch(
m0,-nmin:nmin,2)
271 CALL cdf_read(ncid,
vn_rmnc, tempmn_r)
272 CALL interpit(tempmn_r, rmnc, ns, nsin, mpol, mpolin,
273 ntor, ntorin, nfp, nfpin, .false.)
275 CALL cdf_read(ncid,
vn_zmns, tempmn_r)
276 CALL interpit(tempmn_r, zmns, ns, nsin, mpol, mpolin,
277 ntor, ntorin, nfp, nfpin, .false.)
280 jbsupsmnch(:,:,1) = 0
282 CALL interpit(tempmn_r, jbsupsmnch, ns, nsin, mpol, mpolin,
283 & ntor, ntorin, nfp, nfpin, .true.)
284 jbsupsmnch(
m1,-nmin:nmin,1) = jbsupsmnch(
m1,-nmin:nmin,2)
287 CALL interpit(tempmn_r, jbsupumnsh, ns, nsin, mpol, mpolin,
288 & ntor, ntorin, nfp, nfpin, .true.)
289 jbsupumnsh(
m1,-nmin:nmin,1) = jbsupumnsh(
m1,-nmin:nmin,2)
292 CALL interpit(tempmn_r, jbsupvmnsh, ns, nsin, mpol, mpolin,
293 & ntor, ntorin, nfp, nfpin, .true.)
294 jbsupvmnsh(
m0,-nmin:nmin,1) = jbsupvmnsh(
m0,-nmin:nmin,2)
297 CALL interpit(tempmn_r, jpmnsh, ns, nsin, mpol, mpolin,
298 & ntor, ntorin, nfp, nfpin, .true.)
299 jpmnsh(
m0,-nmin:nmin,1) = jpmnsh(
m0,-nmin:nmin,2)
301 CALL cdf_read(ncid,
vn_rmns, tempmn_r)
302 CALL interpit(tempmn_r, rmns, ns, nsin, mpol, mpolin,
303 ntor, ntorin, nfp, nfpin, .false.)
305 CALL cdf_read(ncid,
vn_zmns, tempmn_r)
306 CALL interpit(tempmn_r, zmnc, ns, nsin, mpol, mpolin,
307 ntor, ntorin, nfp, nfpin, .false.)
319 CALL cdf_read(ncid,
vn_wb, wb)
320 CALL cdf_read(ncid,
vn_wp, wp)
342 p_factor = 1.0/abs(wb)
343 b_factor = sqrt(p_factor)
344 gnorm = abs(wb)/(wb + wp/(
gamma - 1.0))
346 WRITE (
unit_out, 1000) mpol, ntor, ns
350 1000
FORMAT(/,
' RESTARTED FROM RUN PARAMETERS M: ',i3,
' N: ',i3,
' NS: '
364 jbsupumnsh, jbsupumnch, &
365 jbsupvmnsh, jbsupvmnch, &
367 b_factor, p_factor, jacobh
372 mpol=>mpol_i, ntor=>ntor_i, ns=>ns_i, &
373 ntheta=>nu_i, nzeta=>nv_i
375 USE utilities,
ONLY: curl_htof
376 USE stel_constants,
ONLY: one
381 CHARACTER (len=*),
INTENT(in) :: restart_ext
382 CHARACTER (len=*),
INTENT(in) :: wout_file
394 REAL (dp) :: tempscalar
395 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsupsijh
396 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsupuijh
397 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsupvijh
398 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubsijh
399 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubuijh
400 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubvijh
401 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubsmnh
402 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubumnh
403 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubvmnh
404 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: jksupsmnf
405 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: jksupumnf
406 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: jksupvmnf
407 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: tempmn_w
408 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: pijh
411 CALL cdf_open(ncid,
'siesta_' // trim(restart_ext) //
'.nc',
'w', status
412 CALL assert_eq(0, status,
'Failed to write restart file.')
422 ALLOCATE(tempmn_w(0:mpol,-ntor:ntor,ns))
424 CALL cdf_define(ncid,
vn_flags, flags)
425 CALL cdf_define(ncid,
vn_nsin, ns)
428 CALL cdf_define(ncid,
vn_nfpin, nfp)
429 CALL cdf_define(ncid,
vn_wout, wout_file)
442 CALL cdf_define(ncid,
vn_wb, wb)
443 CALL cdf_define(ncid,
vn_wp, wp)
455 recon0:
IF (lrecon)
THEN
471 CALL cdf_define(ncid,
vn_p_max, b_factor)
472 CALL cdf_define(ncid,
vn_p_min, p_factor)
473 CALL cdf_define(ncid,
vn_curtor, tempscalar)
491 CALL cdf_write(ncid,
vn_flags, flags)
492 CALL cdf_write(ncid,
vn_nsin, ns)
496 CALL cdf_write(ncid,
vn_wout, wout_file)
503 CALL cdf_write(ncid,
vn_chipf, chipf)
504 CALL cdf_write(ncid,
vn_phipf, phipf)
508 CALL cdf_write(ncid,
vn_rmnc, tempmn_w)
511 CALL cdf_write(ncid,
vn_zmns, tempmn_w)
521 CALL cdf_write(ncid,
vn_rmns, tempmn_w)
524 CALL cdf_write(ncid,
vn_zmnc, tempmn_w)
527 CALL cdf_write(ncid,
vn_wb, wb)
528 CALL cdf_write(ncid,
vn_wp, wp)
531 recon1:
IF (lrecon)
THEN
532 ALLOCATE(bsupsijh(ntheta,nzeta,ns))
533 ALLOCATE(bsupuijh(ntheta,nzeta,ns))
534 ALLOCATE(bsupvijh(ntheta,nzeta,ns))
535 ALLOCATE(pijh(ntheta,nzeta,ns))
563 bsupsijh = bsupsijh/jacobh
564 bsupuijh = bsupuijh/jacobh
565 bsupvijh = bsupvijh/jacobh
568 tempscalar = maxval(pijh(:,:,2:))
569 CALL cdf_write(ncid,
vn_p_max, tempscalar)
570 tempscalar = minval(pijh(:,:,2:))
571 CALL cdf_write(ncid,
vn_p_min, tempscalar)
591 CALL cdf_write(ncid,
vn_pmnc, tempmn_w)
593 ALLOCATE(bsubsijh(ntheta,nzeta,ns))
594 ALLOCATE(bsubuijh(ntheta,nzeta,ns))
595 ALLOCATE(bsubvijh(ntheta,nzeta,ns))
597 CALL tolowerh(bsupsijh, bsupuijh, bsupvijh,
598 bsubsijh, bsubuijh, bsubvijh, 1, ns)
601 ALLOCATE(bsubsmnh(0:mpol,-ntor:ntor,ns))
602 ALLOCATE(bsubumnh(0:mpol,-ntor:ntor,ns))
603 ALLOCATE(bsubvmnh(0:mpol,-ntor:ntor,ns))
619 ALLOCATE(jksupsmnf(0:mpol,-ntor:ntor,ns))
620 ALLOCATE(jksupumnf(0:mpol,-ntor:ntor,ns))
621 ALLOCATE(jksupvmnf(0:mpol,-ntor:ntor,ns))
623 CALL curl_htof(bsubsmnh, bsubumnh, bsubvmnh,
624 & jksupsmnf, jksupumnf, jksupvmnf,
625 &
f_sin, 1, ns, .false., tempscalar)
635 CALL cdf_write(ncid,
vn_curtor, tempscalar)
654 CALL cdf_write(ncid,
vn_pmns, tempmn_w)
669 CALL curl_htof(bsubsmnh, bsubumnh, bsubvmnh,
670 & jksupsmnf, jksupumnf, jksupvmnf,
671 &
f_cos, 1, ns, .false., tempscalar)
691 DEALLOCATE(jksupsmnf)
692 DEALLOCATE(jksupumnf)
693 DEALLOCATE(jksupvmnf)
721 & mpol_old, mpol_new, &
722 & ntor_old, ntor_new, &
723 & nfp_old, nfp_new, lhalf)
724 USE stel_constants,
ONLY: one, zero
729 REAL (dp),
INTENT(in) :: aold(0:mpol_old,-ntor_old:ntor_old,ns_old)
730 REAL (dp),
INTENT(out) :: anew(0:mpol_new,-ntor_new:ntor_new,ns_new)
731 INTEGER,
INTENT(in) :: ns_old
732 INTEGER,
INTENT(in) :: ns_new
733 INTEGER,
INTENT(in) :: mpol_old
734 INTEGER,
INTENT(in) :: mpol_new
735 INTEGER,
INTENT(in) :: ntor_old
736 INTEGER,
INTENT(in) :: ntor_new
737 INTEGER,
INTENT(in) :: nfp_old
738 INTEGER,
INTENT(in) :: nfp_new
739 LOGICAL,
INTENT(in) :: lhalf
742 INTEGER :: real_ntor_min
751 mpol_min = min(mpol_new, mpol_old)
752 real_ntor_min = min(ntor_new*nfp_new, ntor_old*nfp_old)
756 IF (ns_old .eq. ns_new .and.
757 mpol_old .eq. mpol_new .and.
758 ntor_old .eq. ntor_new .and.
759 nfp_old .eq. nfp_new)
THEN
764 DO i_n = -real_ntor_min, real_ntor_min
765 IF (i_n/nfp_new .eq. i_n/nfp_old)
THEN
767 IF (mod(i_m, 2) .EQ. 0)
THEN
773 CALL interpit_1d(aold(i_m, i_n, :), anew(i_m, i_n, :),
774 ns_old, ns_new, lhalf, parity)
794 SUBROUTINE interpit_1d(aold, anew, ns_old, ns_new, lhalf, parity)
795 USE stel_constants,
ONLY: one, zero
800 REAL (dp),
INTENT(in) :: aold(ns_old)
801 REAL (dp),
INTENT(out) :: anew(ns_new)
802 INTEGER,
INTENT(in) :: ns_old
803 INTEGER,
INTENT(in) :: ns_new
804 LOGICAL,
INTENT(in) :: lhalf
805 INTEGER,
INTENT(in) :: parity
808 REAL (dp),
ALLOCATABLE,
DIMENSION(:) :: temp_y
809 REAL (dp),
ALLOCATABLE,
DIMENSION(:) :: temp_x
810 REAL (dp),
ALLOCATABLE,
DIMENSION(:) :: temp_new
811 REAL (dp),
ALLOCATABLE,
DIMENSION(:) :: temp
816 REAL (dp),
PARAMETER :: lower_b = -1.e30_dp
817 REAL (dp),
PARAMETER :: upper_b = -1.e30_dp
821 IF (ns_old .EQ. ns_new)
THEN
828 ds = 1.0/(ns_old - 1)
830 ALLOCATE(temp_y(2*(ns_old - 1)))
831 ALLOCATE(temp_x(2*(ns_old - 1)))
832 ALLOCATE(temp(2*(ns_old - 1)))
835 temp_x(ns_old - i_s + 1) = -ds*(i_s - 1.5)
836 temp_y(ns_old + i_s - 2) = ds*(i_s - 1.5)
837 temp_y(ns_old - i_s + 1) = parity*aold(i_s)
838 temp_y(ns_old + i_s - 2) = aold(i_s)
841 ALLOCATE(temp_y(2*ns_old - 1))
842 ALLOCATE(temp_x(2*ns_old - 1))
843 ALLOCATE(temp(2*ns_old - 1))
846 temp_x(ns_old - i_s + 1) = -ds*(i_s - 1)
847 temp_x(ns_old + i_s - 1) = ds*(i_s - 1)
848 temp_y(ns_old - i_s + 1) = parity*aold(i_s)
849 temp_y(ns_old + i_s - 1) = aold(i_s)
853 CALL spline(temp_x, temp_y,
SIZE(temp_x), lower_b, upper_b, temp)
855 ALLOCATE(temp_new(ns_new))
856 ds = 1.0/(ns_new - 1)
859 temp_new(i_s) = ds*(i_s - 1.5)
863 temp_new(i_s) = ds*(i_s - 1)
867 CALL splint(temp_x, temp_y, temp,
SIZE(temp_x), temp_new, anew)
890 REAL (dp),
DIMENSION(:,:,:) :: xmn
897 DO s = 1,
SIZE(xmn,3)