Skip to content

Commit

Permalink
Tidy up MPAS-related changes introduced in PR ESCOMP#316
Browse files Browse the repository at this point in the history
* Adjust wording and keep code comments up-to-date.
* Fix up code style inconsistencies.
  • Loading branch information
kuanchihwang committed Dec 16, 2024
1 parent a6d6289 commit 7f8e3a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
37 changes: 21 additions & 16 deletions src/dynamics/mpas/dyn_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 physics timestep.
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__)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down
17 changes: 6 additions & 11 deletions src/dynamics/mpas/dyn_coupling.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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, &
Expand Down Expand Up @@ -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
Expand All @@ -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, &
Expand All @@ -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)

Expand Down

0 comments on commit 7f8e3a0

Please sign in to comment.