Skip to content

Commit

Permalink
ESCOMP tag: cam6_3_118
Browse files Browse the repository at this point in the history
Merge pull request ESCOMP#560 from CESM-GC/HEMCO-CESM_rebased_on_cam6_3_045

cam6_3_118: Integrating HEMCO emissions component in CESM

ESCOMP commit: 69c5b1c
  • Loading branch information
fvitt authored and Steve Goldhaber committed Aug 24, 2023
1 parent 11d061c commit ccced04
Show file tree
Hide file tree
Showing 19 changed files with 873 additions and 72 deletions.
113 changes: 68 additions & 45 deletions bld/build-namelist
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
# build-namelist
#
# This script builds the namelists for the standalone CAM configuration of
# CESM.
# This script builds the namelists for the CAM component of CESM.
#
# build-namelist is designed to be used in conjuction with configure.
# By default configure produces a config_cache.xml file that contains all
Expand Down Expand Up @@ -49,7 +48,7 @@ OPTIONS
-case "name" Case identifier up to 32 characters
-config "filepath" Read the given configuration cache file to determine the configuration
of the CAM executable. Default: "config_cache.xml".
-csmdata "dir" Root directory of CCSM input data.
-csmdata "dir" Root directory of CESM input data.
Can also be set by using the CSMDATA environment variable.
-dir "directory" Directory where output namelist files for each component will be
written, i.e., atm_in, drv_in, ice_in, lnd_in, rof_in, and ocn_in.
Expand Down Expand Up @@ -93,7 +92,7 @@ EOF
(my $ProgName = $0) =~ s!(.*)/!!; # name of this script
$ProgName = "CAM $ProgName"; # Since multiple components are now using a build-namelist
# utility add "CAM" qualifier to the name. This helps when
# looking at error output from the whole CCSM system.
# looking at error output from the whole CESM system.
my $ProgDir = $1; # name of directory containing this script -- may be a
# relative or absolute path, or null if the script is in
# the user's PATH
Expand Down Expand Up @@ -183,7 +182,7 @@ EOF

if ($print>=2) { print "Using CAM configuration cache file $opts{'config'}$eol"; }

