Skip to content

Commit

Permalink
Fix build issues; update factor in get_cp call to 1/dp
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmielin committed Oct 25, 2024
1 parent 041cdfb commit 7493a1d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/control/cam_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
dtime_phys = 0.0_r8
call mark_as_initialized('timestep_for_physics')

is_first_timestep = is_first_step()
is_first_timestep = .true.
call mark_as_initialized('is_first_timestep')

call init_pio_subsystem()
Expand Down
14 changes: 11 additions & 3 deletions src/data/air_composition.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module air_composition
public :: air_composition_init
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
Expand Down Expand Up @@ -533,7 +534,7 @@ subroutine dry_air_composition_update(mmr, ncol, to_dry_factor)

cappav(:ncol,:) = rairv(:ncol,:) / cpairv(:ncol,:)

end subroutine air_composition_update
end subroutine dry_air_composition_update

!===========================================================================
!---------------------------------------------------------------------------
Expand All @@ -557,12 +558,19 @@ subroutine water_composition_update(mmr, ncol, vcoord, to_dry_factor)
! FV: moist pressure vertical coordinate does not need update.
else if (vcoord == vc_dry_pressure) then
! SE

! 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. But from the meaning of the code arguments
! it is unknown where it was meant to be thermodynamic_active_species_idx_dycore.
! This should be verified during code review.
call get_cp(mmr(:ncol,:,:), .false., cp_or_cv_dycore(:ncol,:), &
factor=to_dry_factor, active_species_idx_dycore=thermodynamic_active_species_idx, &
factor=to_dry_factor, active_species_idx_dycore=thermodynamic_active_species_idx(1:), &
cpdry=cpairv(:ncol,:))
else if (vcoord == vc_height) then
! MPAS
call get_R(mmr(:ncol,:,:), thermodynamic_active_species_idx, &

! TODO hplin 9/17/24 same here.
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
Expand Down
3 changes: 2 additions & 1 deletion src/data/cam_thermo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ end subroutine cam_thermo_init
subroutine cam_thermo_dry_air_update(mmr, T, ncol, update_thermo_variables, to_dry_factor)
use air_composition, only: dry_air_composition_update
use air_composition, only: update_zvirv
use string_utils, only: int2str
use string_utils, only: to_str

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
Expand Down Expand Up @@ -1579,6 +1579,7 @@ subroutine get_hydrostatic_energy_1hd(tracer, moist_mixing_ratio, pdel_in, &
use cam_logfile, only: iulog
use dyn_tests_utils, only: vc_height, vc_moist_pressure, vc_dry_pressure
use air_composition, only: wv_idx
use air_composition, only: dry_air_species_num
use physconst, only: rga, latvap, latice

! Dummy arguments
Expand Down
7 changes: 4 additions & 3 deletions src/data/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<metadata_file>$SRCROOT/src/data/ref_pres.meta</metadata_file>
<metadata_file>$SRCROOT/src/dynamics/utils/vert_coord.meta</metadata_file>
<metadata_file>$SRCROOT/src/dynamics/utils/hycoef.meta</metadata_file>
<metadata_file>$SRCROOT/src/dynamics/tests/dyn_tests_utils.meta</metadata_file>
<!-- Variables registered to physics_types -->
<file name="physics_types" type="module">
<use module="ccpp_kinds" reference="kind_phys"/>
Expand Down Expand Up @@ -254,7 +255,7 @@
<!-- Timestep properties -->
<variable local_name="is_first_timestep"
standard_name="is_first_timestep"
units="flag" type="logical" access="protected">
units="flag" type="logical">
<long_name>flag indicating if is first timestep of initial run</long_name>
</variable>
<!-- State tendencies -->
Expand Down Expand Up @@ -422,8 +423,8 @@
<initial_value>zvir</initial_value>
</variable>
<variable local_name="cp_or_cv_dycore"
standard_name="enthalpy_or_internal_energy_scaling_factor_for_energy_consistency?"
units="1" type="real" kind="kind_phys"
standard_name="enthalpy_or_internal_energy_scaling_factor_for_energy_consistency_tbd"
units="J kg-1 K-1" type="real" kind="kind_phys"
allocatable="allocatable">
<long_name>Enthalpy or internal energy scaling factor for energy consistency</long_name>
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
Expand Down
8 changes: 4 additions & 4 deletions src/dynamics/tests/dyn_tests_utils.meta
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
name = dyn_tests_utils
type = module
[ vc_dycore ]
standard_name = vertical_coordinate_for_dynamical_core?
units = none
standard_name = vertical_coordinate_for_dynamical_core_tbd
units = 1
type = integer
dimensions = ()
[ vc_physics ]
standard_name = vertical_coordinate_for_physics?
units = none
standard_name = vertical_coordinate_for_physics_tbd
units = 1
type = integer
dimensions = ()
33 changes: 19 additions & 14 deletions src/dynamics/utils/dyn_thermo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ subroutine get_cp(tracer,inv_cp,cp,dp_dry,active_species_idx_dycore)
!Declare local variables:
real(kind_phys), allocatable :: tracer_phys(:,:,:,:)
real(kind_phys), allocatable :: cp_phys(:,:,:)
real(kind_phys), allocatable :: dp_dry_phys(:,:,:)
real(kind_phys), allocatable :: factor_phys(:,:,:)

!check_allocate variables:
integer :: iret !allocate status integer
Expand All @@ -70,11 +70,16 @@ subroutine get_cp(tracer,inv_cp,cp,dp_dry,active_species_idx_dycore)
!Check if kinds are different:
if (kind_phys == kind_dyn) then

!The dynamics and physics kind is the same, so just call the physics
!routine directly:
call get_cp_phys(tracer,inv_cp,cp, &
dp_dry=dp_dry, &
active_species_idx_dycore=active_species_idx_dycore)
! The dynamics and physics kind is the same, so just call the physics
! routine directly:
if(present(dp_dry)) then
call get_cp_phys(tracer,inv_cp,cp, &
factor=1.0_kind_phys/dp_dry, &
active_species_idx_dycore=active_species_idx_dycore)
else
call get_cp_phys(tracer,inv_cp,cp, &
active_species_idx_dycore=active_species_idx_dycore)
endif

else

Expand All @@ -95,18 +100,18 @@ subroutine get_cp(tracer,inv_cp,cp,dp_dry,active_species_idx_dycore)

!Allocate and set optional variables:
if (present(dp_dry)) then
allocate(dp_dry_phys(size(dp_dry, 1), size(dp_dry, 2), size(dp_dry,3)), stat=iret)
allocate(factor_phys(size(dp_dry, 1), size(dp_dry, 2), size(dp_dry,3)), stat=iret)
call check_allocate(iret, subname, &
'dp_dry_phys', &
'factor_phys', &
file=__FILE__, line=__LINE__)

!Set optional local variable:
dp_dry_phys = real(dp_dry, kind_phys)
factor_phys = 1.0_kind_phys/real(dp_dry, kind_phys)
end if

!Call physics routine using local vriables with matching kinds:
!Call physics routine using local variables with matching kinds:
call get_cp_phys(tracer_phys,inv_cp,cp_phys, &
dp_dry=dp_dry_phys, &
factor=factor_phys, &
active_species_idx_dycore=active_species_idx_dycore)

!Set output variables back to dynamics kind:
Expand All @@ -116,8 +121,8 @@ subroutine get_cp(tracer,inv_cp,cp,dp_dry,active_species_idx_dycore)
deallocate(tracer_phys)
deallocate(cp_phys)

if (allocated(dp_dry_phys)) then
deallocate(dp_dry_phys)
if (allocated(factor_phys)) then
deallocate(factor_phys)
end if


Expand Down Expand Up @@ -957,7 +962,7 @@ subroutine get_rho_dry(tracer,temp,ptop,dp_dry,tracer_mass,&

end if

!Call physics routine using local vriables with matching kinds:
!Call physics routine using local variables with matching kinds:
call get_rho_dry_phys(tracer_phys,temp_phys, &
ptop_phys, dp_dry_phys,tracer_mass, &
rho_dry=rho_dry_phys, &
Expand Down

0 comments on commit 7493a1d

Please sign in to comment.