From e5aae339edfad658cfb765c7b3931f72ad63b068 Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Tue, 17 Jun 2025 09:24:34 -0600 Subject: [PATCH 1/7] Add utgw and vtgw to variable output --- src/physics/cam/gw_nlgw.F90 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index 647b771e68..4cdaf0ce79 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -12,6 +12,7 @@ module gw_nlgw use cam_logfile, only: iulog use physconst, only: cappa, pi use interpolate_data, only: lininterp +use cam_history, only: outfld use ftorch @@ -173,6 +174,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, pver) + call outfld('VTGW_NL', vtgw, ncol, pver) + + ! 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) @@ -205,6 +211,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 @@ -219,6 +227,9 @@ subroutine gw_nlgw_dp_init(model_path) write(iulog,*)'nlgw model loaded from: ', model_path endif + call addfld('UTGW_NL', (/ 'lev' /), 'U', 'm/s2', 'Nonlinear GW zonal wind tendency') + call addfld('VTGW_NL', (/ 'lev' /), 'U', 'm/s2', 'Nonlinear GW meridional wind tendency') + end subroutine gw_nlgw_dp_init From a484ca574f754b3a40da5fee6a544afc2693e6c0 Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Thu, 26 Jun 2025 13:12:31 -0600 Subject: [PATCH 2/7] Pass lchnk to gw_nlgw_dp_ml fix oob block_id error --- src/physics/cam/gw_drag.F90 | 2 +- src/physics/cam/gw_nlgw.F90 | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/physics/cam/gw_drag.F90 b/src/physics/cam/gw_drag.F90 index 9a3a651060..f9e08e5a86 100644 --- a/src/physics/cam/gw_drag.F90 +++ b/src/physics/cam/gw_drag.F90 @@ -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 diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index 4cdaf0ce79..7c5a43c143 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -5,7 +5,7 @@ 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 @@ -105,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 @@ -136,7 +137,7 @@ subroutine gw_nlgw_dp_ml(state_in, ptend) allocate(uflux(ncol,pver)) allocate(vflux(ncol,pver)) - allocate(utgw(ncol,pver)) + allocate(utgw(pcols,pver)) allocate(vtgw(ncol,pver)) allocate(net_inputs(ncol, 4*pver_interp+3)) @@ -175,8 +176,8 @@ subroutine gw_nlgw_dp_ml(state_in, ptend) call flux_to_forcing(vflux, vtgw) ! Write UTGW and VTGW to file - call outfld('UTGW_NL', utgw, ncol, pver) - call outfld('VTGW_NL', vtgw, ncol, pver) + call outfld('UTGW_NL', utgw, ncol, lchnk) + call outfld('VTGW_NL', vtgw, ncol, lcnhk) ! update the tendencies @@ -227,8 +228,8 @@ subroutine gw_nlgw_dp_init(model_path) write(iulog,*)'nlgw model loaded from: ', model_path endif - call addfld('UTGW_NL', (/ 'lev' /), 'U', 'm/s2', 'Nonlinear GW zonal wind tendency') - call addfld('VTGW_NL', (/ 'lev' /), 'U', 'm/s2', 'Nonlinear GW meridional wind tendency') + 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 From 31d4f0bc7767e9109ec505e6c296960cdb56335d Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Fri, 27 Jun 2025 08:38:26 -0600 Subject: [PATCH 3/7] Revert to ncol --- src/physics/cam/gw_nlgw.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index 7c5a43c143..a116284fab 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -137,7 +137,7 @@ subroutine gw_nlgw_dp_ml(state_in, ptend, lchnk) allocate(uflux(ncol,pver)) allocate(vflux(ncol,pver)) - allocate(utgw(pcols,pver)) + allocate(utgw(ncol,pver)) allocate(vtgw(ncol,pver)) allocate(net_inputs(ncol, 4*pver_interp+3)) @@ -177,7 +177,7 @@ subroutine gw_nlgw_dp_ml(state_in, ptend, lchnk) ! Write UTGW and VTGW to file call outfld('UTGW_NL', utgw, ncol, lchnk) - call outfld('VTGW_NL', vtgw, ncol, lcnhk) + call outfld('VTGW_NL', vtgw, ncol, lchnk) ! update the tendencies From ea373198500a7656207f6d6ae9beb6f8b1027afc Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Fri, 12 Sep 2025 08:53:15 -0600 Subject: [PATCH 4/7] Add uflux and vflux outputs --- src/physics/cam/gw_nlgw.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index a116284fab..62044ffe98 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -179,6 +179,8 @@ subroutine gw_nlgw_dp_ml(state_in, ptend, lchnk) call outfld('UTGW_NL', utgw, ncol, lchnk) call outfld('VTGW_NL', vtgw, ncol, lchnk) + call outfld('UFLUX_NL', uflux, ncol, lchnk) + call outfld('VFLUX_NL', vflux, ncol, lchnk) ! update the tendencies ptend%u(:ncol,:pver) = ptend%u(:ncol,:pver) + utgw(:ncol,:pver) @@ -230,6 +232,8 @@ subroutine gw_nlgw_dp_init(model_path) 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') + call addfld('UFLUX_NL', (/ 'lev' /), 'A', 'm/s', 'Nonlinear GW zonal wind flux') + call addfld('VFLUX_NL', (/ 'lev' /), 'A', 'm/s', 'Nonlinear GW meridional wind flux') end subroutine gw_nlgw_dp_init From 3665aedd76273cc706564cf435475ad49d5a81ec Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Fri, 12 Sep 2025 08:55:14 -0600 Subject: [PATCH 5/7] Remove unnecessary pcols variable --- src/physics/cam/gw_nlgw.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index 62044ffe98..f60e639077 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -5,7 +5,7 @@ module gw_nlgw ! use gw_utils, only: r8, r4 -use ppgrid, only: pcols, pver !vertical levels +use ppgrid, only: 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 From b0d2470131646d0fb4f72de9d5a28ea6aef8a4bf Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Fri, 12 Sep 2025 08:57:22 -0600 Subject: [PATCH 6/7] cam_history used twice --- src/physics/cam/gw_nlgw.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index f60e639077..bee21f02ce 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -214,8 +214,6 @@ 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 From 8482d943b60ddb8b3acf54830827d030c228180e Mon Sep 17 00:00:00 2001 From: Matt Archer Date: Fri, 12 Sep 2025 11:14:03 -0600 Subject: [PATCH 7/7] Re-add addfld - compiles --- src/physics/cam/gw_nlgw.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/cam/gw_nlgw.F90 b/src/physics/cam/gw_nlgw.F90 index bee21f02ce..d9eb02e437 100644 --- a/src/physics/cam/gw_nlgw.F90 +++ b/src/physics/cam/gw_nlgw.F90 @@ -12,7 +12,7 @@ module gw_nlgw use cam_logfile, only: iulog use physconst, only: cappa, pi use interpolate_data, only: lininterp -use cam_history, only: outfld +use cam_history, only: outfld, addfld use ftorch