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

NEMSfv3gfs merge changes from VLAB master into CCPP integration code (08/14/2018) #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions physics/GFS_calpreciptype.f90
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ end subroutine GFS_calpreciptype_finalize
!! | snow0 | lwe_thickness_of_snow_amount_per_day | snow fall over 24h period | mm | 1 | real | kind_phys | in | F |
!! | graupel0 | lwe_thickness_of_graupel_amount_per_day | graupel fall over 24h period | mm | 1 | real | kind_phys | in | F |
!! | cplflx | flag_for_flux_coupling | flag controlling cplflx collection (default off) | flag | 0 | logical | | in | F |
!! | cplchm | flag_for_chemistry_coupling | flag controlling cplchm collection (default off) | flag | 0 | logical | | in | F |
!! | rain_cpl | lwe_thickness_of_precipitation_amount_for_coupling | total rain precipitation for model coupling | m | 1 | real | kind_phys | inout | F |
!! | rainc_cpl | lwe_thickness_of_convective_precipitation_amount_for_coupling | total convective precipitation | m | 1 | real | kind_phys | inout | F |
!! | snow_cpl | lwe_thickness_of_snow_amount_for_coupling | total snow precipitation for model coupling | m | 1 | real | kind_phys | inout | F |
!! | errmsg | ccpp_error_message | error message for error handling in CCPP | none | 0 | character | len=* | out | F |
!! | errflg | ccpp_error_flag | error flag for error handling in CCPP | flag | 0 | integer | | out | F |
Expand All @@ -91,7 +93,8 @@ subroutine GFS_calpreciptype_run(kdt,nrcm,im,ix,lm,lp1,randomno, &
totprcpb,toticeb,totsnwb,totgrpb, &
hrate,mrate,save_t,save_qv, &
rain0,ice0,snow0,graupel0, &
cplflx,rain_cpl,snow_cpl,errmsg,errflg)
cplflx,cplchm,rain_cpl,rainc_cpl, &
snow_cpl,errmsg,errflg)

