diff --git a/src/physics/cam/gw_drag.F90 b/src/physics/cam/gw_drag.F90 index a9cf446b05..49e1c36edb 100644 --- a/src/physics/cam/gw_drag.F90 +++ b/src/physics/cam/gw_drag.F90 @@ -29,6 +29,8 @@ module gw_drag use cam_logfile, only: iulog use cam_abortutils, only: endrun + use ftorch + use ref_pres, only: do_molec_diff, nbot_molec, press_lim_idx use physconst, only: cpair @@ -52,6 +54,7 @@ module gw_drag public :: gw_drag_readnl ! Read namelist public :: gw_init ! Initialization public :: gw_tend ! interface to actual parameterization + public :: gw_final ! Finalization ! ! PRIVATE: Rest of the data and interfaces are private to this module @@ -195,6 +198,8 @@ module gw_drag ! Switch for using ML GW parameterisation for deep convection source logical :: gw_convect_dp_ml = .false. logical :: gw_convect_dp_ml_compare = .false. + character(len=132) :: gw_convect_dp_ml_net_path + type(torch_module) :: gw_convect_dp_nn !========================================================================== contains @@ -237,7 +242,7 @@ subroutine gw_drag_readnl(nlfile) gw_oro_south_fac, gw_limit_tau_without_eff, & gw_lndscl_sgh, gw_prndl, gw_apply_tndmax, gw_qbo_hdepth_scaling, & gw_top_taper, front_gaussian_width, & - gw_convect_dp_ml, gw_convect_dp_ml_compare + gw_convect_dp_ml, gw_convect_dp_ml_compare, gw_convect_dp_ml_net_path !---------------------------------------------------------------------- if (use_simple_phys) return @@ -347,6 +352,9 @@ subroutine gw_drag_readnl(nlfile) call mpi_bcast(gw_convect_dp_ml_compare, 1, mpi_logical, mstrid, mpicom, ierr) if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: gw_convect_dp_ml_compare") + call mpi_bcast(gw_convect_dp_ml_net_path, len(gw_convect_dp_ml_net_path), mpi_character, mstrid, mpicom, ierr) + if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: gw_convect_dp_ml_net_path") + ! Check if fcrit2 was set. call shr_assert(fcrit2 /= unset_r8, & "gw_drag_readnl: fcrit2 must be set via the namelist."// & @@ -974,6 +982,12 @@ subroutine gw_init() end if + ! Set up neccessary attributes if using ML scheme for convective drag + if ((gw_convect_dp_ml == 'on') .or. (gw_convect_dp_ml == 'bothon')) then + ! Load the convective drag net from TorchScript file + gw_convect_dp_nn = torch_module_load(gw_convect_dp_ml_net) + endif + if (use_gw_convect_sh) then ttend_sh_idx = pbuf_get_index('TTEND_SH') @@ -1236,6 +1250,15 @@ end subroutine handle_pio_error !========================================================================== +subroutine gw_final() + ! Destroy neccessary attributes if using ML scheme for convective drag + if ((gw_convect_dp_ml == 'on') .or. (gw_convect_dp_ml == 'bothon')) then + call torch_module_delete(gw_convect_dp_nn) + endif +end subroutine gw_final + +!========================================================================== + subroutine gw_tend(state, pbuf, dt, ptend, cam_in, flx_heat) !----------------------------------------------------------------------- ! Interface for multiple gravity wave drag parameterization. diff --git a/src/physics/cam/physpkg.F90 b/src/physics/cam/physpkg.F90 index c7d5b2524b..66a9d8433a 100644 --- a/src/physics/cam/physpkg.F90 +++ b/src/physics/cam/physpkg.F90 @@ -1337,6 +1337,7 @@ subroutine phys_final( phys_state, phys_tend, pbuf2d ) use microp_aero, only : microp_aero_final use phys_grid_ctem, only : phys_grid_ctem_final use nudging, only: Nudge_Model, nudging_final + use gw_drag, only: gw_final !----------------------------------------------------------------------- ! @@ -1367,6 +1368,8 @@ subroutine phys_final( phys_state, phys_tend, pbuf2d ) call HCOI_Chunk_Final endif + call gw_final() + end subroutine phys_final