Skip to content

Commit

Permalink
Fixed underflow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jul 13, 2022
1 parent 65427e4 commit 29e4b76
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/regolith/regolith_depth_model.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
subroutine regolith_depth_model(user,domain,finterval,nflux,p)
use module_globals
use module_util
use, intrinsic :: ieee_arithmetic
use module_regolith, EXCEPT_THIS_ONE => regolith_depth_model
implicit none

Expand All @@ -35,7 +36,9 @@ subroutine regolith_depth_model(user,domain,finterval,nflux,p)
integer(I4B) :: i, j
real(DP) :: h, dr, f, fmin, fmax
real(DP) :: ntotsubcrat
logical :: underflow

if (ieee_support_underflow_control(psum)) call ieee_set_underflow_mode(gradual=.true.)
! Smallest crater size in sub-pixel crater regime (regolith scaling column in "nflux")
! Do it in terms of number of craters
ntotsubcrat = 0._DP
Expand Down Expand Up @@ -93,7 +96,11 @@ subroutine regolith_depth_model(user,domain,finterval,nflux,p)
f = 0.5_DP * dr * ( fmin + fmax )
psum = psum + f
end do
p(2,i) = 1.0_DP - exp(-1.0_DP * PI * psum * t)
if (abs(psum) > epsilon(psum)) then
p(2,i) = 1.0_DP - exp(-1.0_DP * PI * psum * t)
else
p(2,i) = 1.0_DP
end if
end do

return
Expand Down

0 comments on commit 29e4b76

Please sign in to comment.