Skip to content

Commit 883b99c

Browse files
authored
Update MUSICA library (#393)
Tag name (required for release branches): Originator(s): Matt Dawson Description (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number): Updates to use latest MUSICA library and run Terminator and Chapman configurations. closes #321 Describe any changes made to build system: updated commits for cloning musica library and CMake flags Describe any changes made to the namelist: none List any changes to the defaults for the input datasets (e.g. boundary datasets): none List all files eliminated and why: none List all files added and what they do: none List all existing files that have been modified, and describe the changes: (Helpful git command: `git diff --name-status development...<your_branch_name>`) | File | Description | | --------------------------------------------------- | ------------------------------------------------------------------------- | | src/physics/utils/musica_sima_namelist.F90 | Updated log message text for MUSICA configuration. | | src/physics/utils/musica_ccpp_dependencies.F90 | Renamed some variables and added a function to set initial conditions. | | src/physics/ncar_ccpp | Updated submodule commit pointer. | | src/control/cam_initfiles.F90 | Added check to enforce presence of the initial dataset. | | src/control/cam_comp.F90 | Moved initialization of MUSICA species concentrations to timestep_init to avoid having them be overwritten with zeros. | | cime_config/buildlib | Updated MUSICA linker flags and added a new CMake build flag. | | cime_config/atm_musica_config.py | Updated MUSICA_TAG to the new commit version. | | .gitmodules | Revised ncar-physics submodule URL and commit tag. | If there are new failures (compared to the `test/existing-test-failures.txt` file), have them OK'd by the gatekeeper, note them here, and add them to the file. If there are baseline differences, include the test and the reason for the diff. What is the nature of the change? Roundoff? derecho/intel/aux_sima: all tests pass derecho/gnu/aux_sima: all tests pass If this changes climate describe any run(s) done to evaluate the new climate in enough detail that it(they) could be reproduced: N/A CAM-SIMA date used for the baseline comparison tests if different than latest: N/A
1 parent 7f65ef9 commit 883b99c

File tree

9 files changed

+215
-89
lines changed

9 files changed

+215
-89
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
[submodule "ncar-physics"]
2121
path = src/physics/ncar_ccpp
2222
url = https://github.com/ESCOMP/atmospheric_physics
23-
fxtag = 4a31043bb8bd6179db3b59db4895b0563b78af88
23+
fxtag = 2b66267fe263d9268effeaa1d47e3c03e6121d74
2424
fxrequired = AlwaysRequired
2525
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics
2626
[submodule "rrtmgp-data"]

cime_config/atm_musica_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
MUSICA_CCPP_SCHEME_NAME = "musica_ccpp"
77
MUSICA_CONFIG_DIR_NAME = "musica_configurations"
88
MUSICA_REPO_URL = "https://github.com/NCAR/musica.git"
9-
MUSICA_TAG = "cc39bb00d2220fc81c85b22d3ceea4a39bd2bacf"
9+
MUSICA_TAG = "25fff7ae42d146bf3f83ad5ac18b3caac8701ddd"
1010
CHEMISTRY_DATA_REPO_URL = "https://github.com/NCAR/cam-sima-chemistry-data.git"
1111
CHEMISTRY_DATA_TAG = "71ed143c54b0d5d6e3e70f3d05d413fddcf8d59e"

cime_config/buildlib

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ from CIME.buildlib import parse_input
3232
from CIME.build import get_standard_makefile_args
3333
from CIME.Tools.standard_script_setup import check_minimum_python_version
3434
from CIME.locked_files import lock_file, unlock_file
35+
from CIME.XML.env_build import EnvBuild
3536
#pylint: enable=wrong-import-position
3637

3738
check_minimum_python_version(3, 7) #CAM requires version 3.7 or greater
@@ -180,7 +181,7 @@ def _build_cam():
180181
musica_install_path = _build_musica(caseroot)
181182

182183
cam_linked_libs = case.get_value("CAM_LINKED_LIBS")
183-
musica_libs = "-lmusica-fortran -lmusica -lyaml-cpp"
184+
musica_libs = _get_musica_libs(caseroot)
184185
if not musica_libs in cam_linked_libs:
185186
_set_musica_lib_path(musica_install_path, caseroot)
186187

@@ -249,6 +250,60 @@ def _copy2_as_needed(src: str, dst: str) -> None:
249250
# Example scenario: User added some new source code files.
250251
shutil.copy2(src, dst)
251252

253+
###############################################################################
254+
def _cmake_default_args(caseroot):
255+
###############################################################################
256+
# Returns a dictionary of CMake variables based on the Macros.cmake file for
257+
# the build.
258+
259+
build = EnvBuild(case_root=caseroot)
260+
with Case(caseroot) as case:
261+
macro_path = os.path.abspath(os.path.join(caseroot, "cmake_macros", ""))
262+
args = "-DCONVERT_TO_MAKE=ON "
263+
args += f"-DCASEROOT={caseroot} "
264+
args += f"-DCOMPILER={build.get_value('COMPILER')} "
265+
args += f"-DOS={build.get_value('OS')} "
266+
args += f"-DMACH={case.get_value('MACH')} "
267+
args += "-DCMAKE_C_COMPILER_WORKS=1 "
268+
args += "-DCMAKE_Fortran_COMPILER_WORKS=1 "
269+
args += "-DCMAKE_CXX_COMPILER_WORKS=1 "
270+
args += f"-DDEBUG={build.get_value('DEBUG')} "
271+
cmd = f"cmake {args} ."
272+
rc, out, err = run_cmd(cmd, combine_output=True, from_dir=macro_path)
273+
expect(rc == 0, "Command {} failed with rc={} out={} err={}".format(cmd, rc, out, err))
274+
275+
arg_dict = {}
276+
for line in out.splitlines():
277+
if ":=" in line:
278+
key, val = line.split(":=")
279+
arg_dict[key.replace('CIME_SET_MAKEFILE_VAR','').strip()] = val.strip()
280+
281+
return arg_dict
282+
283+
###############################################################################
284+
def _get_musica_libs(caseroot: str) -> str:
285+
###############################################################################
286+
"""
287+
Returns the MUSICA libraries to be linked to CAM.
288+
289+
Args:
290+
caseroot: CASEROOT where the xmlchange command is located
291+
292+
Raises:
293+
Exception: If the subprocess for the xmlquery command fails,
294+
an exception is raised with the error message.
295+
296+
Returns:
297+
musica_libs: MUSICA libraries to be linked to CAM
298+
"""
299+
build = EnvBuild(case_root=caseroot)
300+
if build.get_value("DEBUG"):
301+
musica_libs = "-lmusica-fortran -lmusica -lmechanism_configuration -lyaml-cppd -lstdc++"
302+
else:
303+
musica_libs = "-lmusica-fortran -lmusica -lmechanism_configuration -lyaml-cpp -lstdc++"
304+
305+
return musica_libs
306+
252307
###############################################################################
253308
def _build_musica(clone_dest: str) -> str:
254309
###############################################################################
@@ -266,19 +321,29 @@ def _build_musica(clone_dest: str) -> str:
266321
musica_install_path: path to the MUSICA installation directory
267322
"""
268323
_clone_and_checkout(MUSICA_REPO_URL, MUSICA_TAG, clone_dest)
324+
build = EnvBuild(case_root=clone_dest)
325+
arg_dict = _cmake_default_args(clone_dest)
269326

270327
bld_path = os.path.join(clone_dest, "musica", "build")
271328
if os.path.exists(bld_path):
272329
shutil.rmtree(bld_path)
273330
os.makedirs(bld_path)
274-
275331
install_dir = "install"
332+
333+
with Case(clone_dest) as case:
334+
if build.get_value("DEBUG"):
335+
cmake_build_type = "Debug"
336+
else:
337+
cmake_build_type = "Release"
338+
276339
command = [
277340
"cmake",
278341
f"-D CMAKE_INSTALL_PREFIX={install_dir}",
279-
"-D CMAKE_BUILD_TYPE=Release",
342+
f"-D CMAKE_BUILD_TYPE={cmake_build_type}",
343+
f"-D CMAKE_Fotran_FLAGS={arg_dict['FFLAGS']}",
280344
"-D MUSICA_ENABLE_TESTS=OFF",
281345
"-D MUSICA_BUILD_FORTRAN_INTERFACE=ON",
346+
"-D MUSICA_SET_MICM_DEFAULT_VECTOR_SIZE=128",
282347
".."
283348
]
284349
try:
@@ -365,14 +430,14 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
365430
an exception is raised with the error message.
366431
"""
367432

368-
unlock_file("env_build.xml", caseroot)
433+
musica_libs = _get_musica_libs(caseroot)
369434

370435
command = [
371436
"./xmlchange",
372437
"--append",
373438
# The libraries must be on the same line because CIME flags an
374439
# error for multi-character arguments preceded by a single dash
375-
f"CAM_LINKED_LIBS=-L{os.path.join(musica_install_path, 'lib64')} -lmusica-fortran -lmusica -lyaml-cpp"
440+
f"CAM_LINKED_LIBS=-L{os.path.join(musica_install_path, 'lib64')} {musica_libs}"
376441
]
377442
try:
378443
subprocess.run(command, cwd=caseroot, stdout=subprocess.PIPE,
@@ -385,8 +450,6 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
385450
except OSError as e:
386451
raise OSError("An error occurred while executing the 'xmlchange' command.") from e
387452

388-
lock_file("env_build.xml", caseroot)
389-
390453
###############################################################################
391454
def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
392455
###############################################################################

src/control/cam_comp.F90

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
8686

8787
use cam_initfiles, only: cam_initfiles_open
8888
use dyn_grid, only: model_grid_init
89-
use phys_comp, only: phys_init
89+
use phys_comp, only: phys_init, phys_suite_name
9090
use phys_comp, only: phys_register
9191
use dyn_comp, only: dyn_init
9292
! use cam_restart, only: cam_read_restart
@@ -100,7 +100,6 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
100100
use air_composition, only: air_composition_init
101101
use cam_ccpp_cap, only: cam_ccpp_initialize_constituents
102102
use cam_ccpp_cap, only: cam_model_const_properties
103-
use cam_ccpp_cap, only: cam_constituents_array
104103
use physics_grid, only: columns_on_task
105104
use vert_coord, only: pver
106105
use phys_vars_init_check, only: mark_as_initialized
@@ -156,7 +155,6 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
156155
character(len=cx) :: errmsg
157156

158157
type(ccpp_constituent_prop_ptr_t), pointer :: constituent_properties(:)
159-
real(kind_phys), pointer :: constituents_array(:,:,:)
160158
!-----------------------------------------------------------------------
161159

162160
call init_pio_subsystem()
@@ -255,17 +253,14 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
255253
! Read tropopause climatology
256254
call tropopause_climo_read_file()
257255

258-
! Temporary: Prescribe realistic but inaccurate physical quantities
256+
! TEMPORARY: Prescribe realistic but inaccurate physical quantities
259257
! necessary for MUSICA that are currently unavailable in CAM-SIMA.
260-
! It also initializes the MUSICA constituent values until the file
261-
! I/O object is implemented.
262258
!
263259
! Remove this when MUSICA input data are available from CAM-SIMA or
264260
! other physics schemes.
265261
constituent_properties => cam_model_const_properties()
266-
constituents_array => cam_constituents_array()
267262
call musica_ccpp_dependencies_init(columns_on_task, pver, &
268-
constituent_properties, constituents_array)
263+
constituent_properties, phys_suite_name)
269264

270265
! Initialize orbital data
271266
call orbital_data_init(columns_on_task)
@@ -295,10 +290,15 @@ subroutine cam_timestep_init()
295290
!
296291
!-----------------------------------------------------------------------
297292

298-
use phys_comp, only: phys_timestep_init
299-
use physics_grid, only: lat_rad, lon_rad
300-
use orbital_data, only: orbital_data_advance
301-
use stepon, only: stepon_timestep_init
293+
use phys_comp, only: phys_timestep_init
294+
use physics_grid, only: lat_rad, lon_rad
295+
use orbital_data, only: orbital_data_advance
296+
use stepon, only: stepon_timestep_init
297+
use cam_ccpp_cap, only: cam_constituents_array
298+
use ccpp_kinds, only: kind_phys
299+
use musica_ccpp_dependencies, only: set_initial_musica_concentrations
300+
301+
real(kind_phys), pointer :: constituents_array(:,:,:)
302302

303303
! Update current fractional calendar day. Needs to be updated at every timestep.
304304
calday = get_curr_calday()
@@ -319,6 +319,21 @@ subroutine cam_timestep_init()
319319
call stepon_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_tend, &
320320
dyn_in, dyn_out)
321321
call t_stopf('stepon_timestep_init')
322+
323+
!----------------------------------------------------------
324+
! TEMPORARY: Set initial MUSICA constituent values
325+
!
326+
! This is a temporary workaround to initialize
327+
! MUSICA constituent values until the file I/O
328+
! capability is implemented.
329+
! Remove this when MUSICA species are initialized
330+
! by CAM-SIMA.
331+
!----------------------------------------------------------
332+
if (is_first_timestep) then
333+
constituents_array => cam_constituents_array()
334+
call set_initial_musica_concentrations(constituents_array)
335+
end if
336+
322337
!
323338
!----------------------------------------------------------
324339
! PHYS_TIMESTEP_INIT Call the Physics package

