Skip to content

Add utgw and vtgw to variable output #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: nonlocal-gws
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/physics/cam/gw_drag.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ subroutine gw_tend(state, pbuf, dt, ptend, cam_in, flx_heat)
flx_heat = 0._r8

if ( use_gw_nlgw ) then
call gw_nlgw_dp_ml(state1,ptend)
call gw_nlgw_dp_ml(state1,ptend,lchnk)
end if

if (use_gw_convect_dp) then
Expand Down
16 changes: 14 additions & 2 deletions src/physics/cam/gw_nlgw.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ module gw_nlgw
!

use gw_utils, only: r8, r4
use ppgrid, only: pver !vertical levels
use ppgrid, only: pcols, pver !vertical levels
use physics_types, only: physics_state, physics_ptend
use spmd_utils, only: mpicom, mstrid=>masterprocid, masterproc, mpi_real8, iam
use cam_abortutils, only: endrun
use cam_logfile, only: iulog
use physconst, only: cappa, pi
use interpolate_data, only: lininterp
use cam_history, only: outfld

use ftorch

Expand Down Expand Up @@ -104,10 +105,11 @@ module gw_nlgw

!==========================================================================

subroutine gw_nlgw_dp_ml(state_in, ptend)
subroutine gw_nlgw_dp_ml(state_in, ptend, lchnk)

! inputs
type(physics_state), intent(in) :: state_in
integer, intent(in) :: lchnk
! outputs
type(physics_ptend), intent(inout) :: ptend

Expand Down Expand Up @@ -173,6 +175,11 @@ subroutine gw_nlgw_dp_ml(state_in, ptend)
call flux_to_forcing(uflux, utgw)
call flux_to_forcing(vflux, vtgw)

! Write UTGW and VTGW to file
call outfld('UTGW_NL', utgw, ncol, lchnk)
call outfld('VTGW_NL', vtgw, ncol, lchnk)


! update the tendencies
ptend%u(:ncol,:pver) = ptend%u(:ncol,:pver) + utgw(:ncol,:pver)
ptend%v(:ncol,:pver) = ptend%v(:ncol,:pver) + vtgw(:ncol,:pver)
Expand Down Expand Up @@ -205,6 +212,8 @@ end subroutine gw_nlgw_dp_ml

subroutine gw_nlgw_dp_init(model_path)

use cam_history, only: addfld

character(len=*), intent(in) :: model_path ! Filepath to PyTorch Torchscript net
integer :: device_id

Expand All @@ -219,6 +228,9 @@ subroutine gw_nlgw_dp_init(model_path)
write(iulog,*)'nlgw model loaded from: ', model_path
endif

call addfld('UTGW_NL', (/ 'lev' /), 'A', 'm/s2', 'Nonlinear GW zonal wind tendency')
call addfld('VTGW_NL', (/ 'lev' /), 'A', 'm/s2', 'Nonlinear GW meridional wind tendency')

end subroutine gw_nlgw_dp_init


Expand Down