LCOV - code coverage report
Current view: top level - physics/carma/base - vertdif.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 46 73.9 %
Date: 2025-03-14 01:30:37 Functions: 1 1 100.0 %

          Line data    Source code
       1             : ! Include shortname defintions, so that the F77 code does not have to be modified to
       2             : ! reference the CARMA structure.
       3             : #include "carma_globaer.h"
       4             : 
       5             : !! This routine calculates vertrical transport rates.
       6             : !! Currently treats diffusion only.
       7             : !! Not necessarily generalized for irregular grid.
       8             : !!
       9             : !! @author Eric Jensen
      10             : !! @version Dec-1996
      11   231137280 : subroutine vertdif(carma, cstate, igroup, ibin, itbnd, ibbnd, vertdifu, vertdifd, rc)
      12             : 
      13             :   ! types
      14             :   use carma_precision_mod
      15             :   use carma_enums_mod
      16             :   use carma_constants_mod
      17             :   use carma_types_mod
      18             :   use carmastate_mod
      19             :   use carma_mod
      20             : 
      21             :   implicit none
      22             : 
      23             :   type(carma_type), intent(in)         :: carma           !! the carma object
      24             :   type(carmastate_type), intent(inout) :: cstate          !! the carma state object
      25             :   integer, intent(in)                  :: igroup          !! particle group index
      26             :   integer, intent(in)                  :: ibin            !! particle bin index
      27             :   integer, intent(in)                  :: itbnd           !! top boundary condition
      28             :   integer, intent(in)                  :: ibbnd           !! bottom boundary condition
      29             :   real(kind=f), intent(out)            :: vertdifu(NZP1)  !! upward vertical diffusion rate into level k from level k-1 [cm/s]
      30             :   real(kind=f), intent(out)            :: vertdifd(NZP1)  !! downward vertical diffusion rate into level k from level k-1 [cm/s]
      31             :   integer, intent(inout)               :: rc              !! return code, negative indicates failure
      32             :   
      33             :   ! Local Variables
      34             :   integer      :: k
      35             :   integer      :: nzm1
      36             :   integer      :: itwo
      37             :   real(kind=f) :: dz_avg
      38             :   real(kind=f) :: rhofact
      39             :   real(kind=f) :: xex
      40             :   real(kind=f) :: ttheta
      41             : 
      42             : 
      43             :   ! Set some constants
      44   231137280 :   nzm1 = max( 1, NZ-1 )
      45   231137280 :   itwo = min( 2, NZ   )
      46             : 
      47             :   !  Loop over vertical levels.
      48  7396392960 :   do k = 2, NZ
      49             : 
      50  7165255680 :     dz_avg = dz(k)                            ! layer thickness
      51             : 
      52             :     !  Check the vertical coordinate
      53             : 
      54  7396392960 :     if( igridv .eq. I_CART ) then
      55           0 :       rhofact = log(  rhoa(k)/rhoa(k-1) &
      56           0 :                     * zmet(k-1)/zmet(k) )
      57             :       xex = rhoa(k-1)/rhoa(k) * &
      58           0 :             zmet(k)/zmet(k-1)
      59           0 :       vertdifu(k) = ( rhofact * dkz(k, ibin, igroup) / dz_avg ) / ( 1._f - xex )
      60             : 
      61           0 :       vertdifd(k) = vertdifu(k) * xex
      62             : 
      63             : 
      64             :     !  ...else you're in sigma or hybrid coordinates...
      65  7165255680 :     elseif(( igridv .eq. I_SIG ) .or. ( igridv .eq. I_HYBRID )) then
      66  7165255680 :       vertdifu(k) = dkz(k, ibin, igroup) / dz_avg
      67  7165255680 :       vertdifd(k) = dkz(k, ibin, igroup) / dz_avg
      68             : 
      69             :     !  ...else write an error (maybe redundant)...
      70             :     else
      71           0 :       if (do_print) write(LUNOPRT,*) 'vertdif::ERROR - Invalid vertical grid type (', igridv, ').'
      72           0 :       rc = -1
      73           0 :       return
      74             :     endif
      75             :   enddo
      76             : 
      77             :   ! Fluxes at boundaries specified by user
      78   231137280 :   if( ibbnd .eq. I_FLUX_SPEC ) then
      79           0 :     vertdifu(1) = 0._f
      80           0 :     vertdifd(1) = 0._f
      81             :   endif
      82             : 
      83   231137280 :   if( itbnd .eq. I_FLUX_SPEC ) then
      84           0 :     vertdifu(NZ+1) = 0._f
      85           0 :     vertdifd(NZ+1) = 0._f
      86             :   endif
      87             : 
      88             :   ! Diffusion across boundaries using fixed boundary concentration:
      89   231137280 :   if( ibbnd .eq. I_FIXED_CONC ) then
      90   231137280 :     dz_avg = dz(1)                            ! layer thickness
      91   231137280 :     rhofact = log( rhoa(itwo)/rhoa(1) )
      92   231137280 :     ttheta = rhofact
      93   231137280 :     if( ttheta .ge. 0._f ) then
      94   163320080 :       ttheta = min(ttheta,POWMAX)
      95             :     else
      96    67817200 :       ttheta = max(ttheta,-POWMAX)
      97             :     endif
      98             : 
      99   231137280 :     xex = exp(-ttheta)
     100   231137280 :     if( abs(ONE - xex) .lt. ALMOST_ZERO ) xex = ALMOST_ONE
     101             : 
     102   231137280 :     vertdifu(1) = ( rhofact * dkz(1, ibin, igroup) / dz_avg ) / ( 1._f - xex )
     103   231137280 :     vertdifd(1) = vertdifu(1) * xex
     104             :   endif
     105             : 
     106   231137280 :   if( itbnd .eq. I_FIXED_CONC ) then
     107   231137280 :     dz_avg = dz(NZ)                            ! layer thickness
     108   231137280 :     rhofact = log( rhoa(NZ)/rhoa(nzm1) )
     109   231137280 :     ttheta = rhofact
     110   231137280 :     if( ttheta .ge. 0._f ) then
     111   105919220 :       ttheta = min(ttheta,POWMAX)
     112             :     else
     113   125218060 :       ttheta = max(ttheta,-POWMAX)
     114             :     endif
     115             : 
     116   231137280 :     xex = exp(-ttheta)
     117   231137280 :     if( abs(ONE - xex) .lt. ALMOST_ZERO ) xex = ALMOST_ONE
     118             : 
     119   231137280 :     vertdifu(NZ+1) = ( rhofact * dkz(NZ+1, ibin, igroup) / dz_avg ) / ( 1._f - xex )
     120   231137280 :     vertdifd(NZ+1) = vertdifu(NZ+1) * xex
     121             :   endif
     122             : 
     123             :   ! Return to caller with vertical diffusion rates.
     124             :   return
     125   231137280 : end

Generated by: LCOV version 1.14