From 2eb7c732d9895bd12d827ef7482131fa4ec53da7 Mon Sep 17 00:00:00 2001 From: jatkinson1000 Date: Thu, 9 Jan 2025 03:49:34 -0700 Subject: [PATCH] Add code to apply tendencies from YOG to CAM inputs and check energy/mass conservation on CAM grid after YOG. --- src/physics/cam/nn_interface_cam.F90 | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/physics/cam/nn_interface_cam.F90 b/src/physics/cam/nn_interface_cam.F90 index 145f9e1a59..a54175eb64 100644 --- a/src/physics/cam/nn_interface_cam.F90 +++ b/src/physics/cam/nn_interface_cam.F90 @@ -167,6 +167,15 @@ subroutine nn_convection_flux_CAM(pres_cam, pres_int_cam, pres_sfc_cam, & real(8) :: presi_col(ncol, nz_sam) !! presi repeated ncol times along one dimension, for energy and water checker + + ! Variables for the energy checker calculations at the end of the code + real(8), dimension(:,:), allocatable :: tabs_cam_out + !! absolute temperature [K] from the CAM model + real(8), dimension(:,:), allocatable :: qv_cam_out, qc_cam_out, qi_cam_out + !! moisture content [kg/kg] from the CAM model + integer :: ncol_chnk = size(tabs_cam(1)) + integer :: nver_chnk = size(tabs_cam(2)) + integer :: i,k ! Initialise precipitation to 0 if required and at start of cycle if subcycling @@ -245,7 +254,7 @@ subroutine nn_convection_flux_CAM(pres_cam, pres_int_cam, pres_sfc_cam, & precsfc = precsfc * 1.0D-3 !----------------------------------------------------- - write(iulog, *), "After conversion:" + write(iulog, *), "After YOG NN:" !!presi has just one dimension, so we need to repeat it ncol times to get the required input for the checker. !!Also, convert from hPa to Pa do i = 1, ncol @@ -274,6 +283,30 @@ subroutine nn_convection_flux_CAM(pres_cam, pres_int_cam, pres_sfc_cam, & call interp_to_cam(pres_cam(1:ncol, :), pres_int_cam(1:ncol, :), pres_sfc_cam(1:ncol), dqi_sam, dqi(1:ncol, :)) call interp_to_cam(pres_cam(1:ncol, :), pres_int_cam(1:ncol, :), pres_sfc_cam(1:ncol), ds_sam, ds(1:ncol, :)) + !----------------------------------------------------- + ! For purposes of investigating energy conservation apply the tendencies on the + ! CAM grid to the CAM inputs, and apply the Marion conservation checker to see + ! if values are consistent with the inputs before the parameterisation. + allocate(tabs_cam_out(ncol_chnk,nver_chnk)) + allocate(qv_cam_out(ncol_chnk,nver_chnk)) + allocate(qc_cam_out(ncol_chnk,nver_chnk)) + allocate(qi_cam_out(ncol_chnk,nver_chnk)) + + tabs_cam_out = tabs_cam + dtn * ds / cp_cam + qv_cam_out = qv_cam + dtn * dqv + qc_cam_out = qc_cam + dtn * dqc + qi_cam_out = qi_cam + dtn * dqi + + write(iulog, *), "After conversion back:" + call yog_conservation_check(pres_int_cam, tabs_cam_out, qv_cam_out, qc_cam_out, qi_cam_out, ncol, pver) + + deallocate(tabs_cam_out) + deallocate(qv_cam_out) + deallocate(qc_cam_out) + deallocate(qi_cam_out) + + + end subroutine nn_convection_flux_CAM