Skip to content

Commit d924e4e

Browse files
committed
Update atmos_phys; move energy formula to cam_thermo_formula; write cp_or_cv_dycore to snapshot
1 parent 4b6de43 commit d924e4e

File tree

5 files changed

+53
-30
lines changed

5 files changed

+53
-30
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
[submodule "atmos_phys"]
3737
path = src/atmos_phys
3838
url = https://github.com/jimmielin/atmospheric_physics
39-
fxtag = df80b9c1
39+
fxtag = 952ebdd
4040
fxrequired = AlwaysRequired
4141
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics
4242

src/atmos_phys

Submodule atmos_phys updated 55 files

src/control/cam_snapshot_common.F90

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module cam_snapshot_common
8181
integer :: cam_snapshot_before_num, cam_snapshot_after_num
8282

8383
! Note the maximum number of variables for each type
84-
type (snapshot_type) :: state_snapshot(29)
84+
type (snapshot_type) :: state_snapshot(30)
8585
type (snapshot_type) :: cnst_snapshot(pcnst)
8686
type (snapshot_type) :: tend_snapshot(6)
8787
type (snapshot_type) :: cam_in_snapshot(30)
@@ -283,6 +283,9 @@ subroutine cam_state_snapshot_init(cam_snapshot_before_num_in, cam_snapshot_afte
283283
call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
284284
'state%te_cur_dyn', 'state_te_cur_dyn', 'unset', horiz_only)
285285

286+
call snapshot_addfld( nstate_var, state_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
287+
'air_composition_cp_or_cv_dycore', 'cp_or_cv_dycore', 'J kg-1 K-1', 'lev')
288+
286289
end subroutine cam_state_snapshot_init
287290

288291
subroutine cam_cnst_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
@@ -741,6 +744,7 @@ end subroutine snapshot_addfld
741744
subroutine state_snapshot_all_outfld(lchnk, file_num, state)
742745

743746
use physics_types, only: phys_te_idx, dyn_te_idx
747+
use air_composition, only: cp_or_cv_dycore
744748

745749
integer, intent(in) :: lchnk
746750
integer, intent(in) :: file_num
@@ -843,6 +847,9 @@ subroutine state_snapshot_all_outfld(lchnk, file_num, state)
843847
case ('state%te_cur_dyn')
844848
call outfld(state_snapshot(i)%standard_name, state%te_cur(:, dyn_te_idx), pcols, lchnk)
845849

