Skip to content

Commit

Permalink
Merge pull request #1 from SamuelTrahanNOAA/RRFS_dev_sd_sam
Browse files Browse the repository at this point in the history
Bug fixes to prevent crashes and other failures.
  • Loading branch information
haiqinli authored Oct 5, 2022
2 parents 558c35e + ac34369 commit 5b52582
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 77 deletions.
27 changes: 27 additions & 0 deletions physics/lsm_ruc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,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
!-- diagnostics for a land test point with known lat/lon
if (kdt < 10) then
Expand Down Expand Up @@ -1417,6 +1431,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(xlat_d(i),xlon_d(i), &
& delt, flag_init, lsm_cold_start, kdt, iter, nsoil, &
Expand Down
15 changes: 14 additions & 1 deletion physics/module_bl_mynn.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ SUBROUTINE mynn_bl_driver( &


IF ( mix_chem ) THEN
IF ( rrfs_sd ) THEN
CALL mynn_mix_chem(kts,kte,i, &
&delt, dz1, pblh(i), &
&nchem, kdvel, ndvel, &
Expand All @@ -1361,7 +1362,19 @@ SUBROUTINE mynn_bl_driver( &
&emis_ant_no(i), &
&frp(i), rrfs_sd, &
&enh_mix, smoke_dbg )

ELSE
CALL mynn_mix_chem(kts,kte,i, &
&delt, dz1, pblh(i), &
&nchem, kdvel, ndvel, &
&chem1, vd1, &
&rho1,flt, &
&tcd, qcd, &
&dfh, &
&s_aw1,s_awchem1, &
&zero, &
&zero, rrfs_sd, &
&enh_mix, smoke_dbg )
ENDIF
DO ic = 1,nchem
DO k = kts,kte
chem3d(i,k,ic) = max(1.e-12, chem1(k,ic))
Expand Down
9 changes: 0 additions & 9 deletions physics/module_sf_ruclsm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,6 @@ SUBROUTINE LSMRUC(xlat,xlon, &

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 (abs(xlat-testptlat).lt.0.2 .and. &
abs(xlon-testptlon).lt.0.2)then
Expand Down
12 changes: 5 additions & 7 deletions physics/smoke/module_add_emiss_burn.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module module_add_emiss_burn
use machine , only : kind_phys
use rrfs_smoke_config
CONTAINS
subroutine add_emis_burn(dtstep,ktau,dz8w,rho_phy,rel_hum, &
subroutine add_emis_burn(dtstep,dz8w,rho_phy,rel_hum, &
chem,julday,gmt,xlat,xlong, &
!luf_igbp,lu_fire1, &
vegtype,vfrac,peak_hr, &
Expand All @@ -24,7 +24,7 @@ subroutine add_emis_burn(dtstep,ktau,dz8w,rho_phy,rel_hum, &

! TYPE(grid_config_rec_type), INTENT(IN ) :: config_flags

INTEGER, INTENT(IN ) :: ktau, julday, &
INTEGER, INTENT(IN ) :: julday, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
Expand Down Expand Up @@ -172,21 +172,19 @@ subroutine add_emis_burn(dtstep,ktau,dz8w,rho_phy,rel_hum, &
chem(i,k,j,p_smoke) = chem(i,k,j,p_smoke) + dm_smoke
chem(i,k,j,p_smoke) = MIN(chem(i,k,j,p_smoke),5.e+3)

if (ktau<1000 .and. dbg_opt) then
! if ( k==kts ) then
! WRITE(6,*) 'add_emiss_burn: ktau,gmt,dtstep,time_int ',ktau,gmt,dtstep,time_int
! WRITE(6,*) 'add_emiss_burn: gmt,dtstep,time_int ',gmt,dtstep,time_int
! WRITE(*,*) 'add_emiss_burn: i,j,xlat(i,j),xlong(i,j) ',i,j,xlat(i,j),xlong(i,j)
!WRITE(*,*) 'add_emiss_burn: luf_igbp(i,:,j) ',luf_igbp(i,:,j)
!WRITE(*,*) 'add_emiss_burn: lu_fire1(i,j) ',lu_fire1(i,j)
! WRITE(6,*) 'add_emiss_burn: timeq,peak_hr(i,j),fhist(i,j),r_q(i,j) ',timeq,peak_hr(i,j),fhist(i,j),r_q(i,j)
! WRITE(*,*) 'add_emiss_burn: rainc(i,j),rainnc(i,j) ', rainc(i,j),rainnc(i,j)
! endif
if ( k==kts .OR. k==kfire_max ) then
if ( dbg_opt .and. (k==kts .OR. k==kfire_max) ) then
WRITE(6,*) 'add_emiss_burn: i,j,k ',i,j,k
WRITE(6,*) 'add_emiss_burn: rho_phy(i,k,j),dz8w(i,k,j),conv ',rho_phy(i,k,j),dz8w(i,k,j),conv
WRITE(6,*) 'add_emiss_burn: ebu(i,k,j),dm_smoke ', ebu(i,k,j),dm_smoke
endif
endif

enddo
enddo
Expand All @@ -208,7 +206,7 @@ subroutine add_emis_burn(dtstep,ktau,dz8w,rho_phy,rel_hum, &
enddo
enddo

IF ( ktau<2000 .and. dbg_opt ) then
IF ( dbg_opt ) then
WRITE(*,*) 'add_emis_burn: i,j,k,ext2 ',i,j,k,ext2
WRITE(*,*) 'add_emis_burn: rel_hum(its,kts,jts),rel_hum(ite,kfire_max,jte) ',rel_hum(its,kts,jts),rel_hum(ite,kfire_max,jte)
WRITE(*,*) 'add_emis_burn: ext3d_smoke(its,kts,jts),ext3d_smoke(ite,kfire_max,jte) ',ext3d_smoke(its,kts,jts),ext3d_smoke(ite,kfire_max,jte)
Expand Down
17 changes: 7 additions & 10 deletions physics/smoke/module_plumerise1.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module module_plumerise1
subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
t_phy,q_vap, & ! RAR: moist is replaced with q_vap
rho_phy,vvel,u_phy,v_phy,p_phy, &
z_at_w,z,ktau,g,con_cp,con_rd, & ! scale_fire_emiss is part of config_flags
z_at_w,z,g,con_cp,con_rd, & ! scale_fire_emiss is part of config_flags
plume_frp, k_min, k_max, & ! RAR:
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
Expand All @@ -56,8 +56,7 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
! TYPE(grid_config_rec_type), INTENT(IN ) :: config_flags
character(*), intent(inout) :: errmsg
integer, intent(inout) :: errflg
INTEGER, INTENT(IN ) :: ktau, &
ids,ide, jds,jde, kds,kde, &
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
! real(kind=kind_phys), DIMENSION( ims:ime, kms:kme, jms:jme, num_moist ), &
Expand Down Expand Up @@ -112,7 +111,7 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
cpor =con_cp/con_rd
con_rocp=con_rd/con_cp

IF ( dbg_opt .and. ktau<2000) then
IF ( dbg_opt ) then
WRITE(*,*) 'module_plumerise1: its,ite,jts,jte ', its,ite,jts,jte
WRITE(*,*) 'module_plumerise1: ims,ime,jms,jme ', ims,ime,jms,jme
!WRITE(*,*) 'module_plumerise1: p_ebu_smoke,num_ebu: ', p_ebu_smoke,num_ebu
Expand All @@ -133,7 +132,6 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &

! For now the flammable fraction is constant, based on the namelist. The next
! step to use LU index and meteorology to parameterize it
! IF (ktau==2) THEN
do j=jts,jte
do i=its,ite
flam_frac(i,j)= 0.
Expand All @@ -142,7 +140,6 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
end if
enddo
enddo
! ENDIF


! RAR: new FRP based approach
Expand Down Expand Up @@ -172,7 +169,7 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
!theta_in(k)= t_phy(i,k,j)/pi_in(k)*cp
enddo

IF (dbg_opt .and. ktau<2000) then
IF (dbg_opt) then
WRITE(*,*) 'module_plumerise1: i,j ',i,j
WRITE(*,*) 'module_plumerise1: plume_frp(i,j,:) ',plume_frp(i,j,:)
WRITE(*,*) 'module_plumerise1: ebu(i,kts,j) ',ebu(i,kts,j)
Expand All @@ -188,9 +185,9 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
u_in, v_in, w_in, theta_in ,pi_in, &
rho_phyin, qv_in, zmid, z_lev, &
plume_frp(i,j,1), k_min(i,j), &
k_max(i,j), ktau, dbg_opt, g, con_cp, &
k_max(i,j), dbg_opt, g, con_cp, &
con_rd, cpor, errmsg, errflg )
!k_max(i,j), ktau, config_flags%debug_chem )
!k_max(i,j), config_flags%debug_chem )
if(errflg/=0) return

kp1= k_min(i,j)
Expand All @@ -202,7 +199,7 @@ subroutine ebu_driver ( flam_frac,ebb_smoke,ebu, &
enddo
ebu(i,kts,j)= (1.-flam_frac(i,j))* ebb_smoke(i,j)

IF ( dbg_opt .and. ktau<2000) then
IF ( dbg_opt ) then
WRITE(*,*) 'module_plumerise1: i,j ',i,j
WRITE(*,*) 'module_plumerise1: k_min(i,j), k_max(i,j) ',k_min(i,j), k_max(i,j)
END IF
Expand Down
28 changes: 12 additions & 16 deletions physics/smoke/module_smoke_plumerise.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
! firesize,mean_fct, &
! nspecies,eburn_in,eburn_out, &
up,vp,wp,theta,pp,dn0,rv,zt_rams,zm_rams, &
frp_inst,k1,k2, ktau, dbg_opt, g, cp, rgas, &
frp_inst,k1,k2, dbg_opt, g, cp, rgas, &
cpor, errmsg, errflg )

implicit none
Expand All @@ -43,7 +43,6 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &

integer :: ng,m1,m2,m3,ia,iz,ja,jz,ibcon,mynum,i,j,k,imm,ixx,ispc !,nspecies

INTEGER, INTENT (IN) :: ktau
INTEGER, INTENT (OUT) :: k1,k2
character(*), intent(inout) :: errmsg
integer, intent(inout) :: errflg
Expand Down Expand Up @@ -103,9 +102,6 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
!----------------------------------------------------------------------
! print *,' Plumerise_scalar 1',ncall
coms => get_thread_coms()
if (ktau==2) then
call coms%set_to_zero()
endif

IF (frp_inst<frp_threshold) THEN
k1=1
Expand Down Expand Up @@ -142,7 +138,7 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
! enddo

!- get envinronmental state (temp, water vapor mix ratio, ...)
call get_env_condition(coms,1,m1,kmt,wind_eff,ktau,g,cp,rgas,cpor,errmsg,errflg)
call get_env_condition(coms,1,m1,kmt,wind_eff,g,cp,rgas,cpor,errmsg,errflg)
if(errflg/=0) return

!- loop over the four types of aggregate biomes with fires for plumerise version 1
Expand All @@ -162,15 +158,15 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
endif
burnt_area= max(1.0e4,burnt_area)

IF (dbg_opt .AND. ktau<2000) THEN
WRITE(*,*) 'plumerise: m1,ktau ', m1,ktau
IF (dbg_opt) THEN
WRITE(*,*) 'plumerise: m1 ', m1
WRITE(*,*) 'plumerise: imm, FRP,burnt_area ', imm, FRP,burnt_area
! WRITE(*,*) 'convert_smold_to_flam ',convert_smold_to_flam
WRITE(*,*) 'plumerise: zcon ', coms%zcon
WRITE(*,*) 'plumerise: zzcon ', coms%zzcon
END IF

IF (dbg_opt .AND. ktau<2000) then
IF (dbg_opt) then
WRITE(*,*) 'plumerise: imm ', imm
WRITE(*,*) 'plumerise: burnt_area ',burnt_area
END IF
Expand All @@ -182,7 +178,7 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
!------ generates the plume rise ------
call makeplume (coms,kmt,ztopmax(imm),ixx,imm)

IF (dbg_opt .AND. ktau<2000) then
IF (dbg_opt) then
WRITE(*,*) 'plumerise after makeplume: imm,kmt,ztopmax(imm) ',imm,kmt,ztopmax(imm)
END IF

Expand All @@ -191,9 +187,7 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
!- define o dominio vertical onde a emissao flaming ira ser colocada
call set_flam_vert(ztopmax,k1,k2,nkp,coms%zzcon) !,W_VMD,VMD)

! IF (ktau<2000) then
! WRITE(6,*) 'module_chem_plumerise_scalar: eburn_out(:,3) ', eburn_out(:,3)
! END IF

!- thickness of the vertical layer between k1 and k2 eta levels (lower and upper bounds for the injection height )
!dzi= 1./(coms%zzcon(k2)-coms%zzcon(k1)) ! RAR: k2>=k1+1
Expand All @@ -205,7 +199,7 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
! enddo
!enddo

IF (dbg_opt .AND. ktau<2000) then
IF (dbg_opt) then
WRITE(*,*) 'plumerise after set_flam_vert: nkp,k1,k2, ', nkp,k1,k2
WRITE(*,*) 'plumerise after set_flam_vert: dzi ', dzi
!WRITE(*,*) 'plumerise after set_flam_vert: eburn_in(2) ', eburn_in(2)
Expand All @@ -217,7 +211,7 @@ subroutine plumerise(m1,m2,m3,ia,iz,ja,jz, &
end subroutine plumerise
!-------------------------------------------------------------------------

subroutine get_env_condition(coms,k1,k2,kmt,wind_eff,ktau,g,cp,rgas,cpor,errmsg,errflg)
subroutine get_env_condition(coms,k1,k2,kmt,wind_eff,g,cp,rgas,cpor,errmsg,errflg)

!se module_zero_plumegen_coms
!use rconstants
Expand All @@ -229,11 +223,11 @@ subroutine get_env_condition(coms,k1,k2,kmt,wind_eff,ktau,g,cp,rgas,cpor,errmsg,
real(kind=kind_phys),parameter :: p00=p1000mb
real(kind=kind_phys) :: znz,themax,tlll,plll,rlll,zlll,dzdd,dzlll,tlcl,plcl,dzlcl,dummy
!integer :: n_setgrid = 0
integer :: wind_eff,ktau
integer :: wind_eff
character(*), intent(inout) :: errmsg
integer, intent(inout) :: errflg

if(ktau==2) then
if(.not.coms%initialized) then
! n_setgrid = 1
call set_grid(coms) ! define vertical grid of plume model
! coms%zt(k) = thermo and water levels
Expand Down Expand Up @@ -345,6 +339,8 @@ subroutine set_grid(coms)
coms%dzt(k) = 1. / (coms%zm(k) - coms%zm(k-1))
enddo
coms%dzt(1) = coms%dzt(2) * coms%dzt(2) / coms%dzt(3)

coms%initialized = .true.

! coms%dzm(1) = 0.5/coms%dz
! coms%dzm(2:mzp) = 1./coms%dz
Expand Down
24 changes: 8 additions & 16 deletions physics/smoke/module_zero_plumegen_coms.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module module_zero_plumegen_coms
integer, parameter :: nkp = 200, ntime = 200

type plumegen_coms
logical :: initialized = .false.

real(kind=kind_phys),dimension(nkp) :: w,t,qv,qc,qh,qi,sc, & ! blob
vth,vti,rho,txs, &
est,qsat! never used: ,qpas,qtotal
Expand Down Expand Up @@ -55,38 +57,28 @@ module module_zero_plumegen_coms
procedure :: set_to_zero => plumegen_coms_zero
end type plumegen_coms

interface plumegen_coms
procedure :: plumegen_coms_constructor
end interface plumegen_coms

type(plumegen_coms), private, target :: private_thread_coms
logical, private :: mzpc_initialized = .false.
type(plumegen_coms), private, pointer :: private_thread_coms

!$OMP THREADPRIVATE(private_thread_coms)
!$OMP THREADPRIVATE(mzpc_initialized)

contains

function get_thread_coms() result(coms)
implicit none
class(plumegen_coms), pointer :: coms
if(.not.mzpc_initialized) then
private_thread_coms = plumegen_coms()
mzpc_initialized = .true.
if(.not.associated(private_thread_coms)) then
allocate(private_thread_coms)
call plumegen_coms_zero(private_thread_coms)
endif
coms => private_thread_coms
end function get_thread_coms

type(plumegen_coms) function plumegen_coms_constructor() result(this)
implicit none
call plumegen_coms_zero(this)
this%testval=3314
end function plumegen_coms_constructor

subroutine plumegen_coms_zero(this)
implicit none
class(plumegen_coms) :: this

this%initialized = .false.

this%w=0.0
this%t=0.0
this%qv=0.0
Expand Down
Loading

0 comments on commit 5b52582

Please sign in to comment.