LCOV - code coverage report
Current view: top level - chemistry/mozart - mo_ghg_chem.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 63 0.0 %
Date: 2024-12-17 17:57:11 Functions: 0 5 0.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           0 :   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           0 :     n2o_rxt = get_rxt_ndx( 'n2o_loss' )
      58           0 :     ch4_rxt = get_rxt_ndx( 'ch4_loss' )
      59           0 :     cfc11_rxt = get_rxt_ndx( 'cfc11_loss' )
      60           0 :     cfc12_rxt = get_rxt_ndx( 'cfc12_loss' )
      61           0 :     lyman_alpha_rxt = get_rxt_ndx( 'lyman_alpha' )
      62             : 
      63           0 :     n2o_ndx = get_spc_ndx('N2O')
      64           0 :     ch4_ndx = get_spc_ndx('CH4')
      65           0 :     cfc11_ndx = get_spc_ndx('CFC11')
      66           0 :     cfc12_ndx = get_spc_ndx('CFC12')
      67             : 
      68           0 :     ids(1) = n2o_rxt   
      69           0 :     ids(2) = ch4_rxt   
      70           0 :     ids(3) = cfc11_rxt 
      71           0 :     ids(4) = cfc12_rxt 
      72           0 :     ids(5) = n2o_ndx   
      73           0 :     ids(6) = ch4_ndx   
      74           0 :     ids(7) = cfc11_ndx 
      75           0 :     ids(8) = cfc12_ndx 
      76             : 
      77           0 :     if( any( ids < 1 ) ) then
      78           0 :        call endrun('need to configure with ghg chemistry mechanism')
      79             :     endif
      80             : 
      81           0 :     call boundarydata_init(bndtvg,phys_state,nc_names,ncnst,chemdata)
      82             : 
      83           0 :     if ( present( h2orates ) ) then
      84           0 :        if ( len_trim( h2orates ) > 0 .and. lyman_alpha_rxt > 0 ) then
      85           0 :           lyman_alpha = .true.
      86           0 :           call boundarydata_init(h2orates,phys_state,(/h2orate_name/),1,h2orate_data)
      87             :        endif
      88             :     endif
      89             : 
      90           0 :     call addfld( 'GHG_CFC11_R', (/ 'lev' /), 'I', '1/sec', 'prescribed cfc11 loss rate for ghg chem' )
      91           0 :     call addfld( 'GHG_CFC12_R', (/ 'lev' /), 'I', '1/sec', 'prescribed cfc12 loss rate for ghg chem' )
      92           0 :     call addfld( 'GHG_N2O_R',   (/ 'lev' /), 'I', '1/sec', 'prescribed n2o loss rate for ghg chem' )
      93           0 :     call addfld( 'GHG_CH4_R',   (/ 'lev' /), 'I', '1/sec', 'prescribed ch4 loss rate for ghg chem' )
      94           0 :     call addfld( 'GHG_H2O_R',   (/ 'lev' /), 'I', '1/sec', 'prescribed h2o loss rate for ghg chem' )
      95             : 
      96           0 :     ghg_ndx =       (/  n2o_ndx,  ch4_ndx, cfc11_ndx, cfc12_ndx /)
      97           0 :     ghg_bnd_names = (/ 'N2OVMR', 'CH4VMR',  'F11VMR',  'F12VMR' /)
      98             : 
      99           0 :   end subroutine ghg_chem_init
     100             : 
     101             : !-----------------------------------------------------------------
     102             : !-----------------------------------------------------------------
     103           0 :   subroutine ghg_chem_timestep_init(phys_state)
     104             :     implicit none
     105             : 
     106             :     type(physics_state), intent(in) :: phys_state(begchunk:endchunk)
     107             : 
     108           0 :     call boundarydata_update(phys_state,chemdata)
     109           0 :     if (lyman_alpha) then
     110           0 :        call boundarydata_update(phys_state,h2orate_data)
     111             :     endif
     112           0 :   end subroutine ghg_chem_timestep_init
     113             : 
     114             : !-----------------------------------------------------------------
     115             : !-----------------------------------------------------------------
     116           0 :   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           0 :     do k=1,pver-2
     133           0 :        do i=1,ncol
     134           0 :           rxn_rates(i,k,n2o_rxt)   = chemdata%datainst(latmapback(i),k,lchnk,1)
     135             :           rxn_rates(i,k,ch4_rxt)   = chemdata%datainst(latmapback(i),k,lchnk,2)
     136             :           rxn_rates(i,k,cfc11_rxt) = chemdata%datainst(latmapback(i),k,lchnk,3)
     137           0 :           rxn_rates(i,k,cfc12_rxt) = chemdata%datainst(latmapback(i),k,lchnk,4)
     138             :        enddo
     139             :     enddo
     140             : 
     141           0 :     rxn_rates(:ncol,pver-1:pver,n2o_rxt)   = 0._r8
     142             :     rxn_rates(:ncol,pver-1:pver,ch4_rxt)   = 0._r8
     143             :     rxn_rates(:ncol,pver-1:pver,cfc11_rxt) = 0._r8
     144             :     rxn_rates(:ncol,pver-1:pver,cfc12_rxt) = 0._r8
     145             : 
     146             :     call outfld( 'GHG_CFC11_R', rxn_rates(:ncol,:,cfc11_rxt), ncol, lchnk )
     147             :     call outfld( 'GHG_CFC12_R', rxn_rates(:ncol,:,cfc12_rxt), ncol, lchnk )
     148             :     call outfld( 'GHG_N2O_R',   rxn_rates(:ncol,:,n2o_rxt),   ncol, lchnk )
     149             :     call outfld( 'GHG_CH4_R',   rxn_rates(:ncol,:,ch4_rxt),   ncol, lchnk )
     150             :     
     151             :     if (lyman_alpha_rxt > 0) then
     152             :        rxn_rates(:ncol,:,lyman_alpha_rxt) = 0._r8 
     153             :     endif
     154             : 
     155             :     if (lyman_alpha) then
     156             :        do i=1,ncol
     157             :           if (zen_angle(i) < half_pi) then
     158             :              rxn_rates(i,:,lyman_alpha_rxt) = h2orate_data%datainst(latmapback(i),:,lchnk,1)
     159             :           endif
     160             :        enddo
     161             : 
     162             :        call outfld( 'GHG_H2O_R', rxn_rates(:ncol,:,lyman_alpha_rxt), ncol, lchnk )
     163             :     endif
     164             : 
     165             :   endsubroutine ghg_chem_set_rates
     166             : 
     167             : !-----------------------------------------------------------------
     168             : !-----------------------------------------------------------------
     169           0 :   subroutine ghg_chem_set_flbc( vmr, ncol )
     170           0 :     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             :     do i = 1,ncnst
     180           0 :        ndx = ghg_ndx(i)
     181           0 :        if ( has_flbc(ndx)) then
     182           0 :           vmr(:ncol, pver-1, ndx) = vmr(:ncol, pver, ndx)
     183             :        else
     184           0 :           vmr(:ncol, pver-1:pver, ndx) = chem_surfvals_get(ghg_bnd_names(i))
     185             :        endif
     186             :     enddo
     187             : 
     188             :   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           0 :   end subroutine ghg_chem_final
     212             : 
     213             : end module mo_ghg_chem

Generated by: LCOV version 1.14