Line data Source code
1 : 2 : module mo_mean_mass 3 : 4 : implicit none 5 : 6 : private 7 : public :: set_mean_mass, init_mean_mass 8 : 9 : integer :: id_o2, id_o, id_h, id_n 10 : 11 : contains 12 : 13 0 : subroutine init_mean_mass 14 : use mo_chem_utls, only : get_spc_ndx 15 : 16 : implicit none 17 : 18 0 : id_o2 = get_spc_ndx('O2') 19 0 : id_o = get_spc_ndx('O') 20 0 : id_h = get_spc_ndx('H') 21 0 : id_n = get_spc_ndx('N') 22 : 23 0 : endsubroutine init_mean_mass 24 : 25 0 : subroutine set_mean_mass( ncol, mmr, mbar ) 26 : !----------------------------------------------------------------- 27 : ! ... Set the invariant densities (molecules/cm**3) 28 : !----------------------------------------------------------------- 29 : 30 : use shr_kind_mod, only : r8 => shr_kind_r8 31 : use ppgrid, only : pver, pcols 32 : use chem_mods, only : adv_mass, gas_pcnst 33 : use physconst, only : mwdry ! molecular weight of dry air 34 : use cam_abortutils, only : endrun 35 : use phys_control, only : waccmx_is !WACCM-X runtime switch 36 : 37 : implicit none 38 : 39 : !----------------------------------------------------------------- 40 : ! ... Dummy arguments 41 : !----------------------------------------------------------------- 42 : integer, intent(in) :: ncol 43 : real(r8), intent(in) :: mmr(:,:,:) ! species concentrations (kg/kg) 44 : real(r8), intent(out) :: mbar(:,:) ! mean mass (g/mole) 45 : 46 : !----------------------------------------------------------------- 47 : ! ... Local variables 48 : !----------------------------------------------------------------- 49 : integer :: k 50 0 : real(r8) :: xn2(ncol) ! n2 mmr 51 0 : real(r8) :: fn2(ncol) ! n2 vmr 52 0 : real(r8) :: fo(ncol) ! o vmr 53 0 : real(r8) :: fo2(ncol) ! o2 vmr 54 0 : real(r8) :: fh(ncol) ! h vmr 55 : real(r8) :: ftot(ncol) ! total vmr 56 : real(r8) :: mean_mass(ncol) ! wrk variable 57 : 58 : logical :: fixed_mbar ! Fixed mean mass flag 59 : 60 : !------------------------------------------- 61 : ! Mean mass not fixed for WACCM-X 62 : !------------------------------------------- 63 0 : if ( waccmx_is('ionosphere') .or. waccmx_is('neutral') ) then 64 : fixed_mbar = .false. 65 : else 66 : fixed_mbar = .true. 67 : endif 68 : 69 : if( fixed_mbar ) then 70 : !----------------------------------------------------------------- 71 : ! ... use CAM meam molecular weight 72 : !----------------------------------------------------------------- 73 0 : mbar(:ncol,:pver) = mwdry 74 : else 75 0 : if ( id_o2 > 0 .and. id_o > 0 .and. id_h > 0 .and. id_n > 0 ) then 76 : !----------------------------------------------------------------- 77 : ! ... set the mean mass 78 : !----------------------------------------------------------------- 79 : do k = 1,pver 80 0 : xn2(:) = 1._r8 - (mmr(:ncol,k,id_o2) + mmr(:ncol,k,id_o) + mmr(:ncol,k,id_h)) 81 0 : fn2(:) = .5_r8 * xn2(:) / adv_mass(id_n) 82 : fo2(:) = mmr(:ncol,k,id_o2) / adv_mass(id_o2) 83 : fo(:) = mmr(:ncol,k,id_o) / adv_mass(id_o) 84 : fh(:) = mmr(:ncol,k,id_h) / adv_mass(id_h) 85 : mbar(:ncol,k) = 1._r8 / (fn2(:) + fo2(:) + fo(:) + fh(:)) 86 : end do 87 : else 88 0 : call endrun('set_mean_mass: not able to compute mean mass') 89 : endif 90 : endif 91 : 92 0 : end subroutine set_mean_mass 93 : 94 : end module mo_mean_mass