From ff30858f55edcc7c70b6aea706ffb1d0bbdee190 Mon Sep 17 00:00:00 2001 From: Kuan-Chih Wang Date: Mon, 16 Dec 2024 14:46:55 -0700 Subject: [PATCH] Tidy up MPAS-related changes introduced in PR #316 * Adjust wording and keep code comments up-to-date * Concentrate all calls to `mark_as_initialized` in one place * Fix up code style inconsistencies --- src/dynamics/mpas/dyn_comp.F90 | 37 +++++++++++++++++------------- src/dynamics/mpas/dyn_coupling.F90 | 17 +++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/dynamics/mpas/dyn_comp.F90 b/src/dynamics/mpas/dyn_comp.F90 index 3911af4f..a911531a 100644 --- a/src/dynamics/mpas/dyn_comp.F90 +++ b/src/dynamics/mpas/dyn_comp.F90 @@ -187,9 +187,8 @@ end subroutine dyn_readnl ! ! Called by `cam_init` in `src/control/cam_comp.F90`. subroutine dyn_init(cam_runtime_opts, dyn_in, dyn_out) - use cam_thermo_formula, only: energy_formula_dycore, ENERGY_FORMULA_DYCORE_MPAS - use phys_vars_init_check, only: mark_as_initialized - use physics_types, only: dycore_energy_consistency_adjust + use cam_thermo_formula, only: energy_formula_dycore, energy_formula_dycore_mpas + use physics_types, only: dycore_energy_consistency_adjust type(runtime_options), intent(in) :: cam_runtime_opts type(dyn_import_t), intent(in) :: dyn_in @@ -207,14 +206,13 @@ subroutine dyn_init(cam_runtime_opts, dyn_in, dyn_out) nullify(pio_init_file) nullify(pio_topo_file) - ! Set dynamical core energy formula for use in cam_thermo. - energy_formula_dycore = ENERGY_FORMULA_DYCORE_MPAS - call mark_as_initialized('total_energy_formula_for_dycore') + ! Set the energy formula of dynamical core to MPAS for use in `cam_thermo`. + energy_formula_dycore = energy_formula_dycore_mpas - ! Dynamical core energy is not consistent with CAM physics and requires - ! temperature and temperature tendency adjustment at end of physics. + ! The total energy of dynamical core, which uses "MPAS formula" as set above, is not consistent with + ! that of CAM physics, which uses "FV formula". Therefore, temperature and temperature tendency adjustments + ! are needed at the end of each physics time step. dycore_energy_consistency_adjust = .true. - call mark_as_initialized('flag_for_dycore_energy_consistency_adjustment') allocate(constituent_name(num_advected), stat=ierr) call check_allocate(ierr, subname, 'constituent_name(num_advected)', 'dyn_comp', __LINE__) @@ -931,15 +929,21 @@ subroutine dyn_exchange_constituent_state(direction, exchange, conversion) end if end subroutine dyn_exchange_constituent_state - !> Mark everything in the `physics_{state,tend}` derived types along with constituents as initialized - !> to prevent physics from attempting to read them from a file. These variables are to be exchanged later - !> during dynamics-physics coupling. + !> Mark everything in the `physics_types` module along with constituents as initialized + !> to prevent physics from attempting to read them from a file. !> (KCW, 2024-05-23) subroutine mark_variable_as_initialized() character(*), parameter :: subname = 'dyn_comp::mark_variable_as_initialized' integer :: i - ! CCPP standard names of physical quantities in the `physics_{state,tend}` derived types. + ! The variables below are managed by dynamics interface. + ! We are responsible for initializing and updating them. + + ! These variables are to be set during dynamics initialization. + call mark_as_initialized('flag_for_dycore_energy_consistency_adjustment') + call mark_as_initialized('total_energy_formula_for_dycore') + + ! These variables are to be set during dynamics-physics coupling. call mark_as_initialized('air_pressure') call mark_as_initialized('air_pressure_at_interface') call mark_as_initialized('air_pressure_of_dry_air') @@ -960,6 +964,7 @@ subroutine mark_variable_as_initialized() call mark_as_initialized('reciprocal_of_air_pressure_thickness') call mark_as_initialized('reciprocal_of_air_pressure_thickness_of_dry_air') call mark_as_initialized('reciprocal_of_dimensionless_exner_function_wrt_surface_air_pressure') + call mark_as_initialized('specific_heat_of_air_used_in_dycore') call mark_as_initialized('surface_air_pressure') call mark_as_initialized('surface_geopotential') call mark_as_initialized('surface_pressure_of_dry_air') @@ -972,10 +977,10 @@ subroutine mark_variable_as_initialized() call mark_as_initialized(trim(adjustl(const_name(i)))) end do - call mark_as_initialized('specific_heat_of_air_used_in_dycore') + ! The variables below are not managed by dynamics interface. They are used by external CCPP physics schemes. + ! While we are not responsible for initializing or updating them, we still need to help mark them as initialized. - ! These energy variables are calculated by check_energy_timestep_init - ! but need to be marked here + ! These variables are to be set externally by the `check_energy_chng` CCPP physics scheme. call mark_as_initialized('vertically_integrated_total_energy_at_end_of_physics_timestep') call mark_as_initialized('vertically_integrated_total_energy_using_dycore_energy_formula') call mark_as_initialized('vertically_integrated_total_energy_using_dycore_energy_formula_at_start_of_physics_timestep') diff --git a/src/dynamics/mpas/dyn_coupling.F90 b/src/dynamics/mpas/dyn_coupling.F90 index a2066e16..14b211f3 100644 --- a/src/dynamics/mpas/dyn_coupling.F90 +++ b/src/dynamics/mpas/dyn_coupling.F90 @@ -3,7 +3,7 @@ module dyn_coupling use cam_abortutils, only: check_allocate, endrun use cam_constituents, only: const_is_water_species, const_qmin, num_advected use cam_thermo, only: cam_thermo_dry_air_update, cam_thermo_water_update - use cam_thermo_formula, only: ENERGY_FORMULA_DYCORE_MPAS + use cam_thermo_formula, only: energy_formula_dycore_mpas use dyn_comp, only: dyn_debug_print, dyn_exchange_constituent_state, reverse, mpas_dynamical_core, & ncells_solve use dynconst, only: constant_cpd => cpair, constant_g => gravit, constant_p0 => pref, & @@ -333,15 +333,10 @@ subroutine set_physics_state_external() call cam_thermo_dry_air_update( & constituents, phys_state % t, ncells_solve, pver, cam_runtime_opts % update_thermodynamic_variables()) - ! update cp_or_cv_dycore in SIMA state. - ! (note: at this point q is dry) + ! Update `cp_or_cv_dycore` by calling `cam_thermo_water_update`. + ! Note that this subroutine expects constituents to be dry. call cam_thermo_water_update( & - mmr = constituents, & ! dry MMR - ncol = ncells_solve, & - pver = pver, & - energy_formula = ENERGY_FORMULA_DYCORE_MPAS, & - cp_or_cv_dycore = cp_or_cv_dycore & - ) + constituents, ncells_solve, pver, energy_formula_dycore_mpas, cp_or_cv_dycore) ! This variable name is really misleading. It actually represents the reciprocal of Exner function ! with respect to surface pressure. This definition is sometimes used for boundary layer work. See @@ -364,7 +359,7 @@ subroutine set_physics_state_external() end if ! Set `zi` (i.e., geopotential height at layer interfaces) and `zm` (i.e., geopotential height at layer midpoints). - ! Note that `rairv` and `zvirv` are updated externally by `cam_thermo_update`. + ! Note that `rairv` and `zvirv` are updated externally by `cam_thermo_dry_air_update`. call geopotential_temp_run( & pver, lagrangian_vertical, pver, 1, pverp, 1, num_advected, & phys_state % lnpint, phys_state % pint, phys_state % pmid, phys_state % pdel, phys_state % rpdel, phys_state % t, & @@ -378,7 +373,7 @@ subroutine set_physics_state_external() end if ! Set `dse` (i.e., dry static energy). - ! Note that `cpairv` is updated externally by `cam_thermo_update`. + ! Note that `cpairv` is updated externally by `cam_thermo_dry_air_update`. call update_dry_static_energy_run( & pver, constant_g, phys_state % t, phys_state % zm, phys_state % phis, phys_state % dse, cpairv, ierr, cerr)