140 USE write_mgrid,
only: mgrid_ext, mgrid_mode, lstell_sym, &
141 & rmin, rmax, zmin, zmax, kp, ir, jz
143 USE makegrid_global,
only: task
149 INTEGER :: numargs, i
150 CHARACTER(LEN=100) :: arg1
151 CHARACTER(LEN=20) :: task_use
153 CHARACTER(LEN=57),
DIMENSION(23),
PARAMETER :: help_message=
154 & (/
' Program makegrid command line help ',
155 &
' -h Display this message. ',
156 &
' Number of Command Line Arguments: ',
158 &
' Run makegrid using Namelist input file supplied in ',
161 &
' Use command line arguments as input to makegrid in ',
162 &
' order (only for task MGRID): ',
171 &
' ir (optional,default=121) ',
172 &
' jz (optional,default=121) ',
174 &
' Get command line input interactively (only for task ',
176 &
' END HELP MESSAGE '/)
182 CALL getcarg(1, arg1, numargs)
188 IF (arg1 .EQ.
'-h' .OR. arg1 .EQ.
'--h' .OR. arg1 .EQ.
'-H'
189 1 .OR. arg1 .EQ.
'--H')
THEN
190 DO i=1,
SIZE(help_message)
191 WRITE(6,*) help_message(i)
195 CALL namelist_input(arg1)
200 CALL interactive_input()
205 mgrid_ext = trim(arg1)
206 CALL getcarg(2, arg1, numargs)
207 IF (arg1(1:1) ==
'R' .or. arg1(1:1) ==
'r')
209 CALL getcarg(3, arg1, numargs)
210 IF (arg1(1:1) ==
'Y' .or. arg1(1:1) ==
'y' .or.
211 1 arg1(1:1) ==
'T' .or. arg1(1:1) ==
't')
212 1 lstell_sym = .true.
213 CALL getcarg(4, arg1, numargs)
215 CALL getcarg(5, arg1, numargs)
217 CALL getcarg(6, arg1, numargs)
219 CALL getcarg(7, arg1, numargs)
221 CALL getcarg(8, arg1, numargs)
223 IF (numargs .GE. 9)
THEN
224 CALL getcarg(9, arg1, numargs)
227 IF (numargs .EQ. 10)
THEN
228 CALL getcarg(10, arg1, numargs)
234 stop
'Unknown number of arguments, type "xgrid -h" for help.'
249 CALL tolower(task_use)
251 SELECT CASE(trim(adjustl(task_use)))
261 CASE(
'circ_tor_mgrid')
263 CALL task_circ_tor_grid()
267 WRITE(*,*)
'Unknown task ', trim(adjustl(task_use))
282 SUBROUTINE namelist_input(arg1)
288 USE write_mgrid,
only: mgrid_ext, mgrid_mode, lstell_sym, &
289 & rmin, rmax, zmin, zmax, kp, ir, jz
291 USE makegrid_global,
only: task, rmajor, aminor, nphi, ntheta, &
293 & cg_shift_1, cg_shift_2, cg_rot_xcent, cg_rot_theta, &
294 & cg_rot_phi, cg_rot_angle, l_rot_coil_center
296 USE sym_check,
ONLY: sym_ir, sym_jz, sym_kp, sym_perform_tests
303 CHARACTER(LEN=100),
INTENT(IN) :: arg1
305 INTEGER,
PARAMETER :: iou_nli=12
352 namelist /mgrid_nli/ task,
353 & mgrid_ext, mgrid_mode, lstell_sym,
354 & rmin, rmax, zmin, zmax, kp, ir, jz,
355 & rmajor, aminor, nphi, ntheta, extcur_mgrid,
356 & cg_shift_1, cg_shift_2, cg_rot_xcent, cg_rot_theta,
357 & cg_rot_phi, cg_rot_angle, l_rot_coil_center,
358 & sym_ir, sym_jz, sym_kp, sym_perform_tests
366 mgrid_ext=
'dummy.cth.m.d12c.f5ss'
386 sym_perform_tests=.false.
394 l_rot_coil_center = .true.
396 WRITE(*,*)
' Running makegrid using NLI file ',
398 OPEN(iou_nli, file=trim(adjustl(arg1)),status=
'OLD',iostat=ferror)
399 IF(ferror .NE. 0)
THEN
400 WRITE(*,*)
'Could not open NLI file ', arg1
401 WRITE(*,*)
'Open failed with error status ', ferror
404 READ(iou_nli,mgrid_nli)
408 END SUBROUTINE namelist_input
414 SUBROUTINE interactive_input()
419 USE write_mgrid,
only: mgrid_ext, mgrid_mode, lstell_sym, &
420 & rmin, rmax, zmin, zmax, kp, ir, jz, &
423 USE makegrid_global,
only: task
429 INTEGER :: numargs, i
430 CHARACTER(LEN=100) :: arg1
436 WRITE (6, 220, advance=
'no')
437 &
' Enter extension of "coils" file : '
438 READ (*, *) mgrid_ext
440 WRITE (6,
'(a,/,a)', advance=
'no')
441 &
' Scale (S) bfield to unit current/turn OR',
442 &
' use raw (R) currents from coils file: '
443 READ (*, *) mgrid_file
444 IF (mgrid_file(1:1) ==
'R' .or. mgrid_file(1:1) ==
'r')
447 WRITE (6, 220, advance=
'no')
448 &
' Assume stellarator symmetry (Y/N)? : '
449 READ (*, *) mgrid_file
450 IF (mgrid_file(1:1) ==
'Y' .or. mgrid_file(1:1) ==
'y')
451 & lstell_sym = .true.
453 WRITE (6, 220, advance=
'no')
454 &
' Enter rmin (min radial grid dimension) : '
457 WRITE (6, 220, advance=
'no')
458 &
' Enter rmax (max radial grid dimension) : '
461 WRITE (6, 220, advance=
'no')
462 &
' Enter zmin (min vertical grid dimension): '
465 WRITE (6, 220, advance=
'no')
466 &
' Enter zmax (max vertical grid dimension): '
469 WRITE (6, 220, advance=
'no')
470 &
' Enter number of toroidal planes/period : '
473 WRITE (6, 220, advance=
'no')
474 &
' Enter number of r (radial) mesh points : '
477 WRITE (6, 220, advance=
'no')
478 &
' Enter number of z mesh points : '
484 END SUBROUTINE interactive_input
499 SUBROUTINE task_mgrid()
518 USE makegrid_global,
only: task
522 USE sym_check,
ONLY: init_symmetry, cleanup_symmetry
529 CHARACTER(LEN=100) :: extcur_file
530 REAL(rprec) :: time_start, time_end1, time_end2
532 REAL(rprec) :: r_ave, z_ave
533 REAL(rprec),
DIMENSION(:),
ALLOCATABLE :: phi_array
534 INTEGER :: kmax, k, icoll
541 WRITE(*,*)
' Running makegrid with the following parameters:'
542 WRITE(*,*)
' task = ', task
543 WRITE(*,*)
' mgrid_ext = ', mgrid_ext
544 WRITE(*,*)
' mgrid_mode = ', mgrid_mode
545 WRITE(*,*)
' lstell_sym = ', lstell_sym
546 WRITE(*,*)
' rmin = ', rmin
547 WRITE(*,*)
' rmax = ', rmax
548 WRITE(*,*)
' zmin = ', zmin
549 WRITE(*,*)
' zmax = ', zmax
550 WRITE(*,*)
' kp = ', kp
551 WRITE(*,*)
' ir = ', ir
552 WRITE(*,*)
' jz = ', jz
555 IF (rmin .lt. 0.) stop
' rmin must be > 0 in xgrid'
556 IF (rmax .le. rmin) stop
' rmax must be > rmin in xgrid'
557 IF (zmax .le. zmin) stop
' zmax must be > zmin in xgrid'
558 IF (kp .le. 0) stop
'kp must be > 0 in xgrid'
560 ALLOCATE (br(ir,jz,kp), bz(ir,jz,kp), bp(ir,jz,kp), stat=istat)
561 IF (istat .ne. 0) stop
' allocation error in xgrid'
562 ALLOCATE (ar(ir,jz,kp), az(ir,jz,kp), ap(ir,jz,kp), stat=istat)
563 IF (istat .ne. 0) stop
' allocation error in xgrid'
566 kp2 = kp/2; jz2 = jz/2
572 IF (abs(zmax) > abs(zmin))
THEN
581 kp_odd = 0; jz_odd = 0
584 coil_file =
'coils.' // trim(mgrid_ext)
585 mgrid_file =
'mgrid_' // trim(mgrid_ext)
586 extcur_file =
'extcur.' // trim(mgrid_ext)
588 WRITE (6,*)
'Stellarator symmetry IS assumed'
590 WRITE (6,*)
'Stellarator symmetry IS NOT assumed'
592 WRITE (6, *)
'rmin = ', rmin,
' rmax = ', rmax
593 WRITE (6, *)
'zmin = ', zmin,
' zmax = ', zmax
594 WRITE (6, *)
'kp = ', kp,
' ir = ',ir,
' jz = ',jz
596 WRITE (6, *)
'Input file: ',trim(coil_file)
597 WRITE (6, *)
'Mgrid file: ',trim(mgrid_file)
598 WRITE (6, *)
'Extcur file: ',trim(extcur_file)
602 CALL safe_open(iextc, istat, trim(extcur_file),
603 1
'replace',
'formatted')
604 IF (istat .ne. 0)
THEN
605 WRITE (6,*)
'XGRID could not create ', trim(extcur_file)
606 WRITE (6,*)
'IOSTAT = ', istat,
' IUNIT = ', iextc
617 CALL second0(time_start)
621 CALL parse_coils_file (coil_file)
623 nextcur =
SIZE(coil_group)
625 ALLOCATE (extcur(nextcur))
627 CALL second0(time_end1)
629 fperiod = (8*atan(one))/nfp
630 delr = (rmax-rmin)/(ir-1)
631 delz = (zmax-zmin)/(jz-1)
640 CALL second0(time_end2)
642 WRITE (*,
'(2(/,a,f8.3,a))')
643 1
' TIME IN PARSER = ', time_end1-time_start,
' SECONDS',
644 2
' TIME IN BFIELD = ', time_end2-time_end1,
' SECONDS'
650 WRITE(*,
'(/a/)')
"Extra Information about coil groups:"
651 kmax = max(1,kp2 + kp_odd)
652 IF ((kp_odd == 0) .and. lstell_sym)
THEN
653 kmax = max(kmax,kp2 + 1)
655 ALLOCATE (phi_array(kmax))
656 r_ave = (rmax + rmin) / 2.
657 z_ave = (zmax + zmin) / 2.
659 phi_array(k) = (k-1) * delp
662 DO icoll = 1,
SIZE(coil_group)
663 CALL coil_group_report(coil_group(icoll),icoll,r_ave,z_ave
664 & ,kmax,phi_array(1:kmax))
666 DEALLOCATE (phi_array)
667 WRITE(*,
'(/80("*"))')
671 CALL cleanup_symmetry
672 CALL cleanup_biotsavart
674 DEALLOCATE (br, bp, bz)
675 DEALLOCATE (ar, ap, az)
677 IF (mgrid_mode .eq.
'R')
THEN
681 WRITE (6, 200) extcur_file
689 1
' THE BFIELDS HAVE BEEN STORED IN THE MGRID FILE IN SCALED',
690 2
' MODE. THE EXTERNAL',/,
' CURRENTS CORRESPONDING TO THOSE',
691 3
' IN THE COILS-DOT FILE',/,
' ARE GIVEN IN THE EXTCUR ARRAY IN',
692 4
' THE FILE',1x,a,
'. THEY SHOULD BE ENTERED INTO THE VMEC',
693 5
' INPUT (INDATA) FILE.'/)
695 1
' THE BFIELDS HAVE BEEN STORED IN THE MGRID FILE IN RAW MODE.',
696 2 /
' THE USER MUST PROVIDE THE EXTCUR ARRAY VALUES FOR THE',
697 3
' VMEC INPUT (INDATA) FILE.',
698 4 /
' CHOOSING EXTCUR=1 CORRESPONDS TO THE CURRENTS PRESENT',
699 5
' IN THE COILS FILE.')
702 END SUBROUTINE task_mgrid
708 SUBROUTINE task_mgrid_rs()
728 USE makegrid_global,
only: task, nextcur_dim, &
729 & cg_shift_1, cg_shift_2, cg_rot_xcent, cg_rot_theta, &
730 & cg_rot_phi, cg_rot_angle, l_rot_coil_center
734 USE sym_check,
ONLY: init_symmetry, cleanup_symmetry
741 CHARACTER(LEN=100) :: extcur_file
742 REAL(rprec) :: time_start, time_end1, time_end2
744 INTEGER :: iextcur, icoil
745 REAL(rprec),
DIMENSION(3) :: cgxcent, cg_rot_xcent_use, mean_r
746 REAL(rprec),
DIMENSION(3) :: zero_a3 = (/zero,zero,zero/)
747 REAL(rprec) :: cur_coil, cur_total
749 REAL(rprec) :: r_ave, z_ave
750 REAL(rprec),
DIMENSION(:),
ALLOCATABLE :: phi_array
751 INTEGER :: kmax, k, icoll
753 TYPE (bsc_rs) :: this_bsc_rs
759 WRITE(*,*)
' Running makegrid with the following parameters:'
760 WRITE(*,*)
' task = ', task
761 WRITE(*,*)
' mgrid_ext = ', mgrid_ext
762 WRITE(*,*)
' mgrid_mode = ', mgrid_mode
763 WRITE(*,*)
' lstell_sym = ', lstell_sym
764 WRITE(*,*)
' rmin = ', rmin
765 WRITE(*,*)
' rmax = ', rmax
766 WRITE(*,*)
' zmin = ', zmin
767 WRITE(*,*)
' zmax = ', zmax
768 WRITE(*,*)
' kp = ', kp
769 WRITE(*,*)
' ir = ', ir
770 WRITE(*,*)
' jz = ', jz
773 IF (rmin .lt. 0.) stop
' rmin must be > 0 in xgrid'
774 IF (rmax .le. rmin) stop
' rmax must be > rmin in xgrid'
775 IF (zmax .le. zmin) stop
' zmax must be > zmin in xgrid'
776 IF (kp .le. 0) stop
'kp must be > 0 in xgrid'
778 ALLOCATE (br(ir,jz,kp), bz(ir,jz,kp), bp(ir,jz,kp), stat=istat)
779 IF (istat .ne. 0) stop
' allocation error in xgrid'
780 ALLOCATE (ar(ir,jz,kp), az(ir,jz,kp), ap(ir,jz,kp), stat=istat)
781 IF (istat .ne. 0) stop
' allocation error in xgrid'
784 kp2 = kp/2; jz2 = jz/2
790 IF (abs(zmax) > abs(zmin))
THEN
799 kp_odd = 0; jz_odd = 0
802 coil_file =
'coils.' // trim(mgrid_ext)
803 mgrid_file =
'mgrid_' // trim(mgrid_ext)
804 extcur_file =
'extcur.' // trim(mgrid_ext)
806 WRITE (6,*)
'Stellarator symmetry IS assumed'
808 WRITE (6,*)
'Stellarator symmetry IS NOT assumed'
810 WRITE (6, *)
'rmin = ', rmin,
' rmax = ', rmax
811 WRITE (6, *)
'zmin = ', zmin,
' zmax = ', zmax
812 WRITE (6, *)
'kp = ', kp,
' ir = ',ir,
' jz = ',jz
814 WRITE (6, *)
'Input file: ',trim(coil_file)
815 WRITE (6, *)
'Mgrid file: ',trim(mgrid_file)
816 WRITE (6, *)
'Extcur file: ',trim(extcur_file)
819 CALL safe_open(iextc, istat, trim(extcur_file),
820 1
'replace',
'formatted')
821 IF (istat .ne. 0)
THEN
822 WRITE (6,*)
'XGRID could not create ', trim(extcur_file)
823 WRITE (6,*)
'IOSTAT = ', istat,
' IUNIT = ', iextc
832 CALL second0(time_start)
836 CALL parse_coils_file (coil_file)
838 nextcur =
SIZE(coil_group)
841 IF(nextcur .gt. nextcur_dim)
THEN
842 WRITE(*,*)
'Number of coils greater than default number of ',
847 ALLOCATE (extcur(nextcur))
856 WRITE(*,*)
' Rotate and Shift of the Coil Groups'
857 DO iextcur = 1,nextcur
859 WRITE(*,*)
' Coil Group ', iextcur,
' with s_name ',
860 & coil_group(iextcur) % s_name
870 DO icoil = 1, coil_group(iextcur) % ncoil
871 cur_coil = coil_group(iextcur) % coils(icoil) % current
872 cur_total = cur_total + cur_coil
873 CALL bsc_mean_r(coil_group(iextcur) % coils(icoil),
875 cgxcent(1:3) = cgxcent(1:3) + mean_r(1:3) * cur_coil
877 IF (cur_total .ne. 0) cgxcent(1:3) = cgxcent(1:3) / cur_total
878 IF (l_rot_coil_center(iextcur))
THEN
879 cg_rot_xcent_use = cgxcent
881 cg_rot_xcent_use = cg_rot_xcent(iextcur,1:3)
885 CALL bsc_construct_rs(this_bsc_rs,zero,zero,zero,zero_a3,
886 & cg_shift_1(iextcur,1:3))
890 CALL bsc_construct_rs(this_bsc_rs,cg_rot_theta(iextcur),
891 & cg_rot_phi(iextcur),cg_rot_angle(iextcur),
892 & cg_rot_xcent_use(1:3),cg_shift_2(iextcur,1:3))
896 WRITE(*,1000)
' Current-Averaged center of cg = ',
898 WRITE(*,1000)
' First Shift = ', cg_shift_1(iextcur,1:3)
899 WRITE(*,1000)
' Center of Rotation Used = ',
901 WRITE(*,1000)
' Rotation theta, phi, angle = ',
902 & cg_rot_theta(iextcur), cg_rot_phi(iextcur),
903 & cg_rot_angle(iextcur)
904 WRITE(*,1000)
' Second Shift = ', cg_shift_2(iextcur,1:3)
905 1000
FORMAT(a34,3(2x,es12.5))
914 CALL second0(time_end1)
916 fperiod = (8*atan(one))/nfp
917 delr = (rmax-rmin)/(ir-1)
918 delz = (zmax-zmin)/(jz-1)
927 CALL second0(time_end2)
929 WRITE (*,
'(2(/,a,f8.3,a))')
930 1
' TIME IN PARSER = ', time_end1-time_start,
' SECONDS',
931 2
' TIME IN BFIELD = ', time_end2-time_end1,
' SECONDS'
937 WRITE(*,
'(/a/)')
"Extra Information about coil groups:"
938 kmax = max(1,kp2 + kp_odd)
939 IF ((kp_odd == 0) .and. lstell_sym)
THEN
940 kmax = max(kmax,kp2 + 1)
942 ALLOCATE (phi_array(kmax))
943 r_ave = (rmax + rmin) / 2.
944 z_ave = (zmax + zmin) / 2.
946 phi_array(k) = (k-1) * delp
949 DO icoll = 1,
SIZE(coil_group)
950 CALL coil_group_report(coil_group(icoll),icoll,r_ave,z_ave
951 & ,kmax,phi_array(1:kmax))
953 DEALLOCATE (phi_array)
954 WRITE(*,
'(/80("*"))')
958 CALL cleanup_symmetry
959 CALL cleanup_biotsavart
961 DEALLOCATE (br, bp, bz)
962 DEALLOCATE (ar, ap, az)
964 IF (mgrid_mode .eq.
'R')
THEN
968 WRITE (6, 200) extcur_file
976 1
' THE BFIELDS HAVE BEEN STORED IN THE MGRID FILE IN SCALED',
977 2
' MODE. THE EXTERNAL',/,
' CURRENTS CORRESPONDING TO THOSE',
978 3
' IN THE COILS-DOT FILE',/,
' ARE GIVEN IN THE EXTCUR ARRAY IN',
979 4
' THE FILE',1x,a,
'. THEY SHOULD BE ENTERED INTO THE VMEC',
980 5
' INPUT (INDATA) FILE.'/)
982 1
' THE BFIELDS HAVE BEEN STORED IN THE MGRID FILE IN RAW MODE.',
983 2 /
' THE USER MUST PROVIDE THE EXTCUR ARRAY VALUES FOR THE',
984 3
' VMEC INPUT (INDATA) FILE.',
985 4 /
' CHOOSING EXTCUR=1 CORRESPONDS TO THE CURRENTS PRESENT',
986 5
' IN THE COILS FILE.')
989 END SUBROUTINE task_mgrid_rs
995 SUBROUTINE task_circ_tor_grid()
1008 USE write_mgrid,
only: mgrid_ext, mgrid_mode, lstell_sym, &
1009 & rmin, rmax, zmin, zmax, kp, ir, jz, &
1010 & coil_file, nextcur
1012 USE makegrid_global,
only: task, rmajor, aminor, nphi, ntheta, &
1013 & extcur_mgrid, nextcur_dim
1026 REAL(rprec),
DIMENSION(3) :: x
1027 REAL(rprec),
DIMENSION(3) :: btot, bdum
1028 REAL(rprec) :: tfrac, pfrac, brr, bpp, brout, btheta
1029 REAL(rprec) :: cost, sint, cosp, sinp, norm
1030 REAL(rprec) :: imagr, imagp, imagt, realr, realp, realt
1031 REAL(rprec),
DIMENSION(nphi,ntheta,2) :: brf, bpf, bthetaf
1032 CHARACTER(LEN=80) :: ctg_file
1033 INTEGER :: i, j, k, nmode, mmode
1034 INTEGER,
PARAMETER :: ctg_iou=17, fp=5
1043 SUBROUTINE fft_local(dat)
1045 REAL(rprec),
DIMENSION(:,:,:) :: dat
1046 END SUBROUTINE fft_local
1053 WRITE(*,*)
' Running makegrid with the following parameters:'
1054 WRITE(*,*)
' task = ', task
1055 WRITE(*,*)
' mgrid_ext = ', mgrid_ext
1056 WRITE(*,*)
' rmajor = ', rmajor
1057 WRITE(*,*)
' aminor = ', aminor
1058 WRITE(*,*)
' nphi = ', nphi
1059 WRITE(*,*)
' ntheta = ', ntheta
1062 coil_file =
'coils.' // trim(mgrid_ext)
1063 WRITE (6, *)
'Input file: ',trim(coil_file)
1065 ctg_file =
'ctg.'// trim(mgrid_ext)
1066 WRITE(*,*)
'CTG file: ', trim(adjustl(ctg_file))
1067 OPEN(unit=ctg_iou, file=trim(adjustl(ctg_file)))
1069 CALL parse_coils_file(coil_file)
1070 nextcur =
SIZE(coil_group)
1074 WRITE(ctg_iou,*)
'Fourier coefficients of magnetic field.'
1075 WRITE(ctg_iou,*)
'This magnetic geometry is 5 fold periodic in ',
1076 &
'phi. Only modes which preserve this ',
1077 &
'periodicity are kept.'
1078 WRITE(ctg_iou,*)
'If the field is stellarator symmetric, the ',
1079 &
'Fourier transform can be expressed in terms ',
1080 &
'of only sines or only cosines.'
1082 WRITE(ctg_iou,*)
'Major radius: R0 = ', rmajor
1083 WRITE(ctg_iou,*)
'Minor radius: a = ', aminor
1084 WRITE(ctg_iou,*)
'nphi (number of points in phi) = ', nphi
1085 WRITE(ctg_iou,*)
'ntheta (number of points in theta) = ', ntheta
1087 WRITE(ctg_iou,*)
'Coordinate system:'
1088 WRITE(ctg_iou,*)
'r = SQRT((SQRT(x**2+y**2)-R0**2)**2+z**2)'
1089 WRITE(ctg_iou,*)
'THETA = ARCSIN(z/(SQRT(x**2+y**2)-R0)'
1090 WRITE(ctg_iou,*)
'PHI = ARCTAN(y/x)'
1091 WRITE(ctg_iou,*)
'Br = B.r_hat'
1092 WRITE(ctg_iou,*)
'Btheta = B.theta_hat'
1093 WRITE(ctg_iou,*)
'Bphi = B.phi_hat'
1095 WRITE(ctg_iou,*)
'The magnetic field is given by'
1096 WRITE(ctg_iou,*)
'Br(theta,phi) = 1/SQRT(ntheta*nphi) Sum_over_',
1097 &
'm_and_n (BR_smn * (SIN(m*theta+n*phi))'
1098 WRITE(ctg_iou,*)
'Bphi(theta,phi) = 1/SQRT(ntheta*nphi) Sum_over_'
1099 & ,
'm_and_n (BPHI_cmn * (COS(m*theta+n*phi))'
1100 WRITE(ctg_iou,*)
'Btheta(theta,phi) = 1/SQRT(ntheta*nphi) Sum_',
1101 &
'over_m_and_n(BTHETA_cmn * (COS(m*theta+n*phi))'
1102 WRITE(ctg_iou,*)
'Where the subscripts "cmn" and"smn" is ',
1103 &
'shorthand for the trig function involved ("c" ',
1104 &
'or "s") and the mode number ("m", "n)'
1107 WRITE(ctg_iou,245)
"N",
"M",
"BR_smn",
"BPHI_cmn",
"BTHETA_cmn"
1111 IF(nextcur .gt. nextcur_dim)
THEN
1112 WRITE(*,*)
'Number of coils greater than default number of ',
1119 pfrac=(i-1)*1.0/nphi
1121 tfrac=(j-1)*1.0/ntheta
1124 cost=cos(twopi*tfrac)
1125 sint=sin(twopi*tfrac)
1126 cosp=cos(twopi*pfrac/fp)
1127 sinp=sin(-twopi*pfrac/fp)
1128 x(1)=(rmajor+aminor*cost)*cosp
1129 x(2)=(rmajor+aminor*cost)*sinp
1135 CALL bsc_b(coil_group(k),x,bdum)
1136 btot=btot+bdum*extcur_mgrid(k)
1140 brr=btot(1)*cosp+btot(2)*sinp
1141 brout=cost*brr+sint*btot(3)
1142 btheta=-sint*brr+cost*btot(3)
1143 bpp=-btot(1)*sinp+btot(2)*cosp
1150 bthetaf(i,j,1)=btheta
1159 CALL fft_local(bthetaf)
1164 DO j=ntheta/2+1, ntheta
1166 norm=sqrt(nphi*one)*sqrt(ntheta*one)
1167 realr=brf(i,j,1)/norm
1168 imagr=brf(i,j,2)/norm
1169 realp=bpf(i,j,1)/norm
1170 imagp=bpf(i,j,2)/norm
1171 realt=bthetaf(i,j,1)/norm
1172 imagt=bthetaf(i,j,2)/norm
1177 WRITE(ctg_iou,240) nmode, mmode, -imagr, realp, realt
1181 norm=sqrt(nphi*one)*sqrt(ntheta*one)
1182 realr=brf(i,j,1)/norm
1183 imagr=brf(i,j,2)/norm
1184 realp=bpf(i,j,1)/norm
1185 imagp=bpf(i,j,2)/norm
1186 realt=bthetaf(i,j,1)/norm
1187 imagt=bthetaf(i,j,2)/norm
1192 WRITE(ctg_iou,240) nmode, mmode, -imagr, realp, realt
1198 DO j=ntheta/2+1, ntheta
1200 norm=sqrt(nphi*one)*sqrt(ntheta*one)
1201 realr=brf(i,j,1)/norm
1202 imagr=brf(i,j,2)/norm
1203 realp=bpf(i,j,1)/norm
1204 imagp=bpf(i,j,2)/norm
1205 realt=bthetaf(i,j,1)/norm
1206 imagt=bthetaf(i,j,2)/norm
1211 WRITE(ctg_iou,240) nmode, mmode, -imagr, realp, realt
1215 norm=sqrt(nphi*one)*sqrt(ntheta*one)
1216 realr=brf(i,j,1)/norm
1217 imagr=brf(i,j,2)/norm
1218 realp=bpf(i,j,1)/norm
1219 imagp=bpf(i,j,2)/norm
1220 realt=bthetaf(i,j,1)/norm
1221 imagt=bthetaf(i,j,2)/norm
1226 WRITE(ctg_iou,240) nmode, mmode, -imagr, realp, realt
1230 240
FORMAT(2i6,3es20.12)
1231 245
FORMAT(2a6,3a20)
1232 END SUBROUTINE task_circ_tor_grid
1241 SUBROUTINE coil_group_report(cg,igroup,rR,zZ,nphi,phi_array)
1253 USE sym_check,
ONLY: check_symmetry
1260 TYPE (bsc_coilcoll),
INTENT(inout) :: cg
1261 INTEGER,
INTENT(in) :: igroup, nphi
1262 REAL(rprec),
INTENT(in) :: rR, zZ
1263 REAL(rprec),
DIMENSION(1:nphi),
INTENT(in) :: phi_array
1274 REAL(rprec),
PARAMETER :: big = 1.e40_rprec
1275 INTEGER,
PARAMETER :: int_big = 987654321
1277 INTEGER :: n_coil_fl, n_coil_fc, n_coil_other, nfil_max_fl,
1280 INTEGER :: ic, ncoil, nfil, iphi, i
1282 REAL(rprec) :: cur_max_fl, cur_min_fl, cur_sum_fl,
1287 TYPE(bsc_coil),
POINTER :: coil
1289 REAL(rprec),
DIMENSION(3) :: x, b
1291 REAL(rprec) :: c, s, br, bphi, bz, cur, phi
1299 IF (ncoil .le. 0)
THEN
1300 WRITE(*,4000) igroup, cg % s_name
1301 4000
FORMAT(/80(
"*")/
"No coils in coil group # ",i4,
", group ID ",a30)
1304 WRITE(*,4100) igroup, cg % s_name
1305 4100
FORMAT(/80(
"*")/
"Coil group # ",i4,
", with group ID ",a30)
1313 nfil_min_fl = int_big
1327 coil => cg % coils(ic)
1328 cur = coil % current
1331 SELECT CASE (coil % c_type)
1332 CASE (
'fil_loop',
'floop')
1333 n_coil_fl = n_coil_fl + 1
1335 nfil =
SIZE(coil % xnod,2) - 1
1336 nfil_max_fl = max(nfil_max_fl,nfil)
1337 nfil_min_fl = min(nfil_min_fl,nfil)
1338 nfil_sum_fl = nfil_sum_fl + nfil
1339 nfil_sumsq_fl = nfil_sumsq_fl + nfil * nfil
1341 cur_max_fl = max(cur_max_fl,cur)
1342 cur_min_fl = min(cur_min_fl,cur)
1343 cur_sum_fl = cur_sum_fl + cur
1344 cur_sumsq_fl = cur_sumsq_fl + cur * cur
1346 CASE (
'fil_circ',
'fcirc')
1347 n_coil_fc = n_coil_fc + 1
1348 cur_max_fc = max(cur_max_fc,cur)
1349 cur_min_fc = min(cur_min_fc,cur)
1350 cur_sum_fc = cur_sum_fc + cur
1351 cur_sumsq_fc = cur_sumsq_fc + cur * cur
1354 n_coil_other = n_coil_other + 1
1359 ave_nfil_fl = nfil_sum_fl * one / max(n_coil_fl,1)
1360 sd_nfil_fl = sqrt(nfil_sumsq_fl * one / max(n_coil_fl,1) -
1362 cur_ave_fl = cur_sum_fl / max(n_coil_fl,1)
1363 cur_sd_fl = sqrt(cur_sumsq_fl / max(n_coil_fl,1) -
1365 cur_ave_fc = cur_sum_fc / max(n_coil_fc,1)
1366 cur_sd_fc = sqrt(cur_sumsq_fc / max(n_coil_fc,1) -
1371 WRITE(*,5100) n_coil_fl, n_coil_fc, n_coil_other, ncoil
1373 IF (n_coil_fl .gt. 0)
THEN
1374 WRITE(*,5200) nfil_min_fl, nfil_max_fl, ave_nfil_fl,
1376 WRITE(*,5300) cur_min_fl, cur_max_fl, cur_ave_fl, cur_sd_fl
1379 IF (n_coil_fc .gt. 0)
THEN
1380 WRITE(*,5400) cur_min_fc, cur_max_fc, cur_ave_fc, cur_sd_fc
1383 5000
FORMAT(/
" Loops Circles Other Total")
1384 5100
FORMAT(
" # coils ",4(3x,i7))
1385 5200
FORMAT(/
" Filamentary loops, number of filaments:"/
1386 &
" Min Max Average SD "/
1387 & i8,3x,i8,2(2x,f11.1))
1388 5300
FORMAT(/
" Filamentary loops, current:"/
1389 &
" Min Max Average SD "/
1390 & 3(2x,es12.5),2x,es9.2)
1391 5400
FORMAT(/
" Filamentary circles, current:"/
1392 &
" Min Max Average SD "/
1393 & 3(2x,es12.5),2x,es9.2)
1396 WRITE(*,6000) rr, zz
1398 phi = phi_array(iphi)
1405 br = b(1) * c + b(2) * s
1406 bphi = - b(1) * s + b(2) * c
1408 WRITE(*,6100) phi, br, bphi, bz
1411 CALL check_symmetry(igroup)
1413 6000
FORMAT(/
"Magnetic field with unit current multiplier, at R,Z=",
1414 & 2(2x,es12.5)/t7,
"phi",t24,
"B . rhat",t38,
"B . phihat",
1416 6100
FORMAT(4(3x,es12.5))
1418 END SUBROUTINE coil_group_report
1424 SUBROUTINE fft_local(dat)
1437 USE stel_kinds,
only: rprec
1444 REAL(rprec),
DIMENSION(:,:,:) :: dat
1445 REAL(rprec),
DIMENSION(:),
ALLOCATABLE :: a, trigs, work
1446 INTEGER :: N, i, inc, jump, lot, isign, j
1447 INTEGER,
DIMENSION(13) :: ifax
1462 ALLOCATE(trigs(2*n))
1463 ALLOCATE(work(lot*n))
1474 CALL cftfax_g(n, ifax, trigs)
1475 CALL cfft99(a,work,trigs, ifax, inc, jump, n, 1, isign)
1485 IF(
ALLOCATED(a))
DEALLOCATE(a)
1487 IF(
ALLOCATED(trigs))
DEALLOCATE(trigs)
1488 ALLOCATE(trigs(2*lot))
1489 IF(
ALLOCATED(work))
DEALLOCATE(work)
1490 ALLOCATE(work(lot*n))
1498 CALL cftfax_g(lot, ifax, trigs)
1499 CALL cfft99(a,work,trigs, ifax, inc, jump, lot, 1, isign)
1507 END SUBROUTINE fft_local