Skip to content

Commit

Permalink
Add initialize_constituents scheme (#149)
Browse files Browse the repository at this point in the history
Originator(s): peverwhee

Summary (include the keyword ['closes', 'fixes', 'resolves'] and issue
number): Adds new (non-portable) initialize_constituents scheme (.F90
and .meta). This scheme will be used to instantiate all constituents in
the file (used to validate schemes that need the full constituent array
but do not modify all of the individual constituents). Added to new
"test_schemes" directory.

Describe any changes made to the namelist: N/A

List all files eliminated and why: N/A

List all files added and what they do:
A  test/test_schemes/initialize_constituents.F90
A  test/test_schemes/initialize_constituents.F90
 - add initialize_constituents scheme

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

List any test failures: none

Is this a science-changing update? New physics package, algorithm
change, tuning changes, etc? No

---------

Co-authored-by: Courtney Peverley <[email protected]>
  • Loading branch information
peverwhee and Courtney Peverley authored Dec 2, 2024
1 parent 557e42a commit d46bb55
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 2 deletions.
9 changes: 8 additions & 1 deletion doc/NamesNotInDictionary.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@

#######################
Date/time of when script was run:
2024-11-27 11:22:40.595150
2024-12-02 10:21:31.914990
#######################

Non-dictionary standard names found in the following metadata files:

--------------------------

atmospheric_physics/test/test_schemes/initialize_constituents.meta

- dynamic_constituents_for_initialize_constituents

--------------------------

atmospheric_physics/schemes/sima_diagnostics/tropopause_diagnostics.meta

- tropopause_air_pressure
Expand Down Expand Up @@ -314,6 +320,7 @@ atmospheric_physics/schemes/tj2016/tj2016_precip.meta
atmospheric_physics/schemes/musica/musica_ccpp.meta

- blackbody_temperature_at_surface
- cloud_area_fraction
- dynamic_constituents_for_musica_ccpp
- extraterrestrial_radiation_flux
- geopotential_height_wrt_surface_at_interface
Expand Down
2 changes: 1 addition & 1 deletion schemes/utilities/state_converters.meta
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
[ exner ]
standard_name = dimensionless_exner_function
type = real | kind = kind_phys
units = count
units = 1
dimensions = (horizontal_loop_extent, vertical_layer_dimension)
intent = out
[ errmsg ]
Expand Down
153 changes: 153 additions & 0 deletions test/test_schemes/initialize_constituents.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
module initialize_constituents

implicit none
private

public :: initialize_constituents_register
public :: initialize_constituents_run

contains

!> \section arg_table_initialize_constituents_register Argument Table
!! \htmlinclude initialize_constituents_register.html
subroutine initialize_constituents_register(constituents, errmsg, errcode)
use ccpp_constituent_prop_mod, only: ccpp_constituent_properties_t
use cam_initfiles, only: initial_file_get_id
use pio, only: pio_inquire, file_desc_t, pio_inq_varname
use ccpp_kinds, only: kind_phys
! Dummy variables
type(ccpp_constituent_properties_t), allocatable, intent(out) :: constituents(:)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode
! Local variables
type(file_desc_t), pointer :: ncdata
integer :: num_variables
integer :: ierr
integer :: var_index
integer :: constituent_index
integer :: known_const_index
integer :: found_const_count
logical :: known_constituent
character(len=256) :: variable_name
character(len=512) :: alloc_err_msg
character(len=256), allocatable :: constituent_names(:)
character(len=65), parameter :: water_species_std_names(6) = &
(/'water_vapor_mixing_ratio_wrt_moist_air_and_condensed_water ', &
'cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water', &
'rain_mixing_ratio_wrt_moist_air_and_condensed_water ', &
'cloud_ice_mixing_ratio_wrt_moist_air_and_condensed_water ', &
'snow_mixing_ratio_wrt_moist_air_and_condensed_water ', &
'graupel_water_mixing_ratio_wrt_moist_air_and_condensed_water '/)

character(len=11), parameter :: const_file_names(6) = (/'cnst_Q ', &
'cnst_CLDLIQ', &
'cnst_RAINQM', &
'cnst_CLDICE', &
'cnst_SNOWQM', &
'cnst_GRAUQM'/)
character(len=11), parameter :: water_species_number_concentrations(5) = &
(/'cnst_NUMLIQ', &
'cnst_NUMRAI', &
'cnst_NUMICE', &
'cnst_NUMSNO', &
'cnst_NUMGRA'/)

errcode = 0
errmsg = ''
constituent_index = 0
found_const_count = 0

ncdata => initial_file_get_id()
! See how many variables are present on the file
ierr = pio_inquire(ncdata, nVariables=num_variables)
allocate(constituent_names(num_variables), stat=ierr, errmsg=alloc_err_msg)
if (ierr /= 0) then
errcode = 1
write(errmsg,*) 'Failed to allocate "constituent_names" in initialize_constituents_register: ', trim(alloc_err_msg)
return
end if

! Loop over all variables in the file and add each constituent to the
! dynamic constituent array
do var_index = 1, num_variables
ierr = pio_inq_varname(ncdata, var_index, variable_name)
known_constituent = .false.
if (index(variable_name, 'cnst_') > 0) then
constituent_index = constituent_index + 1
! Replace with standard name if known, to avoid duplicates
if (found_const_count < size(water_species_std_names)) then
do known_const_index = 1, size(const_file_names)
if (trim(const_file_names(known_const_index)) == trim(variable_name)) then
constituent_names(constituent_index) = water_species_std_names(known_const_index)
found_const_count = found_const_count + 1
known_constituent = .true.
exit
end if
end do
end if
if (.not. known_constituent) then
constituent_names(constituent_index) = variable_name
end if
end if
end do

allocate(constituents(constituent_index), stat=ierr, errmsg=alloc_err_msg)
if (ierr /= 0) then
errcode = 1
write(errmsg,*) 'Failed to allocate "constituents" in initialize_constituents_register: ', trim(alloc_err_msg)
return
end if

do var_index = 1, size(constituents)
if (any(water_species_number_concentrations == trim(constituent_names(var_index)))) then
call constituents(var_index)%instantiate( &
std_name = constituent_names(var_index), &
long_name = constituent_names(var_index), &
units = 'kg-1', &
vertical_dim = 'vertical_layer_dimension', &
min_value = 0.0_kind_phys, &
advected = .true., &
water_species = .true., &
mixing_ratio_type = 'wet', &
errcode = errcode, &
errmsg = errmsg)
else if (any(water_species_std_names == trim(constituent_names(var_index)))) then
call constituents(var_index)%instantiate( &
std_name = constituent_names(var_index), &
long_name = constituent_names(var_index), &
units = 'kg kg-1', &
vertical_dim = 'vertical_layer_dimension', &
min_value = 0.0_kind_phys, &
advected = .true., &
water_species = .true., &
mixing_ratio_type = 'wet', &
errcode = errcode, &
errmsg = errmsg)
else
call constituents(var_index)%instantiate( &
std_name = constituent_names(var_index), &
long_name = constituent_names(var_index), &
units = 'kg kg-1', &
vertical_dim = 'vertical_layer_dimension', &
min_value = 0.0_kind_phys, &
advected = .true., &
errcode = errcode, &
errmsg = errmsg)
end if
if (errcode /= 0) then
exit
end if
end do

end subroutine initialize_constituents_register

!> \section arg_table_initialize_constituents_run Argument Table
!! \htmlinclude initialize_constituents_run.html
subroutine initialize_constituents_run(errmsg, errcode)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errcode

errcode = 0
errmsg = ''
end subroutine initialize_constituents_run
end module initialize_constituents
44 changes: 44 additions & 0 deletions test/test_schemes/initialize_constituents.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[ccpp-table-properties]
name = initialize_constituents
type = scheme
[ccpp-arg-table]
name = initialize_constituents_register
type = scheme
[ constituents ]
standard_name = dynamic_constituents_for_initialize_constituents
units = none
dimensions = (:)
allocatable = True
type = ccpp_constituent_properties_t
intent = out
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
units = none
type = character | kind = len=512
dimensions = ()
intent = out
[ errcode ]
standard_name = ccpp_error_code
long_name = Error flag for error handling in CCPP
units = 1
type = integer
dimensions = ()
intent = out
[ccpp-arg-table]
name = initialize_constituents_run
type = scheme
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
units = none
type = character | kind = len=512
dimensions = ()
intent = out
[ errcode ]
standard_name = ccpp_error_code
long_name = Error flag for error handling in CCPP
units = 1
type = integer
dimensions = ()
intent = out

0 comments on commit d46bb55

Please sign in to comment.