src/control/cam_initfiles.F90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ subroutine cam_initfiles_open()
224224
! Open initial dataset
225225

226226
if (initial_run) then
227+
if (trim(ncdata) == 'ncdata' .or. trim(ncdata) == trim(unset_path_str)) then
228+
call endrun(subname//': ERROR: Missing initial dataset. '// &
229+
'Please set "ncdata" in the CAM namelist')
230+
end if
227231
call cam_get_file(ncdata, ncdata_loc)
228232
allocate(fh_ini, stat=iret)
229233
if (iret /= 0) then

src/data/air_composition.F90

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ subroutine air_composition_init()
179179

180180
liq_num = 0
181181
ice_num = 0
182-
has_liq = .false.
183-
has_ice = .false.
184182
ix = -1
185183
! standard dry air (constant composition)
186184
o2_mwi = 1._kind_phys / 32._kind_phys
@@ -239,9 +237,10 @@ subroutine air_composition_init()
239237
icnst = 1
240238
water_species_num = 0
241239
dry_species_num = 0
242-
has_ice = .false.
243240
do idx = 1, num_advected
244241
cnst_stdname = const_name(idx)
242+
has_liq = .false.
243+
has_ice = .false.
245244
select case (TRIM((cnst_stdname)))
246245
!
247246
! O
@@ -437,6 +436,8 @@ subroutine air_composition_init()
437436
!
438437
! If support for more major species is to be included add code here
439438
!
439+
case default
440+
cycle ! skip thermodynamically inactive species
440441
end select
441442

