From ba43da215e197b21bae1715a58ea14713db85a93 Mon Sep 17 00:00:00 2001 From: "samuel.trahan" Date: Wed, 21 Sep 2022 15:47:05 +0000 Subject: [PATCH 1/2] module_sf_ruclsm imprecision workaround The module_sf_ruclsm has comparisons to zero, which break the code when numbers are very close to 0, such as 1e-322. This happens with the gfortran compiler when compled -DDEBUG=ON since the option to truncate subnormal numbers is turned off. The workaround is to truncate subnormal numbers manually, for the two variables that cause trouble. --- physics/module_sf_ruclsm.F90 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/physics/module_sf_ruclsm.F90 b/physics/module_sf_ruclsm.F90 index 9a6363c08..eff3aa0fc 100644 --- a/physics/module_sf_ruclsm.F90 +++ b/physics/module_sf_ruclsm.F90 @@ -521,6 +521,15 @@ SUBROUTINE LSMRUC( & DO i=its,ite + IF(ABS(SNOWH(I,J))<1e-20) THEN + ! Workaround needed for subnormal numbers (gfortran issue) + SNOWH(I,J)=0 + ENDIF + IF(ABS(SNOW(I,J))<1e-20) THEN + ! Workaround needed for subnormal numbers (gfortran issue) + SNOW(I,J)=0 + ENDIF + IF (debug_print ) THEN ! if(j==10) then print *,' IN LSMRUC ','ims,ime,jms,jme,its,ite,jts,jte,nzs', & From 824d40d2c5329112c040d9ca766e78e56d0aace1 Mon Sep 17 00:00:00 2001 From: "samuel.trahan" Date: Mon, 26 Sep 2022 14:36:31 +0000 Subject: [PATCH 2/2] move sanity checks to lsm_ruc and add "snow on ice" check --- physics/lsm_ruc.F90 | 27 +++++++++++++++++++++++++++ physics/module_sf_ruclsm.F90 | 9 --------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/physics/lsm_ruc.F90 b/physics/lsm_ruc.F90 index 4db2c9894..99b6c2b41 100644 --- a/physics/lsm_ruc.F90 +++ b/physics/lsm_ruc.F90 @@ -1043,6 +1043,20 @@ subroutine lsm_ruc_run & ! inputs z0_lnd(i,j) = z0rl_lnd(i)/100. znt_lnd(i,j) = z0rl_lnd(i)/100. + ! Workaround needed for subnormal numbers. This should be + ! done after all other sanity checks, in case a sanity check + ! results in subnormal numbers. + ! + ! This bug was caught by the UFS gfortran debug-mode + ! regression tests, and the fix is necessary to pass those + ! tests. + if(abs(snowh_lnd(i,j))<1e-20) then + snowh_lnd(i,j)=0 + endif + if(abs(sneqv_lnd(i,j))<1e-20) then + sneqv_lnd(i,j)=0 + endif + if(debug_print) then if(me==0 ) then write (0,*)'before LSMRUC for land' @@ -1360,6 +1374,19 @@ subroutine lsm_ruc_run & ! inputs z0_ice(i,j) = z0rl_ice(i)/100. znt_ice(i,j) = z0rl_ice(i)/100. + ! Workaround needed for subnormal numbers. This should be + ! done after all other sanity checks, in case a sanity check + ! results in subnormal numbers. + ! + ! Although this bug has not been triggered yet, it is expected + ! to be, like the _lnd variants many lines up from here. + if(abs(snowh_ice(i,j))<1e-20) then + snowh_ice(i,j)=0 + endif + if(abs(sneqv_ice(i,j))<1e-20) then + sneqv_ice(i,j)=0 + endif + !> - Call RUC LSM lsmruc() for ice. call lsmruc( & & delt, flag_init, lsm_cold_start, kdt, iter, nsoil, & diff --git a/physics/module_sf_ruclsm.F90 b/physics/module_sf_ruclsm.F90 index eff3aa0fc..9a6363c08 100644 --- a/physics/module_sf_ruclsm.F90 +++ b/physics/module_sf_ruclsm.F90 @@ -521,15 +521,6 @@ SUBROUTINE LSMRUC( & DO i=its,ite - IF(ABS(SNOWH(I,J))<1e-20) THEN - ! Workaround needed for subnormal numbers (gfortran issue) - SNOWH(I,J)=0 - ENDIF - IF(ABS(SNOW(I,J))<1e-20) THEN - ! Workaround needed for subnormal numbers (gfortran issue) - SNOW(I,J)=0 - ENDIF - IF (debug_print ) THEN ! if(j==10) then print *,' IN LSMRUC ','ims,ime,jms,jme,its,ite,jts,jte,nzs', &