Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIAGNO] add an option to write a more accurate output file for the afield_points diagnostic #237

Merged
merged 7 commits into from
May 17, 2024
39 changes: 28 additions & 11 deletions DIAGNO/Sources/diagno_afield.f90
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,35 @@ SUBROUTINE diagno_afield
moda = sqrt(ax*ax+ay*ay+az*az)
ar = ax * cos(phip) + ay * sin(phip)
aphi = ay * cos(phip) - ax * sin(phip)
IF (lrphiz) THEN
DO i = 1, ncoils
IF (lverb) WRITE(6,'(13X,I8,1X,7E14.5)') i,rp(i),phip(i),zp(i),ar(i),aphi(i),az(i),moda(i)
WRITE(iunit_out,'(13X,I8,1X,7E14.5)') i,rp(i),phip(i),zp(i),ar(i),aphi(i),az(i),moda(i)
END DO
WRITE(iunit_out,'(A)')' # rp[m] phip[deg] zp[m] A_R[Tm] A_PHI[Tm] A_Z[Tm] |A|[Tm]'
IF (lapoints_accurate_output) THEN
! more digits of accuracy, if enabled
WRITE(iunit_out,'(1X,I6.6)') ncoils ! also write number of points first
IF (lrphiz) THEN
DO i = 1, ncoils
IF (lverb) WRITE(6,'(13X,I8,1X,7E14.5)') i,rp(i),phip(i),zp(i),ar(i),aphi(i),az(i),moda(i)
WRITE(iunit_out,'(13X,I8,1X,7ES22.12E3)') i,rp(i),phip(i),zp(i),ar(i),aphi(i),az(i),moda(i)
END DO
ELSE
DO i = 1, ncoils
IF (lverb) WRITE(6,'(13X,I8,1X,7E14.5)') i,xp(i),yp(i),zp(i),ax(i),ay(i),az(i),moda(i)
WRITE(iunit_out,'(13X,I8,1X,7ES22.12E3)') i,xp(i),yp(i),zp(i),ax(i),ay(i),az(i),moda(i)
END DO
END IF
ELSE
DO i = 1, ncoils
IF (lverb) WRITE(6,'(13X,I8,1X,7E14.5)') i,xp(i),yp(i),zp(i),ax(i),ay(i),az(i),moda(i)
WRITE(iunit_out,'(13X,I8,1X,7E14.5)') i,xp(i),yp(i),zp(i),ax(i),ay(i),az(i),moda(i)
END DO
WRITE(iunit_out,'(A)')' # xp[m] yp[m] zp[m] A_X[Tm] A_Y[Tm] A_Z[Tm] |A|[Tm]'
! backward compatibility output
IF (lrphiz) THEN
DO i = 1, ncoils
IF (lverb) WRITE(6,'(13X,I8,1X,7E14.5)') i,rp(i),phip(i),zp(i),ar(i),aphi(i),az(i),moda(i)
WRITE(iunit_out,'(13X,I8,1X,7E14.5)') i,rp(i),phip(i),zp(i),ar(i),aphi(i),az(i),moda(i)
END DO
WRITE(iunit_out,'(A)')' # rp[m] phip[deg] zp[m] A_R[Tm] A_PHI[Tm] A_Z[Tm] |A|[Tm]'
ELSE
DO i = 1, ncoils
IF (lverb) WRITE(6,'(13X,I8,1X,7E14.5)') i,xp(i),yp(i),zp(i),ax(i),ay(i),az(i),moda(i)
WRITE(iunit_out,'(13X,I8,1X,7E14.5)') i,xp(i),yp(i),zp(i),ax(i),ay(i),az(i),moda(i)
END DO
WRITE(iunit_out,'(A)')' # xp[m] yp[m] zp[m] A_X[Tm] A_Y[Tm] A_Z[Tm] |A|[Tm]'
END IF
END IF
CLOSE(iunit_out)
END IF
Expand Down
16 changes: 10 additions & 6 deletions DIAGNO/Sources/diagno_input_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ MODULE diagno_input_mod
!-----------------------------------------------------------------------
USE diagno_runtime
USE safe_open_mod, ONLY: safe_open

!-----------------------------------------------------------------------
! Module Variables
!
!
!-----------------------------------------------------------------------
IMPLICIT NONE
LOGICAL :: lexist
Expand All @@ -39,6 +39,7 @@ MODULE diagno_input_mod
! vc_adapt_rel Adaptive integration relative tollerance
! flux_mut_file Mutual induction file (not fully implemented)
! lvc_field Use virtual casing instead of volume integral for free boundary
! lapoints_accurate_output Enable writing apoints outputs with more digits
! lbpoints_accurate_output Enable writing bpoints outputs with more digits
!-----------------------------------------------------------------------
namelist /diagno_in/ nu, nv, &
Expand All @@ -48,14 +49,14 @@ MODULE diagno_input_mod
int_step, lrphiz, vc_adapt_tol, vc_adapt_rel,&
flux_mut_file, lvc_field, bprobe_turns, luse_extcur, &
bprobes_mut_file, mir_mut_file, rog_mut_file, segrog_turns, &
lbpoints_accurate_output
lapoints_accurate_output, lbpoints_accurate_output

