module atm_comp_mct ! !USES: use shr_kind_mod, only: IN=>shr_kind_IN use seq_infodata_mod use seq_timemgr_mod use mct_mod use ESMF use seq_comm_mct , only: seq_comm_getcompstates use seq_cdata_mod use esmfshr_mod use atm_comp_esmf ! ! !PUBLIC TYPES: implicit none save private ! except !-------------------------------------------------------------------------- ! Public interfaces !-------------------------------------------------------------------------- public :: atm_init_mct public :: atm_run_mct public :: atm_final_mct public :: atm_register !-------------------------------------------------------------------------- ! Private data interfaces !-------------------------------------------------------------------------- !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONTAINS !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ subroutine atm_register(atm_petlist, ccsmComp, atm_comp, import_state, export_state) implicit none ! Arguments integer, pointer :: atm_petlist(:) type(ESMF_CplComp) ,intent(inout) :: ccsmComp type(ESMF_GridComp),intent(out) :: atm_comp type(ESMF_State) ,intent(out) :: import_state, export_state ! Local variables integer :: rc ! Create Gridded Component and import/export States atm_comp = ESMF_GridCompCreate(name="atm_comp", petList=atm_petlist, rc=rc) if(rc /= ESMF_SUCCESS) call shr_sys_abort('failed to create atm comp') call ESMF_GridCompSetServices(atm_comp, atm_register_esmf, rc=rc) if(rc /= ESMF_SUCCESS) call shr_sys_abort('failed to register atm comp') import_state = ESMF_StateCreate(name="atm import", stateintent=ESMF_STATEINTENT_IMPORT, rc=rc) if(rc /= ESMF_SUCCESS) call shr_sys_abort('failed to create import atm state') export_state = ESMF_StateCreate(name="atm export", stateintent=ESMF_STATEINTENT_EXPORT, rc=rc) if(rc /= ESMF_SUCCESS) call shr_sys_abort('failed to create export atm state') ! Link attribute call ESMF_AttributeLink(ccsmComp, atm_comp, rc=rc) if(rc /= ESMF_SUCCESS) call shr_sys_abort('failed to link attribute') end subroutine !=============================================================================== !BOP =========================================================================== ! ! !IROUTINE: atm_init_mct ! ! !DESCRIPTION: ! initialize stub atm model ! ! !REVISION HISTORY: ! ! !Authors: ! Fei Liu ! ! !INTERFACE: ------------------------------------------------------------------ subroutine atm_init_mct( EClock, cdata, x2d, d2x, NLFilename ) ! !INPUT/OUTPUT PARAMETERS: type(ESMF_Clock) , intent(inout) :: EClock type(seq_cdata) , intent(inout) :: cdata type(mct_aVect) , intent(inout) :: x2d, d2x character(len=*), optional , intent(in) :: NLFilename ! Namelist filename !EOP !--- local variables --- integer(IN) :: mpicom integer(IN) :: COMPID type(mct_gsMap) , pointer :: gsMap type(mct_gGrid) , pointer :: dom type(seq_infodata_type) , pointer :: infodata integer :: rc, urc type(ESMF_State) :: import_state, export_state type(ESMF_GridComp) :: atm_comp !------------------------------------------------------------------------------- ! Set cdata pointers call seq_cdata_setptrs(cdata, ID=COMPID, mpicom=mpicom, & gsMap=gsMap, dom=dom, infodata=infodata) call seq_comm_getcompstates(COMPID, atm_comp, import_state, export_state) ! Copy infodata to state call esmfshr_infodata_infodata2state(infodata,export_state,rc=rc) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) ! call into ESMF init method which calls ESMF run method call ESMF_AttributeSet(export_state, name="ID", value=COMPID, rc=rc) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) call ESMF_GridCompInitialize(atm_comp, importState=import_state, exportState=export_state, clock=EClock, userRc=urc, rc=rc) if (urc /= ESMF_SUCCESS) call ESMF_Finalize(rc=urc, endflag=ESMF_END_ABORT) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) ! copy export_state to infodata call esmfshr_infodata_state2infodata(export_state, infodata, rc=rc) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) end subroutine atm_init_mct !=============================================================================== !BOP =========================================================================== ! ! !IROUTINE: atm_run_mct ! ! !DESCRIPTION: ! run method for stub atm model ! ! !REVISION HISTORY: ! ! !INTERFACE: ------------------------------------------------------------------ subroutine atm_run_mct(EClock, cdata, x2d, d2x) ! !INPUT/OUTPUT PARAMETERS: type(ESMF_Clock) ,intent(inout) :: EClock ! clock type(seq_cdata) ,intent(inout) :: cdata type(mct_aVect) ,intent(inout) :: x2d ! driver -> stub type(mct_aVect) ,intent(inout) :: d2x ! stub -> driver !EOP type(seq_infodata_type) , pointer :: infodata integer :: rc, urc, COMPID type(ESMF_State) :: import_state, export_state type(ESMF_GridComp) :: atm_comp !------------------------------------------------------------------------------- ! !------------------------------------------------------------------------------- call seq_cdata_setptrs(cdata, ID=COMPID, infodata=infodata) call seq_comm_getcompstates(COMPID, atm_comp, import_state, export_state) call ESMF_AttributeSet(export_state, name="ID", value=COMPID, rc=rc) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) call ESMF_GridCompRun(atm_comp, importState=import_state, exportState=export_state, clock=EClock, userRc=urc, rc=rc) if (urc /= ESMF_SUCCESS) call ESMF_Finalize(rc=urc, endflag=ESMF_END_ABORT) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) end subroutine atm_run_mct !=============================================================================== !BOP =========================================================================== ! ! !IROUTINE: atm_final_mct ! ! !DESCRIPTION: ! finalize method for stub model ! ! !REVISION HISTORY: ! ! !INTERFACE: ------------------------------------------------------------------ subroutine atm_final_mct(EClock, cdata, x2d, d2x) implicit none ! !INPUT/OUTPUT PARAMETERS: type(ESMF_Clock) ,intent(inout) :: EClock ! clock type(seq_cdata) ,intent(inout) :: cdata type(mct_aVect) ,intent(inout) :: x2d ! driver -> dead type(mct_aVect) ,intent(inout) :: d2x ! dead -> driver !EOP integer :: rc, urc integer(IN) :: COMPID type(ESMF_State) :: import_state, export_state type(ESMF_GridComp) :: atm_comp !---------------------------------------------------------------------------- ! Finalize routine !---------------------------------------------------------------------------- call seq_cdata_setptrs(cdata, ID=COMPID) call seq_comm_getcompstates(COMPID, atm_comp, import_state, export_state) call ESMF_GridCompFinalize(atm_comp, importState=import_state, exportState=export_state, userRc=urc, rc=rc) if (urc /= ESMF_SUCCESS) call ESMF_Finalize(rc=urc, endflag=ESMF_END_ABORT) if (rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) ! destroy component and states call ESMF_StateDestroy(import_state, rc=rc) if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) call ESMF_StateDestroy(export_state, rc=rc) if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) call ESMF_GridCompDestroy(atm_comp, rc=rc) if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT) end subroutine atm_final_mct !=============================================================================== end module atm_comp_mct