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

RUC LSM precision workaround #163

Merged
merged 2 commits into from
Sep 28, 2022

Conversation

SamuelTrahanNOAA
Copy link
Collaborator

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.

My fix is truncate subnormal numbers manually, for the two variables that cause trouble.

Another possible fix is to remove all comparisons to zero and all equality comparisons from the ruclsm. However, I don't know why the developer used that method of comparing, nor what the appropriate epsilons are for the comparisons. Ultimately, this would require changing many more lines of code than my approach.

This is a copy of the community PR, with a different destination (RRFS_dev)

ufs-community#6

Copy link
Collaborator

@tanyasmirnova tanyasmirnova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamuelTrahanNOAA Sam, will be be more appropriate to put this workaround into lsm_ruc.F90? There is a sanity check on snow in there, and I guess it did not cover this situation when snow < 1.e-20

@SamuelTrahanNOAA
Copy link
Collaborator Author

@SamuelTrahanNOAA Sam, will be be more appropriate to put this workaround into lsm_ruc.F90? There is a sanity check on snow in there, and I guess it did not cover this situation when snow < 1.e-20

I looked for that before, but I couldn't find it. Can you tell me where the sanity checks reside?

Also, can you please put your comment on the community PR as well?

ufs-community#6

It will probably get more widespread review there.

@tanyasmirnova
Copy link
Collaborator

@SamuelTrahanNOAA Please, look for a comment "!> -- sanity checks on sneqv and snowh" in lsm_ruc.F90

@SamuelTrahanNOAA
Copy link
Collaborator Author

@SamuelTrahanNOAA Please, look for a comment "!> -- sanity checks on sneqv and snowh" in lsm_ruc.F90

I put it here, and I'm testing the change now with the gnu compiler:

            if (debug_print .and. abs(xlat_d(i)-testptlat).lt.0.5 .and.   &
              abs(xlon_d(i)-testptlon).lt.0.5)then
              print *,'fixed small snow density',kdt,i,j,sneqv_lnd(i,j)/snowh_lnd(i,j),sneqv_lnd(i,j),snowh_lnd(i,j)
            endif
          endif
        endif


         if(abs(snowh_lnd(i,j))<1e-20) then
           ! Workaround needed for subnormal numbers (gfortran debug issue)
           snowh_lnd(i,j)=0
         endif
         if(abs(sneqv_lnd(i,j))<1e-20) then
           ! Workaround needed for subnormal numbers (gfortran debug issue)
           sneqv_lnd(i,j)=0
         endif

        !-- z0rl is in [cm]                                                                                                                                                                                                                  
        z0_lnd(i,j)  = z0rl_lnd(i)/100.
        znt_lnd(i,j) = z0rl_lnd(i)/100.

@tanyasmirnova
Copy link
Collaborator

@SamuelTrahanNOAA Looks good. Thank you!

@tanyasmirnova
Copy link
Collaborator

@SamuelTrahanNOAA actually, we should add this workaround also to snow on ice. Please, look for another comment "sanity chack on sneqv' around line 1402.

@SamuelTrahanNOAA
Copy link
Collaborator Author

SamuelTrahanNOAA commented Sep 23, 2022

That means the fix is now:

              print *,'fixed small snow density',kdt,i,j,sneqv_lnd(i,j)/snowh_lnd(i,j),sneqv_lnd(i,j),snowh_lnd(i,j)
            endif
          endif
        endif


         ! Workaround needed for subnormal numbers (gfortran debug issue)                                                                                                                                                                  
         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(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

        !-- z0rl is in [cm]                                                                                                                                                                                                                  
        z0_lnd(i,j)  = z0rl_lnd(i)/100.
        znt_lnd(i,j) = z0rl_lnd(i)/100.

        !if (debug_print) then                                                                                                                                                                                                               
        !-- diagnostics for a land test point with known lat/lon                                                                                                                                                                             
        if (kdt < 10) then
        if (abs(xlat_d(i)-testptlat).lt.0.5 .and.   &

@tanyasmirnova
Copy link
Collaborator

@SamuelTrahanNOAA This will do it, although ice variables are in the different section of lsm_ruc.F90 after the land part.

@SamuelTrahanNOAA
Copy link
Collaborator Author

SamuelTrahanNOAA commented Sep 23, 2022

@SamuelTrahanNOAA This will do it, although ice variables are in the different section of lsm_ruc.F90 after the land part.

I put this at the end of the sanity checks, in case the other sanity checks result in subnormal numbers.

Edit: I've updated the comment in the code to explain that.

@SamuelTrahanNOAA SamuelTrahanNOAA changed the title module_sf_ruclsm precision workaround RUC LSM precision workaround Sep 23, 2022
@SamuelTrahanNOAA SamuelTrahanNOAA merged commit 1985ee1 into NOAA-GSL:RRFS_dev Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants