From b3f6c92ead1639879f48af0de2b296e1187ebfd6 Mon Sep 17 00:00:00 2001 From: Thibaud Fritz Date: Tue, 1 Dec 2020 11:36:14 -0500 Subject: [PATCH 1/2] Feat: Add option to check if we are running with CESM-GC Signed-off-by: Thibaud Fritz --- hemco_interface.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/hemco_interface.F90 b/hemco_interface.F90 index 96c71ad..7aaa884 100644 --- a/hemco_interface.F90 +++ b/hemco_interface.F90 @@ -610,6 +610,7 @@ subroutine HCOI_Chunk_Init() ! Additional exports: Verify if we need to add additional exports ! for integration with CESM-GC. (hplin, 4/15/20) !----------------------------------------------------------------------- + ! Do additional exports! if(chem_is('GEOS-Chem')) then do N = 0, 72 From 96a8bca6d2410032ccfcacf0ffe1c6ee8dd11f7d Mon Sep 17 00:00:00 2001 From: Thibaud Fritz Date: Wed, 9 Dec 2020 19:05:57 -0500 Subject: [PATCH 2/2] Feat: Export fields on first call Signed-off-by: Thibaud Fritz --- hemco_interface.F90 | 130 +++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 73 deletions(-) diff --git a/hemco_interface.F90 b/hemco_interface.F90 index 7aaa884..4776de3 100644 --- a/hemco_interface.F90 +++ b/hemco_interface.F90 @@ -443,7 +443,7 @@ subroutine HCOI_Chunk_Init() HcoConfig%amIRoot = masterproc - HcoConfig%amIRoot = .true. ! for debug only so verbosity is higher + !HcoConfig%amIRoot = .true. ! for debug only so verbosity is higher HcoConfig%MetField = 'MERRA2' HcoConfig%GridRes = '' @@ -1107,6 +1107,9 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! HEMCO return code integer :: HMRC + logical, save :: FIRST = .True. + logical :: doExport = .False. + ! Assume success RC = ESMF_SUCCESS HMRC = HCO_SUCCESS @@ -1347,67 +1350,30 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Build history / pbuf field name (HCO_NO, HCO_CO, etc.) exportName = 'HCO_' // trim(HcoConfig%ModelSpc(spcID)%SpcName) + doExport = ( FIRST .or. associated(HcoState%Spc(spcID)%Emis%Val) ) ! if(masterproc) write(iulog,*) "HEMCO_CAM: Begin exporting " // trim(exportName) ! Get HEMCO emissions flux [kg/m2/s]. ! For performance optimization ... tap into HEMCO structure directly (ugly ugly) ! No need to flip vertical here. The regridder will do it for us - if(associated(HcoState%Spc(spcID)%Emis%Val)) then + if( associated(HcoState%Spc(spcID)%Emis%Val) ) then exportFldHco(my_IS:my_IE,my_JS:my_JE,1:LM) = HcoState%Spc(spcID)%Emis%Val(1:HI,1:HJ,1:LM) - ! do K = 1, LM - ! do J = my_JS, my_JE - ! HJ = J - my_JS + 1 - - ! exportFldHco(my_IS:my_IE,J,K) = HcoState%Spc(spcID)%Emis%Val(1:HI,J,K) - ! enddo - ! enddo - if(masterproc) then - write(iulog,*) "HEMCO_CAM: Retrieved from HCO " // trim(exportName) - endif - else - if(masterproc) then - write(iulog,*) "HEMCO_CAM: No emissions HCO " // trim(exportName) - endif + if(masterproc) write(iulog,*) "HEMCO_CAM: Retrieved from HCO " // trim(exportName) + !write(6,*) "HEMCO_CAM: Retrieved from HCO " // trim(exportName) endif ! Regrid exportFldHco to CAM grid... - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM, doRegrid=associated(HcoState%Spc(spcID)%Emis%Val)) - ! if(masterproc) write(iulog,*) "HEMCO_CAM: Regridded " // trim(exportName) + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM, doRegrid=doExport) - if(associated(HcoState%Spc(spcID)%Emis%Val)) then + if( doExport ) then ! Write to history on CAM mesh call HCO_Export_History_CAM3D(exportName, exportFldCAM) - ! if(masterproc) write(iulog,*) "HEMCO_CAM: Exported to history " // trim(exportName) ! Write to physics buffer (pass model name) call HCO_Export_Pbuf_CAM3D(HcoConfig%ModelSpc(spcID)%SpcName, spcID, exportFldCAM) endif - ! do K = 1, LM - ! HL = K ! map to HEMCO index - ! do J = my_JS, my_JE - ! HJ = J - my_JS + 1 - ! do I = my_IS, my_IE - ! HI = I - my_IS + 1 - - ! ! Maybe no need to call GetHcoVal and just directly grab the pointer - ! ! instead? - ! ! call GetHcoVal(HcoState, ExtState, spcID, HI, HJ, HL, FND, emis=TMP) - - ! ! For performance optimization - - ! if(FND) then - ! exportFldHco(I,J,K) = TMP - - ! if(masterproc .and. TMP < 0.0_r8) then - ! write(iulog) "> **ERR** HEMCO_CAM negative value HI,HJ,HL,spcID,val", HI, HJ, HL, spcID, TMP - ! endif - ! endif - ! enddo - ! enddo - ! enddo - ! if(masterproc) write(iulog,*) "HEMCO_CAM: Retrieved from HCO " // trim(exportName) enddo @@ -1429,10 +1395,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1448,10 +1416,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1468,10 +1438,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1487,16 +1459,17 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - ! This is required as the physics buffer cannot store ! `HCO_surf_salinity` as it is too long.. We thus export as ! `HCO_salinity` write(exportNameTmp, '(a)') 'salinity' exportName = 'HCO_' // trim(exportNameTmp) - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1512,14 +1485,15 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - ! See above comment about `HCO_surf_salinity` write(exportNameTmp, '(a)') 'iodide' exportName = 'HCO_' // trim(exportNameTmp) - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1535,10 +1509,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1554,10 +1530,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1573,10 +1551,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1592,10 +1572,12 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) ! Grab the pointer if available call HCO_GetPtr(HcoState, exportNameTmp, Ptr2D, HMRC, FOUND=FND) - if(HMRC == HCO_SUCCESS .and. FND) then + doExport = (FIRST .or. (HMRC == HCO_SUCCESS .and. FND)) + if ( HMRC == HCO_SUCCESS .and. FND ) then exportFldHco(:,:,1) = Ptr2D ! Copy data in - - call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + endif + call HCO_Grid_HCO2CAM_3D(exportFldHco, exportFldCAM) + if ( doExport ) then call HCO_Export_History_CAM3D(exportName, exportFldCAM) call HCO_Export_Pbuf_CAM3D(exportNameTmp, -1, exportFldCAM) endif @@ -1624,6 +1606,8 @@ subroutine HCO_GC_Run(GC, IMPORT, EXPORT, Clock, RC) last_HCO_day = now_day last_HCO_second = now_s + IF ( FIRST ) FIRST = .False. + RC = ESMF_SUCCESS end subroutine HCO_GC_Run