Skip to content
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

cam6_4_034: Add missing total energy in physics state from dycore in snapshots and cleanup total water #1142

Merged
Merged
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
63 changes: 63 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
===============================================================

Tag name: cam6_4_034
Originator(s): jimmielin
Date: Thu Sep 19 2024
One-line Summary: Add missing total energy in physics state from dycore in snapshots and cleanup total water
Github PR URL: https://github.com/ESCOMP/CAM/pull/1142

Purpose of changes (include the issue number and title text for each relevant GitHub issue):

Save second dimension (dycore formula) of total energy and total water initial and current condition
(fixes #1141)

Remove second dimension of tw_ini and tw_cur as they are not different between physics and dycore.

Describe any changes made to build system: N/A

Describe any changes made to the namelist: N/A

List any changes to the defaults for the boundary datasets: N/A

Describe any substantial timing or memory changes: N/A

Code reviewed by: cacraigucar, nusbaume

List all files eliminated: N/A

List all files added and what they do: N/A

List all existing files that have been modified, and describe the changes:
M src/control/cam_snapshot_common.F90
- renamed te_ini -> te_ini_phys, te_cur -> te_cur_phys
- added te_ini_dyn, te_cur_dyn which were missing from snapshot, now fixed
- resized state history buffer size

M src/physics/cam/check_energy.F90
M src/physics/cam/physics_types.F90
- removed incorrect second dimension of tw_ini and tw_cur as they are not different between physics / dycore

If there were any failures reported from running test_driver.sh on any test
platform, and checkin with these failures has been OK'd by the gatekeeper,
then copy the lines from the td.*.status files for the failed tests to the
appropriate machine below. All failed tests must be justified.

derecho/intel/aux_cam:

ERP_Ln9.f09_f09_mg17.FCSD_HCO.derecho_intel.cam-outfrq9s (Overall: FAIL)
- pre-existing failure due to HEMCO not having reproducible results issues #1018 and #856

SMS_D_Ln9_P1280x1.ne0CONUSne30x8_ne0CONUSne30x8_mt12.FCHIST.derecho_intel.cam-outfrq9s (Overall: PEND)
- pre-existing failure -- need fix in CLM external

derecho/nvhpc/aux_cam: ALL PASS

izumi/nag/aux_cam:

DAE.f45_f45_mg37.FHS94.izumi_nag.cam-dae (Overall: FAIL)
- pre-existing failure - issue #670

izumi/gnu/aux_cam: ALL PASS

Summarize any changes to answers: BFB

===============================================================

Tag name: cam6_4_033
Originator(s): gdicker1 ([email protected])
Date: Tue 10 Sep 2024
Expand Down
32 changes: 23 additions & 9 deletions src/control/cam_snapshot_common.F90
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module cam_snapshot_common
integer :: cam_snapshot_before_num, cam_snapshot_after_num

! Note the maximum number of variables for each type
type (snapshot_type) :: state_snapshot(27)
type (snapshot_type) :: state_snapshot(29)
type (snapshot_type) :: cnst_snapshot(pcnst)
type (snapshot_type) :: tend_snapshot(6)
type (snapshot_type) :: cam_in_snapshot(30)
Expand Down Expand Up @@ -266,16 +266,22 @@ subroutine cam_state_snapshot_init(cam_snapshot_before_num_in, cam_snapshot_afte
'state%zi', 'state_zi', 'm', 'ilev')

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%te_ini', 'state_te_ini', 'unset', horiz_only)
'state%te_ini_phys', 'state_te_ini_phys', 'unset', horiz_only)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%te_cur', 'state_te_cur', 'unset', horiz_only)
'state%te_cur_phys', 'state_te_cur_phys', 'unset', horiz_only)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%tw_ini', 'state_tw_ini', 'unset', horiz_only)
'state%tw_ini', 'state_tw_ini', 'unset', horiz_only)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%tw_cur', 'state_tw_cur', 'unset', horiz_only)
'state%tw_cur', 'state_tw_cur', 'unset', horiz_only)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%te_ini_dyn', 'state_te_ini_dyn', 'unset', horiz_only)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%te_cur_dyn', 'state_te_cur_dyn', 'unset', horiz_only)

end subroutine cam_state_snapshot_init

