Skip to content

Commit

Permalink
Merge pull request #73 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Enable use of online lightning flash rates in GEOSCHEMchem
  • Loading branch information
mmanyin authored Apr 7, 2020
2 parents 2c61301 + 60bcf87 commit e3ece8d
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GEOSCHEMchem_GridComp/GEOSCHEMchem_ExtData.rc
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ HTAP_MONTHLY_SO2_RESIDENTIAL '1' Y N 2010-%m2-01T00:00:00 none none emi_so2 /

# Lightning inputs - currently read from external file but eventually this needs to be taken from the online model
LFR_OFFLINE 'km-2s-1' Y N 2017-%m2-01T00:00:00 none none LDENS /discover/nobackup/projects/gmao/geos_cf_dev/gcc_inputs/OFFLINE_LIGHTNING/FLASH_CTH_MERRA2_0.5x0.625_2017_%m2_mean.nc4
CCTH 'm' Y N 2017-%m2-01T00:00:00 none none CTH /discover/nobackup/projects/gmao/geos_cf_dev/gcc_inputs/OFFLINE_LIGHTNING/FLASH_CTH_MERRA2_0.5x0.625_2017_%m2_mean.nc4
CCTH_OFFLINE 'm' Y N 2017-%m2-01T00:00:00 none none CTH /discover/nobackup/projects/gmao/geos_cf_dev/gcc_inputs/OFFLINE_LIGHTNING/FLASH_CTH_MERRA2_0.5x0.625_2017_%m2_mean.nc4

# Masks
DEAD_SFC_TYP NA N V - none none SFC_TYP /discover/nobackup/cakelle2/data/dst_tibds.esmf.2x25.nc
Expand Down
17 changes: 17 additions & 0 deletions GEOSCHEMchem_GridComp/GEOSCHEMchem_GridComp.rc
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,20 @@ ANAO3L3: 72
ANAO3L4: 72
ANAO3FR: 0.2
Use_PCHEM_O3: 0

#
# NOx lightning met inputs
#
# Input source for flash rates: If set to 'LFR' or 'LFR_GCC', the corresponding MOIST export is used. If set to any other
# name, will search for that name in the import state. For instance, set it to 'LFR_OFFLINE' and then define an import via
# ExtData to use LFR values from a file. Default is LFR_GCC. All values expected in [flashes km-2 s-1].
#
LIGHTNING_FLASH_RATE_SOURCE: LFR_GCC
#
# Input source for convective height: If set to 'CNV_MFC', will compute the convective height from convective mass fluxes
# (default). If set to 'BYNCY', will compute it from the buoyancy and convective fraction. For all other cases, will look
# for the field in import and use that as is. For instance, set it to 'CCTH_OFFLINE' and define an import via ExtData to
# use values from an external file. If read from file, the values must be in [m].
#
LIGHTNING_CONVECTIVE_TOP_SOURCE: CNV_MFC
#
310 changes: 307 additions & 3 deletions GEOSCHEMchem_GridComp/GEOSCHEMchem_GridCompMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ SUBROUTINE SetServices( GC, RC )
VERIFY_(STATUS)
#endif

! Define imports to fill met fields needed for lightning
#if defined( MODEL_GEOS )
CALL MetVars_For_Lightning_Init( GC, MyState%myCF, __RC__ )
#endif

!
! !INTERNAL STATE:
!
Expand Down Expand Up @@ -3216,6 +3221,9 @@ SUBROUTINE Run_( GC, Import, Export, Clock, Phase, RC )
REAL, POINTER :: PTR_GCCTO3 (:,:) => NULL()
REAL, POINTER :: PTR_GCCTTO3(:,:) => NULL()

! Lightning
REAL, POINTER :: LFR(:,:) => NULL()

#else
! GCHP only local variables
INTEGER :: trcID, RST
Expand Down Expand Up @@ -3803,6 +3811,9 @@ SUBROUTINE Run_( GC, Import, Export, Clock, Phase, RC )
#endif

#if defined( MODEL_GEOS )
CALL MetVars_For_Lightning_Run( GC, Import=IMPORT, Export=EXPORT, &
State_Met=State_Met, State_Grid=State_Grid, __RC__ )

! Eventually initialize species concentrations from external field.
IF ( InitFromFile ) THEN
IsFirst = ( FIRST .OR. FIRSTREWIND )
Expand Down Expand Up @@ -4504,8 +4515,7 @@ SUBROUTINE Run_( GC, Import, Export, Clock, Phase, RC )
ENDIF

