Skip to content
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
merged 43 commits into from
Dec 16, 2024

Conversation

jimmielin
Copy link
Member

Originator(s): jimmielin

Description (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number):

All changes are bit-for-bit, except those noted:

Implements cam_thermo_water_update:

  • updates cp_or_cv_dycore (specific_heat_for_air_used_in_dycore) in air_composition.F90 for SE and MPAS dynamical cores
  • read cp_or_cv_dycore from CAM snapshot (refer to companion CAM PR)
  • energy formula (that has to be matching dycore) is recognized and set by null-dycore in dyn_grid.F90 by looking at global attributes of the initial file; see find_energy_formula
  • added is_first_timestep logical state flag

Ports cam_thermo and related updates in air_composition and dp_coupling from CAM 6.3.109 (https://github.com/ESCOMP/CAM/pull/761/files)

  • update to hydrostatic energy calculation
  • changes get_cp, get_R in air_composition.F90 to use moist mixing ratios
  • answer-changing: update to moist-to-dry (for physics) conversion in dp_coupling::derived_phys_dry to account for all water tracers instead of just Q
  • answer-changing: update to not-really-"exner" calculation to use composition-dependent cappav instead of cappa

Changes vcoord in dyn_tests_utils (old CAM) to energy_formula now in cam_thermo_formula (separated out into a different file to avoid dependency issues)

  • vc_moist_pressure is now ENERGY_FORMULA_DYCORE_FV; vc_dry_pressure is _SE; vc_height is _MPAS
  • these are just integer flags (0,1,2) and values are kept consistent with old CAM and their use in dynamics tests

Ports global mean utility module (gmean_mod.F90), de-chunkized from CAM:

  • Implements get_wght in physics_grid for weighted sum calculation

Imports check_energy_chng and check_energy_fix from atmospheric_physics

Describe any changes made to build system: N/A

Describe any changes made to the namelist: contained within ncar-physics

List any changes to the defaults for the input datasets (e.g. boundary datasets):

  • Added cp_or_cv_dycore in CAM snapshots

List all files eliminated and why: N/A

List all files added and what they do:

- energy_formula
A       src/data/cam_thermo_formula.F90
A       src/data/cam_thermo_formula.meta

- gmean
A       src/utils/gmean_mod.F90

List all existing files that have been modified, and describe the changes:
(Helpful git command: git diff --name-status development...<your_branch_name>)

- ncar-physics update
M       .gitmodules
M       src/physics/ncar_ccpp

- `is_first_timestep`
M       src/control/cam_comp.F90

- cam_thermo_water_update for cp_or_cv_dycore (include in registry; read from ic)
M       src/data/air_composition.F90
M       src/data/cam_thermo.F90
M       src/data/registry.xml
M       tools/stdnames_to_inputnames_dictionary.xml
M       src/dynamics/se/dp_coupling.F90
M       src/dynamics/se/dycore/prim_advance_mod.F90
M       src/dynamics/se/dyn_comp.F90
M       src/dynamics/utils/dyn_thermo.F90

- energy_formula
M       src/physics/utils/phys_comp.F90
M       src/dynamics/mpas/dyn_comp.F90
M       src/dynamics/none/dyn_comp.F90
M       src/dynamics/none/dyn_grid.F90

- gmean
M       src/physics/utils/physics_grid.F90

Note: bit-for-bit in check_energy with CAM is tricky to validate without dycore updates to SE; may need to merge #301 first

jimmielin and others added 15 commits October 25, 2024 11:45
…m stash

Needs work to split into cam_thermo_water_update. This is WIP code
total_hours_in_debugging_one_line = 6
Squashed commit of the following:

commit 8b8a8e0
    Fix merge conflicts

commit bef25fb
    Update atmos_phys external

commit 240ef54
    Set wv_idx in air_composition

    total_hours_in_debugging_one_line = 6

commit 38fdbb2
    Read cp_or_cv_dycore and identify dycore information from CAM snapshot

commit 8fca3a4
    Update vcoord to energy_formula

commit 0d16be9
    New const_get_index logic without cam_ccpp_cap dependency

commit e13e7ea
    Fix build (part 1); update standard names and atmos_phys external

commit c015e28
    Update ncar-physics external

commit 2372f7f
    Fix for b4b to CAM-SIMA (w/ History); add notes on modifications and/or divergence from CAM and/or -SIMA

commit 4ce8427
    Add gmean_mod to src/utils including support infra in physics_grid.F90

commit 7493a1d
    Fix build issues; update factor in get_cp call to 1/dp

commit 041cdfb
    Add is_first_timestep registry

commit 333ad4e
    Initial port of updates to energy budget (port of CAM #761) into CAM-SIMA

commit 8648970
    Initial implementation of cp_to_cv_dycore/cam_thermo_water_update from stash

    Needs work to split into cam_thermo_water_update. This is WIP code
@jimmielin jimmielin marked this pull request as ready for review November 11, 2024 17:34
Copy link
Collaborator

@nusbaume nusbaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @jimmielin! I did have some change requests, but hopefully most of them are minor (and if any do become problematic please let me know). Thanks!

.gitmodules Outdated Show resolved Hide resolved
cime_config/config_component.xml Outdated Show resolved Hide resolved
src/data/air_composition.F90 Outdated Show resolved Hide resolved
src/data/air_composition.F90 Outdated Show resolved Hide resolved
src/data/air_composition.F90 Outdated Show resolved Hide resolved
src/physics/utils/physics_grid.F90 Outdated Show resolved Hide resolved
src/physics/utils/physics_grid.F90 Outdated Show resolved Hide resolved
src/utils/gmean_mod.F90 Outdated Show resolved Hide resolved
src/utils/gmean_mod.F90 Outdated Show resolved Hide resolved
src/utils/gmean_mod.F90 Outdated Show resolved Hide resolved
@jimmielin jimmielin requested a review from nusbaume December 12, 2024 17:59
! 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.
Copy link
Collaborator

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:

Suggested change
! Note: species index subset to 1: because SIMA currently uses index 0. See #334.
! Note: species index subset to 1: because SIMA currently uses index 0. See Github issue #334 in ESCOMP/CAM-SIMA.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed!

src/data/air_composition.F90 Outdated Show resolved Hide resolved
! 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factor is used to convert tracer to dry mixing ratio. So if tracer is mass then one can divide by dpdry (factor=dpdry) to get dry mixing ratio. If tracer is moist mixing ratio then factor is used to convert wet to dry mixing ratio (dpmoist/dpdry).

I guess a more accurate comment would be:

factor to convert tracer to dry mixing ratio.

Comment on lines 787 to 801
! **TEMP** TODO CHECK hplin: CAM has this if-clause for dry_air_species_num > 0
! or otherwise uses zvirv = zvir. CAM-SIMA previously did not have this, and
! instead has a switch for update_thermodynamic_variables. Check if we still want
! this if-clause or change it to something else.
if (dry_air_species_num > 0) then
call cam_thermo_dry_air_update( &
mmr = const_data_ptr, & ! dry MMR
T = phys_state%t, &
ncol = pcols, &
pver = pver, &
update_thermo_variables = cam_runtime_opts%update_thermodynamic_variables() &
)
else
zvirv(:,:) = zvir
end if
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PeterHjortLauritzen and @nusbaume, could you confirm this change (to bring it consistent with CAM behavior) is correct? The original CAM-SIMA call was simply

call cam_thermo_update(const_data_ptr, phys_state%t, pcols, &
        cam_runtime_opts%update_thermodynamic_variables())

Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

Copy link
Collaborator

@nusbaume nusbaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me now! I did have a few final change requests, but none that require an extra review from me. I also left some of my comments un-resolved if they eventually might need additional input from Peter. Thanks again for getting this into CAM-SIMA!

!
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
! if provided then tracer is not a mass mixing ratio
! if provided then tracer is not a dry mass mixing ratio

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated!

src/data/registry.xml Show resolved Hide resolved
@@ -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/)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might want to add spaces here:

Suggested change
call endrun(subname//'DIM 1 of to_dry_factor is'//stringify((/SIZE(to_dry_factor,1)/))//'but should be'//stringify((/ncol/)))
call endrun(subname//'DIM 1 of to_dry_factor is '//stringify((/SIZE(to_dry_factor,1)/))//' but should be '//stringify((/ncol/)))

I have this same request for the other related endrun calls below as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added!

src/dynamics/se/dp_coupling.F90 Outdated Show resolved Hide resolved
Copy link
Collaborator

@kuanchihwang kuanchihwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the code updates to the MPAS dycore interface. I have some (optional) suggestions related to code style.

src/dynamics/mpas/dyn_comp.F90 Outdated Show resolved Hide resolved
src/dynamics/mpas/dyn_comp.F90 Outdated Show resolved Hide resolved
src/dynamics/mpas/dyn_comp.F90 Outdated Show resolved Hide resolved
src/dynamics/mpas/dyn_comp.F90 Outdated Show resolved Hide resolved
@jimmielin
Copy link
Member Author

Regression tests completed

aux_sima_intel_20241213135651: 9 tests
  SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_intel.cam-outfrq_kessler_derecho (Overall: DIFF) details:
    FAIL SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_intel.cam-outfrq_kessler_derecho NLCOMP
    FAIL SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_intel.cam-outfrq_kessler_derecho BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_intel: ERROR BFAIL some baseline files were missing
  SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_intel.cam-outfrq_kessler_mpas_derecho (Overall: FAIL) details:
    FAIL SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_intel.cam-outfrq_kessler_mpas_derecho NLCOMP
    FAIL SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_intel.cam-outfrq_kessler_mpas_derecho RUN time=22
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FCAM7.derecho_intel.cam-outfrq_se_cslam_analy_ic (Overall: PEND) details:
    PEND SMS_Ln9.ne5pg3_ne5pg3_mg37.FCAM7.derecho_intel.cam-outfrq_se_cslam_analy_ic SHAREDLIB_BUILD RERUN
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_intel.cam-outfrq_se_cslam (Overall: DIFF) details:
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_intel.cam-outfrq_se_cslam NLCOMP
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_intel.cam-outfrq_se_cslam BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_intel: ERROR BFAIL some baseline files were missing
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_intel.cam-outfrq_se_cslam (Overall: DIFF) details:
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_intel.cam-outfrq_se_cslam NLCOMP
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_intel.cam-outfrq_se_cslam BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_intel: ERROR BFAIL some baseline files were missing
aux_sima_gnu_20241213135656: 9 tests
  SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_gnu.cam-outfrq_kessler_derecho (Overall: DIFF) details:
    FAIL SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_gnu.cam-outfrq_kessler_derecho NLCOMP
    FAIL SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_gnu.cam-outfrq_kessler_derecho BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_gnu: ERROR BFAIL some baseline files were missing
  SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_gnu.cam-outfrq_kessler_mpas_derecho (Overall: FAIL) details:
    FAIL SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_gnu.cam-outfrq_kessler_mpas_derecho NLCOMP
    FAIL SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_gnu.cam-outfrq_kessler_mpas_derecho RUN time=23
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FCAM7.derecho_gnu.cam-outfrq_se_cslam_analy_ic (Overall: PEND) details:
    PEND SMS_Ln9.ne5pg3_ne5pg3_mg37.FCAM7.derecho_gnu.cam-outfrq_se_cslam_analy_ic SHAREDLIB_BUILD RERUN
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_gnu.cam-outfrq_se_cslam (Overall: DIFF) details:
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_gnu.cam-outfrq_se_cslam NLCOMP
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_gnu.cam-outfrq_se_cslam BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_gnu: ERROR BFAIL some baseline files were missing
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_gnu.cam-outfrq_se_cslam (Overall: DIFF) details:
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_gnu.cam-outfrq_se_cslam NLCOMP
    FAIL SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_gnu.cam-outfrq_se_cslam BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_gnu: ERROR BFAIL some baseline files were missing

Test failures for this tag:

Derecho Intel

  SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_intel.cam-outfrq_kessler_mpas_derecho (Overall: FAIL) details:
  - will fail until MPAS is fully integrated

  SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_intel.cam-outfrq_kessler_derecho (Overall: DIFF) details:
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_intel.cam-outfrq_se_cslam (Overall: DIFF) details:
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_intel.cam-outfrq_se_cslam (Overall: DIFF) details:
  - new baselines (previously no baselines were available due to model build failure)

  SMS_Ln9.ne5pg3_ne5pg3_mg37.FCAM7.derecho_intel.cam-outfrq_se_cslam_analy_ic (Overall: PEND) details:
  - build failure due to dadadj_apply_qv_tendency removal, needs to be updated to use constituent tendency updater atmospheric_physics#179
  - also expected runtime failure CAM-SIMA#335


Derecho GNU

  SMS_Ln9.mpasa480_mpasa480.FKESSLER.derecho_gnu.cam-outfrq_kessler_mpas_derecho (Overall: FAIL) details:
  - will fail until MPAS is fully integrated

  SMS_Ln2.ne3pg3_ne3pg3_mg37.FPHYStest.derecho_gnu.cam-outfrq_kessler_derecho (Overall: DIFF) details:
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FKESSLER.derecho_gnu.cam-outfrq_se_cslam (Overall: DIFF) details:
  SMS_Ln9.ne5pg3_ne5pg3_mg37.FTJ16.derecho_gnu.cam-outfrq_se_cslam (Overall: DIFF) details:
  - new baselines (previously no baselines were available due to model build failure)

  SMS_Ln9.ne5pg3_ne5pg3_mg37.FCAM7.derecho_gnu.cam-outfrq_se_cslam_analy_ic (Overall: PEND) details:
  - build failure due to dadadj_apply_qv_tendency removal, needs to be updated to use constituent tendency updater atmospheric_physics#179
  - also expected runtime failure CAM-SIMA#335

@jimmielin jimmielin merged commit 37fdbfb into ESCOMP:development Dec 16, 2024
8 checks passed
kuanchihwang added a commit to kuanchihwang/CAM-SIMA that referenced this pull request Dec 16, 2024
* Adjust wording and keep code comments up-to-date.
* Fix up code style inconsistencies.
kuanchihwang added a commit to kuanchihwang/CAM-SIMA that referenced this pull request Dec 16, 2024
* Adjust wording and keep code comments up-to-date
* Concentrate all calls to `mark_as_initialized` in one place
* Fix up code style inconsistencies
kuanchihwang added a commit to kuanchihwang/CAM-SIMA that referenced this pull request Dec 16, 2024
* Adjust wording and keep code comments up-to-date
* Concentrate all calls to `mark_as_initialized` in one place
* Fix up code style inconsistencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Tag
Development

Successfully merging this pull request may close these issues.

5 participants