!-----------------------------------------------------------------------
! Subroutines
! read_diagno_input: Reads diagno_in namelist
!-----------------------------------------------------------------------
CONTAINS

SUBROUTINE read_diagno_input(filename, istat)
CHARACTER(*), INTENT(in) :: filename
INTEGER, INTENT(out) :: istat
Expand Down Expand Up @@ -86,6 +87,7 @@ SUBROUTINE read_diagno_input(filename, istat)
vc_adapt_rel = 1.0E-04_rprec
lvc_field = .TRUE.
luse_extcur(:) = .TRUE. ! Do this so we default to using the whole coil if the user forgets
lapoints_accurate_output = .false. ! default for backward compatibility
lbpoints_accurate_output = .false. ! default for backward compatibility
! Read namelist
istat=0; iunit = 25
Expand Down Expand Up @@ -169,7 +171,7 @@ SUBROUTINE read_diagno_input(filename, istat)
IF (LEN_TRIM(rog_mut_file)>1) luse_mut = .TRUE.
IF (lmut) luse_mut = .FALSE.
END SUBROUTINE read_diagno_input

SUBROUTINE write_diagno_input(iunit,istat)
INTEGER, INTENT(in) :: iunit
INTEGER, INTENT(inout) :: istat
Expand All @@ -195,6 +197,8 @@ SUBROUTINE write_diagno_input(iunit,istat)
WRITE(iunit,"(2X,A,1X,'=',10(1X,E22.14))") 'SEGROG_TURNS',(segrog_turns(n), n=1,256)
WRITE(iunit,"(2X,A,1X,'=',1X,L1)") 'LRPHIZ',lrphiz
WRITE(iunit,"(2X,A,1X,'=',1X,L1)") 'LVC_FIELD',lvc_field
WRITE(iunit,"(2X,A,1X,'=',1X,L1)") 'LAPOINTS_ACCURATE_OUTPUT',lapoints_accurate_output
WRITE(iunit,"(2X,A,1X,'=',1X,L1)") 'LBPOINTS_ACCURATE_OUTPUT',lbpoints_accurate_output
WRITE(iunit,'(A)') '/'
CALL FLUSH(iunit)
END SUBROUTINE write_diagno_input
Expand Down
16 changes: 9 additions & 7 deletions DIAGNO/Sources/diagno_runtime.f90
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ MODULE diagno_runtime
! afield_points_file A-Field at a point diagnostic
! bfield_points_file B-Field at a point diagnostic
! extcur External currents for MGRID calculation
! lapoints_accurate_output Enable writing apoints outputs with more digits
! lbpoints_accurate_output Enable writing bpoints outputs with more digits
!----------------------------------------------------------------------
IMPLICIT NONE

INTEGER, PARAMETER :: FILE_OPEN_ERR = 1
INTEGER, PARAMETER :: ALLOC_ERR = 11
INTEGER, PARAMETER :: NAMELIST_READ_ERR = 12
Expand All @@ -103,9 +104,10 @@ MODULE diagno_runtime
INTEGER, PARAMETER :: MPI_FINE_ERR = 89

INTEGER, PARAMETER :: MAXLINES = 256

LOGICAL :: lverb, lvmec, lpies, lspec, lcoil, lvac, &
lrphiz, lmut, luse_mut, lvc_field, &
lapoints_accurate_output, &
lbpoints_accurate_output
LOGICAL :: luse_extcur(512),lskip_flux(2048),lskip_rogo(2048)
INTEGER :: nextcur, int_step, nu, nv, nfp_diagno, eq_sgns,&
Expand All @@ -118,7 +120,7 @@ MODULE diagno_runtime
bfield_points_file, &
int_type, coil_string, flux_mut_file, rog_mut_file,&
mir_mut_file, bprobes_mut_file

REAL(rprec), PARAMETER :: DIAGNO_VERSION = 4.00
REAL(rprec), PARAMETER :: pi = 3.14159265358979312D+00
REAL(rprec), PARAMETER :: pi2 = 6.28318530717958623
Expand All @@ -130,14 +132,14 @@ MODULE diagno_runtime
! handle_error Controls Program Termination
!-----------------------------------------------------------------------
CONTAINS

SUBROUTINE handle_error(error_num,string_val,ierr)
IMPLICIT NONE
INTEGER,INTENT(in) :: error_num
INTEGER,INTENT(inout) :: ierr
CHARACTER(*),INTENT(in) :: string_val
WRITE(6,*) '!!!!! ERROR !!!!!'

IF (error_num .eq. FILE_OPEN_ERR) THEN
WRITE(6,*) ' DIAGNO COULD NOT OPEN A FILE.'
WRITE(6,*) ' FILENAME: ',TRIM(string_val)
Expand Down Expand Up @@ -235,9 +237,9 @@ SUBROUTINE handle_error(error_num,string_val,ierr)
END IF
CALL FLUSH(6)
!DEC$ IF DEFINED (MPI_OPT)
CALL MPI_FINALIZE(ierr)
CALL MPI_FINALIZE(ierr)
!DEC$ ENDIF
STOP
END SUBROUTINE handle_error

END MODULE diagno_runtime