V3FIT
magnetic_response.f
Go to the documentation of this file.
1 !*******************************************************************************
4 !
5 ! Note separating the Doxygen comment block here so detailed decription is
6 ! found in the Module not the file.
7 !
9 !*******************************************************************************
10 
12  USE compression
13  USE stel_kinds, only: rprec
14  USE profiler
15 
16  IMPLICIT NONE
17 
18 !*******************************************************************************
19 ! magnetic_response module parameters
20 !*******************************************************************************
21 ! NOTE: When changing this version changes, the select statement in
22 ! magnetic_construct_netcdf of magnetic.f in the V3FIT needs to be updated. ???
23 ! FIXME Check if this is true. The versioning should probably be handeled
24 ! internally here.
25 
26 ! Currnet version -------------------------------------------------------------
28  CHARACTER (len=*), PARAMETER :: &
29  & magnetic_response_current = 'MRC 2015-04-27'
30 ! Previous versions -----------------------------------------------------------
33  CHARACTER (len=*), PARAMETER :: &
34  & magnetic_response_20140928 = 'MRC 2014-09-28'
35 
37  INTEGER, PARAMETER :: magnetic_response_len = 80
38 
40  INTEGER, PARAMETER :: magnetic_response_use_coil_flag = 1
42  INTEGER, PARAMETER :: magnetic_response_use_plasma_flag = 2
44  INTEGER, PARAMETER :: magnetic_response_stell_sym_flag = 3
46  INTEGER, PARAMETER :: magnetic_response_use_shell_flag = 4
48  INTEGER, PARAMETER :: magnetic_response_is_point_flag = 5
49 
50 ! NETCDF file variable names --------------------------------------------------
52  CHARACTER (len=*), PARAMETER :: nc_flags = 'mddc_mrf_flags'
53 
54 ! Identification Variables ----------------------------------------------------
56  CHARACTER (len=*), PARAMETER :: nc_name = 'mddc_mrf_code_name'
58  CHARACTER (len=*), PARAMETER :: nc_version = &
59  & 'mddc_mrf_code_version'
61  CHARACTER (len=*), PARAMETER :: nc_date = 'mddc_mrf_date_run'
63  CHARACTER (len=*), PARAMETER :: nc_coil_id = &
64  & 'mddc_mrf_field_coils_id'
65 
66 ! Coil Responce Function Variables --------------------------------------------
68  CHARACTER (len=*), PARAMETER :: nc_n_field_cg = &
69  & 'mddc_mrf_n_field_cg'
71  CHARACTER (len=*), PARAMETER :: nc_inductance = &
72  & 'mddc_mrf_rdiag_coilg_1'
74  CHARACTER (len=*), PARAMETER :: nc_current_scale = &
75  & 'mddc_mrf_extcur_mg'
76 
77 ! Plasma Response Grid Variables ----------------------------------------------
79  CHARACTER (len=*), PARAMETER :: nc_num_t = 'mddc_mrf_kp'
81  CHARACTER (len=*), PARAMETER :: nc_num_r = 'mddc_mrf_ir'
83  CHARACTER (len=*), PARAMETER :: nc_num_z = 'mddc_mrf_jz'
85  CHARACTER (len=*), PARAMETER :: nc_rmin = 'mddc_mrf_rmin'
87  CHARACTER (len=*), PARAMETER :: nc_rmax = 'mddc_mrf_rmax'
89  CHARACTER (len=*), PARAMETER :: nc_zmin = 'mddc_mrf_zmin'
91  CHARACTER (len=*), PARAMETER :: nc_zmax = 'mddc_mrf_zmax'
93  CHARACTER (len=*), PARAMETER :: nc_n_field_periods = &
94  & 'mddc_mrf_n_field_periods'
95 
98  CHARACTER (len=*), PARAMETER :: nc_stell_sym = &
99  & 'mddc_mrf_lstell_sym'
100 
102  CHARACTER (len=*), PARAMETER :: nc_a_r = 'mddc_mrf_a_r'
104  CHARACTER (len=*), PARAMETER :: nc_a_f = 'mddc_mrf_a_f'
106  CHARACTER (len=*), PARAMETER :: nc_a_z = 'mddc_mrf_a_z'
107 
108 ! Conducting Shell Response Arrays --------------------------------------------
111  CHARACTER (len=*), PARAMETER :: nc_use_shell = &
112  & 'mddc_mrf_use_con_shell'
114  CHARACTER (len=*), PARAMETER :: nc_num_t_shell = &
115  & 'mddc_mrf_kp_shell'
116 
118  CHARACTER (len=*), PARAMETER :: nc_a_s_r = 'mddc_mrf_a_s_r'
120  CHARACTER (len=*), PARAMETER :: nc_a_s_f = 'mddc_mrf_a_s_f'
122  CHARACTER (len=*), PARAMETER :: nc_a_s_z = 'mddc_mrf_a_s_z'
123 
124 ! Point Diagnostic ------------------------------------------------------------
126  CHARACTER (len=*), PARAMETER :: nc_position = &
127  & 'mddc_mrf_position'
129  CHARACTER (len=*), PARAMETER :: nc_direction = &
130  & 'mddc_mrf_direction'
131 
132 !*******************************************************************************
133 ! DERIVED-TYPE DECLARATIONS
134 ! 1) magnetic base class
135 !
136 !*******************************************************************************
137 !-------------------------------------------------------------------------------
139 !-------------------------------------------------------------------------------
142  INTEGER :: flags
143 
144 ! Identification Variables ----------------------------------------------------
146  CHARACTER (len=magnetic_response_len) :: name
148  CHARACTER (len=magnetic_response_len) :: version
150  CHARACTER (len=magnetic_response_len) :: date
152  CHARACTER (len=magnetic_response_len) :: coil_id
153 
154 ! Coil Responce Function Variables --------------------------------------------
156  INTEGER :: n_field_cg
158  REAL (rprec), DIMENSION(:), POINTER :: inductance => null()
160  REAL (rprec), DIMENSION(:), POINTER :: current_scale => null()
161 
162 ! Plasma Response Grid Variables ----------------------------------------------
164  INTEGER :: num_t
166  REAL (rprec) :: rmin
168  REAL (rprec) :: rmax
170  REAL (rprec) :: zmin
172  REAL (rprec) :: zmax
173 
175  INTEGER :: n_field_periods
176 
178  INTEGER :: num_t_shell
179 
180 ! Plasma Response Arrays ------------------------------------------------------
182  TYPE (compression_pointer), DIMENSION(:), POINTER :: &
183  & a_r => null()
185  TYPE (compression_pointer), DIMENSION(:), POINTER :: &
186  & a_f => null()
188  TYPE (compression_pointer), DIMENSION(:), POINTER :: &
189  & a_z => null()
190 
191 ! Conducting Shell Response Arrays --------------------------------------------
193  TYPE (compression_class), POINTER :: a_s_r => null()
195  TYPE (compression_class), POINTER :: a_s_f => null()
197  TYPE (compression_class), POINTER :: a_s_z => null()
198 
199 ! Point Diagnostic Response ---------------------------------------------------
200 ! Use the mutual inductance array to store the vacuum field response.
202  REAL (rprec), DIMENSION(3) :: position
204  REAL (rprec), DIMENSION(3) :: direction
205  END TYPE
206 
207 !*******************************************************************************
208 ! INTERFACE BLOCKS
209 !*******************************************************************************
210 !-------------------------------------------------------------------------------
215 !-------------------------------------------------------------------------------
217  MODULE PROCEDURE magnetic_response_construct_new, &
220  END INTERFACE
221 
222  CONTAINS
223 !*******************************************************************************
224 ! CONSTRUCTION SUBROUTINES
225 !*******************************************************************************
226 !-------------------------------------------------------------------------------
257 !-------------------------------------------------------------------------------
258  FUNCTION magnetic_response_construct_new(name, date, &
259  & coil_id, inductance, &
260  & current_scale, &
261  & num_t, num_t_shell, &
262  & rmin, rmax, zmin, zmax, &
263  & n_field_periods, &
264  & stell_sym, a_r, a_f, a_z, &
265  & a_s_r, a_s_f, a_s_z, &
266  & svd_cut_off)
267  USE v3_utilities
268 
269  IMPLICIT NONE
270 
271 ! Declare Arguments
272  TYPE (magnetic_response_class), POINTER &
274  CHARACTER (len=*), INTENT(in) :: name
275  CHARACTER (len=*), INTENT(in) :: date
276  CHARACTER (len=*), INTENT(in) :: coil_id
277  REAL (rprec), DIMENSION(:), POINTER :: inductance
278  REAL (rprec), DIMENSION(:), POINTER :: current_scale
279  INTEGER, INTENT(in) :: num_t
280  INTEGER, INTENT(in) :: num_t_shell
281  REAL (rprec), INTENT(in) :: rmin
282  REAL (rprec), INTENT(in) :: rmax
283  REAL (rprec), INTENT(in) :: zmin
284  REAL (rprec), INTENT(in) :: zmax
285  INTEGER, INTENT(in) :: n_field_periods
286  LOGICAL, INTENT(in) :: stell_sym
287  REAL (rprec), DIMENSION(:,:,:), POINTER :: a_r
288  REAL (rprec), DIMENSION(:,:,:), POINTER :: a_f
289  REAL (rprec), DIMENSION(:,:,:), POINTER :: a_z
290  REAL (rprec), DIMENSION(:,:), POINTER :: a_s_r
291  REAL (rprec), DIMENSION(:,:), POINTER :: a_s_f
292  REAL (rprec), DIMENSION(:,:), POINTER :: a_s_z
293  REAL (rprec), INTENT(in) :: svd_cut_off
294 
295 ! local variables
296  INTEGER :: phi
297  REAL (rprec) :: start_time
298 
299 ! Start of executable code
300  start_time = profiler_get_start_time()
301 
303 
305 
306 ! Identification Variables ----------------------------------------------------
311  magnetic_response_construct_new%coil_id = coil_id
312 
313 ! Coil Responce Function Variables --------------------------------------------
314  IF (ASSOCIATED(inductance)) THEN
316  & ibset(magnetic_response_construct_new%flags, &
318 
319  ALLOCATE(magnetic_response_construct_new%inductance( &
320  & SIZE(inductance)))
321  magnetic_response_construct_new%inductance = inductance
322  magnetic_response_construct_new%n_field_cg = SIZE(inductance)
323  END IF
324 
325  IF (ASSOCIATED(current_scale)) THEN
326  ALLOCATE(magnetic_response_construct_new%current_scale( &
327  & SIZE(current_scale)))
328  magnetic_response_construct_new%current_scale = current_scale
329  END IF
330 
331 ! Plasma Response Grid Variables ----------------------------------------------
332  magnetic_response_construct_new%num_t = num_t
333  magnetic_response_construct_new%num_t_shell = num_t_shell
338  magnetic_response_construct_new%n_field_periods = n_field_periods
339 
340  IF (stell_sym) THEN
342  & ibset(magnetic_response_construct_new%flags, &
344  END IF
345 
346 ! Plasma Response Arrays ------------------------------------------------------
347  IF (ASSOCIATED(a_r)) THEN
349  & ibset(magnetic_response_construct_new%flags, &
351 
352  CALL assert(ASSOCIATED(a_f), 'a_f response function not ' // &
353  & 'allocated')
354  CALL assert(ASSOCIATED(a_z), 'a_z response function not ' // &
355  & 'allocated')
356 
357  ALLOCATE(magnetic_response_construct_new%a_r(SIZE(a_r, 3)))
358  ALLOCATE(magnetic_response_construct_new%a_f(SIZE(a_r, 3)))
359  ALLOCATE(magnetic_response_construct_new%a_z(SIZE(a_r, 3)))
360 
361  DO phi = 1, SIZE(a_r, 3)
362  magnetic_response_construct_new%a_r(phi)%p => &
363  & compression_construct(a_r(:,:,phi), svd_cut_off)
364  magnetic_response_construct_new%a_f(phi)%p => &
365  & compression_construct(a_f(:,:,phi), svd_cut_off)
366  magnetic_response_construct_new%a_z(phi)%p => &
367  & compression_construct(a_z(:,:,phi), svd_cut_off)
368  END DO
369  END IF
370 
371 ! Conducting Shell Response Arrays --------------------------------------------
372  IF (ASSOCIATED(a_s_r)) THEN
374  & ibset(magnetic_response_construct_new%flags, &
376 
377  CALL assert(ASSOCIATED(a_s_f), 'a_s_f response function ' // &
378  & 'not allocated')
379  CALL assert(ASSOCIATED(a_s_z), 'a_s_z response function ' // &
380  & 'not allocated')
381 
383  & compression_construct(a_s_r, svd_cut_off)
385  & compression_construct(a_s_f, svd_cut_off)
387  & compression_construct(a_s_z, svd_cut_off)
388  END IF
389 
390  CALL profiler_set_stop_time('magnetic_response_construct_new', &
391  & start_time)
392 
393  END FUNCTION
394 
395 !-------------------------------------------------------------------------------
408 !-------------------------------------------------------------------------------
409  FUNCTION magnetic_response_construct_point(name, date, &
410  & coil_id, position, &
411  & direction, vacuum, &
412  & current_scale)
413  USE v3_utilities
414 
415  IMPLICIT NONE
416 
417 ! Declare Arguments
418  TYPE (magnetic_response_class), POINTER &
420  CHARACTER (len=*), INTENT(in) :: name
421  CHARACTER (len=*), INTENT(in) :: date
422  CHARACTER (len=*), INTENT(in) :: coil_id
423  REAL (rprec), DIMENSION(3) :: position
424  REAL (rprec), DIMENSION(3) :: direction
425  REAL (rprec), DIMENSION(:), POINTER :: vacuum
426  REAL (rprec), DIMENSION(:), POINTER :: current_scale
427 
428 ! local variables
429  REAL (rprec) :: start_time
430 
431 ! Start of executable code
432  start_time = profiler_get_start_time()
433 
435 
437 
439  & ibset(magnetic_response_construct_point%flags, &
441 
442 ! Identification Variables ----------------------------------------------------
447  magnetic_response_construct_point%coil_id = coil_id
448 
449 ! Geometric Variables ---------------------------------------------------------
450  magnetic_response_construct_point%position = position
451  magnetic_response_construct_point%direction = direction
452 
453 ! Coil Responce Function Variables --------------------------------------------
454  IF (ASSOCIATED(vacuum)) THEN
456  & ibset(magnetic_response_construct_point%flags, &
458 
459  ALLOCATE(magnetic_response_construct_point%inductance( &
460  & SIZE(vacuum)))
461  magnetic_response_construct_point%inductance = vacuum
462  magnetic_response_construct_point%n_field_cg = SIZE(vacuum)
463  END IF
464 
465  IF (ASSOCIATED(current_scale)) THEN
466  ALLOCATE(magnetic_response_construct_point%current_scale( &
467  & SIZE(current_scale)))
468  magnetic_response_construct_point%current_scale = current_scale
469  END IF
470 
471  CALL profiler_set_stop_time('magnetic_response_construct_point', &
472  & start_time)
473 
474  END FUNCTION
475 
476 !-------------------------------------------------------------------------------
486 !-------------------------------------------------------------------------------
487  FUNCTION magnetic_response_construct_netcdf(mdsig_iou, &
488  & svd_cut_off)
489  USE ezcdf
490 
491  IMPLICIT NONE
492 
493 ! Declare Arguments
494  TYPE (magnetic_response_class), POINTER :: &
496  INTEGER, INTENT(in) :: mdsig_iou
497  REAL (rprec), INTENT(in) :: svd_cut_off
498 
499 ! local variables
500  REAL(rprec), DIMENSION(:,:,:), ALLOCATABLE :: temp_buffer
501  LOGICAL :: temp_logical
502  INTEGER, DIMENSION(3) :: dim_lengths
503  INTEGER :: phi
504  REAL (rprec) :: start_time
505 
506 ! Start of executable code
507  start_time = profiler_get_start_time()
508 
510 
511 ! Identification Variables ----------------------------------------------------
512  CALL cdf_read(mdsig_iou, nc_name, &
514  CALL cdf_read(mdsig_iou, nc_version, &
516  CALL cdf_read(mdsig_iou, nc_date, &
518  CALL cdf_read(mdsig_iou, nc_coil_id, &
520 
521 ! Check the version code verison. If the version is 'MRC 2015-04-27' or later,
522 ! there is a flag variable that indicates the contents of the file.
524 
525  SELECT CASE (trim(magnetic_response_construct_netcdf%version))
526 
528 ! This version adds the new point diagnostic. The format of the netcdf mdsig
529 ! file has been modified to hold bit packed flags to determine what is or isn't
530 ! present in the netcdf file.
531  CALL cdf_read(mdsig_iou, nc_flags, &
533 
535 ! This version added the option for a coducting shell. Options were stored as
536 ! logicals.
537  CALL cdf_read(mdsig_iou, nc_use_shell, temp_logical)
538  IF (temp_logical) THEN
540  & ibset(magnetic_response_construct_netcdf%flags, &
542  END IF
543 
544  CALL cdf_read(mdsig_iou, nc_stell_sym, temp_logical)
545  IF (temp_logical) THEN
547  & ibset(magnetic_response_construct_netcdf%flags, &
549  END IF
550 
551 ! The mutual inductance and plasma response are expected.
553  & ibset(magnetic_response_construct_netcdf%flags, &
555 
557  & ibset(magnetic_response_construct_netcdf%flags, &
559 
560  CASE DEFAULT
561 ! This is the orginal format. Options were stored as logicals.
562  CALL cdf_read(mdsig_iou, nc_stell_sym, temp_logical)
563  IF (temp_logical) THEN
565  & ibset(magnetic_response_construct_netcdf%flags, &
567  END IF
568 
569 ! The mutual inductance and plasma response are expected.
571  & ibset(magnetic_response_construct_netcdf%flags, &
573 
575  & ibset(magnetic_response_construct_netcdf%flags, &
577 
578  END SELECT
579 
580 ! Coil Responce Function Variables --------------------------------------------
581  IF (btest(magnetic_response_construct_netcdf%flags, &
583  CALL cdf_read(mdsig_iou, nc_n_field_cg, &
585 
586  ALLOCATE(magnetic_response_construct_netcdf%inductance( &
588  CALL cdf_read(mdsig_iou, nc_inductance, &
590 
591  ALLOCATE(magnetic_response_construct_netcdf%current_scale( &
593  CALL cdf_read(mdsig_iou, nc_current_scale, &
594  & magnetic_response_construct_netcdf%current_scale)
595  END IF
596 
597 ! Plasma Response Grid Variables ----------------------------------------------
598  IF (btest(magnetic_response_construct_netcdf%flags, &
600  CALL cdf_read(mdsig_iou, nc_num_t, &
602  CALL cdf_read(mdsig_iou, nc_rmin, &
604  CALL cdf_read(mdsig_iou, nc_rmax, &
606  CALL cdf_read(mdsig_iou, nc_zmin, &
608  CALL cdf_read(mdsig_iou, nc_zmax, &
610  CALL cdf_read(mdsig_iou, nc_n_field_periods, &
611  & magnetic_response_construct_netcdf%n_field_periods)
612 
613  CALL cdf_inquire(mdsig_iou, nc_a_r, dim_lengths)
614  ALLOCATE(temp_buffer(dim_lengths(1), &
615  & dim_lengths(2), &
616  & dim_lengths(3)))
617 
618  CALL cdf_read(mdsig_iou, nc_a_r, temp_buffer)
619  ALLOCATE(magnetic_response_construct_netcdf%a_r( &
620  & dim_lengths(3)))
621  DO phi = 1, dim_lengths(3)
622  magnetic_response_construct_netcdf%a_r(phi)%p => &
623  & compression_construct(temp_buffer(:,:,phi), svd_cut_off)
624  END DO
625 
626  CALL cdf_read(mdsig_iou, nc_a_f, temp_buffer)
627  ALLOCATE(magnetic_response_construct_netcdf%a_f( &
628  & dim_lengths(3)))
629  DO phi = 1, dim_lengths(3)
630  magnetic_response_construct_netcdf%a_f(phi)%p => &
631  & compression_construct(temp_buffer(:,:,phi), svd_cut_off)
632  END DO
633 
634  CALL cdf_read(mdsig_iou, nc_a_z, temp_buffer)
635  ALLOCATE(magnetic_response_construct_netcdf%a_z( &
636  & dim_lengths(3)))
637  DO phi = 1, dim_lengths(3)
638  magnetic_response_construct_netcdf%a_z(phi)%p => &
639  & compression_construct(temp_buffer(:,:,phi), svd_cut_off)
640  END DO
641 
642  DEALLOCATE(temp_buffer)
643  END IF
644 
645 ! Conducting Shell Response Arrays --------------------------------------------
646  IF (btest(magnetic_response_construct_netcdf%flags, &
648  CALL cdf_read(mdsig_iou, nc_num_t_shell, &
650 
651  CALL cdf_inquire(mdsig_iou, nc_a_s_r, dim_lengths(1:2))
652  ALLOCATE(temp_buffer(1,dim_lengths(1),dim_lengths(2)))
653 
654  CALL cdf_read(mdsig_iou, nc_a_s_r, temp_buffer(1,:,:))
656  & compression_construct(temp_buffer(1,:,:), svd_cut_off)
657 
658  CALL cdf_read(mdsig_iou, nc_a_s_f, temp_buffer(1,:,:))
660  & compression_construct(temp_buffer(1,:,:), svd_cut_off)
661 
662  CALL cdf_read(mdsig_iou, nc_a_s_z, temp_buffer(1,:,:))
664  & compression_construct(temp_buffer(1,:,:), svd_cut_off)
665 
666  DEALLOCATE(temp_buffer)
667  END IF
668 
669 ! Point Diagnostic Response ---------------------------------------------------
670  IF (btest(magnetic_response_construct_netcdf%flags, &
672  CALL cdf_read(mdsig_iou, nc_position, &
674 
675  CALL cdf_read(mdsig_iou, nc_direction, &
677  END IF
678 
679  CALL profiler_set_stop_time('magnetic_response_construct_netcdf', &
680  & start_time)
681 
682  END FUNCTION
683 
684 !*******************************************************************************
685 ! DESTRUCTION SUBROUTINES
686 !*******************************************************************************
687 !-------------------------------------------------------------------------------
693 !-------------------------------------------------------------------------------
694  SUBROUTINE magnetic_response_destruct(this)
695 
696 ! Declare Arguments
697  TYPE (magnetic_response_class), POINTER :: this
698 
699 ! local variables
700  INTEGER :: phi
701 
702 ! Start of executable code
703  IF (ASSOCIATED(this%inductance)) THEN
704  DEALLOCATE(this%inductance)
705  this%inductance => null()
706  END IF
707 
708  IF (ASSOCIATED(this%current_scale)) THEN
709  DEALLOCATE(this%current_scale)
710  this%current_scale => null()
711  END IF
712 
713  IF (ASSOCIATED(this%a_r)) THEN
714  DO phi = 1, SIZE(this%a_r)
715  CALL compression_destruct(this%a_r(phi)%p)
716  END DO
717  DEALLOCATE(this%a_r)
718  this%a_r => null()
719  END IF
720 
721  IF (ASSOCIATED(this%a_f)) THEN
722  DO phi = 1, SIZE(this%a_f)
723  CALL compression_destruct(this%a_f(phi)%p)
724  END DO
725  DEALLOCATE(this%a_f)
726  this%a_f => null()
727  END IF
728 
729  IF (ASSOCIATED(this%a_z)) THEN
730  DO phi = 1, SIZE(this%a_z)
731  CALL compression_destruct(this%a_z(phi)%p)
732  END DO
733  DEALLOCATE(this%a_z)
734  this%a_z => null()
735  END IF
736 
737  IF (ASSOCIATED(this%a_s_r)) THEN
738  CALL compression_destruct(this%a_s_r)
739  this%a_s_r => null()
740  END IF
741 
742  IF (ASSOCIATED(this%a_s_f)) THEN
743  CALL compression_destruct(this%a_s_f)
744  this%a_s_f => null()
745  END IF
746 
747  IF (ASSOCIATED(this%a_s_z)) THEN
748  CALL compression_destruct(this%a_s_z)
749  this%a_s_z => null()
750  END IF
751 
752  DEALLOCATE(this)
753 
754  END SUBROUTINE
755 
756 !*******************************************************************************
757 ! QUERY SUBROUTINES
758 !*******************************************************************************
759 !-------------------------------------------------------------------------------
767 !-------------------------------------------------------------------------------
768  FUNCTION magnetic_response_is_stell_sym(this)
769 
770  IMPLICIT NONE
771 
772 ! Declare Arguments
774  TYPE (magnetic_response_class), INTENT(in) :: this
775 
776 ! local variables
777  REAL (rprec) :: start_time
778 
779 ! Start of executable code
780  start_time = profiler_get_start_time()
781 
783  & btest(this%flags, magnetic_response_stell_sym_flag)
784 
785  CALL profiler_set_stop_time('magnetic_response_is_stell_sym', &
786  & start_time)
787 
788  END FUNCTION
789 
790 !-------------------------------------------------------------------------------
798 !-------------------------------------------------------------------------------
799  FUNCTION magnetic_response_use_plasma(this)
800 
801  IMPLICIT NONE
802 
803 ! Declare Arguments
805  TYPE (magnetic_response_class), INTENT(in) :: this
806 
807 ! local variables
808  REAL (rprec) :: start_time
809 
810 ! Start of executable code
811  start_time = profiler_get_start_time()
812 
814  & btest(this%flags, magnetic_response_use_plasma_flag)
815 
816  CALL profiler_set_stop_time('magnetic_response_use_plasma', &
817  & start_time)
818 
819  END FUNCTION
820 
821 !-------------------------------------------------------------------------------
829 !-------------------------------------------------------------------------------
830  FUNCTION magnetic_response_use_shell(this)
831 
832  IMPLICIT NONE
833 
834 ! Declare Arguments
835  LOGICAL :: magnetic_response_use_shell
836  TYPE (magnetic_response_class), INTENT(in) :: this
837 
838 ! local variables
839  REAL (rprec) :: start_time
840 
841 ! Start of executable code
842  start_time = profiler_get_start_time()
843 
845  & btest(this%flags, magnetic_response_use_shell_flag)
846 
847  CALL profiler_set_stop_time('magnetic_response_use_shell', &
848  & start_time)
849 
850  END FUNCTION
851 
852 !-------------------------------------------------------------------------------
860 !-------------------------------------------------------------------------------
861  FUNCTION magnetic_response_use_coil(this)
862 
863  IMPLICIT NONE
864 
865 ! Declare Arguments
866  LOGICAL :: magnetic_response_use_coil
867  TYPE (magnetic_response_class), INTENT(in) :: this
868 
869 ! local variables
870  REAL (rprec) :: start_time
871 
872 ! Start of executable code
873  start_time = profiler_get_start_time()
874 
876  & btest(this%flags, magnetic_response_use_coil_flag)
877 
878  CALL profiler_set_stop_time('magnetic_response_use_coil', &
879  & start_time)
880 
881  END FUNCTION
882 
883 !-------------------------------------------------------------------------------
891 !-------------------------------------------------------------------------------
892  SUBROUTINE magnetic_response_clr_use_coil(this)
893 
894  IMPLICIT NONE
895 
896 ! Declare Arguments
897  TYPE (magnetic_response_class), INTENT(inout) :: this
898 
899 ! local variables
900  REAL (rprec) :: start_time
901 
902 ! Start of executable code
903  start_time = profiler_get_start_time()
904 
905  this%flags = ibclr(this%flags, magnetic_response_use_coil_flag)
906 
907  CALL profiler_set_stop_time('magnetic_response_clr_use_coil', &
908  & start_time)
909 
910  END SUBROUTINE
911 
912 !-------------------------------------------------------------------------------
920 !-------------------------------------------------------------------------------
921  FUNCTION magnetic_response_is_point(this)
922 
923  IMPLICIT NONE
924 
925 ! Declare Arguments
926  LOGICAL :: magnetic_response_is_point
927  TYPE (magnetic_response_class), INTENT(in) :: this
928 
929 ! local variables
930  REAL (rprec) :: start_time
931 
932 ! Start of executable code
933  start_time = profiler_get_start_time()
934 
936  & btest(this%flags, magnetic_response_is_point_flag)
937 
938  CALL profiler_set_stop_time('magnetic_response_is_point', &
939  & start_time)
940 
941  END FUNCTION
942 
943 !*******************************************************************************
944 ! NETCDF SUBROUTINES
945 !*******************************************************************************
946 !-------------------------------------------------------------------------------
953 !-------------------------------------------------------------------------------
954  SUBROUTINE magnetic_response_define(this, mdsig_iou)
955  USE ezcdf
956 
957  IMPLICIT NONE
958 
959 ! Declare Arguments
960  TYPE (magnetic_response_class), INTENT(in) :: this
961  INTEGER, INTENT(in) :: mdsig_iou
962 
963 ! local variables
964  REAL (rprec), DIMENSION(:,:,:), ALLOCATABLE :: temp_buffer
965  INTEGER :: phi
966  REAL (rprec) :: start_time
967 
968 ! Start of executable code
969  start_time = profiler_get_start_time()
970 
971 ! Define Variables ------------------------------------------------------------
972  CALL cdf_define(mdsig_iou, nc_flags, this%flags)
973 
974 ! Identification Variables ----------------------------------------------------
975  CALL cdf_define(mdsig_iou, nc_name, this%name)
976  CALL cdf_define(mdsig_iou, nc_version, this%version)
977  CALL cdf_define(mdsig_iou, nc_date, this%date)
978  CALL cdf_define(mdsig_iou, nc_coil_id, this%coil_id)
979 
980 ! Coil Responce Function Variables --------------------------------------------
981  IF (btest(this%flags, magnetic_response_use_coil_flag)) THEN
982  CALL cdf_define(mdsig_iou, nc_n_field_cg, this%n_field_cg)
983  CALL cdf_define(mdsig_iou, nc_inductance, this%inductance)
984  CALL cdf_define(mdsig_iou, nc_current_scale, &
985  & this%current_scale)
986  END IF
987 
988 ! Plasma Response Grid Variables ----------------------------------------------
989  IF (btest(this%flags, magnetic_response_use_plasma_flag)) THEN
990  CALL cdf_define(mdsig_iou, nc_num_t, this%num_t)
991  CALL cdf_define(mdsig_iou, nc_rmin, this%rmin)
992  CALL cdf_define(mdsig_iou, nc_rmax, this%rmax)
993  CALL cdf_define(mdsig_iou, nc_zmin, this%zmin)
994  CALL cdf_define(mdsig_iou, nc_zmax, this%zmax)
995  CALL cdf_define(mdsig_iou, nc_n_field_periods, &
996  & this%n_field_periods)
997 
998 ! Decompress a single response function phi plane to get the r z dimensions.
999 ! Then define the netcdf variables based off a temp buffer. All response
1000 ! function directions should have the same dimensions.
1001  ALLOCATE(temp_buffer(compression_get_dimension1(this%a_r(1)%p), &
1002  & compression_get_dimension2(this%a_r(1)%p), &
1003  & SIZE(this%a_r)))
1004 
1005  CALL cdf_define(mdsig_iou, nc_a_r, temp_buffer)
1006  CALL cdf_define(mdsig_iou, nc_a_f, temp_buffer)
1007  CALL cdf_define(mdsig_iou, nc_a_z, temp_buffer)
1008 
1009  DEALLOCATE(temp_buffer)
1010  END IF
1011 
1012 ! Conducting Shell Response Arrays --------------------------------------------
1013  IF (btest(this%flags, magnetic_response_use_shell_flag)) THEN
1014  CALL cdf_define(mdsig_iou, nc_num_t_shell, this%num_t_shell)
1015 
1016 ! Decompress a single conducting shell response function phi plane to get the
1017 ! data buffer. All shell response function directions should have the same
1018 ! dimensions.
1019  ALLOCATE(temp_buffer(1, &
1020  & compression_get_dimension1(this%a_s_r), &
1021  & compression_get_dimension2(this%a_s_r)))
1022 
1023  CALL cdf_define(mdsig_iou, nc_a_s_r, temp_buffer(1,:,:))
1024  CALL cdf_define(mdsig_iou, nc_a_s_f, temp_buffer(1,:,:))
1025  CALL cdf_define(mdsig_iou, nc_a_s_z, temp_buffer(1,:,:))
1026 
1027  DEALLOCATE(temp_buffer)
1028  END IF
1029 
1030 ! Point Diagnostic Response ---------------------------------------------------
1031  IF (btest(this%flags, magnetic_response_is_point_flag)) THEN
1032  CALL cdf_define(mdsig_iou, nc_position, this%position)
1033  CALL cdf_define(mdsig_iou, nc_direction, this%direction)
1034  END IF
1035 
1036  CALL profiler_set_stop_time('magnetic_response_define', &
1037  & start_time)
1038 
1039  END SUBROUTINE
1040 
1041 !-------------------------------------------------------------------------------
1048 !-------------------------------------------------------------------------------
1049  SUBROUTINE magnetic_response_write(this, mdsig_iou)
1050  USE ezcdf
1051  IMPLICIT NONE
1052 
1053 ! Declare Arguments
1054  TYPE (magnetic_response_class), INTENT(in) :: this
1055  INTEGER, INTENT(in) :: mdsig_iou
1056 
1057 ! local variables
1058  REAL (rprec), DIMENSION(:,:,:), ALLOCATABLE :: temp_buffer
1059  INTEGER :: phi
1060  REAL (rprec) :: start_time
1061 
1062 ! Start of executable code
1063  start_time = profiler_get_start_time()
1064 
1065 ! Define Variables ------------------------------------------------------------
1066  CALL cdf_write(mdsig_iou, nc_flags, this%flags)
1067 
1068 ! Identification Variables ----------------------------------------------------
1069  CALL cdf_write(mdsig_iou, nc_name, this%name)
1070  CALL cdf_write(mdsig_iou, nc_version, this%version)
1071  CALL cdf_write(mdsig_iou, nc_date, this%date)
1072  CALL cdf_write(mdsig_iou, nc_coil_id, this%coil_id)
1073 
1074 ! Coil Responce Function Variables --------------------------------------------
1075  IF (btest(this%flags, magnetic_response_use_coil_flag)) THEN
1076  CALL cdf_write(mdsig_iou, nc_n_field_cg, this%n_field_cg)
1077  CALL cdf_write(mdsig_iou, nc_inductance, this%inductance)
1078  CALL cdf_write(mdsig_iou, nc_current_scale, this%current_scale)
1079  END IF
1080 
1081 ! Plasma Response Grid Variables ----------------------------------------------
1082  IF (btest(this%flags, magnetic_response_use_plasma_flag)) THEN
1083  CALL cdf_write(mdsig_iou, nc_num_t, this%num_t)
1084  CALL cdf_write(mdsig_iou, nc_rmin, this%rmin)
1085  CALL cdf_write(mdsig_iou, nc_rmax, this%rmax)
1086  CALL cdf_write(mdsig_iou, nc_zmin, this%zmin)
1087  CALL cdf_write(mdsig_iou, nc_zmax, this%zmax)
1088  CALL cdf_write(mdsig_iou, nc_n_field_periods, &
1089  & this%n_field_periods)
1090 
1091 ! Need to decompress all the response function planes to and write the data
1092 ! buffers to a temp buffer. Decompress the r direction first to get the r z
1093 ! dimensions to allocate the temp buffer.
1094  CALL compression_decompress(this%a_r(1)%p)
1095  ALLOCATE(temp_buffer(SIZE(this%a_r(1)%p%data_buffer, 1), &
1096  & SIZE(this%a_r(1)%p%data_buffer, 2), &
1097  & SIZE(this%a_r)))
1098 
1099  temp_buffer(:,:,1) = this%a_r(1)%p%data_buffer
1100  CALL compression_cleanup(this%a_r(1)%p)
1101  DO phi = 2, SIZE(this%a_r)
1102  CALL compression_decompress(this%a_r(phi)%p)
1103  temp_buffer(:,:,phi) = this%a_r(phi)%p%data_buffer
1104  CALL compression_cleanup(this%a_r(phi)%p)
1105  END DO
1106  CALL cdf_write(mdsig_iou, nc_a_r, temp_buffer)
1107 
1108  DO phi = 1, SIZE(this%a_f)
1109  CALL compression_decompress(this%a_f(phi)%p)
1110  temp_buffer(:,:,phi) = this%a_f(phi)%p%data_buffer
1111  CALL compression_cleanup(this%a_f(phi)%p)
1112  END DO
1113  CALL cdf_write(mdsig_iou, nc_a_f, temp_buffer)
1114 
1115  DO phi = 1, SIZE(this%a_z)
1116  CALL compression_decompress(this%a_z(phi)%p)
1117  temp_buffer(:,:,phi) = this%a_z(phi)%p%data_buffer
1118  CALL compression_cleanup(this%a_z(phi)%p)
1119  END DO
1120  CALL cdf_write(mdsig_iou, nc_a_z, temp_buffer)
1121 
1122  DEALLOCATE(temp_buffer)
1123  END IF
1124 
1125 ! Conducting Shell Response Arrays --------------------------------------------
1126  IF (btest(this%flags, magnetic_response_use_shell_flag)) THEN
1127  CALL cdf_write(mdsig_iou, nc_num_t_shell, this%num_t_shell)
1128 
1129 ! Decompress each shell response function direction then write the data buffer.
1130  CALL compression_decompress(this%a_s_r)
1131  CALL cdf_write(mdsig_iou, nc_a_s_r, this%a_s_r%data_buffer)
1132  CALL compression_cleanup(this%a_s_r)
1133 
1134  CALL compression_decompress(this%a_s_f)
1135  CALL cdf_write(mdsig_iou, nc_a_s_f, this%a_s_f%data_buffer)
1136  CALL compression_cleanup(this%a_s_f)
1137 
1138  CALL compression_decompress(this%a_s_z)
1139  CALL cdf_write(mdsig_iou, nc_a_s_z, this%a_s_z%data_buffer)
1140  CALL compression_cleanup(this%a_s_z)
1141  END IF
1142 
1143 ! Point Diagnostic Response ---------------------------------------------------
1144  IF (btest(this%flags, magnetic_response_is_point_flag)) THEN
1145  CALL cdf_write(mdsig_iou, nc_position, this%position)
1146  CALL cdf_write(mdsig_iou, nc_direction, this%direction)
1147  END IF
1148 
1149  CALL profiler_set_stop_time('magnetic_response_write', start_time)
1150 
1151  END SUBROUTINE
1152 
1153  END MODULE
magnetic_response::nc_flags
character(len= *), parameter nc_flags
NETCDF configureation flags.
Definition: magnetic_response.f:52
magnetic_response::nc_a_r
character(len= *), parameter nc_a_r
NETCDF radial response grid variable.
Definition: magnetic_response.f:102
profiler
Defines functions for measuring an tabulating performance of function and subroutine calls....
Definition: profiler.f:13
magnetic_response::magnetic_response_construct
Interface for the construction of magnetic_response_class types using magnetic_response_construct_new...
Definition: magnetic_response.f:216
magnetic_response::nc_date
character(len= *), parameter nc_date
NETCDF date run variable.
Definition: magnetic_response.f:61
compression::compression_get_dimension2
integer function compression_get_dimension2(this)
Get the jth dimension length.
Definition: compression.f:425
magnetic_response::nc_stell_sym
character(len= *), parameter nc_stell_sym
NETCDF stell symmetric variable.
Definition: magnetic_response.f:98
compression::compression_cleanup
subroutine compression_cleanup(this)
Cleanup decompressed data.
Definition: compression.f:496
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
magnetic_response::nc_num_z
character(len= *), parameter nc_num_z
NETCDF number vertical grid points variable.
Definition: magnetic_response.f:83
magnetic_response::nc_version
character(len= *), parameter nc_version
NETCDF version variable.
Definition: magnetic_response.f:58
magnetic_response::nc_a_s_z
character(len= *), parameter nc_a_s_z
NETCDF vertical response shell grid variable.
Definition: magnetic_response.f:122
magnetic_response::nc_inductance
character(len= *), parameter nc_inductance
NETCDF mutual inductance variable.
Definition: magnetic_response.f:71
magnetic_response::magnetic_response_is_point_flag
integer, parameter magnetic_response_is_point_flag
Bit position for the use conducting shell flag.
Definition: magnetic_response.f:48
magnetic_response::magnetic_response_define
subroutine magnetic_response_define(this, mdsig_iou)
Defines the variables for the NETCDF file.
Definition: magnetic_response.f:955
magnetic_response::nc_current_scale
character(len= *), parameter nc_current_scale
NETCDF current scale variable.
Definition: magnetic_response.f:74
magnetic_response::nc_rmax
character(len= *), parameter nc_rmax
NETCDF maximum radial grid variable.
Definition: magnetic_response.f:87
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
magnetic_response::nc_num_t
character(len= *), parameter nc_num_t
NETCDF number torodial planes variable.
Definition: magnetic_response.f:79
magnetic_response::magnetic_response_is_stell_sym
logical function magnetic_response_is_stell_sym(this)
Checks if the stellarator symmetric flag is set.
Definition: magnetic_response.f:769
magnetic_response::nc_a_s_f
character(len= *), parameter nc_a_s_f
NETCDF toroidal response shell grid variable.
Definition: magnetic_response.f:120
magnetic_response::nc_rmin
character(len= *), parameter nc_rmin
NETCDF minimum radial grid variable.
Definition: magnetic_response.f:85
magnetic_response::nc_coil_id
character(len= *), parameter nc_coil_id
NETCDF coil identifier variable.
Definition: magnetic_response.f:63
magnetic_response::magnetic_response_write
subroutine magnetic_response_write(this, mdsig_iou)
Write variables to the NETCDF file.
Definition: magnetic_response.f:1050
v3_utilities::assert
Definition: v3_utilities.f:55
magnetic_response::magnetic_response_len
integer, parameter magnetic_response_len
Length for strings.
Definition: magnetic_response.f:37
magnetic_response::magnetic_response_use_plasma_flag
integer, parameter magnetic_response_use_plasma_flag
Bit position for the force coil response flag.
Definition: magnetic_response.f:42
magnetic_response::nc_num_r
character(len= *), parameter nc_num_r
NETCDF number radial grid points variable.
Definition: magnetic_response.f:81
magnetic_response::nc_a_f
character(len= *), parameter nc_a_f
NETCDF toroidal response grid variable.
Definition: magnetic_response.f:104
magnetic_response::magnetic_response_stell_sym_flag
integer, parameter magnetic_response_stell_sym_flag
Bit position for the stellerator symmetry flag.
Definition: magnetic_response.f:44
magnetic_response::nc_a_s_r
character(len= *), parameter nc_a_s_r
NETCDF radial response shell grid variable.
Definition: magnetic_response.f:118
magnetic_response::nc_direction
character(len= *), parameter nc_direction
NETCDF number torodial shell grid points variable.
Definition: magnetic_response.f:129
profiler::profiler_get_start_time
real(rprec) function profiler_get_start_time()
Gets the start time of profiled function.
Definition: profiler.f:194
magnetic_response::magnetic_response_is_point
logical function magnetic_response_is_point(this)
Checks if the coil response flag is set.
Definition: magnetic_response.f:922
magnetic_response::magnetic_response_construct_point
type(magnetic_response_class) function, pointer magnetic_response_construct_point(name, date, coil_id, position, direction, vacuum, current_scale)
Construct a magnetic_response_class object.
Definition: magnetic_response.f:413
magnetic_response::nc_use_shell
character(len= *), parameter nc_use_shell
NETCDF use conducting shell variable.
Definition: magnetic_response.f:111
magnetic_response::nc_n_field_cg
character(len= *), parameter nc_n_field_cg
NETCDF number of field coils variable.
Definition: magnetic_response.f:68
compression::compression_decompress
subroutine compression_decompress(this)
Decompress the data.
Definition: compression.f:459
magnetic_response::nc_num_t_shell
character(len= *), parameter nc_num_t_shell
NETCDF number torodial shell grid points variable.
Definition: magnetic_response.f:114
magnetic_response::nc_name
character(len= *), parameter nc_name
NETCDF code name variable.
Definition: magnetic_response.f:56
compression::compression_pointer
Pointer to a compression object. Used for creating arrays of compression pointers....
Definition: compression.f:66
magnetic_response::magnetic_response_destruct
subroutine magnetic_response_destruct(this)
Deconstruct a magnetic_response_class object.
Definition: magnetic_response.f:695
magnetic_response::magnetic_response_class
Base class representing a magnetic signal response function.
Definition: magnetic_response.f:140
magnetic_response::magnetic_response_construct_new
type(magnetic_response_class) function, pointer magnetic_response_construct_new(name, date, coil_id, inductance, current_scale, num_t, num_t_shell, rmin, rmax, zmin, zmax, n_field_periods, stell_sym, a_r, a_f, a_z, a_s_r, a_s_f, a_s_z, svd_cut_off)
Construct a magnetic_response_class object.
Definition: magnetic_response.f:267
magnetic_response::magnetic_response_use_coil
logical function magnetic_response_use_coil(this)
Checks if the coil response flag is set.
Definition: magnetic_response.f:862
compression
Defines the base class of the type compression_class. This class contains the code and buffers to hol...
Definition: compression.f:14
profiler::profiler_set_stop_time
subroutine profiler_set_stop_time(symbol_name, start_time)
Gets the end time of profiled function.
Definition: profiler.f:121
magnetic_response::magnetic_response_20140928
character(len= *), parameter magnetic_response_20140928
Version for the MDSIG files. This version adds the conducting shell.
Definition: magnetic_response.f:33
magnetic_response::nc_a_z
character(len= *), parameter nc_a_z
NETCDF vertical response grid variable.
Definition: magnetic_response.f:106
magnetic_response::nc_zmin
character(len= *), parameter nc_zmin
NETCDF minimum vertical grid variable.
Definition: magnetic_response.f:89
magnetic_response
Defines the base class of the type magnetic_response_class.
Definition: magnetic_response.f:11
magnetic_response::magnetic_response_current
character(len= *), parameter magnetic_response_current
Version for the MDSIG files. This version adds the point diagnostics.
Definition: magnetic_response.f:28
magnetic_response::magnetic_response_construct_netcdf
type(magnetic_response_class) function, pointer magnetic_response_construct_netcdf(mdsig_iou, svd_cut_off)
Construct a magnetic_response_class object.
Definition: magnetic_response.f:489
magnetic_response::magnetic_response_clr_use_coil
subroutine magnetic_response_clr_use_coil(this)
Clears the coil response bit.
Definition: magnetic_response.f:893
compression::compression_get_dimension1
integer function compression_get_dimension1(this)
Get the ith dimension length.
Definition: compression.f:395
compression::compression_class
Base class containing buffers for compressed and uncompressed data.
Definition: compression.f:47
magnetic_response::nc_zmax
character(len= *), parameter nc_zmax
NETCDF maximum vertical grid variable.
Definition: magnetic_response.f:91
compression::compression_construct
Interface for the construction of compression_class types using compression_construct_new or compress...
Definition: compression.f:79
magnetic_response::nc_position
character(len= *), parameter nc_position
NETCDF use conducting shell variable.
Definition: magnetic_response.f:126
compression::compression_destruct
subroutine compression_destruct(this)
Deconstruct a compression_class object.
Definition: compression.f:356
magnetic_response::magnetic_response_use_shell_flag
integer, parameter magnetic_response_use_shell_flag
Bit position for the use conducting shell flag.
Definition: magnetic_response.f:46
magnetic_response::magnetic_response_use_coil_flag
integer, parameter magnetic_response_use_coil_flag
Bit position for the use coil response flag.
Definition: magnetic_response.f:40
magnetic_response::nc_n_field_periods
character(len= *), parameter nc_n_field_periods
NETCDF number of field periods variable.
Definition: magnetic_response.f:93