LCOV - code coverage report
Current view: top level - physics/cam - zm_conv_intr.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 343 387 88.6 %
Date: 2025-03-14 01:26:08 Functions: 5 5 100.0 %

          Line data    Source code
       1             : module zm_conv_intr
       2             : !---------------------------------------------------------------------------------
       3             : ! Purpose:
       4             : !
       5             : ! CAM interface to the Zhang-McFarlane deep convection scheme
       6             : !
       7             : ! Author: D.B. Coleman
       8             : ! January 2010 modified by J. Kay to add COSP simulator fields to physics buffer
       9             : !---------------------------------------------------------------------------------
      10             :    use shr_kind_mod, only: r8=>shr_kind_r8
      11             :    use physconst,    only: cpair, epsilo, gravit, latvap, tmelt, rair
      12             :    use ppgrid,       only: pver, pcols, pverp, begchunk, endchunk
      13             :    use zm_conv_evap,         only: zm_conv_evap_run
      14             :    use zm_convr,             only: zm_convr_init, zm_convr_run
      15             :    use zm_conv_convtran,     only: zm_conv_convtran_run
      16             :    use zm_conv_momtran,      only: zm_conv_momtran_run
      17             :    use cloud_fraction_fice,  only: cloud_fraction_fice_run
      18             : 
      19             :    use rad_constituents, only: rad_cnst_get_info, rad_cnst_get_mode_num, rad_cnst_get_aer_mmr, &
      20             :                                rad_cnst_get_aer_props, rad_cnst_get_mode_props !, &
      21             :    use cam_abortutils,   only: endrun
      22             :    use physconst,        only: pi
      23             :    use spmd_utils,       only: masterproc
      24             :    use perf_mod
      25             :    use cam_logfile,  only: iulog
      26             :    use constituents, only: cnst_add
      27             :    use ref_pres,     only: trop_cloud_top_lev
      28             :    use phys_control, only:  phys_getopts
      29             : 
      30             :    implicit none
      31             :    private
      32             :    save
      33             : 
      34             :    ! Public methods
      35             : 
      36             :    public ::&
      37             :       zm_conv_register,           &! register fields in physics buffer
      38             :       zm_conv_readnl,             &! read namelist
      39             :       zm_conv_init,               &! initialize donner_deep module
      40             :       zm_conv_tend,               &! return tendencies
      41             :       zm_conv_tend_2               ! return tendencies
      42             : 
      43             :    public zmconv_ke, zmconv_ke_lnd  ! needed by convect_shallow
      44             : 
      45             :    integer ::& ! indices for fields in the physics buffer
      46             :       zm_mu_idx,      &
      47             :       zm_eu_idx,      &
      48             :       zm_du_idx,      &
      49             :       zm_md_idx,      &
      50             :       zm_ed_idx,      &
      51             :       zm_dp_idx,      &
      52             :       zm_dsubcld_idx, &
      53             :       zm_jt_idx,      &
      54             :       zm_maxg_idx,    &
      55             :       zm_ideep_idx,   &
      56             :       dp_flxprc_idx, &
      57             :       dp_flxsnw_idx, &
      58             :       dp_cldliq_idx, &
      59             :       dp_cldice_idx, &
      60             :       dlfzm_idx,     &     ! detrained convective cloud water mixing ratio.
      61             :       prec_dp_idx,   &
      62             :       snow_dp_idx,   &
      63             :       mconzm_idx           ! convective mass flux
      64             : 
      65             :    real(r8), parameter :: unset_r8 = huge(1.0_r8)
      66             :    real(r8) :: zmconv_c0_lnd = unset_r8
      67             :    real(r8) :: zmconv_c0_ocn = unset_r8
      68             :    real(r8) :: zmconv_ke     = unset_r8
      69             :    real(r8) :: zmconv_ke_lnd = unset_r8
      70             :    real(r8) :: zmconv_momcu  = unset_r8
      71             :    real(r8) :: zmconv_momcd  = unset_r8
      72             :    integer  :: zmconv_num_cin            ! Number of negative buoyancy regions that are allowed
      73             :                                          ! before the convection top and CAPE calculations are completed.
      74             :    real(r8) :: zmconv_dmpdz = unset_r8        ! Parcel fractional mass entrainment rate
      75             :    real(r8) :: zmconv_tiedke_add = unset_r8   ! Convective parcel temperature perturbation
      76             :    real(r8) :: zmconv_capelmt = unset_r8      ! Triggering thereshold for ZM convection
      77             :    logical  :: zmconv_parcel_pbl = .false.           ! switch for parcel pbl calculation
      78             :    real(r8) :: zmconv_parcel_hscale = unset_r8       ! Fraction of PBL depth over which to mix initial parcel
      79             :    real(r8) :: zmconv_tau = unset_r8          ! Timescale for convection
      80             : 
      81             : 
      82             : !  indices for fields in the physics buffer
      83             :    integer  ::    cld_idx          = 0
      84             :    integer  ::    icwmrdp_idx      = 0
      85             :    integer  ::    rprddp_idx       = 0
      86             :    integer  ::    fracis_idx       = 0
      87             :    integer  ::    nevapr_dpcu_idx  = 0
      88             :    integer  ::    dgnum_idx        = 0
      89             : 
      90             :    integer :: nmodes
      91             :    integer :: nbulk
      92             : 
      93             : !=========================================================================================
      94             : contains
      95             : !=========================================================================================
      96             : 
      97       24960 : subroutine zm_conv_register
      98             : 
      99             : !----------------------------------------
     100             : ! Purpose: register fields with the physics buffer
     101             : !----------------------------------------
     102             : 
     103             :   use physics_buffer, only : pbuf_add_field, dtype_r8, dtype_i4
     104             : 
     105             :   implicit none
     106             : 
     107             :   integer idx
     108             : 
     109         768 :    call pbuf_add_field('ZM_MU', 'physpkg', dtype_r8, (/pcols,pver/), zm_mu_idx)
     110         768 :    call pbuf_add_field('ZM_EU', 'physpkg', dtype_r8, (/pcols,pver/), zm_eu_idx)
     111         768 :    call pbuf_add_field('ZM_DU', 'physpkg', dtype_r8, (/pcols,pver/), zm_du_idx)
     112         768 :    call pbuf_add_field('ZM_MD', 'physpkg', dtype_r8, (/pcols,pver/), zm_md_idx)
     113         768 :    call pbuf_add_field('ZM_ED', 'physpkg', dtype_r8, (/pcols,pver/), zm_ed_idx)
     114             : 
     115             :    ! wg layer thickness in mbs (between upper/lower interface).
     116         768 :    call pbuf_add_field('ZM_DP', 'physpkg', dtype_r8, (/pcols,pver/), zm_dp_idx)
     117             : 
     118             :    ! wg layer thickness in mbs between lcl and maxi.
     119         768 :    call pbuf_add_field('ZM_DSUBCLD', 'physpkg', dtype_r8, (/pcols/), zm_dsubcld_idx)
     120             : 
     121             :    ! wg top level index of deep cumulus convection.
     122         768 :    call pbuf_add_field('ZM_JT', 'physpkg', dtype_i4, (/pcols/), zm_jt_idx)
     123             : 
     124             :    ! wg gathered values of maxi.
     125         768 :    call pbuf_add_field('ZM_MAXG', 'physpkg', dtype_i4, (/pcols/), zm_maxg_idx)
     126             : 
     127             :    ! map gathered points to chunk index
     128         768 :    call pbuf_add_field('ZM_IDEEP', 'physpkg', dtype_i4, (/pcols/), zm_ideep_idx)
     129             : 
     130             : ! Flux of precipitation from deep convection (kg/m2/s)
     131         768 :    call pbuf_add_field('DP_FLXPRC','global',dtype_r8,(/pcols,pverp/),dp_flxprc_idx)
     132             : 
     133             : ! Flux of snow from deep convection (kg/m2/s)
     134         768 :    call pbuf_add_field('DP_FLXSNW','global',dtype_r8,(/pcols,pverp/),dp_flxsnw_idx)
     135             : 
     136         768 :    call pbuf_add_field('ICWMRDP',    'physpkg',dtype_r8,(/pcols,pver/),icwmrdp_idx)
     137         768 :    call pbuf_add_field('RPRDDP',     'physpkg',dtype_r8,(/pcols,pver/),rprddp_idx)
     138         768 :    call pbuf_add_field('NEVAPR_DPCU','physpkg',dtype_r8,(/pcols,pver/),nevapr_dpcu_idx)
     139         768 :    call pbuf_add_field('PREC_DP',    'physpkg',dtype_r8,(/pcols/),     prec_dp_idx)
     140         768 :    call pbuf_add_field('SNOW_DP',    'physpkg',dtype_r8,(/pcols/),     snow_dp_idx)
     141             : 
     142             :    ! detrained convective cloud water mixing ratio.
     143         768 :    call pbuf_add_field('DLFZM', 'physpkg', dtype_r8, (/pcols,pver/), dlfzm_idx)
     144             :    ! convective mass fluxes
     145         768 :    call pbuf_add_field('CMFMC_DP', 'physpkg', dtype_r8, (/pcols,pverp/), mconzm_idx)
     146             : 
     147             : 
     148         768 : end subroutine zm_conv_register
     149             : 
     150             : !=========================================================================================
     151             : 
     152         768 : subroutine zm_conv_readnl(nlfile)
     153             : 
     154         768 :    use spmd_utils,      only: mpicom, masterproc, masterprocid, mpi_real8, mpi_integer, mpi_logical
     155             :    use namelist_utils,  only: find_group_name
     156             : 
     157             :    character(len=*), intent(in) :: nlfile  ! filepath for file containing namelist input
     158             : 
     159             :    ! Local variables
     160             :    integer :: unitn, ierr
     161             :    character(len=*), parameter :: subname = 'zm_conv_readnl'
     162             : 
     163             :    namelist /zmconv_nl/ zmconv_c0_lnd, zmconv_c0_ocn, zmconv_num_cin, &
     164             :                         zmconv_ke, zmconv_ke_lnd,  &
     165             :                         zmconv_momcu, zmconv_momcd, &
     166             :                         zmconv_dmpdz, zmconv_tiedke_add, zmconv_capelmt, &
     167             :                         zmconv_parcel_pbl,  zmconv_parcel_hscale, zmconv_tau
     168             :    !-----------------------------------------------------------------------------
     169             : 
     170         768 :    if (masterproc) then
     171           2 :       open( newunit=unitn, file=trim(nlfile), status='old' )
     172           2 :       call find_group_name(unitn, 'zmconv_nl', status=ierr)
     173           2 :       if (ierr == 0) then
     174           2 :          read(unitn, zmconv_nl, iostat=ierr)
     175           2 :          if (ierr /= 0) then
     176           0 :             call endrun(subname // ':: ERROR reading namelist')
     177             :          end if
     178             :       end if
     179           2 :       close(unitn)
     180             : 
     181             :    end if
     182             : 
     183             :    ! Broadcast namelist variables
     184         768 :    call mpi_bcast(zmconv_num_cin,           1, mpi_integer, masterprocid, mpicom, ierr)
     185         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_num_cin")
     186         768 :    call mpi_bcast(zmconv_c0_lnd,            1, mpi_real8,   masterprocid, mpicom, ierr)
     187         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_c0_lnd")
     188         768 :    call mpi_bcast(zmconv_c0_ocn,            1, mpi_real8,   masterprocid, mpicom, ierr)
     189         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_c0_ocn")
     190         768 :    call mpi_bcast(zmconv_ke,                1, mpi_real8,   masterprocid, mpicom, ierr)
     191         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_ke")
     192         768 :    call mpi_bcast(zmconv_ke_lnd,            1, mpi_real8,   masterprocid, mpicom, ierr)
     193         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_ke_lnd")
     194         768 :    call mpi_bcast(zmconv_momcu,             1, mpi_real8,   masterprocid, mpicom, ierr)
     195         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_momcu")
     196         768 :    call mpi_bcast(zmconv_momcd,             1, mpi_real8,   masterprocid, mpicom, ierr)
     197         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_momcd")
     198         768 :    call mpi_bcast(zmconv_dmpdz,             1, mpi_real8, masterprocid, mpicom, ierr)
     199         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_dmpdz")
     200         768 :    call mpi_bcast(zmconv_tiedke_add,        1, mpi_real8, masterprocid, mpicom, ierr)
     201         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_tiedke_add")
     202         768 :    call mpi_bcast(zmconv_capelmt,           1, mpi_real8, masterprocid, mpicom, ierr)
     203         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_capelmt")
     204         768 :    call mpi_bcast(zmconv_parcel_pbl,        1, mpi_logical, masterprocid, mpicom, ierr)
     205         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_parcel_pbl")
     206         768 :    call mpi_bcast(zmconv_parcel_hscale,      1, mpi_real8, masterprocid, mpicom, ierr)
     207         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_parcel_hscale")
     208         768 :    call mpi_bcast(zmconv_tau,               1, mpi_real8, masterprocid, mpicom, ierr)
     209         768 :    if (ierr /= 0) call endrun("zm_conv_readnl: FATAL: mpi_bcast: zmconv_tau")
     210             : 
     211         768 : end subroutine zm_conv_readnl
     212             : 
     213             : !=========================================================================================
     214             : 
     215         768 : subroutine zm_conv_init(pref_edge)
     216             : 
     217             : !----------------------------------------
     218             : ! Purpose:  declare output fields, initialize variables needed by convection
     219             : !----------------------------------------
     220             : 
     221             :   use cam_history,    only: addfld, add_default, horiz_only
     222             :   use ppgrid,         only: pcols, pver
     223             :   use zm_convr,       only: zm_convr_init
     224             :   use pmgrid,         only: plev,plevp
     225             :   use spmd_utils,     only: masterproc
     226             :   use phys_control,   only: phys_deepconv_pbl, phys_getopts, cam_physpkg_is
     227             :   use physics_buffer, only: pbuf_get_index
     228             : 
     229             :   implicit none
     230             : 
     231             :   real(r8),intent(in) :: pref_edge(plevp)        ! reference pressures at interfaces
     232             : 
     233             :   ! local variables
     234             :   real(r8), parameter :: scale_height = 7000._r8  ! std atm scale height (m)
     235             :   real(r8), parameter :: dz_min = 100._r8         ! minimum thickness for using
     236             :                                                   !   zmconv_parcel_pbl=.false.
     237             :   real(r8)            :: dz_bot_layer             ! thickness of bottom layer (m)
     238             : 
     239             :   character(len=512) :: errmsg
     240             :   integer            :: errflg
     241             : 
     242             :   logical :: no_deep_pbl    ! if true, no deep convection in PBL
     243             :   integer  limcnv           ! top interface level limit for convection
     244             :   integer k, istat
     245             :   logical :: history_budget ! output tendencies and state variables for CAM4
     246             :                             ! temperature, water vapor, cloud ice and cloud
     247             :                             ! liquid budgets.
     248             :   integer :: history_budget_histfile_num ! output history file number for budget fields
     249             : 
     250             : !
     251             : ! Register fields with the output buffer
     252             : !
     253             : 
     254         768 :     call addfld ('PRECZ',    horiz_only,   'A', 'm/s','total precipitation from ZM convection')
     255        1536 :     call addfld ('ZMDT',     (/ 'lev' /),  'A', 'K/s','T tendency - Zhang-McFarlane moist convection')
     256        1536 :     call addfld ('ZMDQ',     (/ 'lev' /),  'A', 'kg/kg/s','Q tendency - Zhang-McFarlane moist convection')
     257        1536 :     call addfld ('ZMDICE',   (/ 'lev' /),  'A', 'kg/kg/s','Cloud ice tendency - Zhang-McFarlane convection')
     258        1536 :     call addfld ('ZMDLIQ',   (/ 'lev' /),  'A', 'kg/kg/s','Cloud liq tendency - Zhang-McFarlane convection')
     259        1536 :     call addfld ('EVAPTZM',  (/ 'lev' /),  'A', 'K/s','T tendency - Evaporation/snow prod from Zhang convection')
     260        1536 :     call addfld ('FZSNTZM',  (/ 'lev' /),  'A', 'K/s','T tendency - Rain to snow conversion from Zhang convection')
     261        1536 :     call addfld ('EVSNTZM',  (/ 'lev' /),  'A', 'K/s','T tendency - Snow to rain prod from Zhang convection')
     262        1536 :     call addfld ('EVAPQZM',  (/ 'lev' /),  'A', 'kg/kg/s','Q tendency - Evaporation from Zhang-McFarlane moist convection')
     263             : 
     264        1536 :     call addfld ('ZMFLXPRC', (/ 'ilev' /), 'A', 'kg/m2/s','Flux of precipitation from ZM convection'       )
     265        1536 :     call addfld ('ZMFLXSNW', (/ 'ilev' /), 'A', 'kg/m2/s','Flux of snow from ZM convection'                )
     266        1536 :     call addfld ('ZMNTPRPD', (/ 'lev' /) , 'A', 'kg/kg/s','Net precipitation production from ZM convection')
     267        1536 :     call addfld ('ZMNTSNPD', (/ 'lev' /) , 'A', 'kg/kg/s','Net snow production from ZM convection'         )
     268        1536 :     call addfld ('ZMEIHEAT', (/ 'lev' /) , 'A', 'W/kg'   ,'Heating by ice and evaporation in ZM convection')
     269             : 
     270        1536 :     call addfld ('CMFMC_DP', (/ 'ilev' /), 'A', 'kg/m2/s','Convection mass flux from ZM deep ')
     271         768 :     call addfld ('PRECCDZM', horiz_only,   'A', 'm/s','Convective precipitation rate from ZM deep')
     272             : 
     273         768 :     call addfld ('PCONVB',   horiz_only ,  'A', 'Pa'    ,'convection base pressure')
     274         768 :     call addfld ('PCONVT',   horiz_only ,  'A', 'Pa'    ,'convection top  pressure')
     275             : 
     276         768 :     call addfld ('CAPE',     horiz_only,   'A', 'J/kg', 'Convectively available potential energy')
     277         768 :     call addfld ('FREQZM',   horiz_only  , 'A', 'fraction', 'Fractional occurance of ZM convection')
     278             : 
     279        1536 :     call addfld ('ZMMTT',    (/ 'lev' /),  'A', 'K/s', 'T tendency - ZM convective momentum transport')
     280        1536 :     call addfld ('ZMMTU',    (/ 'lev' /),  'A', 'm/s2', 'U tendency - ZM convective momentum transport')
     281        1536 :     call addfld ('ZMMTV',    (/ 'lev' /),  'A', 'm/s2', 'V tendency - ZM convective momentum transport')
     282             : 
     283        1536 :     call addfld ('ZMMU',     (/ 'lev' /),  'A', 'kg/m2/s', 'ZM convection updraft mass flux')
     284        1536 :     call addfld ('ZMMD',     (/ 'lev' /),  'A', 'kg/m2/s', 'ZM convection downdraft mass flux')
     285             : 
     286        1536 :     call addfld ('ZMUPGU',   (/ 'lev' /),  'A', 'm/s2', 'zonal force from ZM updraft pressure gradient term')
     287        1536 :     call addfld ('ZMUPGD',   (/ 'lev' /),  'A', 'm/s2', 'zonal force from ZM downdraft pressure gradient term')
     288        1536 :     call addfld ('ZMVPGU',   (/ 'lev' /),  'A', 'm/s2', 'meridional force from ZM updraft pressure gradient term')
     289        1536 :     call addfld ('ZMVPGD',   (/ 'lev' /),  'A', 'm/s2', 'merdional force from ZM downdraft pressure gradient term')
     290             : 
     291        1536 :     call addfld ('ZMICUU',   (/ 'lev' /),  'A', 'm/s', 'ZM in-cloud U updrafts')
     292        1536 :     call addfld ('ZMICUD',   (/ 'lev' /),  'A', 'm/s', 'ZM in-cloud U downdrafts')
     293        1536 :     call addfld ('ZMICVU',   (/ 'lev' /),  'A', 'm/s', 'ZM in-cloud V updrafts')
     294        1536 :     call addfld ('ZMICVD',   (/ 'lev' /),  'A', 'm/s', 'ZM in-cloud V downdrafts')
     295             : 
     296        1536 :     call addfld ('DLFZM'   ,(/ 'lev' /), 'A','kg/kg/s ','Detrained liquid water from ZM convection')
     297             : 
     298             :     call phys_getopts( history_budget_out = history_budget, &
     299         768 :                        history_budget_histfile_num_out = history_budget_histfile_num)
     300             : 
     301         768 :     if ( history_budget ) then
     302           0 :        call add_default('EVAPTZM  ', history_budget_histfile_num, ' ')
     303           0 :        call add_default('EVAPQZM  ', history_budget_histfile_num, ' ')
     304           0 :        call add_default('ZMDT     ', history_budget_histfile_num, ' ')
     305           0 :        call add_default('ZMDQ     ', history_budget_histfile_num, ' ')
     306           0 :        call add_default('ZMDLIQ   ', history_budget_histfile_num, ' ')
     307           0 :        call add_default('ZMDICE   ', history_budget_histfile_num, ' ')
     308           0 :        call add_default('ZMMTT    ', history_budget_histfile_num, ' ')
     309             :     end if
     310             : 
     311             : !
     312             : ! Limit deep convection to regions below 40 mb
     313             : ! Note this calculation is repeated in the shallow convection interface
     314             : !
     315         768 :     limcnv = 0   ! null value to check against below
     316         768 :     if (pref_edge(1) >= 4.e3_r8) then
     317           0 :        limcnv = 1
     318             :     else
     319       79872 :        do k=1,plev
     320       79872 :           if (pref_edge(k) < 4.e3_r8 .and. pref_edge(k+1) >= 4.e3_r8) then
     321         768 :              limcnv = k
     322         768 :              exit
     323             :           end if
     324             :        end do
     325         768 :        if ( limcnv == 0 ) limcnv = plevp
     326             :     end if
     327             : 
     328         768 :     if (masterproc) then
     329           2 :        write(iulog,*)'ZM_CONV_INIT: Deep convection will be capped at intfc ',limcnv, &
     330           4 :             ' which is ',pref_edge(limcnv),' pascals'
     331             :     end if
     332             : 
     333             :     ! If thickness of bottom layer is less than dz_min, and zmconv_parcel_pbl=.false.,
     334             :     ! then issue a warning.
     335         768 :     dz_bot_layer = scale_height * log(pref_edge(pverp)/pref_edge(pver))
     336         768 :     if (dz_bot_layer < dz_min .and. .not. zmconv_parcel_pbl) then
     337           0 :        if (masterproc) then
     338           0 :           write(iulog,*)'********** WARNING **********'
     339           0 :           write(iulog,*)' ZM_CONV_INIT: Bottom layer thickness (m) is ', dz_bot_layer
     340           0 :           write(iulog,*)' The namelist variable zmconv_parcel_pbl should be set to .true.'
     341           0 :           write(iulog,*)' when the bottom layer thickness is < ', dz_min
     342           0 :           write(iulog,*)'********** WARNING **********'
     343             :        end if
     344             :     end if
     345             : 
     346         768 :     no_deep_pbl = phys_deepconv_pbl()
     347             :     call zm_convr_init(plev, plevp, cpair, epsilo, gravit, latvap, tmelt, rair, &
     348             :                   pref_edge,zmconv_c0_lnd, zmconv_c0_ocn, zmconv_ke, zmconv_ke_lnd, &
     349             :                   zmconv_momcu, zmconv_momcd, zmconv_num_cin,  &
     350             :                   no_deep_pbl, zmconv_tiedke_add, &
     351             :                   zmconv_capelmt, zmconv_dmpdz,zmconv_parcel_pbl, zmconv_parcel_hscale, zmconv_tau, &
     352         768 :                   masterproc, iulog, errmsg, errflg)
     353             : 
     354         768 :       if (errflg /= 0) then
     355           0 :          call endrun('From zm_convr_init:'  // errmsg)
     356             :       end if
     357             : 
     358         768 :     cld_idx         = pbuf_get_index('CLD')
     359         768 :     fracis_idx      = pbuf_get_index('FRACIS')
     360             : 
     361         768 : end subroutine zm_conv_init
     362             : !=========================================================================================
     363             : !subroutine zm_conv_tend(state, ptend, tdt)
     364             : 
     365     2467584 : subroutine zm_conv_tend(pblh    ,mcon    ,cme     , &
     366             :      tpert   ,zdu      , &
     367             :      rliq    ,rice    ,ztodt    , &
     368             :      jctop   ,jcbot , &
     369             :      state   ,ptend_all   ,landfrac,  pbuf)
     370             : 
     371             : 
     372         768 :    use cam_history,   only: outfld
     373             :    use physics_types, only: physics_state, physics_ptend
     374             :    use physics_types, only: physics_ptend_init, physics_update
     375             :    use physics_types, only: physics_state_copy, physics_state_dealloc
     376             :    use physics_types, only: physics_ptend_sum, physics_ptend_dealloc
     377             : 
     378             :    use time_manager,  only: get_nstep, is_first_step
     379             :    use physics_buffer, only : pbuf_get_field, physics_buffer_desc, pbuf_old_tim_idx
     380             :    use constituents,  only: pcnst, cnst_get_ind, cnst_is_convtran1
     381             :    use physconst,     only: gravit, latice, latvap, tmelt, cpwv, cpliq, rh2o
     382             :    use phys_grid,     only: get_rlat_all_p, get_rlon_all_p
     383             : 
     384             :    use phys_control,  only: cam_physpkg_is
     385             :    use ccpp_constituent_prop_mod, only: ccpp_const_props
     386             : 
     387             :    ! Arguments
     388             : 
     389             :    type(physics_state), intent(in),target   :: state          ! Physics state variables
     390             :    type(physics_ptend), intent(out)         :: ptend_all      ! individual parameterization tendencies
     391             :    type(physics_buffer_desc), pointer       :: pbuf(:)
     392             : 
     393             :    real(r8), intent(in) :: ztodt                       ! 2 delta t (model time increment)
     394             :    real(r8), intent(in) :: pblh(pcols)                 ! Planetary boundary layer height
     395             :    real(r8), intent(in) :: tpert(pcols)                ! Thermal temperature excess
     396             :    real(r8), intent(in) :: landfrac(pcols)             ! RBN - Landfrac
     397             : 
     398             :    real(r8), intent(out) :: mcon(pcols,pverp)  ! Convective mass flux--m sub c
     399             :    real(r8), intent(out) :: cme(pcols,pver)    ! cmf condensation - evaporation
     400             :    real(r8), intent(out) :: zdu(pcols,pver)    ! detraining mass flux
     401             : 
     402             :    real(r8), intent(out) :: rliq(pcols) ! reserved liquid (not yet in cldliq) for energy integrals
     403             :    real(r8), intent(out) :: rice(pcols) ! reserved ice (not yet in cldice) for energy integrals
     404             : 
     405             : 
     406             :    ! Local variables
     407             :    character(len=512) :: errmsg
     408             :    integer            :: errflg
     409             : 
     410             :    integer :: i,k,l,m
     411             :    integer :: ilon                      ! global longitude index of a column
     412             :    integer :: ilat                      ! global latitude index of a column
     413             :    integer :: nstep
     414             :    integer :: ixcldice, ixcldliq      ! constituent indices for cloud liquid and ice water.
     415             :    integer :: lchnk                   ! chunk identifier
     416             :    integer :: ncol                    ! number of atmospheric columns
     417             :    integer :: itim_old                ! for physics buffer fields
     418             : 
     419             :    real(r8) :: ftem(pcols,pver)              ! Temporary workspace for outfld variables
     420             :    real(r8) :: ntprprd(pcols,pver)    ! evap outfld: net precip production in layer
     421             :    real(r8) :: ntsnprd(pcols,pver)    ! evap outfld: net snow production in layer
     422             :    real(r8) :: tend_s_snwprd  (pcols,pver) ! Heating rate of snow production
     423             :    real(r8) :: tend_s_snwevmlt(pcols,pver) ! Heating rate of evap/melting of snow
     424             :    real(r8) :: fake_dpdry(pcols,pver) ! used in convtran call
     425             : 
     426             :    ! physics types
     427       24192 :    type(physics_state) :: state1        ! locally modify for evaporation to use, not returned
     428     2467584 :    type(physics_ptend),target :: ptend_loc     ! package tendencies
     429             : 
     430             :    ! physics buffer fields
     431       24192 :    real(r8), pointer, dimension(:)   :: prec         ! total precipitation
     432       24192 :    real(r8), pointer, dimension(:)   :: snow         ! snow from ZM convection
     433       24192 :    real(r8), pointer, dimension(:,:) :: cld
     434       24192 :    real(r8), pointer, dimension(:,:) :: ql           ! wg grid slice of cloud liquid water.
     435       24192 :    real(r8), pointer, dimension(:,:) :: rprd         ! rain production rate
     436       24192 :    real(r8), pointer, dimension(:,:,:) :: fracis  ! fraction of transported species that are insoluble
     437       24192 :    real(r8), pointer, dimension(:,:) :: evapcdp      ! Evaporation of deep convective precipitation
     438       24192 :    real(r8), pointer, dimension(:,:) :: flxprec      ! Convective-scale flux of precip at interfaces (kg/m2/s)
     439       24192 :    real(r8), pointer, dimension(:,:) :: flxsnow      ! Convective-scale flux of snow   at interfaces (kg/m2/s)
     440       24192 :    real(r8), pointer :: dlf(:,:)    ! detrained convective cloud water mixing ratio.
     441             :    real(r8), pointer :: lambdadpcu(:,:) ! slope of cloud liquid size distr
     442             :    real(r8), pointer :: mudpcu(:,:)     ! width parameter of droplet size distr
     443       24192 :    real(r8), pointer :: mconzm(:,:)     !convective mass fluxes
     444             : 
     445       24192 :    real(r8), pointer :: mu(:,:)    ! (pcols,pver)
     446       24192 :    real(r8), pointer :: eu(:,:)    ! (pcols,pver)
     447       24192 :    real(r8), pointer :: du(:,:)    ! (pcols,pver)
     448       24192 :    real(r8), pointer :: md(:,:)    ! (pcols,pver)
     449       24192 :    real(r8), pointer :: ed(:,:)    ! (pcols,pver)
     450       24192 :    real(r8), pointer :: dp(:,:)    ! (pcols,pver)
     451       24192 :    real(r8), pointer :: dsubcld(:) ! (pcols)
     452       24192 :    integer,  pointer :: jt(:)      ! (pcols)
     453       24192 :    integer,  pointer :: maxg(:)    ! (pcols)
     454       24192 :    integer,  pointer :: ideep(:)   ! (pcols)
     455             :    integer           :: lengath
     456             : 
     457             :    real(r8) :: jctop(pcols)  ! o row of top-of-deep-convection indices passed out.
     458             :    real(r8) :: jcbot(pcols)  ! o row of base of cloud indices passed out.
     459             : 
     460             :    real(r8) :: pcont(pcols), pconb(pcols), freqzm(pcols)
     461             : 
     462             :    real(r8) :: lat_all(pcols), long_all(pcols)
     463             : 
     464             :    ! history output fields
     465             :    real(r8) :: cape(pcols)        ! w  convective available potential energy.
     466             :    real(r8) :: mu_out(pcols,pver)
     467             :    real(r8) :: md_out(pcols,pver)
     468             :    real(r8) :: dif(pcols,pver)
     469             : 
     470             :    ! used in momentum transport calculation
     471             :    real(r8) :: pguallu(pcols, pver)
     472             :    real(r8) :: pguallv(pcols, pver)
     473             :    real(r8) :: pgdallu(pcols, pver)
     474             :    real(r8) :: pgdallv(pcols, pver)
     475             :    real(r8) :: icwuu(pcols,pver)
     476             :    real(r8) :: icwuv(pcols,pver)
     477             :    real(r8) :: icwdu(pcols,pver)
     478             :    real(r8) :: icwdv(pcols,pver)
     479             :    real(r8) :: seten(pcols, pver)
     480             :    logical  :: l_windt
     481             :    real(r8) :: tfinal1, tfinal2
     482             :    integer  :: ii
     483             : 
     484             :    real(r8) :: fice(pcols,pver)
     485             :    real(r8) :: fsnow_conv(pcols,pver)
     486             : 
     487             :    logical  :: lq(pcnst)
     488             :    character(len=16) :: macrop_scheme
     489             :    character(len=40) :: scheme_name
     490             :    character(len=40) :: str
     491             :    integer :: top_lev
     492             : 
     493             :    !----------------------------------------------------------------------
     494             : 
     495             :    ! initialize
     496       24192 :    lchnk = state%lchnk
     497       24192 :    ncol  = state%ncol
     498       24192 :    nstep = get_nstep()
     499             : 
     500       24192 :    ftem = 0._r8
     501       24192 :    mu_out(:,:) = 0._r8
     502       24192 :    md_out(:,:) = 0._r8
     503             : 
     504       24192 :    call physics_state_copy(state,state1)             ! copy state to local state1.
     505             : 
     506       24192 :    lq(:) = .FALSE.
     507       24192 :    lq(1) = .TRUE.
     508       24192 :    call physics_ptend_init(ptend_loc, state%psetcols, 'zm_convr_run', ls=.true., lq=lq)! initialize local ptend type
     509             : 
     510             : !
     511             : ! Associate pointers with physics buffer fields
     512             : !
     513       24192 :    itim_old = pbuf_old_tim_idx()
     514       96768 :    call pbuf_get_field(pbuf, cld_idx,         cld,    start=(/1,1,itim_old/), kount=(/pcols,pver,1/) )
     515             : 
     516       24192 :    call pbuf_get_field(pbuf, icwmrdp_idx,     ql )
     517       24192 :    call pbuf_get_field(pbuf, rprddp_idx,      rprd )
     518       24192 :    call pbuf_get_field(pbuf, fracis_idx,      fracis, start=(/1,1,1/),    kount=(/pcols, pver, pcnst/) )
     519       24192 :    call pbuf_get_field(pbuf, nevapr_dpcu_idx, evapcdp )
     520       24192 :    call pbuf_get_field(pbuf, prec_dp_idx,     prec )
     521       24192 :    call pbuf_get_field(pbuf, snow_dp_idx,     snow )
     522             : 
     523       24192 :    call pbuf_get_field(pbuf, zm_mu_idx,      mu)
     524       24192 :    call pbuf_get_field(pbuf, zm_eu_idx,      eu)
     525       24192 :    call pbuf_get_field(pbuf, zm_du_idx,      du)
     526       24192 :    call pbuf_get_field(pbuf, zm_md_idx,      md)
     527       24192 :    call pbuf_get_field(pbuf, zm_ed_idx,      ed)
     528       24192 :    call pbuf_get_field(pbuf, zm_dp_idx,      dp)
     529       24192 :    call pbuf_get_field(pbuf, zm_dsubcld_idx, dsubcld)
     530       24192 :    call pbuf_get_field(pbuf, zm_jt_idx,      jt)
     531       24192 :    call pbuf_get_field(pbuf, zm_maxg_idx,    maxg)
     532       24192 :    call pbuf_get_field(pbuf, zm_ideep_idx,   ideep)
     533             : 
     534       24192 :    call pbuf_get_field(pbuf, dlfzm_idx,  dlf)
     535       24192 :    call pbuf_get_field(pbuf, mconzm_idx, mconzm)
     536             : 
     537             : ! Begin with Zhang-McFarlane (1996) convection parameterization
     538             : !
     539       24192 :    call t_startf ('zm_convr_run')
     540             : 
     541             : !REMOVECAM - no longer need these when CAM is retired and pcols no longer exists
     542    53488512 :    ptend_loc%q(:,:,1) = 0._r8
     543    53488512 :    ptend_loc%s(:,:) = 0._r8
     544       24192 :    dif(:,:) = 0._r8
     545       24192 :    mcon(:,:) = 0._r8
     546    53488512 :    dlf(:,:) = 0._r8
     547       24192 :    cme(:,:) = 0._r8
     548       24192 :    cape(:) = 0._r8
     549       24192 :    zdu(:,:) = 0._r8
     550    53488512 :    rprd(:,:) = 0._r8
     551    53488512 :    mu(:,:) = 0._r8
     552    53488512 :    eu(:,:) = 0._r8
     553    53488512 :    du(:,:) = 0._r8
     554    53488512 :    md(:,:) = 0._r8
     555    53488512 :    ed(:,:) = 0._r8
     556    53488512 :    dp(:,:) = 0._r8
     557      411264 :    dsubcld(:) = 0._r8
     558       24192 :    jctop(:) = 0._r8
     559       24192 :    jcbot(:) = 0._r8
     560      411264 :    prec(:) = 0._r8
     561       24192 :    rliq(:) = 0._r8
     562       24192 :    rice(:) = 0._r8
     563      411264 :    ideep(:) = 0._r8
     564             : !REMOVECAM_END
     565             : 
     566             : 
     567       24192 :    call get_rlat_all_p(lchnk, ncol, lat_all)
     568       24192 :    call get_rlon_all_p(lchnk, ncol, long_all)
     569             : 
     570             :    call zm_convr_run(ncol, pver, &
     571             :                     pverp, gravit, latice, cpwv, cpliq, rh2o,  &
     572             :                     lat_all, long_all, &
     573           0 :                     state%t(:ncol,:), state%q(:ncol,:,1), prec(:ncol),  &
     574           0 :                     pblh(:ncol), state%zm(:ncol,:), state%phis(:ncol), state%zi(:ncol,:), ptend_loc%q(:ncol,:,1), &
     575           0 :                     ptend_loc%s(:ncol,:), state%pmid(:ncol,:), state%pint(:ncol,:), state%pdel(:ncol,:), &
     576             :                     ztodt, mcon(:ncol,:), cme(:ncol,:), cape(:ncol),      &
     577           0 :                     tpert(:ncol), dlf(:ncol,:), dif(:ncol,:), zdu(:ncol,:), rprd(:ncol,:), &
     578           0 :                     mu(:ncol,:), md(:ncol,:), du(:ncol,:), eu(:ncol,:), ed(:ncol,:),       &
     579           0 :                     dp(:ncol,:), dsubcld(:ncol), jt(:ncol), maxg(:ncol), ideep(:ncol),    &
     580           0 :                     ql(:ncol,:),  rliq(:ncol), landfrac(:ncol),                          &
     581       24192 :                     rice(:ncol), lengath, scheme_name, errmsg, errflg)
     582             : 
     583       24192 :    if (errflg /= 0) then
     584           0 :      write(str,*) 'From zm_convr_run: at chunk ',lchnk, ' : '
     585           0 :      call endrun(str // errmsg)
     586             :    end if
     587             : 
     588      411264 :    jctop(:) = real(pver,r8)
     589      411264 :    jcbot(:) = 1._r8
     590      109369 :    do i = 1,lengath
     591       85177 :       jctop(ideep(i)) = real(jt(i), r8)
     592      109369 :       jcbot(ideep(i)) = real(maxg(i), r8)
     593             :    end do
     594             : 
     595       24192 :    call outfld('CAPE', cape, pcols, lchnk)        ! RBN - CAPE output
     596             : !
     597             : ! Output fractional occurance of ZM convection
     598             : !
     599       24192 :    freqzm(:) = 0._r8
     600      109369 :    do i = 1,lengath
     601      109369 :       freqzm(ideep(i)) = 1.0_r8
     602             :    end do
     603       24192 :    call outfld('FREQZM  ',freqzm          ,pcols   ,lchnk   )
     604             : 
     605    41223168 :    mconzm(:ncol,:pverp) = mcon(:ncol,:pverp)
     606             : 
     607       24192 :    call outfld('CMFMC_DP', mconzm, pcols, lchnk)
     608             : 
     609             :    ! Store upward and downward mass fluxes in un-gathered arrays
     610             :    ! + convert from mb/s to kg/m^2/s
     611      109369 :    do i=1,lengath
     612    11182379 :       do k=1,pver
     613    11073010 :          ii = ideep(i)
     614    11073010 :          mu_out(ii,k) = mu(i,k) * 100._r8/gravit
     615    11158187 :          md_out(ii,k) = md(i,k) * 100._r8/gravit
     616             :       end do
     617             :    end do
     618             : 
     619       24192 :    call outfld('ZMMU', mu_out, pcols, lchnk)
     620       24192 :    call outfld('ZMMD', md_out, pcols, lchnk)
     621             : 
     622    40908672 :    ftem(:ncol,:pver) = ptend_loc%s(:ncol,:pver)/cpair
     623       24192 :    call outfld('ZMDT    ',ftem           ,pcols   ,lchnk   )
     624       24192 :    call outfld('ZMDQ    ',ptend_loc%q(1,1,1) ,pcols   ,lchnk   )
     625       24192 :    call t_stopf ('zm_convr_run')
     626             : 
     627       24192 :    call outfld('DLFZM'   ,dlf            ,pcols, lchnk)
     628             : 
     629      314496 :    pcont(:ncol) = state%ps(:ncol)
     630      314496 :    pconb(:ncol) = state%ps(:ncol)
     631      109369 :    do i = 1,lengath
     632      109369 :        if (maxg(i).gt.jt(i)) then
     633       85177 :           pcont(ideep(i)) = state%pmid(ideep(i),jt(i))  ! gathered array (or jctop ungathered)
     634       85177 :           pconb(ideep(i)) = state%pmid(ideep(i),maxg(i))! gathered array
     635             :        endif
     636             :        !     write(iulog,*) ' pcont, pconb ', pcont(i), pconb(i), cnt(i), cnb(i)
     637             :     end do
     638       24192 :     call outfld('PCONVT  ',pcont          ,pcols   ,lchnk   )
     639       24192 :     call outfld('PCONVB  ',pconb          ,pcols   ,lchnk   )
     640             : 
     641       24192 :   call physics_ptend_init(ptend_all, state%psetcols, 'zm_conv_tend')
     642             : 
     643             :   ! add tendency from this process to tendencies from other processes
     644       24192 :   call physics_ptend_sum(ptend_loc,ptend_all, ncol)
     645             : 
     646             :   ! update physics state type state1 with ptend_loc
     647       24192 :   call physics_update(state1, ptend_loc, ztodt)
     648             : 
     649             :   ! initialize ptend for next process
     650       24192 :   lq(:) = .FALSE.
     651       24192 :   lq(1) = .TRUE.
     652       24192 :   call physics_ptend_init(ptend_loc, state1%psetcols, 'zm_conv_evap_run', ls=.true., lq=lq)
     653             : 
     654       24192 :    call t_startf ('zm_conv_evap_run')
     655             : !
     656             : ! Determine the phase of the precipitation produced and add latent heat of fusion
     657             : ! Evaporate some of the precip directly into the environment (Sundqvist)
     658             : ! Allow this to use the updated state1 and the fresh ptend_loc type
     659             : ! heating and specific humidity tendencies produced
     660             : !
     661             : 
     662       24192 :     call pbuf_get_field(pbuf, dp_flxprc_idx, flxprec    )
     663       24192 :     call pbuf_get_field(pbuf, dp_flxsnw_idx, flxsnow    )
     664             : !REMOVECAM - no longer need these when CAM is retired and pcols no longer exists
     665    53899776 :     flxprec(:,:) = 0._r8
     666    53899776 :     flxsnow(:,:) = 0._r8
     667      411264 :     snow(:) = 0._r8
     668       24192 :     fice(:,:) = 0._r8
     669       24192 :     fsnow_conv(:,:) = 0._r8
     670             : !REMOVECAM_END
     671             : 
     672       24192 :     top_lev = 1
     673       24192 :     call phys_getopts (macrop_scheme_out  = macrop_scheme)
     674       24192 :     if ( .not. (macrop_scheme == "rk")) top_lev = trop_cloud_top_lev
     675             : 
     676       24192 :     call cloud_fraction_fice_run(ncol, state1%t(:ncol,:), tmelt, top_lev, pver, fice(:ncol,:), fsnow_conv(:ncol,:), errmsg, errflg)
     677             : 
     678             :     call zm_conv_evap_run(state1%ncol, pver, pverp, &
     679             :          gravit, latice, latvap, tmelt, &
     680             :          cpair, zmconv_ke, zmconv_ke_lnd, &
     681           0 :          state1%t(:ncol,:),state1%pmid(:ncol,:),state1%pdel(:ncol,:),state1%q(:ncol,:pver,1), &
     682           0 :          landfrac(:ncol), &
     683           0 :          ptend_loc%s(:ncol,:), tend_s_snwprd(:ncol,:), tend_s_snwevmlt(:ncol,:), ptend_loc%q(:ncol,:pver,1), &
     684           0 :          rprd(:ncol,:), cld(:ncol,:), ztodt, &
     685           0 :          prec(:ncol), snow(:ncol), ntprprd(:ncol,:), ntsnprd(:ncol,:), fsnow_conv(:ncol,:), flxprec(:ncol,:), flxsnow(:ncol,:),&
     686       24192 :          scheme_name, errmsg, errflg)
     687             : 
     688    40908672 :     evapcdp(:ncol,:pver) = ptend_loc%q(:ncol,:pver,1)
     689             : 
     690             : !
     691             : ! Write out variables from zm_conv_evap_run
     692             : !
     693    40908672 :    ftem(:ncol,:pver) = ptend_loc%s(:ncol,:pver)/cpair
     694       24192 :    call outfld('EVAPTZM ',ftem           ,pcols   ,lchnk   )
     695    40908672 :    ftem(:ncol,:pver) = tend_s_snwprd  (:ncol,:pver)/cpair
     696       24192 :    call outfld('FZSNTZM ',ftem           ,pcols   ,lchnk   )
     697    40908672 :    ftem(:ncol,:pver) = tend_s_snwevmlt(:ncol,:pver)/cpair
     698       24192 :    call outfld('EVSNTZM ',ftem           ,pcols   ,lchnk   )
     699       24192 :    call outfld('EVAPQZM ',ptend_loc%q(1,1,1) ,pcols   ,lchnk   )
     700       24192 :    call outfld('ZMFLXPRC', flxprec, pcols, lchnk)
     701       24192 :    call outfld('ZMFLXSNW', flxsnow, pcols, lchnk)
     702       24192 :    call outfld('ZMNTPRPD', ntprprd, pcols, lchnk)
     703       24192 :    call outfld('ZMNTSNPD', ntsnprd, pcols, lchnk)
     704       24192 :    call outfld('ZMEIHEAT', ptend_loc%s, pcols, lchnk)
     705       24192 :    call outfld('CMFMC_DP   ',mcon ,  pcols   ,lchnk   )
     706       24192 :    call outfld('PRECCDZM   ',prec,  pcols   ,lchnk   )
     707             : 
     708             : 
     709       24192 :    call t_stopf ('zm_conv_evap_run')
     710             : 
     711       24192 :    call outfld('PRECZ   ', prec   , pcols, lchnk)
     712             : 
     713             :   ! add tendency from this process to tend from other processes here
     714       24192 :   call physics_ptend_sum(ptend_loc,ptend_all, ncol)
     715             : 
     716             :   ! update physics state type state1 with ptend_loc
     717       24192 :   call physics_update(state1, ptend_loc, ztodt)
     718             : 
     719             : 
     720             :   ! Momentum Transport
     721             : 
     722       24192 :   call physics_ptend_init(ptend_loc, state1%psetcols, 'zm_conv_momtran_run', ls=.true., lu=.true., lv=.true.)
     723             : 
     724       24192 :      l_windt = .true.
     725             : !REMOVECAM - no longer need these when CAM is retired and pcols no longer exists
     726    53488512 :   ptend_loc%s(:,:) = 0._r8
     727    53488512 :   ptend_loc%u(:,:) = 0._r8
     728    53488512 :   ptend_loc%v(:,:) = 0._r8
     729             : !REMOVECAM_END
     730             : 
     731       24192 :   call t_startf ('zm_conv_momtran_run')
     732             : 
     733             :      call zm_conv_momtran_run (ncol, pver, pverp,                    &
     734           0 :                    l_windt,state1%u(:ncol,:), state1%v(:ncol,:), mu(:ncol,:), md(:ncol,:),   &
     735             :                    zmconv_momcu, zmconv_momcd, &
     736           0 :                    du(:ncol,:), eu(:ncol,:), ed(:ncol,:), dp(:ncol,:), dsubcld(:ncol),  &
     737           0 :                    jt(:ncol), maxg(:ncol), ideep(:ncol), 1, lengath,  &
     738           0 :                    nstep,  ptend_loc%u(:ncol,:), ptend_loc%v(:ncol,:),&
     739           0 :                    pguallu(:ncol,:), pguallv(:ncol,:),  pgdallu(:ncol,:), pgdallv(:ncol,:), &
     740             :                    icwuu(:ncol,:), icwuv(:ncol,:), icwdu(:ncol,:), icwdv(:ncol,:), ztodt, seten(:ncol,:), &
     741       24192 :                    scheme_name, errmsg, errflg)
     742       24192 :      call t_stopf ('zm_conv_momtran_run')
     743             : 
     744    40908672 :   ptend_loc%s(:ncol,:pver) = seten(:ncol,:pver)
     745             : 
     746       24192 :   call physics_ptend_sum(ptend_loc,ptend_all, ncol)
     747             : 
     748             :   ! Output ptend variables before they are set to zero with physics_update
     749       24192 :   call outfld('ZMMTU', ptend_loc%u, pcols, lchnk)
     750       24192 :   call outfld('ZMMTV', ptend_loc%v, pcols, lchnk)
     751             : 
     752             :   ! update physics state type state1 with ptend_loc
     753       24192 :   call physics_update(state1, ptend_loc, ztodt)
     754             : 
     755    40908672 :      ftem(:ncol,:pver) = seten(:ncol,:pver)/cpair
     756       24192 :      call outfld('ZMMTT', ftem             , pcols, lchnk)
     757             : 
     758             :   ! Output apparent force from  pressure gradient
     759       24192 :   call outfld('ZMUPGU', pguallu, pcols, lchnk)
     760       24192 :   call outfld('ZMUPGD', pgdallu, pcols, lchnk)
     761       24192 :   call outfld('ZMVPGU', pguallv, pcols, lchnk)
     762       24192 :   call outfld('ZMVPGD', pgdallv, pcols, lchnk)
     763             : 
     764             :   ! Output in-cloud winds
     765       24192 :   call outfld('ZMICUU', icwuu, pcols, lchnk)
     766       24192 :   call outfld('ZMICUD', icwdu, pcols, lchnk)
     767       24192 :   call outfld('ZMICVU', icwuv, pcols, lchnk)
     768       24192 :   call outfld('ZMICVD', icwdv, pcols, lchnk)
     769             : 
     770             :   ! Transport cloud water and ice only
     771       24192 :   call cnst_get_ind('CLDLIQ', ixcldliq)
     772       24192 :   call cnst_get_ind('CLDICE', ixcldice)
     773             : 
     774       24192 :   lq(:)  = .FALSE.
     775     2443392 :   lq(2:) = cnst_is_convtran1(2:)
     776       24192 :   call physics_ptend_init(ptend_loc, state1%psetcols, 'convtran1', lq=lq)
     777             : 
     778             : 
     779             :    ! dpdry is not used in this call to convtran since the cloud liquid and ice mixing
     780             :    ! ratios are moist
     781       24192 :    fake_dpdry(:,:) = 0._r8
     782             : 
     783       24192 :    call t_startf ('convtran1')
     784             : 
     785             : !REMOVECAM - no longer need this when CAM is retired and pcols no longer exists
     786  5402363904 :    ptend_loc%q(:,:,:) = 0._r8
     787             : !REMOVECAM_END
     788             : 
     789             :    call zm_conv_convtran_run (ncol, pver,          &
     790           0 :                   ptend_loc%lq,state1%q(:ncol,:,:), pcnst,  mu(:ncol,:), md(:ncol,:),   &
     791           0 :                   du(:ncol,:), eu(:ncol,:), ed(:ncol,:), dp(:ncol,:), dsubcld(:ncol),  &
     792           0 :                   jt(:ncol), maxg(:ncol), ideep(:ncol), 1, lengath,  &
     793           0 :                   nstep,   fracis(:ncol,:,:),  ptend_loc%q(:ncol,:,:), fake_dpdry(:ncol,:), ccpp_const_props, &
     794       24192 :                   scheme_name, errmsg, errflg)
     795       24192 :    call t_stopf ('convtran1')
     796             : 
     797       24192 :    call outfld('ZMDICE ',ptend_loc%q(1,1,ixcldice) ,pcols   ,lchnk   )
     798       24192 :    call outfld('ZMDLIQ ',ptend_loc%q(1,1,ixcldliq) ,pcols   ,lchnk   )
     799             : 
     800             :    ! add tendency from this process to tend from other processes here
     801       24192 :    call physics_ptend_sum(ptend_loc,ptend_all, ncol)
     802             : 
     803       24192 :    call physics_state_dealloc(state1)
     804       24192 :    call physics_ptend_dealloc(ptend_loc)
     805             : 
     806             : 
     807             : 
     808       72576 : end subroutine zm_conv_tend
     809             : !=========================================================================================
     810             : 
     811             : 
     812     2491776 : subroutine zm_conv_tend_2( state,  ptend,  ztodt, pbuf)
     813             : 
     814       24192 :    use physics_types, only: physics_state, physics_ptend, physics_ptend_init
     815             :    use time_manager,  only: get_nstep
     816             :    use physics_buffer, only: pbuf_get_index, pbuf_get_field, physics_buffer_desc
     817             :    use constituents,   only: pcnst, cnst_is_convtran2
     818             :    use ccpp_constituent_prop_mod, only: ccpp_const_props
     819             : 
     820             : 
     821             : ! Arguments
     822             :    type(physics_state), intent(in )   :: state          ! Physics state variables
     823             :    type(physics_ptend), intent(out)   :: ptend          ! indivdual parameterization tendencies
     824             : 
     825             :    type(physics_buffer_desc), pointer :: pbuf(:)
     826             : 
     827             :    real(r8), intent(in) :: ztodt                          ! 2 delta t (model time increment)
     828             : 
     829             : ! Local variables
     830             :    integer :: i, lchnk, istat
     831             :    integer :: lengath          ! number of columns with deep convection
     832             :    integer :: nstep
     833             :    integer :: ncol
     834             : 
     835             :    real(r8), dimension(pcols,pver) :: dpdry
     836             : 
     837             :    ! physics buffer fields
     838       24192 :    real(r8), pointer :: fracis(:,:,:)  ! fraction of transported species that are insoluble
     839       24192 :    real(r8), pointer :: mu(:,:)    ! (pcols,pver)
     840       24192 :    real(r8), pointer :: eu(:,:)    ! (pcols,pver)
     841       24192 :    real(r8), pointer :: du(:,:)    ! (pcols,pver)
     842       24192 :    real(r8), pointer :: md(:,:)    ! (pcols,pver)
     843       24192 :    real(r8), pointer :: ed(:,:)    ! (pcols,pver)
     844       24192 :    real(r8), pointer :: dp(:,:)    ! (pcols,pver)
     845       24192 :    real(r8), pointer :: dsubcld(:) ! (pcols)
     846       24192 :    integer,  pointer :: jt(:)      ! (pcols)
     847       24192 :    integer,  pointer :: maxg(:)    ! (pcols)
     848       24192 :    integer,  pointer :: ideep(:)   ! (pcols)
     849             : 
     850             :    character(len=40)  :: scheme_name
     851             :    character(len=512) :: errmsg
     852             :    integer            :: errflg
     853             : 
     854             :    !-----------------------------------------------------------------------------------
     855             : 
     856             : 
     857       24192 :    call physics_ptend_init(ptend, state%psetcols, 'convtran2', lq=cnst_is_convtran2 )
     858             : 
     859       24192 :    call pbuf_get_field(pbuf, fracis_idx,     fracis)
     860       24192 :    call pbuf_get_field(pbuf, zm_mu_idx,      mu)
     861       24192 :    call pbuf_get_field(pbuf, zm_eu_idx,      eu)
     862       24192 :    call pbuf_get_field(pbuf, zm_du_idx,      du)
     863       24192 :    call pbuf_get_field(pbuf, zm_md_idx,      md)
     864       24192 :    call pbuf_get_field(pbuf, zm_ed_idx,      ed)
     865       24192 :    call pbuf_get_field(pbuf, zm_dp_idx,      dp)
     866       24192 :    call pbuf_get_field(pbuf, zm_dsubcld_idx, dsubcld)
     867       24192 :    call pbuf_get_field(pbuf, zm_jt_idx,      jt)
     868       24192 :    call pbuf_get_field(pbuf, zm_maxg_idx,    maxg)
     869       24192 :    call pbuf_get_field(pbuf, zm_ideep_idx,   ideep)
     870             : 
     871             : 
     872       24192 :    lchnk = state%lchnk
     873       24192 :    ncol  = state%ncol
     874       24192 :    nstep = get_nstep()
     875             : 
     876      411264 :    lengath = count(ideep > 0)
     877       24192 :    if (lengath > ncol) lengath = ncol  ! should not happen, but force it to not be larger than ncol for safety sake
     878             : 
     879      290304 :    if (any(ptend%lq(:))) then
     880             :       ! initialize dpdry for call to convtran
     881             :       ! it is used for tracers of dry mixing ratio type
     882       24192 :       dpdry = 0._r8
     883      109369 :       do i = 1, lengath
     884    11182379 :          dpdry(i,:) = state%pdeldry(ideep(i),:)/100._r8
     885             :       end do
     886             : 
     887       24192 :       call t_startf ('convtran2')
     888             : 
     889             : !REMOVECAM - no longer need this when CAM is retired and pcols no longer exists
     890  5402363904 :    ptend%q(:,:,:) = 0._r8
     891             : !REMOVECAM_END
     892             : 
     893             :       call zm_conv_convtran_run (ncol, pver,          &
     894           0 :                   ptend%lq,state%q(:ncol,:,:), pcnst,  mu(:ncol,:), md(:ncol,:),   &
     895           0 :                   du(:ncol,:), eu(:ncol,:), ed(:ncol,:), dp(:ncol,:), dsubcld(:ncol),  &
     896           0 :                   jt(:ncol), maxg(:ncol), ideep(:ncol), 1, lengath,  &
     897           0 :                   nstep,   fracis(:ncol,:,:),  ptend%q(:ncol,:,:), dpdry(:ncol,:), ccpp_const_props, &
     898       24192 :                   scheme_name, errmsg, errflg)
     899             : 
     900       24192 :       if (errflg /= 0) then
     901           0 :          call endrun('From zm_conv_convtran_run:'  // errmsg)
     902             :       end if
     903             : 
     904       24192 :       call t_stopf ('convtran2')
     905             :    end if
     906             : 
     907       48384 : end subroutine zm_conv_tend_2
     908             : 
     909             : !=========================================================================================
     910             : 
     911             : 
     912             : end module zm_conv_intr

Generated by: LCOV version 1.14