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

Fix uninitialized min_rand variable in Thompson MP when using SPP #892

Merged
merged 11 commits into from
Apr 20, 2022
Merged
28 changes: 21 additions & 7 deletions physics/module_mp_thompson.F90
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ SUBROUTINE mp_gt_driver(qv, qc, qr, qi, qs, qg, ni, nr, nc, &
has_reqc, has_reqi, has_reqs, &
rand_perturb_on, &
kme_stoch, &
rand_pert, &
rand_pert, spp_prt_list, spp_var_list, &
spp_stddev_cutoff, n_var_spp, &
ids,ide, jds,jde, kds,kde, & ! domain dims
ims,ime, jms,jme, kms,kme, & ! memory dims
its,ite, jts,jte, kts,kte, & ! tile dims
Expand Down Expand Up @@ -1025,10 +1026,10 @@ SUBROUTINE mp_gt_driver(qv, qc, qr, qi, qs, qg, ni, nr, nc, &
REAL, DIMENSION(ims:ime, jms:jme), OPTIONAL, INTENT(IN):: nwfa2d, nifa2d
REAL, DIMENSION(ims:ime, kms:kme, jms:jme), OPTIONAL, INTENT(INOUT):: &
re_cloud, re_ice, re_snow
INTEGER, INTENT(IN) :: rand_perturb_on, kme_stoch
REAL, DIMENSION(:,:), INTENT(IN) :: &
rand_pert

INTEGER, INTENT(IN) :: rand_perturb_on, kme_stoch, n_var_spp
REAL, DIMENSION(:,:), INTENT(IN) :: rand_pert
REAL, DIMENSION(:), INTENT(IN) :: spp_prt_list, spp_stddev_cutoff
CHARACTER(len=3), DIMENSION(:), INTENT(IN) :: spp_var_list
INTEGER, INTENT(IN):: has_reqc, has_reqi, has_reqs
#if ( WRF_CHEM == 1 )
REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT):: &
Expand Down Expand Up @@ -1101,7 +1102,7 @@ SUBROUTINE mp_gt_driver(qv, qc, qr, qi, qs, qg, ni, nr, nc, &
REAL, DIMENSION(its:ite, jts:jte):: pcp_ra, pcp_sn, pcp_gr, pcp_ic
REAL:: dt, pptrain, pptsnow, pptgraul, pptice
REAL:: qc_max, qr_max, qs_max, qi_max, qg_max, ni_max, nr_max
REAL:: rand1, rand2, rand3, min_rand
REAL:: rand1, rand2, rand3, rand_pert_max
INTEGER:: i, j, k, m
INTEGER:: imax_qc,imax_qr,imax_qi,imax_qs,imax_qg,imax_ni,imax_nr
INTEGER:: jmax_qc,jmax_qr,jmax_qi,jmax_qs,jmax_qg,jmax_ni,jmax_nr
Expand Down Expand Up @@ -1233,10 +1234,23 @@ SUBROUTINE mp_gt_driver(qv, qc, qr, qi, qs, qg, ni, nr, nc, &
pcp_sn(:,:) = 0.0
pcp_gr(:,:) = 0.0
pcp_ic(:,:) = 0.0
rand_pert_max = 0.0
ndt = max(nint(dt_in/dt_inner),1)
dt = dt_in/ndt
if(dt_in .le. dt_inner) dt= dt_in

!Get the Thompson MP SPP magnitude and standard deviation cutoff,
!then compute rand_pert_max

if (rand_perturb_on .ne. 0) then
do k =1,n_var_spp
select case (spp_var_list(k))
case('mp')
rand_pert_max = spp_prt_list(k)*spp_stddev_cutoff(k)
end select
enddo
endif

do it = 1, ndt

qc_max = 0.
Expand Down Expand Up @@ -1292,7 +1306,7 @@ SUBROUTINE mp_gt_driver(qv, qc, qr, qi, qs, qg, ni, nr, nc, &
m = RSHIFT(ABS(rand_perturb_on),1)
if (MOD(m,2) .ne. 0) rand2 = rand_pert(i,1)*2.
m = RSHIFT(ABS(rand_perturb_on),2)
if (MOD(m,2) .ne. 0) rand3 = 0.25*(rand_pert(i,1)+ABS(min_rand))
if (MOD(m,2) .ne. 0) rand3 = 0.25*(rand_pert(i,1)+rand_pert_max)
m = RSHIFT(ABS(rand_perturb_on),3)
endif
!+---+-----------------------------------------------------------------+
Expand Down
16 changes: 13 additions & 3 deletions physics/mp_thompson.F90
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ subroutine mp_thompson_run(ncol, nlev, con_g, con_rd, &
refl_10cm, reset_dBZ, do_radar_ref, &
mpicomm, mpirank, mpiroot, blkno, &
ext_diag, diag3d, reset_diag3d, &
spp_wts_mp, spp_mp, &
spp_wts_mp, spp_mp, n_var_spp, &
spp_prt_list, spp_var_list, &
spp_stddev_cutoff, &
errmsg, errflg)

implicit none
Expand Down Expand Up @@ -376,7 +378,11 @@ subroutine mp_thompson_run(ncol, nlev, con_g, con_rd, &

! SPP
integer, intent(in) :: spp_mp
integer, intent(in) :: n_var_spp
real(kind_phys), intent(in) :: spp_wts_mp(:,:)
real(kind_phys), intent(in) :: spp_prt_list(:)
character(len=3), intent(in) :: spp_var_list(:)
real(kind_phys), intent(in) :: spp_stddev_cutoff(:)

! Local variables

Expand Down Expand Up @@ -644,7 +650,9 @@ subroutine mp_thompson_run(ncol, nlev, con_g, con_rd, &
diagflag=diagflag, do_radar_ref=do_radar_ref_mp, &
has_reqc=has_reqc, has_reqi=has_reqi, has_reqs=has_reqs, &
rand_perturb_on=spp_mp_opt, kme_stoch=kme_stoch, &
rand_pert=spp_wts_mp, &
rand_pert=spp_wts_mp, spp_var_list=spp_var_list, &
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is sorta stupid request, but couldn't the new added arguments be listed in the same order in this block as in the block 40 lines lower? Just think it makes it easier. The order of arguments differs a little.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can make that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

spp_prt_list=spp_prt_list, n_var_spp=n_var_spp, &
spp_stddev_cutoff=spp_stddev_cutoff, &
ids=ids, ide=ide, jds=jds, jde=jde, kds=kds, kde=kde, &
ims=ims, ime=ime, jms=jms, jme=jme, kms=kms, kme=kme, &
its=its, ite=ite, jts=jts, jte=jte, kts=kts, kte=kte, &
Expand Down Expand Up @@ -681,7 +689,9 @@ subroutine mp_thompson_run(ncol, nlev, con_g, con_rd, &
diagflag=diagflag, do_radar_ref=do_radar_ref_mp, &
has_reqc=has_reqc, has_reqi=has_reqi, has_reqs=has_reqs, &
rand_perturb_on=spp_mp_opt, kme_stoch=kme_stoch, &
rand_pert=spp_wts_mp, &
rand_pert=spp_wts_mp, spp_var_list=spp_var_list, &
spp_prt_list=spp_prt_list, n_var_spp=n_var_spp, &
spp_stddev_cutoff=spp_stddev_cutoff, &
ids=ids, ide=ide, jds=jds, jde=jde, kds=kds, kde=kde, &
ims=ims, ime=ime, jms=jms, jme=jme, kms=kms, kme=kme, &
its=its, ite=ite, jts=jts, jte=jte, kts=kts, kte=kte, &
Expand Down
32 changes: 31 additions & 1 deletion physics/mp_thompson.meta
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@
units = 1
dimensions = (horizontal_loop_extent,vertical_layer_dimension)
type = real
kind = kind_phys
intent = in
[spp_mp]
standard_name = control_for_microphysics_spp_perturbations
Expand All @@ -653,6 +652,37 @@
dimensions = ()
type = integer
intent = in
[n_var_spp]
standard_name = number_of_perturbed_spp_schemes
long_name = number of perturbed spp schemes
units = count
dimensions = ()
type = integer
intent = in
[spp_prt_list]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clearly I am still being thick, but I don't see how the name "prt_list" gives me any clue of a magnitude of spp perturbation.

Copy link
Contributor Author

@JeffBeck-NOAA JeffBeck-NOAA Apr 8, 2022

Choose a reason for hiding this comment

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

Yes, it could be better named. We followed the same naming convention for SPP as what was already in place for the land perturbation scheme in stochastic_physics. For that scheme, "lndp_prt_list" is used for the perturbation array. At some point, changing to something like *_mag_list would be more descriptive.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could use a different name in mp_thompson than GFS_Typedefs so the variable will make sense in both contexts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since spp_prt_list is used across multiple physics suites and UFS submodules, I'd prefer keeping the name the same everywhere. We can certainly address this in a future PR, though.

standard_name = magnitude_of_spp_perturbations
long_name = magnitude of spp perturbations
units = 1
dimensions = (number_of_perturbed_spp_schemes)
type = real
kind = kind_phys
intent = in
[spp_stddev_cutoff]
standard_name = magnitude_of_spp_standard_deviation_cutoff
long_name = magnitude of spp standard deviation cutoff
units = 1
dimensions = (number_of_perturbed_spp_schemes)
type = real
kind = kind_phys
intent = in
[spp_var_list]
standard_name = perturbed_spp_schemes
long_name = perturbed spp schemes
units = none
dimensions = (number_of_perturbed_spp_schemes)
type = character
kind = len=3
intent = in
[errmsg]
standard_name = ccpp_error_message
long_name = error message for error handling in CCPP
Expand Down