Skip to content

Commit

Permalink
Merge pull request #206 from peverwhee/constituents_court
Browse files Browse the repository at this point in the history
Constituents
  • Loading branch information
peverwhee committed May 15, 2023
2 parents 101fd31 + af08f73 commit f2ee2a8
Show file tree
Hide file tree
Showing 83 changed files with 3,452 additions and 1,461 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
#All of these python versions will be used to run tests:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
fail-fast: false
steps:
# Acquire github action routines:
Expand Down
20 changes: 10 additions & 10 deletions Externals.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[ccs_config]
tag = ccs_config_cesm0.0.28
tag = ccs_config_cesm0.0.59
protocol = git
repo_url = https://github.com/ESMCI/ccs_config_cesm
local_path = ccs_config
Expand All @@ -13,37 +13,37 @@ local_path = components/cice5
required = True

[cice6]
tag = cesm_cice6_2_0_21
tag = cesm_cice6_4_1_3
protocol = git
repo_url = https://github.com/ESCOMP/CESM_CICE
local_path = components/cice
externals = Externals.cfg
required = True

[cmeps]
tag = cmeps0.13.62
tag = cmeps0.14.24
protocol = git
repo_url = https://github.com/ESCOMP/CMEPS.git
local_path = components/cmeps
required = True

[cdeps]
tag = cdeps0.12.46
tag = cdeps1.0.8
protocol = git
repo_url = https://github.com/ESCOMP/CDEPS.git
local_path = components/cdeps
externals = Externals_CDEPS.cfg
required = True

[cpl7]
tag = cpl7.0.12
tag = cpl7.0.15
protocol = git
repo_url = https://github.com/ESCOMP/CESM_CPL7andDataComps
local_path = components/cpl7
required = True

[share]
tag = share1.0.11
tag = share1.0.16
protocol = git
repo_url = https://github.com/ESCOMP/CESM_share
local_path = share
Expand All @@ -57,14 +57,14 @@ local_path = libraries/mct
required = True

[parallelio]
tag = pio2_5_6
tag = pio2_5_10
protocol = git
repo_url = https://github.com/NCAR/ParallelIO
local_path = libraries/parallelio
required = True

[cime]
tag = cime6.0.38
tag = cime6.0.94
protocol = git
repo_url = https://github.com/ESMCI/cime
local_path = cime
Expand All @@ -79,7 +79,7 @@ externals = Externals_CISM.cfg
required = True

[clm]
tag = ctsm5.1.dev082
tag = ctsm5.1.dev120
protocol = git
repo_url = https://github.com/ESCOMP/CTSM
local_path = components/clm
Expand All @@ -95,7 +95,7 @@ externals = Externals_FMS.cfg
required = True

[mosart]
tag = mosart1_0_45
tag = mosart1_0_48
protocol = git
repo_url = https://github.com/ESCOMP/MOSART
local_path = components/mosart
Expand Down
4 changes: 2 additions & 2 deletions Externals_CAM.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[ccpp-framework]
local_path = ccpp_framework
protocol = git
repo_url = https://github.com/gold2718/ccpp-framework
tag = CPF_0.2.032
repo_url = https://github.com/peverwhee/ccpp-framework
tag = CPF_0.2.042
required = True

[cosp2]
Expand Down
58 changes: 50 additions & 8 deletions cime_config/cam_build_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,34 @@ def new_entry_from_xml(item):
# end if
return new_entry

###############################################################################
def clean_xml_text(item):
###############################################################################
"""Return a 'clean' (stripped) version of <item>.text or an empty
string if <item>.text is None or not a string-type variable
doctests
1. Test that the function works as expected when passed a string.
>>> test_xml = ET.Element("text")
>>> test_xml.text = " THIS IS A test "
>>> clean_xml_text(test_xml)
'THIS IS A test'
2. Verify that the function returns an empty string when not passed a string.
>>> test_xml = ET.Element("text")
>>> test_xml.text = 2
>>> clean_xml_text(test_xml)
''
"""
itext = item.text
iret = ""
if isinstance(itext, str):
iret = itext.strip()
# end if
return iret

class FileStatus:
"""Class to hold full path and SHA hash of a file"""

