subroutine seq_ccsmInit( ESyncClock, initinfo, TimeMgrInfo )
type(ESMF_Clock), intent(in) :: ESyncClock
type(initinfo_t), intent(in) :: initinfo
type(TimeMgrInfo_t), intent(in) :: TimeMgrInfo
!
! Clock rules: clocks sent to components are used read-only, information can be read
! from them, but not added. Each component has it s own internal clock
!
call ESMF_VMGetGlobal( vm )
call ESMF_VMGet( vm, localpet=petid, mpicommunicator=mpicom )
masterproc = (petid == 1)
call seq_ccsm_esmfPrintLogHeader()
! Read namelist on masterproc and MPI broadcast to all MPI tasks (if MPI)
call shr_inputinfo_SetDefaults( initinfo )
call shr_inputinfo_ReadNL( nlfilename, logprint=masterproc, &
mastertask=masterproc, &
mpicom=mpicom, initinfo )
call shr_inputinfo_Get( initinfo, perpetual_run=perpetual_run, &
perpetual_ymd=perpetual_ymd )
call shr_timemgr_SetDefaults( ClockSetup, perpetual_run, perpetual_ymd )
call shr_timemgr_ReadNL( nlfilename, logprint=masterproc, &
mastertask=masterproc, &
mpicom=mpicom, Setup_Out=ClockSetup )
if ( shr_inputinfo_isRestart( initinfo ) )then
call shr_inputinfo_ReadRPointer( mpicom, masterproc, initinfo, rest_file )
call shr_inputinfo_ReadRestart( rest_file, mpicom, masterproc, initinfo )
call shr_timemgr_ReadRestart( rest_file, &
mpicom=mpicom, mastertask=masterproc, setup=ClockSetup, clock_out=SyncClock )
else
call shr_timemgr_SetupClock( ClockSetup, log_print=masterproc, clock_out=SyncClock )
end if
call shr_timemgr_ClockGet( SyncClock, e_clock=ESyncClock, info=TimeMgrInfo )
! Create import/export states of all components
cs_a = ESMF_StateCreate( type//"Atm composite state from each component on atm grid", rc )
cs_l = ESMF_StateCreate( type//"Lnd composite state from each component on land grid", rc )
cs_i = ESMF_StateCreate( type//"Ice composite state from each component on ice grid", rc )
cs_o = ESMF_StateCreate( type//"Ocn composite state from each component on ocean grid", rc )
a2x_a = ESMF_StateCreate( type//"Atm export on atmosphere grid/decomp export", rc )
a2x_l = ESMF_StateCreate( type//"Atm export on land grid/decomp export", rc )
a2x_i = ESMF_StateCreate( type//"Atm export on ice grid/decomp export", rc )
a2x_o = ESMF_StateCreate( type//"Atm export on ocean grid/decomp export", rc )
l2x_l = ESMF_StateCreate( type//"Lnd export on land grid/decomp export", rc )
l2x_a = ESMF_StateCreate( type//"Lnd export on atmosphere grid/decomp export", rc )
o2x_o = ESMF_StateCreate( type//"Ocn export on ocean grid/decomp export", rc )
o2x_a = ESMF_StateCreate( type//"Ocn export on atmosphere grid/decomp export", rc )
o2x_i = ESMF_StateCreate( type//"Ocn export on ice grid/decomp export", rc )
i2x_i = ESMF_StateCreate( type//"Ice export on ice grid/decomp export", rc )
i2x_a = ESMF_StateCreate( type//"Ice export on atmosphere grid/decomp export", rc )
i2x_o = ESMF_StateCreate( type//"Ice export on ocean grid/decomp export", rc )
x2a_a = ESMF_StateCreate( type//"All model output on atmosphere grid/decomp -- import to atm", rc )
x2l_o = ESMF_StateCreate( type//"All model output on ocean grid/decomp -- import to land", rc )
x2o_o = ESMF_StateCreate( type//"All model output on ocean grid/decomp -- import to ocean", rc )
x2i_i = ESMF_StateCreate( type//"All model output on ice grid/decomp -- import to ocean", rc )
!
! Create the composite states by adding nested states to composite states
! These are pointers to the nested states, and as such when the nested states
! are updated the composite states are updated as well.
!
! Atmosphere composite state
call ESMF_StateAddState(cs_a, o2x_a, rc)
call ESMF_StateAddState(cs_a, l2x_a, rc)
call ESMF_StateAddState(cs_a, i2x_a, rc)
! Land composite state
call ESMF_StateAddState(cs_l, a2x_l, rc)
! Ice composite state
call ESMF_StateAddState(cs_i, o2x_i, rc)
call ESMF_StateAddState(cs_i, a2x_i, rc)
! Ocean composite state
call ESMF_StateAddState(cs_o, a2x_o, rc)
call ESMF_StateAddState(cs_o, i2x_o, rc)
! Create components using global VM already gotten at high level
gc_atm = ESMF_GridCompCreate(vm, name="Sequential CCSM atmosphere ESMF Gridded Component", &
gridcomptype=ESMF_ATM, contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_atm, atm_comp_esmf_SetServices )
gc_lnd = ESMF_GridCompCreate(vm, name="Sequential CCSM land ESMF Gridded Component", &
gridcomptype=ESMF_LAND, contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_lnd, lnd_comp_esmf_SetServices )
gc_ice = ESMF_GridCompCreate(vm, name="Sequential CCSM sea-ice ESMF Gridded Component", &
gridcomptype=ESMF_SEAICE, contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_ice, ice_comp_esmf_SetServices )
gc_ocn = ESMF_GridCompCreate(vm, name="Sequential CCSM ocean ESMF Gridded Component", &
gridcomptype=ESMF_OCEAN, contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_ocn, ocn_comp_esmf_SetServices )
gc_mrg_x2a = ESMF_GridCompCreate(vm, name="Sequential CCSM atmosphere merger ESMF Gridded Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_mrg_x2a, seq_esmf_mrg_x2a_SetServices )
gc_mrg_x2l = ESMF_GridCompCreate(vm, name="Sequential CCSM land merger ESMF Gridded Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_mrg_x2l, seq_esmf_mrg_x2l_SetServices )
gc_mrg_x2i = ESMF_GridCompCreate(vm, name="Sequential CCSM sea-ice merger ESMF Gridded Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_mrg_x2i, seq_esmf_mrg_x2i_SetServices )
gc_mrg_x2o = ESMF_GridCompCreate(vm, name="Sequential CCSM ocean merger ESMF Gridded Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(gc_mrg_x2o, seq_esmf_mrg_x2o_SetServices )
cc_map_a2o = ESMF_CplCompCreate(vm, name="Sequential CCSM atmosphere to ocean ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_a2o, seq_esmf_map_SetServices )
cc_map_o2a = ESMF_CplCompCreate(vm, name="Sequential CCSM ocean to atmosphere ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_o2a, seq_esmf_map_SetServices )
cc_map_a2l = ESMF_CplCompCreate(vm, name="Sequential CCSM atmosphere to land ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_a2l, seq_esmf_map_SetServices )
cc_map_l2a = ESMF_CplCompCreate(vm, name="Sequential CCSM land to atmosphere ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_l2a, seq_esmf_map_SetServices )
cc_map_a2i = ESMF_CplCompCreate(vm, name="Sequential CCSM atmosphere to sea-ice ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_a2i, seq_esmf_map_SetServices )
cc_map_i2a = ESMF_CplCompCreate(vm, name="Sequential CCSM sea-ice to atmosphere ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_i2a, seq_esmf_map_SetServices )
cc_map_o2i = ESMF_CplCompCreate(vm, name="Sequential CCSM ocean to sea-ice ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_o2i, seq_esmf_map_SetServices )
cc_map_i2o = ESMF_CplCompCreate(vm, name="Sequential CCSM sea-ice to ocean ESMF Coupler Component", &
contextFlag=ESMF_CHILD_IN_PARENT_VM, rc=rc)
call ESMF_GridCompSetServices(cc_map_i2o, seq_esmf_map_SetServices )
! Call phase-1 initialization for each component (Setup states for each component)
! Components will also read in namelists (and possibly configuration file information)
! And they use the ESyncClock to set their internal clocks start and stop time
! They can also populate their export state with data if appropriate.
! At this stage every component is indepenent of each other. Hence
! order of the following calls is not important.
! Note that x2a_a, x2l_l, x2i_i, x2o_o will only have array control information filled in
! The fields and grids for these states will be defined in the following calls
! Add ccsm_init_data to import state as state on each import state
call eshr_inputinfo_Info2EState( initinfo, x2a_a )
call eshr_inputinfo_Info2EState( initinfo, x2l_l )
call eshr_inputinfo_Info2EState( initinfo, x2i_i )
call eshr_inputinfo_Info2EState( initinfo, x2o_o )
! Each component is given it s coupling interval by querying the alarms setup for each component
! Each component will create it s own internal clock, using ESyncClock to set start,
! stop, calendar and ref time, as well as using the restart alarm
call eshr_timemgr_Info2EState( TimeMgrInfo, x2a_a )
call eshr_timemgr_Info2EState( TimeMgrInfo, x2l_l )
call eshr_timemgr_Info2EState( TimeMgrInfo, x2i_i )
call eshr_timemgr_Info2EState( TimeMgrInfo, x2o_o )
{color:red}if ( shr_inputinfo_RunModel( initinfo, atm ) )then
call ESMF_GridCompInitialize( gc_atm, import=x2a_a, export=a2x_a, phase=1, clock=ESyncClock, rc=rc )
! If export state has different coupling intervals on it -- change alarm interval
call eshr_EState_Get( Estate=a2x_a, Cpl_dt=atm_cpl_dt )
call eshr_timemgr_ChangeAlarm( CompType="atm", Cpl_Dt=atm_cpl_dt, SyncClock )
end if
if ( shr_inputinfo_RunModel( initinfo, lnd ) )then
call ESMF_GridCompInitialize( gc_lnd, import=x2l_l, export=l2x_l, phase=1, clock=ESyncClock, rc=rc )
! If export state has different coupling interval on it -- change alarm interval
call eshr_EState_Get( Estate=l2x_l, Cpl_dt=lnd_cpl_dt )
call eshr_timemgr_ChangeAlarm( CompType="lnd", Cpl_Dt=lnd_cpl_dt, SyncClock )
end if
if ( shr_inputinfo_RunModel( initinfo, ice ) )then
call ESMF_GridCompInitialize( gc_ice, import=x2i_i, export=i2x_i, phase=1, clock=ESyncClock, rc=rc )
! If export state has different coupling intervals on it -- change alarm interval
call eshr_EState_Get( Estate=i2x_i, Cpl_dt=ice_cpl_dt )
call eshr_timemgr_ChangeAlarm( CompType="ice", Cpl_Dt=ice_cpl_dt, SyncClock )
end if
if ( shr_inputinfo_RunModel( initinfo, ocn ) )then
call ESMF_GridCompInitialize( gc_ocn, import=x2o_o, export=o2x_o, phase=1, clock=ESyncClock, rc=rc )
! If export state has different coupling interval on it -- change alarm interval
call eshr_EState_Get( Estate=o2x_o, Cpl_dt=ocn_cpl_dt )
call eshr_timemgr_ChangeAlarm( CompType="ocn", Cpl_Dt=ocn_cpl_dt, SyncClock )
end if
{color}
! Fill the following states (using grid and information from the input states)
! fill in a2x_l ! (this will be a2x on the atm grid on the lnd decomposition)
! get fields from a2x_a and grid from x2l_l and create a new state
call eshr_EState_Create(state=a2x_a, grid=x2l_l, out=a2x_l)
! fill in a2x_i ! (this will be a2x on the ocn grid on the ice decomposition)
call eshr_EState_Create(state=a2x_a, grid=x2i_i, out=a2x_i)
! fill in a2x_o ! (this will be a2x on the ocn grid on the ocn decomposition)
call eshr_EState_Create(state=a2x_a, grid=x2o_o, out=a2x_o)
! fill in l2x_a (this will be l2x on the atm grid and atm decomposition)
call eshr_EState_Create( state=l2x_l, grid=x2a_a, out=l2x_a )
! fill in o2x_a (this will be o2x on the atm grid and atm decomposition)
call eshr_EState_Create( state=o2x_o, grid=x2a_a, out=o2x_a )
! fill in o2x_i (this will be o2x on the ice grid and ice decomposition)
call eshr_EState_Create( state=o2x_o, grid=x2i_i, out=o2x_i )
! fill in i2x_a (this will be i2x on the atm grid and atm decomposition)
call eshr_EState_Create( state=i2x_i, grid=x2a_a, out=i2x_a )
! fill in i2x_o (this will be i2x on the ocn grid and ocn decomposition)
call eshr_EState_Create( state=i2x_i, grid=x2o_o, out=i2x_o )
!
! Initialize couplers - note that couplers don't need a sync clock
!
call ESMF_CplCompInitialize( cc_map_a2l, import=a2x_a, export=a2x_l, rc=rc )
call ESMF_CplCompInitialize( cc_map_a2o, import=a2x_a, export=a2x_o, rc=rc )
call ESMF_CplCompInitialize( cc_map_a2i, import=a2x_a, export=a2x_i, rc=rc )
call ESMF_CplCompInitialize( cc_map_o2i, import=o2x_o, export=o2x_i, rc=rc )
!
! 2nd phase of component initialization, fill export states with data, and use import data from couplers
!
if ( shr_inputinfo_RunModel( initinfo, atm ) )then
call ESMF_GridCompInitialize( gc_atm, import=x2a_a, export=a2x_a, phase=2, rc=rc )
else
call eshr_EState_Zero( x2a_a )
call eshr_EState_Zero( a2x_a )
end if
if ( shr_inputinfo_RunModel( initinfo, lnd ) )then
call ESMF_GridCompInitialize( gc_lnd, import=x2l_l, export=l2x_l, phase=2, rc=rc )
else
call eshr_EState_Zero( x2l_l )
call eshr_EState_Zero( l2x_l )
end if
if ( shr_inputinfo_RunModel( initinfo, ice ) )then
call ESMF_GridCompInitialize( gc_ice, import=x2i_i, export=i2x_i, phase=2, rc=rc )
else
call eshr_EState_Zero( x2i_i )
call eshr_EState_Zero( i2x_i )
end if
if ( shr_inputinfo_RunModel( initinfo, ocn ) )then
call ESMF_GridCompInitialize( gc_ocn, import=x2o_o, export=o2x_o, phase=2, rc=rc )
else
call eshr_EState_Zero( x2o_o )
call eshr_EState_Zero( o2x_o )
end if
!
! Couple back
!
call ESMF_CplCompInitialize( cc_map_l2a, import=l2x_l, export=l2x_a, rc=rc )
call ESMF_CplCompInitialize( cc_map_o2a, import=o2x_o, export=o2x_a, rc=rc )
call ESMF_CplCompInitialize( cc_map_i2a, import=i2x_i, export=i2a_a, rc=rc )
call ESMF_CplCompInitialize( cc_map_i2o, import=i2x_i, export=i2x_o, rc=rc )
!
! Run mergers to merge data
!
if ( shr_inputinfo_RunModel( initinfo, atm ) ) &
call ESMF_GridCompInitialize( gc_mrg_x2a, import=cs_a, export=x2a_a, rc=rc )
if ( shr_inputinfo_RunModel( initinfo, lnd ) ) &
call ESMF_GridCompInitialize( gc_mrg_x2l, import=cs_l, export=x2l_l, rc=rc )
if ( shr_inputinfo_RunModel( initinfo, ice ) ) &
call ESMF_GridCompInitialize( gc_mrg_x2i, import=cs_i, export=x2i_i, rc=rc )
if ( shr_inputinfo_RunModel( initinfo, ocn ) ) &
call ESMF_GridCompInitialize( gc_mrg_x2o, import=cs_o, export=x2o_o, rc=rc )
call ESMF_ClockGetAlarm( ESyncClock, Restart alarm , restart ) ! Get restart alarm
! For Stage-2 you would also get alarms for each component (ocn,ice,lnd, and atm)
! The run method only calls components when their alarms are ringing
call ESMF_ClockGetAlarm( ESyncClock, Atmosphere component alarm , atm_alarm )
call ESMF_ClockGetAlarm( ESyncClock, Land component alarm , lnd_alarm )
call ESMF_ClockGetAlarm( ESyncClock, Oean component alarm , ocn_alarm )
call ESMF_ClockGetAlarm( ESyncClock, Sea-ice component alarm , ice_alarm )
end subroutine seq_ccsm_esmfInit
|