!=======================================================================
! Lightning potential (from GEOS lightning flash rates and convective
! fraction)
! FJX diagnostics
!=======================================================================
if ( phase /= 1 ) then
CALL MAPL_GetPointer( EXPORT, Ptr2D, 'FJX_EXTRAL_NLEVS', &
Expand All @@ -4526,8 +4536,8 @@ SUBROUTINE Run_( GC, Import, Export, Clock, Phase, RC )
NotFoundOk=.TRUE., __RC__ )
IF ( ASSOCIATED(Ptr2D) ) THEN
ASSERT_(ASSOCIATED(LWI)) ! Land-Water-Ice flag
ASSERT_(ASSOCIATED(LFR)) ! GEOS lightning flash rate
ASSERT_(ASSOCIATED(CNV_FRC)) ! Convective fraction
CALL MAPL_GetPointer( IMPORT, LFR, 'LFR', __RC__ )
CALL MAPL_GetPointer( EXPORT, PtrEmis, 'EMIS_NO_LGHT', &
NotFoundOk=.TRUE., __RC__ )
Ptr2D = 0.0
Expand Down Expand Up @@ -7452,7 +7462,301 @@ SUBROUTINE SetAnaO3_( GC, Import, Internal, Export, Clock, &

END SUBROUTINE SetAnaO3_
!EOC
!------------------------------------------------------------------------------
! NASA/GSFC, Global Modeling and Assimilation Office, Code 910.1 and !
! Harvard University Atmospheric Chemistry Modeling Group !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: MetVars_For_Lightning_Init
!
! !DESCRIPTION: Initialize the imports to fill the met variables needed for
! lightning NOx computation
!\\
!\\
! !INTERFACE:
!
SUBROUTINE MetVars_For_Lightning_Init( GC, CF, RC )
!
! !INPUT/OUTPUT PARAMETERS:
!
TYPE(ESMF_GridComp), INTENT(INOUT) :: GC ! Ref. to this GridComp
TYPE(ESMF_Config), INTENT(INOUT) :: CF ! GEOSCHEM*.rc
!
! !OUTPUT PARAMETERS:
!
INTEGER, INTENT(OUT) :: RC ! Success or failure?
!
! !REMARKS:
!
! !REVISION HISTORY:
! 20 Jan 2020 - C. Keller - Initial version
!EOP
!------------------------------------------------------------------------------
!BOC
!
! LOCAL VARIABLES:
!
CHARACTER(LEN=31) :: LfrSrc, CnvSrc

__Iam__('MetVars_For_Lightning_Init')

! Get source for lightning fields
CALL MetVars_For_Lightning_Run( GC, DryRun=.TRUE., CF=CF, &
LfrSrc=LfrSrc, CnvSrc=CnvSrc, __RC__ )

! LFR import - always pass LFR and LFR_GCC. Depending on specification,
! also provide import from external file
call MAPL_AddImportSpec(GC, &
SHORT_NAME='LFR', &
LONG_NAME ='lightning_flash_rate', &
UNITS ='km-2 s-1', &
DIMS = MAPL_DimsHorzOnly, &
VLOCATION = MAPL_VLocationNone, &
__RC__ )

call MAPL_AddImportSpec(GC, &
SHORT_NAME='LFR_GCC', &
LONG_NAME ='lightning_flash_rate', &
UNITS ='km-2 s-1', &
DIMS = MAPL_DimsHorzOnly, &
VLOCATION = MAPL_VLocationNone, &
__RC__ )

IF ( (TRIM(LfrSrc)/='LFR') .AND. &
(TRIM(LfrSrc)/='LFR_GCC') ) THEN
call MAPL_AddImportSpec(GC, &
SHORT_NAME=TRIM(LfrSrc), &
LONG_NAME ='lightning_flash_rate', &
UNITS ='km-2 s-1', &
DIMS = MAPL_DimsHorzOnly, &
VLOCATION = MAPL_VLocationNone, &
__RC__ )
ENDIF

! Import fields needed to compute convective height, depending on specification
SELECT CASE ( TRIM(CnvSrc) )
CASE ( 'CNV_MFC' )
! CNV_MFC is always imported, nothing to do here
!CONTINUE

CASE ( 'BYNCY' )
call MAPL_AddImportSpec(GC, &
SHORT_NAME = 'BYNCY', &
LONG_NAME ='buoyancy_of surface_parcel', &
UNITS ='m s-2', &
DIMS = MAPL_DimsHorzVert, &
VLOCATION = MAPL_VLocationCenter, &
__RC__ )

CASE DEFAULT
call MAPL_AddImportSpec(GC, &
SHORT_NAME=TRIM(CnvSrc), &
LONG_NAME ='convective_cloud_top_from_file', &
UNITS ='m', &
DIMS = MAPL_DimsHorzOnly, &
VLOCATION = MAPL_VLocationNone, &
__RC__ )

END SELECT

! Also add export for CONV_DEPTH_GCC & LFR diagnostics
call MAPL_AddExportSpec(GC, &
SHORT_NAME='GCD_CONV_DEPTH', &
LONG_NAME ='Convective_depth_seen_by_GEOSCHEMchem', &
UNITS ='m', &
DIMS = MAPL_DimsHorzOnly, &
VLOCATION = MAPL_VLocationNone, &
__RC__ )

call MAPL_AddExportSpec(GC, &
SHORT_NAME='GCD_LFR', &
LONG_NAME ='Lightning_flash_rate_seen_GEOSCHEMchem', &
UNITS ='km-2 s-1', &
DIMS = MAPL_DimsHorzOnly, &
VLOCATION = MAPL_VLocationNone, &
__RC__ )


RETURN_(ESMF_SUCCESS)

END SUBROUTINE MetVars_For_Lightning_Init
!EOC
!------------------------------------------------------------------------------
! NASA/GSFC, Global Modeling and Assimilation Office, Code 910.1 and !
! Harvard University Atmospheric Chemistry Modeling Group !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: MetVars_For_Lightning_Run
!
! !DESCRIPTION: Fill the State_Met variables needed for lightning NOx calculation
!\\
!\\
! !INTERFACE:
!
SUBROUTINE MetVars_For_Lightning_Run( GC, Import, Export, State_Met, State_Grid, &
DryRun, CF, LfrSrc, CnvSrc, RC )
!
! !INPUT/OUTPUT PARAMETERS:
!
TYPE(ESMF_GridComp), INTENT(INOUT) :: GC ! Ref. to this GridComp
TYPE(ESMF_State), INTENT(INOUT), OPTIONAL :: Import ! Import State
TYPE(ESMF_State), INTENT(INOUT), OPTIONAL :: Export ! Export State
TYPE(MetState), INTENT(INOUT), OPTIONAL :: State_Met ! Met. state object
TYPE(GrdState), INTENT(IN), OPTIONAL :: State_Grid ! Grid state
LOGICAL, INTENT(IN), OPTIONAL :: DryRun ! Don't fill fields
TYPE(ESMF_Config), INTENT(INOUT), OPTIONAL :: CF ! GEOSCHEM*.rc
!
! !OUTPUT PARAMETERS:
!
CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: LfrSrc ! Lightning flash rate source ID
CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: CnvSrc ! Convective height source ID
INTEGER, INTENT(OUT) :: RC ! Success or failure?
!
! !REMARKS:
!
! !REVISION HISTORY:
! 20 Jan 2020 - C. Keller - Initial version
!EOP
!------------------------------------------------------------------------------
!BOC
!
! LOCAL VARIABLES:
!
INTEGER :: I,J,L
INTEGER :: LTOP
LOGICAL :: am_I_Root
LOGICAL :: Skip
CHARACTER(LEN=31), SAVE :: LFR_SOURCE = ""
CHARACTER(LEN=31), SAVE :: CNV_SOURCE = ""
INTEGER, SAVE :: CNV_ID = -1
REAL, POINTER :: Ptr2d(:,:)
REAL, POINTER :: BYNCY(:,:,:)

__Iam__('MetVars_For_Lightning_Run')
am_I_Root = MAPL_Am_I_Root()

!-LFR source
IF ( TRIM(LFR_SOURCE)=="" .OR. CNV_ID<0 ) THEN
ASSERT_(PRESENT(CF))
CALL ESMF_ConfigGetAttribute( CF, LFR_SOURCE, &
Label="LIGHTNING_FLASH_RATE_SOURCE:", &
Default="LFR_GCC", &
__RC__ )
! Verbose
IF (am_I_Root) THEN
WRITE(*,*) 'GEOSCHEMchem lightning flash rate source: ',TRIM(LFR_SOURCE)
ENDIF

!----Convective height source
CALL ESMF_ConfigGetAttribute( CF, CNV_SOURCE, &
Label="LIGHTNING_CONVECTIVE_TOP_SOURCE:", &
Default="CNV_MFC", &
__RC__ )
SELECT CASE ( TRIM(CNV_SOURCE) )
CASE ( "CNV_MFC" )
CNV_ID = 0
CASE ( "BYNCY" )
CNV_ID = 1
CASE DEFAULT
CNV_ID = 2
END SELECT

! Verbose
IF (am_I_Root) THEN
WRITE(*,*) 'GEOSCHEMchem lightning convective height source: ',TRIM(CNV_SOURCE)
ENDIF

ENDIF

!-Fill state met
IF ( PRESENT(DryRun) ) THEN
Skip = DryRun
ELSE
Skip = .FALSE.
ENDIF
IF ( .NOT. Skip ) THEN

!----Lightning flash rate density [km-2 s-1]
call MAPL_GetPointer ( IMPORT, Ptr2D, TRIM(LFR_SOURCE), __RC__ )
State_Met%FLASH_DENS = Ptr2D

! Eventually add to Export
Ptr2D => NULL()
call MAPL_GetPointer ( EXPORT, Ptr2D, 'GCD_LFR', NotFoundOk=.TRUE., __RC__ )
IF ( ASSOCIATED(Ptr2D) ) Ptr2D = State_Met%FLASH_DENS

!----Convective depth [m]
SELECT CASE ( CNV_ID )
! Convective mass flux
! Get highest level with positive convective mass flux. CNV_MFC is on
! GEOS coordinates (--> 1=top of atmosphere) and on level edges.
CASE ( 0 )
DO J=1,State_Grid%NY
DO I=1,State_Grid%NX
LTOP = 0
DO L = 2,State_Grid%NZ+1
IF ( CNV_MFC(I,J,L) > 0.0 ) THEN
LTOP = (State_Grid%NZ+1) - L + 1
EXIT
ENDIF
ENDDO
IF ( LTOP > 0 ) THEN
State_Met%CONV_DEPTH(I,J) = SUM(State_Met%BXHEIGHT(I,J,1:LTOP))
ELSE
State_Met%CONV_DEPTH(I,J) = 0.0
ENDIF
ENDDO
ENDDO

! Buoyancy and convective fraction
! Get highest level with positive buoyancy and where convective fraction
! is non-zero. BYNCY is on GEOS coordinates (--> 1=top of atmosphere) and
! on level mid-points. LM captures the dimension of CNV_MFC, which is on
! level edges.
CASE ( 1 )
call MAPL_GetPointer ( IMPORT, BYNCY, 'BYNCY', __RC__ )
ASSERT_(ASSOCIATED(CNV_FRC))
DO J=1,State_Grid%NY
DO I=1,State_Grid%NX
LTOP = 0
IF ( CNV_FRC(I,J) > 0.0 ) THEN
DO L = 1,State_Grid%NZ
IF ( BYNCY(I,J,L) > 0.0 ) THEN
LTOP = State_Grid%NZ - L + 1
EXIT
ENDIF
ENDDO
ENDIF
IF ( LTOP > 0 ) THEN
State_Met%CONV_DEPTH(I,J) = SUM(State_Met%BXHEIGHT(I,J,1:LTOP))
ELSE
State_Met%CONV_DEPTH(I,J) = 0.0
ENDIF
ENDDO
ENDDO

! Offline file
CASE ( 2 )
call MAPL_GetPointer ( IMPORT, Ptr2D, TRIM(CNV_SOURCE), __RC__ )
State_Met%CONV_DEPTH = Ptr2D
END SELECT

! Eventually add to Export
Ptr2D => NULL()
call MAPL_GetPointer ( EXPORT, Ptr2D, 'GCD_CONV_DEPTH', NotFoundOk=.TRUE., __RC__ )
IF ( ASSOCIATED(Ptr2D) ) Ptr2D = State_Met%CONV_DEPTH

ENDIF ! Skip

!-Cleanup
IF ( PRESENT(LfrSrc) ) LfrSrc = LFR_SOURCE
IF ( PRESENT(CnvSrc) ) CnvSrc = CNV_SOURCE
RETURN_(ESMF_SUCCESS)

END SUBROUTINE MetVars_For_Lightning_Run
!EOC
!------------------------------------------------------------------------------
! NASA/GSFC, Global Modeling and Assimilation Office, Code 910.1 and !
! Harvard University Atmospheric Chemistry Modeling Group !
Expand Down
4 changes: 0 additions & 4 deletions GEOSCHEMchem_GridComp/GEOSCHEMchem_Registry.rc
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@
U | ms-1 | xyz | C | | | | | | | eastward_wind
V | ms-1 | xyz | C | | | | | | | northward_wind
CNV_FRC | 1 | xy | | | | | | | x | convective_fraction
BYNCY | 1 | xyz | C | | | | | | | buoyancy
Q10M | kg/kg | xy | | | | | | | | 10m_specific_humidity
Q2M | kg/kg | xy | | | | | | | | 2m_specific_humidity
LFR | s-1km-2 | xy | | | | | | | | lightning_flash_rate_density
LFR_OFFLINE | s-1km-2 | xy | | | | | | | | lightning_flash_rate_density_from_offline_source
CCTH | m | xy | | | | | | | | convective_cloud_top_height
#===========
# GCHP only:
#===========
Expand Down
Loading

0 comments on commit e3ece8d

Please sign in to comment.