Skip to content

Commit 6face23

Browse files
authored
Merge pull request #567 from GEOS-ESM/develop
Sync develop into main
2 parents cb754a3 + 818d15b commit 6face23

File tree

77 files changed

+460
-16916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+460
-16916
lines changed

GEOS_GcmGridComp.F90

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ module GEOS_GcmGridCompMod
2121
use GEOS_mkiauGridCompMod, only: AIAU_SetServices => SetServices
2222
use DFI_GridCompMod, only: ADFI_SetServices => SetServices
2323
use GEOS_OgcmGridCompMod, only: OGCM_SetServices => SetServices
24-
24+
use MAPL_HistoryGridCompMod, only: Hist_SetServices => SetServices
25+
use MAPL_HistoryGridCompMod, only: HISTORY_ExchangeListWrap
26+
use iso_fortran_env
2527

2628
implicit none
2729
private
@@ -50,6 +52,7 @@ module GEOS_GcmGridCompMod
5052
integer :: OGCM
5153
integer :: AIAU
5254
integer :: ADFI
55+
integer :: hist
5356

5457
integer :: bypass_ogcm
5558
integer :: k
@@ -76,6 +79,8 @@ module GEOS_GcmGridCompMod
7679
logical :: checkpointRequested = .false.
7780
character(len=ESMF_MAXSTR) :: checkpointFilename = ''
7881
character(len=ESMF_MAXSTR) :: checkpointFileType = ''
82+
type(ESMF_GridComp) :: history_parent
83+
logical :: run_history = .false.
7984
end type T_GCM_STATE
8085

8186
! Wrapper for extracting internal state
@@ -613,7 +618,9 @@ subroutine SetServices ( GC, RC )
613618
VERIFY_(STATUS)
614619
ExtDataWrap%ptr => extdata_internal_state
615620
call ESMF_UserCompSetInternalState( GC, 'ExtData_state',ExtDataWrap,status)
616-
VERIFY_(STATUS)
621+
VERIFY_(STATUS)
622+
623+
call history_setservice(_RC)
617624
end if
618625

619626

@@ -646,6 +653,37 @@ subroutine SetServices ( GC, RC )
646653

647654
contains
648655

656+
subroutine history_setservice(rc)
657+
integer, intent(out), optional :: rc
658+
659+
integer :: status
660+
type(ESMF_Config) :: hist_cf, gcm_cf
661+
type(MAPL_MetaComp), pointer :: history_metaobj
662+
type(StubComponent) :: stub_component
663+
integer :: run_dt
664+
character(len=ESMF_MAXSTR) :: replay_history
665+
logical :: is_present
666+
667+
call ESMF_GridCompGet(gc,config=gcm_cf,_RC)
668+
call ESMF_ConfigFindLabel(gcm_cf,"REPLAY_HISTORY_RC:",isPresent=is_present,_RC)
669+
670+
if (is_present) then
671+
gcm_internal_state%run_history = .true.
672+
call MAPL_GetResource(MAPL,replay_history,"REPLAY_HISTORY_RC:",_RC)
673+
hist_cf = ESMF_ConfigCreate(_RC)
674+
call ESMF_ConfigLoadFile(hist_cf,trim(replay_history),_RC)
675+
call MAPL_GetResource(MAPL,run_dt,"RUN_DT:",_RC)
676+
call MAPL_ConfigSetAttribute(hist_cf,value=run_dt,label="RUN_DT:",_RC)
677+
call MAPL_ConfigSetAttribute(hist_cf,value=replay_history,label="HIST_CF:",_RC)
678+
gcm_internal_state%history_parent = ESMF_GridCompCreate(name="History_GCM_parent",config=hist_cf,_RC)
679+
history_metaobj => null()
680+
call MAPL_InternalStateCreate(gcm_internal_state%history_parent,history_metaobj,_RC)
681+
call MAPL_Set(history_metaobj,cf=hist_cf,name="History_GCM_parent",component=stub_component,_RC)
682+
hist = MAPL_AddChild(history_metaobj,name="History_GCM",ss=hist_setservices,_RC)
683+
end if
684+
_RETURN(_SUCCESS)
685+
end subroutine history_setservice
686+
649687
subroutine OBIO_TerminateImports(DO_DATAATM, RC)
650688

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

