Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions bld/build-namelist
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,15 @@ if (not $waccm_phys) {
add_default($nl, 'p_bot_for_radmrg');
}

# Check TUV-X configuration
my $tuvx_active = $nl->get_value('tuvx_active');
if ($tuvx_active =~ /$TRUE/io) {
my $tuvx_config = $cfg->get('tuvx');
if (!$tuvx_config) {
die "$ProgName - ERROR: must use -tuvx CAM configure flag \n";
}
}

# Solar irradiance

# First check that solar_const and solar_irrad_data_file are not both defined
Expand Down
3 changes: 3 additions & 0 deletions bld/config_files/definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Option to turn on waccmx thermosphere/ionosphere extension: 0 => no, 1 => yes
<entry id="ext_co2_cool" valid_values="0,1" value="0">
Option to turn on extended non-LTE CO2 cooling: 0 => no, 1 => yes
</entry>
<entry id="tuvx" valid_values="0,1" value="0">
Option to build TUV-X library: 0 => no, 1 => yes
</entry>
<entry id="ionosphere" valid_values="none,wxie" value="none">
Ionosphere model used in WACCMX.
</entry>
Expand Down
15 changes: 14 additions & 1 deletion bld/configure
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ OPTIONS
-psubcols <n> Maximum number of sub-columns in a run - set to 1 if not using sub-columns (default)
-rad <name> Specify the radiation package [rrtmg | rrtmgp | rrtmgp_gpu | camrt]
-silhs Switch on SILHS.
-tuvx Switch to build TUV-X library
-usr_mech_infile Path and file name of the user supplied chemistry mechanism file.
-waccm_phys Switch enables the use of WACCM physics in any chemistry configuration.
The user does not need to set this if one of the waccm chemistry options
Expand Down Expand Up @@ -305,6 +306,7 @@ GetOptions(
"waccm_phys" => \$opts{'waccm_phys'},
"waccmx" => \$opts{'waccmx'},
"ext_co2_cool" => \$opts{'ext_co2_cool'},
"tuvx" => \$opts{'tuvx'},
) or usage();

# Give usage message.
Expand Down Expand Up @@ -717,6 +719,12 @@ if (defined $opts{'ext_co2_cool'}) {
}
my $ext_co2_cool = $cfg_ref->get('ext_co2_cool');

# TUV-x option
if (defined $opts{'tuvx'}) {
$cfg_ref->set('tuvx', $opts{'tuvx'});
}
my $tuvx = $cfg_ref->get('tuvx');

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

# Prognostic species package(s)
Expand Down Expand Up @@ -1788,6 +1796,11 @@ if ($ext_co2_cool) {
$cfg_cppdefs .= ' -DEXT_CO2_COOL';
}

# TUV-X
if ($tuvx) {
$cfg_cppdefs .= ' -DTUVX';
}

# PIO
my $pio2_build = (defined $opts{'pio2'}) ? 1 : 0;

Expand Down Expand Up @@ -1864,7 +1877,7 @@ if ($cosp) {
$ldflags .= " -L$cosp_libdir -lrttov13_wrapper -lrttov13_mw_scatt -lrttov13_brdf_atlas -lrttov13_emis_atlas -lrttov13_other -lrttov13_parallel -lrttov13_coef_io -lrttov13_hdf -lrttov13_main ";
$cfg_ref->set('ldflags', $ldflags);
print "Adding rttov libraries as dependencies in ldflags.\n";
}
}
# Create the COSP Makefile from a template and copy it into the cosp bld directory
if ($print) { print "creating $cosp_libdir/Makefile\n"; }
write_cosp_makefile("$cfgdir/../src/physics/cosp2/Makefile.in", "$cosp_libdir/Makefile");
Expand Down
126 changes: 71 additions & 55 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ create the cam library
# pylint: disable=multiple-imports, wrong-import-position, wildcard-import
# pylint: disable=unused-wildcard-import, bad-whitespace, too-many-locals
# pylint: disable=invalid-name
import sys, os, filecmp, shutil
import sys, os, filecmp, shutil, re
from glob import glob

_CIMEROOT = os.environ.get("CIMEROOT")
Expand Down Expand Up @@ -232,60 +232,76 @@ def _build_tuvx(caseroot, libroot, bldroot):
# Builds the TUV-x library and updates the case variables used to set the
# include paths and linked libraries

with Case(caseroot) as case:
bldpath = os.path.join(bldroot, "tuv-x")
if not os.path.exists(bldpath):
os.makedirs(bldpath)
srcpath = os.path.abspath(os.path.join(case.get_value("SRCROOT"), \
"libraries", "tuv-x", ""))
logger.info("Building TUV-x in {} from source in {}\n".format(bldpath, srcpath))

arg_dict = _cmake_default_args(caseroot)
cmake_args = "-DCMAKE_VERBOSE_MAKEFILE=ON "
if case.get_value("MPILIB") != "mpi-serial":
cmake_args += "-DTUVX_ENABLE_MPI:BOOL=TRUE "
cmake_args += "-DCMAKE_BUILD_TYPE=Debug "
cmake_args += "-DCMAKE_Fortran_COMPILER=mpif90 "
cmake_args += "-DCMAKE_C_COMPILER=mpicc "
cmake_args += "-DCMAKE_CXX_COMPILER=mpicxx "
cmake_args += "-DCMAKE_Fortran_COMPILER_WORKS=1 "
cmake_args += "-DCMAKE_C_COMPILER_WORKS=1 "
cmake_args += "-DCMAKE_CXX_COMPILER_WORKS=1 "
if (case.get_value("MACH") == "izumi") :
cmake_args += f"-DCMAKE_PREFIX_PATH={arg_dict['NETCDF_PATH']} "
cmake_args += f"-DCMAKE_IGNORE_PATH={os.environ.get('PYTHONHOME')} "
if (case.get_value("MACH") == "izumi") and (case.get_value('COMPILER') == "nag") :
cmake_args += "-DCMAKE_Fortran_FLAGS='-C=all -g ' "
else :
cmake_args += f"-DCMAKE_Fortran_FLAGS='{arg_dict['FFLAGS']}' "
cmake_args += f"-DCMAKE_INSTALL_PREFIX='{libroot}' "
cmake_args += "-DTUVX_ENABLE_TESTS=OFF "
cmake_args += "-DTUVX_ENABLE_COVERAGE=OFF "
cmake_args += "-DTUVX_BUILD_CLI=OFF "
cmake_args += f"-DTUVX_INSTALL_INCLUDE_DIR='{_tuvx_include_dir(libroot)}' "
cmake_args += f"-DTUVX_INSTALL_MOD_DIR='{_tuvx_include_dir(libroot)}' "
cmake_args += srcpath

_run_cmd(f"cmake {cmake_args}", bldpath)
_run_cmd(case.get_value('GMAKE'), bldpath)
_run_cmd(f"{case.get_value('GMAKE')} install", bldpath)

# add TUV-x to include paths
incldir = os.environ.get('USER_INCLDIR')
if incldir is None:
incldir = ''
os.environ['USER_INCLDIR'] = incldir + \
f" -I{_tuvx_include_dir(libroot)} "

# create symlink to library in folder CIME expects libraries to be in
dst = os.path.join(libroot, "libtuvx.a")
if os.path.isfile(dst):
os.remove(dst)
os.symlink(_tuvx_lib_path(libroot), dst)
dst = os.path.join(libroot, "libyaml-cpp.a")
if os.path.isfile(dst):
os.remove(dst)
os.symlink(_yaml_cpp_lib_path(libroot), dst)
with Case(caseroot, read_only=False) as case:
config_opts = case.get_value("CAM_CONFIG_OPTS")
Comment thread
fvitt marked this conversation as resolved.

# Remove any TUV-x link options set by a previous build, so that
# re-building the case does not accumulate duplicate or stale
# options in CAM_LINKED_LIBS:
linked_libs = case.get_value("CAM_LINKED_LIBS",
subgroup="build_component_cam")
tuvx_link_opts = " -ltuvx -lyaml-cpp"
new_linked_libs = re.sub(r"\s*-ltuvx -lyaml-cpp", "", linked_libs)
if "-tuvx" in config_opts:
bldpath = os.path.join(bldroot, "tuv-x")
if not os.path.exists(bldpath):
os.makedirs(bldpath)
srcpath = os.path.abspath(os.path.join(case.get_value("SRCROOT"), \
"libraries", "tuv-x", ""))
logger.info("Building TUV-x in {} from source in {}\n".format(bldpath, srcpath))

arg_dict = _cmake_default_args(caseroot)
cmake_args = "-DCMAKE_VERBOSE_MAKEFILE=ON "
if case.get_value("MPILIB") != "mpi-serial":
cmake_args += "-DTUVX_ENABLE_MPI:BOOL=TRUE "
cmake_args += "-DCMAKE_BUILD_TYPE=Debug "
cmake_args += "-DCMAKE_Fortran_COMPILER=mpif90 "
cmake_args += "-DCMAKE_C_COMPILER=mpicc "
cmake_args += "-DCMAKE_CXX_COMPILER=mpicxx "
cmake_args += "-DCMAKE_Fortran_COMPILER_WORKS=1 "
cmake_args += "-DCMAKE_C_COMPILER_WORKS=1 "
cmake_args += "-DCMAKE_CXX_COMPILER_WORKS=1 "
cmake_args += "-DCMAKE_DISABLE_FIND_PACKAGE_yaml-cpp=1 "
if (case.get_value("MACH") == "izumi") :
cmake_args += f"-DCMAKE_PREFIX_PATH={arg_dict['NETCDF_PATH']} "
if (case.get_value("MACH") == "izumi") and (case.get_value('COMPILER') == "nag") :
cmake_args += "-DCMAKE_Fortran_FLAGS='-C=all -g ' "
else :
cmake_args += f"-DCMAKE_Fortran_FLAGS='{arg_dict['FFLAGS']}' "
cmake_args += f"-DCMAKE_INSTALL_PREFIX='{libroot}' "
cmake_args += "-DTUVX_ENABLE_TESTS=OFF "
cmake_args += "-DTUVX_ENABLE_COVERAGE=OFF "
cmake_args += "-DTUVX_BUILD_CLI=OFF "
cmake_args += f"-DTUVX_INSTALL_INCLUDE_DIR='{_tuvx_include_dir(libroot)}' "
cmake_args += f"-DTUVX_INSTALL_MOD_DIR='{_tuvx_include_dir(libroot)}' "
cmake_args += srcpath

_run_cmd(f"cmake {cmake_args}", bldpath)
_run_cmd(case.get_value('GMAKE'), bldpath)
_run_cmd(f"{case.get_value('GMAKE')} install", bldpath)

# add TUV-x to include paths
incldir = os.environ.get('USER_INCLDIR')
if incldir is None:
incldir = ''
os.environ['USER_INCLDIR'] = incldir + \
f" -I{_tuvx_include_dir(libroot)} "

# create symlink to library in folder CIME expects libraries to be in
dst = os.path.join(libroot, "libtuvx.a")
if os.path.isfile(dst):
os.remove(dst)
os.symlink(_tuvx_lib_path(libroot), dst)
dst = os.path.join(libroot, "libyaml-cpp.a")
if os.path.isfile(dst):
os.remove(dst)
os.symlink(_yaml_cpp_lib_path(libroot), dst)

# Add TUVX to CAM linked library list:
new_linked_libs = tuvx_link_opts.strip() + " " + new_linked_libs

if new_linked_libs != linked_libs:
case.set_value("CAM_LINKED_LIBS", new_linked_libs)

###############################################################################
def _tuvx_include_dir(libroot):
Expand Down
12 changes: 7 additions & 5 deletions cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def buildnml(case, caseroot, compname):
"Gregorian calendar (modifier _cG) cannot be used with spinup compset \n {}".format(COMPSET)
)

tuvx_data_src = os.path.join(srcroot, "libraries", "tuv-x", "data")
if '-tuvx' in CAM_CONFIG_OPTS:
tuvx_data_src = os.path.join(srcroot, "libraries", "tuv-x", "data")

testsrc = os.path.join(srcroot, "components", "cam")
if os.path.exists(testsrc):
Expand Down Expand Up @@ -237,10 +238,11 @@ def buildnml(case, caseroot, compname):
shutil.copy(file1,file2)

# Copy TUV-x data to rundir
dest_data = os.path.join(rundir, "data")
if os.path.exists(dest_data):
shutil.rmtree(dest_data)
shutil.copytree(tuvx_data_src, dest_data)
if '-tuvx' in CAM_CONFIG_OPTS:
dest_data = os.path.join(rundir, "data")
if os.path.exists(dest_data):
shutil.rmtree(dest_data)
shutil.copytree(tuvx_data_src, dest_data)

