Skip to content

Commit 9cdfc64

Browse files
committed
Merge branch 'development' into hplin/rk_stratiform
2 parents af2efc9 + ea16d8a commit 9cdfc64

26 files changed

+1326
-117
lines changed

.gitmodules

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
[submodule "ncar-physics"]
2121
path = src/physics/ncar_ccpp
2222
url = https://github.com/ESCOMP/atmospheric_physics
23-
fxtag = atmos_phys0_10_001
23+
fxtag = 0af2e2b80bc2f8597b685bf08b0917233ce84afa
2424
fxrequired = AlwaysRequired
2525
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics
26+
[submodule "rrtmgp-data"]
27+
path = src/physics/utils/rrtmgp-data
28+
url = https://github.com/earth-system-radiation/rrtmgp-data.git
29+
fxrequired = AlwaysRequired
30+
fxtag = v1.8
31+
fxDONOTUSEurl = https://github.com/earth-system-radiation/rrtmgp-data.git
2632
[submodule "ccs_config"]
2733
path = ccs_config
2834
url = https://github.com/ESMCI/ccs_config_cesm.git

cime_config/atm_musica_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"""
55

66
MUSICA_CCPP_SCHEME_NAME = "musica_ccpp"
7+
MUSICA_CONFIG_DIR_NAME = "musica_configurations"
78
MUSICA_REPO_URL = "https://github.com/NCAR/musica.git"
89
MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf"
910
CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git"
10-
CHEMISTRY_DATA_TAG = "2b58f2410ec7a565bcf80dee16ec20f6bc35d78b"
11+
CHEMISTRY_DATA_TAG = "71ed143c54b0d5d6e3e70f3d05d413fddcf8d59e"

cime_config/buildlib

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import subprocess
1212
import logging
1313

1414
from cam_config import ConfigCAM # CAM's configure structure
15-
from atm_musica_config import MUSICA_CCPP_SCHEME_NAME
15+
from atm_musica_config import MUSICA_CCPP_SCHEME_NAME, MUSICA_CONFIG_DIR_NAME
1616
from atm_musica_config import MUSICA_REPO_URL, MUSICA_TAG
1717
from atm_musica_config import CHEMISTRY_DATA_REPO_URL, CHEMISTRY_DATA_TAG
1818

@@ -176,21 +176,22 @@ def _build_cam():
176176
# If MUSICA-CCPP scheme is used in a suite, download
177177
# the MUSICA configuration and build the MUSICA library
178178
if MUSICA_CCPP_SCHEME_NAME in scheme_names:
179-
_download_musica_configuration(caseroot)
179+
_ = _download_musica_configuration(caseroot)
180180
musica_install_path = _build_musica(caseroot)
181181

182182
cam_linked_libs = case.get_value("CAM_LINKED_LIBS")
183183
musica_libs = "-lmusica-fortran -lmusica -lyaml-cpp"
184184
if not musica_libs in cam_linked_libs:
185185
_set_musica_lib_path(musica_install_path, caseroot)
186186

187-
cmd += ' USER_INCLDIR="'\
188-
f'-I{os.path.join(musica_install_path, "include", "micm")} '\
189-
f'-I{os.path.join(musica_install_path, "include", "musica")} '\
190-
f'-I{os.path.join(musica_install_path, "include", "musica", "micm")} '\
191-
f'-I{os.path.join(musica_install_path, "include", "musica", "tuvx")} '\
192-
f'-I{os.path.join(musica_install_path, "include", "musica", "fortran")} '\
187+
cmd += (' USER_INCLDIR="'
188+
f'-I{os.path.join(musica_install_path, "include", "micm")} '
189+
f'-I{os.path.join(musica_install_path, "include", "musica")} '
190+
f'-I{os.path.join(musica_install_path, "include", "musica", "micm")} '
191+
f'-I{os.path.join(musica_install_path, "include", "musica", "tuvx")} '
192+
f'-I{os.path.join(musica_install_path, "include", "musica", "fortran")} '
193193
'"'
194+
)
194195

195196
retcode, out, err = run_cmd(cmd)
196197
_LOGGER.info("Command %s:\n\nstdout:\n%s\n\nstderr:\n%s\n", cmd, out, err)
@@ -284,8 +285,8 @@ def _build_musica(clone_dest: str) -> str:
284285
subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE,
285286
stderr=subprocess.PIPE, text=True, check=False)
286287
except subprocess.CalledProcessError as e:
287-
raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \
288-
for cmake to configure the MUSICA CMake project failed.") from e
288+
raise subprocess.CalledProcessError(e.returncode, e.cmd,
289+
"The subprocess for cmake to configure the MUSICA CMake project failed.") from e
289290
except FileNotFoundError as e:
290291
raise FileNotFoundError("The 'cmake' command was not found.") from e
291292
except OSError as e:
@@ -294,10 +295,10 @@ def _build_musica(clone_dest: str) -> str:
294295
command = ["cmake", "--build", ".", "--target", "install"]
295296
try:
296297
subprocess.run(command, cwd=bld_path, stdout=subprocess.PIPE,
297-
stderr=subprocess.PIPE, text=True, check=False)
298+
text=True, check=False)
298299
except subprocess.CalledProcessError as e:
299-
raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \
300-
for cmake to build the MUSICA library failed.") from e
300+
raise subprocess.CalledProcessError(e.returncode, e.cmd,
301+
"The subprocess for cmake to build the MUSICA library failed.") from e
301302
except FileNotFoundError as e:
302303
raise FileNotFoundError("The 'cmake' command was not found.") from e
303304
except OSError as e:
@@ -308,7 +309,7 @@ def _build_musica(clone_dest: str) -> str:
308309
return musica_install_path
309310

310311
###############################################################################
311-
def _download_musica_configuration(download_dest: str) -> None:
312+
def _download_musica_configuration(download_dest: str) -> str:
312313
###############################################################################
313314
"""
314315
Downloads the MUSICA configuration and renames the configuration
@@ -321,13 +322,14 @@ def _download_musica_configuration(download_dest: str) -> None:
321322
Exception: If the directory to be renamed is not found or
322323
any other exceptions occur during the renaming process,
323324
an exception is raised with the error message.
325+
Returns:
326+
musica_config_path: path to the MUSICA configuration directory
324327
"""
325-
musica_config_dir_name = "musica_configurations"
326328

327329
_clone_and_checkout(CHEMISTRY_DATA_REPO_URL, CHEMISTRY_DATA_TAG, download_dest)
328330

329331
original_dir = os.path.join(download_dest, "cam-sima-chemistry-data", "mechanisms")
330-
renamed_dir = os.path.join(download_dest, "cam-sima-chemistry-data", musica_config_dir_name)
332+
renamed_dir = os.path.join(download_dest, "cam-sima-chemistry-data", MUSICA_CONFIG_DIR_NAME)
331333
try:
332334
os.rename(original_dir, renamed_dir)
333335
except FileNotFoundError as e:
@@ -339,12 +341,14 @@ def _download_musica_configuration(download_dest: str) -> None:
339341
except OSError as e:
340342
raise OSError("An error occurred while renaming.") from e
341343

342-
musica_config_path = os.path.join(download_dest, musica_config_dir_name)
344+
musica_config_path = os.path.join(download_dest, MUSICA_CONFIG_DIR_NAME)
343345
if os.path.exists(musica_config_path):
344346
shutil.rmtree(musica_config_path)
345347

346348
shutil.move(renamed_dir, download_dest)
347349

350+
return musica_config_path
351+
348352
###############################################################################
349353
def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
350354
###############################################################################
@@ -374,8 +378,8 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
374378
subprocess.run(command, cwd=caseroot, stdout=subprocess.PIPE,
375379
stderr=subprocess.PIPE, text=True, check=False)
376380
except subprocess.CalledProcessError as e:
377-
raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \
378-
for xmlchange to set the MUSICA library path failed.") from e
381+
raise subprocess.CalledProcessError(e.returncode, e.cmd,
382+
"The subprocess for xmlchange to set the MUSICA library path failed.") from e
379383
except FileNotFoundError as e:
380384
raise FileNotFoundError("The 'xmlchange' command was not found.") from e
381385
except OSError as e:
@@ -408,8 +412,8 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
408412
subprocess.run(["git", "clone", repo_url, repo_path],
409413
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False)
410414
except subprocess.CalledProcessError as e:
411-
raise subprocess.CalledProcessError(e.returncode, e.cmd, f"The subprocess \
412-
for git to clone the repository {repo_url} failed.") from e
415+
raise subprocess.CalledProcessError(e.returncode, e.cmd,
416+
f"The subprocess for git to clone the repository {repo_url} failed.") from e
413417
except FileNotFoundError as e:
414418
raise FileNotFoundError("The 'git' command was not found.") from e
415419
except OSError as e:
@@ -419,8 +423,8 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
419423
subprocess.run(["git", "-C", repo_path, "checkout", tag_name],
420424
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False)
421425
except subprocess.CalledProcessError as e:
422-
raise subprocess.CalledProcessError(e.returncode, e.cmd, f"The subprocess \
423-
for git to checkout the branch {tag_name} failed.") from e
426+
raise subprocess.CalledProcessError(e.returncode, e.cmd,
427+
f"The subprocess for git to checkout the branch {tag_name} failed.") from e
424428
except FileNotFoundError as e:
425429
raise FileNotFoundError("The 'git' command was not found.") from e
426430
except OSError as e:

cime_config/buildnml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from CIME.Tools.standard_script_setup import *
2222
from CIME.XML.standard_module_setup import *
2323
from CIME.buildnml import create_namelist_infile, parse_input
2424
from CIME.case import Case
25-
from CIME.utils import expect
25+
from CIME.utils import expect, symlink_force
2626

2727
# Save local (cime_config) directory path:
2828
_CIME_CONFIG_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -35,8 +35,10 @@ from cam_config import ConfigCAM
3535
# HistoryConfig allows translation from user_nl_cam into Fortran namelists
3636
from hist_config import HistoryConfig
3737

38-
#Import CAM's ParamGen class:
38+
# Import CAM's ParamGen class:
3939
from atm_in_paramgen import AtmInParamGen
40+
# Import specific names associated with the MUSICA scheme
41+
from atm_musica_config import MUSICA_CCPP_SCHEME_NAME, MUSICA_CONFIG_DIR_NAME
4042

4143
# Open CIME case log:
4244
_LOGGER = logging.getLogger(__name__)
@@ -166,7 +168,7 @@ def buildnml(case, caseroot, compname):
166168
gen_indent = 3
167169

168170
#Generate model code and meta-data:
169-
_ = config.generate_cam_src(gen_indent)
171+
scheme_names = config.generate_cam_src(gen_indent)
170172

171173
#----------------------------------------------------------------
172174
# Create namelist attribute dictionary (to set namelist defaults):
@@ -376,6 +378,21 @@ def buildnml(case, caseroot, compname):
376378
# end for
377379
# end with
378380

381+
# If MUSICA-CCPP scheme is used in a suite, create symlinks in the run
382+
# directory pointing to the MUSICA configuration data located in the caseroot
383+
if MUSICA_CCPP_SCHEME_NAME in scheme_names:
384+
musica_config_src_dir = os.path.join(caseroot, MUSICA_CONFIG_DIR_NAME)
385+
musica_config_dest_dir = os.path.join(rundir, MUSICA_CONFIG_DIR_NAME)
386+
387+
if os.path.exists(musica_config_src_dir):
388+
os.makedirs(musica_config_dest_dir, exist_ok=True)
389+
for root, _, files in os.walk(musica_config_src_dir):
390+
rel_path = os.path.relpath(root, musica_config_src_dir)
391+
dest_dir = os.path.join(musica_config_dest_dir, rel_path)
392+
393+
os.makedirs(dest_dir, exist_ok=True)
394+
for file in files:
395+
symlink_force(os.path.join(root, file), os.path.join(dest_dir, file))
379396

380397
###############################################################################
381398
def _main_func():

cime_config/cam_autogen.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -601,20 +601,20 @@ def generate_physics_suites(build_cache, preproc_defs, host_name,
601601
# So go-ahead and copy all of the source code from
602602
# there to the bld directory:
603603
if do_gen_ccpp:
604-
# Set CCPP physics "utilities" path
605-
atm_phys_util_dir = os.path.join(atm_schemes_path, "utilities")
604+
# Set CCPP physics 'utilities' path
605+
atm_phys_utilities_dir = os.path.join(atm_schemes_path, "utilities")
606606

607-
# Check that directory exists
608-
if not os.path.isdir(atm_phys_util_dir):
607+
# Check that the directory exists
608+
if not os.path.isdir(atm_phys_utilities_dir):
609609
# CAM-SIMA will likely not run without this, so raise an error
610-
emsg = "ERROR: Unable to find CCPP physics utilities directory:\n"
611-
emsg += f" {atm_phys_util_dir}\n Have you run 'git-fleximod'?"
610+
emsg = "ERROR: Unable to find CCPP physics 'utilities' directory:\n"
611+
emsg += f" {atm_phys_utilities_dir}\n Have you run 'git-fleximod'?"
612612
raise CamAutoGenError(emsg)
613613
# end if
614614

615-
# Copy all utility source files to the build directory
616-
atm_phys_util_files = glob.glob(os.path.join(atm_phys_util_dir, "*.F90"))
617-
for util_file in atm_phys_util_files:
615+
# Copy all 'utilities' source files to the build directory
616+
atm_phys_utilities_files = glob.glob(os.path.join(atm_phys_utilities_dir, "*.F90"))
617+
for util_file in atm_phys_utilities_files:
618618
shutil.copy(util_file, physics_blddir)
619619
# end for
620620

@@ -632,11 +632,32 @@ def generate_physics_suites(build_cache, preproc_defs, host_name,
632632
raise CamAutoGenError(emsg)
633633
# end if
634634

635+
# Copy all 'to_be_ccppized' source files to the build directory
635636
atm_phys_to_be_ccppized_files = glob.glob(os.path.join(atm_phys_to_be_ccppized_dir, "*.F90"))
636637
for to_be_ccppized_file in atm_phys_to_be_ccppized_files:
637638
shutil.copy(to_be_ccppized_file, physics_blddir)
638639
# end for
639-
# end if
640+
641+
# Copy 'phys_utils' modules to the build directory,
642+
# as SIMA's pio_reader module depends on them.
643+
# Note: This requirement will likely disappear once
644+
# the abstract File I/O interface has been moved to the
645+
# CCPP-framework itself.
646+
atm_phys_phys_utils_dir = os.path.join(atm_phys_top_dir, "phys_utils")
647+
648+
# Check that the directory exists
649+
if not os.path.isdir(atm_phys_phys_utils_dir):
650+
# CAM-SIMA will likely not run without this, so raise an error
651+
emsg = "ERROR: Unable to find CCPP physics 'phys_utils' directory:\n"
652+
emsg += f" {atm_phys_phys_utils_dir}\n Have you run 'git-fleximod'?"
653+
raise CamAutoGenError(emsg)
654+
655+
# Copy all 'phys_utils' source files to the build directory
656+
atm_phys_phys_utils_files = glob.glob(os.path.join(atm_phys_phys_utils_dir, "*.F90"))
657+
for util_file in atm_phys_phys_utils_files:
658+
shutil.copy(util_file, physics_blddir)
659+
660+
# end if (do_gen_ccpp)
640661

641662
if do_gen_ccpp or do_gen_nl:
642663
# save build details in the build cache

cime_config/namelist_definition_cam.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22

3-
<entry_id_pg version="0.1">
3+
<entry_id_pg version="2.0">
44

55
<!-- Initial Conditions -->
66

@@ -364,6 +364,23 @@
364364
</values>
365365
</entry>
366366

367+
<!-- Host model chemistry settings -->
368+
369+
<entry id="musica_config">
370+
<type>char*256</type>
371+
<category>chemistry</category>
372+
<group>chemistry_nl</group>
373+
<desc>
374+
Configuration option for the
375+
MUSICA chemistry package.
376+
377+
Default: none
378+
</desc>
379+
<values>
380+
<value>none</value>
381+
</values>
382+
</entry>
383+
367384
<!-- Tropopause -->
368385
<entry id="tropopause_climo_file">
369386
<type>char*256</type>

cime_config/testdefs/testlist_cam.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
<option name="comment">Test for Hack shallow convection scheme</option>
6262
</options>
6363
</test>
64+
<test compset="FPHYStest" grid="ne3pg3_ne3pg3_mg37" name="SMS_Ln2" testmods="cam/outfrq_dme_adjust_derecho">
65+
<machines>
66+
<machine name="derecho" compiler="gnu" category="aux_sima"/>
67+
</machines>
68+
<options>
69+
<option name="wallclock">00:10:00</option>
70+
<option name="comment">Test for dme_adjust scheme</option>
71+
</options>
72+
</test>
6473
<test compset="FPHYStest" grid="ne3pg3_ne3pg3_mg37" name="SMS_Ln2" testmods="cam/outfrq_rk_stratiform_derecho">
6574
<machines>
6675
<machine name="derecho" compiler="gnu" category="aux_sima"/>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites dme_adjust"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ncdata='/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_ne3pg3_dme_adjust_snapshot_derecho_gnu_before_c20250416.nc'
2+
ncdata_check='/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_ne3pg3_dme_adjust_snapshot_derecho_gnu_after_c20250416.nc'
3+
debug_output=0
4+
pver=32
5+
hist_add_inst_fields;h2: Q,PS
6+
hist_output_frequency;h2: nsteps
7+
hist_write_nstep0;h2: .true.

docker/Dockerfile.musica

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,29 @@ RUN /home/cam_sima_user/CAM-SIMA/cime/scripts/create_newcase --case $CASE_NAME \
7777

7878
WORKDIR $CASE_NAME
7979

80-
RUN ./case.setup
81-
80+
RUN ./xmlchange COMPILER=gnu
81+
RUN ./xmlchange DEBUG=true
8282
RUN ./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites musica"
83-
RUN ./xmlchange ROF_NCPL=48
8483
RUN ./xmlchange STOP_OPTION=nsteps
8584
RUN ./xmlchange STOP_N=5
8685

86+
# Match the GLC timestep to atmosphere timestep
87+
RUN ./xmlchange ATM_NCPL=48
88+
RUN ./xmlchange GLC_NCPL=48
89+
90+
# Avoid writing restart files
91+
RUN ./xmlchange REST_N=100
92+
93+
RUN ./case.setup
94+
95+
# Specify the path to the MUSICA configuraiton files by adding the following lines to the `user_nl_cam` file.
96+
# For example, to configure the Chapman mechanisms, include these lines.
97+
# filename_of_micm_configuration=/home/cam_sima_user/case_name/test-case/musica_configurations/chapman/micm/config.json
98+
# filename_of_tuvx_configuration=/home/cam_sima_user/case_name/test-case/musica_configurations/chapman/tuvx/config.json
99+
# filename_of_tuvx_micm_mapping_configuration=/home/cam_sima_user/case_name/test-case/musica_configurations/chapman/tuvx_micm_mapping.json
100+
101+
# You can run the model with the snapshot file by adding this line to the end of 'user_nl_cam' file on Derecho.
102+
# Note that this snapshot contains only ten time slices.
103+
# ncdata=/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_ne3pg3_kessler_snapshot_derecho_gnu_before_c20240412.nc
104+
87105
RUN ./case.build

0 commit comments

Comments
 (0)