Skip to content

Commit

Permalink
initial ensemble forcing check in
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyuan-jiang committed Sep 20, 2021
1 parent b369234 commit de81177
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 22 deletions.
74 changes: 56 additions & 18 deletions src/Components/GEOSldas_GridComp/GEOS_LdasGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ module GEOS_LdasGridCompMod
! All children
integer,allocatable :: LAND(:)
integer,allocatable :: LANDPERT(:)
integer :: METFORCE, ENSAVG, LANDASSIM
integer,allocatable :: METFORCE(:)
integer :: ENSAVG, LANDASSIM

! other global variables
integer :: NUM_ENSEMBLE
logical :: land_assim
logical :: mwRTM
logical :: ensemble_forcing

contains

Expand All @@ -75,7 +77,7 @@ subroutine SetServices(gc, rc)

! ensemble set up:

integer :: i
integer :: i, k
integer,allocatable :: ens_id(:)
type(MAPL_MetaComp), pointer :: MAPL=>null()
type(ESMF_GridComp), pointer :: gcs(:)=>null() ! Children gridcomps
Expand All @@ -85,7 +87,7 @@ subroutine SetServices(gc, rc)
character(len=ESMF_MAXSTR) :: Iam
character(len=ESMF_MAXSTR) :: comp_name
character(len=ESMF_MAXSTR) :: id_string,childname, fmt_str
character(len=ESMF_MAXSTR) :: LAND_ASSIM_STR, mwRTM_file
character(len=ESMF_MAXSTR) :: LAND_ASSIM_STR, mwRTM_file, ENS_FORCING_STR
integer :: ens_id_width
! Local variables
type(T_TILECOORD_STATE), pointer :: tcinternal
Expand Down Expand Up @@ -144,6 +146,11 @@ subroutine SetServices(gc, rc)
VERIFY_(STATUS)
call MAPL_GetResource ( MAPL, FIRST_ENS_ID, Label="FIRST_ENS_ID:", DEFAULT=0, RC=STATUS)
VERIFY_(STATUS)
call MAPL_GetResource ( MAPL, ENS_FORCING_STR, Label="ENSEMBLE_FORCING:", DEFAULT="NO", RC=STATUS)
VERIFY_(STATUS)
ENS_FORCING_STR = ESMF_UtilStringUpperCase(ENS_FORCING_STR, rc=STATUS)
VERIFY_(STATUS)
ensemble_forcing = (trim(ENS_FORCING_STR) == 'YES')

call MAPL_GetResource ( MAPL, LAND_ASSIM_STR, Label="LAND_ASSIM:", DEFAULT="NO", RC=STATUS)
VERIFY_(STATUS)
Expand All @@ -160,12 +167,32 @@ subroutine SetServices(gc, rc)
_ASSERT( .not. (mwRTM .or. land_assim), "CatchCN is Not Ready for assimilation or mwRTM")
endif

METFORCE = MAPL_AddChild(gc, name='METFORCE', ss=MetforceSetServices, rc=status)
VERIFY_(status)
if (ensemble_forcing) then
allocate(METFORCE(NUM_ENSEMBLE))
else
allocate(METFORCE(1))
endif

allocate(ens_id(NUM_ENSEMBLE),LAND(NUM_ENSEMBLE),LANDPERT(NUM_ENSEMBLE))
_ASSERT( ens_id_width < 10, "need 1 billion ensemble members? increase ens_id_width first")
write (fmt_str, "(A2,I1,A1,I1,A1)") "(I", ens_id_width,".",ens_id_width,")"

do i=1,NUM_ENSEMBLE
ens_id(i) = i-1 + FIRST_ENS_ID ! id start form FIRST_ENS_ID
if(NUM_ENSEMBLE == 1 .or. .not. ensemble_forcing) then
id_string=''
else
write(id_string, fmt_str) ens_id(i)
endif

id_string=trim(id_string)

childname='METFORCE'//trim(id_string)
METFORCE(i) = MAPL_AddChild(gc, name=trim(childname), ss=MetforceSetServices, rc=status)
VERIFY_(status)
if (.not. ensemble_forcing ) exit
enddo

do i=1,NUM_ENSEMBLE
ens_id(i) = i-1 + FIRST_ENS_ID ! id start form FIRST_ENS_ID
if(NUM_ENSEMBLE == 1 ) then
Expand Down Expand Up @@ -196,12 +223,14 @@ subroutine SetServices(gc, rc)
! Connections
do i=1,NUM_ENSEMBLE
! -METFORCE-feeds-LANDPERT's-imports-
k = 1
if ( ensemble_forcing ) k = i
call MAPL_AddConnectivity( &
gc, &
SHORT_NAME = ['Tair ', 'Qair ', 'Psurf ', 'Rainf_C', 'Rainf ', &
'Snowf ', 'LWdown ', 'SWdown ', 'PARdrct', 'PARdffs', &
'Wind ', 'RefH '], &
SRC_ID = METFORCE, &
SRC_ID = METFORCE(k), &
DST_ID = LANDPERT(i), &
rc = status &
)
Expand Down Expand Up @@ -230,7 +259,7 @@ subroutine SetServices(gc, rc)
'DUDP ', 'DUSV ', 'DUWT ', 'DUSD ', 'BCDP ', 'BCSV ', &
'BCWT ', 'BCSD ', 'OCDP ', 'OCSV ', 'OCWT ', 'OCSD ', &
'SUDP ', 'SUSV ', 'SUWT ', 'SUSD ', 'SSDP ', 'SSSV ' ], &
SRC_ID = METFORCE, &
SRC_ID = METFORCE(k), &
DST_NAME = ['PS ', 'DZ ', &
'DUDP', 'DUSV', 'DUWT', 'DUSD', 'BCDP', 'BCSV', &
'BCWT', 'BCSD', 'OCDP', 'OCSV', 'OCWT', 'OCSD', &
Expand Down Expand Up @@ -660,17 +689,21 @@ subroutine Initialize(gc, import, export, clock, rc)
tcinternal%grid_f = tile_grid_f
tcinternal%grid_l = tile_grid_l

call MAPL_GetObjectFromGC(gcs(METFORCE), CHILD_MAPL, rc=status)
VERIFY_(status) ! CHILD = METFORCE
call MAPL_Set(CHILD_MAPL, LocStream=land_locstream, rc=status)
VERIFY_(status)
do i = 1, NUM_ENSEMBLE
call MAPL_GetObjectFromGC(gcs(METFORCE(i)), CHILD_MAPL, rc=status)
VERIFY_(status) ! CHILD = METFORCE
call MAPL_Set(CHILD_MAPL, LocStream=land_locstream, rc=status)
VERIFY_(status)
call ESMF_UserCompSetInternalState(gcs(METFORCE(i)), 'TILE_COORD', tcwrap, status)
VERIFY_(status)
! only loop on i = 1 if it is not enenmbel_forcing
if (.not. ensemble_forcing) exit
enddo

call MAPL_GetObjectFromGC(gcs(ENSAVG), CHILD_MAPL, rc=status)
VERIFY_(status) ! CHILD = ens_avg
call MAPL_Set(CHILD_MAPL, LocStream=land_locstream, rc=status)
VERIFY_(status)
call ESMF_UserCompSetInternalState(gcs(METFORCE), 'TILE_COORD', tcwrap, status)
VERIFY_(status)

do i = 1,NUM_ENSEMBLE
call MAPL_GetObjectFromGC(gcs(LAND(i)), CHILD_MAPL, rc=status)
Expand Down Expand Up @@ -834,11 +867,16 @@ subroutine Run(gc, import, export, clock, rc)
enddo


igc = METFORCE
call MAPL_TimerOn(MAPL, gcnames(igc))
call ESMF_GridCompRun(gcs(igc), importState=gim(igc), exportState=gex(igc), clock=clock, userRC=status)
VERIFY_(status)
call MAPL_TimerOff(MAPL, gcnames(igc))
do i = 1, NUM_ENSEMBLE
igc = METFORCE(i)
call MAPL_TimerOn(MAPL, gcnames(igc))
call ESMF_GridCompRun(gcs(igc), importState=gim(igc), exportState=gex(igc), clock=clock, userRC=status)
VERIFY_(status)
call MAPL_TimerOff(MAPL, gcnames(igc))
! exit after i = 1 if it is not ensemble forcing
if (.not. ensemble_forcing) exit
enddo


do i = 1,NUM_ENSEMBLE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,15 @@ subroutine Initialize(gc, import, export, clock, rc)
type(tile_coord_type), pointer :: tile_coord(:)=>null()

! Misc variables
integer :: land_nt_local
integer :: land_nt_local, k, NUM_ENSEMBLE
integer :: ForceDtStep
type(met_force_type) :: mf_nodata
logical :: MERRA_file_specs
logical :: MERRA_file_specs, ensemble_forcing, ens_id_width
logical :: backward_looking_fluxes

integer :: AEROSOL_DEPOSITION
type(MAPL_LocStream) :: locstream
character(len=ESMF_MAXSTR) :: grid_type
character(len=ESMF_MAXSTR) :: grid_type, ENS_FORCING_STR, ens_forcing_path, id_string
type(ESMF_Grid) :: agrid
integer :: dims(ESMF_MAXDIM)
! Begin...
Expand Down Expand Up @@ -673,9 +673,25 @@ subroutine Initialize(gc, import, export, clock, rc)
! -allocate-memory-for-avg-zenith-angle
allocate(mf%zenav(land_nt_local), source=nodata_generic, stat=status)
VERIFY_(status)
call MAPL_GetResource ( MAPL, ENS_FORCING_STR, Label="ENSEMBLE_FORCING:", DEFAULT="NO", RC=STATUS)
VERIFY_(STATUS)
ENS_FORCING_STR = ESMF_UtilStringUpperCase(ENS_FORCING_STR, rc=STATUS)
VERIFY_(STATUS)
call MAPL_GetResource ( MAPL, NUM_ENSEMBLE, Label="NUM_LDAS_ENSEMBLE:", DEFAULT=1, RC=STATUS)
VERIFY_(STATUS)
ensemble_forcing = (trim(ENS_FORCING_STR) == 'YES')
if (ensemble_forcing .and. NUM_ENSEMBLE > 1) then
id_string = ""
call MAPL_GetResource ( MAPL, ens_id_width, Label="ENS_ID_WIDTH:", DEFAULT=0, RC=STATUS)
k = len(trim(comp_name))
id_string = comp_name(k-ens_id_width+1:k)
k = len(trim(id_string))
! hard coded 3 character for forcing
call ESMF_CFIOStrTemplate(ens_forcing_path, trim(adjustl(mf%Path)),'GRADS', xid = trim(id_string(k-2:k)), stat=status)
mf%Path = ens_forcing_path
endif
! Put MetForcing in Ldas' pvt internal state
internal%mf = mf

! Create alarm for MetForcing
! -create-nonsticky-alarm-
MetForcingAlarm = ESMF_AlarmCreate( &
Expand Down

1 comment on commit de81177

@saraqzhang
Copy link
Contributor

Choose a reason for hiding this comment

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

@weiyuan-jiang
are the ensemble initial forcing (at and before the restart time) loaded by a single call in GEOS_MetforceGridCompMod Initialize "call LDAS_GetForcing(...) " ?

Please sign in to comment.