Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics tendency updaters #163

Merged
merged 19 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Externals.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local_path = components/cice
required = False

[cime]
tag = cime5.8.38
tag = cime5.8.47
protocol = git
repo_url = https://github.com/ESMCI/cime
local_path = cime
Expand Down
4 changes: 2 additions & 2 deletions Externals_CAM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local_path = ccpp_framework
protocol = git
repo_url = https://github.com/gold2718/ccpp-framework
tag = CPF_0.2.026
tag = CPF_0.2.029
required = True

[cosp2]
Expand All @@ -23,7 +23,7 @@ required = False
local_path = src/physics/ncar_ccpp
protocol = git
repo_url = https://github.com/NCAR/atmospheric_physics
tag = atmos_phys0_00_011
tag = atmos_phys0_00_014
required = True

[silhs]
Expand Down
2 changes: 1 addition & 1 deletion cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ from CIME.buildlib import parse_input
from CIME.build import get_standard_makefile_args
#pylint: enable=wrong-import-position

check_minimum_python_version(2, 7)
check_minimum_python_version(3, 6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that for issue #156 we should have the restriction be for a 3.6 minimum (instead of 3.7)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that for issue #156 we should have the restriction be for a 3.6 minimum (instead of 3.7)?

I think so, let's settle this over there (where I have been commenting).

stop_buffering_output()

_LOGGER = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sys.path.append(_LIBDIR)
from standard_script_setup import *
from CIME.XML.standard_module_setup import *
from CIME.buildnml import create_namelist_infile, parse_input
from CIME.utils import check_minimum_python_version
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we do not really need this now.

from CIME.case import Case
from CIME.utils import expect
from CIME.nmlgen import NamelistGenerator
Expand Down
24 changes: 18 additions & 6 deletions cime_config/cam_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Import needed python libraries/modules
########################################

# Python library imports
import sys
import os
import logging
Expand Down Expand Up @@ -397,6 +398,7 @@ def generate_physics_suites(ccpp_scripts_path, build_cache, preproc_defs, host_n
# Import needed CCPP-framework scripts:
try:
from ccpp_capgen import capgen
from framework_env import CCPPFrameworkEnv
#pylint: disable=redefined-outer-name
# pylint change because of doctest import below
from metadata_table import find_scheme_names
Expand Down Expand Up @@ -453,6 +455,7 @@ def generate_physics_suites(ccpp_scripts_path, build_cache, preproc_defs, host_n
# Figure out if we need to generate new physics code
genccpp_dir = os.path.join(bldroot, "ccpp")
kind_phys = 'REAL64'
kind_types = ["kind_phys={}".format(kind_phys)]

# Set location of CCPP "capfiles.txt" file:
cap_output_file = os.path.join(genccpp_dir, "ccpp_datatable.xml")
Expand Down Expand Up @@ -482,8 +485,8 @@ def generate_physics_suites(ccpp_scripts_path, build_cache, preproc_defs, host_n
do_gen_ccpp = True
# End if
if do_gen_ccpp:
gen_hostcap = True
gen_docfiles = False
use_error_obj = False

# print extra info to bldlog if DEBUG is TRUE
_LOGGER.debug("Calling capgen: ")
Expand All @@ -492,13 +495,22 @@ def generate_physics_suites(ccpp_scripts_path, build_cache, preproc_defs, host_n
_LOGGER.debug(" suite definition files: %s", ', '.join(sdfs))
_LOGGER.debug(" preproc defs: %s", preproc_cache_str)
_LOGGER.debug(" output directory: '%s'", genccpp_dir)
_LOGGER.debug(" kind_phys: '%s'", kind_phys)
for kind_type in kind_types:
name, type = [x.strip() for x in kind_type.split('=')]
_LOGGER.debug(" %s: '%s'", name, type)
# end for

# generate CCPP caps
force_overwrite = False
capgen(host_files, scheme_files, sdfs, cap_output_file,
preproc_cache_str, gen_hostcap, gen_docfiles, genccpp_dir,
host_name, kind_phys, force_overwrite, _LOGGER)
run_env = CCPPFrameworkEnv(_LOGGER, host_files=host_files,
scheme_files=scheme_files, suites=sdfs,
preproc_directives=preproc_defs,
generate_docfiles=gen_docfiles,
host_name=host_name, kind_types=kind_types,
use_error_obj=use_error_obj,
force_overwrite=False,
output_root=genccpp_dir,
ccpp_datafile=cap_output_file)
capgen(run_env)

# save build details in the build cache
build_cache.update_ccpp(sdfs, scheme_files, preproc_cache_str, kind_phys)
Expand Down
29 changes: 18 additions & 11 deletions src/data/generate_registry_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

# CCPP framework imports
# pylint: disable=wrong-import-position
from framework_env import CCPPFrameworkEnv
from parse_tools import validate_xml_file, read_xml_file
from parse_tools import find_schema_file, find_schema_version
from parse_tools import init_log, CCPPError, ParseInternalError
Expand Down Expand Up @@ -433,7 +434,7 @@ def __init__(self, elem_node, parent_name, dimensions, known_types,
', '.join(dimensions)))
# end if
local_name = '{}({})'.format(parent_name, self.index_string)
super(ArrayElement, self).__init__(elem_node, local_name, my_dimensions,
super().__init__(elem_node, local_name, my_dimensions,
known_types, parent_type,
units_default=parent_units,
kind_default=parent_kind,
Expand Down Expand Up @@ -555,7 +556,7 @@ def __init__(self, var_node, known_types, vdict, logger):
# end if
# end for
# Initialize the base class
super(Variable, self).__init__(var_node, local_name,
super().__init__(var_node, local_name,
my_dimensions, known_types, ttype,
protected=protected)

Expand Down Expand Up @@ -591,7 +592,7 @@ def __init__(self, var_node, known_types, vdict, logger):
def write_metadata(self, outfile):
"""Write out this variable as CCPP metadata"""
if self.access != "private":
super(Variable, self).write_metadata(outfile)
super().write_metadata(outfile)
if (self.allocatable == "parameter") or self.protected:
outfile.write(' protected = True\n')
# end if
Expand Down Expand Up @@ -1430,16 +1431,18 @@ def parse_command_line(args, description):
return pargs

###############################################################################
def metadata_file_to_files(file_path, known_types, dycore, config, logger):
def metadata_file_to_files(file_path, known_types, dycore, config, run_env):
###############################################################################
"""Read the metadata file at <relative_file_path> and convert it to a
registry File object.
"""
known_ddts = known_types.known_ddt_names()
mfiles = []
if os.path.exists(file_path):
meta_tables = parse_metadata_file(file_path, known_ddts, logger)
logger.info("Parsing metadata_file, '{}'".format(file_path))
if run_env.logger:
run_env.logger.info("Parsing metadata_file, '{}'".format(file_path))
meta_tables = parse_metadata_file(file_path, known_ddts, run_env)
# end if
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion, these need to be swapped:

Suggested change
meta_tables = parse_metadata_file(file_path, known_ddts, run_env)
# end if
# end if
meta_tables = parse_metadata_file(file_path, known_ddts, run_env)

else:
emsg = "Metadata file, '{}', does not exist"
raise CCPPError(emsg.format(file_path))
Expand All @@ -1455,7 +1458,7 @@ def metadata_file_to_files(file_path, known_types, dycore, config, logger):
section = '<file name="{}" type="{}"></file>'.format(hname, htype)
sect_xml = ET.fromstring(section)
mfile = File(sect_xml, known_types, dycore, config,
logger, gen_code=False, file_path=file_path)
run_env.logger, gen_code=False, file_path=file_path)
# Add variables
# Note, we only support one section per table for host variables
sections = mtable.sections()
Expand Down Expand Up @@ -1497,7 +1500,7 @@ def metadata_file_to_files(file_path, known_types, dycore, config, logger):
# end if
vnode_str += '\n</variable>'
var_node = ET.fromstring(vnode_str)
mfile.add_variable(var_node, logger)
mfile.add_variable(var_node, run_env.logger)
# end for
if htype == 'ddt':
# We defined the variables, now create the DDT for them.
Expand All @@ -1509,8 +1512,8 @@ def metadata_file_to_files(file_path, known_types, dycore, config, logger):
vnode_str += '\n</ddt>'
var_node = ET.fromstring(vnode_str)
new_ddt = DDT(var_node, known_types, mfile.var_dict,
dycore, config, logger)
mfile.add_ddt(new_ddt, logger=logger)
dycore, config, run_env.logger)
mfile.add_ddt(new_ddt, logger=run_env.logger)
# end if
mfiles.append(mfile)
# end for
Expand All @@ -1532,6 +1535,10 @@ def write_registry_files(registry, dycore, config, outdir, src_mod, src_root,
"""
files = []
known_types = TypeRegistry()
logger.debug('hi')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhh, not sure what is going on here. If we need this line, I think the correct syntax is logger.debug('hi mom') ;)

# Create a fake CCPPFrameworkEnv object to contain the logger
run_env = CCPPFrameworkEnv(logger, host_files='',
scheme_files='', suites='')
for section in registry:
sec_name = section.get('name')
if sec_name:
Expand Down Expand Up @@ -1567,7 +1574,7 @@ def write_registry_files(registry, dycore, config, outdir, src_mod, src_root,
# end if
# end if
meta_files = metadata_file_to_files(file_path, known_types,
dycore, config, logger)
dycore, config, run_env)
files.extend(meta_files)
else:
emsg = "Unknown registry object type, '{}'"
Expand Down
22 changes: 14 additions & 8 deletions src/data/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,29 @@
<ic_file_input_names>tw_cur state_tw_cur</ic_file_input_names>
</variable>
<!-- State tendencies -->
<variable local_name="dTdt" standard_name="total_tendency_of_air_temperature"
<variable local_name="dTdt_total"
standard_name="tendency_of_air_temperature_due_to_model_physics"
units="K s-1" type="real" kind="kind_phys"
allocatable="pointer">
<long_name>Change in temperature from a parameterization</long_name>
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
<ic_file_input_names>dTdt tend_dtdt</ic_file_input_names>
</variable>
<variable local_name="dudt" standard_name="total_tendency_of_x_wind"
<variable local_name="dudt_total"
standard_name="tendency_of_x_wind_due_to_model_physics"
units="m s-2" type="real" kind="kind_phys"
allocatable="pointer">
<long_name>Change in x wind from a parameterization</long_name>
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
<ic_file_input_names>dudt tend_dudt</ic_file_input_names>
</variable>
<variable local_name="dvdt" standard_name="total_tendency_of_y_wind"
<variable local_name="dvdt_total"
standard_name="tendency_of_y_wind_due_to_model_physics"
units="m s-2" type="real" kind="kind_phys"
allocatable="pointer">
<long_name>Change in y wind from a parameterization</long_name>
<dimensions>horizontal_dimension vertical_layer_dimension</dimensions>
<ic_file_input_names>dvdt tend_dvdt</ic_file_input_names>
</variable>
<variable local_name="lagrangian_vertical"
standard_name="lagrangian_vertical_coordinate"
Expand Down Expand Up @@ -321,18 +326,19 @@
<data>frontogenesis_angle</data>
</ddt>
<ddt type="physics_tend">
<data>total_tendency_of_air_temperature</data>
<data>total_tendency_of_x_wind</data>
<data>total_tendency_of_y_wind</data>
<data>tendency_of_air_temperature_due_to_model_physics</data>
<data>tendency_of_x_wind_due_to_model_physics</data>
<data>tendency_of_y_wind_due_to_model_physics</data>
</ddt>
<variable local_name="phys_state"
standard_name="physics_state_due_to_dynamics"
units="None" type="physics_state">
<long_name>Physics state variables updated by dynamical core</long_name>
</variable>
<variable local_name="phys_tend"
standard_name="total_tendency_of_physics"
units="None" type="physics_tend" phys_timestep_init_zero="true">
nusbaume marked this conversation as resolved.
Show resolved Hide resolved
standard_name="tendency_due_to_model_physics"
units="None" type="physics_tend"
phys_timestep_init_zero="true">
<long_name>Total tendency from physics suite</long_name>
</variable>
</file>
Expand Down
36 changes: 18 additions & 18 deletions src/physics/utils/phys_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out)
! Local variables
real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not set yet
character(len=512) :: errmsg
integer :: errflg
integer :: errcode

errflg = 0
errcode = 0
call physconst_init(columns_on_task, pver, pverp)

call allocate_physics_types_fields(columns_on_task, pver, pverp, &
pcnst, set_init_val_in=.true., reallocate_in=.false.)
call cam_ccpp_physics_initialize(phys_suite_name, dtime_phys, &
errmsg, errflg)
if (errflg /= 0) then
errmsg, errcode)
if (errcode /= 0) then
call endrun('cam_ccpp_physics_initialize: '//trim(errmsg))
end if
call ccpp_physics_suite_part_list(phys_suite_name, suite_parts, &
errmsg, errflg)
if (errflg /= 0) then
errmsg, errcode)
if (errcode /= 0) then
call endrun('cam_ccpp_suite_part_list: '//trim(errmsg))
end if

Expand Down Expand Up @@ -202,14 +202,14 @@ subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, &
! Local variables
type(file_desc_t), pointer :: ncdata
character(len=512) :: errmsg
integer :: errflg
integer :: errcode
integer :: part_ind
integer :: col_start
integer :: col_end
integer :: data_frame
logical :: use_init_variables

errflg = 0
errcode = 0
! Physics needs to read in all data not read in by the dycore
ncdata => initial_file_get_id()

Expand All @@ -231,8 +231,8 @@ subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, &

! Initialize the physics time step
call cam_ccpp_physics_timestep_initial(phys_suite_name, dtime_phys, &
errmsg, errflg)
if (errflg /= 0) then
errmsg, errcode)
if (errcode /= 0) then
call endrun('cam_ccpp_physics_timestep_initial: '//trim(errmsg))
end if

Expand All @@ -243,16 +243,16 @@ subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, &
! Run CCPP suite
do part_ind = 1, size(suite_parts, 1)
call cam_ccpp_physics_run(phys_suite_name, suite_parts(part_ind), &
col_start, col_end, dtime_phys, errmsg, errflg)
if (errflg /= 0) then
col_start, col_end, dtime_phys, errmsg, errcode)
if (errcode /= 0) then
call endrun('cam_ccpp_physics_run: '//trim(errmsg))
end if
end do

! Finalize the time step
call cam_ccpp_physics_timestep_final(phys_suite_name, dtime_phys, &
errmsg, errflg)
if (errflg /= 0) then
errmsg, errcode)
if (errcode /= 0) then
call endrun('cam_ccpp_physics_timestep_final: '//trim(errmsg))
end if

Expand All @@ -278,13 +278,13 @@ subroutine phys_final(cam_runtime_opts, phys_state, phys_tend)
! Local variables
real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not used
character(len=512) :: errmsg
integer :: errflg
integer :: errcode

errflg = 0
errcode = 0

call cam_ccpp_physics_finalize(phys_suite_name, dtime_phys, &
errmsg, errflg)
if (errflg /= 0) then
errmsg, errcode)
if (errcode /= 0) then
call endrun('cam_ccpp_physics_finalize: '//trim(errmsg))
end if
deallocate(suite_names)
Expand Down
4 changes: 2 additions & 2 deletions src/physics/utils/phys_comp.meta
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
dimensions = ()
type = character
kind = len=512
[ errflg ]
standard_name = ccpp_error_flag
[ errcode ]
standard_name = ccpp_error_code
long_name = Error flag for error handling in CCPP
units = flag
dimensions = ()
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sample_files/write_init_files/missing_var_host.meta
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
type = character
kind = len=512
[ errflg ]
standard_name = ccpp_error_flag
standard_name = ccpp_error_code
long_name = Error flag for error handling in CCPP
units = flag
units = 1
dimensions = ()
type = integer
[ theta ]
Expand Down
Loading