Skip to content

Commit

Permalink
Add code to apply tendencies from YOG to CAM inputs and check energy/…
Browse files Browse the repository at this point in the history
…mass conservation on CAM grid after YOG.
  • Loading branch information
jatkinson1000 committed Jan 9, 2025
1 parent 1cf5d9c commit 2eb7c73
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/physics/cam/nn_interface_cam.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 2eb7c73

Please sign in to comment.