-
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
Changes from 7 commits
8648970
333ad4e
041cdfb
7493a1d
4ce8427
2372f7f
c015e28
e13e7ea
0d16be9
8fca3a4
38fdbb2
240ef54
bef25fb
8b8a8e0
53cba06
a4d3866
e0450f9
6e5873e
768040e
03100c1
e4d387f
3a1a5b9
7a706da
11e9a20
800bf8b
916cb9f
b7abae1
6105ca8
cca6e42
f999707
3d2fd91
fc1789b
58a151a
63dff8f
55ea5b3
a8b977b
7448d73
4bbb920
e28e9b9
2769a0d
835bfbe
1df3251
dc50fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,6 @@ module air_composition | |||||
use runtime_obj, only: unset_real, unset_int | ||||||
use phys_vars_init_check, only: std_name_len | ||||||
use physics_types, only: cpairv, rairv, cappav, mbarv, zvirv | ||||||
use physics_types, only: cp_or_cv_dycore | ||||||
|
||||||
implicit none | ||||||
private | ||||||
|
@@ -540,45 +539,42 @@ 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, to_dry_factor) | ||||||
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), optional, intent(in) :: to_dry_factor(:,:) | ||||||
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 | ||||||
! cp_or_cv_dycore is now a registry variable (physics_types) in CAM-SIMA instead of in-module | ||||||
|
||||||
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 | ||||||
|
||||||
! **TEMP** TODO hplin 9/17/24: | ||||||
! for compatibility with CAM-SIMA that allocates thermodynamic_active_species_idx(0:num_advected) | ||||||
! (whereas CAM only allocates 1-indexed) I subset it here. This should be verified during code | ||||||
! review. | ||||||
! 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; https://rmets.onlinelibrary.wiley.com/doi/epdf/10.1002/qj.4353) | ||||||
! (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 not supported') | ||||||
call endrun(subname//': dycore energy formula (value = '//stringify((/energy_formula/))//') not supported') | ||||||
end if | ||||||
|
||||||
end subroutine water_composition_update | ||||||
|
||||||
!=========================================================================== | ||||||
|
@@ -696,14 +692,14 @@ subroutine get_cp_1hd(tracer, inv_cp, cp, factor, active_species_idx_dycore, cpd | |||||
! Dummy arguments | ||||||
! tracer: Tracer array | ||||||
! | ||||||
! factor not present then tracer must be dry mixing ratio | ||||||
! if factor present tracer*factor must be dry mixing ratio | ||||||
! 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(:,:,:) | ||||||
! inv_cp: output inverse cp instead of cp | ||||||
logical, intent(in) :: inv_cp | ||||||
real(kind_phys), intent(out) :: cp(:,:) | ||||||
! dp: if provided then tracer is mass not mixing ratio | ||||||
! if provided then tracer is not a mass mixing ratio | ||||||
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! |
||||||
real(kind_phys), optional, intent(in) :: factor(:,:) | ||||||
! active_species_idx_dycore: array of indices for index of | ||||||
! thermodynamic active species in dycore tracer array | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -218,17 +218,18 @@ end subroutine cam_thermo_init | |||||
! | ||||||
!*************************************************************************** | ||||||
! | ||||||
subroutine cam_thermo_dry_air_update(mmr, T, ncol, update_thermo_variables, to_dry_factor) | ||||||
subroutine cam_thermo_dry_air_update(mmr, T, ncol, pver, update_thermo_variables, to_dry_factor) | ||||||
use air_composition, only: dry_air_composition_update | ||||||
use air_composition, only: update_zvirv | ||||||
use string_utils, only: to_str | ||||||
use string_utils, only: stringify | ||||||
|
||||||
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) :: T(:,:) ! temperature | ||||||
integer, intent(in) :: pver ! number of vertical levels | ||||||
integer, intent(in) :: ncol ! number of columns | ||||||
logical, intent(in) :: update_thermo_variables ! true: calculate composition-dependent thermo variables | ||||||
! false: do not calculate composition-dependent thermo variables | ||||||
real(kind_phys), optional, intent(in) :: to_dry_factor(:,:) ! if mmr moist convert | ||||||
real(kind_phys), optional, intent(in) :: to_dry_factor(:,:) ! conversion factor to dry if mmr is wet or moist | ||||||
|
||||||
! Local vars | ||||||
real(kind_phys) :: sponge_factor(SIZE(mmr, 2)) | ||||||
|
@@ -240,7 +241,10 @@ subroutine cam_thermo_dry_air_update(mmr, T, ncol, update_thermo_variables, to_d | |||||
|
||||||
if (present(to_dry_factor)) then | ||||||
if (SIZE(to_dry_factor, 1) /= ncol) then | ||||||
call endrun(subname//'DIM 1 of to_dry_factor is'//to_str(SIZE(to_dry_factor,1))//'but should be'//to_str(ncol)) | ||||||
call endrun(subname//'DIM 1 of to_dry_factor is'//stringify((/SIZE(to_dry_factor,1)/))//'but should be'//stringify((/ncol/))) | ||||||
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. I think you might want to add spaces here:
Suggested change
I have this same request for the other related 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, added! |
||||||
end if | ||||||
if (SIZE(to_dry_factor, 2) /= pver) then | ||||||
call endrun(subname//'DIM 2 of to_dry_factor is'//stringify((/SIZE(to_dry_factor,2)/))//'but should be'//stringify((/pver/))) | ||||||
end if | ||||||
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. It looks like we are only checking the first dimension ( 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. Good question, I just inherited a lot of this from CAM which also strangely just checks the first dimension. I guess the reason is that I can add the check, but I also wanted to mention that nowhere in the code this |
||||||
end if | ||||||
|
||||||
|
@@ -263,18 +267,32 @@ end subroutine cam_thermo_dry_air_update | |||||
! | ||||||
!*************************************************************************** | ||||||
! | ||||||
subroutine cam_thermo_water_update(mmr, ncol, energy_formula, to_dry_factor) | ||||||
subroutine cam_thermo_water_update(mmr, ncol, pver, energy_formula, cp_or_cv_dycore, to_dry_factor) | ||||||
use air_composition, only: water_composition_update | ||||||
use string_utils, only: stringify | ||||||
!----------------------------------------------------------------------- | ||||||
! Update the physics "constants" that vary | ||||||
!------------------------------------------------------------------------- | ||||||
|
||||||
real(kind_phys), intent(in) :: mmr(:,:,:) ! constituents array | ||||||
integer, intent(in) :: ncol ! number of columns | ||||||
integer, intent(in) :: energy_formula | ||||||
real(kind_phys), optional, intent(in) :: to_dry_factor(:,:) | ||||||
real(kind_phys), intent(in) :: mmr(:,:,:) ! constituents array (mmr = dry mixing ratio, if not use to_dry_factor to convert) | ||||||
integer, intent(in) :: ncol ! number of columns | ||||||
integer, intent(in) :: pver ! number of vertical levels | ||||||
integer, intent(in) :: energy_formula | ||||||
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 = 'cam_thermo_water_update: ' | ||||||
|
||||||
if (present(to_dry_factor)) then | ||||||
if (SIZE(to_dry_factor, 1) /= ncol) then | ||||||
call endrun(subname//'DIM 1 of to_dry_factor is'//stringify((/SIZE(to_dry_factor,1)/))//'but should be'//stringify((/ncol/))) | ||||||
end if | ||||||
if (SIZE(to_dry_factor, 2) /= pver) then | ||||||
call endrun(subname//'DIM 2 of to_dry_factor is'//stringify((/SIZE(to_dry_factor,2)/))//'but should be'//stringify((/pver/))) | ||||||
end if | ||||||
end if | ||||||
|
||||||
call water_composition_update(mmr, ncol, energy_formula, to_dry_factor=to_dry_factor) | ||||||
call water_composition_update(mmr, ncol, energy_formula, cp_or_cv_dycore, to_dry_factor=to_dry_factor) | ||||||
end subroutine cam_thermo_water_update | ||||||
|
||||||
!=========================================================================== | ||||||
|
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!