Skip to content

Commit

Permalink
Merge pull request #567 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Sync develop into main
  • Loading branch information
sdrabenh authored Mar 18, 2022
2 parents cb754a3 + 818d15b commit 6face23
Show file tree
Hide file tree
Showing 77 changed files with 460 additions and 16,916 deletions.
109 changes: 107 additions & 2 deletions GEOS_GcmGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module GEOS_GcmGridCompMod
use GEOS_mkiauGridCompMod, only: AIAU_SetServices => SetServices
use DFI_GridCompMod, only: ADFI_SetServices => SetServices
use GEOS_OgcmGridCompMod, only: OGCM_SetServices => SetServices

use MAPL_HistoryGridCompMod, only: Hist_SetServices => SetServices
use MAPL_HistoryGridCompMod, only: HISTORY_ExchangeListWrap
use iso_fortran_env

implicit none
private
Expand Down Expand Up @@ -50,6 +52,7 @@ module GEOS_GcmGridCompMod
integer :: OGCM
integer :: AIAU
integer :: ADFI
integer :: hist

integer :: bypass_ogcm
integer :: k
Expand All @@ -76,6 +79,8 @@ module GEOS_GcmGridCompMod
logical :: checkpointRequested = .false.
character(len=ESMF_MAXSTR) :: checkpointFilename = ''
character(len=ESMF_MAXSTR) :: checkpointFileType = ''
type(ESMF_GridComp) :: history_parent
logical :: run_history = .false.
end type T_GCM_STATE

! Wrapper for extracting internal state
Expand Down Expand Up @@ -613,7 +618,9 @@ subroutine SetServices ( GC, RC )
VERIFY_(STATUS)
ExtDataWrap%ptr => extdata_internal_state
call ESMF_UserCompSetInternalState( GC, 'ExtData_state',ExtDataWrap,status)
VERIFY_(STATUS)
VERIFY_(STATUS)

call history_setservice(_RC)
end if


Expand Down Expand Up @@ -646,6 +653,37 @@ subroutine SetServices ( GC, RC )

contains

subroutine history_setservice(rc)
integer, intent(out), optional :: rc

integer :: status
type(ESMF_Config) :: hist_cf, gcm_cf
type(MAPL_MetaComp), pointer :: history_metaobj
type(StubComponent) :: stub_component
integer :: run_dt
character(len=ESMF_MAXSTR) :: replay_history
logical :: is_present

call ESMF_GridCompGet(gc,config=gcm_cf,_RC)
call ESMF_ConfigFindLabel(gcm_cf,"REPLAY_HISTORY_RC:",isPresent=is_present,_RC)

if (is_present) then
gcm_internal_state%run_history = .true.
call MAPL_GetResource(MAPL,replay_history,"REPLAY_HISTORY_RC:",_RC)
hist_cf = ESMF_ConfigCreate(_RC)
call ESMF_ConfigLoadFile(hist_cf,trim(replay_history),_RC)
call MAPL_GetResource(MAPL,run_dt,"RUN_DT:",_RC)
call MAPL_ConfigSetAttribute(hist_cf,value=run_dt,label="RUN_DT:",_RC)
call MAPL_ConfigSetAttribute(hist_cf,value=replay_history,label="HIST_CF:",_RC)
gcm_internal_state%history_parent = ESMF_GridCompCreate(name="History_GCM_parent",config=hist_cf,_RC)
history_metaobj => null()
call MAPL_InternalStateCreate(gcm_internal_state%history_parent,history_metaobj,_RC)
call MAPL_Set(history_metaobj,cf=hist_cf,name="History_GCM_parent",component=stub_component,_RC)
hist = MAPL_AddChild(history_metaobj,name="History_GCM",ss=hist_setservices,_RC)
end if
_RETURN(_SUCCESS)
end subroutine history_setservice

subroutine OBIO_TerminateImports(DO_DATAATM, RC)

integer, intent(IN ) :: DO_DATAATM
Expand Down Expand Up @@ -1297,12 +1335,52 @@ subroutine Initialize ( GC, IMPORT, EXPORT, CLOCK, RC )
if ( MAPL_am_I_root() ) call ESMF_StatePrint ( EXPORT, rc=STATUS )
#endif

if(gcm_internal_state%rplRegular .and. gcm_internal_state%run_history) then
call initialize_history(_RC)
end if

call MAPL_TimerOff(MAPL,"TOTAL")
call MAPL_TimerOff(MAPL,"INITIALIZE")

RETURN_(ESMF_SUCCESS)

contains

subroutine initialize_history(rc)
integer, optional, intent(Out) :: rc

integer :: status,user_status
type(ESMF_State), allocatable :: gcm_exports(:),hist_imports(:),hist_exports(:)
type(ESMF_GridComp), allocatable :: hist_gcs(:)
type(ESMF_GridComp), allocatable :: gcm_gcs(:)
type(MAPL_MetaComp), pointer :: history_metaobj
type(HISTORY_ExchangeListWrap) :: lswrap
integer(kind=INT64), pointer :: LSADDR(:) => null()

call MAPL_GetObjectFromGC ( gcm_internal_state%history_parent, history_metaobj, _RC)

call MAPL_Get(mapl,childrens_export_states = gcm_exports, childrens_gridcomps = gcm_gcs, _RC)

call MAPL_Get(history_metaobj, &
childrens_export_states = hist_exports, &
childrens_import_states = hist_imports, &
childrens_gridcomps = hist_gcs, _RC)

allocate(lswrap%ptr, stat = status)
_VERIFY(STATUS)
call ESMF_UserCompSetInternalState(hist_gcs(hist), 'MAPL_LocStreamList', &
lswrap, _RC)
call MAPL_GetAllExchangeGrids(gcm_gcs(agcm), LSADDR, _RC)
lswrap%ptr%LSADDR_PTR => LSADDR

call ESMF_StateAdd(hist_imports(hist),[gcm_exports(agcm)],_RC)
call ESMF_GridCompInitialize(hist_gcs(hist),importState=hist_imports(hist),&
exportState=hist_exports(hist),&
clock=clock,userRC=user_status,_RC)

_RETURN(_SUCCESS)
end subroutine initialize_history

subroutine AllocateExports(STATE, NAMES, RC)
type(ESMF_State) , intent(INOUT) :: STATE
character(len=*) , intent(IN ) :: NAMES(:)
Expand Down Expand Up @@ -1701,6 +1779,10 @@ subroutine Run ( GC, IMPORT, EXPORT, CLOCK, RC )
call ESMF_VMBarrier(VM, rc=status)
VERIFY_(STATUS)

if (gcm_internal_state%run_history) then
call run_history(_RC)
end if

DONE = ESMF_AlarmIsRinging(GCM_INTERNAL_STATE%replayStopAlarm, RC=STATUS)
VERIFY_(STATUS)
if ( DONE ) exit
Expand Down Expand Up @@ -1826,6 +1908,29 @@ subroutine Run ( GC, IMPORT, EXPORT, CLOCK, RC )

RETURN_(ESMF_SUCCESS)
contains

subroutine run_history(rc)
integer, optional, intent(out) :: rc

integer :: user_status,status
type(ESMF_State), allocatable :: gcm_exports(:),hist_imports(:),hist_exports(:)
type(ESMF_GridComp), allocatable :: hist_gcs(:)
type(MAPL_MetaComp), pointer :: history_metaobj

call MAPL_GetObjectFromGC ( gcm_internal_state%history_parent, history_metaobj, _RC)

call MAPL_Get(history_metaobj, &
childrens_export_states = hist_exports, &
childrens_import_states = hist_imports, &
childrens_gridcomps = hist_gcs, _RC)

call ESMF_GridCompRun(hist_gcs(hist),importState=hist_imports(hist),&
exportState=hist_exports(hist),&
clock=clock,userRC=user_status,_RC)
_RETURN(_SUCCESS)

end subroutine run_history

subroutine RUN_OCEAN(phase, rc)
integer, optional, intent(IN) :: phase
integer, optional, intent(OUT) :: rc
Expand Down
11 changes: 7 additions & 4 deletions GEOSagcm_GridComp/GEOSphysics_GridComp/GEOS_PhysicsGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,9 @@ subroutine SetServices ( GC, RC )
!----------------

call MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/'PCU ','PLS ','SNO ','ICE ','FRZR'/), &
SHORT_NAME = (/'PCU ', 'PLS ', 'SNO ', &
'ICE ', 'FRZR ', 'TPREC ', &
'CN_PRCP' /), &
DST_ID = SURF, &
SRC_ID = MOIST, &
RC=STATUS )
Expand Down Expand Up @@ -1198,8 +1200,8 @@ subroutine SetServices ( GC, RC )
! -----------------

call MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/ 'Q ', 'RH2 ', 'CN_PRCP ', &
'TPREC ', 'SNO ', 'DQDT ', &
SHORT_NAME = (/ 'Q ', 'RH2 ', &
'SNO ', 'DQDT ', &
'FCLD ', 'LS_PRCP ', 'CNV_MFC ', &
'CNV_MFD ', 'QL ', 'PFL_CN ', &
'PFL_LSAN', 'PFI_CN ', 'PFI_LSAN', &
Expand Down Expand Up @@ -1235,7 +1237,8 @@ subroutine SetServices ( GC, RC )
'CN ', 'RHOS ', 'WET2 ', &
'SNOMAS ', 'SNOWDP ', 'ITY ', &
'LHFX ', 'Q2M ', 'Q10M ', &
'T10M ', 'WCSF ' /), &
'T10M ', 'WCSF ', 'CN_PRCP ', &
'PRECTOT ' /), &
DST_ID = CHEM, &
SRC_ID = SURF, &
RC=STATUS )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ set (srcs
ncar_gwd/gw_drag.F90
)

esma_add_library (${this} SRCS ${srcs} DEPENDENCIES GEOS_Shared MAPL)
target_include_directories (${this} PUBLIC ${INC_ESMF} ${INC_NETCDF})
esma_add_library (${this} SRCS ${srcs} DEPENDENCIES GEOS_Shared MAPL esmf NetCDF::NetCDF_Fortran)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ foreach (file ${k_g_srcs})
endforeach ()

esma_add_library (${this} SRCS ${srcs} ${k_g_srcs}
DEPENDENCIES GEOS_Shared MAPL RRTMG_SW_mods GEOS_RadiationShared)
target_include_directories (${this} PUBLIC ${INC_ESMF} ${INC_NETCDF})
DEPENDENCIES GEOS_Shared MAPL RRTMG_SW_mods GEOS_RadiationShared esmf NetCDF::NetCDF_Fortran)


Loading

0 comments on commit 6face23

Please sign in to comment.