Expand Down Expand Up @@ -734,6 +740,8 @@ end subroutine snapshot_addfld

subroutine state_snapshot_all_outfld(lchnk, file_num, state)

use physics_types, only: phys_te_idx, dyn_te_idx

integer, intent(in) :: lchnk
integer, intent(in) :: file_num
type(physics_state), intent(in) :: state
Expand Down Expand Up @@ -817,18 +825,24 @@ subroutine state_snapshot_all_outfld(lchnk, file_num, state)
case ('state%zi')
call outfld(state_snapshot(i)%standard_name, state%zi, pcols, lchnk)

case ('state%te_ini')
call outfld(state_snapshot(i)%standard_name, state%te_ini, pcols, lchnk)
case ('state%te_ini_phys')
call outfld(state_snapshot(i)%standard_name, state%te_ini(:, phys_te_idx), pcols, lchnk)

case ('state%te_cur')
call outfld(state_snapshot(i)%standard_name, state%te_cur, pcols, lchnk)
case ('state%te_cur_phys')
call outfld(state_snapshot(i)%standard_name, state%te_cur(:, phys_te_idx), pcols, lchnk)

case ('state%tw_ini')
call outfld(state_snapshot(i)%standard_name, state%tw_ini, pcols, lchnk)

case ('state%tw_cur')
call outfld(state_snapshot(i)%standard_name, state%tw_cur, pcols, lchnk)

case ('state%te_ini_dyn')
call outfld(state_snapshot(i)%standard_name, state%te_ini(:, dyn_te_idx), pcols, lchnk)

case ('state%te_cur_dyn')
call outfld(state_snapshot(i)%standard_name, state%te_cur(:, dyn_te_idx), pcols, lchnk)

case default
call endrun('ERROR in state_snapshot_all_outfld: no match found for '//trim(state_snapshot(i)%ddt_string))

Expand Down
24 changes: 11 additions & 13 deletions src/physics/cam/check_energy.F90
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
state%pdel(1:ncol,1:pver), cp_or_cv(1:ncol,1:pver), &
state%u(1:ncol,1:pver), state%v(1:ncol,1:pver), state%T(1:ncol,1:pver), &
vc_physics, ptop=state%pintdry(1:ncol,1), phis = state%phis(1:ncol),&
te = state%te_ini(1:ncol,phys_te_idx), H2O = state%tw_ini(1:ncol,phys_te_idx))
te = state%te_ini(1:ncol,phys_te_idx), H2O = state%tw_ini(1:ncol))
!
! Dynamical core total energy
!
Expand All @@ -283,7 +283,7 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
state%u(1:ncol,1:pver), state%v(1:ncol,1:pver), state%T(1:ncol,1:pver), &
vc_dycore, ptop=state%pintdry(1:ncol,1), phis = state%phis(1:ncol), &
z_mid = state%z_ini(1:ncol,:), &
te = state%te_ini(1:ncol,dyn_te_idx), H2O = state%tw_ini(1:ncol,dyn_te_idx))
te = state%te_ini(1:ncol,dyn_te_idx), H2O = state%tw_ini(1:ncol))
else if (vc_dycore == vc_dry_pressure) then
!
! SE specific hydrostatic energy (enthalpy)
Expand All @@ -297,16 +297,15 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
state%pdel(1:ncol,1:pver), cp_or_cv(1:ncol,1:pver), &
state%u(1:ncol,1:pver), state%v(1:ncol,1:pver), state%T(1:ncol,1:pver), &
vc_dry_pressure, ptop=state%pintdry(1:ncol,1), phis = state%phis(1:ncol), &
te = state%te_ini(1:ncol,dyn_te_idx), H2O = state%tw_ini(1:ncol,dyn_te_idx))
te = state%te_ini(1:ncol,dyn_te_idx), H2O = state%tw_ini(1:ncol))
else
!
! dycore energy is the same as physics
!
state%te_ini(1:ncol,dyn_te_idx) = state%te_ini(1:ncol,phys_te_idx)
state%tw_ini(1:ncol,dyn_te_idx) = state%tw_ini(1:ncol,phys_te_idx)
end if
state%te_cur(:ncol,:) = state%te_ini(:ncol,:)
state%tw_cur(:ncol,:) = state%tw_ini(:ncol,:)
state%tw_cur(:ncol) = state%tw_ini(:ncol)

