From e76b112aa9e47b8c0899e0131ed74d1b055a4799 Mon Sep 17 00:00:00 2001 From: jatkinson1000 Date: Mon, 24 Jun 2024 05:00:53 -0600 Subject: [PATCH] Add a gw_final() subroutine to destroy NN instance. --- src/physics/cam/gw_drag.F90 | 10 ++++++++++ src/physics/cam/physpkg.F90 | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/physics/cam/gw_drag.F90 b/src/physics/cam/gw_drag.F90 index bfe4cacfff..7396281c94 100644 --- a/src/physics/cam/gw_drag.F90 +++ b/src/physics/cam/gw_drag.F90 @@ -54,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 @@ -1249,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