442443
if (masterproc) then
@@ -460,8 +461,6 @@ subroutine air_composition_init()
460461
end if
461462
write(iulog, *) " "
462463
end if
463-
has_liq = .false.
464-
has_ice = .false.
465464
end do
466465

467466
!Set dry air thermodynamic properities if no dry air species provided:
@@ -565,12 +564,14 @@ subroutine water_composition_update(mmr, ncol, energy_formula, cp_or_cv_dycore,
565564
! SE
566565
! Note: species index subset to 1: because SIMA currently uses index 0. See GitHub issue #334 in ESCOMP/CAM-SIMA.
567566
call get_cp(mmr(:ncol,:,:), .false., cp_or_cv_dycore(:ncol,:), &
568-
factor=to_dry_factor, active_species_idx_dycore=thermodynamic_active_species_idx(1:), &
567+
factor=to_dry_factor, &
568+
active_species_idx_dycore=thermodynamic_active_species_idx(1:thermodynamic_active_species_num), &
569569
cpdry=cpairv(:ncol,:))
570570
else if (energy_formula == ENERGY_FORMULA_DYCORE_MPAS) then
571571
! MPAS
572572
! Note: species index subset to 1: because SIMA currently uses index 0. See GitHub issue #334 in ESCOMP/CAM-SIMA.
573-
call get_R(mmr(:ncol,:,:), thermodynamic_active_species_idx(1:), &
573+
call get_R(mmr(:ncol,:,:), &
574+
thermodynamic_active_species_idx(1:thermodynamic_active_species_num), &
574575
cp_or_cv_dycore(:ncol,:), fact=to_dry_factor, Rdry=rairv(:ncol,:))
575576

576577
! internal energy coefficient for MPAS

0 commit comments

Comments
 (0)