165 REAL (rprec) :: du_full
167 REAL (rprec) :: dv_full
170 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: rsuv => null()
172 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: zsuv => null()
175 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: jrsuv => null()
177 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: jphisuv => null()
179 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: jzsuv => null()
183 REAL (rprec),
DIMENSION(:,:),
POINTER :: kruv => null()
186 REAL (rprec),
DIMENSION(:,:),
POINTER :: kphiuv => null()
189 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv => null()
192 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: x_prime => null()
195 REAL (rprec),
DIMENSION(:,:),
POINTER :: kxuv_full => null()
198 REAL (rprec),
DIMENSION(:,:),
POINTER :: kyuv_full => null()
201 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv_full => null()
204 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: x_axi => null()
207 REAL (rprec),
DIMENSION(:,:),
POINTER :: kxuv_axi => null()
210 REAL (rprec),
DIMENSION(:,:),
POINTER :: kyuv_axi => null()
213 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv_axi => null()
223 CHARACTER (len=path_length) :: restart_file_name
225 CHARACTER (len=path_length) :: siesta_file_name
228 TYPE (pprofile_class),
POINTER :: ne => null()
231 TYPE (pprofile_class),
POINTER :: te => null()
234 TYPE (pprofile_class),
POINTER :: ti => null()
237 TYPE (pprofile_pointer),
DIMENSION(:),
POINTER ::
241 REAL (rprec) :: pol_rad_ratio
251 REAL (rprec) :: phi_offset = 0
253 REAL (rprec) :: z_offset = 0
386 & ne, te, ti, sxrem, phi_offset, z_offset, &
387 & pol_rad_ratio, iou, eq_comm, recon_comm, &
397 CHARACTER (len=*),
INTENT(in) :: file_name
398 CHARACTER (len=*),
INTENT(in) :: restart_file_name
399 TYPE (pprofile_class),
POINTER :: ne
400 TYPE (pprofile_class),
POINTER :: te
401 TYPE (pprofile_class),
POINTER :: ti
402 TYPE (pprofile_pointer),
DIMENSION(:),
POINTER ::
sxrem
403 REAL (rprec),
INTENT(in) :: phi_offset
404 REAL (rprec),
INTENT(in) :: z_offset
405 REAL (rprec),
INTENT(in) :: pol_rad_ratio
406 INTEGER,
INTENT(in) :: iou
407 INTEGER,
INTENT(in) :: eq_comm
408 INTEGER,
INTENT(in) :: recon_comm
410 INTEGER,
INTENT(inout) :: state_flags
414 INTEGER :: recon_rank
415 INTEGER :: recon_size
418 REAL (rprec) :: start_time
421 start_time = profiler_get_start_time()
429 CALL mpi_comm_rank(eq_comm, eq_rank, error)
431 IF (eq_rank .eq. 0)
THEN
432 CALL mpi_comm_rank(recon_comm, recon_rank, error)
433 CALL mpi_comm_size(recon_comm, recon_size, error)
435 CALL mpi_bcast(recon_rank, 1, mpi_integer, 0, eq_comm, error)
440 IF (eq_rank .eq. 0)
THEN
442 CALL copy_file(trim(file_name), trim(file_name) //
'_save',
445 WRITE (*,*)
' *** Initializing SIESTA equilibrium from ' //
446 &
'file ' // trim(file_name)
447 WRITE (iou,*)
' *** Initializing SIESTA equilibrium from ' //
448 &
'file ' // trim(file_name)
462 CALL safe_open(iou_nli, error, trim(file_name),
'old',
464 READ (iou_nli, nml=siesta_info)
465 CLOSE (iou_nli, iostat=error)
466 wout_file = vmec%wout_file_name
472 IF (restart_file_name .ne.
'')
THEN
479 CALL profiler_set_stop_time(
'siesta_construct', start_time)
481 1000
FORMAT(
'siesta_',a,
'.nc')
496 USE read_wout_mod,
only: read_wout_deallocate
502 TYPE (siesta_class),
POINTER :: this
508 IF (
ASSOCIATED(this%ne))
THEN
509 CALL pprofile_destruct(this%ne)
513 IF (
ASSOCIATED(this%te))
THEN
514 CALL pprofile_destruct(this%te)
518 IF (
ASSOCIATED(this%ti))
THEN
519 CALL pprofile_destruct(this%ti)
523 IF (
ASSOCIATED(this%sxrem))
THEN
524 DO i = 1,
SIZE(this%sxrem)
525 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
526 CALL pprofile_destruct(this%sxrem(i)%p)
527 this%sxrem(i)%p => null()
530 DEALLOCATE(this%sxrem)
534 IF (
ASSOCIATED(this%magnetic_cache))
THEN
535 IF (
ASSOCIATED(this%magnetic_cache%rsuv))
THEN
536 DEALLOCATE(this%magnetic_cache%rsuv)
537 this%magnetic_cache%rsuv => null()
540 IF (
ASSOCIATED(this%magnetic_cache%zsuv))
THEN
541 DEALLOCATE(this%magnetic_cache%zsuv)
542 this%magnetic_cache%zsuv => null()
545 IF (
ASSOCIATED(this%magnetic_cache%jrsuv))
THEN
546 DEALLOCATE(this%magnetic_cache%jrsuv)
547 this%magnetic_cache%jrsuv => null()
550 IF (
ASSOCIATED(this%magnetic_cache%jphisuv))
THEN
551 DEALLOCATE(this%magnetic_cache%jphisuv)
552 this%magnetic_cache%jphisuv => null()
555 IF (
ASSOCIATED(this%magnetic_cache%jzsuv))
THEN
556 DEALLOCATE(this%magnetic_cache%jzsuv)
557 this%magnetic_cache%jzsuv => null()
560 IF (
ASSOCIATED(this%magnetic_cache%kruv))
THEN
561 DEALLOCATE(this%magnetic_cache%kruv)
562 this%magnetic_cache%kruv => null()
565 IF (
ASSOCIATED(this%magnetic_cache%kphiuv))
THEN
566 DEALLOCATE(this%magnetic_cache%kphiuv)
567 this%magnetic_cache%kphiuv => null()
570 IF (
ASSOCIATED(this%magnetic_cache%kzuv))
THEN
571 DEALLOCATE(this%magnetic_cache%kzuv)
572 this%magnetic_cache%kzuv => null()
575 IF (
ASSOCIATED(this%magnetic_cache%x_prime))
THEN
576 DEALLOCATE(this%magnetic_cache%x_prime)
577 this%magnetic_cache%x_prime => null()
580 IF (
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
581 DEALLOCATE(this%magnetic_cache%kxuv_full)
582 this%magnetic_cache%kxuv_full => null()
585 IF (
ASSOCIATED(this%magnetic_cache%kyuv_full))
THEN
586 DEALLOCATE(this%magnetic_cache%kyuv_full)
587 this%magnetic_cache%kyuv_full => null()
590 IF (
ASSOCIATED(this%magnetic_cache%kzuv_full))
THEN
591 DEALLOCATE(this%magnetic_cache%kzuv_full)
592 this%magnetic_cache%kzuv_full => null()
595 IF (
ASSOCIATED(this%magnetic_cache%x_axi))
THEN
596 DEALLOCATE(this%magnetic_cache%x_axi)
597 this%magnetic_cache%x_axi => null()
600 IF (
ASSOCIATED(this%magnetic_cache%kxuv_axi))
THEN
601 DEALLOCATE(this%magnetic_cache%kxuv_axi)
602 this%magnetic_cache%kxuv_axi => null()
605 IF (
ASSOCIATED(this%magnetic_cache%kyuv_axi))
THEN
606 DEALLOCATE(this%magnetic_cache%kyuv_axi)
607 this%magnetic_cache%kyuv_axi => null()
610 IF (
ASSOCIATED(this%magnetic_cache%kzuv_axi))
THEN
611 DEALLOCATE(this%magnetic_cache%kzuv_axi)
612 this%magnetic_cache%kzuv_axi => null()
615 DEALLOCATE(this%magnetic_cache)
616 this%magnetic_cache => null()
620 CALL delete_file(trim(this%restart_file_name) //
'_cache', error)
622 IF (
ASSOCIATED(this%context))
THEN
624 this%context => null()
627 IF (
ASSOCIATED(this%vmec))
THEN
657 & eq_comm, state_flags)
663 TYPE (siesta_class),
INTENT(inout) :: this
664 INTEGER,
INTENT(in) :: id
665 INTEGER,
INTENT(in) :: i_index
666 INTEGER,
INTENT(in) :: j_index
667 REAL (rprec),
INTENT(in) :: value
668 INTEGER,
INTENT(in) :: eq_comm
669 INTEGER,
INTENT(inout) :: state_flags
673 REAL (rprec) :: start_time
676 start_time = profiler_get_start_time()
682 this%ne%b(i_index) =
value
686 this%ne%as(i_index) =
value
690 this%ne%af(i_index) =
value
694 this%te%b(i_index) =
value
698 this%te%as(i_index) =
value
702 this%te%af(i_index) =
value
706 this%ti%b(i_index) =
value
710 this%ti%as(i_index) =
value
714 this%ti%af(i_index) =
value
721 this%sxrem(i_index)%p%b(j_index) =
value
726 this%sxrem(i_index)%p%as(j_index) =
value
731 this%sxrem(i_index)%p%af(j_index) =
value
739 this%phi_offset =
value
740 IF (
ASSOCIATED(this%magnetic_cache))
THEN
746 this%z_offset =
value
747 IF (
ASSOCIATED(this%magnetic_cache))
THEN
753 helpert(i_index) =
value
757 & eq_comm, state_flags)
761 CALL profiler_set_stop_time(
'siesta_set_param', start_time)
778 USE stel_constants,
only: twopi
784 TYPE (siesta_class),
INTENT(inout) :: this
785 TYPE (magnetic_response_class),
INTENT(in) :: response_object
791 REAL (rprec) :: start_time
794 start_time = profiler_get_start_time()
796 IF (.not.
ASSOCIATED(this%magnetic_cache))
THEN
797 ALLOCATE(this%magnetic_cache)
803 IF (
ASSOCIATED(this%context))
THEN
805 mpol = this%context%mpol
810 numu = max(int(this%pol_rad_ratio*ns), 2*mpol)
813 this%magnetic_cache%ds = 1.0/(ns - 1.0)
814 this%magnetic_cache%du = twopi/numu
815 this%magnetic_cache%dv = twopi/response_object%n_field_periods
816 & / response_object%num_t
820 ALLOCATE(this%magnetic_cache%rsuv(ns,numu,
821 &
SIZE(response_object%a_r)))
822 ALLOCATE(this%magnetic_cache%zsuv(ns,numu,
823 &
SIZE(response_object%a_r)))
824 ALLOCATE(this%magnetic_cache%jrsuv(ns,numu,
825 &
SIZE(response_object%a_r)))
826 ALLOCATE(this%magnetic_cache%jphisuv(ns,numu,
827 &
SIZE(response_object%a_r)))
828 ALLOCATE(this%magnetic_cache%jzsuv(ns,numu,
829 &
SIZE(response_object%a_r)))
835 this%magnetic_cache%du_a = twopi/compression_get_dimension1(
836 & response_object%a_s_r)
837 this%magnetic_cache%dv_a
838 & = (twopi/response_object%n_field_periods)
839 & / response_object%num_t_shell
841 ALLOCATE(this%magnetic_cache%kruv(
842 & compression_get_dimension1(response_object%a_s_r),
843 & compression_get_dimension2(response_object%a_s_r)))
844 ALLOCATE(this%magnetic_cache%kphiuv(
845 & compression_get_dimension1(response_object%a_s_r),
846 & compression_get_dimension2(response_object%a_s_r)))
847 ALLOCATE(this%magnetic_cache%kzuv(
848 & compression_get_dimension1(response_object%a_s_r),
849 & compression_get_dimension2(response_object%a_s_r)))
852 CALL profiler_set_stop_time(
'siesta_set_magnetic_cache_responce',
872 TYPE (siesta_class),
INTENT(inout) :: this
873 LOGICAL,
INTENT(in) :: use_axi
876 INTEGER :: u_size, v_size
877 REAL (rprec) :: rbc00, rbc01, zbs01
878 REAL (rprec) :: start_time
881 start_time = profiler_get_start_time()
883 IF (.not.
ASSOCIATED(this%magnetic_cache))
THEN
884 ALLOCATE(this%magnetic_cache)
894 IF (mod(v_size, 2) .eq. 0)
THEN
897 this%magnetic_cache%dv_full = twopi/v_size
899 u_size = max(int(twopi*max(rbc01, zbs01)/
902 IF (mod(u_size, 2) .eq. 0)
THEN
905 this%magnetic_cache%du_full = twopi/u_size
907 ALLOCATE(this%magnetic_cache%kxuv_full(u_size,v_size))
908 ALLOCATE(this%magnetic_cache%kyuv_full(u_size,v_size))
909 ALLOCATE(this%magnetic_cache%kzuv_full(u_size,v_size))
911 ALLOCATE(this%magnetic_cache%x_prime(u_size,v_size,3))
914 ALLOCATE(this%magnetic_cache%kxuv_axi(u_size,v_size))
915 ALLOCATE(this%magnetic_cache%kyuv_axi(u_size,v_size))
916 ALLOCATE(this%magnetic_cache%kzuv_axi(u_size,v_size))
918 ALLOCATE(this%magnetic_cache%x_axi(u_size,v_size,3))
922 CALL profiler_set_stop_time(
'siesta_set_magnetic_cache_point',
936 USE stel_constants,
only: mu0
937 USE read_wout_mod,
only: nfp, mnmax, xm, xn, rmnc, rmns, zmnc, &
938 & zmns, lasym, nsvmec => ns
943 TYPE (siesta_class),
INTENT(inout) :: this
947 REAL (rprec) :: s, u, v
948 INTEGER :: numS, numU, numV
950 INTEGER :: mpol, ntor
951 REAL (rprec) :: r, rs, ru, rv
952 REAL (rprec) :: z, zs, zu, zv
953 REAL (rprec) :: js, ju, jv
954 REAL (rprec) :: bs, bu, bv
955 REAL (rprec) :: kr, kp
956 REAL (rprec) :: theta, phi
957 REAL (rprec),
DIMENSION(:,:),
ALLOCATABLE :: bsubuc, bsubus
958 REAL (rprec),
DIMENSION(:,:),
ALLOCATABLE :: bsubvc, bsubvs
959 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: rmncint, rmnsint
960 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: zmncint, zmnsint
961 REAL (rprec) :: cosphi
962 REAL (rprec) :: sinphi
963 REAL (rprec),
DIMENSION(:,:),
ALLOCATABLE :: cosmn
964 REAL (rprec),
DIMENSION(:,:),
ALLOCATABLE :: sinmn
965 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosmn_vmec
966 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: sinmn_vmec
967 REAL (rprec) :: wlow, whigh
968 INTEGER :: ilow, ihigh
969 REAL (rprec) :: start_time
972 start_time = profiler_get_start_time()
974 IF (
ASSOCIATED(this%magnetic_cache%rsuv))
THEN
976 nums =
SIZE(this%magnetic_cache%rsuv, 1)
977 numu =
SIZE(this%magnetic_cache%rsuv, 2)
978 numv =
SIZE(this%magnetic_cache%rsuv, 3)
980 IF (
ASSOCIATED(this%context))
THEN
981 mpol = this%context%mpol
982 ntor = this%context%ntor
994 ALLOCATE(cosmn(0:mpol,-ntor:ntor))
995 ALLOCATE(sinmn(0:mpol,-ntor:ntor))
997 ALLOCATE(cosmn_vmec(mnmax))
998 ALLOCATE(sinmn_vmec(mnmax))
1000 ALLOCATE(rmncint(mnmax))
1001 ALLOCATE(zmnsint(mnmax))
1003 ALLOCATE(rmnsint(mnmax))
1004 ALLOCATE(zmncint(mnmax))
1022 v = (k - 1)*this%magnetic_cache%dv + this%phi_offset
1025 u = (j - 1)*this%magnetic_cache%du
1027 cosmn_vmec = cos(xm*u - xn*v)
1028 sinmn_vmec = sin(xm*u - xn*v)
1032 cosmn(m,n) = cos(m*u + nfp*n*v)
1033 sinmn(m,n) = sin(m*u + nfp*n*v)
1038 s = (i - 1.0)/(nums - 1.0)
1040 IF (ilow .eq. nsvmec)
THEN
1047 rmncint = wlow*rmnc(:,ilow) + whigh*rmnc(:,ihigh)
1048 zmnsint = wlow*zmns(:,ilow) + whigh*zmns(:,ihigh)
1050 this%magnetic_cache%rsuv(i,j,k) =
1051 & sum(rmncint*cosmn_vmec)
1052 this%magnetic_cache%zsuv(i,j,k) =
1053 & sum(zmnsint*sinmn_vmec)
1055 ru = -sum(xm*rmncint*sinmn_vmec)
1056 rv = sum(xn*rmncint*sinmn_vmec)
1057 zu = sum(xm*zmnsint*cosmn_vmec)
1058 zv = -sum(xn*zmnsint*cosmn_vmec)
1061 rmncint = 2.0*s*(rmnc(:,ihigh) - rmnc(:,ilow))
1064 zmnsint = 2.0*s*(zmns(:,ihigh) - zmns(:,ilow))
1067 rs = sum(rmncint*cosmn_vmec)
1068 zs = sum(zmnsint*sinmn_vmec)
1070 js = sum(this%context%jksupsmnsf(:,:,i)*sinmn)
1071 ju = sum(this%context%jksupumncf(:,:,i)*cosmn)
1072 jv = sum(this%context%jksupvmncf(:,:,i)*cosmn)
1075 IF (this%context%l_asym)
THEN
1078 rmnsint = wlow*rmns(:,ilow)
1079 & + whigh*rmns(:,ihigh)
1080 zmncint = wlow*zmnc(:,ilow)
1081 & + whigh*zmnc(:,ihigh)
1083 this%magnetic_cache%rsuv(i,j,k) =
1084 & this%magnetic_cache%rsuv(i,j,k) +
1085 & sum(rmnsint*sinmn_vmec)
1086 this%magnetic_cache%zsuv(i,j,k) =
1087 & this%magnetic_cache%zsuv(i,j,k) +
1088 & sum(zmncint*cosmn_vmec)
1090 ru = ru + sum(xm*rmnsint*cosmn_vmec)
1091 rv = rv - sum(xn*rmnsint*cosmn_vmec)
1092 zu = zu - sum(xm*zmncint*sinmn_vmec)
1093 zv = zv + sum(xn*zmncint*sinmn_vmec)
1096 rmnsint = 2.0*s*(rmns(:,ihigh) - rmns(:,ilow))
1099 zmncint = 2.0*s*(zmnc(:,ihigh) - zmnc(:,ilow))
1102 rs = rs + sum(rmnsint*sinmn_vmec)
1103 zs = zs + sum(zmncint*cosmn_vmec)
1107 js = js + sum(this%context%jksupsmncf(:,:,i)*cosmn)
1108 ju = ju + sum(this%context%jksupumnsf(:,:,i)*sinmn)
1109 jv = jv + sum(this%context%jksupvmnsf(:,:,i)*sinmn)
1113 js = js/(this%context%b_factor*mu0)
1114 ju = ju/(this%context%b_factor*mu0)
1115 jv = jv/(this%context%b_factor*mu0)
1117 this%magnetic_cache%jrsuv(i,j,k) =
1118 & (js*rs + ju*ru + jv*rv)
1119 this%magnetic_cache%jphisuv(i,j,k) =
1120 & jv*this%magnetic_cache%rsuv(i,j,k)
1121 this%magnetic_cache%jzsuv(i,j,k) =
1122 & js*zs + ju*zu + jv*zv
1131 DEALLOCATE(cosmn_vmec)
1132 DEALLOCATE(sinmn_vmec)
1143 this%magnetic_cache%zsuv = this%magnetic_cache%zsuv
1203 IF (
ASSOCIATED(this%magnetic_cache%kruv) .or.
1204 &
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
1206 ALLOCATE(bsubuc(0:mpol,-ntor:ntor))
1207 ALLOCATE(bsubvc(0:mpol,-ntor:ntor))
1209 nums =
SIZE(this%context%bsubumnch, 3)
1212 bsubuc = 1.5*this%context%bsubumnch(:,:,nums)
1213 & - 0.5*this%context%bsubumnch(:,:,nums - 1)
1214 bsubvc = 1.5*this%context%bsubvmnch(:,:,nums)
1215 & - 0.5*this%context%bsubvmnch(:,:,nums - 1)
1217 IF (this%context%l_asym)
THEN
1218 ALLOCATE(bsubus(0:mpol,-ntor:ntor))
1219 ALLOCATE(bsubvs(0:mpol,-ntor:ntor))
1221 bsubus = 1.5*this%context%bsubumnsh(:,:,nums)
1222 & - 0.5*this%context%bsubumnsh(:,:,nums - 1)
1223 bsubvs = 1.5*this%context%bsubvmnsh(:,:,nums)
1224 & - 0.5*this%context%bsubvmnsh(:,:,nums - 1)
1228 IF (
ASSOCIATED(this%magnetic_cache%kruv))
THEN
1229 numu =
SIZE(this%magnetic_cache%kruv, 1)
1230 numv =
SIZE(this%magnetic_cache%kruv, 2)
1238 ALLOCATE(cosmn(0:mpol,-ntor:ntor))
1239 IF (this%context%l_asym)
THEN
1240 ALLOCATE(sinmn(0:mpol,-ntor:ntor))
1243 ALLOCATE(cosmn_vmec(mnmax))
1244 ALLOCATE(sinmn_vmec(mnmax))
1249 v = (k - 1)*this%magnetic_cache%dv_a + this%phi_offset
1252 u = (j - 1)*this%magnetic_cache%du_a
1254 cosmn_vmec = cos(xm*u - xn*v)
1255 sinmn_vmec = sin(xm*u - xn*v)
1259 cosmn(m,n) = cos(m*u + nfp*n*v)
1263 r = sum(rmncint*cosmn_vmec)
1264 ru = -sum(xm*rmnc(:,nsvmec)*sinmn_vmec)
1265 rv = sum(xn*rmnc(:,nsvmec)*sinmn_vmec)
1266 zu = sum(xm*zmns(:,nsvmec)*cosmn_vmec)
1267 zv = -sum(xn*zmns(:,nsvmec)*cosmn_vmec)
1269 bu = sum(bsubuc*cosmn)
1270 bv = sum(bsubvc*cosmn)
1272 IF (this%context%l_asym)
THEN
1274 r = r + sum(rmnsint*sinmn_vmec)
1275 ru = ru + sum(xm*rmns(:,nsvmec)*cosmn_vmec)
1276 rv = rv - sum(xn*rmns(:,nsvmec)*cosmn_vmec)
1277 zu = zu - sum(xm*zmnc(:,nsvmec)*sinmn_vmec)
1278 zv = zv + sum(xn*zmnc(:,nsvmec)*sinmn_vmec)
1283 sinmn(m,n) = sin(m*u + nfp*n*v)
1287 bu = bu + sum(bsubus*sinmn)
1288 bv = bv + sum(bsubvs*sinmn)
1292 bu = bu/this%context%b_factor
1293 bv = bv/this%context%b_factor
1295 this%magnetic_cache%kruv(j,k) = -(bu*rv - bv*ru)/mu0
1296 this%magnetic_cache%kphiuv(j,k) = -bu*r/mu0
1297 this%magnetic_cache%kzuv(j,k) = -(bu*zv - bv*zu)/mu0
1304 IF (this%context%l_asym)
THEN
1308 DEALLOCATE(cosmn_vmec)
1309 DEALLOCATE(sinmn_vmec)
1314 IF (
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
1315 numu =
SIZE(this%magnetic_cache%kxuv_full, 1)
1316 numv =
SIZE(this%magnetic_cache%kxuv_full, 2)
1322 ALLOCATE(cosmn(0:mpol,-ntor:ntor))
1323 IF (this%context%l_asym)
THEN
1324 ALLOCATE(sinmn(0:mpol,-ntor:ntor))
1327 ALLOCATE(cosmn_vmec(mnmax))
1328 ALLOCATE(sinmn_vmec(mnmax))
1335 v = (k - 1)*this%magnetic_cache%dv_full
1341 u = (j - 1)*this%magnetic_cache%du_full
1343 cosmn_vmec = cos(xm*u - xn*v)
1344 sinmn_vmec = sin(xm*u - xn*v)
1348 cosmn(m,n) = cos(m*u + nfp*n*v)
1352 r = sum(rmnc(:,nsvmec)*cosmn_vmec)
1353 z = sum(zmns(:,nsvmec)*sinmn_vmec)
1355 ru = -sum(xm*rmnc(:,nsvmec)*sinmn_vmec)
1356 rv = sum(xn*rmnc(:,nsvmec)*sinmn_vmec)
1357 zu = sum(xm*zmns(:,nsvmec)*cosmn_vmec)
1358 zv = -sum(xn*zmns(:,nsvmec)*cosmn_vmec)
1360 bu = sum(bsubuc*cosmn)
1361 bv = sum(bsubvc*cosmn)
1363 IF (this%context%l_asym)
THEN
1367 sinmn(m,n) = sin(m*u + nfp*n*v)
1372 r = r + sum(rmns(:,nsvmec)*sinmn_vmec)
1373 z = z + sum(zmnc(:,nsvmec)*cosmn_vmec)
1375 ru = ru + sum(xm*rmns(:,nsvmec)*cosmn_vmec)
1376 rv = rv - sum(xn*rmns(:,nsvmec)*cosmn_vmec)
1377 zu = zu - sum(xm*zmnc(:,nsvmec)*sinmn_vmec)
1378 zv = zv + sum(xn*zmnc(:,nsvmec)*sinmn_vmec)
1381 bu = bu + sum(bsubus*sinmn)
1382 bv = bv + sum(bsubvs*sinmn)
1385 bu = bu/this%context%b_factor
1386 bv = bv/this%context%b_factor
1388 kr = -(bu*rv - bv*ru)/mu0
1391 this%magnetic_cache%kxuv_full(j,k) = kr*cosphi
1393 this%magnetic_cache%kyuv_full(j,k) = kr*sinphi
1395 this%magnetic_cache%kzuv_full(j,k) = -(bu*zv - bv*zu)/mu0
1397 this%magnetic_cache%x_prime(j,k,1) = r*cosphi
1398 this%magnetic_cache%x_prime(j,k,2) = r*sinphi
1399 this%magnetic_cache%x_prime(j,k,3) = z
1401 IF (
ASSOCIATED(this%magnetic_cache%kxuv_axi))
THEN
1411 IF (xn(i) .eq. 0.0)
THEN
1412 r = r + rmnc(i,nsvmec)*cosmn_vmec(i)
1413 z = z + zmns(i,nsvmec)*sinmn_vmec(i)
1414 ru = ru - xm(i)*rmnc(i,nsvmec)*sinmn_vmec(i)
1415 zu = zu + xm(i)*zmns(i,nsvmec)*cosmn_vmec(i)
1419 bu = sum(bsubuc(:,0)*cosmn(:,0))
1420 bv = sum(bsubvc(:,0)*cosmn(:,0))
1422 IF (this%context%l_asym)
THEN
1425 IF (xn(i) .eq. 0.0)
THEN
1426 r = r + rmns(i,nsvmec)*sinmn_vmec(i)
1427 z = z + zmnc(i,nsvmec)*cosmn_vmec(i)
1428 ru = ru + xm(i)*rmns(i,nsvmec)*cosmn_vmec(i)
1429 zu = zu - xm(i)*zmnc(i,nsvmec)*sinmn_vmec(i)
1433 bu = bu + sum(bsubus(:,0)*sinmn(:,0))
1434 bv = bv + sum(bsubvs(:,0)*sinmn(:,0))
1438 bu = bu/this%context%b_factor
1439 bv = bv/this%context%b_factor
1444 this%magnetic_cache%kxuv_axi(j,k) = kr*cosphi
1446 this%magnetic_cache%kyuv_axi(j,k) = kr*sinphi
1448 this%magnetic_cache%kzuv_axi(j,k) = 1.0/mu0*bv*zu
1450 this%magnetic_cache%x_axi(j,k,1) = r*cosphi
1451 this%magnetic_cache%x_axi(j,k,2) = r*sinphi
1452 this%magnetic_cache%x_axi(j,k,3) = z
1460 IF (this%context%l_asym)
THEN
1464 DEALLOCATE(cosmn_vmec)
1465 DEALLOCATE(sinmn_vmec)
1470 IF (
ASSOCIATED(this%magnetic_cache%kruv) .or.
1471 &
ASSOCIATED(this%magnetic_cache%kxuv_full))
THEN
1475 IF (this%context%l_asym)
THEN
1481 CALL profiler_set_stop_time(
'siesta_set_magnetic_cache_calc',
1500 TYPE (siesta_class),
INTENT(in) :: this
1503 REAL (rprec) :: start_time
1506 start_time = profiler_get_start_time()
1510 CALL profiler_set_stop_time(
'siesta_set_namelist', start_time)
1533 CHARACTER (len=*),
INTENT(in) :: param_name
1536 REAL (rprec) :: start_time
1539 start_time = profiler_get_start_time()
1541 SELECT CASE (trim(param_name))
1552 CASE (
'pp_sxrem_b_a')
1555 CASE (
'pp_sxrem_as_a')
1558 CASE (
'pp_sxrem_af_a')
1594 CALL profiler_set_stop_time(
'siesta_get_param_id', start_time)
1616 INTEGER,
INTENT(in) :: id
1617 INTEGER,
INTENT(in) :: i_index
1618 INTEGER,
INTENT(in) :: j_index
1621 REAL (rprec) :: start_time
1624 start_time = profiler_get_start_time()
1679 CALL profiler_set_stop_time(
'siesta_get_param_value', start_time)
1699 INTEGER,
INTENT(in) :: id
1702 REAL (rprec) :: start_time
1705 start_time = profiler_get_start_time()
1760 CALL profiler_set_stop_time(
'siesta_get_param_name', start_time)
1783 REAL (rprec) :: start_time
1786 start_time = profiler_get_start_time()
1788 IF (
ASSOCIATED(this%ne))
THEN
1790 & pprofile_get_gp_num_hyper_param(this%ne)
1795 CALL profiler_set_stop_time(
'siesta_get_gp_ne_num_hyper_param',
1818 REAL (rprec) :: start_time
1821 start_time = profiler_get_start_time()
1823 IF (
ASSOCIATED(this%ne))
THEN
1849 INTEGER,
INTENT(in) :: i
1850 INTEGER,
INTENT(in) :: j
1853 REAL (rprec) :: start_time
1856 start_time = profiler_get_start_time()
1858 IF (
ASSOCIATED(this%ne))
THEN
1864 CALL profiler_set_stop_time(
'siesta_get_gp_ne_ij', start_time)
1886 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
1887 INTEGER,
INTENT(in) :: i
1890 REAL (rprec) :: start_time
1893 start_time = profiler_get_start_time()
1895 IF (
ASSOCIATED(this%ne))
THEN
1905 CALL profiler_set_stop_time(
'siesta_get_gp_ne_pi', start_time)
1928 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
1929 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
1932 REAL (rprec) :: start_time
1935 start_time = profiler_get_start_time()
1937 IF (
ASSOCIATED(this%ne))
THEN
1939 & pprofile_get_gp(this%ne,
siesta_get_p(this, x_cart, .true.),
1945 CALL profiler_set_stop_time(
'siesta_get_gp_ne_pp', start_time)
1967 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
1970 REAL (rprec) :: start_time
1973 start_time = profiler_get_start_time()
1976 & pprofile_get_value(this%ne,
siesta_get_p(this, x_cart, .true.))
1978 CALL profiler_set_stop_time(
'siesta_get_ne_cart', start_time)
2000 REAL (rprec),
INTENT(in) :: s
2003 REAL (rprec) :: start_time
2006 start_time = profiler_get_start_time()
2009 & pprofile_get_value(this%ne,
siesta_get_p(this, s, .true.))
2011 CALL profiler_set_stop_time(
'siesta_get_ne_radial', start_time)
2034 REAL (rprec) :: start_time
2037 start_time = profiler_get_start_time()
2039 IF (
ASSOCIATED(this%te))
THEN
2041 & pprofile_get_gp_num_hyper_param(this%te)
2046 CALL profiler_set_stop_time(
'siesta_get_gp_te_num_hyper_param',
2069 REAL (rprec) :: start_time
2072 start_time = profiler_get_start_time()
2074 IF (
ASSOCIATED(this%te))
THEN
2080 CALL profiler_set_stop_time(
'siesta_get_te_af', start_time)
2102 INTEGER,
INTENT(in) :: i
2103 INTEGER,
INTENT(in) :: j
2106 REAL (rprec) :: start_time
2109 start_time = profiler_get_start_time()
2111 IF (
ASSOCIATED(this%te))
THEN
2117 CALL profiler_set_stop_time(
'siesta_get_gp_te_ij', start_time)
2140 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2141 INTEGER,
INTENT(in) :: i
2144 REAL (rprec) :: start_time
2147 start_time = profiler_get_start_time()
2149 IF (
ASSOCIATED(this%te))
THEN
2159 CALL profiler_set_stop_time(
'siesta_get_gp_te_pi', start_time)
2184 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2185 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
2188 REAL (rprec) :: start_time
2191 start_time = profiler_get_start_time()
2193 IF (
ASSOCIATED(this%te))
THEN
2195 & pprofile_get_gp(this%te,
siesta_get_p(this, x_cart, .true.),
2201 CALL profiler_set_stop_time(
'siesta_get_gp_te_pp', start_time)
2223 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2226 REAL (rprec) :: start_time
2229 start_time = profiler_get_start_time()
2232 & pprofile_get_value(this%te,
siesta_get_p(this, x_cart, .true.))
2234 CALL profiler_set_stop_time(
'siesta_get_te_cart', start_time)
2256 REAL (rprec),
INTENT(in) :: s
2259 REAL (rprec) :: start_time
2262 start_time = profiler_get_start_time()
2265 & pprofile_get_value(this%te,
siesta_get_p(this, s, .true.))
2267 CALL profiler_set_stop_time(
'siesta_get_te_radial', start_time)
2290 REAL (rprec) :: start_time
2293 start_time = profiler_get_start_time()
2295 IF (
ASSOCIATED(this%ti))
THEN
2297 & pprofile_get_gp_num_hyper_param(this%ti)
2302 CALL profiler_set_stop_time(
'siesta_get_gp_ti_num_hyper_param',
2325 REAL (rprec) :: start_time
2328 start_time = profiler_get_start_time()
2330 IF (
ASSOCIATED(this%ti))
THEN
2336 CALL profiler_set_stop_time(
'siesta_get_ti_af', start_time)
2358 INTEGER,
INTENT(in) :: i
2359 INTEGER,
INTENT(in) :: j
2362 REAL (rprec) :: start_time
2365 start_time = profiler_get_start_time()
2367 IF (
ASSOCIATED(this%ti))
THEN
2373 CALL profiler_set_stop_time(
'siesta_get_gp_ti_ij', start_time)
2395 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2396 INTEGER,
INTENT(in) :: i
2399 REAL (rprec) :: start_time
2402 start_time = profiler_get_start_time()
2404 IF (
ASSOCIATED(this%ti))
THEN
2406 & pprofile_get_gp(this%ti,
siesta_get_p(this, x_cart, .true.),
2412 CALL profiler_set_stop_time(
'siesta_get_gp_ti_pi', start_time)
2435 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2436 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
2439 REAL (rprec) :: start_time
2442 start_time = profiler_get_start_time()
2444 IF (
ASSOCIATED(this%ti))
THEN
2446 & pprofile_get_gp(this%ti,
siesta_get_p(this, x_cart, .true.),
2452 CALL profiler_set_stop_time(
'siesta_get_gp_ti_pp', start_time)
2474 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2477 REAL (rprec) :: start_time
2480 start_time = profiler_get_start_time()
2483 & pprofile_get_value(this%ti,
siesta_get_p(this, x_cart, .true.))
2485 CALL profiler_set_stop_time(
'siesta_get_ti_cart', start_time)
2507 REAL (rprec),
INTENT(in) :: s
2510 REAL (rprec) :: start_time
2513 start_time = profiler_get_start_time()
2516 & pprofile_get_value(this%ti,
siesta_get_p(this, s, .true.))
2518 CALL profiler_set_stop_time(
'siesta_get_ti_radial', start_time)
2540 INTEGER,
INTENT(in) :: index
2543 REAL (rprec) :: start_time
2546 start_time = profiler_get_start_time()
2548 IF (
ASSOCIATED(this%sxrem) .and.
2549 & (index .le.
SIZE(this%sxrem)))
THEN
2551 & pprofile_get_gp_num_hyper_param(this%sxrem(index)%p)
2556 CALL profiler_set_stop_time(
'siesta_get_gp_sxrem_num_hyper_param',
2578 INTEGER,
INTENT(in) :: index
2581 REAL (rprec) :: start_time
2584 start_time = profiler_get_start_time()
2586 IF (
ASSOCIATED(this%sxrem) .and.
2587 & (index .le.
SIZE(this%sxrem)))
THEN
2593 CALL profiler_set_stop_time(
'siesta_get_sxrem_af', start_time)
2616 INTEGER,
INTENT(in) :: i
2617 INTEGER,
INTENT(in) :: j
2618 INTEGER,
INTENT(in) :: index
2621 REAL (rprec) :: start_time
2624 start_time = profiler_get_start_time()
2626 IF (
ASSOCIATED(this%sxrem) .and.
2627 & (index .le.
SIZE(this%sxrem)))
THEN
2629 & pprofile_get_gp(this%sxrem(index)%p, i, j)
2634 CALL profiler_set_stop_time(
'siesta_get_gp_sxrem_ij', start_time)
2658 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2659 INTEGER,
INTENT(in) :: i
2660 INTEGER,
INTENT(in) :: index
2663 REAL (rprec) :: start_time
2666 start_time = profiler_get_start_time()
2668 IF (
ASSOCIATED(this%sxrem) .and.
2669 & (index .le.
SIZE(this%sxrem)))
THEN
2679 CALL profiler_set_stop_time(
'siesta_get_gp_sxrem_pi', start_time)
2705 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2706 REAL (rprec),
DIMENSION(3),
INTENT(in) :: y_cart
2707 INTEGER,
INTENT(in) :: index
2710 REAL (rprec) :: start_time
2713 start_time = profiler_get_start_time()
2715 IF (
ASSOCIATED(this%sxrem) .and.
2716 & (index .le.
SIZE(this%sxrem)))
THEN
2718 & pprofile_get_gp(this%sxrem(index)%p,
2725 CALL profiler_set_stop_time(
'siesta_get_gp_sxrem_pp', start_time)
2748 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2749 INTEGER,
INTENT(in) :: index
2752 REAL (rprec) :: start_time
2755 start_time = profiler_get_start_time()
2757 IF (
ASSOCIATED(this%sxrem) .and.
2758 & (index .le.
SIZE(this%sxrem)))
THEN
2760 & pprofile_get_value(this%sxrem(index)%p,
2766 CALL profiler_set_stop_time(
'siesta_get_sxrem_cart', start_time)
2789 REAL (rprec),
INTENT(in) :: s
2790 INTEGER,
INTENT(in) :: index
2793 REAL (rprec) :: start_time
2796 start_time = profiler_get_start_time()
2798 IF (
ASSOCIATED(this%sxrem) .and.
2799 & (index .le.
SIZE(this%sxrem)))
THEN
2801 & pprofile_get_value(this%sxrem(index)%p,
2807 CALL profiler_set_stop_time(
'siesta_get_sxrem_radial', start_time)
2828 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2829 LOGICAL,
INTENT(in) :: normalize
2832 REAL (rprec) :: start_time
2835 start_time = profiler_get_start_time()
2841 CALL profiler_set_stop_time(
'siesta_get_p_cart', start_time)
2862 REAL (rprec),
INTENT(in) :: s
2863 LOGICAL,
INTENT(in) :: normalize
2866 REAL (rprec),
DIMENSION(3) :: flux
2867 REAL (rprec) :: start_time
2870 start_time = profiler_get_start_time()
2872 flux(1) = min(s, 1.0)
2876 CALL profiler_set_stop_time(
'siesta_get_p_cart', start_time)
2891 USE read_wout_mod,
only: nfp
2892 USE stel_constants,
only: mu0
2899 REAL (rprec),
DIMENSION(3),
INTENT(in) :: flux
2900 LOGICAL,
INTENT(in) :: normalize
2904 REAL (rprec) :: wlow
2905 REAL (rprec) :: whigh
2912 REAL (rprec) :: start_time
2915 start_time = profiler_get_start_time()
2917 ds = 1.0/(this%context%ns - 1.0)
2919 IF (flux(1) .lt. ds/2.0)
THEN
2922 whigh = flux(1) - ds/2.0
2924 ELSE IF (flux(1) .gt. 1.0 - ds/2.0)
THEN
2925 ihigh = this%context%ns
2927 wlow = -flux(1)/ds - 0.5 + 1.0/ds
2930 ilow = floor(flux(1)/ds + 1.5)
2932 whigh = flux(1)/ds + 1.5 - ilow
2936 mpol = this%context%mpol
2937 ntor = this%context%ntor
2943 & (wlow*this%context%pmnch(m,n,ilow) +
2944 & whigh*this%context%pmnch(m,n,ihigh))*
2945 & cos(m*flux(2) + nfp*n*flux(3))
2947 IF (this%context%l_asym)
THEN
2949 & (wlow*this%context%pmnsh(m,n,ilow) +
2950 & whigh*this%context%pmnsh(m,n,ihigh))*
2951 & sin(m*flux(2) + nfp*n*flux(3))
2964 & / (this%context%p_max - this%context%p_min)
2967 & / (mu0*this%context%p_factor)
2970 CALL profiler_set_stop_time(
'siesta_get_p_flux', start_time)
2994 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
2995 LOGICAL,
INTENT(in) :: cyl
2998 REAL (rprec),
DIMENSION(3) :: r_cyl
2999 REAL (rprec),
DIMENSION(3) :: flux
3000 REAL (rprec) :: start_time
3003 start_time = profiler_get_start_time()
3012 IF (flux(1) .gt. 1.0)
THEN
3026 CALL profiler_set_stop_time(
'siesta_get_B_vec', start_time)
3043 USE stel_constants,
only: twopi
3044 USE read_wout_mod,
only: bsubvmnc, ns
3051 REAL (rprec),
INTENT(in) :: r
3052 REAL (rprec),
INTENT(in) :: theta
3055 REAL (rprec) :: bsubv00c, ds
3057 REAL (rprec),
DIMENSION(2) :: s
3058 REAL (rprec) :: start_time
3061 start_time = profiler_get_start_time()
3068 & s, this%context%bsubvmnch(0,0,ns - 1:ns), 2)
3072 CALL profiler_set_stop_time(
'siesta_get_Int_B_dphi', start_time)
3094 REAL (rprec),
DIMENSION(3),
INTENT(in) :: x_cart
3097 REAL (rprec),
DIMENSION(3) :: flux
3098 REAL (rprec) :: start_time
3101 start_time = profiler_get_start_time()
3108 CALL profiler_set_stop_time(
'siesta_get_suv', start_time)
3134 REAL (rprec),
INTENT (in) :: phi
3135 REAL (rprec),
DIMENSION(:),
POINTER :: r
3136 REAL (rprec),
DIMENSION(:),
POINTER :: z
3139 REAL (rprec) :: start_time
3142 start_time = profiler_get_start_time()
3149 CALL profiler_set_stop_time(
'siesta_get_plasma_edge', start_time)
3167 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
3172 REAL (rprec) :: start_time
3175 start_time = profiler_get_start_time()
3178 CALL profiler_set_stop_time(
'siesta_get_magnetic_volume_rgrid',
3197 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
3202 REAL (rprec) :: start_time
3205 start_time = profiler_get_start_time()
3208 CALL profiler_set_stop_time(
'siesta_get_magnetic_volume_zgrid',
3227 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
3232 REAL (rprec) :: start_time
3235 start_time = profiler_get_start_time()
3238 CALL profiler_set_stop_time(
'siesta_get_magnetic_volume_jrgrid',
3257 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
3262 REAL (rprec) :: start_time
3265 start_time = profiler_get_start_time()
3268 CALL profiler_set_stop_time(
'siesta_get_magnetic_volume_jphigrid',
3287 REAL (rprec),
DIMENSION(:,:,:),
POINTER ::
3292 REAL (rprec) :: start_time
3295 start_time = profiler_get_start_time()
3298 CALL profiler_set_stop_time(
'siesta_get_magnetic_volume_jzgrid',
3319 USE read_wout_mod,
only: isigng
3328 REAL (rprec) :: start_time
3331 start_time = profiler_get_start_time()
3333 & * this%magnetic_cache%du
3334 & * this%magnetic_cache%dv
3336 CALL profiler_set_stop_time(
'siesta_get_volume_int_element',
3355 REAL (rprec),
DIMENSION(:,:),
POINTER ::
3360 REAL (rprec) :: start_time
3363 start_time = profiler_get_start_time()
3366 CALL profiler_set_stop_time(
'siesta_get_con_surface_krgrid',
3385 REAL (rprec),
DIMENSION(:,:),
POINTER ::
3390 REAL (rprec) :: start_time
3393 start_time = profiler_get_start_time()
3396 CALL profiler_set_stop_time(
'siesta_get_con_surface_kphigrid',
3415 REAL (rprec),
DIMENSION(:,:),
POINTER ::
3420 REAL (rprec) :: start_time
3423 start_time = profiler_get_start_time()
3426 CALL profiler_set_stop_time(
'siesta_get_con_surface_kzgrid',
3447 USE read_wout_mod,
only: isigng
3456 REAL (rprec) :: start_time
3459 start_time = profiler_get_start_time()
3461 & * this%magnetic_cache%dv_a*isigng
3463 CALL profiler_set_stop_time(
'siesta_get_area_int_element',
3489 INTEGER,
INTENT(in) :: num_currents
3490 LOGICAL,
INTENT(out) :: scale_currents
3493 REAL (rprec) :: start_time
3496 start_time = profiler_get_start_time()
3501 CALL profiler_set_stop_time(
'vmec_get_ext_currents', start_time)
3522 USE read_wout_mod,
only: isigng
3529 REAL (rprec),
DIMENSION(3),
INTENT(in) :: position
3530 LOGICAL,
INTENT(in) :: axi_only
3533 REAL (rprec),
DIMENSION(3) :: x_cart
3534 REAL (rprec),
DIMENSION(3) :: r_vec
3536 REAL (rprec) :: length
3537 REAL (rprec),
DIMENSION(:,:,:),
POINTER :: x_prime
3538 REAL (rprec),
DIMENSION(:,:),
POINTER :: kxuv
3539 REAL (rprec),
DIMENSION(:,:),
POINTER :: kyuv
3540 REAL (rprec),
DIMENSION(:,:),
POINTER :: kzuv
3541 REAL (rprec),
DIMENSION(3) :: sum_b
3542 REAL (rprec) :: start_time
3545 start_time = profiler_get_start_time()
3554 CALL assert(
ASSOCIATED(this%magnetic_cache%kxuv_axi),
3555 &
'Cannot get the axisymmtric only ext bfield.')
3557 x_prime => this%magnetic_cache%x_axi
3558 kxuv => this%magnetic_cache%kxuv_axi
3559 kyuv => this%magnetic_cache%kyuv_axi
3560 kzuv => this%magnetic_cache%kzuv_axi
3562 CALL assert(
ASSOCIATED(this%magnetic_cache%kxuv_full),
3563 &
'Cannot get the ext bfield.')
3565 x_prime => this%magnetic_cache%x_prime
3566 kxuv => this%magnetic_cache%kxuv_full
3567 kyuv => this%magnetic_cache%kyuv_full
3568 kzuv => this%magnetic_cache%kzuv_full
3575 DO v = 1,
SIZE(kxuv,2)
3576 DO u = 1,
SIZE(kxuv,1)
3577 r_vec = x_cart - x_prime(u,v,:)
3578 length = sqrt(dot_product(r_vec, r_vec))**3.0
3581 & + (kyuv(u,v)*r_vec(3) - kzuv(u,v)*r_vec(2))
3584 & + (kzuv(u,v)*r_vec(1) - kxuv(u,v)*r_vec(3))
3587 & + (kxuv(u,v)*r_vec(2) - kyuv(u,v)*r_vec(1))
3606 & * this%magnetic_cache%du_full
3607 & * this%magnetic_cache%dv_full
3612 CALL profiler_set_stop_time(
'siesta_get_ext_b_plasma', start_time)
3629 USE read_wout_mod,
only: nfp, mnmax, xm, xn, rmnc, rmns, zmnc, &
3630 & zmns, lasym, nsvmec => ns
3632 USE vmec_utils,
ONLY : getbcyl_wout
3639 REAL (rprec),
DIMENSION(3),
INTENT(in) :: flux
3643 REAL (rprec) :: wlow_v
3644 REAL (rprec) :: whigh_v
3647 REAL (rprec) :: wlow_s
3648 REAL (rprec) :: whigh_s
3665 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: vmecint
3666 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: cosmn_vmec
3667 REAL (rprec),
DIMENSION(:),
ALLOCATABLE :: sinmn_vmec
3668 REAL (rprec) :: start_time
3671 start_time = profiler_get_start_time()
3673 ds = 1.0/(this%context%ns - 1.0)
3676 IF (flux(1) .lt. ds/2.0)
THEN
3679 whigh_s = flux(1) - ds/2.0
3680 wlow_s = 1.0 - whigh_s
3681 ELSE IF (flux(1) .gt. 1.0 - ds/2.0)
THEN
3682 ihigh_s = this%context%ns
3683 ilow_s = ihigh_s - 1
3684 wlow_s = -flux(1)/ds - 0.5 + 1.0/ds
3685 whigh_s = 1.0 - wlow_s
3687 ilow_s = floor(flux(1)/ds + 1.5)
3688 ihigh_s = ilow_s + 1
3689 whigh_s = flux(1)/ds + 1.5 - ilow_s
3690 wlow_s = 1.0 - whigh_s
3694 ihigh_v = ilow_v + 1
3696 whigh_v = 1.0 - wlow_v
3698 ALLOCATE(vmecint(mnmax))
3699 ALLOCATE(cosmn_vmec(mnmax))
3700 ALLOCATE(sinmn_vmec(mnmax))
3702 cosmn_vmec = cos(xm*flux(2) - xn*flux(3))
3703 sinmn_vmec = sin(xm*flux(2) - xn*flux(3))
3705 vmecint = wlow_v*rmnc(:,ilow_v) + whigh_v*rmnc(:,ihigh_v)
3706 r = sum(vmecint*cosmn_vmec)
3707 ru = -sum(xm*vmecint*sinmn_vmec)
3708 rv = sum(xn*vmecint*sinmn_vmec)
3710 vmecint = 2.0*flux(1)*(rmnc(:,ihigh_v) - rmnc(:,ilow_v))
3712 rs = sum(vmecint*cosmn_vmec)
3714 vmecint = wlow_v*zmns(:,ilow_v) + whigh_v*zmns(:,ihigh_v)
3715 zu = sum(xm*vmecint*cosmn_vmec)
3716 zv = -sum(xn*vmecint*cosmn_vmec)
3718 vmecint = 2.0*flux(1)*(zmns(:,ihigh_v) - zmns(:,ilow_v))
3720 zs = sum(vmecint*sinmn_vmec)
3722 mpol = this%context%mpol
3723 ntor = this%context%ntor
3732 & (wlow_s*this%context%bsupsmnsh(m,n,ilow_s) +
3733 & whigh_s*this%context%bsupsmnsh(m,n,ihigh_s))*
3734 & sin(m*flux(2) + nfp*n*flux(3))
3737 & (wlow_s*this%context%bsupumnch(m,n,ilow_s) +
3738 & whigh_s*this%context%bsupumnch(m,n,ihigh_s))*
3739 & cos(m*flux(2) + nfp*n*flux(3))
3742 & (wlow_s*this%context%bsupvmnch(m,n,ilow_s) +
3743 & whigh_s*this%context%bsupvmnch(m,n,ihigh_s))*
3744 & cos(m*flux(2) + nfp*n*flux(3))
3748 IF (this%context%l_asym)
THEN
3751 vmecint = wlow_v*rmns(:,ilow_v) + whigh_v*rmns(:,ihigh_v)
3752 r = r + sum(vmecint*sinmn_vmec)
3753 ru = ru + sum(xm*vmecint*cosmn_vmec)
3754 rv = rv - sum(xn*vmecint*cosmn_vmec)
3756 vmecint = 2.0*flux(1)*(rmns(:,ihigh_v) - rmns(:,ilow_v))
3758 rs = rs + sum(vmecint*sinmn_vmec)
3760 vmecint = wlow_v*zmnc(:,ilow_v) + whigh_v*zmnc(:,ihigh_v)
3761 zu = zu - sum(xm*vmecint*sinmn_vmec)
3762 zv = zv + sum(xn*vmecint*sinmn_vmec)
3764 vmecint = 2.0*flux(1)*(zmnc(:,ihigh_v) - zmnc(:,ilow_v))
3766 zs = zs + sum(vmecint*cosmn_vmec)
3772 & (wlow_s*this%context%bsupsmnch(m,n,ilow_s) +
3773 & whigh_s*this%context%bsupsmnch(m,n,ihigh_s))*
3774 & cos(m*flux(2) + nfp*n*flux(3))
3777 & (wlow_s*this%context%bsupumnsh(m,n,ilow_s) +
3778 & whigh_s*this%context%bsupumnsh(m,n,ihigh_s))*
3779 & sin(m*flux(2) + nfp*n*flux(3))
3782 & (wlow_s*this%context%bsupvmnsh(m,n,ilow_s) +
3783 & whigh_s*this%context%bsupvmnsh(m,n,ihigh_s))*
3784 & sin(m*flux(2) + nfp*n*flux(3))
3790 DEALLOCATE(cosmn_vmec)
3791 DEALLOCATE(sinmn_vmec)
3798 & / this%context%b_factor
3819 REAL (rprec) :: start_time
3822 start_time = profiler_get_start_time()
3824 IF (
ASSOCIATED(this%context))
THEN
3830 CALL profiler_set_stop_time(
'siesta_get_grid_size', start_time)
3851 REAL (rprec) :: start_time
3854 start_time = profiler_get_start_time()
3856 CALL profiler_set_stop_time(
'siesta_get_grid_start', start_time)
3877 REAL (rprec) :: start_time
3880 start_time = profiler_get_start_time()
3882 CALL profiler_set_stop_time(
'siesta_get_grid_stop', start_time)
3905 INTEGER,
INTENT(in) :: id
3908 REAL (rprec) :: start_time
3911 start_time = profiler_get_start_time()
3922 CALL profiler_set_stop_time(
'siesta_is_scaler_value', start_time)
3942 INTEGER,
INTENT(in) :: id
3945 REAL (rprec) :: start_time
3948 start_time = profiler_get_start_time()
3963 CALL profiler_set_stop_time(
'siesta_is_1d_array', start_time)
3983 INTEGER,
INTENT(in) :: id
3986 REAL (rprec) :: start_time
3989 start_time = profiler_get_start_time()
4001 CALL profiler_set_stop_time(
'siesta_is_2d_array', start_time)
4022 INTEGER,
INTENT(in) :: id
4025 REAL (rprec) :: start_time
4028 start_time = profiler_get_start_time()
4047 CALL profiler_set_stop_time(
'siesta_is_recon_param', start_time)
4068 REAL (rprec) :: start_time
4071 start_time = profiler_get_start_time()
4079 &
ASSOCIATED(this%magnetic_cache%kxuv_full)
4082 CALL profiler_set_stop_time(
'vmec_is_using_point', start_time)
4117 INTEGER,
INTENT(inout) :: num_iter
4118 INTEGER,
INTENT(in) :: iou
4119 INTEGER,
INTENT(in) :: eq_comm
4120 INTEGER,
INTENT(in) :: state_flags
4127 INTEGER :: child_comm
4128 TYPE (siesta_run_class),
POINTER :: run_context
4129 REAL (rprec) :: start_time
4132 start_time = profiler_get_start_time()
4146 #if defined(MPI_OPT)
4147 CALL mpi_comm_rank(eq_comm, eq_rank, status)
4148 CALL mpi_comm_size(eq_comm, eq_size, status)
4150 IF (eq_rank .eq. 0)
THEN
4154 lresistive = .false.
4156 CALL safe_open(iou_nli, status, trim(this%siesta_file_name),
4157 &
'replace',
'formatted', delim_in=
'quote')
4158 WRITE (iou_nli, nml=siesta_info)
4159 CLOSE (iou_nli, iostat=status)
4162 #if defined(MPI_OPT)
4163 CALL mpi_barrier(eq_comm, status)
4165 run_context => siesta_run_construct(eq_comm, .false.)
4166 CALL siesta_run_set_vmec(run_context)
4167 CALL siesta_run_converge(run_context)
4168 CALL siesta_run_destruct(run_context, .false., .false.)
4170 IF (siesta_error_state .eq. siesta_error_no_error)
THEN
4172 IF (eq_rank .eq. 0)
THEN
4175 lresistive = .false.
4177 CALL safe_open(iou_nli, status, trim(this%siesta_file_name),
4178 &
'replace',
'formatted', delim_in=
'quote')
4179 WRITE (iou_nli, nml=siesta_info)
4180 CLOSE (iou_nli, iostat=status)
4183 #if defined(MPI_OPT)
4184 CALL mpi_barrier(eq_comm, status)
4186 run_context => siesta_run_construct(eq_comm, .false.)
4187 CALL siesta_run_set_vmec(run_context)
4188 CALL siesta_run_converge(run_context)
4189 CALL siesta_run_destruct(run_context, .false., .false.)
4197 IF (
ASSOCIATED(this%context))
THEN
4199 & this%restart_file_name)
4205 IF (
ASSOCIATED(this%magnetic_cache))
THEN
4210 CALL profiler_set_stop_time(
'siesta_converge', start_time)
4230 TYPE (siesta_class),
INTENT(in) :: this
4231 INTEGER,
INTENT(in) :: index
4232 INTEGER,
INTENT(in) :: eq_comm
4252 TYPE (siesta_class),
INTENT(inout) :: this
4257 REAL (rprec) :: start_time
4260 start_time = profiler_get_start_time()
4266 CALL copy_file(trim(this%restart_file_name),
4267 & trim(this%restart_file_name) //
'_cache',
4269 CALL assert_eq(error, 0,
'Error copying restart file.')
4271 IF (
ASSOCIATED(this%ne))
THEN
4272 CALL pprofile_save_state(this%ne)
4274 IF (
ASSOCIATED(this%te))
THEN
4275 CALL pprofile_save_state(this%te)
4277 IF (
ASSOCIATED(this%ti))
THEN
4278 CALL pprofile_save_state(this%ti)
4280 IF (
ASSOCIATED(this%sxrem))
THEN
4281 DO i = 1,
SIZE(this%sxrem)
4282 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
4283 CALL pprofile_save_state(this%sxrem(i)%p)
4288 CALL profiler_set_stop_time(
'siesta_save_state', start_time)
4305 TYPE (siesta_class),
INTENT(inout) :: this
4310 REAL (rprec) :: start_time
4313 start_time = profiler_get_start_time()
4318 CALL copy_file(trim(this%restart_file_name) //
'_cache',
4319 & trim(this%restart_file_name), error)
4320 CALL assert_eq(error, 0,
'Error moving wout file.')
4324 IF (
ASSOCIATED(this%ne))
THEN
4325 CALL pprofile_reset_state(this%ne)
4327 IF (
ASSOCIATED(this%te))
THEN
4328 CALL pprofile_reset_state(this%te)
4330 IF (
ASSOCIATED(this%ti))
THEN
4331 CALL pprofile_reset_state(this%ti)
4333 IF (
ASSOCIATED(this%sxrem))
THEN
4334 DO i = 1,
SIZE(this%sxrem)
4335 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
4336 CALL pprofile_reset_state(this%sxrem(i)%p)
4341 CALL profiler_set_stop_time(
'siesta_reset_state', start_time)
4361 TYPE (siesta_class),
INTENT(in) :: this
4362 INTEGER,
INTENT(in) :: iou
4368 REAL (rprec) :: start_time
4371 start_time = profiler_get_start_time()
4373 WRITE (iou,*)
'Equilibrium Type : SIESTA'
4374 IF (
ASSOCIATED(this%ne))
THEN
4375 CALL pprofile_write(this%ne,
'pp_ne', iou)
4378 IF (
ASSOCIATED(this%sxrem))
THEN
4379 DO i = 1,
SIZE(this%sxrem)
4380 IF (
ASSOCIATED(this%sxrem(i)%p))
THEN
4381 CALL pprofile_write(this%sxrem(i)%p,
'pp_sxrem', iou)
4386 IF (
ASSOCIATED(this%te))
THEN
4387 CALL pprofile_write(this%te,
'pp_te', iou)
4390 IF (
ASSOCIATED(this%ti))
THEN
4391 CALL pprofile_write(this%ti,
'pp_ti', iou)
4398 CALL safe_open(iou_nl, status,
4399 & trim(this%siesta_file_name) //
'_out',
4400 &
'replace',
'formatted', delim_in=
'quote')
4401 WRITE (iou_nl, nml=siesta_info)
4402 CLOSE (iou_nl, iostat=status)
4404 CALL move_file(trim(this%siesta_file_name) //
'_save',
4405 & trim(this%siesta_file_name), status)
4409 CALL profiler_set_stop_time(
'siesta_write', start_time)
4431 TYPE (siesta_class),
INTENT(in) :: this
4432 INTEGER,
INTENT(in) :: current_step
4437 CHARACTER (len=path_length) :: filename
4438 REAL (rprec) :: start_time
4441 start_time = profiler_get_start_time()
4450 WRITE (filename,1000) trim(this%siesta_file_name), current_step
4452 CALL safe_open(iou_nl, status, trim(filename),
'replace',
4453 &
'formatted', delim_in=
'none')
4454 WRITE (iou_nl, nml=siesta_info)
4455 CLOSE (iou_nl, iostat=status)
4456 CALL assert_eq(status, 0,
'Error saving input file.')
4459 WRITE (filename,1000) trim(this%restart_file_name), current_step
4461 CALL copy_file(this%restart_file_name, trim(filename), status)
4462 CALL assert_eq(status, 0,
'Error copying wout file.')
4466 CALL profiler_set_stop_time(
'vmec_write_input', start_time)
4468 1000
FORMAT(a,
'_',i0.3)
4510 TYPE (siesta_class),
INTENT(in) :: this
4511 INTEGER,
INTENT(in) :: result_ncid
4512 INTEGER,
INTENT(in) :: maxnsetps_dim_id
4515 REAL (rprec) :: start_time
4518 start_time = profiler_get_start_time()
4522 CALL profiler_set_stop_time(
'siesta_def_result', start_time)
4539 TYPE (siesta_class),
INTENT(in) :: this
4540 INTEGER,
INTENT(in) :: result_ncid
4543 REAL (rprec) :: start_time
4546 start_time = profiler_get_start_time()
4553 CALL profiler_set_stop_time(
'siesta_write_init_data', start_time)
4571 TYPE (siesta_class),
INTENT(in) :: this
4572 INTEGER,
INTENT(in) :: result_ncid
4573 INTEGER,
INTENT(in) :: current_step
4576 REAL (rprec) :: start_time
4579 start_time = profiler_get_start_time()
4583 IF (current_step .ne. 1)
THEN
4587 CALL profiler_set_stop_time(
'siesta_write_step_data', start_time)
4605 TYPE (siesta_class),
INTENT(in) :: this
4606 INTEGER,
INTENT(in) :: result_ncid
4607 INTEGER,
INTENT(in) :: current_step
4610 REAL (rprec) :: start_time
4613 start_time = profiler_get_start_time()
4615 CALL vmec_restart(this%vmec, result_ncid, current_step)
4617 CALL profiler_set_stop_time(
'siesta_write_step_data', start_time)
4639 TYPE (siesta_class),
INTENT(inout) :: this
4640 INTEGER,
INTENT(in) :: recon_comm
4642 #if defined(MPI_OPT)
4649 CALL mpi_comm_rank(recon_comm, mpi_rank, error)
4654 CALL mpi_barrier(recon_comm, error)
4661 IF (mpi_rank .gt. 0)
THEN
4663 & trim(this%restart_file_name), error)
4665 IF (
ASSOCIATED(this%context))
THEN
4667 & this%restart_file_name)
4673 IF (
ASSOCIATED(this%magnetic_cache))
THEN
4696 TYPE (siesta_class),
INTENT(inout) :: this
4697 INTEGER,
INTENT(in) :: index
4698 INTEGER,
INTENT(in) :: recon_comm
4700 #if defined(MPI_OPT)
4706 CALL mpi_comm_rank(recon_comm, mpi_rank, error)
4713 IF (mpi_rank .eq. 0)
THEN
4715 & this%restart_file_name),
4716 & trim(this%restart_file_name), error)
4717 CALL assert_eq(error, 0,
'Error reading synced restart file.')
4721 IF (
ASSOCIATED(this%magnetic_cache))
THEN
4748 REAL (rprec),
INTENT(in) :: s
4771 REAL (rprec),
INTENT(in) :: s
4799 USE read_wout_mod,
only: ns
4805 REAL (rprec),
INTENT(in) :: s
4827 REAL (rprec),
INTENT(in) :: s
4867 REAL (rprec),
INTENT(in) :: s
4868 INTEGER,
INTENT(in) :: ilow