# Check that the CCSM inputdata root directory has been specified.
# Check that the CESM inputdata root directory has been specified.
my $inputdata_rootdir = undef;
if (defined($opts{'csmdata'})) {
$inputdata_rootdir = $opts{'csmdata'};
Expand All @@ -192,16 +191,16 @@ elsif (defined $ENV{'CSMDATA'}) {
$inputdata_rootdir = $ENV{'CSMDATA'};
}
else {
die "$ProgName - ERROR: CCSM inputdata root directory must be specified by either -csmdata argument\n" .
die "$ProgName - ERROR: CESM inputdata root directory must be specified by either -csmdata argument\n" .
" or by the CSMDATA environment variable. :";
}

if ($print>=2) { print "CCSM inputdata root directory: $inputdata_rootdir$eol"; }
if ($print>=2) { print "CESM inputdata root directory: $inputdata_rootdir$eol"; }

# If the -test option is specified, then the inputdata root directory must be local or nfs mounted.
if ($opts{'test'}) {
(-d $inputdata_rootdir) or die <<"EOF";
** $ProgName - ERROR: CCSM inputdata root is not a directory: \"$inputdata_rootdir\" **
** $ProgName - ERROR: CESM inputdata root is not a directory: \"$inputdata_rootdir\" **
EOF
}

Expand Down Expand Up @@ -369,7 +368,9 @@ if (defined $opts{'case'}) { add_default($nl, 'case_name', 'val'=>$opts{'case'})
# Run type
if (defined $opts{'runtype'}) { add_default($nl, 'start_type', 'val'=>$opts{'runtype'}); }

# Process the -namelist arg.
# Process the -namelist argument. CIME uses this argument to pass the values that have been
# set by the compset definition via the CAM_NAMELIST_OPTS variable, along with additional
# settings made in the buildnml script.

if (defined $opts{'namelist'}) {
# Parse commandline namelist
Expand All @@ -387,7 +388,8 @@ if (defined $opts{'namelist'}) {
$nl->merge_nl($nl_arg_valid);
}

# Process the -infile arg.
# Process the -infile argument. CIME uses this argument to pass the contents of the user_nl_cam
# file, along with additional settings made in the buildnml script.

if (defined $opts{'infile'}) {
# Parse namelist input from a file
Expand All @@ -405,6 +407,11 @@ if (defined $opts{'infile'}) {
$nl->merge_nl($nl_infile_valid);
}

# Check for user input via the user_nl_cam file which is inconsistent with settings determined by
# the compset definition.

check_user_input($nl);

# Process the -use_case arg.
# Declare global symbol $uc_defaults even if it's not defined, because we check whether it's
# defined before using it in the get_default_value method below.
Expand Down Expand Up @@ -2870,6 +2877,23 @@ else {
}
}

# Harmonized Emissions Component (HEMCO) options
# Because HEMCO is configured at runtime, all of the options will be
# present in the namelist.
add_default($nl, 'use_hemco');
if ($nl->get_value('use_hemco') =~ m/$TRUE/io) {
add_default($nl, 'cam_physics_mesh');
add_default($nl, 'hemco_data_root');
add_default($nl, 'hemco_config_file');
add_default($nl, 'hemco_diagn_file');
add_default($nl, 'hemco_grid_xdim');
add_default($nl, 'hemco_grid_ydim');
# Remove these variables if present in the namelist since they are
# ignored at runtime when HEMCO is used.
$nl->delete_variable('chem_inparm', 'ext_frc_specifier');
$nl->delete_variable('chem_inparm', 'srf_emis_specifier');
}

# Physics options

# Add the name of the physics package based on the info in configure. If the user tries
Expand Down Expand Up @@ -4346,7 +4370,7 @@ sub add_default {
#
# ***** N.B. ***** This routine assumes the following variables are in package main::
# $definition -- the namelist definition object
# $inputdata_rootdir -- CCSM inputdata root directory
# $inputdata_rootdir -- CESM inputdata root directory

my $nl = shift; # namelist object
my $var = shift; # name of namelist variable
Expand Down Expand Up @@ -4399,7 +4423,7 @@ sub add_default {

# The default values for input pathnames are relative. If the namelist
# variable is defined to be an absolute pathname, then prepend
# the CCSM inputdata root directory.
# the CESM inputdata root directory.
if ($is_input_pathname eq 'abs') {
$val = set_abs_filepath($val, $inputdata_rootdir);
}
Expand Down Expand Up @@ -4569,6 +4593,37 @@ sub fv3_decomp_set{

#-----------------------------------------------------------------------------------------------

sub check_user_input {

# Check that user input in the user_nl_cam file is consistent with input that has been set by
# the compset definition via CAM_NAMELIST_OPTS. This routine is called after build-namelist has
# processed both the -namelist argument which contains the input from CAM_NAMELIST_OPTS, and
# the -infile argument which contains input from user_nl_cam.
#
# Checks for specific inconsistencies are added here by CAM developers as deemed useful for
# improving robustness of the user interface.

my $nl = shift; # namelist object

# When HEMCO is being used any emissions or external forcings specified by the
# srf_emis_specifier and ext_frc_specifier variables will be ignored at runtime.
# Check here that these variable are not set if the compset definition sets
# use_hemco=.true.

my $hemco = $nl->get_value('use_hemco');
if (defined $hemco and $hemco =~ m/$TRUE/io) {
if (defined $nl->get_value('srf_emis_specifier') or
defined $nl->get_value('ext_frc_specifier') ) {
die "$ProgName - ERROR: It is not allowed to set either srf_emis_specifier \n",
" or ext_frc_specifier when HEMCO is used.\n";
}
}


}

#-----------------------------------------------------------------------------------------------

sub check_input_files {

# For each variable in the namelist which is an input dataset, or contains filepaths
Expand Down Expand Up @@ -4734,7 +4789,7 @@ sub check_input_files {

# If $name2 starts with a slash, then it is an absolute filepath.
# If $name2 starts with a $, then it is an unresolved filepath
# (generated when run from CCSM scripts).
# (generated when run from CIME scripts).
# Otherwise check for more fields
if ($name2 =~ m:^[/\$]:) {

Expand Down Expand Up @@ -4994,38 +5049,6 @@ sub check_snapshot_settings {

#-----------------------------------------------------------------------------------------------

sub strip_rootdir {

# Strip a root directory from the begining of a filepath.
# Allow for the possibility that the root directory is specified as a shell variable
# to support a CCSM script requirement.

my ($filepath, $rootdir) = @_;

# Check whether the rootdir is specified as a shell variable.
if ($rootdir =~ m/^\$(\w*)/) {

my $rootname = $1;

# Strip off the root directory with the following regexp that
# avoids the problem of $rootdir being interpolated to a scalar variable
# name...
#$filepath =~ s:^\$$rootname::;

# The CCSM scripts are currently set up to expect the shell variable in the
# output file that contains the list of inputdata files. So in this case
# do nothing.

}
else {
# Strip off the rootdir specified as a resolved pathname
$filepath =~ s:^$rootdir::;
}
return $filepath;
}

#-----------------------------------------------------------------------------------------------

sub set_abs_filepath {

# check whether the input filepath is an absolute path, and if it isn't then
Expand Down
3 changes: 3 additions & 0 deletions bld/namelist_files/use_cases/2000_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
'SOAE -> 16.8188D0*$INPUTDATA_ROOT/atm/cam/chem/emis/CMIP6_emissions_2000climo/emissions-cmip6_SVOC_bb_surface_2000climo_0.9x1.25_c20170322.nc'
</srf_emis_specifier>

<!-- HEMCO emissions -->
<hemco_emission_year>2000</hemco_emission_year>

<flbc_file> 'atm/waccm/lb/LBC_2000climo_CMIP6_0p5degLat_c180227.nc' </flbc_file>
<flbc_list> 'CO2','CH4','N2O','CFC11eq','CFC12' </flbc_list>
<flbc_type> 'CYCLICAL' </flbc_type>
Expand Down
3 changes: 3 additions & 0 deletions bld/namelist_files/use_cases/2000_trop_strat_vbs_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
'so4_a2 -> $INPUTDATA_ROOT/atm/cam/chem/emis/CMIP6_emissions_2000climo/emissions-cmip6_so4_a2_anthro-res_surface_2000climo_0.9x1.25_c20170616.nc'
</srf_emis_specifier>

<!-- HEMCO emissions -->
<hemco_emission_year>2000</hemco_emission_year>

<ndep_list>'noy', 'nhx'</ndep_list>

<!-- History Files -->
Expand Down
3 changes: 3 additions & 0 deletions bld/namelist_files/use_cases/2010_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
'SOAE -> 16.8188D0*$INPUTDATA_ROOT/atm/cam/chem/emis/CMIP6_emissions_2010climo/emissions-cmip6_SVOC_bb_surface_2010climo_0.9x1.25_c20180918.nc'
</srf_emis_specifier>

<!-- HEMCO emissions -->
<hemco_emission_year>2010</hemco_emission_year>

<csw_time_type>CYCLICAL</csw_time_type>
<csw_cycle_yr>2010</csw_cycle_yr>

Expand Down
3 changes: 3 additions & 0 deletions bld/namelist_files/use_cases/2010_trop_strat_vbs_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@
'so4_a2 -> $INPUTDATA_ROOT/atm/cam/chem/emis/ne30pg3/2010climo/emissions-cmip6_so4_a2_anthro-res_surface_mol_2010climo_ne30pg3_c20200224.nc'
</srf_emis_specifier>

<!-- HEMCO emissions -->
<hemco_emission_year>2010</hemco_emission_year>

<ndep_list>'noy', 'nhx'</ndep_list>

<!-- History Files -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
./xmlchange GLC_NCPL=\$ATM_NCPL
./xmlchange EPS_AAREA=9.0e-4
./xmlchange EPS_AGRID=9.0e-5
./xmlchange MPILIB=mpi-serial
./xmlchange REST_OPTION=never
./xmlchange CAM_NML_USE_CASE=UNSET
./xmlchange PTS_LAT=36.6
Expand Down
4 changes: 2 additions & 2 deletions cime_config/usermods_dirs/scam_mandatory/shell_commands
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# these are necessary for scam runs.
#========================================
#
# SCAM works in SPMD mode with a single task, but the default is to run serially.
./xmlchange MPILIB=mpi-serial
# SCAM works in SPMD mode with a single task.
./xmlchange NTASKS=1

# SCAM doesn't have restart functionality yet.
./xmlchange REST_OPTION=never
Expand Down
Loading

0 comments on commit ccced04

Please sign in to comment.