Skip to content

Commit

Permalink
Update atmos_phys; move energy formula to cam_thermo_formula; write c…
Browse files Browse the repository at this point in the history
…p_or_cv_dycore to snapshot
  • Loading branch information
jimmielin committed Oct 25, 2024
1 parent 4b6de43 commit d924e4e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[submodule "atmos_phys"]
path = src/atmos_phys
url = https://github.com/jimmielin/atmospheric_physics
fxtag = df80b9c1
fxtag = 952ebdd
fxrequired = AlwaysRequired
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics

Expand Down
2 changes: 1 addition & 1 deletion src/atmos_phys
Submodule atmos_phys updated 55 files
+11 −1 .github/workflows/test.yaml
+88 −0 doc/ChangeLog
+122 −113 doc/NamesNotInDictionary.txt
+27 −28 schemes/check_energy/check_energy_chng.F90
+23 −23 schemes/check_energy/check_energy_chng.meta
+2 −3 schemes/check_energy/check_energy_chng_namelist.xml
+3 −3 schemes/check_energy/check_energy_fix.meta
+8 −21 schemes/check_energy/check_energy_gmean/check_energy_gmean.F90
+28 −4 schemes/check_energy/check_energy_gmean/check_energy_gmean.meta
+2 −2 schemes/check_energy/check_energy_scaling.meta
+1 −1 schemes/check_energy/check_energy_zero_fluxes.F90
+5 −5 schemes/check_energy/check_energy_zero_fluxes.meta
+56 −51 schemes/musica/micm/musica_ccpp_micm.F90
+31 −54 schemes/musica/micm/musica_ccpp_micm_util.F90
+64 −44 schemes/musica/musica_ccpp.F90
+37 −1 schemes/musica/musica_ccpp.meta
+1 −1 schemes/musica/musica_ccpp_namelist.xml
+5 −3 schemes/musica/musica_ccpp_util.F90
+123 −31 schemes/musica/tuvx/musica_ccpp_tuvx.F90
+171 −0 schemes/musica/tuvx/musica_ccpp_tuvx_height_grid.F90
+3 −3 schemes/sima_diagnostics/check_energy_diagnostics.F90
+3 −3 schemes/sima_diagnostics/check_energy_diagnostics.meta
+60 −0 schemes/sima_diagnostics/check_energy_gmean_diagnostics.F90
+49 −0 schemes/sima_diagnostics/check_energy_gmean_diagnostics.meta
+58 −0 schemes/sima_diagnostics/kessler_diagnostics.F90
+41 −0 schemes/sima_diagnostics/kessler_diagnostics.meta
+78 −0 schemes/sima_diagnostics/scheme_diagnostics_template.F90
+180 −0 schemes/sima_diagnostics/sima_state_diagnostics.F90
+191 −0 schemes/sima_diagnostics/sima_state_diagnostics.meta
+48 −0 schemes/sima_diagnostics/sima_tend_diagnostics.F90
+53 −0 schemes/sima_diagnostics/sima_tend_diagnostics.meta
+0 −0 schemes/sima_diagnostics/tropopause_diagnostics.F90
+0 −0 schemes/sima_diagnostics/tropopause_diagnostics.meta
+4 −0 suites/suite_cam7.xml
+4 −0 suites/suite_held_suarez_1994.xml
+5 −0 suites/suite_kessler.xml
+2 −0 suites/suite_tj2016.xml
+5 −2 test/cmake/TestUtils.cmake
+10 −2 test/docker/Dockerfile.musica
+80 −0 test/docker/Dockerfile.musica.no_install
+23 −3 test/musica/CMakeLists.txt
+1 −2 test/musica/micm/CMakeLists.txt
+32 −69 test/musica/micm/test_micm_util.F90
+2 −2 test/musica/musica_ccpp_namelist.F90
+128 −123 test/musica/test_musica_api.F90
+26 −0 test/musica/tuvx/CMakeLists.txt
+0 −8 test/musica/tuvx/configs/ts1_tsmlt.json
+103 −0 test/musica/tuvx/test_tuvx_height_grid.F90
+12 −5 test/test_suites/suite_check_energy.xml
+0 −10 test/test_suites/suite_check_energy_chng.xml
+27 −0 test/valgrind.supp
+50 −0 to_be_ccppized/ccpp_const_utils.F90
+152 −0 to_be_ccppized/coords_1d.F90
+1,181 −0 to_be_ccppized/linear_1d_operators.F90
+130 −0 to_be_ccppized/vertical_diffusion_solver.F90
9 changes: 8 additions & 1 deletion 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(29)
type (snapshot_type) :: state_snapshot(30)
type (snapshot_type) :: cnst_snapshot(pcnst)
type (snapshot_type) :: tend_snapshot(6)
type (snapshot_type) :: cam_in_snapshot(30)
Expand Down Expand Up @@ -283,6 +283,9 @@ subroutine cam_state_snapshot_init(cam_snapshot_before_num_in, cam_snapshot_afte
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, &
'air_composition_cp_or_cv_dycore', 'cp_or_cv_dycore', 'J kg-1 K-1', 'lev')