850+
case ('air_composition_cp_or_cv_dycore')
851+
call outfld(state_snapshot(i)%standard_name, cp_or_cv_dycore(:,:,lchnk), pcols, lchnk)
852+
846853
case default
847854
call endrun('ERROR in state_snapshot_all_outfld: no match found for '//trim(state_snapshot(i)%ddt_string))
848855

src/physics/cam/check_energy.F90

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ subroutine tot_energy_phys(state, outfld_name_suffix,vc)
415415
use cam_thermo, only: get_hydrostatic_energy,thermo_budget_num_vars,thermo_budget_vars, &
416416
wvidx,wlidx,wiidx,seidx,poidx,keidx,moidx,mridx,ttidx,teidx
417417
use cam_history, only: outfld
418-
use dyn_tests_utils, only: vc_physics, vc_height, vc_dry_pressure
418+
use dyn_tests_utils, only: vc_physics
419+
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS
419420

420421
use cam_abortutils, only: endrun
421422
use cam_history_support, only: max_fieldname_len
@@ -467,7 +468,7 @@ subroutine tot_energy_phys(state, outfld_name_suffix,vc)
467468
end if
468469

469470
if (state%psetcols == pcols) then
470-
if (vc_loc == vc_height .or. vc_loc == vc_dry_pressure) then
471+
if (vc_loc == ENERGY_FORMULA_DYCORE_MPAS .or. vc_loc == ENERGY_FORMULA_DYCORE_SE) then
471472
cp_or_cv(:ncol,:) = cp_or_cv_dycore(:ncol,:,lchnk)
472473
else
473474
cp_or_cv(:ncol,:) = cpairv(:ncol,:,lchnk)
@@ -476,7 +477,7 @@ subroutine tot_energy_phys(state, outfld_name_suffix,vc)
476477
call endrun('tot_energy_phys: energy diagnostics not implemented/tested for subcolumns')
477478
end if
478479

479-
if (vc_loc == vc_height .or. vc_loc == vc_dry_pressure) then
480+
if (vc_loc == ENERGY_FORMULA_DYCORE_MPAS .or. vc_loc == ENERGY_FORMULA_DYCORE_SE) then
480481
scaling(:ncol,:) = cpairv(:ncol,:,lchnk)/cp_or_cv(:ncol,:)!scaling for energy consistency
481482
else
482483
scaling(:ncol,:) = 1.0_r8 !internal energy / enthalpy same as CAM physics
@@ -643,7 +644,8 @@ end subroutine check_energy_get_integrals
643644
subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
644645
use physics_buffer, only: physics_buffer_desc, pbuf_set_field
645646
use cam_abortutils, only: endrun
646-
use dyn_tests_utils, only: vc_physics, vc_dycore, vc_height, vc_dry_pressure
647+
use dyn_tests_utils, only: vc_physics, vc_dycore
648+
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS
647649
use physics_types, only: physics_tend
648650
use physics_types, only: phys_te_idx, dyn_te_idx
649651
use time_manager, only: is_first_step
@@ -671,7 +673,7 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
671673

672674
! The code below is split into not-subcolumns and subcolumns code, as there is different handling of the
673675
! cp passed into the hydrostatic energy call. CAM-SIMA does not support subcolumns, so we keep this special
674-
! handling inside this shim module. (hplin, 9/9/24)
676+
! handling inside this CAM interface. (hplin, 9/9/24)
675677
if(state%psetcols == pcols) then
676678
! No subcolumns
677679
local_cp_phys(:ncol,:) = cpairv(:ncol,:,lchnk)
@@ -685,10 +687,10 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
685687

686688
local_cp_phys(1:ncol,:) = cpair
687689

688-
if (vc_dycore == vc_height) then
690+
if (vc_dycore == ENERGY_FORMULA_DYCORE_MPAS) then
689691
! MPAS specific hydrostatic energy computation (internal energy)
690692
local_cp_or_cv_dycore(:ncol,:) = cpair-rair
691-
else if(vc_dycore == vc_dry_pressure) then
693+
else if(vc_dycore == ENERGY_FORMULA_DYCORE_SE) then
692694
! SE specific hydrostatic energy (enthalpy)
693695
local_cp_or_cv_dycore(:ncol,:) = cpair
694696
else
@@ -721,12 +723,12 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
721723
tw_cur = state%tw_cur(1:ncol), &
722724
tend_te_tnd = tend%te_tnd(1:ncol), &
723725
tend_tw_tnd = tend%tw_tnd(1:ncol), &
724-
temp_ini = state%temp_ini(:ncol,:), &
725-
z_ini = state%z_ini(:ncol,:), &
726+
temp_ini = state%temp_ini(:ncol,:), &
727+
z_ini = state%z_ini(:ncol,:), &
726728
count = state%count, &
727729
teout = teout(1:ncol), & ! dummy argument - actual teout written to pbuf directly below
728-
vc_physics = vc_physics, &
729-
vc_dycore = vc_dycore, &
730+
energy_formula_physics = vc_physics, &
731+
energy_formula_dycore = vc_dycore, &
730732
errmsg = errmsg, &
731733
errflg = errflg &
732734
)
@@ -741,15 +743,16 @@ end subroutine check_energy_timestep_init
741743
! Check that the energy and water change matches the boundary fluxes
742744
subroutine check_energy_cam_chng(state, tend, name, nstep, ztodt, &
743745
flx_vap, flx_cnd, flx_ice, flx_sen)
744-
use dyn_tests_utils, only: vc_physics, vc_dycore, vc_height, vc_dry_pressure
745-
use cam_abortutils, only: endrun
746-
use physics_types, only: phys_te_idx, dyn_te_idx
747-
use physics_types, only: physics_tend
748-
use physconst, only: cpair, rair, latice, latvap
749-
use air_composition, only: cpairv, cp_or_cv_dycore
746+
use dyn_tests_utils, only: vc_physics, vc_dycore
747+
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS
748+
use cam_abortutils, only: endrun
749+
use physics_types, only: phys_te_idx, dyn_te_idx
750+
use physics_types, only: physics_tend
751+
use physconst, only: cpair, rair, latice, latvap
752+
use air_composition, only: cpairv, cp_or_cv_dycore
750753