1338+
if(gcm_internal_state%rplRegular .and. gcm_internal_state%run_history) then
1339+
call initialize_history(_RC)
1340+
end if
1341+
13001342
call MAPL_TimerOff(MAPL,"TOTAL")
13011343
call MAPL_TimerOff(MAPL,"INITIALIZE")
13021344

13031345
RETURN_(ESMF_SUCCESS)
13041346

13051347
contains
1348+
1349+
subroutine initialize_history(rc)
1350+
integer, optional, intent(Out) :: rc
1351+
1352+
integer :: status,user_status
1353+
type(ESMF_State), allocatable :: gcm_exports(:),hist_imports(:),hist_exports(:)
1354+
type(ESMF_GridComp), allocatable :: hist_gcs(:)
1355+
type(ESMF_GridComp), allocatable :: gcm_gcs(:)
1356+
type(MAPL_MetaComp), pointer :: history_metaobj
1357+
type(HISTORY_ExchangeListWrap) :: lswrap
1358+
integer(kind=INT64), pointer :: LSADDR(:) => null()
1359+
1360+
call MAPL_GetObjectFromGC ( gcm_internal_state%history_parent, history_metaobj, _RC)
1361+
1362+
call MAPL_Get(mapl,childrens_export_states = gcm_exports, childrens_gridcomps = gcm_gcs, _RC)
1363+
1364+
call MAPL_Get(history_metaobj, &
1365+
childrens_export_states = hist_exports, &
1366+
childrens_import_states = hist_imports, &
1367+
childrens_gridcomps = hist_gcs, _RC)
1368+
1369+
allocate(lswrap%ptr, stat = status)
1370+
_VERIFY(STATUS)
1371+
call ESMF_UserCompSetInternalState(hist_gcs(hist), 'MAPL_LocStreamList', &
1372+
lswrap, _RC)
1373+
call MAPL_GetAllExchangeGrids(gcm_gcs(agcm), LSADDR, _RC)
1374+
lswrap%ptr%LSADDR_PTR => LSADDR
1375+
1376+
call ESMF_StateAdd(hist_imports(hist),[gcm_exports(agcm)],_RC)
1377+
call ESMF_GridCompInitialize(hist_gcs(hist),importState=hist_imports(hist),&
1378+
exportState=hist_exports(hist),&
1379+
clock=clock,userRC=user_status,_RC)
1380+
1381+
_RETURN(_SUCCESS)
1382+
end subroutine initialize_history
1383+
13061384
subroutine AllocateExports(STATE, NAMES, RC)
13071385
type(ESMF_State) , intent(INOUT) :: STATE
13081386
character(len=*) , intent(IN ) :: NAMES(:)
@@ -1701,6 +1779,10 @@ subroutine Run ( GC, IMPORT, EXPORT, CLOCK, RC )
17011779
call ESMF_VMBarrier(VM, rc=status)
17021780
VERIFY_(STATUS)
17031781

1782+
if (gcm_internal_state%run_history) then
1783+
call run_history(_RC)
1784+
end if
1785+
17041786
DONE = ESMF_AlarmIsRinging(GCM_INTERNAL_STATE%replayStopAlarm, RC=STATUS)
17051787
VERIFY_(STATUS)
17061788
if ( DONE ) exit
@@ -1826,6 +1908,29 @@ subroutine Run ( GC, IMPORT, EXPORT, CLOCK, RC )
18261908