end subroutine cam_state_snapshot_init

subroutine cam_cnst_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
Expand Down Expand Up @@ -741,6 +744,7 @@ end subroutine snapshot_addfld
subroutine state_snapshot_all_outfld(lchnk, file_num, state)

use physics_types, only: phys_te_idx, dyn_te_idx
use air_composition, only: cp_or_cv_dycore

integer, intent(in) :: lchnk
integer, intent(in) :: file_num
Expand Down Expand Up @@ -843,6 +847,9 @@ subroutine state_snapshot_all_outfld(lchnk, file_num, state)
case ('state%te_cur_dyn')
call outfld(state_snapshot(i)%standard_name, state%te_cur(:, dyn_te_idx), pcols, lchnk)

case ('air_composition_cp_or_cv_dycore')
call outfld(state_snapshot(i)%standard_name, cp_or_cv_dycore(:,:,lchnk), pcols, lchnk)

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

Expand Down
56 changes: 29 additions & 27 deletions src/physics/cam/check_energy.F90
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ subroutine tot_energy_phys(state, outfld_name_suffix,vc)
use cam_thermo, only: get_hydrostatic_energy,thermo_budget_num_vars,thermo_budget_vars, &
wvidx,wlidx,wiidx,seidx,poidx,keidx,moidx,mridx,ttidx,teidx
use cam_history, only: outfld
use dyn_tests_utils, only: vc_physics, vc_height, vc_dry_pressure
use dyn_tests_utils, only: vc_physics
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS

use cam_abortutils, only: endrun
use cam_history_support, only: max_fieldname_len
Expand Down Expand Up @@ -467,7 +468,7 @@ subroutine tot_energy_phys(state, outfld_name_suffix,vc)
end if

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

if (vc_loc == vc_height .or. vc_loc == vc_dry_pressure) then
if (vc_loc == ENERGY_FORMULA_DYCORE_MPAS .or. vc_loc == ENERGY_FORMULA_DYCORE_SE) then
scaling(:ncol,:) = cpairv(:ncol,:,lchnk)/cp_or_cv(:ncol,:)!scaling for energy consistency
else
scaling(:ncol,:) = 1.0_r8 !internal energy / enthalpy same as CAM physics
Expand Down Expand Up @@ -643,7 +644,8 @@ end subroutine check_energy_get_integrals
subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
use physics_buffer, only: physics_buffer_desc, pbuf_set_field
use cam_abortutils, only: endrun
use dyn_tests_utils, only: vc_physics, vc_dycore, vc_height, vc_dry_pressure
use dyn_tests_utils, only: vc_physics, vc_dycore
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS
use physics_types, only: physics_tend
use physics_types, only: phys_te_idx, dyn_te_idx
use time_manager, only: is_first_step
Expand Down Expand Up @@ -671,7 +673,7 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)

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

local_cp_phys(1:ncol,:) = cpair

