32 USE stel_kinds,
only : rprec, cprec
33 USE stel_constants,
only : pi, twopi, one, zero
49 PRIVATE rprec, cprec, pi, twopi, one, zero
54 INTEGER,
PARAMETER,
PRIVATE :: type_len=10
55 INTEGER,
PARAMETER,
PRIVATE :: sn_len=30
56 INTEGER,
PARAMETER,
PRIVATE :: ln_len=80
57 INTEGER,
PARAMETER,
PRIVATE :: units_len=30
119 CHARACTER(len=80) :: code_name
120 CHARACTER(len=80) :: code_version
121 CHARACTER(len=80) :: date_run
122 CHARACTER(len=80) :: field_coils_id
124 INTEGER :: n_field_cg
125 REAL(rprec),
DIMENSION(:),
POINTER :: rdiag_coilg_1 => null()
126 REAL(rprec),
DIMENSION(:),
POINTER :: extcur_mg => null()
136 INTEGER :: n_field_periods
137 LOGICAL :: lstell_sym
139 REAL(rprec),
DIMENSION(:,:,:),
POINTER :: a_r => null()
140 REAL(rprec),
DIMENSION(:,:,:),
POINTER :: a_f => null()
141 REAL(rprec),
DIMENSION(:,:,:),
POINTER :: a_z => null()
143 LOGICAL :: use_con_shell
146 INTEGER :: kp_shell_store
147 REAL(rprec),
DIMENSION(:,:),
POINTER :: a_s_r => null()
148 REAL(rprec),
DIMENSION(:,:),
POINTER :: a_s_f => null()
149 REAL(rprec),
DIMENSION(:,:),
POINTER :: a_s_z => null()
165 CHARACTER (len=sn_len) :: s_name
166 CHARACTER (len=ln_len) :: l_name
167 CHARACTER (len=units_len) :: units
168 CHARACTER (len=30) :: mddc_type
169 LOGICAL :: l_mdcoil_def
170 REAL(rprec) :: sigma_default
171 REAL(rprec) :: flux_factor
172 TYPE (bsc_coil) :: mdcoil
173 TYPE (mddc_mrf) :: mrf
182 INTERFACE ASSIGNMENT (=)
183 MODULE PROCEDURE mddc_desc_assign,
191 MODULE PROCEDURE mddc_desc_construct,
199 MODULE PROCEDURE mddc_desc_destroy,
207 MODULE PROCEDURE mddc_desc_write,
224 SUBROUTINE mddc_desc_construct(this,s_name,l_name,units, &
225 & sigma_default,mddc_type,mdcoil,mrf,flux_factor)
234 TYPE (mddc_desc),
INTENT(inout) :: this
235 CHARACTER (len=*),
INTENT(in) :: s_name
236 CHARACTER (len=*),
INTENT(in) :: l_name
237 CHARACTER (len=*),
INTENT(in) :: units
238 CHARACTER (len=*),
INTENT(in) :: mddc_type
239 REAL(rprec),
INTENT(in) :: sigma_default
240 TYPE (bsc_coil),
INTENT(in),
TARGET :: mdcoil
241 TYPE (mddc_mrf),
INTENT(in),
OPTIONAL :: mrf
242 REAL(rprec),
INTENT(in),
OPTIONAL :: flux_factor
245 CHARACTER(len=*),
PARAMETER :: sub_name = &
246 &
'mddc_desc_construct: '
254 CALL mddc_mrf_destroy(this % mrf)
257 this % s_name = trim(adjustl(s_name))
258 this % l_name = trim(adjustl(l_name))
259 this % units = trim(adjustl(units))
260 this % mddc_type = trim(adjustl(mddc_type))
261 this % l_mdcoil_def = .true.
262 IF (
PRESENT(flux_factor))
THEN
263 this % flux_factor = flux_factor
265 this % flux_factor = one
269 this % mdcoil = mdcoil
270 IF (
PRESENT(mrf))
THEN
274 END SUBROUTINE mddc_desc_construct
279 SUBROUTINE mddc_mrf_construct(this,code_name,code_version, &
280 & date_run,field_coils_id,rdiag_coilg_1,extcur_mg,kp, &
281 & rmin,rmax,zmin,zmax,n_field_periods,lstell_sym,a_r,a_f,a_z, &
282 & use_con_shell, a_s_r, a_s_f, a_s_z, kp_shell)
287 TYPE (mddc_mrf),
INTENT(inout) :: this
288 CHARACTER(len=*),
INTENT(in) :: code_name
289 CHARACTER(len=*),
INTENT(in) :: code_version
290 CHARACTER(len=*),
INTENT(in) :: date_run
291 CHARACTER(len=*),
INTENT(in) :: field_coils_id
292 REAL(rprec),
DIMENSION(:),
INTENT(in) :: rdiag_coilg_1
293 REAL(rprec),
DIMENSION(:),
INTENT(in) :: extcur_mg
294 INTEGER,
INTENT(in) :: kp
295 REAL(rprec),
INTENT(in) :: rmin
296 REAL(rprec),
INTENT(in) :: rmax
297 REAL(rprec),
INTENT(in) :: zmin
298 REAL(rprec),
INTENT(in) :: zmax
299 INTEGER,
INTENT(in) :: n_field_periods
300 LOGICAL,
INTENT(in) :: lstell_sym
301 REAL(rprec),
DIMENSION(:,:,:),
INTENT(in) :: a_r
302 REAL(rprec),
DIMENSION(:,:,:),
INTENT(in) :: a_f
303 REAL(rprec),
DIMENSION(:,:,:),
INTENT(in) :: a_z
305 LOGICAL,
INTENT(in) :: use_con_shell
306 REAL(rprec),
DIMENSION(:,:),
INTENT(in) :: a_s_r
307 REAL(rprec),
DIMENSION(:,:),
INTENT(in) :: a_s_f
308 REAL(rprec),
DIMENSION(:,:),
INTENT(in) :: a_s_z
309 INTEGER,
INTENT(in) :: kp_shell
312 INTEGER :: ir1, ir2, ir3, if1, if2, if3, iz1, &
314 INTEGER :: ier1, ier2, ier3
315 CHARACTER(len=*),
PARAMETER :: sub_name = &
316 &
'mddc_mrf_construct: '
321 CALL mddc_mrf_destroy(this)
324 this % code_name = adjustl(code_name)
325 this % code_version = adjustl(code_version)
326 this % date_run = adjustl(date_run)
327 this % field_coils_id = adjustl(field_coils_id)
333 this % n_field_periods = n_field_periods
334 this % lstell_sym = lstell_sym
337 this % n_field_cg =
SIZE(rdiag_coilg_1)
347 CALL assert_eq(ir1,if1,iz1,sub_name //
'a_ first dims different')
348 CALL assert_eq(ir2,if2,iz2,sub_name //
'a_ 2nd dims different')
349 CALL assert_eq(ir3,if3,iz3,sub_name //
'a_ 3rd dims different')
352 this % kp_store = ir3
353 CALL assert_eq(this % n_field_cg,
SIZE(extcur_mg),
354 & sub_name //
'rd - extcur dims different')
357 ALLOCATE(this % rdiag_coilg_1(this % n_field_cg),stat=ier1)
358 CALL assert_eq(0,ier1,sub_name //
'alloc rdiag_coilg_1')
359 ALLOCATE(this % extcur_mg(this % n_field_cg),stat=ier1)
360 CALL assert_eq(0,ier1,sub_name //
'alloc extcur_mg')
362 ALLOCATE(this % a_r(ir1,ir2,ir3),stat=ier1)
363 ALLOCATE(this % a_f(ir1,ir2,ir3),stat=ier2)
364 ALLOCATE(this % a_z(ir1,ir2,ir3),stat=ier3)
365 CALL assert_eq(0,ier1,ier2,ier3,sub_name //
'alloc a_')
367 this % use_con_shell = use_con_shell
368 IF (use_con_shell)
THEN
369 this % kp_shell = kp_shell
378 &
'a_s_ first dims different')
380 &
'a_s_ 2nd dims different')
383 this % kp_shell_store = ir2
385 ALLOCATE(this % a_s_r(ir1,ir2),stat=ier1)
386 ALLOCATE(this % a_s_f(ir1,ir2),stat=ier2)
387 ALLOCATE(this % a_s_z(ir1,ir2),stat=ier3)
388 CALL assert_eq(0,ier1,ier2,sub_name //
'alloc a_s_')
393 this % rdiag_coilg_1 = rdiag_coilg_1
394 this % extcur_mg = extcur_mg
399 IF (use_con_shell)
THEN
405 END SUBROUTINE mddc_mrf_construct
413 SUBROUTINE mddc_desc_destroy(this)
417 TYPE (mddc_desc),
INTENT(inout) :: this
420 CHARACTER(len=*),
PARAMETER :: sub_name = &
421 &
'mddc_desc_destroy: '
429 this % mddc_type =
' '
430 this % sigma_default = zero
431 this % flux_factor = zero
432 this % l_mdcoil_def = .false.
438 END SUBROUTINE mddc_desc_destroy
443 SUBROUTINE mddc_mrf_destroy(this)
447 TYPE (mddc_mrf),
INTENT(inout) :: this
450 CHARACTER(len=*),
PARAMETER :: sub_name = &
451 &
'mddc_mrf_destroy: '
459 this % code_name =
' '
460 this % code_version =
' '
461 this % date_run =
' '
462 this % field_coils_id =
' '
468 this % n_field_periods = 0
469 this % lstell_sym = .false.
472 this % n_field_cg = 0
477 this % use_con_shell = .false.
480 this % kp_shell_store = 0
483 IF (
ASSOCIATED(this % rdiag_coilg_1))
THEN
484 DEALLOCATE(this % rdiag_coilg_1,stat=ier1)
485 CALL assert_eq(0,ier1,sub_name //
'dealloc rdiag_coilg_1')
487 IF (
ASSOCIATED(this % extcur_mg))
THEN
488 DEALLOCATE(this % extcur_mg,stat=ier1)
489 CALL assert_eq(0,ier1,sub_name //
'dealloc extcur_mg')
491 IF (
ASSOCIATED(this % a_r))
THEN
492 DEALLOCATE(this % a_r,stat=ier1)
493 CALL assert_eq(0,ier1,sub_name //
'dealloc a_r')
495 IF (
ASSOCIATED(this % a_f))
THEN
496 DEALLOCATE(this % a_f,stat=ier1)
497 CALL assert_eq(0,ier1,sub_name //
'dealloc a_f')
499 IF (
ASSOCIATED(this % a_z))
THEN
500 DEALLOCATE(this % a_z,stat=ier1)
501 CALL assert_eq(0,ier1,sub_name //
'dealloc a_z')
503 IF (
ASSOCIATED(this % a_s_r))
THEN
504 DEALLOCATE(this % a_s_r,stat=ier1)
505 CALL assert_eq(0,ier1,sub_name //
'dealloc a_s_r')
507 IF (
ASSOCIATED(this % a_s_f))
THEN
508 DEALLOCATE(this % a_s_f,stat=ier1)
509 CALL assert_eq(0,ier1,sub_name //
'dealloc a_s_f')
511 IF (
ASSOCIATED(this % a_s_z))
THEN
512 DEALLOCATE(this % a_s_z,stat=ier1)
513 CALL assert_eq(0,ier1,sub_name //
'dealloc a_s_z')
516 END SUBROUTINE mddc_mrf_destroy
524 SUBROUTINE mddc_desc_assign(left,right)
532 TYPE (mddc_desc),
INTENT (inout) :: left
533 TYPE (mddc_desc),
INTENT (in) :: right
536 CHARACTER(len=*),
PARAMETER :: sub_name = &
537 &
'mddc_desc_assign: '
540 left % s_name = right % s_name
541 left % l_name = right % l_name
542 left % units = right % units
543 left % mddc_type = right % mddc_type
544 left % l_mdcoil_def = right % l_mdcoil_def
545 left % sigma_default = right % sigma_default
546 left % flux_factor = right % flux_factor
547 left % mdcoil = right % mdcoil
548 left % mrf = right % mrf
550 END SUBROUTINE mddc_desc_assign
555 SUBROUTINE mddc_mrf_assign(left,right)
559 TYPE (mddc_mrf),
INTENT (inout) :: left
560 TYPE (mddc_mrf),
INTENT (in) :: right
563 CHARACTER(len=*),
PARAMETER :: sub_name = &
564 &
'mddc_mrf_assign: '
565 CHARACTER (len=*),
PARAMETER :: err_mess1 = &
566 &
'left-right pointers are the same?. FIX IT'
567 INTEGER :: ier1, ier2, ier3
568 LOGICAL,
DIMENSION(5) :: lassert
574 lassert(1) = .not.
ASSOCIATED(left % a_r,right % a_r)
575 lassert(2) = .not.
ASSOCIATED(left % a_f,right % a_f)
576 lassert(3) = .not.
ASSOCIATED(left % a_z,right % a_z)
577 lassert(4) = .not.
ASSOCIATED(left % rdiag_coilg_1,
578 & right % rdiag_coilg_1)
579 lassert(5) = .not.
ASSOCIATED(left % extcur_mg,right % extcur_mg)
580 CALL assert(lassert,sub_name // err_mess1)
583 CALL mddc_mrf_destroy(left)
586 left % code_name = right % code_name
587 left % code_version = right % code_version
588 left % date_run = right % date_run
589 left % field_coils_id = right % field_coils_id
590 left % kp = right % kp
591 left % rmin = right % rmin
592 left % rmax = right % rmax
593 left % zmin = right % zmin
594 left % zmax = right % zmax
595 left % n_field_periods = right % n_field_periods
596 left % lstell_sym = right % lstell_sym
597 left % n_field_cg = right % n_field_cg
598 left % ir = right % ir
599 left % jz = right % jz
600 left % kp_store = right % kp_store
602 left % use_con_shell = right % use_con_shell
603 left % n_u = right % n_u
604 left % kp_shell = right % kp_shell
605 left % kp_shell_store = right % kp_shell_store
608 ALLOCATE(left % rdiag_coilg_1(left % n_field_cg),stat=ier1)
609 CALL assert_eq(0,ier1,sub_name //
'alloc rdiag_coilg_1')
610 ALLOCATE(left % extcur_mg(left % n_field_cg),stat=ier1)
611 CALL assert_eq(0,ier1,sub_name //
'alloc extcur_mg')
613 ALLOCATE(left % a_r(left % ir,left % jz,left % kp_store),
615 ALLOCATE(left % a_f(left % ir,left % jz,left % kp_store),
617 ALLOCATE(left % a_z(left % ir,left % jz,left % kp_store),
619 CALL assert_eq(0,ier1,ier2,ier3,sub_name //
'alloc a_')
621 IF (left % use_con_shell)
THEN
622 ALLOCATE(left % a_s_r(left % n_u,left % kp_shell_store),
624 ALLOCATE(left % a_s_f(left % n_u,left % kp_shell_store),
626 ALLOCATE(left % a_s_z(left % n_u,left % kp_shell_store),
628 CALL assert_eq(0,ier1,ier2,ier3,sub_name //
'alloc a_s_')
634 IF (
ASSOCIATED(right % rdiag_coilg_1))
THEN
635 left % rdiag_coilg_1 = right % rdiag_coilg_1
637 IF (
ASSOCIATED(right % extcur_mg))
THEN
638 left % extcur_mg = right % extcur_mg
640 IF (
ASSOCIATED(right % a_r))
THEN
641 left % a_r = right % a_r
643 IF (
ASSOCIATED(right % a_f))
THEN
644 left % a_f = right % a_f
646 IF (
ASSOCIATED(right % a_z))
THEN
647 left % a_z = right % a_z
650 IF (left % use_con_shell)
THEN
651 IF (
ASSOCIATED(right % a_s_r))
THEN
652 left % a_s_r = right % a_s_r
654 IF (
ASSOCIATED(right % a_s_f))
THEN
655 left % a_s_f = right % a_s_f
657 IF (
ASSOCIATED(right % a_s_z))
THEN
658 left % a_s_z = right % a_s_z
662 END SUBROUTINE mddc_mrf_assign
671 SUBROUTINE mddc_desc_write(this,identifier,unit,verbose)
675 TYPE (mddc_desc),
INTENT (in) :: this
676 CHARACTER (len=*),
INTENT(in),
OPTIONAL :: identifier
677 INTEGER,
INTENT(in),
OPTIONAL :: unit
678 INTEGER,
INTENT(in),
OPTIONAL :: verbose
684 INTEGER :: iv_default = 1
686 INTEGER :: iou_default = 6
688 CHARACTER (len=60) :: id
691 CHARACTER(len=*),
PARAMETER,
DIMENSION(10) :: fmt1 = (/
692 '(" start mddc_desc write, called with id = ",a) ',
693 &
'(" s_name = ",a) ',
694 &
'(" l_name = ",a) ',
695 &
'(" units = ",a) ',
696 &
'(" l_mdcoil_def = ",L1) ',
697 &
'(" mddc_type = ",a) ',
698 &
'(" bsc_coil s_name = ",a) ',
699 &
'(" flux_factor = ",es12.5) ',
700 &
'(" sigma_default = ",es12.5) ',
701 &
'(" end mddc_desc write, called with id = ",a) '
706 IF (
PRESENT(identifier))
THEN
712 IF (
PRESENT(unit))
THEN
718 IF (
PRESENT(verbose))
THEN
727 WRITE(iou,*) this % s_name
728 WRITE(iou,*) this % l_name
729 WRITE(iou,*) this % units
730 WRITE(iou,*) this % l_mdcoil_def
731 WRITE(iou,*) this % mddc_type
732 WRITE(iou,*) this % mdcoil % s_name
733 WRITE(iou,*) this % flux_factor
734 WRITE(iou,*) this % sigma_default
737 WRITE(iou,fmt1(1)) id
738 WRITE(iou,fmt1(2)) this % s_name
739 WRITE(iou,fmt1(3)) this % l_name
740 WRITE(iou,fmt1(4)) this % units
741 WRITE(iou,fmt1(5)) this % l_mdcoil_def
742 WRITE(iou,fmt1(6)) this % mddc_type
743 WRITE(iou,fmt1(7)) this % mdcoil % s_name
744 WRITE(iou,fmt1(8)) this % flux_factor
745 WRITE(iou,fmt1(9)) this % sigma_default
746 WRITE(iou,fmt1(10)) id
750 END SUBROUTINE mddc_desc_write
756 SUBROUTINE mddc_mrf_write(this,identifier,unit,verbose)
760 TYPE (mddc_mrf),
INTENT (in) :: this
761 CHARACTER (len=*),
INTENT(in),
OPTIONAL :: identifier
762 INTEGER,
INTENT(in),
OPTIONAL :: unit
763 INTEGER,
INTENT(in),
OPTIONAL :: verbose
769 INTEGER :: iv_default = 1
771 INTEGER :: iou_default = 6
773 CHARACTER (len=60) :: id
775 INTEGER :: i1, i2, i3, i4, i5
778 CHARACTER(len=*),
PARAMETER,
DIMENSION(25) :: fmt1 = (/
779 '(" start mddc_mrf write, called with id = ",a) ',
780 &
'(" code_name = ",a) ',
781 &
'(" code_version = ",a) ',
782 &
'(" date_run = ",a) ',
783 &
'(" field_coils_id = ",a) ',
784 &
'(" number of field-coil groups (n_field_cg) = ",i4) ',
785 &
'(" index rdiag_coilg_1: ",/,(1x,i4,3x,es12.5)) ',
786 &
'(" index extcur_mg: ",/,(1x,i4,3x,es12.5)) ',
787 &
'(" number of grid points in R (ir) = ",i4) ',
788 &
'(" number of grid points in z (jz) = ",i4) ',
789 &
'(" number of grid points in phi (kp) = ",i4) ',
790 &
'(" number of g. p. in phi stored (kp_store) = ",i4) ',
791 &
'(" minimum R in grid (rmin) = ",es12.5) ',
792 &
'(" maximum R in grid (rmax) = ",es12.5) ',
793 &
'(" minimum Z in grid (zmin) = ",es12.5) ',
794 &
'(" maximum Z in grid (zmax) = ",es12.5) ',
795 &
'(" number of field periods (n_field_periods) = ",i4) ',
796 &
'(" Stellarator symmetry logical (lstell_sym) = ",l1) ',
797 &
'(" Three indices for a_ are ",i4,2x,i4,2x,i4) ',
798 &
'(" a_r, a_f, a_z = ",3(3x,es12.5)) ',
799 &
'(" Two indices for a_s_ are ",i4,2x,i4) ',
800 &
'(" a_s_r, a_s_f, a_s_z = ",3(3x,es12.5)) ',
801 &
'(" end mddc_mrf write, called with id = ",a) ',
802 &
'(" number of s grid points in phi ",i4) ',
803 &
'(" number of s g. p. in phi stored ",i4) '
808 IF (
PRESENT(identifier))
THEN
814 IF (
PRESENT(unit))
THEN
820 IF (
PRESENT(verbose))
THEN
829 i3 = this % kp_store / 2
831 i5 = this % kp_shell_store / 2
836 WRITE(iou,*) this % code_name
837 WRITE(iou,*) this % code_version
838 WRITE(iou,*) this % date_run
839 WRITE(iou,*) this % field_coils_id
840 WRITE(iou,*) this % n_field_cg
841 WRITE(iou,*) (i,this % rdiag_coilg_1(i),i=1,this % n_field_cg)
842 WRITE(iou,*) (i,this % extcur_mg(i),i=1,this % n_field_cg)
843 WRITE(iou,*) this % ir
844 WRITE(iou,*) this % jz
845 WRITE(iou,*) this % kp
846 WRITE(iou,*) this % kp_store
847 WRITE(iou,*) this % rmin
848 WRITE(iou,*) this % rmax
849 WRITE(iou,*) this % zmin
850 WRITE(iou,*) this % zmax
851 WRITE(iou,*) this % n_field_periods
852 WRITE(iou,*) this % lstell_sym
853 WRITE(iou,*) i1, i2, i3
854 WRITE(iou,*) this % a_r(i1,i2,i3), this % a_f(i1,i2,i3),
855 & this % a_z(i1,i2,i3)
856 WRITE(iou,*) this % use_con_shell
858 IF (this % use_con_shell)
THEN
859 WRITE(iou,*) this % kp_shell
860 WRITE(iou,*) this % kp_shell_store
861 WRITE(iou,*) this % a_s_r(i4,i5), this % a_s_f(i4,i5),
862 & this % a_s_z(i4,i5)
866 WRITE(iou,fmt1(1)) id
867 WRITE(iou,fmt1(2)) this % code_name
868 WRITE(iou,fmt1(3)) this % code_version
869 WRITE(iou,fmt1(4)) this % date_run
870 WRITE(iou,fmt1(5)) this % field_coils_id
871 WRITE(iou,fmt1(6)) this % n_field_cg
872 WRITE(iou,fmt1(7)) (i,this % rdiag_coilg_1(i),
873 & i=1,this % n_field_cg)
874 WRITE(iou,fmt1(8)) (i,this % extcur_mg(i),
875 & i=1,this % n_field_cg)
876 WRITE(iou,fmt1(9)) this % ir
877 WRITE(iou,fmt1(10)) this % jz
878 WRITE(iou,fmt1(11)) this % kp
879 WRITE(iou,fmt1(12)) this % kp_store
880 WRITE(iou,fmt1(13)) this % rmin
881 WRITE(iou,fmt1(14)) this % rmax
882 WRITE(iou,fmt1(15)) this % zmin
883 WRITE(iou,fmt1(16)) this % zmax
884 WRITE(iou,fmt1(17)) this % n_field_periods
885 WRITE(iou,fmt1(18)) this % lstell_sym
886 WRITE(iou,fmt1(19)) i1, i2, i3
887 WRITE(iou,fmt1(20)) this % a_r(i1,i2,i3), this % a_f(i1,i2,i3),
888 & this % a_z(i1,i2,i3)
889 WRITE(iou,fmt1(21)) i4, i3
890 IF (this % use_con_shell)
THEN
891 WRITE(iou,fmt1(24)) this % kp_shell
892 WRITE(iou,fmt1(25)) this % kp_shell_store
893 WRITE(iou,fmt1(22)) this % a_s_r(i4,i5),
894 & this % a_s_f(i4,i5),
895 & this % a_s_z(i4,i5)
897 WRITE(iou,fmt1(23)) id
901 END SUBROUTINE mddc_mrf_write