Skip to content

Commit

Permalink
Updated solver residual output. Updated test problems to write out re…
Browse files Browse the repository at this point in the history
…sidual every 100 iterations.
  • Loading branch information
sumseq committed Oct 24, 2022
1 parent 5260a3f commit 5904ae7
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 66 deletions.
4 changes: 1 addition & 3 deletions pot3d_input_documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@
! 0 Only writes out total iteration number.
! >0 Writes out every NCGHIST iteration residual.
!
ncgflush=25 ! Flush output file every NGCFLUSH iterations.
!
ncgmax=5000 ! Maximum solver iterations.
ncgmax=1000000 ! Maximum solver iterations.
! If solver does not converge in ncgmax iterations,
! the code will exit with an error.
!
Expand Down
2 changes: 1 addition & 1 deletion run_examples/open_field/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
!
ifprec=2
epscg=1.e-9
ncghist=0
ncghist=100
ncgmax=10000000
!
! Debugging flag.
Expand Down
2 changes: 1 addition & 1 deletion run_examples/potential_field_current_sheet/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
!
ifprec=2
epscg=1.e-9
ncghist=0
ncghist=100
ncgmax=10000000
!
! Debugging flag.
Expand Down
2 changes: 1 addition & 1 deletion run_examples/potential_field_source_surface/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
!
ifprec=2
epscg=1.e-9
ncghist=0
ncghist=100
ncgmax=10000000
!
! Debugging flag.
Expand Down
87 changes: 32 additions & 55 deletions src/pot3d.F
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ module ident
c-----------------------------------------------------------------------
c
character(*), parameter :: idcode='POT3D'
character(*), parameter :: vers ='r4.0.1'
character(*), parameter :: update='03/31/2022'
character(*), parameter :: vers ='r4.1.0'
character(*), parameter :: update='10/24/2022'
c
end module
c#######################################################################
Expand Down Expand Up @@ -451,9 +451,8 @@ module cgcom
c-----------------------------------------------------------------------
c
integer :: ifprec=1
integer :: ncgmax=5000
integer :: ncghist=0
integer :: ncgflush=25
integer :: ncgmax=1000000
integer :: ncghist=100
real(r_typ) :: epscg=1.e-9
c
c-----------------------------------------------------------------------
Expand Down Expand Up @@ -783,11 +782,12 @@ program POT3D
write (*,*)
write (*,*) '### COMMENT from POT3D:'
write (*,*) '### Starting PCG solve.'
call FLUSH(OUTPUT_UNIT)
write (9,*)
write (9,*) '### COMMENT from POT3D:'
write (9,*) '### Starting PCG solve.'
call FLUSH(9)
end if
call flush_output_file(outfile,9)
c
call timer_on
c
Expand Down Expand Up @@ -815,42 +815,6 @@ program POT3D
call endrun (.false.)
c
end
c#######################################################################
subroutine flush_output_file (filename,fsid)
c
c-----------------------------------------------------------------------
c
c ****** Flush output file by closing it and re-opening it in append.
c ****** filename is a character(256) which contains the filename
c ****** and fsid is the file's unit number.
c
c-----------------------------------------------------------------------
c
use mpidefs
use vars
c
c-----------------------------------------------------------------------
c
implicit none
c
c-----------------------------------------------------------------------
c
integer :: fsid
character(256) :: filename
c
c-----------------------------------------------------------------------
c
integer :: ierr
c
c-----------------------------------------------------------------------
c
if (iamp0) then
close(fsid)
call ffopen (fsid,trim(filename),'a',ierr)
end if
call check_error_on_p0 (ierr)
c
end
c#######################################################################
subroutine read_input_file
c
Expand Down Expand Up @@ -900,8 +864,7 @@ subroutine read_input_file
& br_photo_original_file,
& option,
& do_not_balance_flux,hdf32,
& validation_run,dipole_angle,
& ncgflush
& validation_run,dipole_angle
c
c-----------------------------------------------------------------------
c
Expand Down Expand Up @@ -4356,22 +4319,19 @@ subroutine ernorm (bdotb,rdotr,ierr)
epsn=sign(one,epssq)*sqrt(abs(epssq))
c
if (ncghist.gt.0) then
if (iamp0.and.mod(ncg,50).eq.0) then
call flush_output_file(outfile,9)
end if
c
if (mod(ncg,ncghist).eq.0) then
if (iamp0) then
if (ncg.eq.0) then
write (9,*)
write (9,*) '### Comment from ERNORM:'
write (9,*) '### Convergence information:'
write (*,*)
end if
write (*,100) ncg,epsn
FLUSH(OUTPUT_UNIT)
write (9,100) ncg,epsn
if (mod(ncg,ncgflush).eq.0) then
call flush_output_file(outfile,9)
end if
100 format (1x,'N = ',i6,' EPSN = ',1pe13.6)
FLUSH(9)
100 format (1x,'Iteration: ',i8,' Residual: ',1pe23.15)
end if
end if
end if
Expand All @@ -4381,11 +4341,12 @@ subroutine ernorm (bdotb,rdotr,ierr)
if (epsn.lt.epscg) then
if (ncghist.gt.0) then
if (iamp0) then
write (*,100) ncg,epsn
FLUSH(OUTPUT_UNIT)
write (9,*)
write (9,*) '### Comment from ERNORM:'
write (9,*) '### The CG solver has converged.'
write (9,100) ncg,epsn
call flush_output_file(outfile,9)
FLUSH(9)
end if
end if
ierr=0
Expand All @@ -4396,12 +4357,13 @@ subroutine ernorm (bdotb,rdotr,ierr)
write (*,*) '### Exceeded maximum number of iterations.'
write (*,*) 'NCGMAX = ',ncgmax
write (*,*) 'EPSN = ',epsn
FLUSH(OUTPUT_UNIT)
write (9,*)
write (9,*) '### ERROR in ERNORM:'
write (9,*) '### Exceeded maximum number of iterations.'
write (9,*) 'NCGMAX = ',ncgmax
write (9,*) 'EPSN = ',epsn
call flush_output_file(outfile,9)
FLUSH(9)
end if
ierr=1
end if
Expand Down Expand Up @@ -6427,6 +6389,12 @@ subroutine write_timing
write (1,*)
c
close (1)
c
write(*,*)
write(*,200) 'Total time: ',tmax(10)
write(*,200) 'Max Comm/Imbalance time: ',
& tmax(7)+tmax(8)+tmax(9)
write(*,*)
c
end if
c
Expand Down Expand Up @@ -7020,4 +6988,13 @@ subroutine interp (x,n,xv,i,alpha)
c This fixes a compiler error with GFORTRAN when
c using cuSparse.
c
c ### Version 4.1.0, 10/24/2022, modified by RC:
c
c - Removed NCGFLUSH input parameter. The output is
c flushed at every write now.
c - Changed behavior of solver residual reporting
c to also output to terminal.
c - Removed flush_output_file() routine in favor of Fortran 2003
c intrinsic FLUSH.
c
c#######################################################################
2 changes: 1 addition & 1 deletion testsuite/isc2023/input/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
btfile='bt.h5'
bpfile='bp.h5'
br_photo_file=''
ncghist=0
ncghist=100
ncgmax=10000000
epscg=1.e-12
idebug=0
Expand Down
2 changes: 1 addition & 1 deletion testsuite/large/input/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
btfile=''
bpfile=''
br_photo_file=''
ncghist=0
ncghist=100
ncgmax=10000000
epscg=1.e-12
idebug=0
Expand Down
2 changes: 1 addition & 1 deletion testsuite/medium/input/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
btfile=''
bpfile=''
br_photo_file=''
ncghist=0
ncghist=100
ncgmax=10000000
epscg=1.e-12
idebug=0
Expand Down
2 changes: 1 addition & 1 deletion testsuite/small/input/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
btfile=''
bpfile=''
br_photo_file=''
ncghist=0
ncghist=100
ncgmax=10000000
epscg=1.e-12
idebug=0
Expand Down
2 changes: 1 addition & 1 deletion testsuite/validation/input/pot3d.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
btfile=''
bpfile=''
br_photo_file=''
ncghist=0
ncghist=25
ncgmax=10000000
epscg=1.e-12
idebug=0
Expand Down

0 comments on commit 5904ae7

Please sign in to comment.