! zero cummulative boundary fluxes
tend%te_tnd(:ncol) = 0._r8
Expand Down Expand Up @@ -404,7 +403,7 @@ subroutine check_energy_chng(state, tend, name, nstep, ztodt, &
do i = 1, ncol
! change in static energy and total water
te_dif(i) = te(i) - state%te_cur(i,phys_te_idx)
tw_dif(i) = tw(i) - state%tw_cur(i,phys_te_idx)
tw_dif(i) = tw(i) - state%tw_cur(i)

! expected tendencies from boundary fluxes for last process
te_tnd(i) = flx_vap(i)*(latvap+latice) - (flx_cnd(i) - flx_ice(i))*1000._r8*latice + flx_sen(i)
Expand All @@ -416,16 +415,16 @@ subroutine check_energy_chng(state, tend, name, nstep, ztodt, &

! expected new values from previous state plus boundary fluxes
te_xpd(i) = state%te_cur(i,phys_te_idx) + te_tnd(i)*ztodt
tw_xpd(i) = state%tw_cur(i,phys_te_idx) + tw_tnd(i)*ztodt
tw_xpd(i) = state%tw_cur(i) + tw_tnd(i)*ztodt

! relative error, expected value - input state / previous state
te_rer(i) = (te_xpd(i) - te(i)) / state%te_cur(i,phys_te_idx)
end do

! relative error for total water (allow for dry atmosphere)
tw_rer = 0._r8
where (state%tw_cur(:ncol,phys_te_idx) > 0._r8)
tw_rer(:ncol) = (tw_xpd(:ncol) - tw(:ncol)) / state%tw_cur(:ncol,1)
where (state%tw_cur(:ncol) > 0._r8)
tw_rer(:ncol) = (tw_xpd(:ncol) - tw(:ncol)) / state%tw_cur(:ncol)
end where

! error checking
Expand Down Expand Up @@ -457,7 +456,7 @@ subroutine check_energy_chng(state, tend, name, nstep, ztodt, &

do i = 1, ncol
state%te_cur(i,phys_te_idx) = te(i)
state%tw_cur(i,phys_te_idx) = tw(i)
state%tw_cur(i) = tw(i)
end do

!
Expand All @@ -480,7 +479,7 @@ subroutine check_energy_chng(state, tend, name, nstep, ztodt, &
state%u(1:ncol,1:pver), state%v(1:ncol,1:pver), temp(1:ncol,1:pver), &
vc_dycore, ptop=state%pintdry(1:ncol,1), phis = state%phis(1:ncol), &
z_mid = state%z_ini(1:ncol,:), &
te = state%te_cur(1:ncol,dyn_te_idx), H2O = state%tw_cur(1:ncol,dyn_te_idx))
te = state%te_cur(1:ncol,dyn_te_idx), H2O = state%tw_cur(1:ncol))
else if (vc_dycore == vc_dry_pressure) then
!
! SE specific hydrostatic energy
Expand All @@ -500,10 +499,9 @@ subroutine check_energy_chng(state, tend, name, nstep, ztodt, &
state%pdel(1:ncol,1:pver), cp_or_cv(1:ncol,1:pver), &
state%u(1:ncol,1:pver), state%v(1:ncol,1:pver), temp(1:ncol,1:pver), &
vc_dry_pressure, ptop=state%pintdry(1:ncol,1), phis = state%phis(1:ncol), &
te = state%te_cur(1:ncol,dyn_te_idx), H2O = state%tw_cur(1:ncol,dyn_te_idx))
te = state%te_cur(1:ncol,dyn_te_idx), H2O = state%tw_cur(1:ncol))
else
state%te_cur(1:ncol,dyn_te_idx) = te(1:ncol)
state%tw_cur(1:ncol,dyn_te_idx) = tw(1:ncol)
end if
end subroutine check_energy_chng

Expand Down
23 changes: 12 additions & 11 deletions src/physics/cam/physics_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ module physics_types
! Second dimension is (phys_te_idx) CAM physics total energy and
! (dyn_te_idx) dycore total energy computed in physics
te_ini, &! vertically integrated total (kinetic + static) energy of initial state
te_cur, &! vertically integrated total (kinetic + static) energy of current state
te_cur ! vertically integrated total (kinetic + static) energy of current state
real(r8), dimension(:), allocatable :: &
tw_ini, &! vertically integrated total water of initial state
tw_cur ! vertically integrated total water of new state
real(r8), dimension(:,:),allocatable :: &
Expand Down Expand Up @@ -537,9 +538,9 @@ subroutine physics_state_check(state, name)
varname="state%te_ini", msg=msg)
call shr_assert_in_domain(state%te_cur(:ncol,:), is_nan=.false., &
varname="state%te_cur", msg=msg)
call shr_assert_in_domain(state%tw_ini(:ncol,:), is_nan=.false., &
call shr_assert_in_domain(state%tw_ini(:ncol), is_nan=.false., &
varname="state%tw_ini", msg=msg)
call shr_assert_in_domain(state%tw_cur(:ncol,:), is_nan=.false., &
call shr_assert_in_domain(state%tw_cur(:ncol), is_nan=.false., &
varname="state%tw_cur", msg=msg)
call shr_assert_in_domain(state%temp_ini(:ncol,:), is_nan=.false., &
varname="state%temp_ini", msg=msg)
Expand Down Expand Up @@ -615,9 +616,9 @@ subroutine physics_state_check(state, name)
varname="state%te_ini", msg=msg)
call shr_assert_in_domain(state%te_cur(:ncol,:), lt=posinf_r8, gt=neginf_r8, &
varname="state%te_cur", msg=msg)
call shr_assert_in_domain(state%tw_ini(:ncol,:), lt=posinf_r8, gt=neginf_r8, &
call shr_assert_in_domain(state%tw_ini(:ncol), lt=posinf_r8, gt=neginf_r8, &
varname="state%tw_ini", msg=msg)
call shr_assert_in_domain(state%tw_cur(:ncol,:), lt=posinf_r8, gt=neginf_r8, &
call shr_assert_in_domain(state%tw_cur(:ncol), lt=posinf_r8, gt=neginf_r8, &
varname="state%tw_cur", msg=msg)
call shr_assert_in_domain(state%temp_ini(:ncol,:), lt=posinf_r8, gt=neginf_r8, &
varname="state%temp_ini", msg=msg)
Expand Down Expand Up @@ -1351,8 +1352,8 @@ subroutine physics_state_copy(state_in, state_out)
end do
state_out%te_ini(:ncol,:) = state_in%te_ini(:ncol,:)
state_out%te_cur(:ncol,:) = state_in%te_cur(:ncol,:)
state_out%tw_ini(:ncol,:) = state_in%tw_ini(:ncol,:)
state_out%tw_cur(:ncol,:) = state_in%tw_cur(:ncol,:)
state_out%tw_ini(:ncol) = state_in%tw_ini(:ncol)
state_out%tw_cur(:ncol) = state_in%tw_cur(:ncol)

do k = 1, pver
do i = 1, ncol
Expand Down Expand Up @@ -1667,10 +1668,10 @@ subroutine physics_state_alloc(state,lchnk,psetcols)
allocate(state%te_cur(psetcols,2), stat=ierr)
if ( ierr /= 0 ) call endrun('physics_state_alloc error: allocation error for state%te_cur')

allocate(state%tw_ini(psetcols,2), stat=ierr)
allocate(state%tw_ini(psetcols), stat=ierr)
if ( ierr /= 0 ) call endrun('physics_state_alloc error: allocation error for state%tw_ini')

allocate(state%tw_cur(psetcols,2), stat=ierr)
allocate(state%tw_cur(psetcols), stat=ierr)
if ( ierr /= 0 ) call endrun('physics_state_alloc error: allocation error for state%tw_cur')

allocate(state%temp_ini(psetcols,pver), stat=ierr)
Expand Down Expand Up @@ -1720,8 +1721,8 @@ subroutine physics_state_alloc(state,lchnk,psetcols)

state%te_ini(:,:) = inf
state%te_cur(:,:) = inf
state%tw_ini(:,:) = inf
state%tw_cur(:,:) = inf
state%tw_ini(:) = inf
state%tw_cur(:) = inf
state%temp_ini(:,:) = inf
state%z_ini(:,:) = inf

Expand Down
Loading