-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implements cam_thermo_water_update and CCPPized check_energy #316
Merged
jimmielin
merged 43 commits into
ESCOMP:development
from
jimmielin:hplin/check_energy_rebase
Dec 16, 2024
Merged
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
8648970
Initial implementation of cp_to_cv_dycore/cam_thermo_water_update fro…
jimmielin 333ad4e
Initial port of updates to energy budget (port of CAM #761) into CAM-…
jimmielin 041cdfb
Add is_first_timestep registry
jimmielin 7493a1d
Fix build issues; update factor in get_cp call to 1/dp
jimmielin 4ce8427
Add gmean_mod to src/utils including support infra in physics_grid.F90
jimmielin 2372f7f
Fix for b4b to CAM-SIMA (w/ History); add notes on modifications and/…
jimmielin c015e28
Update ncar-physics external
jimmielin e13e7ea
Fix build (part 1); update standard names and atmos_phys external
jimmielin 0d16be9
New const_get_index logic without cam_ccpp_cap dependency
jimmielin 8fca3a4
Update vcoord to energy_formula
jimmielin 38fdbb2
Read cp_or_cv_dycore and identify dycore information from CAM snapshot
jimmielin 240ef54
Set wv_idx in air_composition
jimmielin bef25fb
Update atmos_phys external
jimmielin 8b8a8e0
Fix merge conflicts
jimmielin 53cba06
Implements CCPPized check_energy in SIMA.
jimmielin a4d3866
Add adiabatic scheme and check_energy_fix
jimmielin e0450f9
Fix index underflow in get_hydrostatic_energy; update ncar-physics ex…
jimmielin 6e5873e
Update with ne3np4 inic files
jimmielin 768040e
Now mark energy consistency variables in registry as initialized in d…
jimmielin 03100c1
Fix remaining issues in adiabatic scheme; add teout to registry and i…
jimmielin e4d387f
Merge branch 'hplin/check_energy' into hplin/check_energy_rebase
jimmielin 3a1a5b9
Update ncar-physics external for dycore_energy_consistency_adjust
jimmielin 7a706da
Update atmospheric_physics external; standard names to address review…
jimmielin 11e9a20
Update nstep from model state; add FADIAB physics-suite
jimmielin 800bf8b
Update standard names from review comments; add flag for energy consi…
jimmielin 916cb9f
rga -> gravit
jimmielin b7abae1
gmean diagnostic updates
jimmielin 6105ca8
Address review comments (update external)
jimmielin cca6e42
Merge branch 'development' into hplin/check_energy_rebase
jimmielin f999707
Address review comments
jimmielin 3d2fd91
Address review comments
jimmielin fc1789b
Remove mention of check_energy_timestep_init in dp_coupling since it …
jimmielin 58a151a
Fix build
jimmielin 63dff8f
Add pver dim check in cam_thermo_dry_air_update
jimmielin 55ea5b3
Pass cp_or_cv_dycore explicitly to cam_thermo_water_update in prepara…
jimmielin a8b977b
Fixes for MPAS dynamical core to support cam_thermo_water_update
jimmielin 7448d73
Fix FPHYStest test failure
jimmielin 4bbb920
Address review comments
jimmielin e28e9b9
Update src/dynamics/mpas/dyn_comp.F90
jimmielin 2769a0d
Update src/dynamics/mpas/dyn_comp.F90
jimmielin 835bfbe
Update src/dynamics/mpas/dyn_comp.F90
jimmielin 1df3251
Update src/dynamics/mpas/dyn_comp.F90
jimmielin dc50fea
Update list of existing test failures
jimmielin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||
! air_composition module defines major species of the atmosphere and manages the physical properties that are dependent on the composition of air | ||||||
! air_composition module defines major species of the atmosphere and manages | ||||||
! the physical properties that are dependent on the composition of air | ||||||
module air_composition | ||||||
|
||||||
use ccpp_kinds, only: kind_phys | ||||||
|
@@ -12,7 +13,9 @@ module air_composition | |||||
save | ||||||
|
||||||
public :: air_composition_init | ||||||
public :: air_composition_update | ||||||
public :: dry_air_composition_update | ||||||
public :: water_composition_update | ||||||
|
||||||
! get_cp_dry: (generalized) heat capacity for dry air | ||||||
public :: get_cp_dry | ||||||
! get_cp: (generalized) heat capacity | ||||||
|
@@ -225,7 +228,7 @@ subroutine air_composition_init() | |||||
! | ||||||
!************************************************************************ | ||||||
! | ||||||
! add prognostic components of dry air | ||||||
! add prognostic components of air | ||||||
! | ||||||
!************************************************************************ | ||||||
! | ||||||
|
@@ -309,6 +312,7 @@ subroutine air_composition_init() | |||||
! | ||||||
case(wv_stdname) !water_vapor_mixing_ratio_wrt_moist_air_and_condensed_water | ||||||
call air_species_info(wv_stdname, ix, mw) | ||||||
wv_idx = ix ! set water species index for use in get_hydrostatic_energy | ||||||
thermodynamic_active_species_idx(icnst) = ix | ||||||
thermodynamic_active_species_cp (icnst) = cpwv | ||||||
thermodynamic_active_species_cv (icnst) = cv3 / mw | ||||||
|
@@ -510,26 +514,68 @@ end subroutine air_composition_init | |||||
|
||||||
!=========================================================================== | ||||||
!----------------------------------------------------------------------- | ||||||
! air_composition_update: Update the physics "constants" that vary | ||||||
! dry_air_composition_update: Update the physics "constants" that vary | ||||||
!------------------------------------------------------------------------- | ||||||
!=========================================================================== | ||||||
|
||||||
subroutine air_composition_update(mmr, ncol, to_moist_factor) | ||||||
subroutine dry_air_composition_update(mmr, ncol, to_dry_factor) | ||||||
|
||||||
real(kind_phys), intent(in) :: mmr(:,:,:) ! constituents array | ||||||
!(mmr = dry mixing ratio, if not, use to_dry_factor to convert!) | ||||||
real(kind_phys), intent(in) :: mmr(:,:,:) ! mixing ratios for species dependent dry air | ||||||
integer, intent(in) :: ncol ! number of columns | ||||||
real(kind_phys), optional, intent(in) :: to_moist_factor(:,:) | ||||||
real(kind_phys), optional, intent(in) :: to_dry_factor(:,:) | ||||||
|
||||||
call get_R_dry(mmr(:ncol, :, :), thermodynamic_active_species_idx, & | ||||||
rairv(:ncol, :), fact=to_moist_factor) | ||||||
rairv(:ncol, :), fact=to_dry_factor) | ||||||
call get_cp_dry(mmr(:ncol,:,:), thermodynamic_active_species_idx, & | ||||||
cpairv(:ncol,:), fact=to_moist_factor) | ||||||
cpairv(:ncol,:), fact=to_dry_factor) | ||||||
call get_mbarv(mmr(:ncol,:,:), thermodynamic_active_species_idx, & | ||||||
mbarv(:ncol,:), fact=to_moist_factor) | ||||||
mbarv(:ncol,:), fact=to_dry_factor) | ||||||
|
||||||
cappav(:ncol,:) = rairv(:ncol,:) / cpairv(:ncol,:) | ||||||
|
||||||
end subroutine air_composition_update | ||||||
end subroutine dry_air_composition_update | ||||||
|
||||||
!=========================================================================== | ||||||
!--------------------------------------------------------------------------- | ||||||
! water_composition_update: Update generalized cp or cv depending on dycore | ||||||
! (enthalpy for pressure-based dynamical cores and internal energy for z-based dynamical cores) | ||||||
!--------------------------------------------------------------------------- | ||||||
!=========================================================================== | ||||||
subroutine water_composition_update(mmr, ncol, energy_formula, cp_or_cv_dycore, to_dry_factor) | ||||||
use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_FV, ENERGY_FORMULA_DYCORE_SE, ENERGY_FORMULA_DYCORE_MPAS | ||||||
use string_utils, only: stringify | ||||||
|
||||||
real(kind_phys), intent(in) :: mmr(:,:,:) ! constituents array | ||||||
integer, intent(in) :: ncol ! number of columns | ||||||
integer, intent(in) :: energy_formula ! energy formula for dynamical core | ||||||
real(kind_phys), intent(out) :: cp_or_cv_dycore(:,:) ! enthalpy or heat capacity, dycore dependent [J K-1 kg-1] | ||||||
real(kind_phys), optional, intent(in) :: to_dry_factor(:,:) | ||||||
|
||||||
character(len=*), parameter :: subname = 'water_composition_update' | ||||||
|
||||||
! update enthalpy or internal energy scaling factor for energy consistency with CAM physics | ||||||
if (energy_formula == ENERGY_FORMULA_DYCORE_FV) then | ||||||
! FV: moist pressure vertical coordinate does not need update. | ||||||
else if (energy_formula == ENERGY_FORMULA_DYCORE_SE) then | ||||||
! SE | ||||||
! Note: species index subset to 1: because SIMA currently uses index 0. See #334. | ||||||
call get_cp(mmr(:ncol,:,:), .false., cp_or_cv_dycore(:ncol,:), & | ||||||
factor=to_dry_factor, active_species_idx_dycore=thermodynamic_active_species_idx(1:), & | ||||||
cpdry=cpairv(:ncol,:)) | ||||||
else if (energy_formula == ENERGY_FORMULA_DYCORE_MPAS) then | ||||||
! MPAS | ||||||
! Note: species index subset to 1: because SIMA currently uses index 0. See #334. | ||||||
call get_R(mmr(:ncol,:,:), thermodynamic_active_species_idx(1:), & | ||||||
cp_or_cv_dycore(:ncol,:), fact=to_dry_factor, Rdry=rairv(:ncol,:)) | ||||||
|
||||||
! internal energy coefficient for MPAS | ||||||
! (equation 92 in Eldred et al. 2023; doi:10.1002/qj.4353) | ||||||
cp_or_cv_dycore(:ncol,:) = cp_or_cv_dycore(:ncol,:) * (cpairv(:ncol,:) - rairv(:ncol,:)) / rairv(:ncol,:) | ||||||
else | ||||||
call endrun(subname//': dycore energy formula (value = '//stringify((/energy_formula/))//') not supported') | ||||||
end if | ||||||
end subroutine water_composition_update | ||||||
|
||||||
!=========================================================================== | ||||||
!*************************************************************************** | ||||||
|
@@ -639,27 +685,33 @@ end subroutine get_cp_dry_2hd | |||||
! | ||||||
!*************************************************************************** | ||||||
! | ||||||
subroutine get_cp_1hd(tracer, inv_cp, cp, dp_dry, active_species_idx_dycore) | ||||||
subroutine get_cp_1hd(tracer, inv_cp, cp, factor, active_species_idx_dycore, cpdry) | ||||||
use cam_abortutils, only: endrun | ||||||
use string_utils, only: to_str | ||||||
|
||||||
! Dummy arguments | ||||||
! tracer: Tracer array | ||||||
! | ||||||
! if factor not present then tracer must be a dry mixing ratio | ||||||
! if factor present tracer*factor must be a dry mixing ratio | ||||||
! | ||||||
real(kind_phys), intent(in) :: tracer(:,:,:) | ||||||
real(kind_phys), optional, intent(in) :: dp_dry(:,:) | ||||||
! inv_cp: output inverse cp instead of cp | ||||||
logical, intent(in) :: inv_cp | ||||||
real(kind_phys), intent(out) :: cp(:,:) | ||||||
! if provided then tracer is not a mass mixing ratio | ||||||
real(kind_phys), optional, intent(in) :: factor(:,:) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to specify that is a dry mass mixing ratio (?):
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, updated! |
||||||
! active_species_idx_dycore: array of indices for index of | ||||||
! thermodynamic active species in dycore tracer array | ||||||
! (if different from physics index) | ||||||
integer, optional, intent(in) :: active_species_idx_dycore(:) | ||||||
real(kind_phys), optional, intent(in) :: cpdry(:,:) | ||||||
|
||||||
! Local variables | ||||||
integer :: qdx, itrac | ||||||
real(kind_phys) :: sum_species(SIZE(cp, 1), SIZE(cp, 2)) | ||||||
real(kind_phys) :: sum_cp(SIZE(cp, 1), SIZE(cp, 2)) | ||||||
real(kind_phys) :: factor(SIZE(cp, 1), SIZE(cp, 2)) | ||||||
real(kind_phys) :: factor_local(SIZE(cp, 1), SIZE(cp, 2)) | ||||||
integer :: idx_local(thermodynamic_active_species_num) | ||||||
character(len=*), parameter :: subname = 'get_cp_1hd: ' | ||||||
|
||||||
|
@@ -675,28 +727,37 @@ subroutine get_cp_1hd(tracer, inv_cp, cp, dp_dry, active_species_idx_dycore) | |||||
idx_local = thermodynamic_active_species_idx | ||||||
end if | ||||||
|
||||||
if (present(dp_dry)) then | ||||||
factor = 1.0_kind_phys / dp_dry | ||||||
if (present(factor)) then | ||||||
factor_local = factor | ||||||
else | ||||||
factor = 1.0_kind_phys | ||||||
factor_local = 1.0_kind_phys | ||||||
end if | ||||||
|
||||||
sum_species = 1.0_kind_phys ! all dry air species sum to 1 | ||||||
do qdx = dry_air_species_num + 1, thermodynamic_active_species_num | ||||||
itrac = idx_local(qdx) | ||||||
sum_species(:,:) = sum_species(:,:) + & | ||||||
(tracer(:,:,itrac) * factor(:,:)) | ||||||
sum_species(:,:) = sum_species(:,:) + (tracer(:,:,itrac) * factor_local(:,:)) | ||||||
end do | ||||||
|
||||||
! Get heat capacity at constant pressure (Cp) for dry air: | ||||||
call get_cp_dry(tracer, idx_local, sum_cp, fact=factor) | ||||||
if (dry_air_species_num == 0) then | ||||||
sum_cp = thermodynamic_active_species_cp(0) | ||||||
else if (present(cpdry)) then | ||||||
! | ||||||
! if cpdry is known don't recompute | ||||||
! | ||||||
sum_cp = cpdry | ||||||
else | ||||||
! Get heat capacity at constant pressure (Cp) for dry air: | ||||||
call get_cp_dry(tracer, idx_local, sum_cp, fact=factor_local) | ||||||
end if | ||||||
|
||||||
! Add water species to Cp: | ||||||
do qdx = dry_air_species_num + 1, thermodynamic_active_species_num | ||||||
itrac = idx_local(qdx) | ||||||
sum_cp(:,:) = sum_cp(:,:) + & | ||||||
(thermodynamic_active_species_cp(qdx) * tracer(:,:,itrac) * & | ||||||
factor(:,:)) | ||||||
(thermodynamic_active_species_cp(qdx) * tracer(:,:,itrac) * factor_local(:,:)) | ||||||
end do | ||||||
|
||||||
if (inv_cp) then | ||||||
cp = sum_species / sum_cp | ||||||
else | ||||||
|
@@ -707,34 +768,41 @@ end subroutine get_cp_1hd | |||||
|
||||||
!=========================================================================== | ||||||
|
||||||
subroutine get_cp_2hd(tracer, inv_cp, cp, dp_dry, active_species_idx_dycore) | ||||||
subroutine get_cp_2hd(tracer, inv_cp, cp, factor, active_species_idx_dycore, cpdry) | ||||||
! Version of get_cp for arrays that have a second horizontal index | ||||||
use cam_abortutils, only: endrun | ||||||
use string_utils, only: to_str | ||||||
|
||||||
! Dummy arguments | ||||||
! tracer: Tracer array | ||||||
real(kind_phys), intent(in) :: tracer(:,:,:,:) | ||||||
real(kind_phys), optional, intent(in) :: dp_dry(:,:,:) | ||||||
! inv_cp: output inverse cp instead of cp | ||||||
logical, intent(in) :: inv_cp | ||||||
real(kind_phys), intent(out) :: cp(:,:,:) | ||||||
real(kind_phys), optional, intent(in) :: factor(:,:,:) | ||||||
! active_species_idx_dycore: array of indicies for index of | ||||||
! thermodynamic active species in dycore tracer array | ||||||
! (if different from physics index) | ||||||
integer, optional, intent(in) :: active_species_idx_dycore(:) | ||||||
real(kind_phys), optional, intent(in) :: cpdry(:,:,:) | ||||||
|
||||||
! Local variables | ||||||
integer :: jdx | ||||||
integer :: idx_local(thermodynamic_active_species_num) | ||||||
character(len=*), parameter :: subname = 'get_cp_2hd: ' | ||||||
|
||||||
do jdx = 1, SIZE(cp, 2) | ||||||
if (present(dp_dry)) then | ||||||
call get_cp(tracer(:, jdx, :, :), inv_cp, cp(:, jdx, :), & | ||||||
dp_dry=dp_dry(:, jdx, :), active_species_idx_dycore=active_species_idx_dycore) | ||||||
if (present(factor).and.present(cpdry)) then | ||||||
call get_cp(tracer(:, jdx, :, :), inv_cp, cp(:, jdx, :),& | ||||||
factor=factor(:, jdx, :), active_species_idx_dycore=active_species_idx_dycore, cpdry=cpdry(:,jdx,:)) | ||||||
else if (present(factor)) then | ||||||
call get_cp(tracer(:, jdx, :, :), inv_cp, cp(:, jdx, :),& | ||||||
factor=factor(:, jdx, :), active_species_idx_dycore=active_species_idx_dycore) | ||||||
else if (present(cpdry)) then | ||||||
call get_cp(tracer(:, jdx, :, :), inv_cp, cp(:, jdx, :),& | ||||||
active_species_idx_dycore=active_species_idx_dycore, cpdry=cpdry(:,jdx,:)) | ||||||
else | ||||||
call get_cp(tracer(:, jdx, :, :), inv_cp, cp(:, jdx, :), & | ||||||
call get_cp(tracer(:, jdx, :, :), inv_cp, cp(:, jdx, :),& | ||||||
active_species_idx_dycore=active_species_idx_dycore) | ||||||
end if | ||||||
end do | ||||||
|
@@ -843,9 +911,10 @@ end subroutine get_R_dry_2hd | |||||
! | ||||||
!*************************************************************************** | ||||||
! | ||||||
subroutine get_R_1hd(tracer, active_species_idx, R, fact) | ||||||
subroutine get_R_1hd(tracer, active_species_idx, R, fact, Rdry) | ||||||
use cam_abortutils, only: endrun | ||||||
use string_utils, only: to_str | ||||||
use physconst, only: rair | ||||||
|
||||||
! Dummy arguments | ||||||
! tracer: !tracer array | ||||||
|
@@ -856,6 +925,7 @@ subroutine get_R_1hd(tracer, active_species_idx, R, fact) | |||||
real(kind_phys), intent(out) :: R(:, :) | ||||||
! fact: optional factor for converting tracer to dry mixing ratio | ||||||
real(kind_phys), optional, intent(in) :: fact(:, :) | ||||||
real(kind_phys), optional, intent(in) :: Rdry(:, :) | ||||||
|
||||||
! Local variables | ||||||
integer :: qdx, itrac | ||||||
|
@@ -874,12 +944,19 @@ subroutine get_R_1hd(tracer, active_species_idx, R, fact) | |||||
call endrun(subname//"SIZE mismatch in dimension 2 "// & | ||||||
to_str(SIZE(fact, 2))//' /= '//to_str(SIZE(factor, 2))) | ||||||
end if | ||||||
call get_R_dry(tracer, active_species_idx, R, fact=fact) | ||||||
factor = fact(:,:) | ||||||
else | ||||||
call get_R_dry(tracer, active_species_idx, R) | ||||||
factor = 1.0_kind_phys | ||||||
end if | ||||||
|
||||||
if (dry_air_species_num == 0) then | ||||||
R = rair | ||||||
else if (present(Rdry)) then | ||||||
R = Rdry | ||||||
else | ||||||
call get_R_dry(tracer, active_species_idx, R, fact=factor) | ||||||
end if | ||||||
|
||||||
idx_local = active_species_idx | ||||||
sum_species = 1.0_kind_phys ! all dry air species sum to 1 | ||||||
do qdx = dry_air_species_num + 1, thermodynamic_active_species_num | ||||||
|
@@ -934,7 +1011,7 @@ end subroutine get_R_2hd | |||||
!************************************************************************************************************************* | ||||||
! | ||||||
subroutine get_mbarv_1hd(tracer, active_species_idx, mbarv_in, fact) | ||||||
use physconst, only: mwdry, rair, cpair | ||||||
use physconst, only: mwdry | ||||||
real(kind_phys), intent(in) :: tracer(:,:,:) !tracer array | ||||||
integer, intent(in) :: active_species_idx(:) !index of active species in tracer | ||||||
real(kind_phys), intent(out) :: mbarv_in(:,:) !molecular weight of dry air | ||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to make it clear that #334 is a Github issue:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed!