Skip to content

Commit

Permalink
Merge pull request #16 from ESMCI/mvertens/restart_cime5.6.8
Browse files Browse the repository at this point in the history
add restart capability and cleanup
  • Loading branch information
rsdunlapiv authored Jul 25, 2018
2 parents 6a8173d + ff69720 commit 842ea6a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 8 deletions.
36 changes: 34 additions & 2 deletions share/streams/shr_strdata_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module shr_strdata_mod
!===============================================================================

subroutine shr_strdata_init(SDAT,mpicom,compid,name,scmmode,scmlon,scmlat, &
gsmap,ggrid,nxg,nyg,nzg,calendar,reset_domain_mask)
gsmap,ggrid,nxg,nyg,nzg,calendar,reset_domain_mask,dmodel_domain_fracname_from_stream)

implicit none

Expand All @@ -181,6 +181,18 @@ subroutine shr_strdata_init(SDAT,mpicom,compid,name,scmmode,scmlon,scmlat, &
character(len=*) ,intent(in),optional :: calendar
logical ,intent(in),optional :: reset_domain_mask

! This variable is applicable for data models that read the model domain from the
! domain of the first stream; it is an error to provide this variable in other
! situations. If present, then we read the data model's domain fraction from the
! first stream file, and this variable provides the name of the frac field on this
! file. If absent, then (if we are taking the model domain from the domain of the
! first stream) we do not read a frac field, and instead we set frac to 1 wherever
! mask is 1, and set frac to 0 wherever mask is 0.
!
! BUG(wjs, 2018-05-01, ESMCI/cime#2515) Ideally we'd like to get this frac variable
! name in a more general and robust way; see comments in that issue for more details.
character(len=*) ,intent(in),optional :: dmodel_domain_fracname_from_stream

integer(IN) :: n,m,k ! generic index
integer(IN) :: nu,nv ! u,v index
integer(IN) :: my_task,npes ! my task, total pes
Expand All @@ -204,6 +216,7 @@ subroutine shr_strdata_init(SDAT,mpicom,compid,name,scmmode,scmlon,scmlat, &
integer(IN), pointer :: dof(:)
type(mct_sMat):: sMati
logical :: lscmmode
logical :: readfrac ! whether to read fraction from the first stream file
integer :: kmask, kfrac
character(len=*),parameter :: subname = "(shr_strdata_init) "
character(*),parameter :: F00 = "('(shr_strdata_init) ',8a)"
Expand Down Expand Up @@ -334,6 +347,11 @@ subroutine shr_strdata_init(SDAT,mpicom,compid,name,scmmode,scmlon,scmlat, &

if (present(gsmap)) then

if (present(dmodel_domain_fracname_from_stream)) then
call shr_sys_abort(subname// &
' ERROR: dmodel_domain_fracname_from_stream is irrelevant if gsmap is provided')
end if

SDAT%nxg = nxg
SDAT%nyg = nyg
SDAT%nzg = nzg
Expand All @@ -360,16 +378,30 @@ subroutine shr_strdata_init(SDAT,mpicom,compid,name,scmmode,scmlon,scmlat, &
call shr_mpi_bcast(hgtName,mpicom)
call shr_mpi_bcast(maskName,mpicom)
call shr_mpi_bcast(areaName,mpicom)
if (present(dmodel_domain_fracname_from_stream)) then
readfrac = .true.
else
readfrac = .false.
end if
if (lscmmode) then
call shr_dmodel_readgrid(SDAT%grid,SDAT%gsmap,SDAT%nxg,SDAT%nyg,SDAT%nzg, &
fileName, compid, mpicom, '2d1d', lonName, latName, hgtName, maskName, areaName, &
fracname=dmodel_domain_fracname_from_stream, readfrac=readfrac, &
scmmode=lscmmode,scmlon=scmlon,scmlat=scmlat)
else
call shr_dmodel_readgrid(SDAT%grid,SDAT%gsmap,SDAT%nxg,SDAT%nyg,SDAT%nzg, &
fileName, compid, mpicom, '2d1d', lonName, latName, hgtName, maskName, areaName)
fileName, compid, mpicom, '2d1d', lonName, latName, hgtName, maskName, areaName, &
fracname=dmodel_domain_fracname_from_stream, readfrac=readfrac)
endif
endif
else
if (present(dmodel_domain_fracname_from_stream)) then
write(logunit,*) subname,' ERROR: dmodel_domain_fracname_from_stream'
write(logunit,*) 'can only be provided when taking the data model domain'
write(logunit,*) 'from the domain of the first stream'
write(logunit,*) '(i.e., when the domain file is null).'
call shr_sys_abort(subname//' ERROR: dmodel_domain_fracname_from_stream not expected')
end if
if (lscmmode) then
call shr_dmodel_readgrid(SDAT%grid,SDAT%gsmap,SDAT%nxg,SDAT%nyg,SDAT%nzg, &
SDAT%domainfile, compid, mpicom, '2d1d', readfrac=.true., &
Expand Down
34 changes: 33 additions & 1 deletion share/test/unit/shr_cal_test/test_shr_cal.pf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module test_shr_cal
use pfunit_mod
use shr_cal_mod
use shr_kind_mod , only : r8 => shr_kind_r8, i4 => shr_kind_in, i8 => shr_kind_i8
use esmf, only : ESMF_Initialize, ESMF_Finalize
use esmf, only : ESMF_Initialize, ESMF_Finalize, ESMF_Time, ESMF_TimeSet
use esmf, only : ESMF_CALKIND_GREGORIAN

implicit none

Expand Down Expand Up @@ -360,5 +361,36 @@ contains
@assertEqual('987654-04-05-06789', date_str)
end subroutine datetod2string_long_basic

! ------------------------------------------------------------------------
! Tests of shr_cal_ymds2rday_offset
! ------------------------------------------------------------------------

@Test
subroutine ymds2rdayOffset_basic(this)
class(TestShrCal), intent(inout) :: this
type(ESMF_Time) :: etime
real(r8) :: rdays_offset
real(r8) :: expected

! Most of the current time settings here are arbitrary. However, the year and month
! are important.
call ESMF_TimeSet(etime, yy=2000, mm=4, dd=15, h=1, m=5, s=30, &
calkindflag = ESMF_CALKIND_GREGORIAN)

call shr_cal_ymds2rday_offset(etime=etime, &
rdays_offset = rdays_offset, &
years_offset = -1, &
months_offset = -1, &
days_offset = -2, &
seconds_offset = -21600)

expected = -366._r8 & ! -1 year, since year-2000 is a leap year
- 31._r8 & ! -1 month, since starting month is April
- 2._r8 & ! -2 days
- 0.25_r8 ! -21600 seconds = -0.25 days

@assertEqual(expected, rdays_offset, tolerance=tol)

end subroutine ymds2rdayOffset_basic

end module test_shr_cal
40 changes: 40 additions & 0 deletions share/util/shr_cal_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module shr_cal_mod
public :: shr_cal_setDebug ! set internal debug level
public :: shr_cal_ymdtod2string ! translate ymdtod to string for filenames
public :: shr_cal_datetod2string ! translate date to string for filenames
public :: shr_cal_ymds2rday_offset ! translate yr,month,day,sec offset to a fractional day offset

! !PUBLIC DATA MEMBERS:

Expand Down Expand Up @@ -1363,6 +1364,45 @@ subroutine shr_cal_ymdtod2string(date_str, yy, mm, dd, tod)

end subroutine shr_cal_ymdtod2string

!===============================================================================
subroutine shr_cal_ymds2rday_offset(etime, rdays_offset, &
years_offset, months_offset, days_offset, seconds_offset)
! Given the current time (etime) and optional year, month, day and seconds offsets
! from the current time: Return an offset from the current time given in fractional
! days.
!
! For example, if day_offset = -2 and seconds_offset = -21600, then rday_offset will
! be -2.25.

! !INPUT/OUTPUT PARAMETERS:

type(ESMF_Time), intent(in) :: etime ! current time
real(SHR_KIND_R8), intent(out) :: rdays_offset ! offset from current time in fractional days

! One or more of the following optional arguments should be provided:
integer(SHR_KIND_IN), intent(in), optional :: years_offset ! number of years offset from current time
integer(SHR_KIND_IN), intent(in), optional :: months_offset ! number of months offset from current time
integer(SHR_KIND_IN), intent(in), optional :: days_offset ! number of days offset from current time
integer(SHR_KIND_IN), intent(in), optional :: seconds_offset ! number of seconds offset from current time

!--- local ---
type(ESMF_TimeInterval) :: timeinterval
integer :: rc

!-------------------------------------------------------------------------------

call ESMF_TimeIntervalSet(timeinterval = timeinterval, &
startTime = etime, &
YY = years_offset, &
MM = months_offset, &
D = days_offset, &
S = seconds_offset, &
rc = rc)
if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)

call ESMF_TimeIntervalGet(timeinterval = timeinterval, d_r8 = rdays_offset, rc = rc)
if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
end subroutine shr_cal_ymds2rday_offset

!===============================================================================
end module shr_cal_mod
17 changes: 12 additions & 5 deletions share/util/shr_flux_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ SUBROUTINE shr_flux_atmOcn(nMax ,zbot ,ubot ,vbot ,thbot , prec_gust, gust_

END subroutine shr_flux_atmOcn

real(R8) elemental function cuberoot(a)
real(R8), intent(in) :: a
real(R8), parameter :: one_third = 1._R8/3._R8
cuberoot = sign(abs(a)**one_third, a)
end function cuberoot

!===============================================================================
! !BOP =========================================================================
!
Expand Down Expand Up @@ -694,7 +700,6 @@ SUBROUTINE shr_flux_atmOcn_diurnal &
real(R8) :: tdiff(nMax) ! tbot - ts
real(R8) :: vscl


qsat(Tk) = 640380.0_R8 / exp(5107.4_R8/Tk)
cdn(Umps) = 0.0027_R8 / Umps + 0.000142_R8 + 0.0000764_R8 * Umps
psimhu(xd) = log((1.0_R8+xd*(2.0_R8+xd))*(1.0_R8+xd*xd)/8.0_R8) - 2.0_R8*atan(xd) + 1.571_R8
Expand Down Expand Up @@ -877,7 +882,7 @@ SUBROUTINE shr_flux_atmOcn_diurnal &
Kvisc = 0.0_R8
dif3 = 0.0_R8

ustarw = ustar*sqrt(rbot(n)/rhocn)
ustarw = ustar*sqrt(max(tiny,rbot(n)/rhocn))
Qnsol = lwdn(n) - shr_const_stebol*(tSkin(n))**4 + &
rbot(n)*ustar*(cp*tstar + shr_const_latvap*qstar)
Hd = (Qnsol + Qsol*(1.0_R8-swpen(n)) ) / rcpocn
Expand All @@ -889,8 +894,10 @@ SUBROUTINE shr_flux_atmOcn_diurnal &
(0.137_R8 + 11.0_R8*Dcool - 6.6e-5/Dcool *(1.0_R8 - exp((-1.0_R8*Dcool)/8.0e-4)))
Hb = (Qdel/rcpocn)+(Fd*betaS/alphaT)
Hb = min(Hb , 0.0_R8)
lambdaV = lambdaC*(1.0_R8 + ( (0.0_R8-Hb)*16.0_R8*molvisc(tBulk(n))* &
shr_const_g*alphaT*molPr(tBulk(n))**2/ustarw**4)**0.75_R8)**(-1/3)

! lambdaV = lambdaC*(1.0_R8 + ( (0.0_R8-Hb)*16.0_R8*molvisc(tBulk(n))* &
! shr_const_g*alphaT*molPr(tBulk(n))**2/ustarw**4)**0.75)**(-1._R8/3._R8)
lambdaV = 6.5_R8
cSkin(n) = MIN(0.0_R8, lambdaV * molPr(tBulk(n)) * Qdel / ustarw / rcpocn )

!--- REGIME ---
Expand Down Expand Up @@ -927,7 +934,7 @@ SUBROUTINE shr_flux_atmOcn_diurnal &
Kvisc = Prandtl* kappa0 + NUzero * FofRi
else
regime(n) = 4.0_R8
Kdiff = shr_const_karman*ustarw*shr_const_zsrflyr *(1.0_R8-7.0_R8*doL)**(1/3)
Kdiff = shr_const_karman*ustarw*shr_const_zsrflyr *cuberoot(1.0_R8-7.0_R8*doL)
Kvisc = Kdiff
endif
endif
Expand Down

0 comments on commit 842ea6a

Please sign in to comment.