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 FA table initialization issue in the nest domain #450

Merged
merged 2 commits into from
May 20, 2020
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
148 changes: 105 additions & 43 deletions physics/module_MP_FER_HIRES.F90
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ MODULE MODULE_MP_FER_HIRES
INTEGER, PRIVATE,PARAMETER :: MY_T1=1, MY_T2=35
REAL,PRIVATE,DIMENSION(MY_T1:MY_T2),SAVE :: MY_GROWTH_NMM
!
REAL, PRIVATE,PARAMETER :: DMImin=.05e-3, DMImax=1.e-3, &
REAL, PRIVATE,PARAMETER :: DMImin=.05e-3, DMImax=1.e-3, &
& DelDMI=1.e-6,XMImin=1.e6*DMImin
REAL, PUBLIC,PARAMETER :: XMImax=1.e6*DMImax, XMIexp=.0536
INTEGER, PUBLIC,PARAMETER :: MDImin=XMImin, MDImax=XMImax
REAL, PRIVATE,DIMENSION(MDImin:MDImax) :: &
REAL, ALLOCATABLE, DIMENSION(:) :: &
& ACCRI,VSNOWI,VENTI1,VENTI2
REAL, PUBLIC,DIMENSION(MDImin:MDImax) :: SDENS !-- For RRTM
!
REAL, PRIVATE,PARAMETER :: DMRmin=.05e-3, DMRmax=1.0e-3, &
REAL, PRIVATE,PARAMETER :: DMRmin=.05e-3, DMRmax=1.0e-3, &
& DelDMR=1.e-6, XMRmin=1.e6*DMRmin, XMRmax=1.e6*DMRmax
INTEGER, PUBLIC,PARAMETER :: MDRmin=XMRmin, MDRmax=XMRmax
!
REAL, PRIVATE,DIMENSION(MDRmin:MDRmax):: &
REAL, ALLOCATABLE, DIMENSION(:):: &
& ACCRR,MASSR,RRATE,VRAIN,VENTR1,VENTR2
!
INTEGER, PRIVATE,PARAMETER :: Nrime=40
REAL, DIMENSION(2:9,0:Nrime),PRIVATE,SAVE :: VEL_RF
REAL, ALLOCATABLE, DIMENSION(:,:) :: VEL_RF
!
INTEGER,PARAMETER :: NX=7501
REAL, PARAMETER :: XMIN=180.0,XMAX=330.0
Expand Down Expand Up @@ -226,7 +226,7 @@ MODULE MODULE_MP_FER_HIRES
!HWRF & ,NCW=300.E6 !- 100.e6 (maritime), 500.e6 (continental)

!--- Other public variables passed to other routines:
REAL, PUBLIC,DIMENSION(MDImin:MDImax) :: MASSI
REAL, ALLOCATABLE ,DIMENSION(:) :: MASSI
!