Expand Down Expand Up @@ -219,13 +247,14 @@ def __init__(self, build_cache):
elif item.tag == 'config':
self.__config = item.text
elif item.tag == 'reg_gen_file':
self.__reg_gen_files.append(item.text.strip())
self.__reg_gen_files.append(clean_xml_text(item))
elif item.tag == 'ic_name_entry':
stdname = item.get('standard_name')
if stdname not in self.__ic_names:
self.__ic_names[stdname] = []
# end if
self.__ic_names[stdname].append(item.text.strip())
itext = clean_xml_text(item)
self.__ic_names[stdname].append(itext)
else:
emsg = "ERROR: Unknown registry tag, '{}'"
raise ValueError(emsg.format(item.tag))
Expand All @@ -248,16 +277,29 @@ def __init__(self, build_cache):
new_entry = new_entry_from_xml(item)
self.__xml_files[new_entry.key] = new_entry
elif item.tag == 'scheme_namelist_meta_file':
self.__scheme_nl_metadata.append(item.text.strip())
if isinstance(item.text, str):
if item.text:
self.__scheme_nl_metadata.append(item.text.strip())
# end if
# end if
elif item.tag == 'scheme_namelist_groups':
group_list = [x for x in
item.text.strip().split(' ') if x]
group_list = []
if isinstance(item.text, str):
if item.text:
group_list = [x for x in
item.text.strip().split(' ') if x]
# end if
# end if
self.__scheme_nl_groups = group_list
elif item.tag == 'preproc_defs':
self.__preproc_defs = item.text.strip()
self.__preproc_defs = clean_xml_text(item)
elif item.tag == 'kind_type':
kname, ktype = item.text.strip().split('=')
self.__kind_types[kname.strip()] = ktype.strip()
if isinstance(item.text, str):
if item.text:
kname, ktype = item.text.strip().split('=')
self.__kind_types[kname.strip()] = ktype.strip()
# end if
# end if
else:
emsg = "ERROR: Unknown CCPP tag, '{}'"
raise ValueError(emsg.format(item.tag))
Expand Down
1 change: 0 additions & 1 deletion cime_config/cam_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ def __init__(self, case, case_log):
#Add the default host model namelists:
self._add_xml_nml_file(cime_conf_path, "namelist_definition_cam.xml")
self._add_xml_nml_file(data_nml_path, "namelist_definition_physconst.xml")
self._add_xml_nml_file(data_nml_path, "namelist_definition_air_comp.xml")
self._add_xml_nml_file(data_nml_path, "namelist_definition_ref_pres.xml")

#----------------------------------------------------
Expand Down
122 changes: 101 additions & 21 deletions src/control/cam_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ module cam_comp
!
!-----------------------------------------------------------------------

use shr_kind_mod, only: r8 => SHR_KIND_R8
use shr_kind_mod, only: cl=>SHR_KIND_CL, cs=>SHR_KIND_CS
use shr_sys_mod, only: shr_sys_flush

use spmd_utils, only: masterproc, mpicom
use cam_control_mod, only: cam_ctrl_init, cam_ctrl_set_orbit, cam_ctrl_set_physics_type
use cam_control_mod, only: caseid, ctitle
use runtime_opts, only: read_namelist
use runtime_obj, only: cam_runtime_opts
use time_manager, only: timemgr_init, get_step_size
use time_manager, only: get_nstep, is_first_step, is_first_restart_step

use camsrfexch, only: cam_out_t, cam_in_t
use physics_types, only: phys_state, phys_tend
use dyn_comp, only: dyn_import_t, dyn_export_t

use perf_mod, only: t_barrierf, t_startf, t_stopf
use cam_logfile, only: iulog
use cam_abortutils, only: endrun
use shr_kind_mod, only: r8 => SHR_KIND_R8
use shr_kind_mod, only: cl=>SHR_KIND_CL, cs=>SHR_KIND_CS, cx=>SHR_KIND_CX
use shr_sys_mod, only: shr_sys_flush

use spmd_utils, only: masterproc, mpicom
use cam_control_mod, only: cam_ctrl_init, cam_ctrl_set_orbit
use cam_control_mod, only: cam_ctrl_set_physics_type
use cam_control_mod, only: caseid, ctitle
use runtime_opts, only: read_namelist
use runtime_obj, only: cam_runtime_opts
use time_manager, only: timemgr_init, get_step_size
use time_manager, only: get_nstep
use time_manager, only: is_first_step, is_first_restart_step

use camsrfexch, only: cam_out_t, cam_in_t
use physics_types, only: phys_state, phys_tend
use dyn_comp, only: dyn_import_t, dyn_export_t