751754
! CCPP-ized subroutine
752-
use check_energy_chng, only: check_energy_chng_run
755+
use check_energy_chng, only: check_energy_chng_run
753756

754757
type(physics_state), intent(inout) :: state
755758
type(physics_tend ), intent(inout) :: tend
@@ -776,9 +779,8 @@ subroutine check_energy_cam_chng(state, tend, name, nstep, ztodt, &
776779
! No subcolumns
777780
local_cp_phys(:ncol,:) = cpairv(:ncol,:,lchnk)
778781

779-
! Only if vertical coordinate is vc_height or vc_dry_pressure, cp_or_cv_dycore
780-
! is nonzero.
781-
if(vc_dycore == vc_height .or. vc_dycore == vc_dry_pressure) then
782+
! Only if using MPAS or SE energy formula cp_or_cv_dycore is nonzero.
783+
if(vc_dycore == ENERGY_FORMULA_DYCORE_MPAS .or. vc_dycore == ENERGY_FORMULA_DYCORE_SE) then
782784
local_cp_or_cv_dycore(:ncol,:) = cp_or_cv_dycore(:ncol,:,lchnk)
783785

784786
scaling_dycore(:ncol,:) = cpairv(:ncol,:,lchnk)/local_cp_or_cv_dycore(:ncol,:) ! cp/cv scaling
@@ -792,11 +794,11 @@ subroutine check_energy_cam_chng(state, tend, name, nstep, ztodt, &
792794
local_cp_phys(:,:) = cpair
793795

794796
! Note: cp_or_cv set above for pressure coordinate
795-
if (vc_dycore == vc_height) then
797+
if (vc_dycore == ENERGY_FORMULA_DYCORE_MPAS) then
796798
! compute cv if vertical coordinate is height: cv = cp - R
797799
local_cp_or_cv_dycore(:ncol,:) = cpair-rair
798800
scaling_dycore(:ncol,:) = cpairv(:ncol,:,lchnk)/local_cp_or_cv_dycore(:ncol,:) ! cp/cv scaling
799-
else if (vc_dycore == vc_dry_pressure) then
801+
else if (vc_dycore == ENERGY_FORMULA_DYCORE_SE) then
800802
! SE specific hydrostatic energy
801803
local_cp_or_cv_dycore(:ncol,:) = cpair
802804
scaling_dycore(:ncol,:) = 1.0_r8
@@ -832,10 +834,10 @@ subroutine check_energy_cam_chng(state, tend, name, nstep, ztodt, &
832834
z_ini = state%z_ini(:ncol,:), &
833835
count = state%count, &
834836
ztodt = ztodt, &
835-
latice = latice, &
836-
latvap = latvap, &
837-
vc_physics = vc_physics, &
838-
vc_dycore = vc_dycore, &
837+
latice = latice, &
838+
latvap = latvap, &
839+
energy_formula_physics = vc_physics, &
840+
energy_formula_dycore = vc_dycore, &
839841
name = name, &
840842
flx_vap = flx_vap, &
841843
flx_cnd = flx_cnd, &

src/utils/cam_thermo_formula.F90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module cam_thermo_formula
2+
3+
implicit none
4+
private
5+
save
6+
7+
! energy_formula options for use by CCPPized check_energy
8+
integer, public, parameter :: ENERGY_FORMULA_DYCORE_FV = 0 ! vc_moist_pressure
9+
integer, public, parameter :: ENERGY_FORMULA_DYCORE_SE = 1 ! vc_dry_pressure
10+
integer, public, parameter :: ENERGY_FORMULA_DYCORE_MPAS = 2 ! vc_height
11+
12+
!REMOVECAM: in CAM, energy_formula_physics and energy_formula_dycore still uses vc_physics
13+
! and vc_dycore in dyn_tests_utils. The values are the same.
14+
end module cam_thermo_formula

0 commit comments

Comments
 (0)