V3FIT
vmec_equilibrium.f
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! The @header, @table_section, @table_subsection, @item and @end_table commands
3 ! are custom defined commands in Doxygen.in. They are defined under ALIASES.
4 ! For the page created here, the 80 column limit is exceeded. Arguments of
5 ! aliases are separated by ','. If you intended ',' to be a string you must use
6 ! an escaped comma '\,'.
7 !
122 !*******************************************************************************
125 !
126 ! Note separating the Doxygen comment block here so detailed decription is
127 ! found in the Module not the file.
128 !
133 !*******************************************************************************
134 
136  USE pprofile_t
137  USE vmec_context
138 
139  IMPLICIT NONE
140 
141 !*******************************************************************************
142 ! vmec equilibrium module parameters
143 !*******************************************************************************
144 ! Define id's only for values that can change. All others shouldn't be needed
145 ! outside of the vmec interface. Parameter id's start at 15 since 0-14 are
146 ! reserved for non equilibrium model parameters. These numbers will need to be
147 ! updated if any new model parameters are added.
148 
149 ! Variable Parameters
151  INTEGER, PARAMETER :: vmec_ac_id = 15
153  INTEGER, PARAMETER :: vmec_ac_aux_s_id = 16
155  INTEGER, PARAMETER :: vmec_ac_aux_f_id = 17
157  INTEGER, PARAMETER :: vmec_ai_id = 18
159  INTEGER, PARAMETER :: vmec_ai_aux_s_id = 19
161  INTEGER, PARAMETER :: vmec_ai_aux_f_id = 20
164  INTEGER, PARAMETER :: vmec_am_id = 21
166  INTEGER, PARAMETER :: vmec_am_aux_s_id = 22
168  INTEGER, PARAMETER :: vmec_am_aux_f_id = 23
170  INTEGER, PARAMETER :: vmec_bloat_id = 24
173  INTEGER, PARAMETER :: vmec_rbc_id = 25
175  INTEGER, PARAMETER :: vmec_zbs_id = 26
177  INTEGER, PARAMETER :: vmec_rbs_id = 27
180  INTEGER, PARAMETER :: vmec_zbc_id = 28
182  INTEGER, PARAMETER :: vmec_extcur_id = 29
184  INTEGER, PARAMETER :: vmec_curtor_id = 30
186  INTEGER, PARAMETER :: vmec_phiedge_id = 31
188  INTEGER, PARAMETER :: vmec_pres_scale_id = 32
189 
190 ! Derived Parameters
192  INTEGER, PARAMETER :: vmec_rmnc_id = 33
194  INTEGER, PARAMETER :: vmec_zmns_id = 34
196  INTEGER, PARAMETER :: vmec_lmns_id = 35
198  INTEGER, PARAMETER :: vmec_gmnc_id = 36
200  INTEGER, PARAMETER :: vmec_bsubsmns_id = 37
202  INTEGER, PARAMETER :: vmec_bsubumnc_id = 38
204  INTEGER, PARAMETER :: vmec_bsubvmnc_id = 39
206  INTEGER, PARAMETER :: vmec_bsupumnc_id = 40
208  INTEGER, PARAMETER :: vmec_bsupvmnc_id = 41
210  INTEGER, PARAMETER :: vmec_rmns_id = 42
212  INTEGER, PARAMETER :: vmec_zmnc_id = 43
214  INTEGER, PARAMETER :: vmec_lmnc_id = 44
216  INTEGER, PARAMETER :: vmec_gmns_id = 45
218  INTEGER, PARAMETER :: vmec_bsubsmnc_id = 46
220  INTEGER, PARAMETER :: vmec_bsubumns_id = 47
222  INTEGER, PARAMETER :: vmec_bsubvmns_id = 48
224  INTEGER, PARAMETER :: vmec_bsupumns_id = 49
226  INTEGER, PARAMETER :: vmec_bsupvmns_id = 50
228  INTEGER, PARAMETER :: vmec_phi_id = 51
230  INTEGER, PARAMETER :: vmec_iotaf_id = 52
232  INTEGER, PARAMETER :: vmec_iotas_id = 53
234  INTEGER, PARAMETER :: vmec_raxis_cc_id = 54
236  INTEGER, PARAMETER :: vmec_raxis_cs_id = 55
238  INTEGER, PARAMETER :: vmec_zaxis_cc_id = 56
240  INTEGER, PARAMETER :: vmec_zaxis_cs_id = 57
242  INTEGER, PARAMETER :: vmec_qfact_id = 58
243 
244 ! Auxiliary Model Parameters
246  INTEGER, PARAMETER :: vmec_pp_ne_b_id = 59
248  INTEGER, PARAMETER :: vmec_pp_ne_as_id = 60
250  INTEGER, PARAMETER :: vmec_pp_ne_af_id = 61
252  INTEGER, PARAMETER :: vmec_pp_sxrem_b_id = 62
254  INTEGER, PARAMETER :: vmec_pp_sxrem_as_id = 63
256  INTEGER, PARAMETER :: vmec_pp_sxrem_af_id = 64
259  INTEGER, PARAMETER :: vmec_pp_te_b_id = 65
262  INTEGER, PARAMETER :: vmec_pp_te_as_id = 66
265  INTEGER, PARAMETER :: vmec_pp_te_af_id = 67
268  INTEGER, PARAMETER :: vmec_pp_ti_b_id = 68
271  INTEGER, PARAMETER :: vmec_pp_ti_as_id = 69
274  INTEGER, PARAMETER :: vmec_pp_ti_af_id = 70
277  INTEGER, PARAMETER :: vmec_pp_ze_b_id = 71
280  INTEGER, PARAMETER :: vmec_pp_ze_as_id = 72
283  INTEGER, PARAMETER :: vmec_pp_ze_af_id = 73
284 
285 ! Derived Parameters
287  INTEGER, PARAMETER :: vmec_vvc_smaleli_id = 74
289  INTEGER, PARAMETER :: vmec_vvc_kappa_p_id = 75
291  INTEGER, PARAMETER :: vmec_betatot_id = 76
293  INTEGER, PARAMETER :: vmec_betapol_id = 77
295  INTEGER, PARAMETER :: vmec_betator_id = 78
297  INTEGER, PARAMETER :: vmec_betaxis_id = 79
299  INTEGER, PARAMETER :: vmec_jcuru_id = 80
301  INTEGER, PARAMETER :: vmec_jcurv_id = 81
303  INTEGER, PARAMETER :: vmec_jdotb_id = 82
304 
307  INTEGER, PARAMETER :: vmec_phi_offset_id = 83
310  INTEGER, PARAMETER :: vmec_z_offset_id = 84
311 
313  INTEGER, PARAMETER :: magnetic_cache_vc_min_grid_points = 101
315  REAL (rprec), PARAMETER :: magnetic_cache_vc_grid_dim = 0.01
316 
317 !*******************************************************************************
318 ! DERIVED-TYPE DECLARATIONS
319 ! 1) vmec magnetic cache
320 ! 2) vmec base class
321 !
322 !*******************************************************************************
323 !-------------------------------------------------------------------------------
325 !-------------------------------------------------------------------------------
328  REAL (rprec) :: ds
330  REAL (rprec) :: du
332  REAL (rprec) :: dv
333 
335  REAL (rprec) :: du_a
337  REAL (rprec) :: dv_a
338 
340  REAL (rprec) :: du_full
342  REAL (rprec) :: dv_full
343 
345  REAL (rprec), DIMENSION(:,:,:), POINTER :: rsuv => null()
347  REAL (rprec), DIMENSION(:,:,:), POINTER :: zsuv => null()
348 
350  REAL (rprec), DIMENSION(:,:,:), POINTER :: jrsuv => null()
352  REAL (rprec), DIMENSION(:,:,:), POINTER :: jphisuv => null()
354  REAL (rprec), DIMENSION(:,:,:), POINTER :: jzsuv => null()
355 
358  REAL (rprec), DIMENSION(:,:), POINTER :: kruv => null()
361  REAL (rprec), DIMENSION(:,:), POINTER :: kphiuv => null()
364  REAL (rprec), DIMENSION(:,:), POINTER :: kzuv => null()
365 
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()
377 
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()
389  END TYPE
390 
391 !-------------------------------------------------------------------------------
395 !-------------------------------------------------------------------------------
398  CHARACTER (len=path_length) :: wout_file_name
400  CHARACTER (len=path_length) :: vmec_file_name
401 
403  TYPE (pprofile_class), POINTER :: ne => null()
406  TYPE (pprofile_class), POINTER :: te => null()
408  TYPE (pprofile_class), POINTER :: ti => null()
411  TYPE (pprofile_pointer), DIMENSION(:), POINTER :: &
412  & sxrem => null()
415  TYPE (pprofile_class), POINTER :: ze => null()
416 
418  REAL (rprec) :: pol_rad_ratio
420  TYPE (vmec_magnetic_cache), POINTER :: &
421  & magnetic_cache => null()
422 
424  TYPE (vmec_context_class), POINTER :: &
425  & vmec_context_save => null()
426 
427 ! Extra reconstruction parameters
429  REAL (rprec) :: phi_offset = 0
431  REAL (rprec) :: z_offset = 0
432 
434  INTEGER :: ns_index
435 
436 #if defined (trav)
437 
438 #endif
439  END TYPE
440 
441 !*******************************************************************************
442 ! INTERFACE BLOCKS
443 !*******************************************************************************
444 !-------------------------------------------------------------------------------
447 !-------------------------------------------------------------------------------
448  INTERFACE vmec_construct
449  MODULE PROCEDURE vmec_construct_eq, &
451  END INTERFACE
452 
453 !-------------------------------------------------------------------------------
457 !-------------------------------------------------------------------------------
459  MODULE PROCEDURE vmec_set_magnetic_cache_responce, &
462  END INTERFACE
463 
464 !-------------------------------------------------------------------------------
468 !-------------------------------------------------------------------------------
469  INTERFACE
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
477  END SUBROUTINE
478  END INTERFACE
479 
480 !-------------------------------------------------------------------------------
482 !-------------------------------------------------------------------------------
483  INTERFACE vmec_get_ne
484  MODULE PROCEDURE vmec_get_ne_cart, &
486  END INTERFACE
487 
488 !-------------------------------------------------------------------------------
490 !-------------------------------------------------------------------------------
491  INTERFACE vmec_get_gp_ne
492  MODULE PROCEDURE vmec_get_gp_ne_ij, &
493  & vmec_get_gp_ne_pi, &
495  END INTERFACE
496 
497 !-------------------------------------------------------------------------------
499 !-------------------------------------------------------------------------------
500  INTERFACE vmec_get_te
501  MODULE PROCEDURE vmec_get_te_cart, &
503  END INTERFACE
504 
505 !-------------------------------------------------------------------------------
507 !-------------------------------------------------------------------------------
508  INTERFACE vmec_get_gp_te
509  MODULE PROCEDURE vmec_get_gp_te_ij, &
510  & vmec_get_gp_te_pi, &
512  END INTERFACE
513 
514 !-------------------------------------------------------------------------------
516 !-------------------------------------------------------------------------------
517  INTERFACE vmec_get_ti
518  MODULE PROCEDURE vmec_get_ti_cart, &
520  END INTERFACE
521 
522 !-------------------------------------------------------------------------------
524 !-------------------------------------------------------------------------------
525  INTERFACE vmec_get_gp_ti
526  MODULE PROCEDURE vmec_get_gp_ti_ij, &
527  & vmec_get_gp_ti_pi, &
529  END INTERFACE
530 
531 !-------------------------------------------------------------------------------
533 !-------------------------------------------------------------------------------
534  INTERFACE vmec_get_sxrem
535  MODULE PROCEDURE vmec_get_sxrem_cart, &
537  END INTERFACE
538 
539 !-------------------------------------------------------------------------------
542 !-------------------------------------------------------------------------------
544  MODULE PROCEDURE vmec_get_gp_sxrem_ij, &
547  END INTERFACE
548 
549 !-------------------------------------------------------------------------------
551 !-------------------------------------------------------------------------------
552  INTERFACE vmec_get_p
553  MODULE PROCEDURE vmec_get_p_cart, &
555  END INTERFACE
556 
557 !-------------------------------------------------------------------------------
559 !-------------------------------------------------------------------------------
560  INTERFACE vmec_get_ze
561  MODULE PROCEDURE vmec_get_ze_cart, &
563  END INTERFACE
564 
565  CONTAINS
566 !*******************************************************************************
567 ! CONSTRUCTION SUBROUTINES
568 !*******************************************************************************
569 !-------------------------------------------------------------------------------
584 !-------------------------------------------------------------------------------
585  FUNCTION vmec_construct_eq(file_name, wout_file_name, iou, &
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, &
589  & more_iter_flag
590  USE vmec_input, only: l_v3fit, ns_array, mgrid_file, lfreeb
591  USE read_wout_mod, only: read_wout_file, loadrzl
592  USE file_opts
593  USE model_state
594 
595  IMPLICIT NONE
596 
597 ! Declare Arguments
598  TYPE (vmec_class), POINTER :: vmec_construct_eq
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
605 
606 ! local variables
607  INTEGER :: i
608  INTEGER :: eq_rank
609  INTEGER :: recon_rank
610  INTEGER :: recon_size
611  INTEGER, DIMENSION(5) :: ictrl_array
612  INTEGER :: index_dat, index_end
613  INTEGER :: error
614  REAL (rprec) :: start_time
615  CHARACTER (len=path_length) :: mgrid_path
616 
617 ! Start of executable code
618  start_time = profiler_get_start_time()
619 
620  state_flags = ibset(state_flags, model_state_vmec_flag)
621 
622  eq_rank = 0
623  recon_rank = 0
624  recon_size = 1
625 #if defined(MPI_OPT)
626  CALL mpi_comm_rank(eq_comm, eq_rank, error)
627 
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)
631  END IF
632  CALL mpi_bcast(recon_rank, 1, mpi_integer, 0, eq_comm, error)
633 #endif
634 
635  IF (eq_rank .eq. 0) THEN
636  WRITE (*,*) ' *** Initializing VMEC equilibrium from file ' // &
637  & trim(file_name)
638  WRITE (iou,*) ' *** Initializing VMEC equilibrium from ' // &
639  & 'file ' // trim(file_name)
640  END IF
641 
642  ALLOCATE(vmec_construct_eq)
643 
644 ! Initialize VMEC by taking a single step.
645  ictrl_array = 0
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)
649  ictrl_array(3) = 1 ! Run for one iteration.
650  ictrl_array(4) = 1 ! Limit VMEC to single grid.
651 
652  l_v3fit = .true.
653 
654  vmec_construct_eq%vmec_file_name = trim(file_name)
655 
656 ! Only the rank zero reconstruction pool runs the inital convergence. Initalize
657 ! VMEC on that pool then broad cast the size of the largest NS value to the
658 ! children. This ensures that they are allocated with the correct grid sizes.
659 
660  IF (recon_rank .eq. 0) THEN
661  IF (wout_file_name .ne. '') THEN
662  state_flags = ibclr(state_flags, model_state_vmec_flag)
663 
664 ! runvmec deletes the string holding the wout file to read. As a result save
665 ! the wout filename before using it.
666  vmec_construct_eq%wout_file_name = wout_file_name
667  CALL runvmec(ictrl_array, file_name, .false., eq_comm, &
668  & wout_file_name)
669 
670  IF (eq_rank .eq. 0) THEN
671  CALL read_wout_file(vmec_construct_eq%wout_file_name, &
672  & error)
673  CALL assert_eq(error, 0, 'Error loading initialized ' // &
674  & 'wout file.')
675  CALL loadrzl
676  END IF
677  ELSE
678  !print *, '*** Calling runvmec from construct...'
679  CALL runvmec(ictrl_array, file_name, .false., eq_comm)
680  END IF
681 
682 ! If the mgrid file is a relative path copy it to the sub directories. This
683 ! allows the sub directories to read the mgrid file.
684  IF (lfreeb .and. .not.is_absolute_path(mgrid_file)) THEN
685  mgrid_path = get_path_of_file(mgrid_file)
686  DO i = 2, recon_size
687  IF (trim(mgrid_path) .ne. '') THEN
688  CALL create_directory(build_path(process_dir(i), &
689  & mgrid_file), error)
690  END IF
691  CALL copy_file(mgrid_file, &
692  & build_path(process_dir(i), &
693  & mgrid_file) // mgrid_file, &
694  & error)
695  END DO
696  END IF
697 
698  vmec_construct_eq%ns_index = maxloc(ns_array, 1)
699  IF (eq_rank .eq. 0) THEN
700  CALL mpi_bcast(vmec_construct_eq%ns_index, 1, mpi_integer, &
701  & 0, recon_comm, error)
702  END IF
703  ELSE
704  IF (eq_rank .eq. 0) THEN
705  CALL mpi_bcast(vmec_construct_eq%ns_index, 1, mpi_integer, &
706  & 0, recon_comm, error)
707  END IF
708  CALL mpi_bcast(vmec_construct_eq%ns_index, 1, mpi_integer, 0, &
709  & eq_comm, error)
710 
711  ictrl_array(4) = vmec_construct_eq%ns_index
712  IF (wout_file_name .ne. '') THEN
713  state_flags = ibclr(state_flags, model_state_vmec_flag)
714 
715  vmec_construct_eq%wout_file_name = wout_file_name
716  CALL runvmec(ictrl_array, file_name, .false., eq_comm, &
717  & wout_file_name)
718  IF (eq_rank .eq. 0) THEN
719  CALL read_wout_file(vmec_construct_eq%wout_file_name, &
720  & error)
721  CALL assert_eq(error, 0, 'Error loading initialized ' // &
722  & 'wout file.')
723  CALL loadrzl
724  END IF
725  ELSE
726  CALL runvmec(ictrl_array, file_name, .false., eq_comm)
727  END IF
728  END IF
729 
730 ! Check for errors in runvmec.
731  SELECT CASE (ictrl_array(2))
732 
733  CASE (successful_term_flag, norm_term_flag, more_iter_flag)
734 ! Set the wout file name.
735  index_dat = index(file_name, 'input.')
736  index_end = len_trim(file_name)
737  IF (index_dat .gt. 0) THEN
738  vmec_construct_eq%wout_file_name = 'wout_' // &
739  & trim(file_name(index_dat + 6:index_end)) // '.nc'
740  ELSE
741  vmec_construct_eq%wout_file_name = 'wout_' // &
742  & trim(file_name(1:index_end)) // '.nc'
743  END IF
744 
745  CASE DEFAULT
746  CALL err_fatal('vmec_construct runvmec command failed ', &
747  & int = ictrl_array(2))
748 
749  END SELECT
750 
751  vmec_construct_eq%vmec_context_save => vmec_context_construct()
752 
753  CALL profiler_set_stop_time('vmec_construct_eq', start_time)
754 
755  END FUNCTION
756 
757 !-------------------------------------------------------------------------------
784 !-------------------------------------------------------------------------------
785  FUNCTION vmec_construct_full(file_name, wout_file_name, ne, te, &
786  & ti, ze, sxrem, phi_offset, z_offset, &
787  & pol_rad_ratio, iou, eq_comm, &
788  & recon_comm, state_flags)
789 
790  IMPLICIT NONE
791 
792 ! Declare Arguments
793  TYPE (vmec_class), POINTER :: vmec_construct_full
794  CHARACTER (len=*), INTENT(in) :: file_name
795  CHARACTER (len=*), INTENT(in) :: wout_file_name
796  TYPE (pprofile_class), POINTER :: ne
797  TYPE (pprofile_class), POINTER :: te
798  TYPE (pprofile_class), POINTER :: ti
799  TYPE (pprofile_class), POINTER :: ze
800  TYPE (pprofile_pointer), DIMENSION(:), POINTER :: sxrem
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
808 
809 ! local variables
810  REAL (rprec) :: start_time
811 
812 ! Start of executable code
813  start_time = profiler_get_start_time()
814 
815  vmec_construct_full => vmec_construct(file_name, wout_file_name, &
816  & iou, eq_comm, recon_comm, &
817  & state_flags)
818 
819  vmec_construct_full%ne => ne
820  vmec_construct_full%te => te
821  vmec_construct_full%ti => ti
822  vmec_construct_full%ze => ze
823  vmec_construct_full%sxrem => sxrem
824 
825  vmec_construct_full%phi_offset = phi_offset
826  vmec_construct_full%z_offset = z_offset
827 
828  vmec_construct_full%pol_rad_ratio = pol_rad_ratio
829 
830  CALL profiler_set_stop_time('vmec_construct_full', start_time)
831 
832  END FUNCTION
833 
834 !*******************************************************************************
835 ! DESTRUCTION SUBROUTINES
836 !*******************************************************************************
837 !-------------------------------------------------------------------------------
843 !-------------------------------------------------------------------------------
844  SUBROUTINE vmec_destruct(this)
845  USE read_wout_mod, only: read_wout_deallocate
846  USE file_opts
847 
848  IMPLICIT NONE
849 
850 ! Declare Arguments
851  TYPE (vmec_class), POINTER :: this
852 
853 ! local variables
854  INTEGER :: i, error
855 
856 ! Start of executable code
857  IF (ASSOCIATED(this%ne)) THEN
858  CALL pprofile_destruct(this%ne)
859  this%ne => null()
860  END IF
861 
862  IF (ASSOCIATED(this%te)) THEN
863  CALL pprofile_destruct(this%te)
864  this%te => null()
865  END IF
866 
867  IF (ASSOCIATED(this%ti)) THEN
868  CALL pprofile_destruct(this%ti)
869  this%ti => null()
870  END IF
871 
872  IF (ASSOCIATED(this%ze)) THEN
873  CALL pprofile_destruct(this%ze)
874  this%ze => null()
875  END IF
876 
877  IF (ASSOCIATED(this%sxrem)) THEN
878  DO i = 1, SIZE(this%sxrem)
879  IF (ASSOCIATED(this%sxrem(i)%p)) THEN
880  CALL pprofile_destruct(this%sxrem(i)%p)
881  this%sxrem(i)%p => null()
882  END IF
883  END DO
884  DEALLOCATE(this%sxrem)
885  this%sxrem => null()
886  END IF
887 
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()
892  END IF
893 
894  IF (ASSOCIATED(this%magnetic_cache%zsuv)) THEN
895  DEALLOCATE(this%magnetic_cache%zsuv)
896  this%magnetic_cache%zsuv => null()
897  END IF
898 
899  IF (ASSOCIATED(this%magnetic_cache%jrsuv)) THEN
900  DEALLOCATE(this%magnetic_cache%jrsuv)
901  this%magnetic_cache%jrsuv => null()
902  END IF
903 
904  IF (ASSOCIATED(this%magnetic_cache%jphisuv)) THEN
905  DEALLOCATE(this%magnetic_cache%jphisuv)
906  this%magnetic_cache%jphisuv => null()
907  END IF
908 
909  IF (ASSOCIATED(this%magnetic_cache%jzsuv)) THEN
910  DEALLOCATE(this%magnetic_cache%jzsuv)
911  this%magnetic_cache%jzsuv => null()
912  END IF
913 
914  IF (ASSOCIATED(this%magnetic_cache%kruv)) THEN
915  DEALLOCATE(this%magnetic_cache%kruv)
916  this%magnetic_cache%kruv => null()
917  END IF
918 
919  IF (ASSOCIATED(this%magnetic_cache%kphiuv)) THEN
920  DEALLOCATE(this%magnetic_cache%kphiuv)
921  this%magnetic_cache%kphiuv => null()
922  END IF
923 
924  IF (ASSOCIATED(this%magnetic_cache%kzuv)) THEN
925  DEALLOCATE(this%magnetic_cache%kzuv)
926  this%magnetic_cache%kzuv => null()
927  END IF
928 
929  IF (ASSOCIATED(this%magnetic_cache%x_prime)) THEN
930  DEALLOCATE(this%magnetic_cache%x_prime)
931  this%magnetic_cache%x_prime => null()
932  END IF
933 
934  IF (ASSOCIATED(this%magnetic_cache%kxuv_full)) THEN
935  DEALLOCATE(this%magnetic_cache%kxuv_full)
936  this%magnetic_cache%kxuv_full => null()
937  END IF
938 
939  IF (ASSOCIATED(this%magnetic_cache%kyuv_full)) THEN
940  DEALLOCATE(this%magnetic_cache%kyuv_full)
941  this%magnetic_cache%kyuv_full => null()
942  END IF
943 
944  IF (ASSOCIATED(this%magnetic_cache%kzuv_full)) THEN
945  DEALLOCATE(this%magnetic_cache%kzuv_full)
946  this%magnetic_cache%kzuv_full => null()
947  END IF
948 
949  IF (ASSOCIATED(this%magnetic_cache%x_axi)) THEN
950  DEALLOCATE(this%magnetic_cache%x_axi)
951  this%magnetic_cache%x_axi => null()
952  END IF
953 
954  IF (ASSOCIATED(this%magnetic_cache%kxuv_axi)) THEN
955  DEALLOCATE(this%magnetic_cache%kxuv_axi)
956  this%magnetic_cache%kxuv_axi => null()
957  END IF
958 
959  IF (ASSOCIATED(this%magnetic_cache%kyuv_axi)) THEN
960  DEALLOCATE(this%magnetic_cache%kyuv_axi)
961  this%magnetic_cache%kyuv_axi => null()
962  END IF
963 
964  IF (ASSOCIATED(this%magnetic_cache%kzuv_axi)) THEN
965  DEALLOCATE(this%magnetic_cache%kzuv_axi)
966  this%magnetic_cache%kzuv_axi => null()
967  END IF
968 
969  DEALLOCATE(this%magnetic_cache)
970  this%magnetic_cache => null()
971  END IF
972 
973 ! Delete the cached wout file. Errors here can safely be ignored.
974  CALL delete_file(trim(this%wout_file_name) // '_cache', error)
975 
976  IF (ASSOCIATED(this%vmec_context_save)) THEN
977  CALL vmec_context_destruct(this%vmec_context_save)
978  this%vmec_context_save => null()
979  END IF
980 
981 ! Deallocate VMEC allocated memory.
982  CALL read_wout_deallocate
983  CALL free_mem_ns(.true.)
984  CALL free_mem_funct3d
985  CALL free_mem_nunv
986 
987  DEALLOCATE(this)
988 
989  END SUBROUTINE
990 
991 !*******************************************************************************
992 ! SETTER SUBROUTINES
993 !*******************************************************************************
994 !-------------------------------------------------------------------------------
1010 !-------------------------------------------------------------------------------
1011  SUBROUTINE vmec_set_param(this, id, i_index, j_index, value, &
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
1022  USE model_state
1023 
1024  IMPLICIT NONE
1025 
1026 ! Declare Arguments
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
1034 
1035 ! local variables
1036  REAL (rprec) :: phiedge_ratio
1037  INTEGER :: error
1038  REAL (rprec) :: start_time
1039 
1040 ! Start of executable code
1041  start_time = profiler_get_start_time()
1042 
1043  SELECT CASE (id)
1044 
1045  CASE (vmec_rbc_id)
1046  state_flags = ibset(state_flags, model_state_vmec_flag)
1047  rbc(i_index, j_index) = value
1048  IF (.not.lfreeb) THEN
1049  CALL vmec_reset_boundary(this)
1050  CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1051  ELSE
1052  CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1053  END IF
1054 
1055  CASE (vmec_zbs_id)
1056  state_flags = ibset(state_flags, model_state_vmec_flag)
1057  zbs(i_index, j_index) = value
1058  IF (.not.lfreeb) THEN
1059  CALL vmec_reset_boundary(this)
1060  CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1061  ELSE
1062  CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1063  END IF
1064 
1065  CASE (vmec_rbs_id)
1066  state_flags = ibset(state_flags, model_state_vmec_flag)
1067  rbs(i_index, j_index) = value
1068  IF (.not.lfreeb) THEN
1069  CALL vmec_reset_boundary(this)
1070  CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1071  ELSE
1072  CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1073  END IF
1074 
1075  CASE (vmec_zbc_id)
1076  state_flags = ibset(state_flags, model_state_vmec_flag)
1077  zbc(i_index, j_index) = value
1078  IF (.not.lfreeb) THEN
1079  CALL vmec_reset_boundary(this)
1080  CALL profil3d(xc(1), xc(1 + irzloff), .true., .false.)
1081  ELSE
1082  CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1083  END IF
1084 
1085  CASE (vmec_ac_id)
1086  state_flags = ibset(state_flags, model_state_vmec_flag)
1087  ac(i_index) = value
1088  CALL profil1d(xc, xcdot, .false.)
1089 
1090  CASE (vmec_ac_aux_s_id)
1091  state_flags = ibset(state_flags, model_state_vmec_flag)
1092  ac_aux_s(i_index) = value
1093  CALL profil1d(xc, xcdot, .false.)
1094 
1095  CASE (vmec_ac_aux_f_id)
1096  state_flags = ibset(state_flags, model_state_vmec_flag)
1097  ac_aux_f(i_index) = value
1098  CALL profil1d(xc, xcdot, .false.)
1099 
1100  CASE (vmec_ai_id)
1101  state_flags = ibset(state_flags, model_state_vmec_flag)
1102  ai(i_index) = value
1103  CALL profil1d(xc, xcdot, .false.)
1104 
1105  CASE (vmec_ai_aux_s_id)
1106  state_flags = ibset(state_flags, model_state_vmec_flag)
1107  ai_aux_s(i_index) = value
1108  CALL profil1d(xc, xcdot, .false.)
1109 
1110  CASE (vmec_ai_aux_f_id)
1111  state_flags = ibset(state_flags, model_state_vmec_flag)
1112  ai_aux_f(i_index) = value
1113  CALL profil1d(xc, xcdot, .false.)
1114 
1115  CASE (vmec_am_id)
1116  state_flags = ibset(state_flags, model_state_vmec_flag)
1117  am(i_index) = value
1118  CALL profil1d(xc, xcdot, .false.)
1119 
1120  CASE (vmec_am_aux_s_id)
1121  state_flags = ibset(state_flags, model_state_vmec_flag)
1122  am_aux_s(i_index) = value
1123  CALL profil1d(xc, xcdot, .false.)
1124 
1125  CASE (vmec_am_aux_f_id)
1126  state_flags = ibset(state_flags, model_state_vmec_flag)
1127  am_aux_f(i_index) = value
1128  CALL profil1d(xc, xcdot, .false.)
1129 
1130  CASE (vmec_pp_ne_b_id)
1131  state_flags = ibset(state_flags, model_state_ne_flag)
1132  this%ne%b(i_index) = value
1133 
1134  CASE (vmec_pp_ne_as_id)
1135  state_flags = ibset(state_flags, model_state_ne_flag)
1136  this%ne%as(i_index) = value
1137 
1138  CASE (vmec_pp_ne_af_id)
1139  state_flags = ibset(state_flags, model_state_ne_flag)
1140  this%ne%af(i_index) = value
1141 
1142  CASE (vmec_pp_te_b_id)
1143  state_flags = ibset(state_flags, model_state_te_flag)
1144  this%te%b(i_index) = value
1145 
1146  CASE (vmec_pp_te_as_id)
1147  state_flags = ibset(state_flags, model_state_te_flag)
1148  this%te%as(i_index) = value
1149 
1150  CASE (vmec_pp_te_af_id)
1151  state_flags = ibset(state_flags, model_state_te_flag)
1152  this%te%af(i_index) = value
1153 
1154  CASE (vmec_pp_ti_b_id)
1155  state_flags = ibset(state_flags, model_state_ti_flag)
1156  this%ti%b(i_index) = value
1157 
1158  CASE (vmec_pp_ti_as_id)
1159  state_flags = ibset(state_flags, model_state_ti_flag)
1160  this%ti%as(i_index) = value
1161 
1162  CASE (vmec_pp_ti_af_id)
1163  state_flags = ibset(state_flags, model_state_ti_flag)
1164  this%ti%af(i_index) = value
1165 
1166  CASE (vmec_pp_ze_b_id)
1167  state_flags = ibset(state_flags, model_state_ze_flag)
1168  this%ze%b(i_index) = value
1169 
1170  CASE (vmec_pp_ze_as_id)
1171  state_flags = ibset(state_flags, model_state_ze_flag)
1172  this%ze%as(i_index) = value
1173 
1174  CASE (vmec_pp_ze_af_id)
1175  state_flags = ibset(state_flags, model_state_ze_flag)
1176  this%ze%af(i_index) = value
1177 
1178 ! There are multiple soft x-ray emission profiles. These need to be offset by
1179 ! the array index.
1180  CASE (vmec_pp_sxrem_b_id)
1181  state_flags = ibset(state_flags, model_state_sxrem_flag + &
1182  & (i_index - 1))
1183  this%sxrem(i_index)%p%b(j_index) = value
1184 
1185  CASE (vmec_pp_sxrem_as_id)
1186  state_flags = ibset(state_flags, model_state_sxrem_flag + &
1187  & (i_index - 1))
1188  this%sxrem(i_index)%p%as(j_index) = value
1189 
1190  CASE (vmec_pp_sxrem_af_id)
1191  state_flags = ibset(state_flags, model_state_sxrem_flag + &
1192  & (i_index - 1))
1193  this%sxrem(i_index)%p%af(j_index) = value
1194 
1195  CASE (vmec_extcur_id)
1196  state_flags = ibset(state_flags, model_state_vmec_flag)
1197  extcur(i_index) = value
1198 #if defined(MPI_OPT)
1199  CALL mpi_bcast(mpi_mgrid_task, 1, mpi_integer, 0, eq_comm, &
1200  & error)
1201  CALL mpi_bcast(i_index, 1, mpi_integer, 0, eq_comm, error)
1202 #endif
1203  CALL vmec_read_vac_file(this, i_index, eq_comm)
1204 
1205  CASE (vmec_curtor_id)
1206  state_flags = ibset(state_flags, model_state_vmec_flag)
1207  curtor = value
1208  currv = mu0*curtor
1209  CALL profil1d(xc, xcdot, .false.)
1210 
1211  CASE (vmec_phiedge_id)
1212  state_flags = ibset(state_flags, model_state_vmec_flag)
1213  IF (phiedge .ne. 0.0) THEN
1214  phiedge_ratio = value/phiedge
1215  ELSE
1216  phiedge_ratio = 1.0
1217  END IF
1218  phiedge = value
1219  IF (aphi(1) .eq. 1.0) THEN
1220  xc(1 + 2*irzloff:3*irzloff) = &
1221  & phiedge_ratio*xc(1 + 2*irzloff:3*irzloff)
1222  END IF
1223  CALL profil1d(xc, xcdot, .false.)
1224  CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1225 
1226  CASE (vmec_pres_scale_id)
1227  state_flags = ibset(state_flags, model_state_vmec_flag)
1228  pres_scale = value
1229  CALL profil1d(xc, xcdot, .false.)
1230 
1231  CASE (vmec_bloat_id)
1232  state_flags = ibset(state_flags, model_state_vmec_flag)
1233  bloat = value
1234  CALL profil1d(xc, xcdot, .false.)
1235  CALL profil3d(xc(1), xc(1 + irzloff), .false., .false.)
1236 
1237 ! For the phi_offset, the magnetic cache needs to be updated. Since the phi
1238 ! offset doesn't alter the equilibrium, the magnetics were not getting updated
1239 ! since the equilibrium was not reconverged. Call vmec_set_magnetic_cache_calc
1240 ! to update the magnetic cache without reconverging VMEC.
1241  CASE (vmec_phi_offset_id)
1242  state_flags = ibset(state_flags, model_state_shift_flag)
1243  this%phi_offset = value
1244  IF (ASSOCIATED(this%magnetic_cache)) THEN
1245  CALL vmec_set_magnetic_cache(this)
1246  END IF
1247 
1248  CASE (vmec_z_offset_id)
1249  state_flags = ibset(state_flags, model_state_shift_flag)
1250  this%z_offset = value
1251  IF (ASSOCIATED(this%magnetic_cache)) THEN
1252  CALL vmec_set_magnetic_cache(this)
1253  END IF
1254 
1255  CASE DEFAULT
1258  state_flags = state_flags
1259 
1260  END SELECT
1261 
1262  CALL profiler_set_stop_time('vmec_set_param', start_time)
1263 
1264  END SUBROUTINE
1265 
1266 !-------------------------------------------------------------------------------
1276 !-------------------------------------------------------------------------------
1277  SUBROUTINE vmec_set_magnetic_cache_responce(this, response_object)
1278  USE vmec_input, only: ns_array, mpol
1279  USE stel_constants, only: twopi
1280  USE magnetic_response
1281 
1282  IMPLICIT NONE
1283 
1284 ! Declare Arguments
1285  TYPE (vmec_class), INTENT(inout) :: this
1286  TYPE (magnetic_response_class), INTENT(in) :: response_object
1287 
1288 ! local variables
1289  INTEGER :: numU
1290  INTEGER :: ns
1291  REAL (rprec) :: start_time
1292 
1293 ! Start of executable code.
1294  start_time = profiler_get_start_time()
1295 
1296  IF (.not.ASSOCIATED(this%magnetic_cache)) THEN
1297  ALLOCATE(this%magnetic_cache)
1298  END IF
1299 
1300  IF (magnetic_response_use_plasma(response_object)) THEN
1301 ! In order to sample the fields on a grid, the sampling frequency of the grid
1302 ! must be at least twice the frequency of the highest mode.
1303  ns = ns_array(this%ns_index)
1304  numu = max(int(this%pol_rad_ratio*ns), 2*mpol)
1305 
1306 ! Set the differental volume elements.
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
1311 
1312 ! When stellarator symmetry is used, do not need to store all the toroidal
1313 ! planes in a single field period.
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)))
1324  END IF
1325 
1326 ! When conducting shell is used allocate the surface vector arrays.
1327  IF (magnetic_response_use_shell(response_object)) THEN
1328 ! Set the differental area elements.
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
1334 
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)))
1344  END IF
1345 
1346  CALL profiler_set_stop_time('vmec_set_magnetic_cache_responce', &
1347  & start_time)
1348 
1349  END SUBROUTINE
1350 
1351 !-------------------------------------------------------------------------------
1360 !-------------------------------------------------------------------------------
1361  SUBROUTINE vmec_set_magnetic_cache_point(this, use_axi)
1362  USE vmec_input, only: rbc, zbs
1363 
1364  IMPLICIT NONE
1365 
1366 ! Declare Arguments
1367  TYPE (vmec_class), INTENT(inout) :: this
1368  LOGICAL, INTENT(in) :: use_axi
1369 
1370 ! local variables
1371  INTEGER :: u_size, v_size
1372  REAL (rprec) :: start_time
1373 
1374 ! Start of executable code
1375  start_time = profiler_get_start_time()
1376 
1377  IF (.not.ASSOCIATED(this%magnetic_cache)) THEN
1378  ALLOCATE(this%magnetic_cache)
1379  END IF
1380 
1381 ! Set the grid size based on the size of the rough size of the plasma.
1382  v_size = max(int(twopi*rbc(0,0)/magnetic_cache_vc_grid_dim), &
1384  IF (mod(v_size, 2) .eq. 0) THEN
1385  v_size = v_size + 1
1386  END IF
1387  this%magnetic_cache%dv_full = twopi/v_size
1388 
1389  u_size = max(int(twopi*max(rbc(0,1), zbs(0,1))/ &
1392  IF (mod(u_size, 2) .eq. 0) THEN
1393  u_size = u_size + 1
1394  END IF
1395  this%magnetic_cache%du_full = twopi/u_size
1396 
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))
1400 
1401  ALLOCATE(this%magnetic_cache%x_prime(u_size,v_size,3))
1402 
1403  IF (use_axi) THEN
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))
1407 
1408  ALLOCATE(this%magnetic_cache%x_axi(u_size,v_size,3))
1409 
1410  END IF
1411 
1412  CALL profiler_set_stop_time('vmec_set_magnetic_cache_point', &
1413  & start_time)
1414 
1415  END SUBROUTINE
1416 
1417 !-------------------------------------------------------------------------------
1424 !-------------------------------------------------------------------------------
1425  SUBROUTINE vmec_set_magnetic_cache_calc(this)
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
1432 
1433  IMPLICIT NONE
1434 
1435 ! Declare Arguments
1436  TYPE (vmec_class), INTENT(inout) :: this
1437 
1438 ! local variables
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
1456 
1457 ! Start of executable code.
1458  start_time = profiler_get_start_time()
1459 
1460 ! Only generate the magnetic caches if the woutfile has been opened. This
1461 ! prevents a segfaults when the child processes sync the phi_edge and z_offset
1462 ! parameters before the first reconstruction step when no wout file exists in
1463 ! the child process working directory.
1464  IF (.not.lwout_opened) THEN
1465  CALL profiler_set_stop_time('vmec_set_magnetic_cache_calc', &
1466  & start_time)
1467  RETURN
1468  END IF
1469 
1470  IF (ASSOCIATED(this%magnetic_cache%rsuv)) THEN
1471 ! Get the size of the SUV grid.
1472  numu = SIZE(this%magnetic_cache%rsuv, 2)
1473  numv = SIZE(this%magnetic_cache%rsuv, 3)
1474 
1475  ALLOCATE(cosu(mnmax, numu), sinu(mnmax, numu))
1476  ALLOCATE(cosu_nyq(mnmax_nyq, numu), sinu_nyq(mnmax_nyq, numu))
1477 
1478 ! U grid is square with the s grid.
1484 !$OMP PARALLEL
1485 !$OMP& DEFAULT(SHARED)
1486 !$OMP& PRIVATE(s,u,v,cosz,sinz,cosz_nyq,sinz_nyq,ru,zu,rv,zv,ju,jv,
1487 !$OMP& cosv,sinv,cosv_nyq,sinv_nyq,phi,theta)
1488 !$OMP DO
1489 !$OMP& SCHEDULE(STATIC)
1490  DO u = 1, 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)
1496  END DO
1497 !$OMP END DO
1498 
1499 ! Arrays need to be allocated within the parallel section since each thread
1500 ! requires its own allocation.
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))
1505  IF (lasym) THEN
1506  ALLOCATE(sinz_nyq(mnmax_nyq))
1507  END IF
1508 
1509 ! Set the suv grids
1510 !
1511 ! ru = dR/du
1512 ! rv = dR/dv Note: dRHat/dv = PhiHat
1513 !
1514 ! zu = dZ/du
1515 ! zu = dZ/dv
1516 !
1517 ! jr = ju*ru + jv*rv
1518 ! jphi = jv*R
1519 ! jz = ju*zu + jv*zv
1520 
1521 !$OMP DO
1522 !$OMP& SCHEDULE(STATIC)
1523  DO v = 1, numv
1524  phi = (v - 1)*this%magnetic_cache%dv + this%phi_offset
1525 
1526  cosv = cos(xn*phi)
1527  sinv = sin(xn*phi)
1528  cosv_nyq = cos(xn_nyq*phi)
1529  sinv_nyq = sin(xn_nyq*phi)
1530 
1531  DO u = 1, numu
1532 
1533  cosz = cosu(:,u)*cosv + sinu(:,u)*sinv
1534  sinz = sinu(:,u)*cosv - cosu(:,u)*sinv
1535 
1536  cosz_nyq = cosu_nyq(:,u)*cosv_nyq &
1537  & + sinu_nyq(:,u)*sinv_nyq
1538 
1539  DO s = 1, ns
1540 
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)
1547 
1548  ju = sum(currumnc(:,s)*cosz_nyq)
1549  jv = sum(currvmnc(:,s)*cosz_nyq)
1550 
1551  IF (lasym) THEN
1552  sinz_nyq = sinu_nyq(:,u)*cosv_nyq &
1553  & - cosu_nyq(:,u)*sinv_nyq
1554 
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)
1565 
1566  ju = ju + sum(currumns(:,s)*sinz_nyq)
1567  jv = jv + sum(currvmns(:,s)*sinz_nyq)
1568  END IF
1569 
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
1574  END DO
1575  END DO
1576  END DO
1577 !$OMP END DO
1578 
1579  DEALLOCATE(cosv, sinv)
1580  DEALLOCATE(cosz, sinz)
1581  DEALLOCATE(cosv_nyq, sinv_nyq)
1582  DEALLOCATE(cosz_nyq)
1583  IF (lasym) THEN
1584  DEALLOCATE(sinz_nyq)
1585  END IF
1586 
1587 !$OMP END PARALLEL
1588 
1589  this%magnetic_cache%zsuv = this%magnetic_cache%zsuv &
1590  & + this%z_offset
1591 
1592  DEALLOCATE(cosu, sinu)
1593  DEALLOCATE(cosu_nyq, sinu_nyq)
1594  END IF
1595 
1596 ! Compute the conducting shell if needed. If the kruv array is associated, the
1597 ! the conducting shell is being used. The total conducting shell signal for a
1598 ! magnetic diagnostic is
1599 !
1600 ! S_i = AreaIntegral K(u,v) . R_i(u,v) da (1)
1601 !
1602 ! For now, It will be assumed that the last closed flux surface of the plasma
1603 ! is the conducting shell. This can be refined later. The total magnetic signal
1604 ! in flux coordinates becomes
1605 !
1606 ! S_i = AreaIntegral (-e^s/|e^s| X B/mu0) . R_i * |J||e^s|dudv (2)
1607 !
1608 ! Using the idenity e^s = 1/J*e_u X e_v equation 2 becomes
1609 !
1610 ! S_i = AreaIntegral -e_u X e_v X B/mu0 . R_i |J|/J dudv (3)
1611 !
1612 ! From the triple cross product idenity equation 3 reduces to
1613 !
1614 ! S_i = AreaIntegral -1/mu0(B_u e_v - B_v e_u) . R_i |J|/J dudv (4)
1615 !
1616 ! Computing the conducting shell surface current is simply.
1617 !
1618 ! K(u,v) = -1/mu0(B_u*e_v - B_v*e_u) (5)
1619 !
1620 ! NOTE: The shell current cannot be used with the Z position shift.
1621 !
1622 ! NOTE: Equation 2.5.49a in "Flux Coordinates and Magnetic Field Structure" by
1623 ! W.D.D'haeseleer, W.N.G.Hitchon, J.D.Callen and J.L.Shohet assumes a
1624 ! positive jacobian. The correct equation should be
1625 !
1626 ! dS(i)=|J||e^i| du^j dv^k
1627 !
1628 ! As a result the signal due to the conducting shell contains a |J|/J
1629 ! term. The sign of the jacobian needs to be taken into account. This is
1630 ! taken care of in vmec_get_area_int_element.
1631 !
1632 ! Compute virtual casing points if needed, If the kruv_full array is
1633 ! associated, the point magnetics are being used. The total signal for a point
1634 ! is
1635 !
1636 ! B(x) = mu0/2Pi AreaIntegral K(u,v) x (x - x')/|x - x'|^3 da (6)
1637 !
1638 ! The surface used is the last closed flux surface. Simular to the procedure
1639 ! for the conducting shell, the different area element and surface current in
1640 ! equation 2 reduce the point field to.
1641 !
1642 ! B(x) = mu0/2Pi AreaIntegral -1/mu0(B_u*e_v - B_v*e_u)
1643 ! x (x - x')/|x - x'|^3 |J|/J dudv (7)
1644 !
1645 ! Computing the virtual casing surface current is simply.
1646 !
1647 ! K(u,v) = -1/mu0(B_u*e_v - B_v*e_u)
1648 !
1649 ! NOTE: Unlike the shell current, the virtual casing can be used with the Z
1650 ! position shift.
1651 
1652  IF (ASSOCIATED(this%magnetic_cache%kruv) .or. &
1653  & ASSOCIATED(this%magnetic_cache%kxuv_full)) THEN
1654 ! Interpolate the b_u and b_v onto the last closed flux surface. This
1655 ! interpolation follows what is outlined in tosuvspace. For odd modes
1656 ! X ~ SQRT(s) so interpolate Xmn/SQRT(s)
1657  woddlow = 0.5*sqrt((ns - 1.0)/(ns - 1.5))
1658  woddhigh = 1.5*sqrt((ns - 1.0)/(ns - 2.5))
1659 
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)
1664  ELSE WHERE
1665  bsubuc = woddhigh*bsubumnc(:,ns) &
1666  & - woddlow*bsubumnc(:,ns - 1)
1667  bsubvc = woddhigh*bsubvmnc(:,ns) &
1668  & - woddlow*bsubvmnc(:,ns - 1)
1669  END WHERE
1670 
1671  IF (lasym) THEN
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)
1676  ELSE WHERE
1677  bsubus = woddhigh*bsubumns(:,ns) &
1678  & - woddlow*bsubumns(:,ns - 1)
1679  bsubvs = woddhigh*bsubvmns(:,ns) &
1680  & - woddlow*bsubvmns(:,ns - 1)
1681  END WHERE
1682  END IF
1683  END IF
1684 
1685  IF (ASSOCIATED(this%magnetic_cache%kruv)) THEN
1686  numu = SIZE(this%magnetic_cache%kruv, 1)
1687  numv = SIZE(this%magnetic_cache%kruv, 2)
1688 
1689  ALLOCATE(cosu(mnmax, numu), sinu(mnmax, numu))
1690  ALLOCATE(cosu_nyq(mnmax_nyq, numu), sinu_nyq(mnmax_nyq, numu))
1691 
1692 ! U grid is square with the s grid.
1698 !$OMP PARALLEL
1699 !$OMP& DEFAULT(SHARED)
1700 !$OMP& PRIVATE(u,v,cosz,sinz,cosz_nyq,sinz_nyq,ru,zu,rv,zv,bu,bv,r,
1701 !$OMP& cosv,sinv,cosv_nyq,sinv_nyq,phi,theta)
1702 !$OMP DO
1703 !$OMP& SCHEDULE(STATIC)
1704  DO u = 1, 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)
1710  END DO
1711 !$OMP END DO
1712 
1713 ! Arrays need to be allocated within the parallel section since each thread
1714 ! requires its own allocation.
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))
1719  IF (lasym) THEN
1720  ALLOCATE(sinz_nyq(mnmax_nyq))
1721  END IF
1722 
1723 ! U grid is square with the v grid.
1726 !$OMP DO
1727 !$OMP& SCHEDULE(STATIC)
1728  DO v = 1, numv
1729  phi = (v - 1)*this%magnetic_cache%dv_a + this%phi_offset
1730 
1731  cosv = cos(xn*phi)
1732  sinv = sin(xn*phi)
1733  cosv_nyq = cos(xn_nyq*phi)
1734  sinv_nyq = sin(xn_nyq*phi)
1735 
1736  DO u = 1, numu
1737 
1738  cosz = cosu(:,u)*cosv + sinu(:,u)*sinv
1739  sinz = sinu(:,u)*cosv - cosu(:,u)*sinv
1740 
1741  cosz_nyq = cosu_nyq(:,u)*cosv_nyq &
1742  & + sinu_nyq(:,u)*sinv_nyq
1743 
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)
1749 
1750  bu = sum(bsubuc*cosz_nyq)
1751  bv = sum(bsubvc*cosz_nyq)
1752 
1753  IF (lasym) THEN
1754  sinz_nyq = sinu_nyq(:,u)*cosv_nyq &
1755  & - cosu_nyq(:,u)*sinv_nyq
1756 
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)
1762 
1763  bu = bu + sum(bsubus*sinz_nyq)
1764  bv = bv + sum(bsubvs*sinz_nyq)
1765  END IF
1766 
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)
1770  END DO
1771  END DO
1772 !$OMP END DO
1773 
1774  DEALLOCATE(cosv, sinv)
1775  DEALLOCATE(cosz, sinz)
1776  DEALLOCATE(cosv_nyq, sinv_nyq)
1777  DEALLOCATE(cosz_nyq)
1778  IF (lasym) THEN
1779  DEALLOCATE(sinz_nyq)
1780  END IF
1781 
1782 !$OMP END PARALLEL
1783 
1784  DEALLOCATE(cosu, sinu)
1785  DEALLOCATE(cosu_nyq, sinu_nyq)
1786  END IF
1787 
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)
1791 
1792  ALLOCATE(cosu(mnmax, numu), sinu(mnmax, numu))
1793  ALLOCATE(cosu_nyq(mnmax_nyq, numu), sinu_nyq(mnmax_nyq, numu))
1794 
1800 !$OMP PARALLEL
1801 !$OMP& DEFAULT(SHARED)
1802 !$OMP& PRIVATE(u,v,cosz,sinz,cosz_nyq,sinz_nyq,ru,zu,rv,zv,bu,bv,r, z,
1803 !$OMP& cosv,sinv,cosv_nyq,sinv_nyq,phi,theta,kr,kphi,i,
1804 !$OMP& cosphi,sinphi)
1805 !$OMP DO
1806 !$OMP& SCHEDULE(STATIC)
1807  DO u = 1, 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)
1813  END DO
1814 !$OMP END DO
1815 
1816 ! Arrays need to be allocated within the parallel section since each thread
1817 ! requires its own allocation.
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))
1822  IF (lasym) THEN
1823  ALLOCATE(sinz_nyq(mnmax_nyq))
1824  END IF
1825 
1828 !$OMP DO
1829 !$OMP& SCHEDULE(STATIC)
1830  DO v = 1, numv
1831 ! Rotate the signal with respect to a fixed plasma. The phi and z offsets are
1832 ! applied in vmec_get_ext_b_plasma.
1833  phi = (v - 1)*this%magnetic_cache%dv_full
1834 
1835  cosphi = cos(phi)
1836  sinphi = sin(phi)
1837  cosv = cos(xn*phi)
1838  sinv = sin(xn*phi)
1839  cosv_nyq = cos(xn_nyq*phi)
1840  sinv_nyq = sin(xn_nyq*phi)
1841 
1842  DO u = 1, numu
1843 
1844  cosz = cosu(:,u)*cosv + sinu(:,u)*sinv
1845  sinz = sinu(:,u)*cosv - cosu(:,u)*sinv
1846 
1847  cosz_nyq = cosu_nyq(:,u)*cosv_nyq &
1848  & + sinu_nyq(:,u)*sinv_nyq
1849 
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)
1856 
1857  bu = sum(bsubuc*cosz_nyq)
1858  bv = sum(bsubvc*cosz_nyq)
1859 
1860  IF (lasym) THEN
1861  sinz_nyq = sinu_nyq(:,u)*cosv_nyq &
1862  & - cosu_nyq(:,u)*sinv_nyq
1863 
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)
1870 
1871  bu = bu + sum(bsubus*sinz_nyq)
1872  bv = bv + sum(bsubvs*sinz_nyq)
1873  END IF
1874 
1875  kr = -1.0/mu0*(bu*rv - bv*ru)
1876  kphi = -1.0/mu0*bu*r
1877 
1878  this%magnetic_cache%kxuv_full(u,v) = kr*cosphi &
1879  & - kphi*sinphi
1880  this%magnetic_cache%kyuv_full(u,v) = kr*sinphi &
1881  & + kphi*cosphi
1882  this%magnetic_cache%kzuv_full(u,v) = -1.0/mu0*(bu*zv - &
1883  & bv*zu)
1884 
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
1888 
1889  IF (ASSOCIATED(this%magnetic_cache%kxuv_axi)) THEN
1890  r = 0.0
1891  z = 0.0
1892  ru = 0.0
1893  zu = 0.0
1894 
1895  bu = 0.0
1896  bv = 0.0
1897 
1898  DO i = 1, SIZE(xn)
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)
1904  END IF
1905  END DO
1906 
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)
1911  END IF
1912  END DO
1913 
1914  IF (lasym) THEN
1915  DO i = 1, SIZE(xn)
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)
1921  END IF
1922  END DO
1923 
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)
1928  END IF
1929  END DO
1930  END IF
1931 
1932  kr = 1.0/mu0*bv*ru
1933  kphi = -1.0/mu0*bu*r
1934 
1935  this%magnetic_cache%kxuv_axi(u,v) = kr*cosphi &
1936  & - kphi*sinphi
1937  this%magnetic_cache%kyuv_axi(u,v) = kr*sinphi &
1938  & + kphi*cosphi
1939  this%magnetic_cache%kzuv_axi(u,v) = 1.0/mu0*bv*zu
1940 
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
1944 
1945  END IF
1946  END DO
1947  END DO
1948 !$OMP END DO
1949 
1950  DEALLOCATE(cosv, sinv)
1951  DEALLOCATE(cosz, sinz)
1952  DEALLOCATE(cosv_nyq, sinv_nyq)
1953  DEALLOCATE(cosz_nyq)
1954  IF (lasym) THEN
1955  DEALLOCATE(sinz_nyq)
1956  END IF
1957 
1958 !$OMP END PARALLEL
1959 
1960  DEALLOCATE(cosu, sinu)
1961  DEALLOCATE(cosu_nyq, sinu_nyq)
1962  END IF
1963 
1964  IF (ASSOCIATED(this%magnetic_cache%kruv) .or. &
1965  & ASSOCIATED(this%magnetic_cache%kzuv_full)) THEN
1966  DEALLOCATE(bsubuc, bsubvc)
1967 
1968  IF (lasym) THEN
1969  DEALLOCATE(bsubus, bsubvs)
1970  END IF
1971  END IF
1972 
1973  CALL profiler_set_stop_time('vmec_set_magnetic_cache_calc', &
1974  & start_time)
1975 
1976  END SUBROUTINE
1977 
1978 !-------------------------------------------------------------------------------
1985 !-------------------------------------------------------------------------------
1986  SUBROUTINE vmec_set_namelist(this)
1987  USE read_wout_mod, only: rmnc, rmns, zmnc, zmns, xm, xn, mnmax
1988  USE vmec_input
1989 
1990  IMPLICIT NONE
1991 
1992 ! Declare Arguments
1993  TYPE (vmec_class), INTENT(in) :: this
1994 
1995 ! local variables
1996  INTEGER :: i
1997  REAL (rprec) :: start_time
1998 
1999 ! Start of executable code
2000  start_time = profiler_get_start_time()
2001 
2002 ! Write out the final namelist input file.
2003 ! Update the boundary from the free boundary solution.
2004 
2005  IF (lfreeb) THEN
2006  DO i = 1, mnmax
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))
2011  IF (lasym) THEN
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))
2016  END IF
2017  END DO
2018  END IF
2019 
2020 ! Update the magnetic axis.
2021  raxis_cc(0:ntor) = rmnc(1:ntor + 1,1)
2022  zaxis_cs(0:ntor) = zmns(1:ntor + 1,1)
2023  IF (lasym) THEN
2024  raxis_cs(0:ntor) = rmns(1:ntor + 1,1)
2025  zaxis_cc(0:ntor) = zmnc(1:ntor + 1,1)
2026  END IF
2027 
2028  CALL profiler_set_stop_time('vmec_set_namelist', start_time)
2029 
2030  END SUBROUTINE
2031 
2032 !*******************************************************************************
2033 ! GETTER SUBROUTINES
2034 !*******************************************************************************
2035 !-------------------------------------------------------------------------------
2043 !-------------------------------------------------------------------------------
2044  FUNCTION vmec_get_param_id(this, param_name)
2046  IMPLICIT NONE
2047 
2048 ! Declare Arguments
2049  INTEGER :: vmec_get_param_id
2050  TYPE (vmec_class), INTENT(in) :: this
2051  CHARACTER (len=*), INTENT(in) :: param_name
2052 
2053 ! local variables
2054  REAL (rprec) :: start_time
2055 
2056 ! Start of executable code
2057  start_time = profiler_get_start_time()
2058 
2059  SELECT CASE (trim(param_name))
2060 
2061  CASE ('ac')
2063 
2064  CASE ('ac_aux_s')
2066 
2067  CASE ('ac_aux_f')
2069 
2070  CASE ('ai')
2072 
2073  CASE ('ai_aux_s')
2075 
2076  CASE ('ai_aux_f')
2078 
2079  CASE ('am')
2081 
2082  CASE ('am_aux_s')
2084 
2085  CASE ('am_aux_f')
2087 
2088  CASE ('bloat')
2090 
2091  CASE ('rbc')
2093 
2094  CASE ('zbs')
2096 
2097  CASE ('rbs')
2099 
2100  CASE ('zbc')
2102 
2103  CASE ('extcur')
2105 
2106  CASE ('curtor')
2108 
2109  CASE ('phiedge')
2111 
2112  CASE ('pres_scale')
2114 
2115  CASE ('rmnc')
2117 
2118  CASE ('zmns')
2120 
2121  CASE ('lmns')
2123 
2124  CASE ('gmnc')
2126 
2127  CASE ('bsubumnc')
2129 
2130  CASE ('bsubvmnc')
2132 
2133  CASE ('bsubsmns')
2135 
2136  CASE ('bsupumnc')
2138 
2139  CASE ('bsupvmnc')
2141 
2142  CASE ('rmns')
2144 
2145  CASE ('zmnc')
2147 
2148  CASE ('lmnc')
2150 
2151  CASE ('gmns')
2153 
2154  CASE ('bsubumns')
2156 
2157  CASE ('bsubvmns')
2159 
2160  CASE ('bsubsmnc')
2162 
2163  CASE ('bsupumns')
2165 
2166  CASE ('bsupvmns')
2168 
2169  CASE ('phi')
2171 
2172  CASE ('iotaf')
2174 
2175  CASE ('iotas')
2177 
2178  CASE ('raxis_cc')
2180 
2181  CASE ('raxis_cs')
2183 
2184  CASE ('zaxis_cc')
2186 
2187  CASE ('zaxis_cs')
2189 
2190  CASE ('qfact')
2192 
2193  CASE ('pp_ne_b')
2195 
2196  CASE ('pp_ne_as')
2198 
2199  CASE ('pp_ne_af')
2201 
2202  CASE ('pp_sxrem_b_a')
2204 
2205  CASE ('pp_sxrem_as_a')
2207 
2208  CASE ('pp_sxrem_af_a')
2210 
2211  CASE ('pp_te_b')
2213 
2214  CASE ('pp_te_as')
2216 
2217  CASE ('pp_te_af')
2219 
2220  CASE ('pp_ti_b')
2222 
2223  CASE ('pp_ti_as')
2225 
2226  CASE ('pp_ti_af')
2228 
2229  CASE ('pp_ze_b')
2231 
2232  CASE ('pp_ze_as')
2234 
2235  CASE ('pp_ze_af')
2237 
2238  CASE ('vvc_smaleli')
2240 
2241  CASE ('vvc_kappa_p')
2243 
2244  CASE ('betatot')
2246 
2247  CASE ('betapol')
2249 
2250  CASE ('betator')
2252 
2253  CASE ('betaxis')
2255 
2256  CASE ('jcuru')
2258 
2259  CASE ('jcurv')
2261 
2262  CASE ('jdotb')
2264 
2265  CASE ('phi_offset')
2267 
2268  CASE ('z_offset')
2270 
2271  CASE DEFAULT
2272  WRITE (*,1000) trim(param_name)
2273  CALL exit(1)
2274 
2275  END SELECT
2276 
2277  CALL profiler_set_stop_time('vmec_get_param_id', start_time)
2278 
2279 1000 FORMAT('ERROR: ',a,' is not a valid parameter.')
2280 
2281  END FUNCTION
2282 
2283 !-------------------------------------------------------------------------------
2293 !-------------------------------------------------------------------------------
2294  FUNCTION vmec_get_param_value(this, id, i_index, j_index)
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, &
2300  & bloat
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
2309  USE v3f_vmec_comm
2310 
2311  IMPLICIT NONE
2312 
2313 ! Declare Arguments
2314  REAL (rprec) :: vmec_get_param_value
2315  TYPE (vmec_class), INTENT(in) :: this
2316  INTEGER, INTENT(in) :: id
2317  INTEGER, INTENT(in) :: i_index
2318  INTEGER, INTENT(in) :: j_index
2319 
2320 ! local variables
2321  REAL (rprec) :: start_time
2322 
2323 ! Start of executable code
2324  start_time = profiler_get_start_time()
2325 
2326  SELECT CASE (id)
2327 
2328  CASE (vmec_ac_id)
2329  vmec_get_param_value = ac(i_index)
2330 
2331  CASE (vmec_ac_aux_s_id)
2332  vmec_get_param_value = ac_aux_s(i_index)
2333 
2334  CASE (vmec_ac_aux_f_id)
2335  vmec_get_param_value = ac_aux_f(i_index)
2336 
2337  CASE (vmec_ai_id)
2338  vmec_get_param_value = ai(i_index)
2339 
2340  CASE (vmec_ai_aux_s_id)
2341  vmec_get_param_value = ai_aux_s(i_index)
2342 
2343  CASE (vmec_ai_aux_f_id)
2344  vmec_get_param_value = ai_aux_f(i_index)
2345 
2346  CASE (vmec_am_id)
2347  vmec_get_param_value = am(i_index)
2348 
2349  CASE (vmec_am_aux_s_id)
2350  vmec_get_param_value = am_aux_s(i_index)
2351 
2352  CASE (vmec_am_aux_f_id)
2353  vmec_get_param_value = am_aux_f(i_index)
2354 
2355  CASE (vmec_bloat_id)
2356  vmec_get_param_value = bloat
2357 
2358  CASE (vmec_rbc_id)
2359  vmec_get_param_value = rbc(i_index, j_index)
2360 
2361  CASE (vmec_zbs_id)
2362  vmec_get_param_value = zbs(i_index, j_index)
2363 
2364  CASE (vmec_rbs_id)
2365  vmec_get_param_value = rbs(i_index, j_index)
2366 
2367  CASE (vmec_zbc_id)
2368  vmec_get_param_value = zbc(i_index, j_index)
2369 
2370  CASE (vmec_extcur_id)
2371  vmec_get_param_value = extcur(i_index)
2372 
2373  CASE (vmec_curtor_id)
2374  vmec_get_param_value = curtor
2375 
2376  CASE (vmec_phiedge_id)
2377  vmec_get_param_value = phiedge
2378 
2379  CASE (vmec_pres_scale_id)
2380  vmec_get_param_value = pres_scale
2381 
2382  CASE (vmec_rmnc_id)
2383  vmec_get_param_value = rmnc(i_index, j_index)
2384 
2385  CASE (vmec_zmns_id)
2386  vmec_get_param_value = zmns(i_index, j_index)
2387 
2388  CASE (vmec_lmns_id)
2389  vmec_get_param_value = lmns(i_index, j_index)
2390 
2391  CASE (vmec_gmnc_id)
2392  vmec_get_param_value = gmnc(i_index, j_index)
2393 
2394  CASE (vmec_bsubumnc_id)
2395  vmec_get_param_value = bsubumnc(i_index, j_index)
2396 
2397  CASE (vmec_bsubvmnc_id)
2398  vmec_get_param_value = bsubvmnc(i_index, j_index)
2399 
2400  CASE (vmec_bsubsmns_id)
2401  vmec_get_param_value = bsubsmns(i_index, j_index)
2402 
2403  CASE (vmec_bsupumnc_id)
2404  vmec_get_param_value = bsupumnc(i_index, j_index)
2405 
2406  CASE (vmec_bsupvmnc_id)
2407  vmec_get_param_value = bsupvmnc(i_index, j_index)
2408 
2409  CASE (vmec_rmns_id)
2410  vmec_get_param_value = rmns(i_index, j_index)
2411 
2412  CASE (vmec_zmnc_id)
2413  vmec_get_param_value = zmnc(i_index, j_index)
2414 
2415  CASE (vmec_lmnc_id)
2416  vmec_get_param_value = lmnc(i_index, j_index)
2417 
2418  CASE (vmec_gmns_id)
2419  vmec_get_param_value = gmns(i_index, j_index)
2420 
2421  CASE (vmec_bsubumns_id)
2422  vmec_get_param_value = bsubumns(i_index, j_index)
2423 
2424  CASE (vmec_bsubvmns_id)
2425  vmec_get_param_value = bsubvmns(i_index, j_index)
2426 
2427  CASE (vmec_bsubsmnc_id)
2428  vmec_get_param_value = bsubsmnc(i_index, j_index)
2429 
2430  CASE (vmec_bsupumns_id)
2431  vmec_get_param_value = bsupumns(i_index, j_index)
2432 
2433  CASE (vmec_bsupvmns_id)
2434  vmec_get_param_value = bsupvmns(i_index, j_index)
2435 
2436  CASE (vmec_phi_id)
2437  vmec_get_param_value = phi(i_index)
2438 
2439  CASE (vmec_iotaf_id)
2440  vmec_get_param_value = iotaf(i_index)
2441 
2442  CASE (vmec_iotas_id)
2443  vmec_get_param_value = iotas(i_index)
2444 
2445  CASE (vmec_raxis_cc_id)
2446  vmec_get_param_value = raxis(i_index, 1)
2447 
2448  CASE (vmec_raxis_cs_id)
2449  vmec_get_param_value = raxis(i_index, 2)
2450 
2451  CASE (vmec_zaxis_cc_id)
2452  vmec_get_param_value = zaxis(i_index, 2)
2453 
2454  CASE (vmec_zaxis_cs_id)
2455  vmec_get_param_value = zaxis(i_index, 1)
2456 
2457  CASE (vmec_qfact_id)
2458  vmec_get_param_value = qfact(i_index)
2459 
2460  CASE (vmec_pp_ne_b_id)
2461  vmec_get_param_value = this%ne%b(i_index)
2462 
2463  CASE (vmec_pp_ne_as_id)
2464  vmec_get_param_value = this%ne%as(i_index)
2465 
2466  CASE (vmec_pp_ne_af_id)
2467  vmec_get_param_value = this%ne%af(i_index)
2468 
2469  CASE (vmec_pp_sxrem_b_id)
2470  vmec_get_param_value = this%sxrem(i_index)%p%b(j_index)
2471 
2472  CASE (vmec_pp_sxrem_as_id)
2473  vmec_get_param_value = this%sxrem(i_index)%p%as(j_index)
2474 
2475  CASE (vmec_pp_sxrem_af_id)
2476  vmec_get_param_value = this%sxrem(i_index)%p%af(j_index)
2477 
2478  CASE (vmec_pp_te_b_id)
2479  vmec_get_param_value = this%te%b(i_index)
2480 
2481  CASE (vmec_pp_te_as_id)
2482  vmec_get_param_value = this%te%as(i_index)
2483 
2484  CASE (vmec_pp_te_af_id)
2485  vmec_get_param_value = this%te%af(i_index)
2486 
2487  CASE (vmec_pp_ti_b_id)
2488  vmec_get_param_value = this%ti%b(i_index)
2489 
2490  CASE (vmec_pp_ti_as_id)
2491  vmec_get_param_value = this%ti%as(i_index)
2492 
2493  CASE (vmec_pp_ti_af_id)
2494  vmec_get_param_value = this%ti%af(i_index)
2495 
2496  CASE (vmec_pp_ze_b_id)
2497  vmec_get_param_value = this%ze%b(i_index)
2498 
2499  CASE (vmec_pp_ze_as_id)
2500  vmec_get_param_value = this%ze%as(i_index)
2501 
2502  CASE (vmec_pp_ze_af_id)
2503  vmec_get_param_value = this%ze%af(i_index)
2504 
2505  CASE (vmec_vvc_smaleli_id)
2506  vmec_get_param_value = vvc_smaleli
2507 
2508  CASE (vmec_vvc_kappa_p_id)
2509  vmec_get_param_value = vvc_kappa_p
2510 
2511  CASE (vmec_betatot_id)
2512  vmec_get_param_value = betatot
2513 
2514  CASE (vmec_betapol_id)
2515  vmec_get_param_value = betapol
2516 
2517  CASE (vmec_betator_id)
2518  vmec_get_param_value = betator
2519 
2520  CASE (vmec_betaxis_id)
2521  vmec_get_param_value = betaxis
2522 
2523  CASE (vmec_jcuru_id)
2524  vmec_get_param_value = jcuru(i_index)
2525 
2526  CASE (vmec_jcurv_id)
2527  vmec_get_param_value = jcurv(i_index)
2528 
2529  CASE (vmec_jdotb_id)
2530  vmec_get_param_value = jdotb(i_index)
2531 
2532  CASE (vmec_phi_offset_id)
2533  vmec_get_param_value = this%phi_offset
2534 
2535  CASE (vmec_z_offset_id)
2536  vmec_get_param_value = this%z_offset
2537 
2538  CASE DEFAULT
2539  vmec_get_param_value = 0.0
2540 
2541  END SELECT
2542 
2543  CALL profiler_set_stop_time('vmec_get_param_value', start_time)
2544 
2545  END FUNCTION
2546 
2547 !-------------------------------------------------------------------------------
2555 !-------------------------------------------------------------------------------
2556  FUNCTION vmec_get_param_name(this, id)
2558  IMPLICIT NONE
2559 
2560 ! Declare Arguments
2561  CHARACTER(len=data_name_length) :: vmec_get_param_name
2562  TYPE (vmec_class), INTENT(in) :: this
2563  INTEGER, INTENT(in) :: id
2564 
2565 ! local variables
2566  REAL (rprec) :: start_time
2567 
2568 ! Start of executable code
2569  start_time = profiler_get_start_time()
2570 
2571  SELECT CASE (id)
2572 
2573  CASE (vmec_ac_id)
2574  vmec_get_param_name = 'ac'
2575 
2576  CASE (vmec_ac_aux_s_id)
2577  vmec_get_param_name = 'ac_aux_s'
2578 
2579  CASE (vmec_ac_aux_f_id)
2580  vmec_get_param_name = 'ac_aux_f'
2581 
2582  CASE (vmec_ai_id)
2583  vmec_get_param_name = 'ai'
2584 
2585  CASE (vmec_ai_aux_s_id)
2586  vmec_get_param_name = 'ai_aux_s'
2587 
2588  CASE (vmec_ai_aux_f_id)
2589  vmec_get_param_name = 'ai_aux_f'
2590 
2591  CASE (vmec_am_id)
2592  vmec_get_param_name = 'am'
2593 
2594  CASE (vmec_am_aux_s_id)
2595  vmec_get_param_name = 'am_aux_s'
2596 
2597  CASE (vmec_am_aux_f_id)
2598  vmec_get_param_name = 'am_aux_f'
2599 
2600  CASE (vmec_bloat_id)
2601  vmec_get_param_name = 'bloat'
2602 
2603  CASE (vmec_rbc_id)
2604  vmec_get_param_name = 'rbc'
2605 
2606  CASE (vmec_zbs_id)
2607  vmec_get_param_name = 'zbs'
2608 
2609  CASE (vmec_rbs_id)
2610  vmec_get_param_name = 'rbs'
2611 
2612  CASE (vmec_zbc_id)
2613  vmec_get_param_name = 'zbc'
2614 
2615  CASE (vmec_extcur_id)
2616  vmec_get_param_name = 'extcur'
2617 
2618  CASE (vmec_curtor_id)
2619  vmec_get_param_name = 'curtor'
2620 
2621  CASE (vmec_phiedge_id)
2622  vmec_get_param_name = 'phiedge'
2623 
2624  CASE (vmec_pres_scale_id)
2625  vmec_get_param_name = 'pres_scale'
2626 
2627  CASE (vmec_rmnc_id)
2628  vmec_get_param_name = 'rmnc'
2629 
2630  CASE (vmec_zmns_id)
2631  vmec_get_param_name = 'zmns'
2632 
2633  CASE (vmec_lmns_id)
2634  vmec_get_param_name = 'lmns'
2635 
2636  CASE (vmec_gmnc_id)
2637  vmec_get_param_name = 'gmnc'
2638 
2639  CASE (vmec_bsubumnc_id)
2640  vmec_get_param_name = 'bsubumnc'
2641 
2642  CASE (vmec_bsubvmnc_id)
2643  vmec_get_param_name = 'bsubvmnc'
2644 
2645  CASE (vmec_bsubsmns_id)
2646  vmec_get_param_name = 'bsubsmns'
2647 
2648  CASE (vmec_bsupumnc_id)
2649  vmec_get_param_name = 'bsupumnc'
2650 
2651  CASE (vmec_bsupvmnc_id)
2652  vmec_get_param_name = 'bsupvmnc'
2653 
2654  CASE (vmec_rmns_id)
2655  vmec_get_param_name = 'rmns'
2656 
2657  CASE (vmec_zmnc_id)
2658  vmec_get_param_name = 'zmnc'
2659 
2660  CASE (vmec_lmnc_id)
2661  vmec_get_param_name = 'lmnc'
2662 
2663  CASE (vmec_gmns_id)
2664  vmec_get_param_name = 'gmns'
2665 
2666  CASE (vmec_bsubumns_id)
2667  vmec_get_param_name = 'bsubumns'
2668 
2669  CASE (vmec_bsubvmns_id)
2670  vmec_get_param_name = 'bsubvmns'
2671 
2672  CASE (vmec_bsubsmnc_id)
2673  vmec_get_param_name = 'bsubsmnc'
2674 
2675  CASE (vmec_bsupumns_id)
2676  vmec_get_param_name = 'bsupumns'
2677 
2678  CASE (vmec_bsupvmns_id)
2679  vmec_get_param_name = 'bsupvmns'
2680 
2681  CASE (vmec_phi_id)
2682  vmec_get_param_name = 'phi'
2683 
2684  CASE (vmec_iotaf_id)
2685  vmec_get_param_name = 'iotaf'
2686 
2687  CASE (vmec_iotas_id)
2688  vmec_get_param_name = 'iotas'
2689 
2690  CASE (vmec_raxis_cc_id)
2691  vmec_get_param_name = 'raxis_cc'
2692 
2693  CASE (vmec_raxis_cs_id)
2694  vmec_get_param_name = 'raxis_cs'
2695 
2696  CASE (vmec_zaxis_cc_id)
2697  vmec_get_param_name = 'zaxis_cc'
2698 
2699  CASE (vmec_zaxis_cs_id)
2700  vmec_get_param_name = 'zaxis_cs'
2701 
2702  CASE (vmec_qfact_id)
2703  vmec_get_param_name = 'qfact'
2704 
2705  CASE (vmec_pp_ne_b_id)
2706  vmec_get_param_name = 'pp_ne_b'
2707 
2708  CASE (vmec_pp_ne_as_id)
2709  vmec_get_param_name = 'pp_ne_as'
2710 
2711  CASE (vmec_pp_ne_af_id)
2712  vmec_get_param_name = 'pp_ne_af'
2713 
2714  CASE (vmec_pp_sxrem_b_id)
2715  vmec_get_param_name = 'pp_sxrem_b_a'
2716 
2717  CASE (vmec_pp_sxrem_as_id)
2718  vmec_get_param_name = 'pp_sxrem_as_a'
2719 
2720  CASE (vmec_pp_sxrem_af_id)
2721  vmec_get_param_name = 'pp_sxrem_af_a'
2722 
2723  CASE (vmec_pp_te_b_id)
2724  vmec_get_param_name = 'pp_te_b'
2725 
2726  CASE (vmec_pp_te_as_id)
2727  vmec_get_param_name = 'pp_te_as'
2728 
2729  CASE (vmec_pp_te_af_id)
2730  vmec_get_param_name = 'pp_te_af'
2731 
2732  CASE (vmec_pp_ti_b_id)
2733  vmec_get_param_name = 'pp_ti_b'
2734 
2735  CASE (vmec_pp_ti_as_id)
2736  vmec_get_param_name = 'pp_ti_as'
2737 
2738  CASE (vmec_pp_ti_af_id)
2739  vmec_get_param_name = 'pp_ti_af'
2740 
2741  CASE (vmec_pp_ze_b_id)
2742  vmec_get_param_name = 'pp_ze_b'
2743 
2744  CASE (vmec_pp_ze_as_id)
2745  vmec_get_param_name = 'pp_ze_as'
2746 
2747  CASE (vmec_pp_ze_af_id)
2748  vmec_get_param_name = 'pp_ze_af'
2749 
2750  CASE (vmec_vvc_smaleli_id)
2751  vmec_get_param_name = 'vvc_smaleli'
2752 
2753  CASE (vmec_vvc_kappa_p_id)
2754  vmec_get_param_name = 'vvc_kappa_p'
2755 
2756  CASE (vmec_betatot_id)
2757  vmec_get_param_name = 'betatot'
2758 
2759  CASE (vmec_betapol_id)
2760  vmec_get_param_name = 'betapol'
2761 
2762  CASE (vmec_betator_id)
2763  vmec_get_param_name = 'betator'
2764 
2765  CASE (vmec_betaxis_id)
2766  vmec_get_param_name = 'betaxis'
2767 
2768  CASE (vmec_jcuru_id)
2769  vmec_get_param_name = 'jcuru'
2770 
2771  CASE (vmec_jcurv_id)
2772  vmec_get_param_name = 'jcurv'
2773 
2774  CASE (vmec_jdotb_id)
2775  vmec_get_param_name = 'jdotb'
2776 
2777  CASE (vmec_phi_offset_id)
2778  vmec_get_param_name = 'phi_offset'
2779 
2780  CASE (vmec_z_offset_id)
2781  vmec_get_param_name = 'z_offset'
2782 
2783  CASE DEFAULT
2784  WRITE (*,*) id
2785  stop 'Invalid VMEC parameter id.'
2786 
2787  END SELECT
2788 
2789  CALL profiler_set_stop_time('vmec_get_param_name', start_time)
2790 
2791  END FUNCTION
2792 
2793 !-------------------------------------------------------------------------------
2802 !-------------------------------------------------------------------------------
2803  FUNCTION vmec_get_gp_ne_num_hyper_param(this)
2805  IMPLICIT NONE
2806 
2807 ! Declare Arguments
2809  TYPE (vmec_class), INTENT(in) :: this
2810 
2811 ! local variables
2812  REAL (rprec) :: start_time
2813 
2814 ! Start of executable code
2815  start_time = profiler_get_start_time()
2816 
2817  IF (ASSOCIATED(this%ne)) THEN
2820  ELSE
2822  END IF
2823 
2824  CALL profiler_set_stop_time('vmec_get_gp_ne_num_hyper_param', &
2825  & start_time)
2826 
2827  END FUNCTION
2828 
2829 !-------------------------------------------------------------------------------
2837 !-------------------------------------------------------------------------------
2838  FUNCTION vmec_get_ne_af(this)
2840  IMPLICIT NONE
2841 
2842 ! Declare Arguments
2843  REAL (rprec), DIMENSION(:), POINTER :: vmec_get_ne_af
2844  TYPE (vmec_class), INTENT(in) :: this
2845 
2846 ! local variables
2847  REAL (rprec) :: start_time
2848 
2849 ! Start of executable code
2850  start_time = profiler_get_start_time()
2851 
2852  IF (ASSOCIATED(this%ne)) THEN
2853  vmec_get_ne_af => this%ne%af
2854  ELSE
2855  vmec_get_ne_af => null()
2856  END IF
2857 
2858  CALL profiler_set_stop_time('vmec_get_ne_af', start_time)
2859 
2860  END FUNCTION
2861 
2862 !-------------------------------------------------------------------------------
2872 !-------------------------------------------------------------------------------
2873  FUNCTION vmec_get_gp_ne_ij(this, i, j)
2875  IMPLICIT NONE
2876 
2877 ! Declare Arguments
2878  REAL (rprec) :: vmec_get_gp_ne_ij
2879  TYPE (vmec_class), INTENT(in) :: this
2880  INTEGER, INTENT(in) :: i
2881  INTEGER, INTENT(in) :: j
2882 
2883 ! local variables
2884  REAL (rprec) :: start_time
2885 
2886 ! Start of executable code
2887  start_time = profiler_get_start_time()
2888 
2889  IF (ASSOCIATED(this%ne)) THEN
2890  vmec_get_gp_ne_ij = pprofile_get_gp(this%ne, i, j)
2891  ELSE
2892  vmec_get_gp_ne_ij = 0.0
2893  END IF
2894 
2895  CALL profiler_set_stop_time('vmec_get_gp_ne_ij', start_time)
2896 
2897  END FUNCTION
2898 
2899 !-------------------------------------------------------------------------------
2909 !-------------------------------------------------------------------------------
2910  FUNCTION vmec_get_gp_ne_pi(this, x_cart, i)
2912  IMPLICIT NONE
2913 
2914 ! Declare Arguments
2915  REAL (rprec) :: vmec_get_gp_ne_pi
2916  TYPE (vmec_class), INTENT(in) :: this
2917  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
2918  INTEGER, INTENT(in) :: i
2919 
2920 ! local variables
2921  REAL (rprec) :: s
2922  REAL (rprec) :: start_time
2923 
2924 ! Start of executable code
2925  start_time = profiler_get_start_time()
2926 
2927  s = vmec_get_s(this, x_cart)
2928  IF (ASSOCIATED(this%ne) .and. (s .le. 1.0)) THEN
2929  vmec_get_gp_ne_pi = pprofile_get_gp(this%ne, s, i)
2930  ELSE
2931  vmec_get_gp_ne_pi = 0.0
2932  END IF
2933 
2934  CALL profiler_set_stop_time('vmec_get_gp_ne_pi', start_time)
2935 
2936  END FUNCTION
2937 
2938 !-------------------------------------------------------------------------------
2949 !-------------------------------------------------------------------------------
2950  FUNCTION vmec_get_gp_ne_pp(this, x_cart, y_cart)
2952  IMPLICIT NONE
2953 
2954 ! Declare Arguments
2955  REAL (rprec) :: vmec_get_gp_ne_pp
2956  TYPE (vmec_class), INTENT(in) :: this
2957  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
2958  REAL (rprec), DIMENSION(3), INTENT(in) :: y_cart
2959 
2960 ! local variables
2961  REAL (rprec) :: s1
2962  REAL (rprec) :: s2
2963  REAL (rprec) :: start_time
2964 
2965 ! Start of executable code
2966  start_time = profiler_get_start_time()
2967 
2968  s1 = vmec_get_s(this, x_cart)
2969  s2 = vmec_get_s(this, y_cart)
2970  IF (ASSOCIATED(this%ne) .and. (s1 .le. 1.0) .and. &
2971  & (s2 .le. 1.0)) THEN
2972  vmec_get_gp_ne_pp = pprofile_get_gp(this%ne, s1, s2)
2973  ELSE
2974  vmec_get_gp_ne_pp = 0.0
2975  END IF
2976 
2977  CALL profiler_set_stop_time('vmec_get_gp_ne_pp', start_time)
2978 
2979  END FUNCTION
2980 
2981 !-------------------------------------------------------------------------------
2990 !-------------------------------------------------------------------------------
2991  FUNCTION vmec_get_ne_cart(this, x_cart)
2993  IMPLICIT NONE
2994 
2995 ! Declare Arguments
2996  REAL (rprec) :: vmec_get_ne_cart
2997  TYPE (vmec_class), INTENT(in) :: this
2998  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
2999 
3000 ! local variables
3001  REAL (rprec) :: start_time
3002 
3003 ! Start of executable code
3004  start_time = profiler_get_start_time()
3005  vmec_get_ne_cart = vmec_get_ne(this, vmec_get_flux(this, x_cart))
3006 
3007  CALL profiler_set_stop_time('vmec_get_ne_cart', start_time)
3008 
3009  END FUNCTION
3010 
3011 !-------------------------------------------------------------------------------
3020 !-------------------------------------------------------------------------------
3021  FUNCTION vmec_get_ne_radial(this, s)
3023  IMPLICIT NONE
3024 
3025 ! Declare Arguments
3026  REAL (rprec) :: vmec_get_ne_radial
3027  TYPE (vmec_class), INTENT(in) :: this
3028  REAL (rprec), INTENT(in) :: s
3029 
3030 ! local variables
3031  REAL (rprec) :: start_time
3032 
3033 ! Start of executable code
3034  start_time = profiler_get_start_time()
3035 
3036  IF (ASSOCIATED(this%ne)) THEN
3038  ELSE
3039  vmec_get_ne_radial = 0.0
3040  END IF
3041 
3042  CALL profiler_set_stop_time('vmec_get_ne_radial', start_time)
3043 
3044  END FUNCTION
3045 
3046 !-------------------------------------------------------------------------------
3055 !-------------------------------------------------------------------------------
3056  FUNCTION vmec_get_gp_te_num_hyper_param(this)
3058  IMPLICIT NONE
3059 
3060 ! Declare Arguments
3062  TYPE (vmec_class), INTENT(in) :: this
3063 
3064 ! local variables
3065  REAL (rprec) :: start_time
3066 
3067 ! Start of executable code
3068  start_time = profiler_get_start_time()
3069 
3070  IF (ASSOCIATED(this%te)) THEN
3073  ELSE
3075  END IF
3076 
3077  CALL profiler_set_stop_time('vmec_get_gp_te_num_hyper_param', &
3078  & start_time)
3079 
3080  END FUNCTION
3081 
3082 !-------------------------------------------------------------------------------
3090 !-------------------------------------------------------------------------------
3091  FUNCTION vmec_get_te_af(this)
3093  IMPLICIT NONE
3094 
3095 ! Declare Arguments
3096  REAL (rprec), DIMENSION(:), POINTER :: vmec_get_te_af
3097  TYPE (vmec_class), INTENT(in) :: this
3098 
3099 ! local variables
3100  REAL (rprec) :: start_time
3101 
3102 ! Start of executable code
3103  start_time = profiler_get_start_time()
3104 
3105  IF (ASSOCIATED(this%te)) THEN
3106  vmec_get_te_af => this%te%af
3107  ELSE
3108  vmec_get_te_af => null()
3109  END IF
3110 
3111  CALL profiler_set_stop_time('vmec_get_te_af', start_time)
3112 
3113  END FUNCTION
3114 
3115 !-------------------------------------------------------------------------------
3125 !-------------------------------------------------------------------------------
3126  FUNCTION vmec_get_gp_te_ij(this, i, j)
3128  IMPLICIT NONE
3129 
3130 ! Declare Arguments
3131  REAL (rprec) :: vmec_get_gp_te_ij
3132  TYPE (vmec_class), INTENT(in) :: this
3133  INTEGER, INTENT(in) :: i
3134  INTEGER, INTENT(in) :: j
3135 
3136 ! local variables
3137  REAL (rprec) :: start_time
3138 
3139 ! Start of executable code
3140  start_time = profiler_get_start_time()
3141 
3142  IF (ASSOCIATED(this%te)) THEN
3143  vmec_get_gp_te_ij = pprofile_get_gp(this%te, i, j)
3144  ELSE
3145  vmec_get_gp_te_ij = 0.0
3146  END IF
3147 
3148  CALL profiler_set_stop_time('vmec_get_gp_te_ij', start_time)
3149 
3150  END FUNCTION
3151 
3152 !-------------------------------------------------------------------------------
3163 !-------------------------------------------------------------------------------
3164  FUNCTION vmec_get_gp_te_pi(this, x_cart, i)
3166  IMPLICIT NONE
3167 
3168 ! Declare Arguments
3169  REAL (rprec) :: vmec_get_gp_te_pi
3170  TYPE (vmec_class), INTENT(in) :: this
3171  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3172  INTEGER, INTENT(in) :: i
3173 
3174 ! local variables
3175  REAL (rprec) :: s
3176  REAL (rprec) :: start_time
3177 
3178 ! Start of executable code
3179  start_time = profiler_get_start_time()
3180 
3181  s = vmec_get_s(this, x_cart)
3182  IF (ASSOCIATED(this%te) .and. (s .le. 1.0)) THEN
3183  vmec_get_gp_te_pi = pprofile_get_gp(this%te, s, i)
3184  ELSE
3185  vmec_get_gp_te_pi = 0.0
3186  END IF
3187 
3188  CALL profiler_set_stop_time('vmec_get_gp_te_pi', start_time)
3189 
3190  END FUNCTION
3191 
3192 !-------------------------------------------------------------------------------
3205 !-------------------------------------------------------------------------------
3206  FUNCTION vmec_get_gp_te_pp(this, x_cart, y_cart)
3208  IMPLICIT NONE
3209 
3210 ! Declare Arguments
3211  REAL (rprec) :: vmec_get_gp_te_pp
3212  TYPE (vmec_class), INTENT(in) :: this
3213  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3214  REAL (rprec), DIMENSION(3), INTENT(in) :: y_cart
3215 
3216 ! local variables
3217  REAL (rprec) :: s1
3218  REAL (rprec) :: s2
3219  REAL (rprec) :: start_time
3220 
3221 ! Start of executable code
3222  start_time = profiler_get_start_time()
3223 
3224  s1 = vmec_get_s(this, x_cart)
3225  s2 = vmec_get_s(this, y_cart)
3226  IF (ASSOCIATED(this%te) .and. (s1 .le. 1.0) .and. &
3227  & (s2 .le. 1.0)) THEN
3228  vmec_get_gp_te_pp = pprofile_get_gp(this%te, s1, s2)
3229  ELSE
3230  vmec_get_gp_te_pp = 0.0
3231  END IF
3232 
3233  CALL profiler_set_stop_time('vmec_get_gp_te_pp', start_time)
3234 
3235  END FUNCTION
3236 
3237 !-------------------------------------------------------------------------------
3246 !-------------------------------------------------------------------------------
3247  FUNCTION vmec_get_te_cart(this, x_cart)
3249  IMPLICIT NONE
3250 
3251 ! Declare Arguments
3252  REAL (rprec) :: vmec_get_te_cart
3253  TYPE (vmec_class), INTENT(in) :: this
3254  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3255 
3256 ! local variables
3257  REAL (rprec) :: start_time
3258 
3259 ! Start of executable code
3260  start_time = profiler_get_start_time()
3261  vmec_get_te_cart = vmec_get_te(this, vmec_get_flux(this, x_cart))
3262 
3263  CALL profiler_set_stop_time('vmec_get_te_cart', start_time)
3264 
3265  END FUNCTION
3266 
3267 !-------------------------------------------------------------------------------
3276 !-------------------------------------------------------------------------------
3277  FUNCTION vmec_get_te_radial(this, s)
3279  IMPLICIT NONE
3280 
3281 ! Declare Arguments
3282  REAL (rprec) :: vmec_get_te_radial
3283  TYPE (vmec_class), INTENT(in) :: this
3284  REAL (rprec), INTENT(in) :: s
3285 
3286 ! local variables
3287  REAL (rprec) :: start_time
3288 
3289 ! Start of executable code
3290  start_time = profiler_get_start_time()
3291  IF (ASSOCIATED(this%te)) THEN
3293  ELSE
3294  vmec_get_te_radial = 0.0
3295  END IF
3296 
3297  CALL profiler_set_stop_time('vmec_get_te_radial', start_time)
3298 
3299  END FUNCTION
3300 
3301 !-------------------------------------------------------------------------------
3310 !-------------------------------------------------------------------------------
3311  FUNCTION vmec_get_gp_ti_num_hyper_param(this)
3313  IMPLICIT NONE
3314 
3315 ! Declare Arguments
3317  TYPE (vmec_class), INTENT(in) :: this
3318 
3319 ! local variables
3320  REAL (rprec) :: start_time
3321 
3322 ! Start of executable code
3323  start_time = profiler_get_start_time()
3324 
3325  IF (ASSOCIATED(this%ti)) THEN
3328  ELSE
3330  END IF
3331 
3332  CALL profiler_set_stop_time('vmec_get_gp_ti_num_hyper_param', &
3333  & start_time)
3334 
3335  END FUNCTION
3336 
3337 !-------------------------------------------------------------------------------
3345 !-------------------------------------------------------------------------------
3346  FUNCTION vmec_get_ti_af(this)
3348  IMPLICIT NONE
3349 
3350 ! Declare Arguments
3351  REAL (rprec), DIMENSION(:), POINTER :: vmec_get_ti_af
3352  TYPE (vmec_class), INTENT(in) :: this
3353 
3354 ! local variables
3355  REAL (rprec) :: start_time
3356 
3357 ! Start of executable code
3358  start_time = profiler_get_start_time()
3359 
3360  IF (ASSOCIATED(this%ti)) THEN
3361  vmec_get_ti_af => this%ti%af
3362  ELSE
3363  vmec_get_ti_af => null()
3364  END IF
3365 
3366  CALL profiler_set_stop_time('vmec_get_ti_af', start_time)
3367 
3368  END FUNCTION
3369 
3370 !-------------------------------------------------------------------------------
3380 !-------------------------------------------------------------------------------
3381  FUNCTION vmec_get_gp_ti_ij(this, i, j)
3383  IMPLICIT NONE
3384 
3385 ! Declare Arguments
3386  REAL (rprec) :: vmec_get_gp_ti_ij
3387  TYPE (vmec_class), INTENT(in) :: this
3388  INTEGER, INTENT(in) :: i
3389  INTEGER, INTENT(in) :: j
3390 
3391 ! local variables
3392  REAL (rprec) :: start_time
3393 
3394 ! Start of executable code
3395  start_time = profiler_get_start_time()
3396 
3397  IF (ASSOCIATED(this%ti)) THEN
3398  vmec_get_gp_ti_ij = pprofile_get_gp(this%ti, i, j)
3399  ELSE
3400  vmec_get_gp_ti_ij = 0.0
3401  END IF
3402 
3403  CALL profiler_set_stop_time('vmec_get_gp_ti_ij', start_time)
3404 
3405  END FUNCTION
3406 
3407 !-------------------------------------------------------------------------------
3418 !-------------------------------------------------------------------------------
3419  FUNCTION vmec_get_gp_ti_pi(this, x_cart, i)
3421  IMPLICIT NONE
3422 
3423 ! Declare Arguments
3424  REAL (rprec) :: vmec_get_gp_ti_pi
3425  TYPE (vmec_class), INTENT(in) :: this
3426  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3427  INTEGER, INTENT(in) :: i
3428 
3429 ! local variables
3430  REAL (rprec) :: s
3431  REAL (rprec) :: start_time
3432 
3433 ! Start of executable code
3434  start_time = profiler_get_start_time()
3435 
3436  s = vmec_get_s(this, x_cart)
3437  IF (ASSOCIATED(this%ti) .and. (s .le. 1.0)) THEN
3438  vmec_get_gp_ti_pi = pprofile_get_gp(this%ti, s, i)
3439  ELSE
3440  vmec_get_gp_ti_pi = 0.0
3441  END IF
3442 
3443  CALL profiler_set_stop_time('vmec_get_gp_ti_pi', start_time)
3444 
3445  END FUNCTION
3446 
3447 !-------------------------------------------------------------------------------
3458 !-------------------------------------------------------------------------------
3459  FUNCTION vmec_get_gp_ti_pp(this, x_cart, y_cart)
3461  IMPLICIT NONE
3462 
3463 ! Declare Arguments
3464  REAL (rprec) :: vmec_get_gp_ti_pp
3465  TYPE (vmec_class), INTENT(in) :: this
3466  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3467  REAL (rprec), DIMENSION(3), INTENT(in) :: y_cart
3468 
3469 ! local variables
3470  REAL (rprec) :: s1
3471  REAL (rprec) :: s2
3472  REAL (rprec) :: start_time
3473 
3474 ! Start of executable code
3475  start_time = profiler_get_start_time()
3476 
3477  s1 = vmec_get_s(this, x_cart)
3478  s2 = vmec_get_s(this, y_cart)
3479  IF (ASSOCIATED(this%ti) .and. (s1 .le. 1.0) .and. &
3480  & (s2 .le. 1.0)) THEN
3481  vmec_get_gp_ti_pp = pprofile_get_gp(this%ti, s1, s2)
3482  ELSE
3483  vmec_get_gp_ti_pp = 0.0
3484  END IF
3485 
3486  CALL profiler_set_stop_time('vmec_get_gp_ti_pp', start_time)
3487 
3488  END FUNCTION
3489 
3490 !-------------------------------------------------------------------------------
3499 !-------------------------------------------------------------------------------
3500  FUNCTION vmec_get_ti_cart(this, x_cart)
3502  IMPLICIT NONE
3503 
3504 ! Declare Arguments
3505  REAL (rprec) :: vmec_get_ti_cart
3506  TYPE (vmec_class), INTENT(in) :: this
3507  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3508 
3509 ! local variables
3510  REAL (rprec) :: start_time
3511 
3512 ! Start of executable code
3513  start_time = profiler_get_start_time()
3514  vmec_get_ti_cart = vmec_get_ti(this, vmec_get_flux(this, x_cart))
3515 
3516  CALL profiler_set_stop_time('vmec_get_ti_cart', start_time)
3517 
3518  END FUNCTION
3519 
3520 !-------------------------------------------------------------------------------
3529 !-------------------------------------------------------------------------------
3530  FUNCTION vmec_get_ti_radial(this, s)
3532  IMPLICIT NONE
3533 
3534 ! Declare Arguments
3535  REAL (rprec) :: vmec_get_ti_radial
3536  TYPE (vmec_class), INTENT(in) :: this
3537  REAL (rprec), INTENT(in) :: s
3538 
3539 ! local variables
3540  REAL (rprec) :: start_time
3541 
3542 ! Start of executable code
3543  start_time = profiler_get_start_time()
3544  IF (ASSOCIATED(this%ti)) THEN
3546  ELSE
3547  vmec_get_ti_radial = 0.0
3548  END IF
3549 
3550  CALL profiler_set_stop_time('vmec_get_ti_radial', start_time)
3551 
3552  END FUNCTION
3553 
3554 !-------------------------------------------------------------------------------
3563 !-------------------------------------------------------------------------------
3564  FUNCTION vmec_get_ze_cart(this, x_cart)
3566  IMPLICIT NONE
3567 
3568 ! Declare Arguments
3569  REAL (rprec) :: vmec_get_ze_cart
3570  TYPE (vmec_class), INTENT(in) :: this
3571  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3572 
3573 ! local variables
3574  REAL (rprec) :: start_time
3575 
3576 ! Start of executable code
3577  start_time = profiler_get_start_time()
3578  vmec_get_ze_cart = vmec_get_ze(this, vmec_get_flux(this, x_cart))
3579 
3580  CALL profiler_set_stop_time('vmec_get_ze_cart', start_time)
3581 
3582  END FUNCTION
3583 
3584 !-------------------------------------------------------------------------------
3593 !-------------------------------------------------------------------------------
3594  FUNCTION vmec_get_ze_radial(this, s)
3596  IMPLICIT NONE
3597 
3598 ! Declare Arguments
3599  REAL (rprec) :: vmec_get_ze_radial
3600  TYPE (vmec_class), INTENT(in) :: this
3601  REAL (rprec), INTENT(in) :: s
3602 
3603 ! local variables
3604  REAL (rprec) :: start_time
3605 
3606 ! Start of executable code
3607  start_time = profiler_get_start_time()
3608  IF (ASSOCIATED(this%ze)) THEN
3610  ELSE
3611  vmec_get_ze_radial = 1.0
3612  END IF
3613 
3614  CALL profiler_set_stop_time('vmec_get_ze_radial', start_time)
3615 
3616  END FUNCTION
3617 
3618 !-------------------------------------------------------------------------------
3628 !-------------------------------------------------------------------------------
3629  FUNCTION vmec_get_gp_sxrem_num_hyper_param(this, index)
3631  IMPLICIT NONE
3632 
3633 ! Declare Arguments
3635  TYPE (vmec_class), INTENT(in) :: this
3636  INTEGER, INTENT(in) :: index
3637 
3638 ! local variables
3639  REAL (rprec) :: start_time
3640 
3641 ! Start of executable code
3642  start_time = profiler_get_start_time()
3643 
3644  IF (ASSOCIATED(this%sxrem) .and. &
3645  & (index .le. SIZE(this%sxrem))) THEN
3647  & pprofile_get_gp_num_hyper_param(this%sxrem(index)%p)
3648  ELSE
3650  END IF
3651 
3652  CALL profiler_set_stop_time('vmec_get_gp_sxrem_num_hyper_param', &
3653  & start_time)
3654 
3655  END FUNCTION
3656 
3657 !-------------------------------------------------------------------------------
3666 !-------------------------------------------------------------------------------
3667  FUNCTION vmec_get_sxrem_af(this, index)
3669  IMPLICIT NONE
3670 
3671 ! Declare Arguments
3672  REAL (rprec), DIMENSION(:), POINTER :: vmec_get_sxrem_af
3673  TYPE (vmec_class), INTENT(in) :: this
3674  INTEGER, INTENT(in) :: index
3675 
3676 ! local variables
3677  REAL (rprec) :: start_time
3678 
3679 ! Start of executable code
3680  start_time = profiler_get_start_time()
3681 
3682  IF (ASSOCIATED(this%sxrem) .and. &
3683  & (index .le. SIZE(this%sxrem))) THEN
3684  vmec_get_sxrem_af => this%sxrem(index)%p%af
3685  ELSE
3686  vmec_get_sxrem_af => null()
3687  END IF
3688 
3689  CALL profiler_set_stop_time('vmec_get_sxrem_af', start_time)
3690 
3691  END FUNCTION
3692 
3693 !-------------------------------------------------------------------------------
3704 !-------------------------------------------------------------------------------
3705  FUNCTION vmec_get_gp_sxrem_ij(this, i, j, index)
3707  IMPLICIT NONE
3708 
3709 ! Declare Arguments
3710  REAL (rprec) :: vmec_get_gp_sxrem_ij
3711  TYPE (vmec_class), INTENT(in) :: this
3712  INTEGER, INTENT(in) :: i
3713  INTEGER, INTENT(in) :: j
3714  INTEGER, INTENT(in) :: index
3715 
3716 ! local variables
3717  REAL (rprec) :: start_time
3718 
3719 ! Start of executable code
3720  start_time = profiler_get_start_time()
3721 
3722  IF (ASSOCIATED(this%sxrem) .and. &
3723  & (index .le. SIZE(this%sxrem))) THEN
3725  & pprofile_get_gp(this%sxrem(index)%p, i, j)
3726  ELSE
3727  vmec_get_gp_sxrem_ij = 0.0
3728  END IF
3729 
3730  CALL profiler_set_stop_time('vmec_get_gp_sxrem_ij', start_time)
3731 
3732  END FUNCTION
3733 
3734 !-------------------------------------------------------------------------------
3746 !-------------------------------------------------------------------------------
3747  FUNCTION vmec_get_gp_sxrem_pi(this, x_cart, i, index)
3749  IMPLICIT NONE
3750 
3751 ! Declare Arguments
3752  REAL (rprec) :: vmec_get_gp_sxrem_pi
3753  TYPE (vmec_class), INTENT(in) :: this
3754  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3755  INTEGER, INTENT(in) :: i
3756  INTEGER, INTENT(in) :: index
3757 
3758 ! local variables
3759  REAL (rprec) :: s
3760  REAL (rprec) :: start_time
3761 
3762 ! Start of executable code
3763  start_time = profiler_get_start_time()
3764 
3765  s = vmec_get_s(this, x_cart)
3766  IF (ASSOCIATED(this%sxrem) .and. &
3767  & (index .le. SIZE(this%sxrem)) .and. (s .le. 1.0)) THEN
3768  vmec_get_gp_sxrem_pi = pprofile_get_gp(this%sxrem(index)%p, &
3769  & s, i)
3770  ELSE
3771  vmec_get_gp_sxrem_pi = 0.0
3772  END IF
3773 
3774  CALL profiler_set_stop_time('vmec_get_gp_sxrem_pi', start_time)
3775 
3776  END FUNCTION
3777 
3778 !-------------------------------------------------------------------------------
3792 !-------------------------------------------------------------------------------
3793  FUNCTION vmec_get_gp_sxrem_pp(this, x_cart, y_cart, index)
3795  IMPLICIT NONE
3796 
3797 ! Declare Arguments
3798  REAL (rprec) :: vmec_get_gp_sxrem_pp
3799  TYPE (vmec_class), INTENT(in) :: this
3800  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3801  REAL (rprec), DIMENSION(3), INTENT(in) :: y_cart
3802  INTEGER, INTENT(in) :: index
3803 
3804 ! local variables
3805  REAL (rprec) :: s1
3806  REAL (rprec) :: s2
3807  REAL (rprec) :: start_time
3808 
3809 ! Start of executable code
3810  start_time = profiler_get_start_time()
3811 
3812  s1 = vmec_get_s(this, x_cart)
3813  s2 = vmec_get_s(this, y_cart)
3814  IF (ASSOCIATED(this%sxrem) .and. &
3815  & (index .le. SIZE(this%sxrem)) .and. &
3816  & (s1 .le. 1.0) .and. (s2 .le. 1.0)) THEN
3818  & pprofile_get_gp(this%sxrem(index)%p, s1, s2)
3819  ELSE
3820  vmec_get_gp_sxrem_pp = 0.0
3821  END IF
3822 
3823  CALL profiler_set_stop_time('vmec_get_gp_sxrem_pp', start_time)
3824 
3825  END FUNCTION
3826 
3827 !-------------------------------------------------------------------------------
3837 !-------------------------------------------------------------------------------
3838  FUNCTION vmec_get_sxrem_cart(this, x_cart, index)
3840  IMPLICIT NONE
3841 
3842 ! Declare Arguments
3843  REAL (rprec) :: vmec_get_sxrem_cart
3844  TYPE (vmec_class), INTENT(in) :: this
3845  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3846  INTEGER, INTENT(in) :: index
3847 
3848 ! local variables
3849  REAL (rprec) :: start_time
3850 
3851 ! Start of executable code
3852  start_time = profiler_get_start_time()
3854  & vmec_get_flux(this, x_cart), &
3855  & index)
3856 
3857  CALL profiler_set_stop_time('vmec_get_sxrem_cart', start_time)
3858 
3859  END FUNCTION
3860 
3861 !-------------------------------------------------------------------------------
3871 !-------------------------------------------------------------------------------
3872  FUNCTION vmec_get_sxrem_radial(this, s, index)
3874  IMPLICIT NONE
3875 
3876 ! Declare Arguments
3877  REAL (rprec) :: vmec_get_sxrem_radial
3878  TYPE (vmec_class), INTENT(in) :: this
3879  REAL (rprec), INTENT(in) :: s
3880  INTEGER, INTENT(in) :: index
3881 
3882 ! local variables
3883  REAL (rprec) :: start_time
3884 
3885 ! Start of executable code
3886  start_time = profiler_get_start_time()
3887 
3888  IF (ASSOCIATED(this%sxrem) .and. &
3889  & (index .le. SIZE(this%sxrem))) THEN
3891  & pprofile_get_value(this%sxrem(index)%p, s)
3892  ELSE
3893  vmec_get_sxrem_radial = 0.0
3894  END IF
3895 
3896  CALL profiler_set_stop_time('vmec_get_sxrem_radial', start_time)
3897 
3898  END FUNCTION
3899 
3900 !-------------------------------------------------------------------------------
3908 !-------------------------------------------------------------------------------
3909  FUNCTION vmec_get_p_cart(this, x_cart)
3911  IMPLICIT NONE
3912 
3913 ! Declare Arguments
3914  REAL (rprec) :: vmec_get_p_cart
3915  TYPE (vmec_class), INTENT(in) :: this
3916  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3917 
3918 ! local variables
3919  REAL (rprec) :: start_time
3920 
3921 ! Start of executable code
3922  start_time = profiler_get_start_time()
3923  vmec_get_p_cart = vmec_get_p(this, vmec_get_flux(this, x_cart))
3924 
3925  CALL profiler_set_stop_time('vmec_get_p_cart', start_time)
3926 
3927  END FUNCTION
3928 
3929 !-------------------------------------------------------------------------------
3937 !-------------------------------------------------------------------------------
3938  FUNCTION vmec_get_p_radial(this, s)
3939  USE stel_constants, only: mu0
3940 
3941  IMPLICIT NONE
3942 
3943 ! Declare Arguments
3944  REAL (rprec) :: vmec_get_p_radial
3945  TYPE (vmec_class), INTENT(in) :: this
3946  REAL (rprec), INTENT(in) :: s
3947 
3948 ! local variables
3949  REAL (rprec) :: start_time
3950 
3951 ! Forward declare the interface for pmass. This explicitly defined the type for
3952 ! pmass to avoid a compiler error. If profile_functions.f was implimented as a
3953 ! module this would not be needed.
3954  INTERFACE
3955  FUNCTION pmass(s)
3956  USE stel_kinds
3957  REAL (rprec) :: pmass
3958  REAL (rprec), INTENT(in) :: s
3959  end function
3960  END INTERFACE
3961 
3962 ! Start of executable code
3963  start_time = profiler_get_start_time()
3964  vmec_get_p_radial = pmass(s)/mu0
3965 
3966  CALL profiler_set_stop_time('vmec_get_p_radial', start_time)
3967 
3968  END FUNCTION
3969 
3970 !-------------------------------------------------------------------------------
3980 !-------------------------------------------------------------------------------
3981  FUNCTION vmec_get_b_vec(this, x_cart, cyl)
3983  USE vmec_utils, ONLY : getbcyl_wout
3984  USE mgrid_mod
3985  USE vmec_input, ONLY: nfp
3986 
3987  IMPLICIT NONE
3988 
3989 ! Declare Arguments
3990  REAL (rprec), DIMENSION(3) :: vmec_get_b_vec
3991  TYPE (vmec_class), INTENT(in) :: this
3992  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
3993  LOGICAL, INTENT(in) :: cyl
3994 
3995 ! local variables
3996  REAL (rprec), DIMENSION(3) :: r_cyl
3997  REAL (rprec), DIMENSION(3) :: r_cyl_rot
3998  REAL (rprec) :: s_temp
3999  INTEGER :: status
4000  REAL (rprec) :: start_time
4001 
4002 ! Start of executable code
4003  start_time = profiler_get_start_time()
4004 
4005  r_cyl = cart_to_cyl(x_cart)
4006  r_cyl_rot = r_cyl
4007  r_cyl_rot(2) = r_cyl(2) + this%phi_offset
4008  r_cyl_rot(3) = r_cyl(3) - this%z_offset
4009 
4010  vmec_get_b_vec = 0.0
4011  s_temp = 0.0
4012  CALL getbcyl_wout(r_cyl_rot(1), r_cyl_rot(2), r_cyl_rot(3), &
4013  & vmec_get_b_vec(1), vmec_get_b_vec(2), &
4014  & vmec_get_b_vec(3), sflx=s_temp, info=status)
4015 
4016  IF (lfreeb .and. (s_temp .gt. 1.0 .or. status .eq. -3)) THEN
4017 ! The measurement point stays fixed relative to the field coils so there should
4018 ! be no rotation or offset here. vmec_get_ext_b_plasma handles shift of the
4019 ! plasma internally.
4020  vmec_get_b_vec = vmec_get_b_vac(this, r_cyl) &
4021  & + vmec_get_ext_b_plasma(this, r_cyl, .false.)
4022  END IF
4023 
4024  IF (.not.cyl) THEN
4026  END IF
4027 
4028  CALL profiler_set_stop_time('vmec_get_B_vec', start_time)
4029 
4030  END FUNCTION
4031 
4032 !-------------------------------------------------------------------------------
4042 !-------------------------------------------------------------------------------
4043  FUNCTION vmec_get_int_b_dphi(this, r, theta)
4045  USE stel_constants, only: twopi
4046  USE read_wout_mod, only: bsubvmnc, ns
4047 
4048  IMPLICIT NONE
4049 
4050 ! Declare Arguments
4051  REAL (rprec) :: vmec_get_int_b_dphi
4052  TYPE (vmec_class), INTENT(in) :: this
4053  REAL (rprec), INTENT(in) :: r
4054  REAL (rprec), INTENT(in) :: theta
4055 
4056 ! local variables
4057  REAL (rprec) :: bsubv00c, ds
4058  INTEGER :: i
4059  REAL (rprec), DIMENSION(2) :: s
4060  REAL (rprec) :: start_time
4061 
4062 ! Start of executable code
4063  start_time = profiler_get_start_time()
4064  ds = 1.0/(ns - 1)
4065 
4066  s(1) = 1.0 - 1.5*ds
4067  s(2) = 1.0 - 0.5*ds
4068 
4069  CALL line_seg(r, bsubv00c, s, bsubvmnc(1,ns - 1:ns), 2)
4070 
4071  vmec_get_int_b_dphi = twopi*bsubv00c
4072 
4073  CALL profiler_set_stop_time('vmec_get_Int_B_dphi', start_time)
4074 
4075  END FUNCTION
4076 
4077 !-------------------------------------------------------------------------------
4085 !-------------------------------------------------------------------------------
4086  FUNCTION vmec_get_suv(this, x_cart)
4087  USE cyl_flux, only: cyl2flx
4089  USE read_wout_mod, only: rzl_local, ns, ntmax, lthreed, ntor, &
4090  & mpol, nfp, lasym
4091 
4092  IMPLICIT NONE
4093 
4094 ! Declare Arguments
4095  REAL (rprec), DIMENSION(3) :: vmec_get_suv
4096  TYPE (vmec_class), INTENT(in) :: this
4097  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
4098 
4099 ! local variables
4100  REAL (rprec), DIMENSION(3) :: r_cyl
4101  REAL (rprec) :: fmin
4102  INTEGER :: info
4103  INTEGER :: nfe
4104  REAL (rprec) :: start_time
4105 
4106 ! Start of executable code
4107  start_time = profiler_get_start_time()
4108 
4109  vmec_get_suv = 0.0
4110  fmin = 0.0
4111  info = 0
4112  nfe = 0
4113 
4114  r_cyl = cart_to_cyl(x_cart)
4115  r_cyl(2) = nfp*(r_cyl(2) + this%phi_offset)
4116  r_cyl(3) = r_cyl(3) - this%z_offset
4117 
4118  CALL cyl2flx(rzl_local, r_cyl, vmec_get_suv, ns, ntor, mpol, &
4119  & ntmax, lthreed, lasym, info, nfe, fmin)
4120 
4121  IF (vmec_get_suv(1) .le. 1.0) THEN
4122  IF (fmin .gt. 1.0e-8_rprec) THEN
4123  WRITE(*,*) "Warn: VMEC could not converge to flux position." &
4124  WRITE(*,*) info, fmin, vmec_get_suv
4125  END IF
4126  END IF
4127 
4128 ! If The point was outside the plasma, ensure s is greater than one.
4129  IF (info .eq. -3) THEN
4130  vmec_get_suv = (/ 2.0, 0.0, 0.0 /)
4131  END IF
4132 
4133  CALL profiler_set_stop_time('vmec_get_suv', start_time)
4134 
4135  END FUNCTION
4136 
4137 !-------------------------------------------------------------------------------
4145 !-------------------------------------------------------------------------------
4146  FUNCTION vmec_get_s(this, x_cart)
4147  USE cyl_flux, only: cyl2flx
4149  USE read_wout_mod, only: rzl_local, ns, ntmax, lthreed, ntor, &
4150  & mpol, nfp, lasym
4151 
4152  IMPLICIT NONE
4153 
4154 ! Declare Arguments
4155  REAL (rprec) :: vmec_get_s
4156  TYPE (vmec_class), INTENT(in) :: this
4157  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
4158 
4159 ! local variables
4160  REAL (rprec), DIMENSION(3) :: s_flux
4161  REAL (rprec) :: start_time
4162 
4163 ! Start of executable code
4164  start_time = profiler_get_start_time()
4165 
4166  s_flux = vmec_get_suv(this, x_cart)
4167  vmec_get_s = s_flux(1)
4168 
4169  CALL profiler_set_stop_time('vmec_get_s', start_time)
4170 
4171  END FUNCTION
4172 
4173 !-------------------------------------------------------------------------------
4181 !-------------------------------------------------------------------------------
4182  FUNCTION vmec_get_flux(this, x_cart)
4183  USE vmec_input, only: lrfp
4184 
4185  IMPLICIT NONE
4186 
4187 ! Declare Arguments
4188  REAL (rprec) :: vmec_get_flux
4189  TYPE (vmec_class), INTENT(in) :: this
4190  REAL (rprec), DIMENSION(3), INTENT(in) :: x_cart
4191 
4192 ! local variables
4193  REAL (rprec) :: start_time
4194 
4195 ! external functions
4196  REAL (rprec), EXTERNAL :: torflux
4197 
4198 ! Start of executable code
4199  start_time = profiler_get_start_time()
4200 
4201  vmec_get_flux = vmec_get_s(this, x_cart)
4202 
4203  IF (.not.lrfp) THEN
4204 ! VMEC can redistribute the radial grid. This converts even spaced internal
4205 ! grid to the normalized flux.
4206  vmec_get_flux = torflux(vmec_get_flux)
4207  END IF
4208 
4209  CALL profiler_set_stop_time('vmec_get_flux', start_time)
4210 
4211  END FUNCTION
4212 
4213 !-------------------------------------------------------------------------------
4225 !-------------------------------------------------------------------------------
4226  FUNCTION vmec_get_plasma_edge(this, phi, r, z)
4227  USE read_wout_mod, only: xm, xn, rmnc, zmns, rmns, zmnc, lasym, &
4228  & ns, mpol
4229  USE stel_constants, only: twopi
4230 
4231  IMPLICIT NONE
4232 
4233 ! Declare Arguments
4234  INTEGER :: vmec_get_plasma_edge
4235  TYPE (vmec_class), INTENT(in) :: this
4236  REAL (rprec), INTENT (in) :: phi
4237  REAL (rprec), DIMENSION(:), POINTER :: r
4238  REAL (rprec), DIMENSION(:), POINTER :: z
4239 
4240 ! local variables
4241  REAL (rprec), DIMENSION(:), ALLOCATABLE :: cosv, sinv
4242  REAL (rprec), DIMENSION(:), ALLOCATABLE :: cosu, sinu
4243  INTEGER :: i
4244  REAL (rprec) :: start_time
4245 
4246 ! Start of executable code
4247  start_time = profiler_get_start_time()
4248 
4249  vmec_get_plasma_edge = max(ns, 2*mpol + 6)
4250 
4252 
4253  ALLOCATE(cosv(SIZE(xn, 1)), sinv(SIZE(xn, 1)))
4254  ALLOCATE(cosu(SIZE(xm, 1)), sinu(SIZE(xm, 1)))
4255 
4256  cosv(:) = cos(xn*(phi + this%phi_offset))
4257  sinv(:) = sin(xn*(phi + this%phi_offset))
4258  DO i = 1, vmec_get_plasma_edge
4259  cosu(:) = cos(xm*(i - 1)*twopi/vmec_get_plasma_edge)
4260  sinu(:) = sin(xm*(i - 1)*twopi/vmec_get_plasma_edge)
4261 
4262  r(i) = sum(rmnc(:, ns)*(cosu(:)*cosv(:) + sinu(:)*sinv(:)))
4263  z(i) = sum(zmns(:, ns)*(sinu(:)*cosv(:) - cosu(:)*sinv(:)))
4264 
4265  IF (lasym) THEN
4266  r(i) = r(i) + &
4267  & sum(rmns(:, ns)*(sinu(:)*cosv(:) - cosu(:)*sinv(:)))
4268  z(i) = z(i) + &
4269  & sum(zmnc(:, ns)*(cosu(:)*cosv(:) + sinu(:)*sinv(:)))
4270  END IF
4271  END DO
4272  z = z + this%z_offset
4273  DEALLOCATE(cosu, cosv, sinu, sinv)
4274 
4275  CALL profiler_set_stop_time('vmec_get_plasma_edge', start_time)
4276 
4277  END FUNCTION
4278 
4279 !-------------------------------------------------------------------------------
4287 !-------------------------------------------------------------------------------
4288  FUNCTION vmec_get_magnetic_volume_rgrid(this)
4290  IMPLICIT NONE
4291 
4292 ! Declare Arguments
4293  REAL (rprec), DIMENSION(:,:,:), POINTER :: &
4295  TYPE (vmec_class), INTENT(in) :: this
4296 
4297 ! local variables
4298  REAL (rprec) :: start_time
4299 
4300 ! Start of executable code
4301  start_time = profiler_get_start_time()
4302  vmec_get_magnetic_volume_rgrid => this%magnetic_cache%rsuv
4303 
4304  CALL profiler_set_stop_time('vmec_get_magnetic_volume_rgrid', &
4305  & start_time)
4306 
4307  END FUNCTION
4308 
4309 !-------------------------------------------------------------------------------
4317 !-------------------------------------------------------------------------------
4318  FUNCTION vmec_get_magnetic_volume_zgrid(this)
4320  IMPLICIT NONE
4321 
4322 ! Declare Arguments
4323  REAL (rprec), DIMENSION(:,:,:), POINTER :: &
4325  TYPE (vmec_class), INTENT(in) :: this
4326 
4327 ! local variables
4328  REAL (rprec) :: start_time
4329 
4330 ! Start of executable code
4331  start_time = profiler_get_start_time()
4332  vmec_get_magnetic_volume_zgrid => this%magnetic_cache%zsuv
4333 
4334  CALL profiler_set_stop_time('vmec_get_magnetic_volume_zgrid', &
4335  & start_time)
4336 
4337  END FUNCTION
4338 
4339 !-------------------------------------------------------------------------------
4347 !-------------------------------------------------------------------------------
4348  FUNCTION vmec_get_magnetic_volume_jrgrid(this)
4350  IMPLICIT NONE
4351 
4352 ! Declare Arguments
4353  REAL (rprec), DIMENSION(:,:,:), POINTER :: &
4355  TYPE (vmec_class), INTENT(in) :: this
4356 
4357 ! local variables
4358  REAL (rprec) :: start_time
4359 
4360 ! Start of executable code
4361  start_time = profiler_get_start_time()
4362  vmec_get_magnetic_volume_jrgrid => this%magnetic_cache%jrsuv
4363 
4364  CALL profiler_set_stop_time('vmec_get_magnetic_volume_jrgrid', &
4365  & start_time)
4366 
4367  END FUNCTION
4368 
4369 !-------------------------------------------------------------------------------
4377 !-------------------------------------------------------------------------------
4378  FUNCTION vmec_get_magnetic_volume_jphigrid(this)
4380  IMPLICIT NONE
4381 
4382 ! Declare Arguments
4383  REAL (rprec), DIMENSION(:,:,:), POINTER :: &
4385  TYPE (vmec_class), INTENT(in) :: this
4386 
4387 ! local variables
4388  REAL (rprec) :: start_time
4389 
4390 ! Start of executable code
4391  start_time = profiler_get_start_time()
4392  vmec_get_magnetic_volume_jphigrid => this%magnetic_cache%jphisuv
4393 
4394  CALL profiler_set_stop_time('vmec_get_magnetic_volume_jphigrid', &
4395  & start_time)
4396 
4397  END FUNCTION
4398 
4399 !-------------------------------------------------------------------------------
4407 !-------------------------------------------------------------------------------
4408  FUNCTION vmec_get_magnetic_volume_jzgrid(this)
4410  IMPLICIT NONE
4411 
4412 ! Declare Arguments
4413  REAL (rprec), DIMENSION(:,:,:), POINTER :: &
4415  TYPE (vmec_class), INTENT(in) :: this
4416 
4417 ! local variables
4418  REAL (rprec) :: start_time
4419 
4420 ! Start of executable code
4421  start_time = profiler_get_start_time()
4422  vmec_get_magnetic_volume_jzgrid => this%magnetic_cache%jzsuv
4423 
4424  CALL profiler_set_stop_time('vmec_get_magnetic_volume_jzgrid', &
4425  & start_time)
4426 
4427  END FUNCTION
4428 
4429 !-------------------------------------------------------------------------------
4443 !-------------------------------------------------------------------------------
4444  FUNCTION vmec_get_volume_int_element(this)
4445  USE read_wout_mod, only: isigng
4446 
4447  IMPLICIT NONE
4448 
4449 ! Declare Arguments
4450  REAL (rprec) :: vmec_get_volume_int_element
4451  TYPE (vmec_class), INTENT(in) :: this
4452 
4453 ! local variables
4454  REAL (rprec) :: start_time
4455 
4456 ! Start of executable code
4457  start_time = profiler_get_start_time()
4458  vmec_get_volume_int_element = isigng*this%magnetic_cache%ds &
4459  & * this%magnetic_cache%du &
4460  & * this%magnetic_cache%dv
4461 
4462  CALL profiler_set_stop_time('vmec_get_volume_int_element', &
4463  & start_time)
4464 
4465  END FUNCTION
4466 
4467 !-------------------------------------------------------------------------------
4475 !-------------------------------------------------------------------------------
4476  FUNCTION vmec_get_con_surface_krgrid(this)
4478  IMPLICIT NONE
4479 
4480 ! Declare Arguments
4481  REAL (rprec), DIMENSION(:,:), POINTER :: &
4483  TYPE (vmec_class), INTENT(in) :: this
4484 
4485 ! local variables
4486  REAL (rprec) :: start_time
4487 
4488 ! Start of executable code
4489  start_time = profiler_get_start_time()
4490  vmec_get_con_surface_krgrid => this%magnetic_cache%kruv
4491 
4492  CALL profiler_set_stop_time('vmec_get_con_surface_krgrid', &
4493  & start_time)
4494 
4495  END FUNCTION
4496 
4497 !-------------------------------------------------------------------------------
4505 !-------------------------------------------------------------------------------
4506  FUNCTION vmec_get_con_surface_kphigrid(this)
4508  IMPLICIT NONE
4509 
4510 ! Declare Arguments
4511  REAL (rprec), DIMENSION(:,:), POINTER :: &
4513  TYPE (vmec_class), INTENT(in) :: this
4514 
4515 ! local variables
4516  REAL (rprec) :: start_time
4517 
4518 ! Start of executable code
4519  start_time = profiler_get_start_time()
4520  vmec_get_con_surface_kphigrid => this%magnetic_cache%kphiuv
4521 
4522  CALL profiler_set_stop_time('vmec_get_con_surface_kphigrid', &
4523  & start_time)
4524 
4525  END FUNCTION
4526 
4527 !-------------------------------------------------------------------------------
4535 !-------------------------------------------------------------------------------
4536  FUNCTION vmec_get_con_surface_kzgrid(this)
4538  IMPLICIT NONE
4539 
4540 ! Declare Arguments
4541  REAL (rprec), DIMENSION(:,:), POINTER :: &
4543  TYPE (vmec_class), INTENT(in) :: this
4544 
4545 ! local variables
4546  REAL (rprec) :: start_time
4547 
4548 ! Start of executable code
4549  start_time = profiler_get_start_time()
4550  vmec_get_con_surface_kzgrid => this%magnetic_cache%kzuv
4551 
4552  CALL profiler_set_stop_time('vmec_get_con_surface_kzgrid', &
4553  & start_time)
4554 
4555  END FUNCTION
4556 
4557 !-------------------------------------------------------------------------------
4571 !-------------------------------------------------------------------------------
4572  FUNCTION vmec_get_area_int_element(this)
4573  USE read_wout_mod, only: isigng
4574 
4575  IMPLICIT NONE
4576 
4577 ! Declare Arguments
4578  REAL (rprec) :: vmec_get_area_int_element
4579  TYPE (vmec_class), INTENT(in) :: this
4580 
4581 ! local variables
4582  REAL (rprec) :: start_time
4583 
4584 ! Start of executable code
4585  start_time = profiler_get_start_time()
4586  vmec_get_area_int_element = this%magnetic_cache%du_a
4587  & * this%magnetic_cache%dv_a*isigng
4588 
4589  CALL profiler_set_stop_time('vmec_get_area_int_element', &
4590  & start_time)
4591 
4592  END FUNCTION
4593 
4594 !-------------------------------------------------------------------------------
4608 !-------------------------------------------------------------------------------
4609  FUNCTION vmec_get_ext_currents(this, num_currents, &
4610  & scale_currents)
4611  USE vmec_input, only: lfreeb, extcur
4612  USE mgrid_mod, only: mgrid_mode, nextcur
4613 
4614  IMPLICIT NONE
4615 
4616 ! Declare Arguments
4617  REAL (rprec), DIMENSION(:), POINTER :: vmec_get_ext_currents
4618  TYPE (vmec_class), INTENT(in) :: this
4619  INTEGER, INTENT(in) :: num_currents
4620  LOGICAL, INTENT(out) :: scale_currents
4621 
4622 ! local variables
4623  REAL (rprec) :: start_time
4624 
4625 ! Start of executable code
4626  start_time = profiler_get_start_time()
4627 
4628  IF (lfreeb) THEN
4629  SELECT CASE (mgrid_mode)
4630 
4631  CASE ('S', 's', 'N', 'n')
4632  scale_currents = .true.
4633 
4634  CASE DEFAULT
4635  scale_currents = .false.
4636 
4637  END SELECT
4638  vmec_get_ext_currents => extcur(1:nextcur)
4639  ELSE IF (num_currents .gt. 0) THEN
4640 ! Assume if the currents are being forced that currents are not scaled.
4641  scale_currents = .false.
4642  vmec_get_ext_currents => extcur(1:num_currents)
4643  ELSE
4644  vmec_get_ext_currents => null()
4645  END IF
4646 
4647  CALL profiler_set_stop_time('vmec_get_ext_currents', start_time)
4648 
4649  END FUNCTION
4650 
4651 !-------------------------------------------------------------------------------
4660 !-------------------------------------------------------------------------------
4661  FUNCTION vmec_get_b_vac(this, r_cyl)
4663  USE vmec_utils, ONLY : getbcyl_wout
4664  USE mgrid_mod
4665  USE vmec_input, ONLY: nfp
4666 
4667  IMPLICIT NONE
4668 
4669 ! Declare Arguments
4670  REAL (rprec), DIMENSION(3) :: vmec_get_b_vac
4671  TYPE (vmec_class), INTENT(in) :: this
4672  REAL (rprec), DIMENSION(3), INTENT(in) :: r_cyl
4673 
4674 ! local variables
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
4687 
4688 ! Start of executable code
4689  start_time = profiler_get_start_time()
4690 
4691  IF (r_cyl(1) .gt. rmaxb .or. r_cyl(1) .lt. rminb) THEN
4692  stop 'Radial point outside vacuum grid.'
4693  END IF
4694  IF (r_cyl(3) .gt. zmaxb .or. r_cyl(3) .lt. zminb) THEN
4695  stop 'Vertical point outside vacuum grid.'
4696  END IF
4697 
4698 ! Normalize phi position to fall within 0 - 2Pi.
4699  v_norm = r_cyl(2)
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
4703  ELSE
4704  v_norm = v_norm + twopi
4705  END IF
4706  END DO
4707 
4708 ! Normalize phi position to fall within the first field period. We already
4709 ! made sure that v_norm is greater than zero degrees.
4710  DO WHILE(v_norm .gt. twopi/nfp)
4711  v_norm = v_norm - twopi/nfp
4712  END DO
4713 
4714 ! Need to interpolate the vacuum field grid to get the vacuum field external to
4715 ! the plasma. Also need to be careful about the axisymmetric case. For those
4716 ! cases don't interpolate in the phi direction.
4717  delphib = twopi/(nfp*np0b)
4718 
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
4722 
4723  i_high = i_low + 1
4724  IF (np0b .eq. 1) THEN
4725  j_high = 1
4726  ELSE
4727  j_high = j_low + 1
4728  END IF
4729  k_high = k_low + 1
4730 
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
4734 
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
4741 
4742  vmec_get_b_vac(1) &
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)
4751 
4752  vmec_get_b_vac(2) &
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)
4761 
4762  vmec_get_b_vac(3) &
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)
4771 
4772  CALL profiler_set_stop_time('vmec_get_B_vac', start_time)
4773 
4774  END FUNCTION
4775 
4776 !-------------------------------------------------------------------------------
4790 !-------------------------------------------------------------------------------
4791  FUNCTION vmec_get_ext_b_plasma(this, position, axi_only)
4793  USE read_wout_mod, only: isigng
4794 
4795  IMPLICIT NONE
4796 
4797 ! Declare Arguments
4798  REAL (rprec), DIMENSION(3) :: vmec_get_ext_b_plasma
4799  TYPE (vmec_class), INTENT(in) :: this
4800  REAL (rprec), DIMENSION(3), INTENT(in) :: position
4801  LOGICAL, INTENT(in) :: axi_only
4802 
4803 ! local variables
4804  REAL (rprec), DIMENSION(3) :: x_cart
4805  REAL (rprec), DIMENSION(3) :: r_vec
4806  INTEGER :: u, v
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
4814 
4815 ! Start of executable code
4816  start_time = profiler_get_start_time()
4817 
4818 ! Convert the position to cartesian coordinates. Rotate and shift the signal
4819 ! position with respect to the fixed plasma.
4820  x_cart = cyl_to_cart(position - (/ 0.0_dp, &
4821  & this%phi_offset, &
4822  & this%z_offset /))
4823 
4824  IF (axi_only) THEN
4825  CALL assert(ASSOCIATED(this%magnetic_cache%kxuv_axi), &
4826  & 'Cannot get the axisymmtric only ext bfield.')
4827 
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
4832  ELSE
4833  CALL assert(ASSOCIATED(this%magnetic_cache%kxuv_full), &
4834  & 'Cannot get the ext bfield.')
4835 
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
4840  END IF
4841 
4842 ! The magnetic field produced by a sheet of current is
4843 !
4844 ! B(x) = Int K x (x-x')/|x-x'|^3 da (1)
4845  sum_b = 0.0
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
4850 
4851  sum_b(1) = sum_b(1) &
4852  & + (kyuv(u,v)*r_vec(3) - kzuv(u,v)*r_vec(2)) &
4853  & / length
4854  sum_b(2) = sum_b(2) &
4855  & + (kzuv(u,v)*r_vec(1) - kxuv(u,v)*r_vec(3)) &
4856  & / length
4857  sum_b(3) = sum_b(3) &
4858  & + (kxuv(u,v)*r_vec(2) - kyuv(u,v)*r_vec(1)) &
4859  & / length
4860  END DO
4861  END DO
4862 
4863 ! The virtual casing principal acts as if there is a perfectly conducting shell
4864 ! around the last closed flux surface. In this shell, eddy currents induced
4865 ! from the volume currents get canceled out by the shell currents.
4866 !
4867 ! B_v + B_s = 0 (2)
4868 !
4869 ! Thus the shell field is the same magnetude but opposite sign to the volume
4870 ! current.
4871 !
4872 ! B_v = -B_s (3)
4873 !
4874 ! After the surface integral is completed, negate the result to produce a field
4875 ! that would be the same as a volume integral.
4876  vmec_get_ext_b_plasma = -mu0/(4.0*pi)*sum_b*isigng &
4877  & * this%magnetic_cache%du_full &
4878  & * this%magnetic_cache%dv_full
4879 
4882 
4883  CALL profiler_set_stop_time('vmec_get_ext_b_plasma', start_time)
4884 
4885  END FUNCTION
4886 
4887 !-------------------------------------------------------------------------------
4894 !-------------------------------------------------------------------------------
4895  FUNCTION vmec_get_grid_size(this)
4896  USE vmec_input, only: ns_array
4897 
4898  IMPLICIT NONE
4899 
4900 ! Declare Arguments
4901  INTEGER :: vmec_get_grid_size
4902  TYPE (vmec_class), INTENT(in) :: this
4903 
4904 ! local variables
4905  REAL (rprec) :: start_time
4906 
4907 ! Start of executable code
4908  start_time = profiler_get_start_time()
4909  vmec_get_grid_size = ns_array(this%ns_index)
4910  CALL profiler_set_stop_time('vmec_get_grid_size', start_time)
4911 
4912  END FUNCTION
4913 
4914 !-------------------------------------------------------------------------------
4921 !-------------------------------------------------------------------------------
4922  FUNCTION vmec_get_grid_start(this)
4924  IMPLICIT NONE
4925 
4926 ! Declare Arguments
4927  REAl (rprec) :: vmec_get_grid_start
4928  TYPE (vmec_class), INTENT(in) :: this
4929 
4930 ! local variables
4931  REAL (rprec) :: start_time
4932 
4933 ! Start of executable code
4934  start_time = profiler_get_start_time()
4935  vmec_get_grid_start = 0.0
4936  CALL profiler_set_stop_time('vmec_get_grid_start', start_time)
4937 
4938  END FUNCTION
4939 
4940 !-------------------------------------------------------------------------------
4947 !-------------------------------------------------------------------------------
4948  FUNCTION vmec_get_grid_stop(this)
4950  IMPLICIT NONE
4951 
4952 ! Declare Arguments
4953  REAL (rprec) :: vmec_get_grid_stop
4954  TYPE (vmec_class), INTENT(in) :: this
4955 
4956 ! local variables
4957  REAL (rprec) :: start_time
4958 
4959 ! Start of executable code
4960  start_time = profiler_get_start_time()
4961  vmec_get_grid_stop = 1.0
4962  CALL profiler_set_stop_time('vmec_get_grid_stop', start_time)
4963 
4964  END FUNCTION
4965 
4966 !*******************************************************************************
4967 ! QUERY SUBROUTINES
4968 !*******************************************************************************
4969 !-------------------------------------------------------------------------------
4977 !-------------------------------------------------------------------------------
4978  FUNCTION vmec_is_scaler_value(this, id)
4980  IMPLICIT NONE
4981 
4982 ! Declare Arguments
4983  LOGICAL :: vmec_is_scaler_value
4984  TYPE (vmec_class), INTENT(in) :: this
4985  INTEGER, INTENT(in) :: id
4986 
4987 ! local variables
4988  REAL (rprec) :: start_time
4989 
4990 ! Start of executable code
4991  start_time = profiler_get_start_time()
4992  SELECT CASE (id)
4993 
4998  & vmec_z_offset_id)
4999  vmec_is_scaler_value = .true.
5000 
5001  CASE DEFAULT
5002  vmec_is_scaler_value = .false.
5003 
5004  END SELECT
5005 
5006  CALL profiler_set_stop_time('vmec_is_scaler_value', start_time)
5007 
5008  END FUNCTION
5009 
5010 !-------------------------------------------------------------------------------
5018 !-------------------------------------------------------------------------------
5019  FUNCTION vmec_is_1d_array(this, id)
5021  IMPLICIT NONE
5022 
5023 ! Declare Arguments
5024  LOGICAL :: vmec_is_1d_array
5025  TYPE (vmec_class), INTENT(in) :: this
5026  INTEGER, INTENT(in) :: id
5027 
5028 ! local variables
5029  REAL (rprec) :: start_time
5030 
5031 ! Start of executable code
5032  start_time = profiler_get_start_time()
5033  SELECT CASE (id)
5034 
5046  vmec_is_1d_array = .true.
5047 
5048  CASE DEFAULT
5049  vmec_is_1d_array = .false.
5050 
5051  END SELECT
5052 
5053  CALL profiler_set_stop_time('vmec_is_1d_array', start_time)
5054 
5055  END FUNCTION
5056 
5057 !-------------------------------------------------------------------------------
5065 !-------------------------------------------------------------------------------
5066  FUNCTION vmec_is_2d_array(this, id)
5068  IMPLICIT NONE
5069 
5070 ! Declare Arguments
5071  LOGICAL :: vmec_is_2d_array
5072  TYPE (vmec_class), INTENT(in) :: this
5073  INTEGER, INTENT(in) :: id
5074 
5075 ! local variables
5076  REAL (rprec) :: start_time
5077 
5078 ! Start of executable code
5079  start_time = profiler_get_start_time()
5080  SELECT CASE (id)
5081 
5091  vmec_is_2d_array = .true.
5092 
5093  CASE DEFAULT
5094  vmec_is_2d_array = .false.
5095 
5096  END SELECT
5097 
5098  CALL profiler_set_stop_time('vmec_is_2d_array', start_time)
5099 
5100  END FUNCTION
5101 
5102 !-------------------------------------------------------------------------------
5111 !-------------------------------------------------------------------------------
5112  FUNCTION vmec_is_recon_param(this, id)
5114  IMPLICIT NONE
5115 
5116 ! Declare Arguments
5117  LOGICAL :: vmec_is_recon_param
5118  TYPE (vmec_class), INTENT(in) :: this
5119  INTEGER, INTENT(in) :: id
5120 
5121 ! local variables
5122  REAL (rprec) :: start_time
5123 
5124 ! Start of executable code
5125  start_time = profiler_get_start_time()
5126  SELECT CASE (id)
5127 
5140  vmec_is_recon_param = .true.
5141 
5142  CASE DEFAULT
5143  vmec_is_recon_param = .false.
5144 
5145  END SELECT
5146 
5147  CALL profiler_set_stop_time('vmec_is_recon_param', start_time)
5148 
5149  END FUNCTION
5150 
5151 !-------------------------------------------------------------------------------
5158 !-------------------------------------------------------------------------------
5159  FUNCTION vmec_is_using_point(this)
5161  IMPLICIT NONE
5162 
5163 ! Declare Arguments
5164  LOGICAL :: vmec_is_using_point
5165  TYPE (vmec_class), INTENT(in) :: this
5166 
5167 ! local variables
5168  REAL (rprec) :: start_time
5169 
5170 ! Start of executable code
5171  start_time = profiler_get_start_time()
5172 
5173 ! Some compilers will generate code that will early terminate when a first
5174 ! operand to a .and. operator evaluates to false. Others are not so clever.
5175 ! Avoid running the second ASSOCIATED check if the magnetic cache is null.
5176  vmec_is_using_point = ASSOCIATED(this%magnetic_cache)
5177  IF (vmec_is_using_point) THEN
5178  vmec_is_using_point = ASSOCIATED(this%magnetic_cache%kxuv_full)
5179  END IF
5180 
5181  CALL profiler_set_stop_time('vmec_is_using_point', start_time)
5182 
5183  END FUNCTION
5184 
5185 !*******************************************************************************
5186 ! UTILITY SUBROUTINES
5187 !*******************************************************************************
5188 !-------------------------------------------------------------------------------
5200 !-------------------------------------------------------------------------------
5201  FUNCTION vmec_converge(this, num_iter, iou, eq_comm)
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
5210 
5211  IMPLICIT NONE
5212 
5213 ! Declare Arguments
5214  LOGICAL :: vmec_converge
5215  TYPE (vmec_class), INTENT(inout) :: this
5216  INTEGER, INTENT(inout) :: num_iter
5217  INTEGER, INTENT(in) :: iou
5218  INTEGER, INTENT(in) :: eq_comm
5219 
5220 ! local variables
5221 ! delt_local Value of delt on entry. Store, for restoration after error
5222 ! recovery.
5223 ! ictrl_array Array containing various vmec control parameters.
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
5229  TYPE (vmec_context_class), POINTER :: temp_context => null()
5230  INTEGER :: eq_rank
5231  INTEGER :: nstep_save
5232  REAL (rprec) :: start_time
5233 
5234 ! local parameters
5235  REAL (rprec), PARAMETER :: delt_factor = 2.0
5236  INTEGER, PARAMETER :: niter_factor = 4
5237 
5238 ! Start of executable code
5239  start_time = profiler_get_start_time()
5240 
5241  delt_local = delt
5242  niter_local = niter
5243  num_iter_init = iterc
5244  recovery_index = 0
5245 
5246  eq_rank = 0
5247 #if defined(MPI_OPT)
5248  CALL mpi_comm_rank(eq_comm, eq_rank, error)
5249 #endif
5250 
5251 ! Store the current VMEC context. This context is different than the one stored
5252 ! in save/reset state methods. This context needs to be stored so that error
5253 ! recovery can restore the state to before runvmec was run but after the
5254 ! parameters were changed.
5255  temp_context => vmec_context_construct()
5256 
5257 ! Run vmec until successful or an unrecoverable error has occured.
5258  DO
5259  ictrl_array = 0
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)
5263 
5264 ! Allow multigrid for the inital convergence only.
5265  IF (num_iter .gt. 1) THEN
5266  ictrl_array(3) = niter_local
5267  ictrl_array(4) = this%ns_index
5268  ELSE
5269 ! This allows the inital convergence to match a stand alone VMEC run.
5270  ictrl_array(1) = ior(ictrl_array(1), restart_flag)
5271  END IF
5272 
5273 ! Zero the xcdot array and store the xc array used for timestep resets.
5274  xcdot = 0.0
5275  xstore = xc
5276  CALL reset_params
5277 
5278  nstep_save = nstep
5279  CALL runvmec(ictrl_array, this%vmec_file_name, .false., &
5280  & eq_comm)
5281  nstep = nstep_save
5282 
5283 ! Set error flag. (Flags declared in vmec_params.f)
5284 !
5285 ! Check error flags for error recovery modes.
5286 ! If a recoverable error has occured, rerun vmec with altered eq_state. Error
5287 ! recovery is attempted a maximum of 2 times.
5288 ! If a non-recoverable error has occured, do not rerun vmec and report error.
5289 ! If vmec terminated sucessfully continue.
5290  SELECT CASE (ictrl_array(2))
5291  CASE (jac75_flag)
5292 
5293 ! Restore the context to the state it was before runvmec was called.
5294  CALL vmec_context_set_context(temp_context)
5295 
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
5303  END IF
5304  ELSE
5305  EXIT
5306  END IF
5307 
5308  CASE (more_iter_flag)
5309 
5310 ! Restore the context to the state it was before runvmec was called. Disable
5311 ! this on the inital convergence. Since the niter and niter_array variables in
5312 ! the VMEC namelist input don't change, this has no effect on the initial
5313 ! equilibrium convergence as a consequence of seting the restart_flag.
5314  CALL vmec_context_set_context(temp_context)
5315 
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
5324  END IF
5325  niter_local = niter_local + niter/niter_factor
5326  ELSE
5327  EXIT
5328  END IF
5329 
5330  CASE DEFAULT
5331  EXIT
5332 
5333  END SELECT
5334 
5335  IF (eq_rank .eq. 0) THEN
5336  WRITE (*,*) 'Attempting error recovery'
5337  WRITE (iou,*) 'Attempting error recovery'
5338  END IF
5339 
5340  recovery_index = recovery_index + 1
5341  END DO
5342 
5343 ! No longer need the local context array.
5344  CALL vmec_context_destruct(temp_context)
5345 
5346 ! Check for errors, if vmec was successful, load vmec data for use with the
5347 ! signals. Other wise report the error. This should only be performed on the
5348 ! head node.
5349  IF (eq_rank .eq. 0) THEN
5350  vmec_converge = .false.
5351  SELECT CASE (ictrl_array(2))
5352 
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.")
5356  CALL loadrzl
5357 
5358  vmec_converge = .true.
5359  IF (ASSOCIATED(this%magnetic_cache)) THEN
5360  CALL vmec_set_magnetic_cache(this)
5361  END IF
5362 
5363  CASE DEFAULT
5366 
5367  END SELECT
5368  END IF
5369 
5370 ! Increment the number of iterations by the number of iterations used by
5371 ! runvmec.
5372  num_iter = num_iter + iterc - num_iter_init
5373  delt = delt_local
5374 
5375  CALL profiler_set_stop_time('vmec_converge', start_time)
5376 
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)
5380 
5381  END FUNCTION
5382 
5383 !-------------------------------------------------------------------------------
5393 !-------------------------------------------------------------------------------
5394  SUBROUTINE vmec_read_vac_file(this, index, eq_comm)
5395  USE vmec_input, only: extcur, mgrid_file, nfp
5396  USE mgrid_mod, only: read_mgrid, mgrid_path_old
5397  USE vacmod0, only: nv
5398 
5399  IMPLICIT NONE
5400 
5401 ! Declare Arguments
5402  TYPE (vmec_class), INTENT(in) :: this
5403  INTEGER, INTENT(in) :: index
5404  INTEGER, INTENT(in) :: eq_comm
5405 
5406 #if defined(MPI_OPT)
5407 ! local variables
5408  INTEGER :: error
5409 
5410 ! Start of executable code
5411  mgrid_path_old = ''
5412 
5413  CALL mpi_bcast(extcur(index), 1, mpi_real8, 0, eq_comm, error)
5414  CALL read_mgrid(mgrid_file, extcur, nv, nfp, .false., error, &
5415  & comm = eq_comm)
5416  CALL assert_eq(0, error, 'vmec_set_param: failed to read ' // &
5417  & 'mgrid_file')
5418 #endif
5419  END SUBROUTINE
5420 
5421 !-------------------------------------------------------------------------------
5427 !-------------------------------------------------------------------------------
5428  SUBROUTINE vmec_save_state(this)
5430 
5431  IMPLICIT NONE
5432 
5433 ! Declare Arguments
5434  TYPE (vmec_class), INTENT(inout) :: this
5435 
5436 ! local variables
5437  INTEGER :: error
5438  INTEGER :: i
5439  REAL (rprec) :: start_time
5440 
5441 ! Start of executable code
5442  start_time = profiler_get_start_time()
5443 
5444  IF (ASSOCIATED(this%vmec_context_save)) THEN
5445  CALL vmec_context_get_context(this%vmec_context_save)
5446  ELSE
5447  this%vmec_context_save => vmec_context_construct()
5448  END IF
5449 
5450 ! Cache the wout file by appending _cache to a copy. Use copy here to keep the
5451 ! orginal file intact.
5452  CALL copy_file(trim(this%wout_file_name), &
5453  & trim(this%wout_file_name) // '_cache', &
5454  & error)
5455  CALL assert_eq(error, 0, 'Error copying wout file.')
5456 
5457  IF (ASSOCIATED(this%ne)) THEN
5458  CALL pprofile_save_state(this%ne)
5459  END IF
5460  IF (ASSOCIATED(this%te)) THEN
5461  CALL pprofile_save_state(this%te)
5462  END IF
5463  IF (ASSOCIATED(this%ti)) THEN
5464  CALL pprofile_save_state(this%ti)
5465  END IF
5466  IF (ASSOCIATED(this%sxrem)) THEN
5467  DO i = 1, SIZE(this%sxrem)
5468  IF (ASSOCIATED(this%sxrem(i)%p)) THEN
5469  CALL pprofile_save_state(this%sxrem(i)%p)
5470  END IF
5471  END DO
5472  END IF
5473 
5474  CALL profiler_set_stop_time('vmec_save_state', start_time)
5475 
5476  END SUBROUTINE
5477 
5478 !-------------------------------------------------------------------------------
5484 !-------------------------------------------------------------------------------
5485  SUBROUTINE vmec_reset_state(this)
5486  USE read_wout_mod, only: read_wout_file, loadrzl
5487  USE file_opts
5488 
5489  IMPLICIT NONE
5490 
5491 ! Declare Arguments
5492  TYPE (vmec_class), INTENT(inout) :: this
5493 
5494 ! local variables
5495  INTEGER :: error
5496  INTEGER :: i
5497  REAL (rprec) :: start_time
5498 
5499 ! Start of executable code
5500  start_time = profiler_get_start_time()
5501 
5502  IF (ASSOCIATED(this%vmec_context_save)) THEN
5503  CALL vmec_context_set_context(this%vmec_context_save)
5504  END IF
5505 
5506 ! Reset the wout file.
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.')
5510 
5511  CALL read_wout_file(this%wout_file_name, error)
5512  CALL assert_eq(error, 0, 'Error reading reset wout file.')
5513  CALL loadrzl
5514 
5515  IF (ASSOCIATED(this%magnetic_cache)) THEN
5516  CALL vmec_set_magnetic_cache(this)
5517  END IF
5518 
5519  IF (ASSOCIATED(this%ne)) THEN
5520  CALL pprofile_reset_state(this%ne)
5521  END IF
5522  IF (ASSOCIATED(this%te)) THEN
5523  CALL pprofile_reset_state(this%te)
5524  END IF
5525  IF (ASSOCIATED(this%ti)) THEN
5526  CALL pprofile_reset_state(this%ti)
5527  END IF
5528  IF (ASSOCIATED(this%sxrem)) THEN
5529  DO i = 1, SIZE(this%sxrem)
5530  IF (ASSOCIATED(this%sxrem(i)%p)) THEN
5531  CALL pprofile_reset_state(this%sxrem(i)%p)
5532  END IF
5533  END DO
5534  END IF
5535 
5536  CALL profiler_set_stop_time('vmec_reset_state', start_time)
5537 
5538  END SUBROUTINE
5539 
5540 !-------------------------------------------------------------------------------
5547 !-------------------------------------------------------------------------------
5548  SUBROUTINE vmec_write(this, iou)
5549  USE safe_open_mod
5550  USE vmec_input
5551 
5552  IMPLICIT NONE
5553 
5554 ! Declare Arguments
5555  TYPE (vmec_class), INTENT(in) :: this
5556  INTEGER, INTENT(in) :: iou
5557 
5558 ! local variables
5559  INTEGER :: i
5560  INTEGER :: iou_nl
5561  INTEGER :: status
5562  REAL (rprec) :: start_time
5563 
5564 ! Start of executable code
5565  start_time = profiler_get_start_time()
5566  WRITE (iou,*)
5567  WRITE (iou,*) 'Equilibrium Type : VMEC'
5568  IF (ASSOCIATED(this%ne)) THEN
5569  CALL pprofile_write(this%ne, 'pp_ne', iou)
5570  END IF
5571 
5572  IF (ASSOCIATED(this%sxrem)) THEN
5573  DO i = 1, SIZE(this%sxrem)
5574  IF (ASSOCIATED(this%sxrem(i)%p)) THEN
5575  CALL pprofile_write(this%sxrem(i)%p, 'pp_sxrem', iou)
5576  END IF
5577  END DO
5578  END IF
5579 
5580  IF (ASSOCIATED(this%te)) THEN
5581  CALL pprofile_write(this%te, 'pp_te', iou)
5582  END IF
5583 
5584  IF (ASSOCIATED(this%ti)) THEN
5585  CALL pprofile_write(this%ti, 'pp_ti', iou)
5586  END IF
5587 
5588  IF (ASSOCIATED(this%ze)) THEN
5589  CALL pprofile_write(this%ze, 'pp_ze', iou)
5590  END IF
5591 
5592 ! Update the namelist input variables from the equilibrium solution.
5593  CALL vmec_set_namelist(this)
5594 
5595  iou_nl = 0
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)
5601 
5602  CALL profiler_set_stop_time('vmec_write', start_time)
5603 
5604  END SUBROUTINE
5605 
5606 !-------------------------------------------------------------------------------
5615 !-------------------------------------------------------------------------------
5616  SUBROUTINE vmec_write_input(this, current_step)
5617  USE safe_open_mod
5618  USE vmec_input
5619  USE file_opts
5620 
5621  IMPLICIT NONE
5622 
5623 ! Declare Arguments
5624  TYPE (vmec_class), INTENT(in) :: this
5625  INTEGER, INTENT(in) :: current_step
5626 
5627 ! local variables
5628  INTEGER :: iou_nl
5629  INTEGER :: status
5630  CHARACTER (len=path_length) :: filename
5631  REAL (rprec) :: start_time
5632 
5633 ! Start of executable code
5634  start_time = profiler_get_start_time()
5635 
5636 ! Update the namelist input variables from the equilibrium solution.
5637  CALL vmec_set_namelist(this)
5638 
5639 ! Write out the final namelist input file.
5640  iou_nl = 0
5641  status = 0
5642 
5643  WRITE (filename,1000) trim(this%vmec_file_name), current_step
5644 
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.')
5650 
5651 ! Save the woutfile by making a copy with a new name.
5652  WRITE (filename,1000) trim(this%wout_file_name), current_step
5653 
5654  CALL copy_file(this%wout_file_name, trim(filename), status)
5655  CALL assert_eq(status, 0, 'Error copying wout file.')
5656 
5657  CALL profiler_set_stop_time('vmec_write_input', start_time)
5658 
5659 1000 FORMAT(a,'_',i0.3)
5660 
5661  END SUBROUTINE
5662 
5663 !*******************************************************************************
5664 ! NETCDF SUBROUTINES
5665 !*******************************************************************************
5692 !-------------------------------------------------------------------------------
5704 !-------------------------------------------------------------------------------
5705  SUBROUTINE vmec_def_result(this, result_ncid, maxnsetps_dim_id)
5706  USE mgrid_mod, only: nextcur
5707  USE vmec_dim, only: mpol1
5708  USE vmec_input, only: ntor
5709  USE xstuff, only: xc
5710  USE ezcdf
5711 
5712  IMPLICIT NONE
5713 
5714 ! Declare Arguments
5715  TYPE (vmec_class), INTENT(in) :: this
5716  INTEGER, INTENT(in) :: result_ncid
5717  INTEGER, INTENT(in) :: maxnsetps_dim_id
5718 
5719 ! Local variables
5720  INTEGER :: status
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
5736 
5737 ! Start of executable code
5738  start_time = profiler_get_start_time()
5739 
5740 ! Define dimensions.
5741  status = nf_def_dim(result_ncid, 'vmec_xc_dim', SIZE(xc), &
5742  & vmec_xc_dim_id)
5743  CALL assert_eq(status, nf_noerr, nf_strerror(status))
5744 
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))
5749  END IF
5750 
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))
5754 
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))
5758 
5759 ! Define variables.
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))
5763 
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))
5768  END IF
5769 
5770  status = nf_def_var(result_ncid, 'vmec_curtor', nf_double, 0, 0, &
5771  & vmec_curtor_id)
5772  CALL assert_eq(status, nf_noerr, nf_strerror(status))
5773 
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))
5777 
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))
5782 
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))
5787 
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))
5792 
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))
5797 
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))
5801 
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))
5805 
5806  CALL profiler_set_stop_time('vmec_def_result', start_time)
5807 
5808  END SUBROUTINE
5809 
5810 !-------------------------------------------------------------------------------
5817 !-------------------------------------------------------------------------------
5818  SUBROUTINE vmec_write_init_data(this, result_ncid)
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
5823  USE ezcdf
5824 
5825  IMPLICIT NONE
5826 
5827 ! Declare Arguments
5828  TYPE (vmec_class), INTENT(in) :: this
5829  INTEGER, INTENT(in) :: result_ncid
5830 
5831 ! Local variables
5832  INTEGER :: status
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
5842 
5843 ! Start of executable code
5844  start_time = profiler_get_start_time()
5845 
5846  IF (nextcur .gt. 0) THEN
5847  status = nf_inq_varid(result_ncid, 'vmec_extcur', &
5848  & vmec_extcur_id)
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))
5853  END IF
5854 
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, &
5858  & curtor)
5859  CALL assert_eq(status, nf_noerr, nf_strerror(status))
5860 
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, &
5865  & pres_scale)
5866  CALL assert_eq(status, nf_noerr, nf_strerror(status))
5867 
5868  boundary_size(1) = 2*ntor + 1
5869  boundary_size(2) = mpol1 + 1
5870 
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))
5877 
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))
5884 
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))
5891 
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))
5898 
5899  CALL vmec_write_step_data(this, result_ncid, 1)
5900 
5901  CALL profiler_set_stop_time('vmec_write_init_data', start_time)
5902 
5903  END SUBROUTINE
5904 
5905 !-------------------------------------------------------------------------------
5913 !-------------------------------------------------------------------------------
5914  SUBROUTINE vmec_write_step_data(this, result_ncid, current_step)
5915  USE v3f_vmec_comm
5916  USE ezcdf
5917  USE xstuff, only: xc
5918 
5919  IMPLICIT NONE
5920 
5921 ! Declare Arguments
5922  TYPE (vmec_class), INTENT(in) :: this
5923  INTEGER, INTENT(in) :: result_ncid
5924  INTEGER, INTENT(in) :: current_step
5925 
5926 ! Local variables
5927  INTEGER :: status
5928  INTEGER :: vmec_l_sub_i_id
5929  INTEGER :: vmec_kappa_p_id
5930  INTEGER :: vmec_xc_id
5931  REAL (rprec) :: start_time
5932 
5933 ! Start of executable code
5934  start_time = profiler_get_start_time()
5935 
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))
5941 
5942  status = nf_inq_varid(result_ncid, 'vmec_l_sub_i', &
5943  & vmec_l_sub_i_id)
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))
5948 
5949  status = nf_inq_varid(result_ncid, 'vmec_kappa_p', &
5950  & vmec_kappa_p_id)
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))
5955 
5956  CALL profiler_set_stop_time('vmec_write_step_data', start_time)
5957 
5958  END SUBROUTINE
5959 
5960 !-------------------------------------------------------------------------------
5968 !-------------------------------------------------------------------------------
5969  SUBROUTINE vmec_restart(this, result_ncid, current_step)
5970  USE v3f_vmec_comm
5971  USE ezcdf
5972  USE xstuff, only: xc
5973 
5974  IMPLICIT NONE
5975 
5976 ! Declare Arguments
5977  TYPE (vmec_class), INTENT(in) :: this
5978  INTEGER, INTENT(in) :: result_ncid
5979  INTEGER, INTENT(in) :: current_step
5980 
5981 ! Local variables
5982  INTEGER :: status
5983  INTEGER :: vmec_l_sub_i_id
5984  INTEGER :: vmec_kappa_p_id
5985  INTEGER :: vmec_xc_id
5986  REAL (rprec) :: start_time
5987 
5988 ! Start of executable code
5989  start_time = profiler_get_start_time()
5990 
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))
5996 
5997  status = nf_inq_varid(result_ncid, 'vmec_l_sub_i', &
5998  & vmec_l_sub_i_id)
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))
6003 
6004  status = nf_inq_varid(result_ncid, 'vmec_kappa_p', &
6005  & vmec_kappa_p_id)
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))
6010 
6011  CALL profiler_set_stop_time('vmec_restart', start_time)
6012 
6013  END SUBROUTINE
6014 
6015 !*******************************************************************************
6016 ! MPI SUBROUTINES
6017 !*******************************************************************************
6018 !-------------------------------------------------------------------------------
6026 !-------------------------------------------------------------------------------
6027  SUBROUTINE vmec_sync_state(this, recon_comm)
6028  USE read_wout_mod, only: read_wout_file, loadrzl
6029  USE file_opts
6030 
6031  IMPLICIT NONE
6032 
6033 ! Declare Arguments
6034  TYPE (vmec_class), INTENT(inout) :: this
6035  INTEGER, INTENT(in) :: recon_comm
6036 
6037 #if defined(MPI_OPT)
6038 ! local variables
6039  INTEGER :: i
6040  INTEGER :: error
6041  INTEGER :: mpi_rank
6042 
6043 ! Start of executable code
6044  CALL mpi_comm_rank(recon_comm, mpi_rank, error)
6045 
6046 ! The barrier ensures that the wout is ready to be copied from the parent
6047 ! directory. Otherwise a child process can try to copy a wout file that does
6048 ! not exist.
6049  CALL mpi_barrier(recon_comm, error)
6050 
6051 ! If this is the child process, load the wout file.
6052  IF (mpi_rank .gt. 0) THEN
6053  CALL copy_file(build_path('..', this%wout_file_name), &
6054  & trim(this%wout_file_name), error)
6055 
6056  CALL read_wout_file(this%wout_file_name, error)
6057  CALL assert_eq(error, 0, 'Error reading synced wout file.')
6058  CALL loadrzl
6059 
6060  IF (ASSOCIATED(this%magnetic_cache)) THEN
6061  CALL vmec_set_magnetic_cache(this)
6062  END IF
6063  END IF
6064 
6065  CALL vmec_context_sync_state(this%vmec_context_save, recon_comm)
6066 
6067 #endif
6068  END SUBROUTINE
6069 
6070 !-------------------------------------------------------------------------------
6079 !-------------------------------------------------------------------------------
6080  SUBROUTINE vmec_sync_child(this, index, recon_comm)
6081  USE read_wout_mod, only: read_wout_file, loadrzl
6082  USE file_opts
6083 
6084  IMPLICIT NONE
6085 
6086 ! Declare Arguments
6087  TYPE (vmec_class), INTENT(inout) :: this
6088  INTEGER, INTENT(in) :: index
6089  INTEGER, INTENT(in) :: recon_comm
6090 
6091 #if defined(MPI_OPT)
6092 ! local variables
6093  INTEGER :: error
6094  INTEGER :: mpi_rank
6095 
6096 ! Start of executable code
6097  CALL mpi_comm_rank(recon_comm, mpi_rank, error)
6098 
6099 ! If this is the parent process, load the wout file.
6100  IF (mpi_rank .eq. 0) THEN
6101  CALL copy_file(build_path(process_dir(index + 1), &
6102  & this%wout_file_name), &
6103  & trim(this%wout_file_name), error)
6104 
6105  CALL read_wout_file(this%wout_file_name, error)
6106  CALL assert_eq(error, 0, 'Error reading synced wout file.')
6107  CALL loadrzl
6108 
6109  IF (ASSOCIATED(this%magnetic_cache)) THEN
6110  CALL vmec_set_magnetic_cache(this)
6111  END IF
6112  END IF
6113 
6114  CALL vmec_context_sync_child(this%vmec_context_save, index, &
6115  & recon_comm)
6116 
6117 #endif
6118  END SUBROUTINE
6119 
6120 !*******************************************************************************
6121 ! PRIVATE
6122 !*******************************************************************************
6123 !-------------------------------------------------------------------------------
6130 !-------------------------------------------------------------------------------
6131  SUBROUTINE vmec_reset_boundary(this)
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
6139 
6140  IMPLICIT NONE
6141 
6142 ! Declare Arguments
6143  TYPE (vmec_class), INTENT(in) :: this
6144 
6145 ! local variables
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
6153 
6154 ! Start of executable code
6155  start_time = profiler_get_start_time()
6156 
6157  IF (lasym) THEN
6158 ! Convert to representation with rbs(m=1) = zbc(m=1)
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
6162  DO m = 0, mpol1
6163  DO n = -ntor, ntor
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)
6167  rbc(n,m) = temp
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)
6171  zbc(n,m) = temp
6172  END DO
6173  END DO
6174  END IF
6175  END IF
6176 
6177 ! Convert to internal representation of modes
6178 !
6179 ! r = rbcc*cos(m*u)*cos(n*v) + rbss*sin(m*u)*sin(n*v)
6180 ! + rbcs*cos(m*u)*sin(n*v) + rbsc*sin(m*u)*cos(n*v)
6181 ! z = zbcs*cos(m*u)*sin(n*v) + zbsc*sin(m*u)*cos(n*v)
6182 ! + zbcc*cos(m*u)*cos(n*v) + zbsz*sin(m*u)*sin(n*v)
6183 
6184  rbcc => rmn_bdy(:,:,rcc)
6185  zbsc => zmn_bdy(:,:,zsc)
6186  IF (lthreed) THEN
6187  rbss => rmn_bdy(:,:,rss)
6188  zbcs => zmn_bdy(:,:,zcs)
6189  END IF
6190 
6191  IF (lasym) THEN
6192  rbsc => rmn_bdy(:,:,rsc)
6193  zbcc => zmn_bdy(:,:,zcc)
6194  IF (lthreed) THEN
6195  rbcs => rmn_bdy(:,:,rcs)
6196  zbss => zmn_bdy(:,:,zss)
6197  END IF
6198  END IF
6199 
6200  rmn_bdy = 0.0
6201  zmn_bdy = 0.0
6202 
6203  IF (.not.lfreeb) THEN
6204  DO m = 0, mpol1
6205  IF ((mfilter_fbdy .gt. 1) .and. (m .gt. mfilter_fbdy)) THEN
6206  EXIT
6207  END IF
6208 
6209  mj = m + lbound(rbcc, 2)
6210  DO n = -ntor, ntor
6211  IF ((nfilter_fbdy .gt. 0) .and. &
6212  & (abs(n) .gt. nfilter_fbdy)) THEN
6213  cycle
6214  END IF
6215 
6216  ni = abs(n) + lbound(rbcc, 1)
6217 
6218  IF (n .eq. 0) THEN
6219  sgn = 0.0
6220  ELSE IF (n .gt. 0) THEN
6221  sgn = 1.0
6222  ELSE
6223  sgn = -1.0
6224  END IF
6225 
6226  rbcc(ni,mj) = rbcc(ni,mj) + rbc(n,m)
6227  IF (m .gt. 0) THEN
6228  zbsc(ni,mj) = zbsc(ni,mj) + zbs(n,m)
6229  END IF
6230 
6231  IF (lthreed) THEN
6232  zbcs(ni,mj) = zbcs(ni,mj) - sgn*zbs(n,m)
6233  IF (m .gt. 0) THEN
6234  rbss(ni,mj) = rbss(ni,mj) + sgn*rbc(n,m)
6235  END IF
6236  END IF
6237 
6238  IF (lasym) THEN
6239  zbcc(ni,mj) = zbcc(ni,mj) + zbc(n,m)
6240  IF (m .gt. 0) THEN
6241  rbsc(ni,mj) = rbsc(ni,mj) + rbs(n,m)
6242  END IF
6243 
6244  IF (lthreed) THEN
6245  rbcs(ni,mj) = rbcs(ni,mj) - sgn*rbs(n,m)
6246  IF (m .gt. 0) THEN
6247  zbss(ni,mj) = zbss(ni,mj) + sgn*zbc(n,m)
6248  END IF
6249  END IF
6250  END IF
6251  END DO
6252  END DO
6253  END IF
6254 
6255 ! Check sign of jacobian (should be same as signgs)
6256  mj = 1 + lbound(rbcc, 2)
6257  signgs = 1.0
6258  IF (sum(rbcc(1:ntor1,mj))*sum(zbsc(1:ntor1,mj)) .gt. 0.0) THEN
6259  signgs = -1.0
6260  END IF
6261 
6262 ! Convert to internal form for (constrained) m=1 modes
6263  IF (lconm1 .and. (lthreed .or. lasym)) THEN
6264  ALLOCATE(temp_array(SIZE(rbcc, 1)))
6265  IF (lthreed) THEN
6266  temp_array = rbss(:,mj)
6267  rbss(:,mj) = cp5*(temp_array + zbcs(:,mj))
6268  zbcs(:,mj) = cp5*(temp_array - zbcs(:,mj))
6269  END IF
6270 
6271  IF (lasym) THEN
6272  temp_array = rbsc(:,mj)
6273  rbsc(:,mj) = cp5*(temp_array + zbcc(:,mj))
6274  zbcc(:,mj) = cp5*(temp_array - zbcc(:,mj))
6275  END IF
6276  DEALLOCATE(temp_array)
6277  END IF
6278 
6279  CALL profiler_set_stop_time('vmec_reset_boundary', start_time)
6280 
6281  END SUBROUTINE
6282 
6283  END MODULE
model_state::model_state_shift_flag
integer, parameter model_state_shift_flag
Shift parameter changed bit position.
Definition: model_state.f:36
vmec_equilibrium::vmec_get_ti_radial
real(rprec) function vmec_get_ti_radial(this, s)
Gets the ion temperature at a s position.
Definition: vmec_equilibrium.f:3531
vmec_equilibrium::vmec_zmns_id
integer, parameter vmec_zmns_id
2D Array of surface Z sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:194
model_state::model_state_ze_flag
integer, parameter model_state_ze_flag
Effective charge profile changed bit position.
Definition: model_state.f:38
vmec_equilibrium::vmec_ac_id
integer, parameter vmec_ac_id
1D Array of function current profile parameters. Defined in vmec_input.
Definition: vmec_equilibrium.f:151
pprofile_t::pprofile_class
Base class representing a parameterized profile.
Definition: pprofile_T.f:139
vmec_equilibrium::vmec_get_gp_sxrem_pp
real(rprec) function vmec_get_gp_sxrem_pp(this, x_cart, y_cart, index)
Get the soft x-ray emissivity gp kernel value for the position and position.
Definition: vmec_equilibrium.f:3794
vmec_equilibrium::vmec_set_magnetic_cache_point
subroutine vmec_set_magnetic_cache_point(this, use_axi)
Set magnetic cache initialy.
Definition: vmec_equilibrium.f:1362
pprofile_t::pprofile_get_gp_num_hyper_param
integer function pprofile_get_gp_num_hyper_param(this)
Get the number of hyper parameters for guassian process kernel.
Definition: pprofile_T.f:674
vmec_equilibrium::vmec_get_int_b_dphi
real(rprec) function vmec_get_int_b_dphi(this, r, theta)
Gets the loop integrated magnetic field at a position.
Definition: vmec_equilibrium.f:4044
coordinate_utilities
Module is part of the LIBSTELL. This modules containes code to convert from different coordinate syst...
Definition: coordinate_utilities.f:12
vmec_equilibrium::vmec_converge
logical function vmec_converge(this, num_iter, iou, eq_comm)
Solves the VMEC equilibrium.
Definition: vmec_equilibrium.f:5202
vmec_equilibrium::vmec_write
subroutine vmec_write(this, iou)
Write out the equilibrium to an output file.
Definition: vmec_equilibrium.f:5549
vmec_equilibrium::vmec_pres_scale_id
integer, parameter vmec_pres_scale_id
The scaling parameter for the pressure. Defined in vmec_input.
Definition: vmec_equilibrium.f:188
vmec_equilibrium::vmec_zaxis_cc_id
integer, parameter vmec_zaxis_cc_id
1D Array of magnetic axis Z cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:238
vmec_equilibrium::vmec_rbc_id
integer, parameter vmec_rbc_id
2D Array of outer boundary R cosine coeffiecents. Defined in vmec_input.
Definition: vmec_equilibrium.f:173
vmec_equilibrium::vmec_is_1d_array
logical function vmec_is_1d_array(this, id)
Checks if a parameter id is a 1d array.
Definition: vmec_equilibrium.f:5020
vmec_equilibrium::vmec_write_step_data
subroutine vmec_write_step_data(this, result_ncid, current_step)
Write step data to NetCDF result file.
Definition: vmec_equilibrium.f:5915
vmec_equilibrium::vmec_get_ne
Interface for the vmec density profile values.
Definition: vmec_equilibrium.f:483
vmec_equilibrium::vmec_get_ext_currents
real(rprec) function, dimension(:), pointer vmec_get_ext_currents(this, num_currents, scale_currents)
Get external current.
Definition: vmec_equilibrium.f:4611
vmec_equilibrium::vmec_get_gp_ti_pp
real(rprec) function vmec_get_gp_ti_pp(this, x_cart, y_cart)
Get the ion temperature gp kernel value for the position and position.
Definition: vmec_equilibrium.f:3460
vmec_equilibrium::vmec_get_suv
real(rprec) function, dimension(3) vmec_get_suv(this, x_cart)
Gets VMEC suv position.
Definition: vmec_equilibrium.f:4087
file_opts::copy_file
subroutine copy_file(file_source, file_dest, error)
Copies the source file to the destination.
Definition: file_opts.f:78
vmec_equilibrium::vmec_qfact_id
integer, parameter vmec_qfact_id
1D Array of full grid safety factor. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:242
vmec_equilibrium::vmec_get_ne_af
real(rprec) function, dimension(:), pointer vmec_get_ne_af(this)
Gets the electron density profile af array.
Definition: vmec_equilibrium.f:2839
vmec_equilibrium::vmec_get_param_name
character(len=data_name_length) function vmec_get_param_name(this, id)
Get the name of a reconstruction VMEC parameter.
Definition: vmec_equilibrium.f:2557
vmec_equilibrium::vmec_get_sxrem
Interface for the vmec soft x-ray emissivity profile values.
Definition: vmec_equilibrium.f:534
magnetic_response::magnetic_response_use_shell
logical function magnetic_response_use_shell(this)
Checks if the conducting shell flag is set.
Definition: magnetic_response.f:831
vmec_equilibrium::vmec_get_sxrem_radial
real(rprec) function vmec_get_sxrem_radial(this, s, index)
Gets the soft x-ray emissivity at a s position.
Definition: vmec_equilibrium.f:3873
vmec_equilibrium::vmec_rbs_id
integer, parameter vmec_rbs_id
2D Array of outer boundary R sine coeffiecents. Defined in vmec_input.
Definition: vmec_equilibrium.f:177
vmec_equilibrium::vmec_get_p_radial
real(rprec) function vmec_get_p_radial(this, s)
Gets the plasma pressure at a s position.
Definition: vmec_equilibrium.f:3939
vmec_equilibrium::vmec_get_gp_te
Interface for the vmec guassian process electron temperature profile values.
Definition: vmec_equilibrium.f:508
vmec_equilibrium::vmec_construct
Interface for the construction of vmec_class types using vmec_construct_full or vmec_construct_eq.
Definition: vmec_equilibrium.f:448
vmec_equilibrium::vmec_get_con_surface_kzgrid
real(rprec) function, dimension(:,:), pointer vmec_get_con_surface_kzgrid(this)
Get the conducting surface integration kz grid points.
Definition: vmec_equilibrium.f:4537
vmec_equilibrium::vmec_bsupumns_id
integer, parameter vmec_bsupumns_id
2D Array of surface B^u sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:224
vmec_equilibrium::vmec_am_aux_f_id
integer, parameter vmec_am_aux_f_id
1D Array of segment pressure profile f values. Defined in vmec_input.
Definition: vmec_equilibrium.f:168
vmec_equilibrium::vmec_pp_te_b_id
integer, parameter vmec_pp_te_b_id
1D Array of function electron temperature profile parameters. Defined in pprofile_T.
Definition: vmec_equilibrium.f:259
vmec_equilibrium::vmec_zaxis_cs_id
integer, parameter vmec_zaxis_cs_id
1D Array of magnetic axis Z sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:240
vmec_equilibrium::vmec_pp_ti_b_id
integer, parameter vmec_pp_ti_b_id
1D Array of function ion temperature profile parameters. Defined in pprofile_T.
Definition: vmec_equilibrium.f:268
vmec_equilibrium::vmec_vvc_smaleli_id
integer, parameter vmec_vvc_smaleli_id
Internal inducance. Defined in v3f_vmec_comm. Computed in eqfor.
Definition: vmec_equilibrium.f:287
vmec_equilibrium::vmec_get_gp_te_ij
real(rprec) function vmec_get_gp_te_ij(this, i, j)
Get the electron temperature gp kernel value for the two indicies.
Definition: vmec_equilibrium.f:3127
vmec_equilibrium::vmec_ai_id
integer, parameter vmec_ai_id
1D Array of function iotabar profile parameters. Defined in vmec_input.
Definition: vmec_equilibrium.f:157
vmec_equilibrium::vmec_vvc_kappa_p_id
integer, parameter vmec_vvc_kappa_p_id
Mean elongation. Defined in v3f_vmec_comm. Computed in eqfor.
Definition: vmec_equilibrium.f:289
vmec_equilibrium::vmec_gmnc_id
integer, parameter vmec_gmnc_id
2D Array of surface g cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:198
vmec_equilibrium::vmec_get_ze_cart
real(rprec) function vmec_get_ze_cart(this, x_cart)
Gets the effective charge at a cartesian position.
Definition: vmec_equilibrium.f:3565
vmec_equilibrium::vmec_read_vac_file
subroutine vmec_read_vac_file(this, index, eq_comm)
Loads the vacuum magnetic field file.
Definition: vmec_equilibrium.f:5395
vmec_equilibrium::vmec_jdotb_id
integer, parameter vmec_jdotb_id
Current density in direction of b field. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:303
pprofile_t::pprofile_pointer
Pointer to a pprofile object. Used for creating arrays of pprofile pointers. This is needed because f...
Definition: pprofile_T.f:161
vmec_equilibrium::vmec_class
Base class representing a vmec_equilibrium.
Definition: vmec_equilibrium.f:396
magnetic_response::magnetic_response_use_plasma
logical function magnetic_response_use_plasma(this)
Checks if the plasma flag is set.
Definition: magnetic_response.f:800
vmec_equilibrium::vmec_ai_aux_s_id
integer, parameter vmec_ai_aux_s_id
1D Array of segment iotabar profile s poitions. Defined in vmec_input.
Definition: vmec_equilibrium.f:159
vmec_equilibrium::vmec_pp_ze_b_id
integer, parameter vmec_pp_ze_b_id
1D Array of function zeff profile parameters. Defined in pprofile_T.
Definition: vmec_equilibrium.f:277
vmec_context::vmec_context_construct
type(vmec_context_class) function, pointer vmec_context_construct()
Construct a new vmec_context_class object.
Definition: vmec_context.f:63
vmec_equilibrium::vmec_get_gp_ne_pi
real(rprec) function vmec_get_gp_ne_pi(this, x_cart, i)
Get the electron density gp kernel value for the position and index.
Definition: vmec_equilibrium.f:2911
vmec_equilibrium::vmec_pp_sxrem_af_id
integer, parameter vmec_pp_sxrem_af_id
1D Array of segment sxrem profile f values. Defined in pprofile_T.
Definition: vmec_equilibrium.f:256
file_opts::get_path_of_file
character(len=path_length) function get_path_of_file(file)
Returns the directory of a file.
Definition: file_opts.f:354
pprofile_t::pprofile_get_value
real(rprec) function pprofile_get_value(this, s_arg)
Gets the value of a profile at a radial position.
Definition: pprofile_T.f:350
vmec_equilibrium::vmec_get_gp_sxrem_pi
real(rprec) function vmec_get_gp_sxrem_pi(this, x_cart, i, index)
Get the soft x-ray emissivity gp kernel value for the position and index.
Definition: vmec_equilibrium.f:3748
vmec_equilibrium::vmec_get_gp_ti_ij
real(rprec) function vmec_get_gp_ti_ij(this, i, j)
Get the ion temperature gp kernel value for the two indicies.
Definition: vmec_equilibrium.f:3382
vmec_equilibrium::vmec_get_plasma_edge
integer function vmec_get_plasma_edge(this, phi, r, z)
Gets the r and z positions of the outer surface at a toroidal angle.
Definition: vmec_equilibrium.f:4227
vmec_equilibrium::vmec_get_te_radial
real(rprec) function vmec_get_te_radial(this, s)
Gets the electron temperature at a s position.
Definition: vmec_equilibrium.f:3278
vmec_equilibrium::vmec_betapol_id
integer, parameter vmec_betapol_id
Poloidal Beta. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:293
coordinate_utilities::cart_to_cyl_vec
pure real(rprec) function, dimension(3) cart_to_cyl_vec(cart, vec)
Convert vector from cartesian coordinates to cylindical coordinates.
Definition: coordinate_utilities.f:126
vmec_equilibrium::vmec_get_gp_ne_num_hyper_param
integer function vmec_get_gp_ne_num_hyper_param(this)
Get the number of electron density gp kernel hyper parameters.
Definition: vmec_equilibrium.f:2804
vmec_equilibrium::vmec_z_offset_id
integer, parameter vmec_z_offset_id
Plasma z offset. This is a parameter to allow changing the vertical shift of the plasma.
Definition: vmec_equilibrium.f:310
vmec_equilibrium::vmec_bsupumnc_id
integer, parameter vmec_bsupumnc_id
2D Array of surface B^u cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:206
vmec_equilibrium::vmec_extcur_id
integer, parameter vmec_extcur_id
1D Array of external currents. Defined in vmec_input.
Definition: vmec_equilibrium.f:182
vmec_equilibrium::vmec_get_param_id
integer function vmec_get_param_id(this, param_name)
Get the id for a reconstruction parameter.
Definition: vmec_equilibrium.f:2045
vmec_equilibrium::vmec_get_gp_sxrem_ij
real(rprec) function vmec_get_gp_sxrem_ij(this, i, j, index)
Get the soft x-ray emissivity gp kernel value for the two indicies.
Definition: vmec_equilibrium.f:3706
vmec_equilibrium::vmec_get_ti
Interface for the vmec ion temperature profile values.
Definition: vmec_equilibrium.f:517
model_state::model_state_te_flag
integer, parameter model_state_te_flag
Temperature profile changed bit position.
Definition: model_state.f:32
vmec_equilibrium::vmec_ai_aux_f_id
integer, parameter vmec_ai_aux_f_id
1D Array of segment iotabar profile f values. Defined in vmec_input.
Definition: vmec_equilibrium.f:161
vmec_equilibrium::vmec_get_gp_te_pi
real(rprec) function vmec_get_gp_te_pi(this, x_cart, i)
Get the electron temperature gp kernel value for the position and index.
Definition: vmec_equilibrium.f:3165
vmec_equilibrium::vmec_get_te_cart
real(rprec) function vmec_get_te_cart(this, x_cart)
Gets the electron temperature at a cartesian position.
Definition: vmec_equilibrium.f:3248
vmec_equilibrium::vmec_construct_full
type(vmec_class) function, pointer vmec_construct_full(file_name, wout_file_name, ne, te, ti, ze, sxrem, phi_offset, z_offset, pol_rad_ratio, iou, eq_comm, recon_comm, state_flags)
Construct a vmec_class object.
Definition: vmec_equilibrium.f:789
vmec_equilibrium::vmec_phi_id
integer, parameter vmec_phi_id
Defined in read_wout_mod.
Definition: vmec_equilibrium.f:228
vmec_equilibrium::vmec_pp_sxrem_b_id
integer, parameter vmec_pp_sxrem_b_id
1D Array of function sxrem profile parameters. Defined in pprofile_T.
Definition: vmec_equilibrium.f:252
coordinate_utilities::cyl_to_cart_vec
pure real(rprec) function, dimension(3), public cyl_to_cart_vec(cyl, vec)
Convert vector from cylindical coordinates to cartesian coordinates.
Definition: coordinate_utilities.f:95
vmec_equilibrium::vmec_pp_sxrem_as_id
integer, parameter vmec_pp_sxrem_as_id
1D Array of segment sxrem profile s poitions. Defined in pprofile_T.
Definition: vmec_equilibrium.f:254
file_opts::is_absolute_path
logical function is_absolute_path(path)
Queries if the a path is absoulte.
Definition: file_opts.f:309
vmec_equilibrium::vmec_set_magnetic_cache
Interface for the setting the vmec_magnetic_cache types using vmec_set_magnetic_cache_responce,...
Definition: vmec_equilibrium.f:458
vmec_equilibrium::vmec_reset_boundary
subroutine vmec_reset_boundary(this)
Reset the fixed boundary coefficients.
Definition: vmec_equilibrium.f:6132
vmec_equilibrium::vmec_jcuru_id
integer, parameter vmec_jcuru_id
Poloidal current density. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:299
vmec_equilibrium::vmec_get_volume_int_element
real(rprec) function vmec_get_volume_int_element(this)
Get volume integration element.
Definition: vmec_equilibrium.f:4445
vmec_equilibrium::vmec_raxis_cc_id
integer, parameter vmec_raxis_cc_id
1D Array of magnetic axis R cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:234
vmec_equilibrium::vmec_get_gp_ne_ij
real(rprec) function vmec_get_gp_ne_ij(this, i, j)
Get the electron density gp kernel value for the two indicies.
Definition: vmec_equilibrium.f:2874
vmec_equilibrium::vmec_bsubsmns_id
integer, parameter vmec_bsubsmns_id
2D Array of surface B_s sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:200
vmec_equilibrium::vmec_get_ti_af
real(rprec) function, dimension(:), pointer vmec_get_ti_af(this)
Gets the ion temperature profile af array.
Definition: vmec_equilibrium.f:3347
vmec_equilibrium::vmec_raxis_cs_id
integer, parameter vmec_raxis_cs_id
1D Array of magnetic axis R sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:236
vmec_equilibrium::vmec_set_namelist
subroutine vmec_set_namelist(this)
Sets namelist variables from the solved VMEC equilibrium.
Definition: vmec_equilibrium.f:1987
vmec_equilibrium::vmec_restart
subroutine vmec_restart(this, result_ncid, current_step)
Restart vmec from the result file.
Definition: vmec_equilibrium.f:5970
vmec_equilibrium::vmec_get_gp_te_pp
real(rprec) function vmec_get_gp_te_pp(this, x_cart, y_cart)
Get the electron temperature gp kernel value for the position and position.
Definition: vmec_equilibrium.f:3207
model_state
Contains parameters defining the bit positions for flags that mark changes in different parts of the ...
Definition: model_state.f:11
vmec_equilibrium::vmec_pp_te_as_id
integer, parameter vmec_pp_te_as_id
1D Array of segment electron temperature profile s poitions. Defined in pprofile_T.
Definition: vmec_equilibrium.f:262
file_opts::delete_file
subroutine delete_file(file_source, error)
Deletes a file.
Definition: file_opts.f:215
vmec_equilibrium::vmec_get_gp_ti_pi
real(rprec) function vmec_get_gp_ti_pi(this, x_cart, i)
Get the ion temperature gp kernel value for the position and index.
Definition: vmec_equilibrium.f:3420
vmec_equilibrium::vmec_bsubvmns_id
integer, parameter vmec_bsubvmns_id
2D Array of surface B_v sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:222
vmec_equilibrium::vmec_get_te
Interface for the vmec electron temperature profile values.
Definition: vmec_equilibrium.f:500
vmec_equilibrium::vmec_pp_te_af_id
integer, parameter vmec_pp_te_af_id
1D Array of segment electron temperature profile f values. Defined in pprofile_T.
Definition: vmec_equilibrium.f:265
vmec_context::vmec_context_set_context
subroutine vmec_context_set_context(this)
Sets the current context to the vmec_context_class object.
Definition: vmec_context.f:147
vmec_context::vmec_context_class
Base class representing a vmec_context. This contains a copy of every variable that is needed to defi...
Definition: vmec_context.f:31
vmec_equilibrium::vmec_get_magnetic_volume_jphigrid
real(rprec) function, dimension(:,:,:), pointer vmec_get_magnetic_volume_jphigrid(this)
Get volume magnetic volume integration jphi grid points.
Definition: vmec_equilibrium.f:4379
vmec_equilibrium::vmec_phiedge_id
integer, parameter vmec_phiedge_id
The edge magnetic flux. Defined in vmec_input.
Definition: vmec_equilibrium.f:186
vmec_equilibrium::vmec_get_ext_b_plasma
real(rprec) function, dimension(3) vmec_get_ext_b_plasma(this, position, axi_only)
Get external plasma magnetic field.
Definition: vmec_equilibrium.f:4792
vmec_equilibrium::vmec_betatot_id
integer, parameter vmec_betatot_id
Total Beta. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:291
vmec_equilibrium::vmec_rmns_id
integer, parameter vmec_rmns_id
2D Array of surface R sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:210
sxrem
Defines the base class of the type sxrem_class.
Definition: sxrem.f:13
vmec_equilibrium::vmec_get_sxrem_cart
real(rprec) function vmec_get_sxrem_cart(this, x_cart, index)
Gets the soft x-ray emissivity at a cartesian position.
Definition: vmec_equilibrium.f:3839
vmec_equilibrium::vmec_get_magnetic_volume_jzgrid
real(rprec) function, dimension(:,:,:), pointer vmec_get_magnetic_volume_jzgrid(this)
Get volume magnetic volume integration jz grid points.
Definition: vmec_equilibrium.f:4409
vmec_equilibrium::vmec_get_ne_radial
real(rprec) function vmec_get_ne_radial(this, s)
Gets the electron density at a s position.
Definition: vmec_equilibrium.f:3022
model_state::model_state_ti_flag
integer, parameter model_state_ti_flag
Ion profile changed bit position.
Definition: model_state.f:34
pprofile_t::pprofile_save_state
subroutine pprofile_save_state(this)
Save the internal state of the profile.
Definition: pprofile_T.f:781
vmec_equilibrium::vmec_pp_ti_as_id
integer, parameter vmec_pp_ti_as_id
1D Array of segment ion temperature profile s poitions. Defined in pprofile_T.
Definition: vmec_equilibrium.f:271
pprofile_t::pprofile_get_gp
Interface for the guassian process kernel values.
Definition: pprofile_T.f:171
vmec_equilibrium::vmec_bsupvmnc_id
integer, parameter vmec_bsupvmnc_id
2D Array of surface B^v cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:208
vmec_equilibrium::vmec_get_grid_stop
real(rprec) function vmec_get_grid_stop(this)
Get radial grid size.
Definition: vmec_equilibrium.f:4949
vmec_equilibrium::vmec_sync_child
subroutine vmec_sync_child(this, index, recon_comm)
Syncronize a child vmec state to the parent.
Definition: vmec_equilibrium.f:6081
vmec_equilibrium::vmec_pp_ti_af_id
integer, parameter vmec_pp_ti_af_id
1D Array of segment ion temperature profile f values. Defined in pprofile_T.
Definition: vmec_equilibrium.f:274
vmec_equilibrium::vmec_bsubsmnc_id
integer, parameter vmec_bsubsmnc_id
2D Array of surface B_s cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:218
model_state::model_state_vmec_flag
integer, parameter model_state_vmec_flag
VMEC Equilibrium changed bit position.
Definition: model_state.f:26
vmec_equilibrium::vmec_phi_offset_id
integer, parameter vmec_phi_offset_id
Plasma Phi offset. This is a parameter to allow changing the phi angle of a quasi helical state in an...
Definition: vmec_equilibrium.f:307
pprofile_t::pprofile_write
subroutine pprofile_write(this, id, iou)
Write out the profile to an output file.
Definition: pprofile_T.f:715
coordinate_utilities::cyl_to_cart
pure real(rprec) function, dimension(3), public cyl_to_cart(cyl)
Convert a point from cylindical coordinates to cartesian coordinates.
Definition: coordinate_utilities.f:67
vmec_equilibrium::runvmec
Forward declare the interface for runvmec.
Definition: vmec_equilibrium.f:470
vmec_context::vmec_context_sync_state
subroutine vmec_context_sync_state(this, recon_comm)
Syncronize the vmec_context to children.
Definition: vmec_context.f:233
file_opts
Contains cross platform routines for manipulating files on the file system. Defines a functions to mo...
Definition: file_opts.f:13
vmec_equilibrium::vmec_zbs_id
integer, parameter vmec_zbs_id
2D Array of outer boundary Z sine coeffiecents. Defined in vmec_input.
Definition: vmec_equilibrium.f:175
model_state::model_state_sxrem_flag
integer, parameter model_state_sxrem_flag
Soft x-ray emissivity profile changed bit position. This flag needs to always be the last flag an can...
Definition: model_state.f:46
vmec_equilibrium::vmec_betaxis_id
integer, parameter vmec_betaxis_id
Beta on axis. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:297
vmec_equilibrium::vmec_ac_aux_f_id
integer, parameter vmec_ac_aux_f_id
1D Array of segment current profile f values. Defined in vmec_input.
Definition: vmec_equilibrium.f:155
vmec_equilibrium::vmec_bloat_id
integer, parameter vmec_bloat_id
Defined in vmec_input.
Definition: vmec_equilibrium.f:170
vmec_equilibrium::vmec_pp_ze_as_id
integer, parameter vmec_pp_ze_as_id
1D Array of segment zeff profile s poitions. Defined in pprofile_T.
Definition: vmec_equilibrium.f:280
vmec_equilibrium::vmec_iotaf_id
integer, parameter vmec_iotaf_id
1D Array of full grid iotabar. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:230
vmec_equilibrium::vmec_get_gp_ne
Interface for the vmec guassian process density profile values.
Definition: vmec_equilibrium.f:491
vmec_equilibrium::vmec_betator_id
integer, parameter vmec_betator_id
Toroidal Beta. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:295
vmec_equilibrium::vmec_iotas_id
integer, parameter vmec_iotas_id
1D Array of half grid iotabar. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:232
vmec_equilibrium::vmec_bsupvmns_id
integer, parameter vmec_bsupvmns_id
2D Array of surface B^v sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:226
vmec_equilibrium::vmec_get_grid_size
integer function vmec_get_grid_size(this)
Get radial grid size.
Definition: vmec_equilibrium.f:4896
vmec_equilibrium::vmec_am_aux_s_id
integer, parameter vmec_am_aux_s_id
1D Array of segment pressure profile s poitions. Defined in vmec_input.
Definition: vmec_equilibrium.f:166
vmec_equilibrium::vmec_pp_ne_af_id
integer, parameter vmec_pp_ne_af_id
1D Array of segment density profile f values. Defined in pprofile_T.
Definition: vmec_equilibrium.f:250
vmec_context::vmec_context_sync_child
subroutine vmec_context_sync_child(this, index, recon_comm)
Syncronize a child vmec_context to the parent.
Definition: vmec_context.f:287
file_opts::build_path
character(len=path_length) function build_path(path, name)
Builds a path.
Definition: file_opts.f:382
vmec_equilibrium::vmec_get_flux
real(rprec) function vmec_get_flux(this, x_cart)
Gets VMEC normalized flux value at position.
Definition: vmec_equilibrium.f:4183
model_state::model_state_ne_flag
integer, parameter model_state_ne_flag
Denisty profile changed bit position.
Definition: model_state.f:30
vmec_equilibrium::vmec_save_state
subroutine vmec_save_state(this)
Save the internal state of the equilibrium.
Definition: vmec_equilibrium.f:5429
vmec_equilibrium::vmec_is_2d_array
logical function vmec_is_2d_array(this, id)
Checks if a parameter id is a 2d array.
Definition: vmec_equilibrium.f:5067
vmec_context
Defines the base class of the type vmec_context_class. This contains the state variables needed by VM...
Definition: vmec_context.f:11
vmec_equilibrium::vmec_get_b_vac
real(rprec) function, dimension(3) vmec_get_b_vac(this, r_cyl)
Gets the vacuum magnetic field vector at a position.
Definition: vmec_equilibrium.f:4662
vmec_equilibrium::vmec_get_gp_ti_num_hyper_param
integer function vmec_get_gp_ti_num_hyper_param(this)
Get the number of ion temperature gp kernel hyper parameters.
Definition: vmec_equilibrium.f:3312
vmec_equilibrium::vmec_am_id
integer, parameter vmec_am_id
1D Array of function pressure profile parameters. Defined in vmec_input.
Definition: vmec_equilibrium.f:164
file_opts::create_directory
subroutine create_directory(directory_source, error)
Makes a directory.
Definition: file_opts.f:249
vmec_equilibrium::vmec_magnetic_cache
Object to cache data needed to compute magnetic signals.
Definition: vmec_equilibrium.f:326
line_segment
Module is part of the LIBSTELL. This module contains code to create a profile constructed of line sig...
Definition: line_segment.f:13
coordinate_utilities::cart_to_cyl
pure real(rprec) function, dimension(3), public cart_to_cyl(cart)
Convert a point from cartes cartesian coordinates to cylindical coordinates.
Definition: coordinate_utilities.f:40
pprofile_t::pprofile_reset_state
subroutine pprofile_reset_state(this)
Reset the internal state of the profile.
Definition: pprofile_T.f:814
vmec_equilibrium::vmec_construct_eq
type(vmec_class) function, pointer vmec_construct_eq(file_name, wout_file_name, iou, eq_comm, recon_comm, state_flags)
Construct a vmec_class object.
Definition: vmec_equilibrium.f:587
vmec_equilibrium::vmec_jcurv_id
integer, parameter vmec_jcurv_id
Toroidal current density. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:301
vmec_equilibrium::vmec_set_magnetic_cache_calc
subroutine vmec_set_magnetic_cache_calc(this)
Set magnetic cache initialy.
Definition: vmec_equilibrium.f:1426
vmec_equilibrium::vmec_get_sxrem_af
real(rprec) function, dimension(:), pointer vmec_get_sxrem_af(this, index)
Gets the soft x-ray emissivity profile af array.
Definition: vmec_equilibrium.f:3668
vmec_equilibrium::magnetic_cache_vc_grid_dim
real(rprec), parameter magnetic_cache_vc_grid_dim
Virtual casing grid dimension.
Definition: vmec_equilibrium.f:315
vmec_equilibrium::vmec_get_gp_sxrem_num_hyper_param
integer function vmec_get_gp_sxrem_num_hyper_param(this, index)
Get the number of soft x-ray emission gp kernel hyper parameters.
Definition: vmec_equilibrium.f:3630
vmec_equilibrium::vmec_write_input
subroutine vmec_write_input(this, current_step)
Write the current valid input.
Definition: vmec_equilibrium.f:5617
vmec_equilibrium::vmec_lmnc_id
integer, parameter vmec_lmnc_id
2D Array of surface lambda sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:214
vmec_equilibrium::vmec_get_p
Interface for the vmec pressure profile values.
Definition: vmec_equilibrium.f:552
vmec_equilibrium::vmec_def_result
subroutine vmec_def_result(this, result_ncid, maxnsetps_dim_id)
Define NetCDF variables for the result file.
Definition: vmec_equilibrium.f:5706
pprofile_t::pprofile_destruct
subroutine pprofile_destruct(this)
Deconstruct a pprofile_class object.
Definition: pprofile_T.f:302
vmec_equilibrium::vmec_get_area_int_element
real(rprec) function vmec_get_area_int_element(this)
Get area integration element.
Definition: vmec_equilibrium.f:4573
vmec_equilibrium::vmec_get_gp_sxrem
Interface for the vmec guassian process soft x-ray emissivity profile values.
Definition: vmec_equilibrium.f:543
vmec_equilibrium::vmec_pp_ne_as_id
integer, parameter vmec_pp_ne_as_id
1D Array of segment density profile s poitions. Defined in pprofile_T.
Definition: vmec_equilibrium.f:248
vmec_equilibrium::vmec_write_init_data
subroutine vmec_write_init_data(this, result_ncid)
Write inital data to NetCDF result file.
Definition: vmec_equilibrium.f:5819
vmec_equilibrium::vmec_curtor_id
integer, parameter vmec_curtor_id
The toroidal current. Defined in vmec_input.
Definition: vmec_equilibrium.f:184
vmec_equilibrium::vmec_get_con_surface_krgrid
real(rprec) function, dimension(:,:), pointer vmec_get_con_surface_krgrid(this)
Get the conducting surface integration kr grid points.
Definition: vmec_equilibrium.f:4477
line_segment::line_seg
subroutine, public line_seg(x, y, xx, yy, n)
Interpolate a point on a line.
Definition: line_segment.f:41
vmec_equilibrium::vmec_destruct
subroutine vmec_destruct(this)
Deconstruct a vmec_class object.
Definition: vmec_equilibrium.f:845
vmec_context::vmec_context_destruct
subroutine vmec_context_destruct(this)
Deconstruct a vmec_context_class object.
Definition: vmec_context.f:100
vmec_equilibrium::vmec_get_con_surface_kphigrid
real(rprec) function, dimension(:,:), pointer vmec_get_con_surface_kphigrid(this)
Get the conducting surface integration kphi grid points.
Definition: vmec_equilibrium.f:4507
pprofile_t
Defines the base class of the type pprofile_class. This module contains all the code necessary to def...
Definition: pprofile_T.f:88
vmec_equilibrium::vmec_get_ze_radial
real(rprec) function vmec_get_ze_radial(this, s)
Gets the effective charge at a s position.
Definition: vmec_equilibrium.f:3595
vmec_equilibrium::vmec_pp_ze_af_id
integer, parameter vmec_pp_ze_af_id
1D Array of segment zeff profile f values. Defined in pprofile_T.
Definition: vmec_equilibrium.f:283
vmec_equilibrium::vmec_set_param
subroutine vmec_set_param(this, id, i_index, j_index, value, eq_comm, state_flags)
Sets the value of a reconstruction equilibrium parameter.
Definition: vmec_equilibrium.f:1013
vmec_equilibrium::vmec_get_param_value
real(rprec) function vmec_get_param_value(this, id, i_index, j_index)
Get the value of a reconstruction VMEC parameter.
Definition: vmec_equilibrium.f:2295
vmec_equilibrium::vmec_get_magnetic_volume_rgrid
real(rprec) function, dimension(:,:,:), pointer vmec_get_magnetic_volume_rgrid(this)
Get volume magnetic volume integration radial grid points.
Definition: vmec_equilibrium.f:4289
magnetic_response
Defines the base class of the type magnetic_response_class.
Definition: magnetic_response.f:11
vmec_equilibrium::vmec_is_recon_param
logical function vmec_is_recon_param(this, id)
Checks if a parameter id is a reconstruction parameter.
Definition: vmec_equilibrium.f:5113
vmec_equilibrium::vmec_get_te_af
real(rprec) function, dimension(:), pointer vmec_get_te_af(this)
Gets the electron temperature profile af array.
Definition: vmec_equilibrium.f:3092
vmec_equilibrium::vmec_reset_state
subroutine vmec_reset_state(this)
Reset the internal state of the equilibrium.
Definition: vmec_equilibrium.f:5486
vmec_equilibrium::vmec_pp_ne_b_id
integer, parameter vmec_pp_ne_b_id
1D Array of function density profile parameters. Defined in pprofile_T.
Definition: vmec_equilibrium.f:246
vmec_equilibrium::magnetic_cache_vc_min_grid_points
integer, parameter magnetic_cache_vc_min_grid_points
Virtual casing grid points for vacuum field measurements.
Definition: vmec_equilibrium.f:313
vmec_equilibrium::vmec_gmns_id
integer, parameter vmec_gmns_id
2D Array of surface g sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:216
vmec_equilibrium
Defines the base class of the type vmec_class. This module contains all the code necessary to interfa...
Definition: vmec_equilibrium.f:135
vmec_equilibrium::vmec_set_magnetic_cache_responce
subroutine vmec_set_magnetic_cache_responce(this, response_object)
Set magnetic cache for plasma resonce.
Definition: vmec_equilibrium.f:1278
vmec_equilibrium::vmec_get_s
real(rprec) function vmec_get_s(this, x_cart)
Gets VMEC s value at position.
Definition: vmec_equilibrium.f:4147
vmec_equilibrium::vmec_get_gp_ne_pp
real(rprec) function vmec_get_gp_ne_pp(this, x_cart, y_cart)
Get the electron density gp kernel value for the position and position.
Definition: vmec_equilibrium.f:2951
vmec_equilibrium::vmec_zbc_id
integer, parameter vmec_zbc_id
2D Array of outer boundary Z cosine coeffiecents. Defined in vmec_input.
Definition: vmec_equilibrium.f:180
vmec_equilibrium::vmec_get_grid_start
real(rprec) function vmec_get_grid_start(this)
Get start of the radial grid.
Definition: vmec_equilibrium.f:4923
vmec_equilibrium::vmec_zmnc_id
integer, parameter vmec_zmnc_id
2D Array of surface Z cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:212
vmec_equilibrium::vmec_rmnc_id
integer, parameter vmec_rmnc_id
2D Array of surface R cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:192
vmec_equilibrium::vmec_is_using_point
logical function vmec_is_using_point(this)
Checks if a the point magnetics are being used.
Definition: vmec_equilibrium.f:5160
vmec_equilibrium::vmec_get_magnetic_volume_zgrid
real(rprec) function, dimension(:,:,:), pointer vmec_get_magnetic_volume_zgrid(this)
Get volume magnetic volume integration z grid points.
Definition: vmec_equilibrium.f:4319
vmec_equilibrium::vmec_get_ne_cart
real(rprec) function vmec_get_ne_cart(this, x_cart)
Gets the electron density at a cartesian position.
Definition: vmec_equilibrium.f:2992
vmec_equilibrium::vmec_is_scaler_value
logical function vmec_is_scaler_value(this, id)
Checks if a parameter id is a scaler value.
Definition: vmec_equilibrium.f:4979
vmec_equilibrium::vmec_ac_aux_s_id
integer, parameter vmec_ac_aux_s_id
1D Array of segment current profile s poitions. Defined in vmec_input.
Definition: vmec_equilibrium.f:153
vmec_equilibrium::vmec_sync_state
subroutine vmec_sync_state(this, recon_comm)
Syncronize the vmec state to children.
Definition: vmec_equilibrium.f:6028
vmec_equilibrium::vmec_bsubumnc_id
integer, parameter vmec_bsubumnc_id
2D Array of surface B_u cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:202
vmec_equilibrium::vmec_bsubumns_id
integer, parameter vmec_bsubumns_id
2D Array of surface B_u sine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:220
vmec_equilibrium::vmec_lmns_id
integer, parameter vmec_lmns_id
2D Array of surface lambda cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:196
vmec_context::vmec_context_get_context
subroutine vmec_context_get_context(this)
Gets the current context from the VMEC internal state.
Definition: vmec_context.f:188
vmec_equilibrium::vmec_bsubvmnc_id
integer, parameter vmec_bsubvmnc_id
2D Array of surface B_v cosine coeffiecents. Defined in read_wout_mod.
Definition: vmec_equilibrium.f:204
vmec_equilibrium::vmec_get_ti_cart
real(rprec) function vmec_get_ti_cart(this, x_cart)
Gets the ion temperature at a cartesian position.
Definition: vmec_equilibrium.f:3501
vmec_equilibrium::vmec_get_gp_te_num_hyper_param
integer function vmec_get_gp_te_num_hyper_param(this)
Get the number of electron temperature gp kernel hyper parameters.
Definition: vmec_equilibrium.f:3057
vmec_equilibrium::vmec_get_p_cart
real(rprec) function vmec_get_p_cart(this, x_cart)
Gets the plasma pressure at a cartesian position.
Definition: vmec_equilibrium.f:3910
vmec_equilibrium::vmec_get_ze
Interface for the vmec zeff profile values.
Definition: vmec_equilibrium.f:560
vmec_equilibrium::vmec_get_gp_ti
Interface for the vmec guassian process ion temperature profile values.
Definition: vmec_equilibrium.f:525
vmec_equilibrium::vmec_get_magnetic_volume_jrgrid
real(rprec) function, dimension(:,:,:), pointer vmec_get_magnetic_volume_jrgrid(this)
Get volume magnetic volume integration jr grid points.
Definition: vmec_equilibrium.f:4349
vmec_equilibrium::vmec_get_b_vec
real(rprec) function, dimension(3) vmec_get_b_vec(this, x_cart, cyl)
Gets the magnetic field vector at a position.
Definition: vmec_equilibrium.f:3982