18271909
RETURN_(ESMF_SUCCESS)
18281910
contains
1911+
1912+
subroutine run_history(rc)
1913+
integer, optional, intent(out) :: rc
1914+
1915+
integer :: user_status,status
1916+
type(ESMF_State), allocatable :: gcm_exports(:),hist_imports(:),hist_exports(:)
1917+
type(ESMF_GridComp), allocatable :: hist_gcs(:)
1918+
type(MAPL_MetaComp), pointer :: history_metaobj
1919+
1920+
call MAPL_GetObjectFromGC ( gcm_internal_state%history_parent, history_metaobj, _RC)
1921+
1922+
call MAPL_Get(history_metaobj, &
1923+
childrens_export_states = hist_exports, &
1924+
childrens_import_states = hist_imports, &
1925+
childrens_gridcomps = hist_gcs, _RC)
1926+
1927+
call ESMF_GridCompRun(hist_gcs(hist),importState=hist_imports(hist),&
1928+
exportState=hist_exports(hist),&
1929+
clock=clock,userRC=user_status,_RC)
1930+
_RETURN(_SUCCESS)
1931+
1932+
end subroutine run_history
1933+
18291934
subroutine RUN_OCEAN(phase, rc)
18301935
integer, optional, intent(IN) :: phase
18311936
integer, optional, intent(OUT) :: rc

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOS_PhysicsGridComp.F90

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,9 @@ subroutine SetServices ( GC, RC )
11371137
!----------------
11381138

11391139
call MAPL_AddConnectivity ( GC, &
1140-
SHORT_NAME = (/'PCU ','PLS ','SNO ','ICE ','FRZR'/), &
1140+
SHORT_NAME = (/'PCU ', 'PLS ', 'SNO ', &
1141+
'ICE ', 'FRZR ', 'TPREC ', &
1142+
'CN_PRCP' /), &
11411143
DST_ID = SURF, &
11421144
SRC_ID = MOIST, &
11431145
RC=STATUS )
@@ -1198,8 +1200,8 @@ subroutine SetServices ( GC, RC )
11981200
! -----------------
11991201

12001202
call MAPL_AddConnectivity ( GC, &
1201-
SHORT_NAME = (/ 'Q ', 'RH2 ', 'CN_PRCP ', &
1202-
'TPREC ', 'SNO ', 'DQDT ', &
1203+
SHORT_NAME = (/ 'Q ', 'RH2 ', &
1204+
'SNO ', 'DQDT ', &
12031205
'FCLD ', 'LS_PRCP ', 'CNV_MFC ', &
12041206
'CNV_MFD ', 'QL ', 'PFL_CN ', &
12051207
'PFL_LSAN', 'PFI_CN ', 'PFI_LSAN', &
@@ -1235,7 +1237,8 @@ subroutine SetServices ( GC, RC )
12351237
'CN ', 'RHOS ', 'WET2 ', &
12361238
'SNOMAS ', 'SNOWDP ', 'ITY ', &
12371239
'LHFX ', 'Q2M ', 'Q10M ', &
1238-
'T10M ', 'WCSF ' /), &
1240+
'T10M ', 'WCSF ', 'CN_PRCP ', &
1241+
'PRECTOT ' /), &
12391242
DST_ID = CHEM, &
12401243
SRC_ID = SURF, &
12411244
RC=STATUS )

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSgwd_GridComp/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ set (srcs
1919
ncar_gwd/gw_drag.F90
2020
)
2121

22-
esma_add_library (${this} SRCS ${srcs} DEPENDENCIES GEOS_Shared MAPL)
23-
target_include_directories (${this} PUBLIC ${INC_ESMF} ${INC_NETCDF})
22+
esma_add_library (${this} SRCS ${srcs} DEPENDENCIES GEOS_Shared MAPL esmf NetCDF::NetCDF_Fortran)

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSradiation_GridComp/GEOSsolar_GridComp/RRTMG/rrtmg_sw/gcm_model/src/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ foreach (file ${k_g_srcs})
4040
endforeach ()
4141

4242
esma_add_library (${this} SRCS ${srcs} ${k_g_srcs}
43-
DEPENDENCIES GEOS_Shared MAPL RRTMG_SW_mods GEOS_RadiationShared)
44-
target_include_directories (${this} PUBLIC ${INC_ESMF} ${INC_NETCDF})
43+
DEPENDENCIES GEOS_Shared MAPL RRTMG_SW_mods GEOS_RadiationShared esmf NetCDF::NetCDF_Fortran)
4544

4645

0 commit comments

Comments
 (0)