###############################################################################
def _main_func():
Expand Down
2 changes: 1 addition & 1 deletion cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
<entry id="CAM_LINKED_LIBS">
<type>char</type>
<valid_values></valid_values>
<default_value>-ltuvx -lyaml-cpp -lstdc++</default_value>
<default_value>-lstdc++</default_value>
<group>build_component_cam</group>
<file>env_build.xml</file>
<desc>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
./xmlchange CAM_CONFIG_OPTS=" -phys cam4 -rad rrtmg -chem waccm_ma_sulfur -carma mixed_sulfate"
./xmlchange CAM_CONFIG_OPTS=" -phys cam4 -rad rrtmg -chem waccm_ma_sulfur -carma mixed_sulfate -tuvx"
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange GLC_NCPL=\$ATM_NCPL
./xmlchange RUN_STARTDATE="0001-01-01"
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
./xmlchange --append CAM_CONFIG_OPTS="-tuvx"
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange GLC_NCPL=\$ATM_NCPL
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange CAM_CONFIG_OPTS="-phys cam6 -age_of_air_trcs -chem waccm_ma_mam4 -ext_co2_cool"
./xmlchange CAM_CONFIG_OPTS="-phys cam6 -age_of_air_trcs -chem waccm_ma_mam4 -ext_co2_cool -tuvx"
80 changes: 80 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,84 @@
===============================================================

Tag name: cam6_4_182
Originator(s): fvitt
Date: 16 Jun 2026
One-line Summary: Updates to CAM's build of TUV-X library
Github PR URL: https://github.com/ESCOMP/CAM/pull/1577

Purpose of changes (include the issue number and title text for each relevant GitHub issue):

Build TUV-X library only in cases where TUV-X is used. Configure
switch -tuvx has been added to CAM_CONFIG_OPTS which activates
the build of the TUV-X library.

Address issues:
#1537: TUV-x build issue when users have Conda environments active
https://github.com/ESCOMP/CAM/issues/1570

#1570: TUV-x copies input files to run directory regardless of whether TUV-x is active
https://github.com/ESCOMP/CAM/issues/1570

Describe any changes made to build system:
Changes TUV-X library build as described above

Describe any changes made to the namelist: N/A

List any changes to the defaults for the boundary datasets: N/A

Describe any substantial timing or memory changes: N/A

Code reviewed by: jimmielin cacraigucar

List all files eliminated: N/A

List all files added and what they do: N/A

List all existing files that have been modified, and describe the changes:

M bld/build-namelist
- error out if tuvx_active is TRUE and not configured for TUV-X

M bld/config_files/definition.xml
M bld/configure
- add "-tuvx" configure switch -- define "TUVX" CPP def

M cime_config/buildlib
- build TUV-X lib only if "-tuvx" is included in CAM_CONFIG_OPTS

M cime_config/buildnml
- copy TUV-X input data to run directory only if "-tuvx" is included in CAM_CONFIG_OPTS

M cime_config/config_component.xml
- remove tuvx and yaml-cpp libs from default setting of CAM_LINKED_LIBS
-- buildlib will add these only only if cam is configured for tuvx

M cime_config/testdefs/testmods_dirs/cam/carma_mixed_sulfate/shell_commands
M cime_config/testdefs/testmods_dirs/cam/outfrq9s_tuvx_waccm_ma_mam5/shell_commands
M cime_config/testdefs/testmods_dirs/cam/outfrq9s_waccm_ma_mam4/shell_commands
-- append "-tuvx" to CAM_CONFIG_OPTS

M src/chemistry/mozart/mo_tuvx.F90
- use ifdefs to stub out the module for cases where TUV-X lib is not available

If there were any failures reported from running test_driver.sh on any test
platform, and checkin with these failures has been OK'd by the gatekeeper,
then copy the lines from the td.*.status files for the failed tests to the
appropriate machine below. All failed tests must be justified.

derecho/intel/aux_cam: All PASS

derecho/nvhpc/aux_cam: All PASS

izumi/nag/aux_cam:
FAIL ERC_D_Ln9.f10_f10_mt232.FHIST_C5.izumi_nag.cam-outfrq3s_subcol COMPARE_base_rest
- pre-existing failure -- see https://github.com/ESCOMP/CAM/issues/1514

izumi/gnu/aux_cam: All PASS

Summarize any changes to answers: bit-for-bit

===============================================================
===============================================================

Tag name: cam6_4_181
Expand Down
Loading
Loading