!$$$ subprogram documentation block
! . . .
Expand Down Expand Up @@ -134,9 +137,9 @@ subroutine GFS_calpreciptype_run(kdt,nrcm,im,ix,lm,lp1,randomno, &
real(kind=kind_phys), dimension(ix,lm), intent(in) :: save_t,save_qv
! rain0, ice0, snow0, graupel0 only allocated if GFDL MP is selected (imp_physics == imp_physics_gfdl)
real(kind=kind_phys), dimension(:), intent(in) :: rain0,ice0,snow0,graupel0
logical, intent(in) :: cplflx
logical, intent(in) :: cplflx,cplchm
! rain_cpl, snow_cpl only allocated if cplflx == .true.
real(kind=kind_phys), dimension(:), intent(inout) :: rain_cpl,snow_cpl
real(kind=kind_phys), dimension(:), intent(inout) :: rain_cpl,rainc_cpl,snow_cpl
character(len=*), intent(out) :: errmsg
integer, intent(out) :: errflg

Expand Down Expand Up @@ -399,7 +402,8 @@ subroutine GFS_calpreciptype_run(kdt,nrcm,im,ix,lm,lp1,randomno, &
crain = 0.0
csnow = rainc(i)
endif
if ((snow0(i)+ice0(i)+graupel0(i)+csnow) > (rain0(i)+crain)) then
! if ((snow0(i)+ice0(i)+graupel0(i)+csnow) > (rain0(i)+crain)) then
if ((snow0(i)+ice0(i)+graupel0(i)+csnow) > 0.0) then
srflag(i) = 1. ! clu: set srflag to 'snow' (i.e. 1)
endif
enddo
Expand All @@ -425,6 +429,13 @@ subroutine GFS_calpreciptype_run(kdt,nrcm,im,ix,lm,lp1,randomno, &
enddo
endif

if ((cplchm).and.(.not.cplflx)) then
do i = 1, im
rain_cpl(i) = rain_cpl(i) + rain(i)
rainc_cpl(i) = rainc_cpl(i) + rainc(i)
enddo
endif

return
end subroutine GFS_calpreciptype_run
!
Expand Down
172 changes: 166 additions & 6 deletions physics/GFS_phys_time_vary.fv3.f90
Original file line number Diff line number Diff line change
@@ -1,20 +1,174 @@
!> \file GFS_phys_time_vary.f90
!! Contains code related to GFS physics suite setup (physics part of time_vary_step)

module GFS_phys_time_vary
module GFS_phys_time_vary

use ozne_def, only : levozp, oz_coeff, oz_lat, oz_pres, oz_time, ozplin
use ozinterp, only : read_o3data, setindxoz, ozinterpol

use h2o_def, only : levh2o, h2o_coeff, h2o_lat, h2o_pres, h2o_time, h2oplin
use h2ointerp, only : read_h2odata, setindxh2o, h2ointerpol

implicit none

private

public GFS_phys_time_vary_init, GFS_phys_time_vary_run, GFS_phys_time_vary_finalize

logical :: is_initialized = .false.

contains

subroutine GFS_phys_time_vary_init ()
!> \section arg_table_GFS_phys_time_vary_init Argument Table
!! | local_name | standard_name | long_name | units | rank | type | kind | intent | optional |
!! |----------------|--------------------------------------------------------|-------------------------------------------------------------------------|----------|------|-----------------------|-----------|--------|----------|
!! | Data | FV3-GFS_Data_type_all_blocks | Fortran DDT containing FV3-GFS data | DDT | 1 | GFS_data_type | | inout | F |
!! | Model | FV3-GFS_Control_type | Fortran DDT containing FV3-GFS model control parameters | DDT | 0 | GFS_control_type | | inout | F |
!! | Interstitial | FV3-GFS_Interstitial_type_all_threads | Fortran DDT containing FV3-GFS interstitial data | DDT | 1 | GFS_interstitial_type | | inout | F |
!! | errmsg | ccpp_error_message | error message for error handling in CCPP | none | 0 | character | len=* | out | F |
!! | errflg | ccpp_error_flag | error flag for error handling in CCPP | flag | 0 | integer | | out | F |
!!
subroutine GFS_phys_time_vary_init (Data, Model, Interstitial, errmsg, errflg)

use GFS_typedefs, only: GFS_control_type, GFS_data_type, GFS_interstitial_type

implicit none

! Interface variables
type(GFS_data_type), intent(inout) :: Data(:)
type(GFS_control_type), intent(inout) :: Model
type(GFS_interstitial_type), intent(inout) :: Interstitial(:)
character(len=*), intent(out) :: errmsg
integer, intent(out) :: errflg

! Local variables
integer :: nb, nblks, nt, nthrds

! Initialize CCPP error handling variables
errmsg = ''
errflg = 0

if (is_initialized) return

nblks = size(Model%blksz)
nthrds = size(Interstitial)

call read_o3data (Model%ntoz, Model%me, Model%master)

! Consistency check that the hardcoded values for levozp and
! oz_coeff in GFS_typedefs.F90 match what is set by read_o3data
! in GFS_typedefs.F90: allocate (Tbd%ozpl (IM,levozp,oz_coeff))
if (size(Data(1)%Tbd%ozpl, dim=2).ne.levozp) then
write(errmsg,'(2a,i0,a,i0)') "Value error in GFS_phys_time_vary_init: ", &
"levozp from read_o3data does not match value in GFS_typedefs.F90: ", &
levozp, " /= ", size(Data(1)%Tbd%ozpl, dim=2)
errflg = 1
return
end if
if (size(Data(1)%Tbd%ozpl, dim=3).ne.oz_coeff) then
write(errmsg,'(2a,i0,a,i0)') "Value error in GFS_phys_time_vary_init: ", &
"oz_coeff from read_o3data does not match value in GFS_typedefs.F90: ", &
oz_coeff, " /= ", size(Data(1)%Tbd%ozpl, dim=3)
errflg = 1
return
end if

call read_h2odata (Model%h2o_phys, Model%me, Model%master)

! Consistency check that the hardcoded values for levh2o and
! h2o_coeff in GFS_typedefs.F90 match what is set by read_o3data
! in GFS_typedefs.F90: allocate (Tbd%h2opl (IM,levh2o,h2o_coeff))
if (size(Data(1)%Tbd%h2opl, dim=2).ne.levh2o) then
write(errmsg,'(2a,i0,a,i0)') "Value error in GFS_phys_time_vary_init: ", &
"levh2o from read_h2odata does not match value in GFS_typedefs.F90: ", &
levh2o, " /= ", size(Data(1)%Tbd%h2opl, dim=2)
errflg = 1
return
end if
if (size(Data(1)%Tbd%h2opl, dim=3).ne.h2o_coeff) then
write(errmsg,'(2a,i0,a,i0)') "Value error in GFS_phys_time_vary_init: ", &
"h2o_coeff from read_h2odata does not match value in GFS_typedefs.F90: ", &
h2o_coeff, " /= ", size(Data(1)%Tbd%h2opl, dim=3)
errflg = 1
return
end if

! DH* OpenMP parallel region with OpenMP do loops for the three do loops?
! there is no threading on the outside, i.e. can use CCPP's omp_threads here

! Update values of oz_pres in Interstitial data type for all threads
if (Model%ntoz > 0) then
do nt=1,nthrds
Interstitial(nt)%oz_pres = oz_pres
end do
end if

! Update values of h2o_pres in Interstitial data type for all threads
if (Model%h2o_phys) then
do nt=1,nthrds
Interstitial(nt)%h2o_pres = h2o_pres
end do
end if

!--- read in and initialize ozone and water
if (Model%ntoz > 0) then
do nb = 1, nblks
call setindxoz (Model%blksz(nb), Data(nb)%Grid%xlat_d, Data(nb)%Grid%jindx1_o3, &
Data(nb)%Grid%jindx2_o3, Data(nb)%Grid%ddy_o3)
enddo
endif

if (Model%h2o_phys) then
do nb = 1, nblks
call setindxh2o (Model%blksz(nb), Data(nb)%Grid%xlat_d, Data(nb)%Grid%jindx1_h, &
Data(nb)%Grid%jindx2_h, Data(nb)%Grid%ddy_h)
enddo
endif

! *DH

is_initialized = .true.

end subroutine GFS_phys_time_vary_init

subroutine GFS_phys_time_vary_finalize()

!> \section arg_table_GFS_phys_time_vary_finalize Argument Table
!! | local_name | standard_name | long_name | units | rank | type | kind | intent | optional |
!! |----------------|--------------------------------------------------------|-------------------------------------------------------------------------|----------|------|-----------------------|-----------|--------|----------|
!! | errmsg | ccpp_error_message | error message for error handling in CCPP | none | 0 | character | len=* | out | F |
!! | errflg | ccpp_error_flag | error flag for error handling in CCPP | flag | 0 | integer | | out | F |
!!
subroutine GFS_phys_time_vary_finalize(errmsg, errflg)

implicit none

! Interface variables
character(len=*), intent(out) :: errmsg
integer, intent(out) :: errflg

! Initialize CCPP error handling variables
errmsg = ''
errflg = 0

if (.not.is_initialized) return

! Deallocate ozone arrays
if (allocated(oz_lat) ) deallocate(oz_lat)
if (allocated(oz_pres) ) deallocate(oz_pres)
if (allocated(oz_time) ) deallocate(oz_time)
if (allocated(ozplin) ) deallocate(ozplin)

! Deallocate h2o arrays
if (allocated(h2o_lat) ) deallocate(h2o_lat)
if (allocated(h2o_pres)) deallocate(h2o_pres)
if (allocated(h2o_time)) deallocate(h2o_time)
if (allocated(h2oplin) ) deallocate(h2oplin)

is_initialized = .false.

end subroutine GFS_phys_time_vary_finalize


!> \section arg_table_GFS_phys_time_vary_run Argument Table
!! | local_name | standard_name | long_name | units | rank | type | kind | intent | optional |
!! |----------------|--------------------------------------------------------|-------------------------------------------------------------------------|----------|------|-----------------------|-----------|--------|----------|
Expand All @@ -25,9 +179,8 @@ end subroutine GFS_phys_time_vary_finalize
!!
subroutine GFS_phys_time_vary_run (Data, Model, errmsg, errflg)

use mersenne_twister, only: random_setseed, random_number
use mersenne_twister, only: random_setseed, random_number
use machine, only: kind_phys
use physcons, only: dxmin, dxinv
use GFS_typedefs, only: GFS_control_type, GFS_data_type

implicit none
Expand All @@ -52,6 +205,13 @@ subroutine GFS_phys_time_vary_run (Data, Model, errmsg, errflg)
errmsg = ''
errflg = 0

! Check initialization status
if (.not.is_initialized) then
write(errmsg,'(*(a))') "Logic error: GFS_phys_time_vary_run called before GFS_phys_time_vary_init"
errflg = 1
return
end if

nblks = size(Model%blksz)

!--- switch for saving convective clouds - cnvc90.f
Expand Down Expand Up @@ -141,4 +301,4 @@ subroutine GFS_phys_time_vary_run (Data, Model, errmsg, errflg)

end subroutine GFS_phys_time_vary_run

end module GFS_phys_time_vary
end module GFS_phys_time_vary
11 changes: 10 additions & 1 deletion physics/GFS_stochastics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ end subroutine GFS_stochastics_finalize
!! | tprcp | nonnegative_lwe_thickness_of_precipitation_amount_on_dynamics_timestep | total precipitation amount in each time step | m | 1 | real | kind_phys | inout | F |
!! | totprcp | accumulated_lwe_thickness_of_precipitation_amount | accumulated total precipitation | m | 1 | real | kind_phys | inout | F |
!! | cnvprcp | cumulative_lwe_thickness_of_convective_precipitation_amount | cumulative convective precipitation | m | 1 | real | kind_phys | inout | F |
!! | totprcpb | accumulated_lwe_thickness_of_precipitation_amount_in_bucket | accumulated total precipitation in bucket | m | 1 | real | kind_phys | inout | F |
!! | cnvprcpb | cumulative_lwe_thickness_of_convective_precipitation_amount_in_bucket | cumulative convective precipitation in bucket | m | 1 | real | kind_phys | inout | F |
!! | cplflx | flag_for_flux_coupling | flag controlling cplflx collection (default off) | flag | 0 | logical | | in | F |
!! | rain_cpl | lwe_thickness_of_precipitation_amount_for_coupling | total rain precipitation | m | 1 | real | kind_phys | inout | F |
!! | snow_cpl | lwe_thickness_of_snow_amount_for_coupling | total snow precipitation | m | 1 | real | kind_phys | inout | F |
Expand All @@ -68,7 +70,8 @@ subroutine GFS_stochastics_run (im, km, do_sppt, use_zmtnblck, do_shum, do_skeb,
shum_wts_inv, diss_est, &
ugrs, vgrs, tgrs, qgrs, gu0, gv0, gt0, gq0, dtdtr, &
rain, rainc, tprcp, totprcp, cnvprcp, &
cplflx, rain_cpl, snow_cpl, drain_cpl, dsnow_cpl, &
totprcpb, cnvprcpb, cplflx, &
rain_cpl, snow_cpl, drain_cpl, dsnow_cpl, &
errmsg, errflg)

use machine, only: kind_phys
Expand Down Expand Up @@ -110,6 +113,8 @@ subroutine GFS_stochastics_run (im, km, do_sppt, use_zmtnblck, do_shum, do_skeb,
real(kind_phys), dimension(1:im), intent(inout) :: tprcp
real(kind_phys), dimension(1:im), intent(inout) :: totprcp
real(kind_phys), dimension(1:im), intent(inout) :: cnvprcp
real(kind_phys), dimension(1:im), intent(inout) :: totprcpb
real(kind_phys), dimension(1:im), intent(inout) :: cnvprcpb
logical, intent(in) :: cplflx
! rain_cpl, snow_cpl only allocated if cplflx == .true. or do_sppt == .true.
real(kind_phys), dimension(:), intent(inout) :: rain_cpl
Expand Down Expand Up @@ -174,6 +179,10 @@ subroutine GFS_stochastics_run (im, km, do_sppt, use_zmtnblck, do_shum, do_skeb,
totprcp(:) = totprcp(:) + (sppt_wts(:,15) - 1 )*rain(:)
! acccumulated total and convective preciptiation
cnvprcp(:) = cnvprcp(:) + (sppt_wts(:,15) - 1 )*rainc(:)
! bucket precipitation adjustment due to sppt
totprcpb(:) = totprcpb(:) + (sppt_wts(:,15) - 1 )*rain(:)
cnvprcpb(:) = cnvprcpb(:) + (sppt_wts(:,15) - 1 )*rainc(:)

if (cplflx) then
rain_cpl(:) = rain_cpl(:) + (sppt_wts(:,15) - 1.0)*drain_cpl(:)
snow_cpl(:) = snow_cpl(:) + (sppt_wts(:,15) - 1.0)*dsnow_cpl(:)
Expand Down
Loading