CONTAINS
Expand Down Expand Up @@ -449,8 +449,9 @@ SUBROUTINE FER_HIRES (DT,RHgrd, &
!GFDL => New. Added RHC_col to allow for height- and grid-dependent values for
!GFDL the relative humidity threshold for condensation ("RHgrd")
!6/11/2010 mod - Use lower RHgrd_out threshold for < 850 hPa
!mz 05/06/2020 - 10km
!------------------------------------------------------------
IF(DX1 .GE. 10 .AND. P_col(L)<P_RHgrd_out) THEN ! gopal's doing based on GFDL
IF(DX1 .GE. 10000 .AND. P_col(L)<P_RHgrd_out) THEN ! gopal's doing based on GFDL
RHC_col(L)=RHgrd
ELSE
RHC_col(L)=RHgrd_in
Expand Down Expand Up @@ -2445,6 +2446,9 @@ SUBROUTINE FERRIER_INIT_hr (GSMDT,MPI_COMM_COMP,MYPE,mpiroot,THREADS, &
!
!-----------------------------------------------------------------------
!
#ifdef MPI
use mpi
#endif
IMPLICIT NONE
!
!-------------------------------------------------------------------------
Expand Down Expand Up @@ -2473,11 +2477,16 @@ SUBROUTINE FERRIER_INIT_hr (GSMDT,MPI_COMM_COMP,MYPE,mpiroot,THREADS, &
INTEGER :: I,J,L,K
INTEGER :: etampnew_unit1
LOGICAL :: opened
INTEGER :: IRTN,rc !MYPE,mpi_comm_comp
INTEGER :: IRTN,rc
CHARACTER*80 errmess
INTEGER :: mpi_communicator,ierr
INTEGER :: good
LOGICAL :: lexist,lopen, force_read_ferhires
!
!-----------------------------------------------------------------------
!
! Assign mpicomm to module variable
mpi_communicator= mpi_comm_comp
DTPH=GSMDT !-- Time step in s
!
!--- Create lookup tables for saturation vapor pressure w/r/t water & ice
Expand All @@ -2486,44 +2495,77 @@ SUBROUTINE FERRIER_INIT_hr (GSMDT,MPI_COMM_COMP,MYPE,mpiroot,THREADS, &
!
CALL GPVS_hr
!
!--- Read in various lookup tables
!
IF(MYPE==0)THEN
etampnew_unit1 = -1
DO i = 31,99
INQUIRE ( i , OPENED = opened )
IF ( .NOT. opened ) THEN
etampnew_unit1 = i
EXIT
!zhang:
if (.NOT. ALLOCATED(ventr1)) ALLOCATE(ventr1(MDRmin:MDRmax))
if (.NOT. ALLOCATED(ventr2)) ALLOCATE(ventr2(MDRmin:MDRmax))
if (.NOT. ALLOCATED(accrr)) ALLOCATE(accrr(MDRmin:MDRmax))
if (.NOT. ALLOCATED(massr)) ALLOCATE(massr(MDRmin:MDRmax))
if (.NOT. ALLOCATED(vrain)) ALLOCATE(vrain(MDRmin:MDRmax))
if (.NOT. ALLOCATED(rrate)) ALLOCATE(rrate(MDRmin:MDRmax))
if (.NOT. ALLOCATED(venti1)) ALLOCATE(venti1(MDImin:MDImax))
if (.NOT. ALLOCATED(venti2)) ALLOCATE(venti2(MDImin:MDImax))
if (.NOT. ALLOCATED(accri)) ALLOCATE(accri(MDImin:MDImax))
if (.NOT. ALLOCATED(massi)) ALLOCATE(massi(MDImin:MDImax))
if (.NOT. ALLOCATED(vsnowi)) ALLOCATE(vsnowi(MDImin:MDImax))
if (.NOT. ALLOCATED(vel_rf)) ALLOCATE(vel_rf(2:9,0:Nrime))



force_read_ferhires = .true.
good = 0
INQUIRE(FILE="DETAMPNEW_DATA.expanded_rain_LE",EXIST=lexist)

#ifdef MPI
call MPI_BARRIER(mpi_communicator,ierr)
#endif

IF (lexist) THEN
OPEN(63,FILE="DETAMPNEW_DATA.expanded_rain_LE", &
& FORM="UNFORMATTED",STATUS="OLD",ERR=1234)
!
!sms$serial begin
READ(63, err=1234) VENTR1
READ(63, err=1234) VENTR2
READ(63, err=1234) ACCRR
READ(63, err=1234) MASSR
READ(63, err=1234) VRAIN
READ(63, err=1234) RRATE
READ(63, err=1234) VENTI1
READ(63, err=1234) VENTI2
READ(63, err=1234) ACCRI
READ(63, err=1234) MASSI
READ(63, err=1234) VSNOWI
READ(63, err=1234) VEL_RF
!sms$serial end
good = 1
1234 CONTINUE
IF ( good .NE. 1 ) THEN
INQUIRE(63,opened=lopen)
IF (lopen) THEN
IF( force_read_ferhires ) THEN
write(0,*) "Error reading DETAMPNEW_DATA.expanded_rain_LE. Aborting because force_read_ferhires is .true."
return
ENDIF
CLOSE(63)
ELSE
IF( force_read_ferhires ) THEN
write(0,*) "Error opening DETAMPNEW_DATA.expanded_rain_LE. Aborting because force_read_ferhires is .true."
return
ENDIF
ENDIF
ELSE
INQUIRE(63,opened=lopen)
IF (lopen) THEN
CLOSE(63)
ENDIF
ENDDO
IF (etampnew_unit1<0) THEN
errmsg = 'FERRIER_INIT_hr: Can not find unused fortran &
&unit to read in lookup tables'
errmsg = trim(errmsg)//NEW_LINE('A')//' ABORTING!'
errflg = 1
RETURN
ENDIF
ELSE
IF( force_read_ferhires ) THEN
write(0,*) "Non-existent DETAMPNEW_DATA.expanded_rain_LE. Aborting because force_read_ferhires is .true."
return
ENDIF
ENDIF
!
IF(MYPE==0)THEN
OPEN(UNIT=etampnew_unit1,FILE="DETAMPNEW_DATA.expanded_rain_LE", &
& FORM="UNFORMATTED",STATUS="OLD",ERR=9061)
!
READ(etampnew_unit1) VENTR1
READ(etampnew_unit1) VENTR2
READ(etampnew_unit1) ACCRR
READ(etampnew_unit1) MASSR
READ(etampnew_unit1) VRAIN
READ(etampnew_unit1) RRATE
READ(etampnew_unit1) VENTI1
READ(etampnew_unit1) VENTI2
READ(etampnew_unit1) ACCRI
READ(etampnew_unit1) MASSI
READ(etampnew_unit1) VSNOWI
READ(etampnew_unit1) VEL_RF
CLOSE (etampnew_unit1)
ENDIF

!
#ifdef MPI
CALL MPI_BCAST(VENTR1,SIZE(VENTR1),MPI_DOUBLE_PRECISION,0,MPI_COMM_COMP,IRTN)
Expand All @@ -2539,6 +2581,7 @@ SUBROUTINE FERRIER_INIT_hr (GSMDT,MPI_COMM_COMP,MYPE,mpiroot,THREADS, &
CALL MPI_BCAST(VSNOWI,SIZE(VSNOWI),MPI_DOUBLE_PRECISION,0,MPI_COMM_COMP,IRTN)
CALL MPI_BCAST(VEL_RF,SIZE(VEL_RF),MPI_DOUBLE_PRECISION,0,MPI_COMM_COMP,IRTN)
#endif

!
!--- Calculates coefficients for growth rates of ice nucleated in water
! saturated conditions, scaled by physics time step (lookup table)
Expand Down Expand Up @@ -2934,5 +2977,24 @@ REAL FUNCTION FPVSX0(T)
!
END FUNCTION FPVSX0

SUBROUTINE ferhires_finalize()

IMPLICIT NONE

if (ALLOCATED(ventr1)) DEALLOCATE(ventr1)
if (ALLOCATED(ventr2)) DEALLOCATE(ventr2)
if (ALLOCATED(accrr)) DEALLOCATE(accrr)
if (ALLOCATED(massr)) DEALLOCATE(massr)
if (ALLOCATED(vrain)) DEALLOCATE(vrain)
if (ALLOCATED(rrate)) DEALLOCATE(rrate)
if (ALLOCATED(venti1)) DEALLOCATE(venti1)
if (ALLOCATED(venti2)) DEALLOCATE(venti2)
if (ALLOCATED(accri)) DEALLOCATE(accri)
if (ALLOCATED(massi)) DEALLOCATE(massi)
if (ALLOCATED(vsnowi)) DEALLOCATE(vsnowi)
if (ALLOCATED(vel_rf)) DEALLOCATE(vel_rf)

END SUBROUTINE ferhires_finalize

!
END MODULE module_mp_fer_hires
28 changes: 22 additions & 6 deletions physics/mp_fer_hires.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module mp_fer_hires

use machine, only : kind_phys

use module_mp_fer_hires, only : ferrier_init_hr, FER_HIRES
use module_mp_fer_hires, only : ferrier_init_hr, FER_HIRES, &
ferhires_finalize

implicit none

Expand Down Expand Up @@ -91,18 +92,17 @@ subroutine mp_fer_hires_init(ncol, nlev, dtp, imp_physics, &
end if

!MZ: fer_hires_init() in HWRF
IF(.NOT.RESTART .AND. present(F_ICE)) THEN !HWRF
write(errmsg,'(*(a))') " WARNING: F_ICE,F_RAIN AND F_RIMEF IS REINITIALIZED "
if (mpirank==mpiroot) write (0,*) 'F-A: F_ICE,F_RAIN AND F_RIMEF IS REINITIALIZED'
DO K = 1,lm
DO I= ims,ime
F_ICE(i,k)=0.
F_RAIN(i,k)=0.
F_RIMEF(i,k)=1.
ENDDO
ENDDO
ENDIF
!MZ: fer_hires_init() in HWRF


if (mpirank==mpiroot) write (0,*) 'F-A: calling FERRIER_INIT_HR ...'
CALL FERRIER_INIT_HR(dtp,mpicomm,mpirank,mpiroot,threads,errmsg,errflg)

if (mpirank==mpiroot) write (0,*)'F-A: FERRIER_INIT_HR finished ...'
Expand Down Expand Up @@ -358,7 +358,23 @@ end subroutine mp_fer_hires_run

!> \section arg_table_mp_fer_hires_finalize Argument Table
!!
subroutine mp_fer_hires_finalize ()
subroutine mp_fer_hires_finalize (errmsg,errflg)
implicit none

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

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

if (.not.is_initialized) return

call ferhires_finalize()

is_initialized = .false.


end subroutine mp_fer_hires_finalize

end module mp_fer_hires
18 changes: 18 additions & 0 deletions physics/mp_fer_hires.meta
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@
[ccpp-arg-table]
name = mp_fer_hires_finalize
type = scheme

[errmsg]
standard_name = ccpp_error_message
long_name = error message for error handling in CCPP
units = none
dimensions = ()
type = character
kind = len=*
intent = out
optional = F
[errflg]
standard_name = ccpp_error_flag
long_name = error flag for error handling in CCPP
units = flag
dimensions = ()
type = integer
intent = out
optional = F
########################################################################
[ccpp-arg-table]
name = mp_fer_hires_run
Expand Down