use perf_mod, only: t_barrierf, t_startf, t_stopf
use cam_logfile, only: iulog
use cam_abortutils, only: endrun
use ccpp_constituent_prop_mod, only: ccpp_constituent_properties_t

implicit none
private
Expand All @@ -47,6 +50,16 @@ module cam_comp

logical :: BFB_CAM_SCAM_IOP = .false.

! Currently, the host (CAM) only adds water vapor (specific_humidity)
! as a constituent.
! Does this need to be a configurable variable?
integer, parameter :: num_host_advected = 1
type(ccpp_constituent_properties_t), target :: host_constituents(num_host_advected)

! Private interface (here to avoid circular dependency)
private :: cam_register_constituents


!-----------------------------------------------------------------------
CONTAINS
!-----------------------------------------------------------------------
Expand Down Expand Up @@ -80,6 +93,9 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
! use history_defaults, only: initialize_iop_history
use stepon, only: stepon_init
use air_composition, only: air_composition_init
use cam_ccpp_cap, only: cam_ccpp_initialize_constituents
use physics_grid, only: columns_on_task
use vert_coord, only: pver

! Arguments
character(len=cl), intent(in) :: caseid ! case ID
Expand Down Expand Up @@ -122,6 +138,8 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &

! Local variables
character(len=cs) :: filein ! Input namelist filename
integer :: errflg
character(len=cx) :: errmsg
!-----------------------------------------------------------------------

call init_pio_subsystem()
Expand Down Expand Up @@ -153,12 +171,20 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
! Open initial or restart file, and topo file if specified.
call cam_initfiles_open()

! Initialize model grids and decompositions
call model_grid_init()
! Initialize constituent information
! This will set the total number of constituents and the
! number of advected constituents.
call cam_register_constituents(cam_runtime_opts)

! Initialize composition-dependent constants:
call air_composition_init()

! Initialize model grids and decompositions
call model_grid_init()

! Initialize constituent data
call cam_ccpp_initialize_constituents(columns_on_task, pver, errflg, errmsg)

! Initialize ghg surface values before default initial distributions
! are set in dyn_init
!!XXgoldyXX: This needs to be converted to CCPP and the issue of
Expand Down Expand Up @@ -461,6 +487,60 @@ subroutine cam_final(cam_out, cam_in)

end subroutine cam_final

!-----------------------------------------------------------------------

subroutine cam_register_constituents(cam_runtime_opts)
! Call the CCPP interface to register all constituents for the
! physics suite being invoked during this run.
use cam_abortutils, only: endrun
use runtime_obj, only: runtime_options
use cam_constituents, only: cam_constituents_init
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
use cam_ccpp_cap, only: cam_ccpp_register_constituents
use cam_ccpp_cap, only: cam_ccpp_number_constituents
use cam_ccpp_cap, only: cam_model_const_properties
use cam_ccpp_cap, only: cam_const_get_index

! Dummy arguments
type(runtime_options), intent(in) :: cam_runtime_opts
! Local variables
integer :: index
integer :: num_advect
integer, allocatable :: ind_water_spec(:)
integer :: errflg
character(len=cx) :: errmsg
type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:)
character(len=*), parameter :: subname = 'cam_register_constituents: '

! Register the constituents to find out what needs advecting
call host_constituents(1)%instantiate(std_name="specific_humidity", &
long_name="Specific humidity", units="kg kg-1", &
vertical_dim="vertical_layer_dimension", advected=.true., &
errcode=errflg, errmsg=errmsg)
if (errflg /= 0) then
call endrun(subname//trim(errmsg), file=__FILE__, line=__LINE__)
end if
call cam_ccpp_register_constituents(cam_runtime_opts%suite_as_list(), &
host_constituents, errcode=errflg, errmsg=errmsg)

if (errflg /= 0) then
call endrun(subname//trim(errmsg), file=__FILE__, line=__LINE__)
end if
call cam_ccpp_number_constituents(num_advect, advected=.true., &
errcode=errflg, errmsg=errmsg)

if (errflg /= 0) then
call endrun(subname//trim(errmsg), file=__FILE__, line=__LINE__)
end if

! Grab a pointer to the constituent array
const_props => cam_model_const_properties()

! Finally, initialize the constituents module
call cam_constituents_init(const_props, num_advect)

end subroutine cam_register_constituents

!-----------------------------------------------------------------------

end module cam_comp
Loading

0 comments on commit f2ee2a8

Please sign in to comment.