if (vc_dycore == vc_height) then
if (vc_dycore == ENERGY_FORMULA_DYCORE_MPAS) then
! MPAS specific hydrostatic energy computation (internal energy)
local_cp_or_cv_dycore(:ncol,:) = cpair-rair
else if(vc_dycore == vc_dry_pressure) then
else if(vc_dycore == ENERGY_FORMULA_DYCORE_SE) then
! SE specific hydrostatic energy (enthalpy)
local_cp_or_cv_dycore(:ncol,:) = cpair
else
Expand Down Expand Up @@ -721,12 +723,12 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type)
tw_cur = state%tw_cur(1:ncol), &
tend_te_tnd = tend%te_tnd(1:ncol), &
tend_tw_tnd = tend%tw_tnd(1:ncol), &
temp_ini = state%temp_ini(:ncol,:), &
z_ini = state%z_ini(:ncol,:), &
temp_ini = state%temp_ini(:ncol,:), &
z_ini = state%z_ini(:ncol,:), &
count = state%count, &
teout = teout(1:ncol), & ! dummy argument - actual teout written to pbuf directly below
vc_physics = vc_physics, &
vc_dycore = vc_dycore, &
energy_formula_physics = vc_physics, &
energy_formula_dycore = vc_dycore, &
errmsg = errmsg, &
errflg = errflg &
)
Expand All @@ -741,15 +743,16 @@ end subroutine check_energy_timestep_init
! Check that the energy and water change matches the boundary fluxes
subroutine check_energy_cam_chng(state, tend, name, nstep, ztodt, &
flx_vap, flx_cnd, flx_ice, flx_sen)
use dyn_tests_utils, only: vc_physics, vc_dycore, vc_height, vc_dry_pressure
use cam_abortutils, only: endrun
use physics_types, only: phys_te_idx, dyn_te_idx
use physics_types, only: physics_tend
use physconst, only: cpair, rair, latice, latvap
use air_composition, only: cpairv, cp_or_cv_dycore
use dyn_tests_utils, only: vc_physics, vc_dycore
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS
use cam_abortutils, only: endrun
use physics_types, only: phys_te_idx, dyn_te_idx
use physics_types, only: physics_tend
use physconst, only: cpair, rair, latice, latvap
use air_composition, only: cpairv, cp_or_cv_dycore

! CCPP-ized subroutine
use check_energy_chng, only: check_energy_chng_run
use check_energy_chng, only: check_energy_chng_run

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

! Only if vertical coordinate is vc_height or vc_dry_pressure, cp_or_cv_dycore
! is nonzero.
if(vc_dycore == vc_height .or. vc_dycore == vc_dry_pressure) then
! Only if using MPAS or SE energy formula cp_or_cv_dycore is nonzero.
if(vc_dycore == ENERGY_FORMULA_DYCORE_MPAS .or. vc_dycore == ENERGY_FORMULA_DYCORE_SE) then
local_cp_or_cv_dycore(:ncol,:) = cp_or_cv_dycore(:ncol,:,lchnk)

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

! Note: cp_or_cv set above for pressure coordinate
if (vc_dycore == vc_height) then
if (vc_dycore == ENERGY_FORMULA_DYCORE_MPAS) then
! compute cv if vertical coordinate is height: cv = cp - R
local_cp_or_cv_dycore(:ncol,:) = cpair-rair
scaling_dycore(:ncol,:) = cpairv(:ncol,:,lchnk)/local_cp_or_cv_dycore(:ncol,:) ! cp/cv scaling
else if (vc_dycore == vc_dry_pressure) then
else if (vc_dycore == ENERGY_FORMULA_DYCORE_SE) then
! SE specific hydrostatic energy
local_cp_or_cv_dycore(:ncol,:) = cpair
scaling_dycore(:ncol,:) = 1.0_r8
Expand Down Expand Up @@ -832,10 +834,10 @@ subroutine check_energy_cam_chng(state, tend, name, nstep, ztodt, &
z_ini = state%z_ini(:ncol,:), &
count = state%count, &
ztodt = ztodt, &
latice = latice, &
latvap = latvap, &
vc_physics = vc_physics, &
vc_dycore = vc_dycore, &
latice = latice, &
latvap = latvap, &
energy_formula_physics = vc_physics, &
energy_formula_dycore = vc_dycore, &
name = name, &
flx_vap = flx_vap, &
flx_cnd = flx_cnd, &
Expand Down
14 changes: 14 additions & 0 deletions src/utils/cam_thermo_formula.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module cam_thermo_formula

implicit none
private
save

! energy_formula options for use by CCPPized check_energy
integer, public, parameter :: ENERGY_FORMULA_DYCORE_FV = 0 ! vc_moist_pressure
integer, public, parameter :: ENERGY_FORMULA_DYCORE_SE = 1 ! vc_dry_pressure
integer, public, parameter :: ENERGY_FORMULA_DYCORE_MPAS = 2 ! vc_height

!REMOVECAM: in CAM, energy_formula_physics and energy_formula_dycore still uses vc_physics
! and vc_dycore in dyn_tests_utils. The values are the same.
end module cam_thermo_formula

0 comments on commit d924e4e

Please sign in to comment.