Skip to content

Commit

Permalink
feat(par): add Newton underrelaxation convergence check for parallel (#…
Browse files Browse the repository at this point in the history
…1296)

* feat(par): add Newton underrelaxation convergence check for parallel

* call base method
  • Loading branch information
mjr-deltares authored Jul 14, 2023
1 parent 697b889 commit 34dc907
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/Solution/NumericalSolution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module NumericalSolutionModule

! 'protected' (this can be overridden)
procedure :: sln_has_converged
procedure :: sln_nur_has_converged
procedure :: sln_calc_ptc
procedure :: sln_underrelax

Expand Down Expand Up @@ -1526,7 +1527,7 @@ subroutine solve(this, kiter)
integer(I4B) :: ipos0
integer(I4B) :: ipos1
real(DP) :: dxmax_nur
real(DP) :: dxmax
real(DP) :: dxold_max
real(DP) :: ptcf
real(DP) :: ttform
real(DP) :: ttsoln
Expand Down Expand Up @@ -1754,12 +1755,12 @@ subroutine solve(this, kiter)
!
! -- calculate maximum change in heads in cells that have
! not been adjusted by newton under-relxation
call this%sln_maxval(this%neq, this%dxold, dxmax)
call this%sln_maxval(this%neq, this%dxold, dxold_max)
!
! -- evaluate convergence
if (abs(dxmax) <= this%dvclose .and. &
abs(this%hncg(kiter)) <= this%dvclose .and. &
abs(dpak) <= this%dvclose) then
if (this%sln_nur_has_converged(dxold_max, this%hncg(kiter), dpak)) then
!
! -- converged
this%icnvg = 1
!
! -- reset outer dependent-variable change and location for output
Expand Down Expand Up @@ -3139,6 +3140,25 @@ function sln_has_converged(this, max_dvc) result(has_converged)

end function sln_has_converged

!> @brief Custom convergence check for when Newton UR has been applied
!<
function sln_nur_has_converged(this, dxold_max, hncg, dpak) &
result(has_converged)
class(NumericalSolutionType) :: this !< NumericalSolutionType instance
real(DP) :: dxold_max !< the maximum dependent variable change for unrelaxed cells
real(DP) :: hncg !< largest dep. var. change at end of Picard iteration
real(DP) :: dpak !< largest change in advanced packages
logical(LGP) :: has_converged !< True, when converged

has_converged = .false.
if (abs(dxold_max) <= this%dvclose .and. &
abs(hncg) <= this%dvclose .and. &
abs(dpak) <= this%dvclose) then
has_converged = .true.
end if

end function sln_nur_has_converged

!> @ brief Get cell location string
!!
!! Get the cell location string for the provided solution node number.
Expand Down
28 changes: 28 additions & 0 deletions src/Solution/ParallelSolution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module ParallelSolutionModule
contains
! override
procedure :: sln_has_converged => par_has_converged
procedure :: sln_nur_has_converged => par_nur_has_converged
procedure :: sln_calc_ptc => par_calc_ptc
procedure :: sln_underrelax => par_underrelax
end type ParallelSolutionType
Expand Down Expand Up @@ -44,6 +45,33 @@ function par_has_converged(this, max_dvc) result(has_converged)

end function par_has_converged

function par_nur_has_converged(this, dxold_max, hncg, dpak) &
result(has_converged)
class(ParallelSolutionType) :: this !< parallel solution instance
real(DP) :: dxold_max !< the maximum dependent variable change for cells not adjusted by NUR
real(DP) :: hncg !< largest dep. var. change at end of Picard iter.
real(DP) :: dpak !< largest change in advanced packages
logical(LGP) :: has_converged !< True, when converged
! local
integer(I4B) :: icnvg_local, icnvg_global
integer :: ierr
type(MpiWorldType), pointer :: mpi_world

has_converged = .false.

icnvg_local = 0
if (this%NumericalSolutionType%sln_nur_has_converged( &
dxold_max, hncg, dpak)) then
icnvg_local = 1
end if

call MPI_Allreduce(icnvg_local, icnvg_global, 1, MPI_INTEGER, &
MPI_MIN, mpi_world%comm, ierr)

has_converged = (icnvg_global == 1)

end function par_nur_has_converged

!> @brief Calculate pseudo-transient continuation factor
!< for the parallel case
subroutine par_calc_ptc(this, iptc, ptcf)
Expand Down

0 comments on commit 34dc907

Please sign in to comment.