Skip to content

Commit

Permalink
Merge pull request #14 from m2lines/add-yog-rebase
Browse files Browse the repository at this point in the history
Implement YOG scheme in code
  • Loading branch information
jatkinson1000 authored Jun 26, 2024
2 parents da8f941 + 1e087d4 commit facd0ce
Show file tree
Hide file tree
Showing 9 changed files with 1,943 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bld/namelist_files/namelist_defaults_cam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@
<deep_scheme phys='spcam_m2005' >SPCAM </deep_scheme>

<yog_scheme >off </yog_scheme>
<nn_weights >NONE</nn_weights>
<yog_nn_weights >NONE</yog_nn_weights>
<SAM_sounding >NONE</SAM_sounding>

<shallow_scheme pbl="none" >NONE </shallow_scheme>
Expand Down
2 changes: 1 addition & 1 deletion bld/namelist_files/namelist_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3277,7 +3277,7 @@ Default: true
</entry>

<!-- YOG parameters -->
<entry id="nn_weights" type="char*132" input_pathname="abs" category="conv"
<entry id="yog_nn_weights" type="char*132" input_pathname="abs" category="conv"
group="yog_params_nl" valid_values="" >
Absolute path to the neural net weights used for the YOG deep convection scheme.
</entry>
Expand Down
2 changes: 2 additions & 0 deletions src/control/runtime_opts.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ subroutine read_namelist(nlfilename, single_column, scmlat, scmlon)
use rk_stratiform, only: rk_stratiform_readnl
use unicon_cam, only: unicon_cam_readnl
use zm_conv_intr, only: zm_conv_readnl
use yog_intr, only: yog_readnl
use hk_conv, only: hkconv_readnl
use uwshcu, only: uwshcu_readnl
use pkg_cld_sediment, only: cld_sediment_readnl
Expand Down Expand Up @@ -144,6 +145,7 @@ subroutine read_namelist(nlfilename, single_column, scmlat, scmlon)
call cldfrc2m_readnl(nlfilename)
call unicon_cam_readnl(nlfilename)
call zm_conv_readnl(nlfilename)
call yog_readnl(nlfilename)
call rk_stratiform_readnl(nlfilename)
call hkconv_readnl(nlfilename)
call uwshcu_readnl(nlfilename)
Expand Down
129 changes: 129 additions & 0 deletions src/physics/cam/SAM_consts.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
module SAM_consts_mod
!! Physical constants from the SAM Model required for variable conversions

use netcdf

implicit none
public

! From params.f90 in SAM
! These are constants used in equations as part of the parameterisation.
! Since the net is trained with them they should be left as defined here, rather than
! forced to match the external model

! Physical Constants:

!= unit (m / s^2)
real(8), parameter :: ggr = 9.81
!! Gravity acceleration, m/s2

!= unit J / kg :: lcond, lsub, lfus
real(8), parameter :: lfus = 0.3336e+06
!! Latent heat of fusion
real(8), parameter :: lcond = 2.5104e+06
!! Latent heat of condensation
real(8), parameter :: lsub = 2.8440e+06
!! Latent heat of sublimation, J/kg

!= unit (J / kg) / K :: cp
real(8), parameter :: cp = 1004.
!! Specific heat of air

! unit K :: fac_cond, fac_fus, fac_sub
real(8), parameter :: fac_cond = lcond/cp
!!
real(8), parameter :: fac_fus = lfus/cp
!!
real(8), parameter :: fac_sub = lsub/cp
!!

! Temperatures limits for various hydrometeors
!= unit K :: tprmin
real(8), parameter :: tprmin = 268.16
!! Minimum temperature for rain

!= unit K :: tprmax
real(8), parameter :: tprmax = 283.16
!! Maximum temperature for snow+graupel, K

!= unit K :: tbgmin
real(8), parameter :: tbgmin = 253.16
!! Minimum temperature for cloud water.

!= unit K :: tbgmin
real(8), parameter :: tbgmax = 273.16
!! Maximum temperature for cloud ice, K

!= unit K :: tbgmin
real(8), parameter :: tgrmin = 223.16
!! Maximum temperature for snow, K

!= unit K :: tbgmin
real(8), parameter :: tgrmax = 283.16
!! Maximum temperature for graupel, K

! Misc. microphysics variables
! != unit 1 / K :: a_pr
real(8), parameter :: a_pr = 1./(tprmax-tprmin)
!! Misc. microphysics variables

!= unit 1 / K :: a_bg
real(8), parameter :: a_bg = 1./(tbgmax-tbgmin)
!! Misc. microphysics variables

real(8), parameter :: an = 1./(tbgmax-tbgmin)
real(8), parameter :: bn = tbgmin * an
real(8), parameter :: ap = 1./(tprmax-tprmin)
real(8), parameter :: bp = tprmin * ap
real(8), parameter :: fac1 = fac_cond+(1+bp)*fac_fus
real(8), parameter :: fac2 = fac_fus*ap
real(8), parameter :: ag = 1./(tgrmax-tgrmin)

! ---------------------------
! SAM Grid Variables
! ---------------------------
integer, parameter :: input_ver_dim = 30
!! Set to 48 in setparm.f90 of SAM. Same as nz_gl, but trained on a run with 30.

! Outputs from NN are supplied at lowest 30 half-model levels for sedimentation fluxes,
! and at 29 levels for fluxes (as flux at bottom boundary is zero).
integer, parameter :: nrf = 30
!! number of vertical levels the NN uses
integer, parameter :: nrfq = nrf - 1
!! number of vertical levels the NN uses when boundary condition is set to 0

real(8), parameter :: dt_sam = 30.0
!! SAM timestep in seconds

!---------------------------------------------------------------------
! Functions and Subroutines

contains

!= unit 1 :: omegan
real(8) function omegan(tabs)
!= unit K :: tabs
real(8), intent(in) :: tabs
!! Absolute temperature

omegan = max(0., min(1., (tabs-tbgmin)*a_bg))

return

end function omegan


subroutine check(err_status)
!! Check error status after netcdf call and print message for
!! error codes.

integer, intent(in) :: err_status
!! error status from nf90 function

if(err_status /= nf90_noerr) then
write(*, *) trim(nf90_strerror(err_status))
end if

end subroutine check

end module SAM_consts_mod
Loading

0 comments on commit facd0ce

Please sign in to comment.