LCOV - code coverage report
Current view: | top level - chemistry/mozart - mo_ghg_chem.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 68 | 82 | 82.9 %
Date: | 2024-12-17 22:39:59 |  | Functions: | 4 | 5 | 80.0 %

              Line data    Source code
           1             : !-----------------------------------------------------------------
           2             : ! Manages the reaction rates of the green house gas species.
           3             : ! This is used with the reduced ghg chemical mechanism.
           4             : !
           5             : ! Created by: Francis Vitt -- 20 Aug 2008
           6             : !-----------------------------------------------------------------
           7             : module mo_ghg_chem
           8             :
           9             :   use shr_kind_mod,   only : r8 => shr_kind_r8
          10             :   use boundarydata,   only : boundarydata_type, boundarydata_init, boundarydata_update
          11             :   use physics_types,  only : physics_state
          12             :   use cam_abortutils, only : endrun
          13             :   use ppgrid,         only : pcols, pver, begchunk, endchunk
          14             :
          15             :   implicit none
          16             :
          17             :   private
          18             :   save
          19             :
          20             :   public :: ghg_chem_set_rates
          21             :   public :: ghg_chem_set_flbc
          22             :   public :: ghg_chem_init
          23             :   public :: ghg_chem_timestep_init
          24             :   public :: ghg_chem_final
          25             :
          26             :   integer, parameter :: ncnst=4                      ! number of constituents
          27             :   type(boundarydata_type) :: chemdata
          28             :   character(len=6), dimension(ncnst), parameter :: nc_names = & ! constituent names
          29             :        (/'TN2O  ', 'TCH4  ', 'TCFC11', 'TCFC12'/)
          30             :
          31             :   integer :: n2o_rxt, ch4_rxt, cfc11_rxt, cfc12_rxt, lyman_alpha_rxt
          32             :   integer :: n2o_ndx, ch4_ndx, cfc11_ndx, cfc12_ndx
          33             :   integer :: ghg_ndx(ncnst)
          34             :   character(len=6) :: ghg_bnd_names(ncnst)
          35             :
          36             :   logical :: lyman_alpha = .false.
          37             :   type(boundarydata_type) :: h2orate_data
          38             :   character(len=4), parameter :: h2orate_name = 'jh2o'
          39             :
          40             : contains
          41             :
          42             : !-----------------------------------------------------------------
          43             : !-----------------------------------------------------------------
          44        3072 :   subroutine ghg_chem_init(phys_state, bndtvg, h2orates)
          45             :     use mo_chem_utls, only : get_rxt_ndx, get_spc_ndx
          46             :     use cam_history,  only : addfld
          47             :
          48             :     implicit none
          49             :
          50             :     type(physics_state), intent(in) :: phys_state(begchunk:endchunk)
          51             :     character(len=*),    intent(in) :: bndtvg ! pathname for greenhouse gas loss rate
          52             :     character(len=*),optional,    intent(in) :: h2orates ! lyman-alpha h2o loss rates
          53             :
          54             :     integer    ::  ids(8)
          55             :     integer :: m,mm
          56             :
          57        1536 :     n2o_rxt = get_rxt_ndx( 'n2o_loss' )
          58        1536 :     ch4_rxt = get_rxt_ndx( 'ch4_loss' )
          59        1536 :     cfc11_rxt = get_rxt_ndx( 'cfc11_loss' )
          60        1536 :     cfc12_rxt = get_rxt_ndx( 'cfc12_loss' )
          61        1536 :     lyman_alpha_rxt = get_rxt_ndx( 'lyman_alpha' )
          62             :
          63        1536 :     n2o_ndx = get_spc_ndx('N2O')
          64        1536 :     ch4_ndx = get_spc_ndx('CH4')
          65        1536 :     cfc11_ndx = get_spc_ndx('CFC11')
          66        1536 :     cfc12_ndx = get_spc_ndx('CFC12')
          67             :
          68        1536 :     ids(1) = n2o_rxt
          69        1536 :     ids(2) = ch4_rxt
          70        1536 :     ids(3) = cfc11_rxt
          71        1536 :     ids(4) = cfc12_rxt
          72        1536 :     ids(5) = n2o_ndx
          73        1536 :     ids(6) = ch4_ndx
          74        1536 :     ids(7) = cfc11_ndx
          75        1536 :     ids(8) = cfc12_ndx
          76             :
          77       13824 :     if( any( ids < 1 ) ) then
          78           0 :        call endrun('need to configure with ghg chemistry mechanism')
          79             :     endif
          80             :
          81        1536 :     call boundarydata_init(bndtvg,phys_state,nc_names,ncnst,chemdata)
          82             :
          83        1536 :     if ( present( h2orates ) ) then
          84        1536 :        if ( len_trim( h2orates ) > 0 .and. lyman_alpha_rxt > 0 ) then
          85        1536 :           lyman_alpha = .true.
          86        3072 :           call boundarydata_init(h2orates,phys_state,(/h2orate_name/),1,h2orate_data)
          87             :        endif
          88             :     endif
          89             :
          90        3072 :     call addfld( 'GHG_CFC11_R', (/ 'lev' /), 'I', '1/sec', 'prescribed cfc11 loss rate for ghg chem' )
          91        3072 :     call addfld( 'GHG_CFC12_R', (/ 'lev' /), 'I', '1/sec', 'prescribed cfc12 loss rate for ghg chem' )
          92        3072 :     call addfld( 'GHG_N2O_R',   (/ 'lev' /), 'I', '1/sec', 'prescribed n2o loss rate for ghg chem' )
          93        3072 :     call addfld( 'GHG_CH4_R',   (/ 'lev' /), 'I', '1/sec', 'prescribed ch4 loss rate for ghg chem' )
          94        3072 :     call addfld( 'GHG_H2O_R',   (/ 'lev' /), 'I', '1/sec', 'prescribed h2o loss rate for ghg chem' )
          95             :
          96        7680 :     ghg_ndx =       (/  n2o_ndx,  ch4_ndx, cfc11_ndx, cfc12_ndx /)
          97        7680 :     ghg_bnd_names = (/ 'N2OVMR', 'CH4VMR',  'F11VMR',  'F12VMR' /)
          98             :
          99        1536 :   end subroutine ghg_chem_init
         100             :
         101             : !-----------------------------------------------------------------
         102             : !-----------------------------------------------------------------
         103      370944 :   subroutine ghg_chem_timestep_init(phys_state)
         104             :     implicit none
         105             :
         106             :     type(physics_state), intent(in) :: phys_state(begchunk:endchunk)
         107             :
         108      370944 :     call boundarydata_update(phys_state,chemdata)
         109      370944 :     if (lyman_alpha) then
         110      370944 :        call boundarydata_update(phys_state,h2orate_data)
         111             :     endif
         112        1536 :   end subroutine ghg_chem_timestep_init
         113             :
         114             : !-----------------------------------------------------------------
         115             : !-----------------------------------------------------------------
         116     2978352 :   subroutine ghg_chem_set_rates( rxn_rates, latmapback, zen_angle, ncol, lchnk )
         117             :     use chem_mods,    only : rxntot
         118             :     use cam_history,  only : outfld
         119             :     use mo_constants, only : pi
         120             :
         121             :     implicit none
         122             :
         123             :     integer,  intent(in)    :: ncol                           ! number columns in chunk
         124             :     real(r8), intent(inout) :: rxn_rates(ncol,pver,rxntot)   ! ghg loss rates
         125             :     integer,  intent(in)    :: latmapback(pcols)
         126             :     real(r8), intent(in)    :: zen_angle(ncol)
         127             :     integer,  intent(in)    :: lchnk                          ! chunk index
         128             :
         129             :     integer :: i,k
         130             :     real(r8), parameter :: half_pi = pi/2._r8
         131             :
         132   137004192 :     do k=1,pver-2
         133  2264274792 :        do i=1,ncol
         134  2127270600 :           rxn_rates(i,k,n2o_rxt)   = chemdata%datainst(latmapback(i),k,lchnk,1)
         135  2127270600 :           rxn_rates(i,k,ch4_rxt)   = chemdata%datainst(latmapback(i),k,lchnk,2)
         136  2127270600 :           rxn_rates(i,k,cfc11_rxt) = chemdata%datainst(latmapback(i),k,lchnk,3)
         137  2262785616 :           rxn_rates(i,k,cfc12_rxt) = chemdata%datainst(latmapback(i),k,lchnk,4)
         138             :        enddo
         139             :     enddo
         140             :
         141    51220728 :     rxn_rates(:ncol,pver-1:pver,n2o_rxt)   = 0._r8
         142    51220728 :     rxn_rates(:ncol,pver-1:pver,ch4_rxt)   = 0._r8
         143    51220728 :     rxn_rates(:ncol,pver-1:pver,cfc11_rxt) = 0._r8
         144    51220728 :     rxn_rates(:ncol,pver-1:pver,cfc12_rxt) = 0._r8
         145             :
         146     1489176 :     call outfld( 'GHG_CFC11_R', rxn_rates(:ncol,:,cfc11_rxt), ncol, lchnk )
         147     1489176 :     call outfld( 'GHG_CFC12_R', rxn_rates(:ncol,:,cfc12_rxt), ncol, lchnk )
         148     1489176 :     call outfld( 'GHG_N2O_R',   rxn_rates(:ncol,:,n2o_rxt),   ncol, lchnk )
         149     1489176 :     call outfld( 'GHG_CH4_R',   rxn_rates(:ncol,:,ch4_rxt),   ncol, lchnk )
         150             :
         151     1489176 :     if (lyman_alpha_rxt > 0) then
         152  2314006344 :        rxn_rates(:ncol,:,lyman_alpha_rxt) = 0._r8
         153             :     endif
         154             :
         155     1489176 :     if (lyman_alpha) then
         156    24865776 :        do i=1,ncol
         157    24865776 :           if (zen_angle(i) < half_pi) then
         158  1098700200 :              rxn_rates(i,:,lyman_alpha_rxt) = h2orate_data%datainst(latmapback(i),:,lchnk,1)
         159             :           endif
         160             :        enddo
         161             :
         162     1489176 :        call outfld( 'GHG_H2O_R', rxn_rates(:ncol,:,lyman_alpha_rxt), ncol, lchnk )
         163             :     endif
         164             :
         165     1489176 :   endsubroutine ghg_chem_set_rates
         166             :
         167             : !-----------------------------------------------------------------
         168             : !-----------------------------------------------------------------
         169     2978352 :   subroutine ghg_chem_set_flbc( vmr, ncol )
         170     1489176 :     use chem_surfvals, only : chem_surfvals_get
         171             :     use chem_mods,     only : gas_pcnst
         172             :     use mo_flbc,       only : has_flbc
         173             :     implicit none
         174             :
         175             :     integer,  intent(in)    :: ncol                           ! number columns in chunk
         176             :     real(r8), intent(inout) ::  vmr(ncol,pver,gas_pcnst)              ! xported species (vmr)
         177             :     integer  :: i,ndx
         178             :
         179     7445880 :     do i = 1,ncnst
         180     5956704 :        ndx = ghg_ndx(i)
         181     7445880 :        if ( has_flbc(ndx)) then
         182           0 :           vmr(:ncol, pver-1, ndx) = vmr(:ncol, pver, ndx)
         183             :        else
         184   204882912 :           vmr(:ncol, pver-1:pver, ndx) = chem_surfvals_get(ghg_bnd_names(i))
         185             :        endif
         186             :     enddo
         187             :
         188     1489176 :   endsubroutine ghg_chem_set_flbc
         189             :
         190             : !-----------------------------------------------------------------
         191             : !-----------------------------------------------------------------
         192           0 :   subroutine ghg_chem_final
         193             :     implicit none
         194             :
         195           0 :     deallocate(chemdata%fields)
         196           0 :     deallocate(chemdata%datainst)
         197           0 :     deallocate(chemdata%cdates)
         198           0 :     deallocate(chemdata%lat)
         199           0 :     deallocate(chemdata%zi)
         200             :
         201           0 :     if (lyman_alpha) then
         202             :
         203           0 :        deallocate(h2orate_data%fields)
         204           0 :        deallocate(h2orate_data%datainst)
         205           0 :        deallocate(h2orate_data%cdates)
         206           0 :        deallocate(h2orate_data%lat)
         207           0 :        deallocate(h2orate_data%zi)
         208             :
         209             :     endif
         210             :
         211     1489176 :   end subroutine ghg_chem_final
         212             :
         213             : end module mo_ghg_chem

Generated by: LCOV version 1.14