LCOV - code coverage report
Current view: top level - physics/cam - hk_conv.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 39 28.2 %
Date: 2025-03-13 19:04:48 Functions: 1 3 33.3 %

          Line data    Source code
       1             : ! CAM interface for Hack shallow moist convection
       2             : module hk_conv
       3             :    use shr_kind_mod,     only: r8 => shr_kind_r8
       4             :    use cam_logfile,      only: iulog
       5             :    use spmd_utils,       only: masterproc
       6             :    use cam_abortutils,   only: endrun
       7             : 
       8             :    implicit none
       9             :    private
      10             :    save
      11             : 
      12             :    public :: hkconv_readnl ! Read hkconv_nl namelist
      13             :    public :: mfinti        ! Initialization of data for Hack shallow convection
      14             :    public :: cmfmca_cam    ! CAM wrapper for Hack shallow convection
      15             : 
      16             :    !
      17             :    ! Private data used for Hack shallow convection
      18             :    !
      19             :    real(r8), parameter :: unset_r8 = huge(1.0_r8)
      20             : 
      21             :    ! Namelist variables
      22             :    real(r8) :: hkconv_c0 = unset_r8
      23             :    real(r8) :: hkconv_cmftau = unset_r8
      24             : 
      25             :    real(r8) :: cmftau      ! characteristic adjustment time scale set from namelist input hkconv_cmftau
      26             :    real(r8) :: c0          ! rain water autoconversion coefficient set from namelist input hkconv_c0
      27             : 
      28             : contains
      29        1536 :    subroutine hkconv_readnl(nlfile)
      30             : 
      31             :       use namelist_utils,  only: find_group_name
      32             :       use mpishorthand
      33             : 
      34             :       character(len=*), intent(in) :: nlfile  ! filepath for file containing namelist input
      35             : 
      36             :       ! Local variables
      37             :       integer :: unitn, ierr
      38             :       character(len=*), parameter :: subname = 'hkconv_readnl'
      39             : 
      40             :       namelist /hkconv_nl/ hkconv_cmftau, hkconv_c0
      41             :       !-----------------------------------------------------------------------------
      42             : 
      43        1536 :       if (masterproc) then
      44           2 :          open( newunit=unitn, file=trim(nlfile), status='old' )
      45           2 :          call find_group_name(unitn, 'hkconv_nl', status=ierr)
      46           2 :          if (ierr == 0) then
      47           0 :             read(unitn, hkconv_nl, iostat=ierr)
      48           0 :             if (ierr /= 0) then
      49           0 :                call endrun(subname // ':: ERROR reading namelist')
      50             :             end if
      51             :          end if
      52           2 :          close(unitn)
      53             : 
      54             :          ! set local variables
      55           2 :          cmftau = hkconv_cmftau
      56           2 :          c0     = hkconv_c0
      57             : 
      58             :       end if
      59             : 
      60             : #ifdef SPMD
      61             :       ! Broadcast namelist variables
      62        1536 :       call mpibcast(cmftau,            1, mpir8,  0, mpicom)
      63        1536 :       call mpibcast(c0,                1, mpir8,  0, mpicom)
      64             : #endif
      65             : 
      66        1536 :    end subroutine hkconv_readnl
      67             : 
      68           0 :    subroutine mfinti (rair    ,cpair   ,gravit  ,latvap  ,rhowtr,pref_edge )
      69             :       use spmd_utils, only: masterproc
      70             :       use hack_convect_shallow,     only: hack_convect_shallow_init
      71             :       use ppgrid,     only: pver, pcols
      72             : 
      73             :       real(r8), intent(in) :: rair              ! gas constant for dry air
      74             :       real(r8), intent(in) :: cpair             ! specific heat of dry air
      75             :       real(r8), intent(in) :: gravit            ! acceleration due to gravity
      76             :       real(r8), intent(in) :: latvap            ! latent heat of vaporization
      77             :       real(r8), intent(in) :: rhowtr            ! density of liquid water (STP)
      78             :       real(r8), intent(in)  :: pref_edge(:) ! reference pressures at interface [Pa]
      79             : 
      80             :       character(len=512)   :: errmsg
      81             :       integer              :: errflg
      82             : 
      83             :       ! dummy parameters output from CCPPized scheme.
      84             :       ! the dimensions do not matter as the whole array is assigned zero
      85             :       logical              :: dummy_use_shfrc
      86             :       real(r8)             :: dummy_shfrc_out(pcols, pver)
      87             :       integer              :: dummy_top_lev_out
      88             : 
      89             :       ! Initialize free parameters for moist convective mass flux procedure
      90             :       ! cmftau - characteristic adjustment time scale
      91             :       ! c0     - rain water autoconversion coeff (1/m)
      92             :       !
      93             :       ! call CCPPized subroutine
      94             :       call hack_convect_shallow_init( &
      95             :          pver = pver, &
      96             :          amIRoot = masterproc, &
      97             :          iulog = iulog, &
      98             :          cmftau_in = cmftau, &
      99             :          c0_in = c0, &
     100             :          rair = rair, &
     101             :          cpair = cpair, &
     102             :          gravit = gravit, &
     103             :          latvap = latvap, &
     104             :          rhoh2o_in = rhowtr, &
     105             :          pref_edge = pref_edge, &
     106             :          use_shfrc = dummy_use_shfrc, &
     107             :          shfrc = dummy_shfrc_out, &
     108             :          top_lev = dummy_top_lev_out, &
     109             :          errmsg = errmsg, &
     110             :          errflg = errflg &
     111           0 :       )
     112           0 :    end subroutine mfinti
     113             : 
     114           0 :    subroutine cmfmca_cam(lchnk   ,ncol    , &
     115             :                   nstep   ,ztodt     ,pmid    ,pdel    , &
     116             :                   rpdel   ,zm      ,tpert   ,qpert   ,phis    , &
     117             :                   pblh    ,t       ,q       ,cmfdt   ,dq      , &
     118             :                   cmfmc   ,cmfdqr  ,cmfsl   ,cmflq   ,precc   , &
     119             :                   qc      ,cnt     ,cnb     ,icwmr   ,rliq    , &
     120             :                   pmiddry ,pdeldry ,rpdeldry)
     121             :       use ppgrid,                    only: pcols, pver, pverp
     122             :       use constituents,              only: pcnst
     123             :       use ccpp_constituent_prop_mod, only: ccpp_const_props
     124             : 
     125             :       use hack_convect_shallow, only: hack_convect_shallow_run
     126             :       !
     127             :       ! Input arguments
     128             :       !
     129             :       integer, intent(in) :: lchnk                ! chunk identifier
     130             :       integer, intent(in) :: ncol                 ! number of atmospheric columns
     131             :       integer, intent(in) :: nstep                ! current time step index
     132             : 
     133             :       real(r8), intent(in) :: ztodt               ! physics timestep (seconds)
     134             :       real(r8), intent(in) :: pmid(pcols,pver)    ! pressure
     135             :       real(r8), intent(in) :: pdel(pcols,pver)    ! delta-p
     136             :       real(r8), intent(in) :: pmiddry(pcols,pver)    ! dry air pressure
     137             :       real(r8), intent(in) :: pdeldry(pcols,pver)    ! dry air delta-p
     138             :       real(r8), intent(in) :: rpdel(pcols,pver)   ! 1./pdel
     139             :       real(r8), intent(in) :: rpdeldry(pcols,pver)   ! 1./pdeldry
     140             :       real(r8), intent(in) :: zm(pcols,pver)      ! height abv sfc at midpoints
     141             :       real(r8), intent(in) :: tpert(pcols)        ! PBL perturbation theta
     142             :       real(r8), intent(in) :: qpert(pcols)        ! PBL perturbation specific humidity
     143             :       real(r8), intent(in) :: phis(pcols)         ! surface geopotential
     144             :       real(r8), intent(in) :: pblh(pcols)         ! PBL height (provided by PBL routine)
     145             :       real(r8), intent(in) :: t(pcols,pver)       ! temperature (t bar)
     146             :       real(r8), intent(in) :: q(pcols,pver,pcnst) ! specific humidity (sh bar)
     147             :       !
     148             :       ! Output arguments
     149             :       !
     150             :       real(r8), intent(out) :: cmfdt(pcols,pver)   ! dt/dt due to moist convection
     151             :       real(r8), intent(out) :: cmfmc(pcols,pverp)  ! moist convection cloud mass flux
     152             :       real(r8), intent(out) :: cmfdqr(pcols,pver)  ! dq/dt due to convective rainout
     153             :       real(r8), intent(out) :: cmfsl(pcols,pver )  ! convective lw static energy flux
     154             :       real(r8), intent(out) :: cmflq(pcols,pver )  ! convective total water flux
     155             :       real(r8), intent(out) :: precc(pcols)        ! convective precipitation rate
     156             :       ! JJH mod to explicitly export cloud water
     157             :       real(r8), intent(out) :: qc(pcols,pver)      ! dq/dt due to export of cloud water
     158             :       real(r8), intent(out) :: cnt(pcols)          ! top level of convective activity
     159             :       real(r8), intent(out) :: cnb(pcols)          ! bottom level of convective activity
     160             :       real(r8), intent(out) :: dq(pcols,pver,pcnst) ! constituent tendencies
     161             :       real(r8), intent(out) :: icwmr(pcols,pver)
     162             :       real(r8), intent(out) :: rliq(pcols)
     163             : 
     164             :       ! local variables
     165             :       character(len=512) :: errmsg
     166             :       integer :: errflg
     167             :       character(len=64) :: dummy_scheme_name  ! dummy scheme name for CCPP-ized scheme
     168             :       real(r8) :: flx_cnd(pcols) ! dummy flx_cnd for CCPP-ized scheme (actual check_energy flux computed in convect_shallow)
     169             : 
     170             :       ! integer output arguments for CCPP-ized scheme to be later converted to real
     171           0 :       integer :: cnt_out(ncol)
     172           0 :       integer :: cnb_out(ncol)
     173             : 
     174           0 :       errmsg = ''
     175           0 :       errflg = 0
     176             : 
     177             :       ! zero output arguments to pcols
     178           0 :       cmfdt(:,:) = 0.0_r8
     179           0 :       cmfmc(:,:) = 0.0_r8
     180           0 :       cmfdqr(:,:) = 0.0_r8
     181           0 :       cmfsl(:,:) = 0.0_r8
     182           0 :       cmflq(:,:) = 0.0_r8
     183           0 :       precc(:) = 0.0_r8
     184           0 :       qc(:,:) = 0.0_r8
     185           0 :       cnt(:) = 0.0_r8
     186           0 :       cnb(:) = 0.0_r8
     187           0 :       dq(:,:,:) = 0.0_r8
     188           0 :       icwmr(:,:) = 0.0_r8
     189           0 :       rliq(:) = 0.0_r8
     190             : 
     191             :       ! Call the CCPPized subroutine with subsetting to ncol
     192             :       call hack_convect_shallow_run( &
     193             :          ncol = ncol, &
     194             :          pver = pver, &
     195             :          pcnst = pcnst, &
     196             :          iulog = iulog, &
     197             :          const_props = ccpp_const_props, &
     198             :          ztodt = ztodt, &
     199           0 :          pmid = pmid(:ncol,:), &
     200             :          pmiddry = pmiddry(:ncol,:), &
     201             :          pdel = pdel(:ncol,:), &
     202             :          pdeldry = pdeldry(:ncol,:), &
     203             :          rpdel = rpdel(:ncol,:), &
     204             :          rpdeldry = rpdeldry(:ncol,:), &
     205             :          zm = zm(:ncol,:), &
     206             :          ! tpert is always zero
     207             :          qpert_in = qpert(:ncol), &
     208             :          phis = phis(:ncol), &
     209             :          pblh = pblh(:ncol), &
     210             :          t = t(:ncol,:), &
     211             :          q = q(:ncol,:,:), &
     212             :          dq = dq(:ncol,:,:), &
     213             :          qc_sh = qc(:ncol,:), &
     214             :          cmfdt = cmfdt(:ncol,:), &
     215             :          cmfmc_sh = cmfmc(:ncol,:), &
     216             :          cmfdqr = cmfdqr(:ncol,:), &
     217             :          cmfsl = cmfsl(:ncol,:), &
     218             :          cmflq = cmflq(:ncol,:), &
     219             :          precc = precc(:ncol), &
     220             :          cnt_sh = cnt_out(:ncol), &
     221             :          cnb_sh = cnb_out(:ncol), &
     222             :          icwmr = icwmr(:ncol,:), &
     223             :          rliq_sh = rliq(:ncol), &
     224             :          scheme_name = dummy_scheme_name, &
     225             :          flx_cnd = flx_cnd(:ncol), &
     226             :          errmsg = errmsg, &
     227             :          errflg = errflg &
     228           0 :       )
     229             : 
     230             :       ! convert back to real for diagnostics
     231           0 :       cnt(:ncol) = real(cnt_out(:ncol), r8)
     232           0 :       cnb(:ncol) = real(cnb_out(:ncol), r8)
     233           0 :    end subroutine cmfmca_cam
     234             : 
     235             : end module hk_conv

Generated by: LCOV version 1.14