Skip to content

Commit

Permalink
Remove second dimension of tw_ini tw_cur as it is not different betwe…
Browse files Browse the repository at this point in the history
…en physics and dycore
  • Loading branch information
jimmielin committed Sep 10, 2024
1 parent 89e430f commit 1ecca08
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
26 changes: 7 additions & 19 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(31)
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 @@ -272,23 +272,17 @@ subroutine cam_state_snapshot_init(cam_snapshot_before_num_in, cam_snapshot_afte
'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_phys', 'state_tw_ini_phys', '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_phys', 'state_tw_cur_phys', '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)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%tw_ini_dyn', 'state_tw_ini_dyn', 'unset', horiz_only)

call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
'state%tw_cur_dyn', 'state_tw_cur_dyn', 'unset', horiz_only)

end subroutine cam_state_snapshot_init

subroutine cam_cnst_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
Expand Down Expand Up @@ -837,24 +831,18 @@ subroutine state_snapshot_all_outfld(lchnk, file_num, state)
case ('state%te_cur_phys')
call outfld(state_snapshot(i)%standard_name, state%te_cur(:, phys_te_idx), pcols, lchnk)

case ('state%tw_ini_phys')
call outfld(state_snapshot(i)%standard_name, state%tw_ini(:, 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_phys')
call outfld(state_snapshot(i)%standard_name, state%tw_cur(:, phys_te_idx), 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 ('state%tw_ini_dyn')
call outfld(state_snapshot(i)%standard_name, state%tw_ini(:, dyn_te_idx), pcols, lchnk)

case ('state%tw_cur_dyn')
call outfld(state_snapshot(i)%standard_name, state%tw_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

0 comments on commit 1ecca08

Please sign in to comment.