340 REAL (rprec) :: du_full
342 REAL (rprec) :: dv_full
345 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: rsuv => null()
347 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: zsuv => null()
350 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: jrsuv => null()
352 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: jphisuv => null()
354 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: jzsuv => null()
358 REAL (rprec),
DIMENSION(:,:),
POINTER :: kruv => null()
361 REAL (rprec),
DIMENSION(:,:),
POINTER :: kphiuv => null()
364 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv => null()
367 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: x_prime => null()
370 REAL (rprec),
DIMENSION(:,:),
POINTER :: kxuv_full => null()
373 REAL (rprec),
DIMENSION(:,:),
POINTER :: kyuv_full => null()
376 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv_full => null()
379 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: x_axi => null()
382 REAL (rprec),
DIMENSION(:,:),
POINTER :: kxuv_axi => null()
385 REAL (rprec),
DIMENSION(:,:),
POINTER :: kyuv_axi => null()
388 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv_axi => null()
398 CHARACTER (len=path_length) :: wout_file_name
400 CHARACTER (len=path_length) :: vmec_file_name
418 REAL (rprec) :: pol_rad_ratio
429 REAL (rprec) :: phi_offset = 0
431 REAL (rprec) :: z_offset = 0
470 SUBROUTINE runvmec(control_array, vmec_input_file, &
471 & use_screen, comm, reset_file_name)
472 INTEGER,
INTENT(inout),
TARGET :: control_array(5)
473 LOGICAL,
INTENT(in) :: use_screen
474 CHARACTER(LEN=*),
INTENT(in) :: vmec_input_file
475 INTEGER,
INTENT(in) :: comm
476 CHARACTER(LEN=*),
OPTIONAL :: reset_file_name
586 & eq_comm, recon_comm, state_flags)
587 USE vmec_params,
only: restart_flag, readin_flag, timestep_flag, &
588 & successful_term_flag, norm_term_flag, &
590 USE vmec_input,
only: l_v3fit, ns_array, mgrid_file, lfreeb
591 USE read_wout_mod,
only: read_wout_file, loadrzl
599 CHARACTER (len=*),
INTENT(in) :: file_name
600 CHARACTER (len=*),
INTENT(in) :: wout_file_name
601 INTEGER,
INTENT(in) :: iou
602 INTEGER,
INTENT(in) :: eq_comm
603 INTEGER,
INTENT(in) :: recon_comm
604 INTEGER,
INTENT(inout) :: state_flags
609 INTEGER :: recon_rank
610 INTEGER :: recon_size
611 INTEGER,
DIMENSION(5) :: ictrl_array
612 INTEGER :: index_dat, index_end
614 REAL (rprec) :: start_time
615 CHARACTER (len=path_length) :: mgrid_path
618 start_time = profiler_get_start_time()
626 CALL mpi_comm_rank(eq_comm, eq_rank, error)
628 IF (eq_rank .eq. 0)
THEN
629 CALL mpi_comm_rank(recon_comm, recon_rank, error)
630 CALL mpi_comm_size(recon_comm, recon_size, error)
632 CALL mpi_bcast(recon_rank, 1, mpi_integer, 0, eq_comm, error)
635 IF (eq_rank .eq. 0)
THEN
636 WRITE (*,*)
' *** Initializing VMEC equilibrium from file ' //
638 WRITE (iou,*)
' *** Initializing VMEC equilibrium from ' //
639 &
'file ' // trim(file_name)
646 ictrl_array(1) = ior(ictrl_array(1), restart_flag)
647 ictrl_array(1) = ior(ictrl_array(1), readin_flag)
648 ictrl_array(1) = ior(ictrl_array(1), timestep_flag)
660 IF (recon_rank .eq. 0)
THEN
661 IF (wout_file_name .ne.
'')
THEN
667 CALL runvmec(ictrl_array, file_name, .false., eq_comm,
670 IF (eq_rank .eq. 0)
THEN
673 CALL assert_eq(error, 0,
'Error loading initialized ' //
679 CALL runvmec(ictrl_array, file_name, .false., eq_comm)
687 IF (trim(mgrid_path) .ne.
'')
THEN
689 & mgrid_file), error)
693 & mgrid_file) // mgrid_file,
699 IF (eq_rank .eq. 0)
THEN
701 & 0, recon_comm, error)
704 IF (eq_rank .eq. 0)
THEN
706 & 0, recon_comm, error)
712 IF (wout_file_name .ne.
'')
THEN
716 CALL runvmec(ictrl_array, file_name, .false., eq_comm,
718 IF (eq_rank .eq. 0)
THEN
721 CALL assert_eq(error, 0,
'Error loading initialized ' //
726 CALL runvmec(ictrl_array, file_name, .false., eq_comm)
731 SELECT CASE (ictrl_array(2))
733 CASE (successful_term_flag, norm_term_flag, more_iter_flag)
735 index_dat = index(file_name,
'input.')
736 index_end = len_trim(file_name)
737 IF (index_dat .gt. 0)
THEN
739 & trim(file_name(index_dat + 6:index_end)) //
'.nc'
742 & trim(file_name(1:index_end)) //
'.nc'
746 CALL err_fatal(
'vmec_construct runvmec command failed ',
747 & int = ictrl_array(2))
753 CALL profiler_set_stop_time(
'vmec_construct_eq', start_time)
786 & ti, ze, sxrem, phi_offset, z_offset, &
787 & pol_rad_ratio, iou, eq_comm, &
788 & recon_comm, state_flags)
794 CHARACTER (len=*),
INTENT(in) :: file_name
795 CHARACTER (len=*),
INTENT(in) :: wout_file_name
801 REAL (rprec),
INTENT(in) :: phi_offset
802 REAL (rprec),
INTENT(in) :: z_offset
803 REAL (rprec),
INTENT(in) :: pol_rad_ratio
804 INTEGER,
INTENT(in) :: iou
805 INTEGER,
INTENT(in) :: eq_comm
806 INTEGER,
INTENT(in) :: recon_comm
807 INTEGER,
INTENT(inout) :: state_flags
810 REAL (rprec) :: start_time
813 start_time = profiler_get_start_time()
816 & iou, eq_comm, recon_comm,
830 CALL profiler_set_stop_time(
'vmec_construct_full', start_time)
845 USE read_wout_mod,
only: read_wout_deallocate
851 TYPE (vmec_class),
POINTER :: this
857 IF (
ASSOCIATED(this%ne))
THEN
862 IF (
ASSOCIATED(this%te))
THEN
867 IF (
ASSOCIATED(this%ti))
THEN
872 IF (
ASSOCIATED(this%ze))
THEN
877 IF (
ASSOCIATED(this%sxrem))
THEN
878 DO i = 1,
SIZE(this%sxrem)
879 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
881 this%sxrem(i)%p => null()
884 DEALLOCATE(this%sxrem)
888 IF (
ASSOCIATED(this%magnetic_cache))
THEN
889 IF (
ASSOCIATED(this%magnetic_cache%rsuv))
THEN
890 DEALLOCATE(this%magnetic_cache%rsuv)
891 this%magnetic_cache%rsuv => null()
894 IF (
ASSOCIATED(this%magnetic_cache%zsuv))
THEN
895 DEALLOCATE(this%magnetic_cache%zsuv)
896 this%magnetic_cache%zsuv => null()
899 IF (
ASSOCIATED(this%magnetic_cache%jrsuv))
THEN
900 DEALLOCATE(this%magnetic_cache%jrsuv)
901 this%magnetic_cache%jrsuv => null()
904 IF (
ASSOCIATED(this%magnetic_cache%jphisuv))
THEN
905 DEALLOCATE(this%magnetic_cache%jphisuv)
906 this%magnetic_cache%jphisuv => null()
909 IF (
ASSOCIATED(this%magnetic_cache%jzsuv))
THEN
910 DEALLOCATE(this%magnetic_cache%jzsuv)
911 this%magnetic_cache%jzsuv => null()
914 IF (
ASSOCIATED(this%magnetic_cache%kruv))
THEN
915 DEALLOCATE(this%magnetic_cache%kruv)
916 this%magnetic_cache%kruv => null()
919 IF (
ASSOCIATED(this%magnetic_cache%kphiuv))
THEN
920 DEALLOCATE(this%magnetic_cache%kphiuv)
921 this%magnetic_cache%kphiuv => null()
924 IF (
ASSOCIATED(this%magnetic_cache%kzuv))
THEN
925 DEALLOCATE(this%magnetic_cache%kzuv)
926 this%magnetic_cache%kzuv => null()
929 IF (
ASSOCIATED(this%magnetic_cache%x_prime))
THEN
930 DEALLOCATE(this%magnetic_cache%x_prime)
931 this%magnetic_cache%x_prime => null()
934 IF (
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
935 DEALLOCATE(this%magnetic_cache%kxuv_full)
936 this%magnetic_cache%kxuv_full => null()
939 IF (
ASSOCIATED(this%magnetic_cache%kyuv_full))
THEN
940 DEALLOCATE(this%magnetic_cache%kyuv_full)
941 this%magnetic_cache%kyuv_full => null()
944 IF (
ASSOCIATED(this%magnetic_cache%kzuv_full))
THEN
945 DEALLOCATE(this%magnetic_cache%kzuv_full)
946 this%magnetic_cache%kzuv_full => null()
949 IF (
ASSOCIATED(this%magnetic_cache%x_axi))
THEN
950 DEALLOCATE(this%magnetic_cache%x_axi)
951 this%magnetic_cache%x_axi => null()
954 IF (
ASSOCIATED(this%magnetic_cache%kxuv_axi))
THEN
955 DEALLOCATE(this%magnetic_cache%kxuv_axi)
956 this%magnetic_cache%kxuv_axi => null()
959 IF (
ASSOCIATED(this%magnetic_cache%kyuv_axi))
THEN
960 DEALLOCATE(this%magnetic_cache%kyuv_axi)
961 this%magnetic_cache%kyuv_axi => null()
964 IF (
ASSOCIATED(this%magnetic_cache%kzuv_axi))
THEN
965 DEALLOCATE(this%magnetic_cache%kzuv_axi)
966 this%magnetic_cache%kzuv_axi => null()
969 DEALLOCATE(this%magnetic_cache)
970 this%magnetic_cache => null()
974 CALL delete_file(trim(this%wout_file_name) //
'_cache', error)
976 IF (
ASSOCIATED(this%vmec_context_save))
THEN
978 this%vmec_context_save => null()
982 CALL read_wout_deallocate
983 CALL free_mem_ns(.true.)
984 CALL free_mem_funct3d
1012 & eq_comm, state_flags)
1013 USE vmec_input,
only: rbc, zbs, rbs, zbc, &
1014 & ac, ac_aux_s, ac_aux_f, &
1015 & ai, ai_aux_s, ai_aux_f, &
1016 & am, am_aux_s, am_aux_f, &
1017 & extcur, curtor, phiedge, pres_scale, &
1018 & bloat, lfreeb, aphi
1019 USE xstuff,
only: xc, xcdot
1020 USE vmec_main,
only: irzloff, currv, ivac
1021 USE stel_constants,
only: mu0
1027 TYPE (vmec_class),
INTENT(inout) :: this
1028 INTEGER,
INTENT(in) :: id
1029 INTEGER,
INTENT(in) :: i_index
1030 INTEGER,
INTENT(in) :: j_index
1031 REAL (rprec),
INTENT(in) :: value
1032 INTEGER,
INTENT(in) :: eq_comm
1033 INTEGER,
INTENT(inout) :: state_flags
1036 REAL (rprec) :: phiedge_ratio
1038 REAL (rprec) :: start_time
1041 start_time = profiler_get_start_time()
1047 rbc(i_index, j_index) =
value
1048 IF (.not.lfreeb)
THEN
1050 CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1052 CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1057 zbs(i_index, j_index) =
value
1058 IF (.not.lfreeb)
THEN
1060 CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1062 CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1067 rbs(i_index, j_index) =
value
1068 IF (.not.lfreeb)
THEN
1070 CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1072 CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1077 zbc(i_index, j_index) =
value
1078 IF (.not.lfreeb)
THEN
1080 CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1082 CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1088 CALL profil1d(xc, xcdot, .false.)
1092 ac_aux_s(i_index) =
value
1093 CALL profil1d(xc, xcdot, .false.)
1097 ac_aux_f(i_index) =
value
1098 CALL profil1d(xc, xcdot, .false.)
1103 CALL profil1d(xc, xcdot, .false.)
1107 ai_aux_s(i_index) =
value
1108 CALL profil1d(xc, xcdot, .false.)
1112 ai_aux_f(i_index) =
value
1113 CALL profil1d(xc, xcdot, .false.)
1118 CALL profil1d(xc, xcdot, .false.)
1122 am_aux_s(i_index) =
value
1123 CALL profil1d(xc, xcdot, .false.)
1127 am_aux_f(i_index) =
value
1128 CALL profil1d(xc, xcdot, .false.)
1132 this%ne%b(i_index) =
value
1136 this%ne%as(i_index) =
value
1140 this%ne%af(i_index) =
value
1144 this%te%b(i_index) =
value
1148 this%te%as(i_index) =
value
1152 this%te%af(i_index) =
value
1156 this%ti%b(i_index) =
value
1160 this%ti%as(i_index) =
value
1164 this%ti%af(i_index) =
value
1168 this%ze%b(i_index) =
value
1172 this%ze%as(i_index) =
value
1176 this%ze%af(i_index) =
value
1183 this%sxrem(i_index)%p%b(j_index) =
value
1188 this%sxrem(i_index)%p%as(j_index) =
value
1193 this%sxrem(i_index)%p%af(j_index) =
value
1197 extcur(i_index) =
value
1198 #if defined(MPI_OPT)
1199 CALL mpi_bcast(mpi_mgrid_task, 1, mpi_integer, 0, eq_comm,
1201 CALL mpi_bcast(i_index, 1, mpi_integer, 0, eq_comm, error)
1209 CALL profil1d(xc, xcdot, .false.)
1213 IF (phiedge .ne. 0.0)
THEN
1214 phiedge_ratio =
value/phiedge
1219 IF (aphi(1) .eq. 1.0)
THEN
1220 xc(1 + 2*irzloff:3*irzloff) =
1221 & phiedge_ratio*xc(1 + 2*irzloff:3*irzloff)
1223 CALL profil1d(xc, xcdot, .false.)
1224 CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1229 CALL profil1d(xc, xcdot, .false.)
1234 CALL profil1d(xc, xcdot, .false.)
1235 CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1243 this%phi_offset =
value
1244 IF (
ASSOCIATED(this%magnetic_cache))
THEN
1250 this%z_offset =
value
1251 IF (
ASSOCIATED(this%magnetic_cache))
THEN
1258 state_flags = state_flags
1262 CALL profiler_set_stop_time(
'vmec_set_param', start_time)
1278 USE vmec_input,
only: ns_array, mpol
1279 USE stel_constants,
only: twopi
1285 TYPE (vmec_class),
INTENT(inout) :: this
1286 TYPE (magnetic_response_class),
INTENT(in) :: response_object
1291 REAL (rprec) :: start_time
1294 start_time = profiler_get_start_time()
1296 IF (.not.
ASSOCIATED(this%magnetic_cache))
THEN
1297 ALLOCATE(this%magnetic_cache)
1303 ns = ns_array(this%ns_index)
1304 numu = max(int(this%pol_rad_ratio*ns), 2*mpol)
1307 this%magnetic_cache%ds = 1.0/(ns - 1.0)
1308 this%magnetic_cache%du = twopi/numu
1309 this%magnetic_cache%dv = twopi/response_object%n_field_periods
1310 & / response_object%num_t
1314 ALLOCATE(this%magnetic_cache%rsuv(ns,numu,
1315 &
SIZE(response_object%a_r)))
1316 ALLOCATE(this%magnetic_cache%zsuv(ns,numu,
1317 &
SIZE(response_object%a_r)))
1318 ALLOCATE(this%magnetic_cache%jrsuv(ns,numu,
1319 &
SIZE(response_object%a_r)))
1320 ALLOCATE(this%magnetic_cache%jphisuv(ns,numu,
1321 &
SIZE(response_object%a_r)))
1322 ALLOCATE(this%magnetic_cache%jzsuv(ns,numu,
1323 &
SIZE(response_object%a_r)))
1329 this%magnetic_cache%du_a = twopi/compression_get_dimension1(
1330 & response_object%a_s_r)
1331 this%magnetic_cache%dv_a
1332 & = (twopi/response_object%n_field_periods)
1333 & / response_object%num_t_shell
1335 ALLOCATE(this%magnetic_cache%kruv(
1336 & compression_get_dimension1(response_object%a_s_r),
1337 & compression_get_dimension2(response_object%a_s_r)))
1338 ALLOCATE(this%magnetic_cache%kphiuv(
1339 & compression_get_dimension1(response_object%a_s_r),
1340 & compression_get_dimension2(response_object%a_s_r)))
1341 ALLOCATE(this%magnetic_cache%kzuv(
1342 & compression_get_dimension1(response_object%a_s_r),
1343 & compression_get_dimension2(response_object%a_s_r)))
1346 CALL profiler_set_stop_time(
'vmec_set_magnetic_cache_responce',
1362 USE vmec_input,
only: rbc, zbs
1367 TYPE (vmec_class),
INTENT(inout) :: this
1368 LOGICAL,
INTENT(in) :: use_axi
1371 INTEGER :: u_size, v_size
1372 REAL (rprec) :: start_time
1375 start_time = profiler_get_start_time()
1377 IF (.not.
ASSOCIATED(this%magnetic_cache))
THEN
1378 ALLOCATE(this%magnetic_cache)
1384 IF (mod(v_size, 2) .eq. 0)
THEN
1387 this%magnetic_cache%dv_full = twopi/v_size
1389 u_size = max(int(twopi*max(rbc(0,1), zbs(0,1))/
1392 IF (mod(u_size, 2) .eq. 0)
THEN
1395 this%magnetic_cache%du_full = twopi/u_size
1397 ALLOCATE(this%magnetic_cache%kxuv_full(u_size,v_size))
1398 ALLOCATE(this%magnetic_cache%kyuv_full(u_size,v_size))
1399 ALLOCATE(this%magnetic_cache%kzuv_full(u_size,v_size))
1401 ALLOCATE(this%magnetic_cache%x_prime(u_size,v_size,3))
1404 ALLOCATE(this%magnetic_cache%kxuv_axi(u_size,v_size))
1405 ALLOCATE(this%magnetic_cache%kyuv_axi(u_size,v_size))
1406 ALLOCATE(this%magnetic_cache%kzuv_axi(u_size,v_size))
1408 ALLOCATE(this%magnetic_cache%x_axi(u_size,v_size,3))
1412 CALL profiler_set_stop_time(
'vmec_set_magnetic_cache_point',
1426 USE read_wout_mod,
only: lasym, xm, xn, mnmax, xm_nyq, xn_nyq, &
1427 & mnmax_nyq, rmnc, zmns, rmns, zmnc, &
1428 & currumnc, currvmnc, currumns, currvmns, &
1429 & bsubumnc, bsubumns, bsubvmnc, bsubvmns, &
1430 & nfp, ns, lwout_opened, lfreeb
1431 USE stel_constants,
only: mu0
1436 TYPE (vmec_class),
INTENT(inout) :: this
1439 INTEGER :: s, u, v, i
1440 INTEGER :: numU, numV
1441 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosz, sinz
1442 REAL (rprec),
DIMENSION(:,:),
ALLOCATABLE :: cosu, sinu
1443 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosv, sinv
1444 REAL (rprec) :: cosphi, sinphi
1445 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosz_nyq, sinz_nyq
1446 REAL (rprec),
DIMENSION(:,:),
ALLOCATABLE :: cosu_nyq, sinu_nyq
1447 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosv_nyq, sinv_nyq
1448 REAL (rprec) :: ru, rv, zu, zv, r, z
1449 REAL (rprec) :: ju, jv, bu, bv
1450 REAL (rprec) :: kr, kphi
1451 REAL (rprec) :: theta, phi
1452 REAL (rprec) :: start_time
1453 REAl (rprec),
DIMENSION(:),
ALLOCATABLE :: bsubuc, bsubus
1454 REAl (rprec),
DIMENSION(:),
ALLOCATABLE :: bsubvc, bsubvs
1455 REAL (rprec) :: woddlow, woddhigh
1458 start_time = profiler_get_start_time()
1464 IF (.not.lwout_opened)
THEN
1465 CALL profiler_set_stop_time(
'vmec_set_magnetic_cache_calc',
1470 IF (
ASSOCIATED(this%magnetic_cache%rsuv))
THEN
1472 numu =
SIZE(this%magnetic_cache%rsuv, 2)
1473 numv =
SIZE(this%magnetic_cache%rsuv, 3)
1475 ALLOCATE(cosu(mnmax, numu), sinu(mnmax, numu))
1476 ALLOCATE(cosu_nyq(mnmax_nyq, numu), sinu_nyq(mnmax_nyq, numu))
1491 theta = (u - 1)*this%magnetic_cache%du
1492 cosu(:,u) = cos(xm*theta)
1493 sinu(:,u) = sin(xm*theta)
1494 cosu_nyq(:,u) = cos(xm_nyq*theta)
1495 sinu_nyq(:,u) = sin(xm_nyq*theta)
1501 ALLOCATE(cosv(mnmax), sinv(mnmax))
1502 ALLOCATE(cosz(mnmax), sinz(mnmax))
1503 ALLOCATE(cosv_nyq(mnmax_nyq), sinv_nyq(mnmax_nyq))
1504 ALLOCATE(cosz_nyq(mnmax_nyq))
1506 ALLOCATE(sinz_nyq(mnmax_nyq))
1524 phi = (v - 1)*this%magnetic_cache%dv + this%phi_offset
1528 cosv_nyq = cos(xn_nyq*phi)
1529 sinv_nyq = sin(xn_nyq*phi)
1533 cosz = cosu(:,u)*cosv + sinu(:,u)*sinv
1534 sinz = sinu(:,u)*cosv - cosu(:,u)*sinv
1536 cosz_nyq = cosu_nyq(:,u)*cosv_nyq
1537 & + sinu_nyq(:,u)*sinv_nyq
1541 this%magnetic_cache%rsuv(s,u,v) = sum(rmnc(:,s)*cosz)
1542 this%magnetic_cache%zsuv(s,u,v) = sum(zmns(:,s)*sinz)
1543 ru = -sum(xm*rmnc(:,s)*sinz)
1544 zu = sum(xm*zmns(:,s)*cosz)
1545 rv = sum(xn*rmnc(:,s)*sinz)
1546 zv = -sum(xn*zmns(:,s)*cosz)
1548 ju = sum(currumnc(:,s)*cosz_nyq)
1549 jv = sum(currvmnc(:,s)*cosz_nyq)
1552 sinz_nyq = sinu_nyq(:,u)*cosv_nyq
1553 & - cosu_nyq(:,u)*sinv_nyq
1555 this%magnetic_cache%rsuv(s,u,v) =
1556 & this%magnetic_cache%rsuv(s,u,v) +
1557 & sum(rmns(:,s)*sinz)
1558 this%magnetic_cache%zsuv(s,u,v) =
1559 & this%magnetic_cache%zsuv(s,u,v) +
1560 & sum(zmnc(:,s)*cosz)
1561 ru = ru + sum(xm*rmns(:,s)*cosz)
1562 zu = zu - sum(xm*zmnc(:,s)*sinz)
1563 rv = rv - sum(xn*rmns(:,s)*cosz)
1564 zv = zv + sum(xn*zmnc(:,s)*sinz)
1566 ju = ju + sum(currumns(:,s)*sinz_nyq)
1567 jv = jv + sum(currvmns(:,s)*sinz_nyq)
1570 this%magnetic_cache%jrsuv(s,u,v) = ju*ru + jv*rv
1571 this%magnetic_cache%jphisuv(s,u,v) =
1572 & jv*this%magnetic_cache%rsuv(s,u,v)
1573 this%magnetic_cache%jzsuv(s,u,v) = ju*zu + jv*zv
1579 DEALLOCATE(cosv, sinv)
1580 DEALLOCATE(cosz, sinz)
1581 DEALLOCATE(cosv_nyq, sinv_nyq)
1582 DEALLOCATE(cosz_nyq)
1584 DEALLOCATE(sinz_nyq)
1589 this%magnetic_cache%zsuv = this%magnetic_cache%zsuv
1592 DEALLOCATE(cosu, sinu)
1593 DEALLOCATE(cosu_nyq, sinu_nyq)
1652 IF (
ASSOCIATED(this%magnetic_cache%kruv) .or.
1653 &
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
1657 woddlow = 0.5*sqrt((ns - 1.0)/(ns - 1.5))
1658 woddhigh = 1.5*sqrt((ns - 1.0)/(ns - 2.5))
1660 ALLOCATE(bsubuc(mnmax_nyq), bsubvc(mnmax_nyq))
1661 WHERE (mod(nint(xm_nyq), 2) .eq. 0)
1662 bsubuc = 1.5*bsubumnc(:,ns) - 0.5*bsubumnc(:,ns - 1)
1663 bsubvc = 1.5*bsubvmnc(:,ns) - 0.5*bsubvmnc(:,ns - 1)
1665 bsubuc = woddhigh*bsubumnc(:,ns)
1666 & - woddlow*bsubumnc(:,ns - 1)
1667 bsubvc = woddhigh*bsubvmnc(:,ns)
1668 & - woddlow*bsubvmnc(:,ns - 1)
1672 ALLOCATE(bsubus(mnmax_nyq), bsubvs(mnmax_nyq))
1673 WHERE (mod(nint(xm_nyq), 2) .eq. 0)
1674 bsubus = 1.5*bsubumns(:,ns) - 0.5*bsubumns(:,ns - 1)
1675 bsubvs = 1.5*bsubvmns(:,ns) - 0.5*bsubvmns(:,ns - 1)
1677 bsubus = woddhigh*bsubumns(:,ns)
1678 & - woddlow*bsubumns(:,ns - 1)
1679 bsubvs = woddhigh*bsubvmns(:,ns)
1680 & - woddlow*bsubvmns(:,ns - 1)
1685 IF (
ASSOCIATED(this%magnetic_cache%kruv))
THEN
1686 numu =
SIZE(this%magnetic_cache%kruv, 1)
1687 numv =
SIZE(this%magnetic_cache%kruv, 2)
1689 ALLOCATE(cosu(mnmax, numu), sinu(mnmax, numu))
1690 ALLOCATE(cosu_nyq(mnmax_nyq, numu), sinu_nyq(mnmax_nyq, numu))
1705 theta = (u - 1)*this%magnetic_cache%du_a
1706 cosu(:,u) = cos(xm*theta)
1707 sinu(:,u) = sin(xm*theta)
1708 cosu_nyq(:,u) = cos(xm_nyq*theta)
1709 sinu_nyq(:,u) = sin(xm_nyq*theta)
1715 ALLOCATE(cosv(mnmax), sinv(mnmax))
1716 ALLOCATE(cosz(mnmax), sinz(mnmax))
1717 ALLOCATE(cosv_nyq(mnmax_nyq), sinv_nyq(mnmax_nyq))
1718 ALLOCATE(cosz_nyq(mnmax_nyq))
1720 ALLOCATE(sinz_nyq(mnmax_nyq))
1729 phi = (v - 1)*this%magnetic_cache%dv_a + this%phi_offset
1733 cosv_nyq = cos(xn_nyq*phi)
1734 sinv_nyq = sin(xn_nyq*phi)
1738 cosz = cosu(:,u)*cosv + sinu(:,u)*sinv
1739 sinz = sinu(:,u)*cosv - cosu(:,u)*sinv
1741 cosz_nyq = cosu_nyq(:,u)*cosv_nyq
1742 & + sinu_nyq(:,u)*sinv_nyq
1744 ru = -sum(xm*rmnc(:,ns)*sinz)
1745 zu = sum(xm*zmns(:,ns)*cosz)
1746 rv = sum(xn*rmnc(:,ns)*sinz)
1747 zv = -sum(xn*zmns(:,ns)*cosz)
1748 r = sum(rmnc(:,ns)*cosz)
1750 bu = sum(bsubuc*cosz_nyq)
1751 bv = sum(bsubvc*cosz_nyq)
1754 sinz_nyq = sinu_nyq(:,u)*cosv_nyq
1755 & - cosu_nyq(:,u)*sinv_nyq
1757 ru = ru + sum(xm*rmns(:,ns)*cosz)
1758 zu = zu - sum(xm*zmnc(:,ns)*sinz)
1759 rv = rv - sum(xn*rmns(:,ns)*cosz)
1760 zv = zv + sum(xn*zmnc(:,ns)*sinz)
1761 r = r + sum(rmns(:,ns)*sinz)
1763 bu = bu + sum(bsubus*sinz_nyq)
1764 bv = bv + sum(bsubvs*sinz_nyq)
1767 this%magnetic_cache%kruv(u,v) = -1.0/mu0*(bu*rv - bv*ru)
1768 this%magnetic_cache%kphiuv(u,v) = -1.0/mu0*bu*r
1769 this%magnetic_cache%kzuv(u,v) = -1.0/mu0*(bu*zv - bv*zu)
1774 DEALLOCATE(cosv, sinv)
1775 DEALLOCATE(cosz, sinz)
1776 DEALLOCATE(cosv_nyq, sinv_nyq)
1777 DEALLOCATE(cosz_nyq)
1779 DEALLOCATE(sinz_nyq)
1784 DEALLOCATE(cosu, sinu)
1785 DEALLOCATE(cosu_nyq, sinu_nyq)
1788 IF (
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
1789 numu =
SIZE(this%magnetic_cache%kxuv_full, 1)
1790 numv =
SIZE(this%magnetic_cache%kxuv_full, 2)
1792 ALLOCATE(cosu(mnmax, numu), sinu(mnmax, numu))
1793 ALLOCATE(cosu_nyq(mnmax_nyq, numu), sinu_nyq(mnmax_nyq, numu))
1808 theta = (u - 1)*this%magnetic_cache%du_full
1809 cosu(:,u) = cos(xm*theta)
1810 sinu(:,u) = sin(xm*theta)
1811 cosu_nyq(:,u) = cos(xm_nyq*theta)
1812 sinu_nyq(:,u) = sin(xm_nyq*theta)
1818 ALLOCATE(cosv(mnmax), sinv(mnmax))
1819 ALLOCATE(cosz(mnmax), sinz(mnmax))
1820 ALLOCATE(cosv_nyq(mnmax_nyq), sinv_nyq(mnmax_nyq))
1821 ALLOCATE(cosz_nyq(mnmax_nyq))
1823 ALLOCATE(sinz_nyq(mnmax_nyq))
1833 phi = (v - 1)*this%magnetic_cache%dv_full
1839 cosv_nyq = cos(xn_nyq*phi)
1840 sinv_nyq = sin(xn_nyq*phi)
1844 cosz = cosu(:,u)*cosv + sinu(:,u)*sinv
1845 sinz = sinu(:,u)*cosv - cosu(:,u)*sinv
1847 cosz_nyq = cosu_nyq(:,u)*cosv_nyq
1848 & + sinu_nyq(:,u)*sinv_nyq
1850 ru = -sum(xm*rmnc(:,ns)*sinz)
1851 zu = sum(xm*zmns(:,ns)*cosz)
1852 rv = sum(xn*rmnc(:,ns)*sinz)
1853 zv = -sum(xn*zmns(:,ns)*cosz)
1854 r = sum(rmnc(:,ns)*cosz)
1855 z = sum(zmns(:,ns)*sinz)
1857 bu = sum(bsubuc*cosz_nyq)
1858 bv = sum(bsubvc*cosz_nyq)
1861 sinz_nyq = sinu_nyq(:,u)*cosv_nyq
1862 & - cosu_nyq(:,u)*sinv_nyq
1864 ru = ru + sum(xm*rmns(:,ns)*cosz)
1865 zu = zu - sum(xm*zmnc(:,ns)*sinz)
1866 rv = rv - sum(xn*rmns(:,ns)*cosz)
1867 zv = zv + sum(xn*zmnc(:,ns)*sinz)
1868 r = r + sum(rmns(:,ns)*sinz)
1869 z = z + sum(zmnc(:,ns)*cosz)
1871 bu = bu + sum(bsubus*sinz_nyq)
1872 bv = bv + sum(bsubvs*sinz_nyq)
1875 kr = -1.0/mu0*(bu*rv - bv*ru)
1876 kphi = -1.0/mu0*bu*r
1878 this%magnetic_cache%kxuv_full(u,v) = kr*cosphi
1880 this%magnetic_cache%kyuv_full(u,v) = kr*sinphi
1882 this%magnetic_cache%kzuv_full(u,v) = -1.0/mu0*(bu*zv -
1885 this%magnetic_cache%x_prime(u,v,1) = r*cosphi
1886 this%magnetic_cache%x_prime(u,v,2) = r*sinphi
1887 this%magnetic_cache%x_prime(u,v,3) = z
1889 IF (
ASSOCIATED(this%magnetic_cache%kxuv_axi))
THEN
1899 IF (xn(i) .eq. 0.0)
THEN
1900 ru = ru - xm(i)*rmnc(i,ns)*sinz(i)
1901 zu = zu + xm(i)*zmns(i,ns)*cosz(i)
1902 r = r + rmnc(i,ns)*cosz(i)
1903 z = z + zmns(i,ns)*sinz(i)
1907 DO i = 1,
SIZE(xn_nyq)
1908 IF (xn_nyq(i) .eq. 0.0)
THEN
1909 bu = bu + bsubuc(i)*cosz_nyq(i)
1910 bv = bv + bsubvc(i)*cosz_nyq(i)
1916 IF (xn(i) .eq. 0.0)
THEN
1917 ru = ru + xm(i)*rmns(i,ns)*cosz(i)
1918 zu = zu - xm(i)*zmnc(i,ns)*sinz(i)
1919 r = r + rmns(i,ns)*sinz(i)
1920 z = z + zmnc(i,ns)*cosz(i)
1924 DO i = 1,
SIZE(xn_nyq)
1925 IF (xn_nyq(i) .eq. 0.0)
THEN
1926 bu = bu + bsubus(i)*sinz_nyq(i)
1927 bv = bv + bsubvs(i)*sinz_nyq(i)
1933 kphi = -1.0/mu0*bu*r
1935 this%magnetic_cache%kxuv_axi(u,v) = kr*cosphi
1937 this%magnetic_cache%kyuv_axi(u,v) = kr*sinphi
1939 this%magnetic_cache%kzuv_axi(u,v) = 1.0/mu0*bv*zu
1941 this%magnetic_cache%x_axi(u,v,1) = r*cosphi
1942 this%magnetic_cache%x_axi(u,v,2) = r*sinphi
1943 this%magnetic_cache%x_axi(u,v,3) = z
1950 DEALLOCATE(cosv, sinv)
1951 DEALLOCATE(cosz, sinz)
1952 DEALLOCATE(cosv_nyq, sinv_nyq)
1953 DEALLOCATE(cosz_nyq)
1955 DEALLOCATE(sinz_nyq)
1960 DEALLOCATE(cosu, sinu)
1961 DEALLOCATE(cosu_nyq, sinu_nyq)
1964 IF (
ASSOCIATED(this%magnetic_cache%kruv) .or.
1965 &
ASSOCIATED(this%magnetic_cache%kzuv_full))
THEN
1966 DEALLOCATE(bsubuc, bsubvc)
1969 DEALLOCATE(bsubus, bsubvs)
1973 CALL profiler_set_stop_time(
'vmec_set_magnetic_cache_calc',
1987 USE read_wout_mod,
only: rmnc, rmns, zmnc, zmns, xm, xn, mnmax
1993 TYPE (vmec_class),
INTENT(in) :: this
1997 REAL (rprec) :: start_time
2000 start_time = profiler_get_start_time()
2007 rbc(int(xn(i)/nfp),int(xm(i))) =
2008 & rmnc(i,ns_array(this%ns_index))
2009 zbs(int(xn(i)/nfp),int(xm(i))) =
2010 & zmns(i,ns_array(this%ns_index))
2012 rbs(int(xn(i)/nfp),int(xm(i))) =
2013 & rmns(i,ns_array(this%ns_index))
2014 zbc(int(xn(i)/nfp),int(xm(i))) =
2015 & zmnc(i,ns_array(this%ns_index))
2021 raxis_cc(0:ntor) = rmnc(1:ntor + 1,1)
2022 zaxis_cs(0:ntor) = zmns(1:ntor + 1,1)
2024 raxis_cs(0:ntor) = rmns(1:ntor + 1,1)
2025 zaxis_cc(0:ntor) = zmnc(1:ntor + 1,1)
2028 CALL profiler_set_stop_time(
'vmec_set_namelist', start_time)
2051 CHARACTER (len=*),
INTENT(in) :: param_name
2054 REAL (rprec) :: start_time
2057 start_time = profiler_get_start_time()
2059 SELECT CASE (trim(param_name))
2202 CASE (
'pp_sxrem_b_a')
2205 CASE (
'pp_sxrem_as_a')
2208 CASE (
'pp_sxrem_af_a')
2238 CASE (
'vvc_smaleli')
2241 CASE (
'vvc_kappa_p')
2272 WRITE (*,1000) trim(param_name)
2277 CALL profiler_set_stop_time(
'vmec_get_param_id', start_time)
2279 1000
FORMAT(
'ERROR: ',a,
' is not a valid parameter.')
2295 USE vmec_input,
only: rbc, zbs, rbs, zbc, &
2296 & ac, ac_aux_s, ac_aux_f, &
2297 & ai, ai_aux_s, ai_aux_f, &
2298 & am, am_aux_s, am_aux_f, &
2299 & extcur, curtor, phiedge, pres_scale, &
2301 USE read_wout_mod,
only: rmnc, zmns, rmns, zmnc, lmns, lmnc, &
2302 & gmnc, gmns, bsubumnc, bsubvmnc, &
2303 & bsubsmns, bsupumnc, bsupvmnc, &
2304 & bsubumns, bsubvmns, &
2305 & bsubsmnc, bsupumns, bsupvmns, &
2306 & phi, iotaf, iotas, &
2307 & betatot, betapol, betator, betaxis, &
2308 & jcuru, jcurv, jdotb, raxis, zaxis, qfact
2316 INTEGER,
INTENT(in) :: id
2317 INTEGER,
INTENT(in) :: i_index
2318 INTEGER,
INTENT(in) :: j_index
2321 REAL (rprec) :: start_time
2324 start_time = profiler_get_start_time()
2543 CALL profiler_set_stop_time(
'vmec_get_param_value', start_time)
2563 INTEGER,
INTENT(in) :: id
2566 REAL (rprec) :: start_time
2569 start_time = profiler_get_start_time()
2785 stop
'Invalid VMEC parameter id.'
2789 CALL profiler_set_stop_time(
'vmec_get_param_name', start_time)
2812 REAL (rprec) :: start_time
2815 start_time = profiler_get_start_time()
2817 IF (
ASSOCIATED(this%ne))
THEN
2824 CALL profiler_set_stop_time(
'vmec_get_gp_ne_num_hyper_param',
2847 REAL (rprec) :: start_time
2850 start_time = profiler_get_start_time()
2852 IF (
ASSOCIATED(this%ne))
THEN
2858 CALL profiler_set_stop_time(
'vmec_get_ne_af', start_time)
2880 INTEGER,
INTENT(in) :: i
2881 INTEGER,
INTENT(in) :: j
2884 REAL (rprec) :: start_time
2887 start_time = profiler_get_start_time()
2889 IF (
ASSOCIATED(this%ne))
THEN
2895 CALL profiler_set_stop_time(
'vmec_get_gp_ne_ij', start_time)
2917 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2918 INTEGER,
INTENT(in) :: i
2922 REAL (rprec) :: start_time
2925 start_time = profiler_get_start_time()
2928 IF (
ASSOCIATED(this%ne) .and. (s .le. 1.0))
THEN
2934 CALL profiler_set_stop_time(
'vmec_get_gp_ne_pi', start_time)
2957 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2958 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
2963 REAL (rprec) :: start_time
2966 start_time = profiler_get_start_time()
2970 IF (
ASSOCIATED(this%ne) .and. (s1 .le. 1.0) .and.
2971 & (s2 .le. 1.0))
THEN
2977 CALL profiler_set_stop_time(
'vmec_get_gp_ne_pp', start_time)
2998 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3001 REAL (rprec) :: start_time
3004 start_time = profiler_get_start_time()
3007 CALL profiler_set_stop_time(
'vmec_get_ne_cart', start_time)
3028 REAL (rprec),
INTENT(in) :: s
3031 REAL (rprec) :: start_time
3034 start_time = profiler_get_start_time()
3036 IF (
ASSOCIATED(this%ne))
THEN
3042 CALL profiler_set_stop_time(
'vmec_get_ne_radial', start_time)
3065 REAL (rprec) :: start_time
3068 start_time = profiler_get_start_time()
3070 IF (
ASSOCIATED(this%te))
THEN
3077 CALL profiler_set_stop_time(
'vmec_get_gp_te_num_hyper_param',
3100 REAL (rprec) :: start_time
3103 start_time = profiler_get_start_time()
3105 IF (
ASSOCIATED(this%te))
THEN
3111 CALL profiler_set_stop_time(
'vmec_get_te_af', start_time)
3133 INTEGER,
INTENT(in) :: i
3134 INTEGER,
INTENT(in) :: j
3137 REAL (rprec) :: start_time
3140 start_time = profiler_get_start_time()
3142 IF (
ASSOCIATED(this%te))
THEN
3148 CALL profiler_set_stop_time(
'vmec_get_gp_te_ij', start_time)
3171 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3172 INTEGER,
INTENT(in) :: i
3176 REAL (rprec) :: start_time
3179 start_time = profiler_get_start_time()
3182 IF (
ASSOCIATED(this%te) .and. (s .le. 1.0))
THEN
3188 CALL profiler_set_stop_time(
'vmec_get_gp_te_pi', start_time)
3213 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3214 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
3219 REAL (rprec) :: start_time
3222 start_time = profiler_get_start_time()
3226 IF (
ASSOCIATED(this%te) .and. (s1 .le. 1.0) .and.
3227 & (s2 .le. 1.0))
THEN
3233 CALL profiler_set_stop_time(
'vmec_get_gp_te_pp', start_time)
3254 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3257 REAL (rprec) :: start_time
3260 start_time = profiler_get_start_time()
3263 CALL profiler_set_stop_time(
'vmec_get_te_cart', start_time)
3284 REAL (rprec),
INTENT(in) :: s
3287 REAL (rprec) :: start_time
3290 start_time = profiler_get_start_time()
3291 IF (
ASSOCIATED(this%te))
THEN
3297 CALL profiler_set_stop_time(
'vmec_get_te_radial', start_time)
3320 REAL (rprec) :: start_time
3323 start_time = profiler_get_start_time()
3325 IF (
ASSOCIATED(this%ti))
THEN
3332 CALL profiler_set_stop_time(
'vmec_get_gp_ti_num_hyper_param',
3355 REAL (rprec) :: start_time
3358 start_time = profiler_get_start_time()
3360 IF (
ASSOCIATED(this%ti))
THEN
3366 CALL profiler_set_stop_time(
'vmec_get_ti_af', start_time)
3388 INTEGER,
INTENT(in) :: i
3389 INTEGER,
INTENT(in) :: j
3392 REAL (rprec) :: start_time
3395 start_time = profiler_get_start_time()
3397 IF (
ASSOCIATED(this%ti))
THEN
3403 CALL profiler_set_stop_time(
'vmec_get_gp_ti_ij', start_time)
3426 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3427 INTEGER,
INTENT(in) :: i
3431 REAL (rprec) :: start_time
3434 start_time = profiler_get_start_time()
3437 IF (
ASSOCIATED(this%ti) .and. (s .le. 1.0))
THEN
3443 CALL profiler_set_stop_time(
'vmec_get_gp_ti_pi', start_time)
3466 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3467 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
3472 REAL (rprec) :: start_time
3475 start_time = profiler_get_start_time()
3479 IF (
ASSOCIATED(this%ti) .and. (s1 .le. 1.0) .and.
3480 & (s2 .le. 1.0))
THEN
3486 CALL profiler_set_stop_time(
'vmec_get_gp_ti_pp', start_time)
3507 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3510 REAL (rprec) :: start_time
3513 start_time = profiler_get_start_time()
3516 CALL profiler_set_stop_time(
'vmec_get_ti_cart', start_time)
3537 REAL (rprec),
INTENT(in) :: s
3540 REAL (rprec) :: start_time
3543 start_time = profiler_get_start_time()
3544 IF (
ASSOCIATED(this%ti))
THEN
3550 CALL profiler_set_stop_time(
'vmec_get_ti_radial', start_time)
3571 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3574 REAL (rprec) :: start_time
3577 start_time = profiler_get_start_time()
3580 CALL profiler_set_stop_time(
'vmec_get_ze_cart', start_time)
3601 REAL (rprec),
INTENT(in) :: s
3604 REAL (rprec) :: start_time
3607 start_time = profiler_get_start_time()
3608 IF (
ASSOCIATED(this%ze))
THEN
3614 CALL profiler_set_stop_time(
'vmec_get_ze_radial', start_time)
3636 INTEGER,
INTENT(in) :: index
3639 REAL (rprec) :: start_time
3642 start_time = profiler_get_start_time()
3644 IF (
ASSOCIATED(this%sxrem) .and.
3645 & (index .le.
SIZE(this%sxrem)))
THEN
3652 CALL profiler_set_stop_time(
'vmec_get_gp_sxrem_num_hyper_param',
3674 INTEGER,
INTENT(in) :: index
3677 REAL (rprec) :: start_time
3680 start_time = profiler_get_start_time()
3682 IF (
ASSOCIATED(this%sxrem) .and.
3683 & (index .le.
SIZE(this%sxrem)))
THEN
3689 CALL profiler_set_stop_time(
'vmec_get_sxrem_af', start_time)
3712 INTEGER,
INTENT(in) :: i
3713 INTEGER,
INTENT(in) :: j
3714 INTEGER,
INTENT(in) :: index
3717 REAL (rprec) :: start_time
3720 start_time = profiler_get_start_time()
3722 IF (
ASSOCIATED(this%sxrem) .and.
3723 & (index .le.
SIZE(this%sxrem)))
THEN
3730 CALL profiler_set_stop_time(
'vmec_get_gp_sxrem_ij', start_time)
3754 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3755 INTEGER,
INTENT(in) :: i
3756 INTEGER,
INTENT(in) :: index
3760 REAL (rprec) :: start_time
3763 start_time = profiler_get_start_time()
3766 IF (
ASSOCIATED(this%sxrem) .and.
3767 & (index .le.
SIZE(this%sxrem)) .and. (s .le. 1.0))
THEN
3774 CALL profiler_set_stop_time(
'vmec_get_gp_sxrem_pi', start_time)
3800 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3801 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
3802 INTEGER,
INTENT(in) :: index
3807 REAL (rprec) :: start_time
3810 start_time = profiler_get_start_time()
3814 IF (
ASSOCIATED(this%sxrem) .and.
3815 & (index .le.
SIZE(this%sxrem)) .and.
3816 & (s1 .le. 1.0) .and. (s2 .le. 1.0))
THEN
3823 CALL profiler_set_stop_time(
'vmec_get_gp_sxrem_pp', start_time)
3845 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3846 INTEGER,
INTENT(in) :: index
3849 REAL (rprec) :: start_time
3852 start_time = profiler_get_start_time()
3857 CALL profiler_set_stop_time(
'vmec_get_sxrem_cart', start_time)
3879 REAL (rprec),
INTENT(in) :: s
3880 INTEGER,
INTENT(in) :: index
3883 REAL (rprec) :: start_time
3886 start_time = profiler_get_start_time()
3888 IF (
ASSOCIATED(this%sxrem) .and.
3889 & (index .le.
SIZE(this%sxrem)))
THEN
3896 CALL profiler_set_stop_time(
'vmec_get_sxrem_radial', start_time)
3916 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3919 REAL (rprec) :: start_time
3922 start_time = profiler_get_start_time()
3925 CALL profiler_set_stop_time(
'vmec_get_p_cart', start_time)
3939 USE stel_constants,
only: mu0
3946 REAL (rprec),
INTENT(in) :: s
3949 REAL (rprec) :: start_time
3957 REAL (rprec) :: pmass
3958 REAL (rprec),
INTENT(in) :: s
3963 start_time = profiler_get_start_time()
3966 CALL profiler_set_stop_time(
'vmec_get_p_radial', start_time)
3983 USE vmec_utils,
ONLY : getbcyl_wout
3985 USE vmec_input,
ONLY: nfp
3992 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3993 LOGICAL,
INTENT(in) :: cyl
3996 REAL (rprec),
DIMENSION(3) :: r_cyl
3997 REAL (rprec),
DIMENSION(3) :: r_cyl_rot
3998 REAL (rprec) :: s_temp
4000 REAL (rprec) :: start_time
4003 start_time = profiler_get_start_time()
4007 r_cyl_rot(2) = r_cyl(2) + this%phi_offset
4008 r_cyl_rot(3) = r_cyl(3) - this%z_offset
4012 CALL getbcyl_wout(r_cyl_rot(1), r_cyl_rot(2), r_cyl_rot(3),
4016 IF (lfreeb .and. (s_temp .gt. 1.0 .or. status .eq. -3))
THEN
4028 CALL profiler_set_stop_time(
'vmec_get_B_vec', start_time)
4045 USE stel_constants,
only: twopi
4046 USE read_wout_mod,
only: bsubvmnc, ns
4053 REAL (rprec),
INTENT(in) :: r
4054 REAL (rprec),
INTENT(in) :: theta
4057 REAL (rprec) :: bsubv00c, ds
4059 REAL (rprec),
DIMENSION(2) :: s
4060 REAL (rprec) :: start_time
4063 start_time = profiler_get_start_time()
4069 CALL line_seg(r, bsubv00c, s, bsubvmnc(1,ns - 1:ns), 2)
4073 CALL profiler_set_stop_time(
'vmec_get_Int_B_dphi', start_time)
4087 USE cyl_flux,
only: cyl2flx
4089 USE read_wout_mod,
only: rzl_local, ns, ntmax, lthreed, ntor, &
4097 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
4100 REAL (rprec),
DIMENSION(3) :: r_cyl
4101 REAL (rprec) :: fmin
4104 REAL (rprec) :: start_time
4107 start_time = profiler_get_start_time()
4115 r_cyl(2) = nfp*(r_cyl(2) + this%phi_offset)
4116 r_cyl(3) = r_cyl(3) - this%z_offset
4118 CALL cyl2flx(rzl_local, r_cyl,
vmec_get_suv, ns, ntor, mpol,
4119 & ntmax, lthreed, lasym, info, nfe, fmin)
4122 IF (fmin .gt. 1.0e-8_rprec)
THEN
4123 WRITE(*,*)
"Warn: VMEC could not converge to flux position."
4129 IF (info .eq. -3)
THEN
4133 CALL profiler_set_stop_time(
'vmec_get_suv', start_time)
4147 USE cyl_flux,
only: cyl2flx
4149 USE read_wout_mod,
only: rzl_local, ns, ntmax, lthreed, ntor, &
4157 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
4160 REAL (rprec),
DIMENSION(3) :: s_flux
4161 REAL (rprec) :: start_time
4164 start_time = profiler_get_start_time()
4169 CALL profiler_set_stop_time(
'vmec_get_s', start_time)
4183 USE vmec_input,
only: lrfp
4190 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
4193 REAL (rprec) :: start_time
4196 REAL (rprec),
EXTERNAL :: torflux
4199 start_time = profiler_get_start_time()
4209 CALL profiler_set_stop_time(
'vmec_get_flux', start_time)
4227 USE read_wout_mod,
only: xm, xn, rmnc, zmns, rmns, zmnc, lasym, &
4229 USE stel_constants,
only: twopi
4236 REAL (rprec),
INTENT (in) :: phi
4237 REAL (rprec),
DIMENSION(:),
POINTER :: r
4238 REAL (rprec),
DIMENSION(:),
POINTER :: z
4241 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosv, sinv
4242 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosu, sinu
4244 REAL (rprec) :: start_time
4247 start_time = profiler_get_start_time()
4253 ALLOCATE(cosv(
SIZE(xn, 1)), sinv(
SIZE(xn, 1)))
4254 ALLOCATE(cosu(
SIZE(xm, 1)), sinu(
SIZE(xm, 1)))
4256 cosv(:) = cos(xn*(phi + this%phi_offset))
4257 sinv(:) = sin(xn*(phi + this%phi_offset))
4262 r(i) = sum(rmnc(:, ns)*(cosu(:)*cosv(:) + sinu(:)*sinv(:)))
4263 z(i) = sum(zmns(:, ns)*(sinu(:)*cosv(:) - cosu(:)*sinv(:)))
4267 & sum(rmns(:, ns)*(sinu(:)*cosv(:) - cosu(:)*sinv(:)))
4269 & sum(zmnc(:, ns)*(cosu(:)*cosv(:) + sinu(:)*sinv(:)))
4272 z = z + this%z_offset
4273 DEALLOCATE(cosu, cosv, sinu, sinv)
4275 CALL profiler_set_stop_time(
'vmec_get_plasma_edge', start_time)
4293 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
4298 REAL (rprec) :: start_time
4301 start_time = profiler_get_start_time()
4304 CALL profiler_set_stop_time(
'vmec_get_magnetic_volume_rgrid',
4323 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
4328 REAL (rprec) :: start_time
4331 start_time = profiler_get_start_time()
4334 CALL profiler_set_stop_time(
'vmec_get_magnetic_volume_zgrid',
4353 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
4358 REAL (rprec) :: start_time
4361 start_time = profiler_get_start_time()
4364 CALL profiler_set_stop_time(
'vmec_get_magnetic_volume_jrgrid',
4383 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
4388 REAL (rprec) :: start_time
4391 start_time = profiler_get_start_time()
4394 CALL profiler_set_stop_time(
'vmec_get_magnetic_volume_jphigrid',
4413 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
4418 REAL (rprec) :: start_time
4421 start_time = profiler_get_start_time()
4424 CALL profiler_set_stop_time(
'vmec_get_magnetic_volume_jzgrid',
4445 USE read_wout_mod,
only: isigng
4454 REAL (rprec) :: start_time
4457 start_time = profiler_get_start_time()
4459 & * this%magnetic_cache%du
4460 & * this%magnetic_cache%dv
4462 CALL profiler_set_stop_time(
'vmec_get_volume_int_element',
4481 REAL (rprec),
DIMENSION(:,:),
POINTER ::
4486 REAL (rprec) :: start_time
4489 start_time = profiler_get_start_time()
4492 CALL profiler_set_stop_time(
'vmec_get_con_surface_krgrid',
4511 REAL (rprec),
DIMENSION(:,:),
POINTER ::
4516 REAL (rprec) :: start_time
4519 start_time = profiler_get_start_time()
4522 CALL profiler_set_stop_time(
'vmec_get_con_surface_kphigrid',
4541 REAL (rprec),
DIMENSION(:,:),
POINTER ::
4546 REAL (rprec) :: start_time
4549 start_time = profiler_get_start_time()
4552 CALL profiler_set_stop_time(
'vmec_get_con_surface_kzgrid',
4573 USE read_wout_mod,
only: isigng
4582 REAL (rprec) :: start_time
4585 start_time = profiler_get_start_time()
4587 & * this%magnetic_cache%dv_a*isigng
4589 CALL profiler_set_stop_time(
'vmec_get_area_int_element',
4611 USE vmec_input,
only: lfreeb, extcur
4612 USE mgrid_mod,
only: mgrid_mode, nextcur
4619 INTEGER,
INTENT(in) :: num_currents
4620 LOGICAL,
INTENT(out) :: scale_currents
4623 REAL (rprec) :: start_time
4626 start_time = profiler_get_start_time()
4629 SELECT CASE (mgrid_mode)
4631 CASE (
'S',
's',
'N',
'n')
4632 scale_currents = .true.
4635 scale_currents = .false.
4639 ELSE IF (num_currents .gt. 0)
THEN
4641 scale_currents = .false.
4647 CALL profiler_set_stop_time(
'vmec_get_ext_currents', start_time)
4663 USE vmec_utils,
ONLY : getbcyl_wout
4665 USE vmec_input,
ONLY: nfp
4672 REAL (rprec),
DIMENSION(3),
INTENT(in) :: r_cyl
4675 REAL (rprec) :: v_norm
4676 INTEGER :: i_low, i_high
4677 INTEGER :: j_low, j_high
4678 INTEGER :: k_low, k_high
4679 REAL (rprec) :: r_low
4680 REAL (rprec) :: phi_low
4681 REAL (rprec) :: z_low
4682 REAL (rprec) :: delphib
4683 REAL (rprec) :: wrl, wrh
4684 REAL (rprec) :: wphil, wphih
4685 REAL (rprec) :: wzl, wzh
4686 REAL (rprec) :: start_time
4689 start_time = profiler_get_start_time()
4691 IF (r_cyl(1) .gt. rmaxb .or. r_cyl(1) .lt. rminb)
THEN
4692 stop
'Radial point outside vacuum grid.'
4694 IF (r_cyl(3) .gt. zmaxb .or. r_cyl(3) .lt. zminb)
THEN
4695 stop
'Vertical point outside vacuum grid.'
4700 DO WHILE(v_norm .gt. twopi .or. v_norm .lt. 0)
4701 IF (v_norm .gt. twopi)
THEN
4702 v_norm = v_norm - twopi
4704 v_norm = v_norm + twopi
4710 DO WHILE(v_norm .gt. twopi/nfp)
4711 v_norm = v_norm - twopi/nfp
4717 delphib = twopi/(nfp*np0b)
4719 i_low = int((r_cyl(1) - rminb)/delrb) + 1
4720 j_low = int(v_norm/delphib) + 1
4721 k_low = int((r_cyl(3) - zminb)/delzb) + 1
4724 IF (np0b .eq. 1)
THEN
4731 r_low = rminb + (i_low - 1.0)*delrb
4732 phi_low = (j_low - 1.0)*delphib
4733 z_low = zminb + (k_low - 1.0)*delzb
4735 wrh = (r_cyl(1) - r_low)/delrb
4736 wrl = (delrb - r_cyl(1) + r_low)/delrb
4737 wphih = (v_norm - phi_low)/delphib
4738 wphil = (delphib - v_norm + phi_low)/delphib
4739 wzh = (r_cyl(3) - z_low)/delzb
4740 wzl = (delzb - r_cyl(3) + z_low)/delzb
4743 & = wrl*wphil*wzl*brvac(i_low,k_low,j_low)
4744 & + wrh*wphil*wzl*brvac(i_high,k_low,j_low)
4745 & + wrl*wphih*wzl*brvac(i_low,k_low,j_high)
4746 & + wrh*wphih*wzl*brvac(i_high,k_low,j_high)
4747 & + wrl*wphil*wzh*brvac(i_low,k_high,j_low)
4748 & + wrh*wphil*wzh*brvac(i_high,k_high,j_low)
4749 & + wrl*wphih*wzh*brvac(i_low,k_high,j_high)
4750 & + wrh*wphih*wzh*brvac(i_high,k_high,j_high)
4753 & = wrl*wphil*wzl*bpvac(i_low,k_low,j_low)
4754 & + wrh*wphil*wzl*bpvac(i_high,k_low,j_low)
4755 & + wrl*wphih*wzl*bpvac(i_low,k_low,j_high)
4756 & + wrh*wphih*wzl*bpvac(i_high,k_low,j_high)
4757 & + wrl*wphil*wzh*bpvac(i_low,k_high,j_low)
4758 & + wrh*wphil*wzh*bpvac(i_high,k_high,j_low)
4759 & + wrl*wphih*wzh*bpvac(i_low,k_high,j_high)
4760 & + wrh*wphih*wzh*bpvac(i_high,k_high,j_high)
4763 & = wrl*wphil*wzl*bzvac(i_low,k_low,j_low)
4764 & + wrh*wphil*wzl*bzvac(i_high,k_low,j_low)
4765 & + wrl*wphih*wzl*bzvac(i_low,k_low,j_high)
4766 & + wrh*wphih*wzl*bzvac(i_high,k_low,j_high)
4767 & + wrl*wphil*wzh*bzvac(i_low,k_high,j_low)
4768 & + wrh*wphil*wzh*bzvac(i_high,k_high,j_low)
4769 & + wrl*wphih*wzh*bzvac(i_low,k_high,j_high)
4770 & + wrh*wphih*wzh*bzvac(i_high,k_high,j_high)
4772 CALL profiler_set_stop_time(
'vmec_get_B_vac', start_time)
4793 USE read_wout_mod,
only: isigng
4800 REAL (rprec),
DIMENSION(3),
INTENT(in) :: position
4801 LOGICAL,
INTENT(in) :: axi_only
4804 REAL (rprec),
DIMENSION(3) :: x_cart
4805 REAL (rprec),
DIMENSION(3) :: r_vec
4807 REAL (rprec) :: length
4808 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: x_prime
4809 REAL (rprec),
DIMENSION(:,:),
POINTER :: kxuv
4810 REAL (rprec),
DIMENSION(:,:),
POINTER :: kyuv
4811 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv
4812 REAL (rprec),
DIMENSION(3) :: sum_b
4813 REAL (rprec) :: start_time
4816 start_time = profiler_get_start_time()
4825 CALL assert(
ASSOCIATED(this%magnetic_cache%kxuv_axi),
4826 &
'Cannot get the axisymmtric only ext bfield.')
4828 x_prime => this%magnetic_cache%x_axi
4829 kxuv => this%magnetic_cache%kxuv_axi
4830 kyuv => this%magnetic_cache%kyuv_axi
4831 kzuv => this%magnetic_cache%kzuv_axi
4833 CALL assert(
ASSOCIATED(this%magnetic_cache%kxuv_full),
4834 &
'Cannot get the ext bfield.')
4836 x_prime => this%magnetic_cache%x_prime
4837 kxuv => this%magnetic_cache%kxuv_full
4838 kyuv => this%magnetic_cache%kyuv_full
4839 kzuv => this%magnetic_cache%kzuv_full
4846 DO v = 1,
SIZE(kxuv,2)
4847 DO u = 1,
SIZE(kxuv,1)
4848 r_vec = x_cart - x_prime(u,v,:)
4849 length = sqrt(dot_product(r_vec, r_vec))**3.0
4852 & + (kyuv(u,v)*r_vec(3) - kzuv(u,v)*r_vec(2))
4855 & + (kzuv(u,v)*r_vec(1) - kxuv(u,v)*r_vec(3))
4858 & + (kxuv(u,v)*r_vec(2) - kyuv(u,v)*r_vec(1))
4877 & * this%magnetic_cache%du_full
4878 & * this%magnetic_cache%dv_full
4883 CALL profiler_set_stop_time(
'vmec_get_ext_b_plasma', start_time)
4896 USE vmec_input,
only: ns_array
4905 REAL (rprec) :: start_time
4908 start_time = profiler_get_start_time()
4910 CALL profiler_set_stop_time(
'vmec_get_grid_size', start_time)
4931 REAL (rprec) :: start_time
4934 start_time = profiler_get_start_time()
4936 CALL profiler_set_stop_time(
'vmec_get_grid_start', start_time)
4957 REAL (rprec) :: start_time
4960 start_time = profiler_get_start_time()
4962 CALL profiler_set_stop_time(
'vmec_get_grid_stop', start_time)
4985 INTEGER,
INTENT(in) :: id
4988 REAL (rprec) :: start_time
4991 start_time = profiler_get_start_time()
5006 CALL profiler_set_stop_time(
'vmec_is_scaler_value', start_time)
5026 INTEGER,
INTENT(in) :: id
5029 REAL (rprec) :: start_time
5032 start_time = profiler_get_start_time()
5053 CALL profiler_set_stop_time(
'vmec_is_1d_array', start_time)
5073 INTEGER,
INTENT(in) :: id
5076 REAL (rprec) :: start_time
5079 start_time = profiler_get_start_time()
5098 CALL profiler_set_stop_time(
'vmec_is_2d_array', start_time)
5119 INTEGER,
INTENT(in) :: id
5122 REAL (rprec) :: start_time
5125 start_time = profiler_get_start_time()
5147 CALL profiler_set_stop_time(
'vmec_is_recon_param', start_time)
5168 REAL (rprec) :: start_time
5171 start_time = profiler_get_start_time()
5181 CALL profiler_set_stop_time(
'vmec_is_using_point', start_time)
5202 USE vmec_input,
only: delt, niter, nstep
5203 USE vmec_params,
only: timestep_flag, output_flag, &
5204 & reset_jacdt_flag, jac75_flag, &
5205 & successful_term_flag, norm_term_flag, &
5206 & more_iter_flag, restart_flag
5207 USE xstuff,
only: xcdot, xc, xstore
5208 USE read_wout_mod,
only: read_wout_file, loadrzl
5209 USE vmec_main,
only: iterc, iter1, iter2
5216 INTEGER,
INTENT(inout) :: num_iter
5217 INTEGER,
INTENT(in) :: iou
5218 INTEGER,
INTENT(in) :: eq_comm
5224 REAL (rprec) :: delt_local
5225 INTEGER :: niter_local
5226 INTEGER,
DIMENSION(5) :: ictrl_array
5227 INTEGER :: recovery_index
5228 INTEGER :: error, num_iter_init
5231 INTEGER :: nstep_save
5232 REAL (rprec) :: start_time
5235 REAL (rprec),
PARAMETER :: delt_factor = 2.0
5236 INTEGER,
PARAMETER :: niter_factor = 4
5239 start_time = profiler_get_start_time()
5243 num_iter_init = iterc
5247 #if defined(MPI_OPT)
5248 CALL mpi_comm_rank(eq_comm, eq_rank, error)
5260 ictrl_array(1) = ior(ictrl_array(1), timestep_flag)
5261 ictrl_array(1) = ior(ictrl_array(1), output_flag)
5262 ictrl_array(1) = ior(ictrl_array(1), reset_jacdt_flag)
5265 IF (num_iter .gt. 1)
THEN
5266 ictrl_array(3) = niter_local
5267 ictrl_array(4) = this%ns_index
5270 ictrl_array(1) = ior(ictrl_array(1), restart_flag)
5279 CALL runvmec(ictrl_array, this%vmec_file_name, .false.,
5290 SELECT CASE (ictrl_array(2))
5296 IF (recovery_index .le. 2)
THEN
5297 IF (eq_rank .eq. 0)
THEN
5298 WRITE (*,1000)
'jac75_flag'
5299 WRITE (*,1001)
'delt', delt, delt/delt_factor
5300 WRITE (iou,1000)
'jac75_flag'
5301 WRITE (iou,1001)
'delt', delt, delt/delt_factor
5302 delt = delt/delt_factor
5308 CASE (more_iter_flag)
5316 IF (recovery_index .le. 2 .and. num_iter .gt. 1)
THEN
5317 IF (eq_rank .eq. 0)
THEN
5318 WRITE (*,1000)
'more_iter_flag'
5319 WRITE (*,1002)
'niter', niter_local,
5320 & niter_local + niter/niter_factor
5321 WRITE (iou,1000)
'more_iter_flag'
5322 WRITE (iou,1002)
'niter', niter_local,
5323 & niter_local + niter/niter_factor
5325 niter_local = niter_local + niter/niter_factor
5335 IF (eq_rank .eq. 0)
THEN
5336 WRITE (*,*)
'Attempting error recovery'
5337 WRITE (iou,*)
'Attempting error recovery'
5340 recovery_index = recovery_index + 1
5349 IF (eq_rank .eq. 0)
THEN
5351 SELECT CASE (ictrl_array(2))
5353 CASE (successful_term_flag, norm_term_flag)
5354 CALL read_wout_file(this%wout_file_name, error)
5355 CALL assert_eq(error, 0,
"Error reading wout file.")
5359 IF (
ASSOCIATED(this%magnetic_cache))
THEN
5372 num_iter = num_iter + iterc - num_iter_init
5375 CALL profiler_set_stop_time(
'vmec_converge', start_time)
5377 1000
FORMAT(
'VMEC CONVERGENCE ERROR: ',a)
5378 1001
FORMAT(a,
' change: old, new: ',es12.5,
' ',es12.5)
5379 1002
FORMAT(a,
' change: old, new: ',i12,
' ',i12)
5395 USE vmec_input,
only: extcur, mgrid_file, nfp
5396 USE mgrid_mod,
only: read_mgrid, mgrid_path_old
5397 USE vacmod0,
only: nv
5402 TYPE (vmec_class),
INTENT(in) :: this
5403 INTEGER,
INTENT(in) :: index
5404 INTEGER,
INTENT(in) :: eq_comm
5406 #if defined(MPI_OPT)
5413 CALL mpi_bcast(extcur(index), 1, mpi_real8, 0, eq_comm, error)
5414 CALL read_mgrid(mgrid_file, extcur, nv, nfp, .false., error,
5416 CALL assert_eq(0, error,
'vmec_set_param: failed to read ' //
5434 TYPE (vmec_class),
INTENT(inout) :: this
5439 REAL (rprec) :: start_time
5442 start_time = profiler_get_start_time()
5444 IF (
ASSOCIATED(this%vmec_context_save))
THEN
5452 CALL copy_file(trim(this%wout_file_name),
5453 & trim(this%wout_file_name) //
'_cache',
5455 CALL assert_eq(error, 0,
'Error copying wout file.')
5457 IF (
ASSOCIATED(this%ne))
THEN
5460 IF (
ASSOCIATED(this%te))
THEN
5463 IF (
ASSOCIATED(this%ti))
THEN
5466 IF (
ASSOCIATED(this%sxrem))
THEN
5467 DO i = 1,
SIZE(this%sxrem)
5468 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
5474 CALL profiler_set_stop_time(
'vmec_save_state', start_time)
5486 USE read_wout_mod,
only: read_wout_file, loadrzl
5492 TYPE (vmec_class),
INTENT(inout) :: this
5497 REAL (rprec) :: start_time
5500 start_time = profiler_get_start_time()
5502 IF (
ASSOCIATED(this%vmec_context_save))
THEN
5507 CALL copy_file(trim(this%wout_file_name) //
'_cache',
5508 & trim(this%wout_file_name), error)
5509 CALL assert_eq(error, 0,
'Error moving wout file.')
5511 CALL read_wout_file(this%wout_file_name, error)
5512 CALL assert_eq(error, 0,
'Error reading reset wout file.')
5515 IF (
ASSOCIATED(this%magnetic_cache))
THEN
5519 IF (
ASSOCIATED(this%ne))
THEN
5522 IF (
ASSOCIATED(this%te))
THEN
5525 IF (
ASSOCIATED(this%ti))
THEN
5528 IF (
ASSOCIATED(this%sxrem))
THEN
5529 DO i = 1,
SIZE(this%sxrem)
5530 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
5536 CALL profiler_set_stop_time(
'vmec_reset_state', start_time)
5555 TYPE (vmec_class),
INTENT(in) :: this
5556 INTEGER,
INTENT(in) :: iou
5562 REAL (rprec) :: start_time
5565 start_time = profiler_get_start_time()
5567 WRITE (iou,*)
'Equilibrium Type : VMEC'
5568 IF (
ASSOCIATED(this%ne))
THEN
5572 IF (
ASSOCIATED(this%sxrem))
THEN
5573 DO i = 1,
SIZE(this%sxrem)
5574 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
5580 IF (
ASSOCIATED(this%te))
THEN
5584 IF (
ASSOCIATED(this%ti))
THEN
5588 IF (
ASSOCIATED(this%ze))
THEN
5596 CALL safe_open(iou_nl, status,
5597 & trim(this%vmec_file_name) //
'_out',
5598 &
'replace',
'formatted', delim_in=
'quote')
5599 WRITE (iou_nl, nml=indata)
5600 CLOSE (iou_nl, iostat=status)
5602 CALL profiler_set_stop_time(
'vmec_write', start_time)
5624 TYPE (vmec_class),
INTENT(in) :: this
5625 INTEGER,
INTENT(in) :: current_step
5630 CHARACTER (len=path_length) :: filename
5631 REAL (rprec) :: start_time
5634 start_time = profiler_get_start_time()
5643 WRITE (filename,1000) trim(this%vmec_file_name), current_step
5645 CALL safe_open(iou_nl, status, trim(filename),
'replace',
5646 &
'formatted', delim_in=
'none')
5647 WRITE (iou_nl, nml=indata)
5648 CLOSE (iou_nl, iostat=status)
5649 CALL assert_eq(status, 0,
'Error saving input file.')
5652 WRITE (filename,1000) trim(this%wout_file_name), current_step
5654 CALL copy_file(this%wout_file_name, trim(filename), status)
5655 CALL assert_eq(status, 0,
'Error copying wout file.')
5657 CALL profiler_set_stop_time(
'vmec_write_input', start_time)
5659 1000
FORMAT(a,
'_',i0.3)
5706 USE mgrid_mod,
only: nextcur
5707 USE vmec_dim,
only: mpol1
5708 USE vmec_input,
only: ntor
5709 USE xstuff,
only: xc
5715 TYPE (vmec_class),
INTENT(in) :: this
5716 INTEGER,
INTENT(in) :: result_ncid
5717 INTEGER,
INTENT(in) :: maxnsetps_dim_id
5721 INTEGER :: vmec_nextcur_dim_id
5722 INTEGER :: vmec_boundary_m_dim_id
5723 INTEGER :: vmec_boundary_n_dim_id
5724 INTEGER :: vmec_extcur_id
5725 INTEGER :: vmec_curtor_id
5726 INTEGER :: vmec_pres_scale_id
5727 INTEGER :: vmec_rbc_id
5728 INTEGER :: vmec_rbs_id
5729 INTEGER :: vmec_zbc_id
5730 INTEGER :: vmec_zbs_id
5731 INTEGER :: vmec_l_sub_i_id
5732 INTEGER :: vmec_kappa_p_id
5733 INTEGER :: vmec_xc_id
5734 INTEGER :: vmec_xc_dim_id
5735 REAL (rprec) :: start_time
5738 start_time = profiler_get_start_time()
5741 status = nf_def_dim(result_ncid,
'vmec_xc_dim',
SIZE(xc),
5743 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5745 IF (nextcur .gt. 0)
THEN
5746 status = nf_def_dim(result_ncid,
'vmec_nextcur', nextcur,
5747 & vmec_nextcur_dim_id)
5748 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5751 status = nf_def_dim(result_ncid,
'vmec_boundary_m', mpol1 + 1,
5752 & vmec_boundary_m_dim_id)
5753 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5755 status = nf_def_dim(result_ncid,
'vmec_boundary_n', 2*ntor + 1,
5756 & vmec_boundary_n_dim_id)
5757 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5760 status = nf_def_var(result_ncid,
'vmec_xc', nf_double, 1,
5761 & (/ vmec_xc_dim_id /), vmec_xc_id)
5762 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5764 IF (nextcur .gt. 0)
THEN
5765 status = nf_def_var(result_ncid,
'vmec_extcur', nf_double, 1,
5766 & (/ vmec_nextcur_dim_id /), vmec_extcur_id)
5767 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5770 status = nf_def_var(result_ncid,
'vmec_curtor', nf_double, 0, 0,
5772 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5774 status = nf_def_var(result_ncid,
'vmec_pres_scale', nf_double, 0,
5775 & 0, vmec_pres_scale_id)
5776 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5778 status = nf_def_var(result_ncid,
'vmec_rbc', nf_double, 2,
5779 & (/ vmec_boundary_n_dim_id,
5780 & vmec_boundary_m_dim_id /), vmec_rbc_id)
5781 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5783 status = nf_def_var(result_ncid,
'vmec_rbs', nf_double, 2,
5784 & (/ vmec_boundary_n_dim_id,
5785 & vmec_boundary_m_dim_id /), vmec_rbs_id)
5786 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5788 status = nf_def_var(result_ncid,
'vmec_zbc', nf_double, 2,
5789 & (/ vmec_boundary_n_dim_id,
5790 & vmec_boundary_m_dim_id /), vmec_zbc_id)
5791 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5793 status = nf_def_var(result_ncid,
'vmec_zbs', nf_double, 2,
5794 & (/ vmec_boundary_n_dim_id,
5795 & vmec_boundary_m_dim_id /), vmec_zbs_id)
5796 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5798 status = nf_def_var(result_ncid,
'vmec_l_sub_i', nf_double, 1,
5799 & (/ maxnsetps_dim_id /), vmec_l_sub_i_id)
5800 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5802 status = nf_def_var(result_ncid,
'vmec_kappa_p', nf_double, 1,
5803 & (/ maxnsetps_dim_id /), vmec_kappa_p_id)
5804 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5806 CALL profiler_set_stop_time(
'vmec_def_result', start_time)
5819 USE mgrid_mod,
only: nextcur
5820 USE vmec_input,
only: extcur, curtor, pres_scale, ntor, &
5821 & rbc, zbs, rbs, zbc
5822 USE vmec_dim,
only: mpol1
5828 TYPE (vmec_class),
INTENT(in) :: this
5829 INTEGER,
INTENT(in) :: result_ncid
5833 INTEGER,
DIMENSION(2) :: boundary_size
5834 INTEGER :: vmec_extcur_id
5835 INTEGER :: vmec_curtor_id
5836 INTEGER :: vmec_pres_scale_id
5837 INTEGER :: vmec_rbc_id
5838 INTEGER :: vmec_rbs_id
5839 INTEGER :: vmec_zbc_id
5840 INTEGER :: vmec_zbs_id
5841 REAL (rprec) :: start_time
5844 start_time = profiler_get_start_time()
5846 IF (nextcur .gt. 0)
THEN
5847 status = nf_inq_varid(result_ncid,
'vmec_extcur',
5849 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5850 status = nf_put_var_double(result_ncid, vmec_extcur_id,
5851 & extcur(1:nextcur))
5852 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5855 status = nf_inq_varid(result_ncid,
'vmec_curtor', vmec_curtor_id)
5856 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5857 status = nf_put_var_double(result_ncid, vmec_curtor_id,
5859 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5861 status = nf_inq_varid(result_ncid,
'vmec_pres_scale',
5862 & vmec_pres_scale_id)
5863 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5864 status = nf_put_var_double(result_ncid, vmec_pres_scale_id,
5866 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5868 boundary_size(1) = 2*ntor + 1
5869 boundary_size(2) = mpol1 + 1
5871 status = nf_inq_varid(result_ncid,
'vmec_rbc', vmec_rbc_id)
5872 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5873 status = nf_put_vara_double(result_ncid, vmec_rbc_id,
5874 & (/ 1, 1 /), boundary_size,
5875 & rbc(-ntor:ntor,0:mpol1))
5876 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5878 status = nf_inq_varid(result_ncid,
'vmec_rbs', vmec_rbs_id)
5879 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5880 status = nf_put_vara_double(result_ncid, vmec_rbs_id,
5881 & (/ 1, 1 /), boundary_size,
5882 & rbs(-ntor:ntor,0:mpol1))
5883 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5885 status = nf_inq_varid(result_ncid,
'vmec_zbc', vmec_zbc_id)
5886 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5887 status = nf_put_vara_double(result_ncid, vmec_zbc_id,
5888 & (/ 1, 1 /), boundary_size,
5889 & zbc(-ntor:ntor,0:mpol1))
5890 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5892 status = nf_inq_varid(result_ncid,
'vmec_zbs', vmec_zbs_id)
5893 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5894 status = nf_put_vara_double(result_ncid, vmec_zbs_id,
5895 & (/ 1, 1 /), boundary_size,
5896 & zbs(-ntor:ntor,0:mpol1))
5897 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5901 CALL profiler_set_stop_time(
'vmec_write_init_data', start_time)
5917 USE xstuff,
only: xc
5922 TYPE (vmec_class),
INTENT(in) :: this
5923 INTEGER,
INTENT(in) :: result_ncid
5924 INTEGER,
INTENT(in) :: current_step
5928 INTEGER :: vmec_l_sub_i_id
5929 INTEGER :: vmec_kappa_p_id
5930 INTEGER :: vmec_xc_id
5931 REAL (rprec) :: start_time
5934 start_time = profiler_get_start_time()
5936 status = nf_inq_varid(result_ncid,
'vmec_xc', vmec_xc_id)
5937 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5938 status = nf_put_vara_double(result_ncid, vmec_xc_id,
5939 & (/ 1 /), (/
SIZE(xc) /), xc)
5940 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5942 status = nf_inq_varid(result_ncid,
'vmec_l_sub_i',
5944 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5945 status = nf_put_var1_double(result_ncid, vmec_l_sub_i_id,
5946 & current_step, vvc_smaleli)
5947 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5949 status = nf_inq_varid(result_ncid,
'vmec_kappa_p',
5951 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5952 status = nf_put_var1_double(result_ncid, vmec_kappa_p_id,
5953 & current_step, vvc_kappa_p)
5954 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5956 CALL profiler_set_stop_time(
'vmec_write_step_data', start_time)
5969 SUBROUTINE vmec_restart(this, result_ncid, current_step)
5972 USE xstuff,
only: xc
5977 TYPE (vmec_class),
INTENT(in) :: this
5978 INTEGER,
INTENT(in) :: result_ncid
5979 INTEGER,
INTENT(in) :: current_step
5983 INTEGER :: vmec_l_sub_i_id
5984 INTEGER :: vmec_kappa_p_id
5985 INTEGER :: vmec_xc_id
5986 REAL (rprec) :: start_time
5989 start_time = profiler_get_start_time()
5991 status = nf_inq_varid(result_ncid,
'vmec_xc', vmec_xc_id)
5992 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5993 status = nf_get_vara_double(result_ncid, vmec_xc_id,
5994 & (/ 1 /), (/
SIZE(xc) /), xc)
5995 CALL assert_eq(status, nf_noerr, nf_strerror(status))
5997 status = nf_inq_varid(result_ncid,
'vmec_l_sub_i',
5999 CALL assert_eq(status, nf_noerr, nf_strerror(status))
6000 status = nf_get_var1_double(result_ncid, vmec_l_sub_i_id,
6001 & current_step, vvc_smaleli)
6002 CALL assert_eq(status, nf_noerr, nf_strerror(status))
6004 status = nf_inq_varid(result_ncid,
'vmec_kappa_p',
6006 CALL assert_eq(status, nf_noerr, nf_strerror(status))
6007 status = nf_get_var1_double(result_ncid, vmec_kappa_p_id,
6008 & current_step, vvc_kappa_p)
6009 CALL assert_eq(status, nf_noerr, nf_strerror(status))
6011 CALL profiler_set_stop_time(
'vmec_restart', start_time)
6028 USE read_wout_mod,
only: read_wout_file, loadrzl
6034 TYPE (vmec_class),
INTENT(inout) :: this
6035 INTEGER,
INTENT(in) :: recon_comm
6037 #if defined(MPI_OPT)
6044 CALL mpi_comm_rank(recon_comm, mpi_rank, error)
6049 CALL mpi_barrier(recon_comm, error)
6052 IF (mpi_rank .gt. 0)
THEN
6054 & trim(this%wout_file_name), error)
6056 CALL read_wout_file(this%wout_file_name, error)
6057 CALL assert_eq(error, 0,
'Error reading synced wout file.')
6060 IF (
ASSOCIATED(this%magnetic_cache))
THEN
6081 USE read_wout_mod,
only: read_wout_file, loadrzl
6087 TYPE (vmec_class),
INTENT(inout) :: this
6088 INTEGER,
INTENT(in) :: index
6089 INTEGER,
INTENT(in) :: recon_comm
6091 #if defined(MPI_OPT)
6097 CALL mpi_comm_rank(recon_comm, mpi_rank, error)
6100 IF (mpi_rank .eq. 0)
THEN
6102 & this%wout_file_name),
6103 & trim(this%wout_file_name), error)
6105 CALL read_wout_file(this%wout_file_name, error)
6106 CALL assert_eq(error, 0,
'Error reading synced wout file.')
6109 IF (
ASSOCIATED(this%magnetic_cache))
THEN
6132 USE vmec_input,
only: lasym, rbc, zbs, rbs, zbc, ntor, &
6133 & mfilter_fbdy, nfilter_fbdy, lfreeb
6134 USE vmec_dim,
only: mpol1, ntor1
6135 USE vmec_main,
only: rmn_bdy, zmn_bdy, lthreed, lconm1
6136 USE vmec_params,
only: rcc, rss, rsc, rcs, &
6137 & zsc, zcs, zcc, zss, signgs
6138 USE vparams,
only: cp5
6143 TYPE (vmec_class),
INTENT(in) :: this
6146 REAL (rprec) :: delta, sgn
6147 INTEGER :: m, n, mj, ni
6148 REAL (rprec) :: temp
6149 REAL (rprec),
DIMENSION(:,:),
POINTER :: rbcc, rbss, rbcs, rbsc
6150 REAL (rprec),
DIMENSION(:,:),
POINTER :: zbcc, zbss, zbcs, zbsc
6151 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: temp_array
6152 REAL (rprec) :: start_time
6155 start_time = profiler_get_start_time()
6159 delta = atan((rbs(0,1) - zbc(0,1))/
6160 & (abs(rbc(0,1) + abs(zbs(0,1)))))
6161 IF (delta .ne. 0.0)
THEN
6164 temp = rbc(n,m)*cos(m*delta) + rbs(n,m)*sin(m*delta)
6165 rbs(n,m) = rbs(n,m)*cos(m*delta)
6166 & - rbc(n,m)*sin(m*delta)
6168 temp = zbc(n,m)*cos(m*delta) + zbs(n,m)*sin(m*delta)
6169 zbs(n,m) = zbs(n,m)*cos(m*delta)
6170 & - zbc(n,m)*sin(m*delta)
6184 rbcc => rmn_bdy(:,:,rcc)
6185 zbsc => zmn_bdy(:,:,zsc)
6187 rbss => rmn_bdy(:,:,rss)
6188 zbcs => zmn_bdy(:,:,zcs)
6192 rbsc => rmn_bdy(:,:,rsc)
6193 zbcc => zmn_bdy(:,:,zcc)
6195 rbcs => rmn_bdy(:,:,rcs)
6196 zbss => zmn_bdy(:,:,zss)
6203 IF (.not.lfreeb)
THEN
6205 IF ((mfilter_fbdy .gt. 1) .and. (m .gt. mfilter_fbdy))
THEN
6209 mj = m + lbound(rbcc, 2)
6211 IF ((nfilter_fbdy .gt. 0) .and.
6212 & (abs(n) .gt. nfilter_fbdy))
THEN
6216 ni = abs(n) + lbound(rbcc, 1)
6220 ELSE IF (n .gt. 0)
THEN
6226 rbcc(ni,mj) = rbcc(ni,mj) + rbc(n,m)
6228 zbsc(ni,mj) = zbsc(ni,mj) + zbs(n,m)
6232 zbcs(ni,mj) = zbcs(ni,mj) - sgn*zbs(n,m)
6234 rbss(ni,mj) = rbss(ni,mj) + sgn*rbc(n,m)
6239 zbcc(ni,mj) = zbcc(ni,mj) + zbc(n,m)
6241 rbsc(ni,mj) = rbsc(ni,mj) + rbs(n,m)
6245 rbcs(ni,mj) = rbcs(ni,mj) - sgn*rbs(n,m)
6247 zbss(ni,mj) = zbss(ni,mj) + sgn*zbc(n,m)
6256 mj = 1 + lbound(rbcc, 2)
6258 IF (sum(rbcc(1:ntor1,mj))*sum(zbsc(1:ntor1,mj)) .gt. 0.0)
THEN
6263 IF (lconm1 .and. (lthreed .or. lasym))
THEN
6264 ALLOCATE(temp_array(
SIZE(rbcc, 1)))
6266 temp_array = rbss(:,mj)
6267 rbss(:,mj) = cp5*(temp_array + zbcs(:,mj))
6268 zbcs(:,mj) = cp5*(temp_array - zbcs(:,mj))
6272 temp_array = rbsc(:,mj)
6273 rbsc(:,mj) = cp5*(temp_array + zbcc(:,mj))
6274 zbcc(:,mj) = cp5*(temp_array - zbcc(:,mj))
6276 DEALLOCATE(temp_array)
6279 CALL profiler_set_stop_time(
'vmec_reset_boundary', start_time)