Skip to content

Commit ea16d8a

Browse files
nusbaumemwaxmonsky
andauthored
Initial physics file reader for CAM-SIMA (#385)
Tag name (required for release branches): Originator(s): @mwaxmonsky @nusbaume Description (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number): This PR contains the CAM-SIMA subroutines and interfaces required for implementing the file I/O reader object in PR ESCOMP/atmospheric_physics#240 in a CAM-SIMA simulation. Currently CAM-SIMA uses the Parallel I/O (PIO) system to read NetCDF files whenever a user calls the FileIO object, and so that is what is used for this initial implementation, but if different methods are required in the future we can hopefully implement them in a similar but independent fashion. This PR also adds a new MUSICA namelist variable to fix a bug that prevented the model from building whenever the MUSICA CCPP scheme wasn't being used. Describe any changes made to build system: N/A Describe any changes made to the namelist: N/A List any changes to the defaults for the input datasets (e.g. boundary datasets): N/A List all files eliminated and why: N/A List all files added and what they do: A src/physics/utils/pio_reader.F90 A src/physics/utils/pio_reader_sub.F90 - SIMA's NetCDF file reader object implementation using PIO. A src/physics/utils/rrtmgp-data - RRTMGP data files. Mostly used for testing now, but will be needed for RRTMGP itself once the time comes (otherwise it can simply be removed). A src/physics/utils/musica_sima_namelist.F90 - Implement new CAM-SIMA 'musica_config' namelist variable in a separate, non-CCPPized module. List all existing files that have been modified, and describe the changes: (Helpful git command: `git diff --name-status development...<your_branch_name>`) M .gitmodules M src/physics/ncar_ccpp - Updated atmospheric_physics submodule M cime_config/cam_autogen.py - Make sure the 'phys_utils' directory is always available during a build. M cime_config/namelist_definition_cam.xml M src/control/runtime_opts.F90 M src/physics/utils/musica_ccpp_dependencies.F90 - Implement the 'musica_config' SIMA namelist option to control MUSICA dependencies settings. M src/utils/string_utils.F90 - Make 'to_lower' and 'to_upper' functions public. 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: derecho/gnu/aux_sima: If this changes climate describe any run(s) done to evaluate the new climate in enough detail that it(they) could be reproduced: CAM-SIMA date used for the baseline comparison tests if different than latest: --------- Co-authored-by: Michael Waxmonsky <mwaxmonsky@ucar.edu>
1 parent 7b89ac1 commit ea16d8a

File tree

11 files changed

+1002
-28
lines changed

11 files changed

+1002
-28
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 = ac83803062a5d38b92e416e1cf737d3811e20cd1
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/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>

src/control/runtime_opts.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ subroutine read_namelist(nlfilename, single_column, scmlat, scmlon)
4545
use inic_analytic_utils, only: analytic_ic_readnl
4646

4747
use tropopause_climo_read, only: tropopause_climo_readnl
48+
use musica_sima_namelist, only: musica_ccpp_dependencies_readnl
4849

4950
! use tracers, only: tracers_readnl
5051
! use nudging, only: nudging_readnl
@@ -102,6 +103,7 @@ subroutine read_namelist(nlfilename, single_column, scmlat, scmlon)
102103
! call check_energy_readnl(nlfilename)
103104
call analytic_ic_readnl(nlfilename)
104105
call tropopause_climo_readnl(nlfilename)
106+
call musica_ccpp_dependencies_readnl(nlfilename)
105107
! call scam_readnl(nlfilename, single_column, scmlat, scmlon)
106108
! call nudging_readnl(nlfilename)
107109

src/physics/utils/musica_ccpp_dependencies.F90

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module musica_ccpp_dependencies
1313
!
1414
!--------------------------------------------------------------------------
1515

16-
use ccpp_kinds, only: kind_phys
16+
use ccpp_kinds, only: kind_phys
1717

1818
implicit none
1919
private
@@ -76,7 +76,7 @@ subroutine initialize_musica_species_constituents(constituents_properties, &
7676
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
7777
use ccpp_const_utils, only: ccpp_const_get_idx
7878
use cam_logfile, only: iulog
79-
use musica_ccpp_namelist, only: filename_of_micm_configuration
79+
use musica_sima_namelist, only: musica_config_str
8080

8181
type(ccpp_constituent_prop_ptr_t), pointer :: constituents_properties(:)
8282
real(kind_phys), pointer :: constituents_array(:,:,:)
@@ -105,20 +105,16 @@ subroutine initialize_musica_species_constituents(constituents_properties, &
105105
! Currently, we only support two types of MUSICA configurations: Chapman and Terminator,
106106
! until the file I/O object is implemented. If the configuration is neither of these,
107107
! an error will be thrown.
108-
position = index(filename_of_micm_configuration, chapman_config) ! Check if the substring exists
109-
if (position > 0) then
108+
if (trim(musica_config_str) == "chapman") then
110109
is_chapman = .true.
111110
write(iulog,*) "[MUSICA Info] Using the Chapman configuriation."
111+
else if (trim(musica_config_str) == "terminator") then
112+
is_terminator = .true.
113+
write(iulog,*) "[MUSICA Info] Using the Terminator configuriation."
112114
else
113-
position = index(filename_of_micm_configuration, terminator_config)
114-
if (position > 0) then
115-
is_terminator = .true.
116-
write(iulog,*) "[MUSICA Info] Using the Terminator configuriation."
117-
else
118-
errcode = 1
119-
errmsg = "[MUSICA Error] MUSICA configuration is not found."
120-
return
121-
end if
115+
errcode = 1
116+
errmsg = "[MUSICA Error] MUSICA configuration is not found."
117+
return
122118
end if
123119

124120
if (is_chapman) then
@@ -136,7 +132,7 @@ subroutine initialize_musica_species_constituents(constituents_properties, &
136132
species_group(1) = species_constructor(&
137133
"cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water", 0.00060_kind_phys)
138134

139-
if (is_chapman) then
135+
if (is_chapman) then
140136
species_group(2) = species_constructor("O2", 0.22474_kind_phys)
141137
species_group(3) = species_constructor("O", 5.3509e-10_kind_phys)
142138
species_group(4) = species_constructor("O1D", 5.3509e-10_kind_phys)
@@ -174,6 +170,7 @@ subroutine musica_ccpp_dependencies_init( &
174170
use cam_abortutils, only: check_allocate, endrun
175171
use cam_logfile, only: iulog
176172
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
173+
use musica_sima_namelist, only: musica_config_str
177174

178175
!-----------------------------------------------------------------------
179176
!
@@ -192,6 +189,9 @@ subroutine musica_ccpp_dependencies_init( &
192189
character(len=512) :: errmsg
193190
integer :: errcode
194191

192+
! Check if a MUSICA configuration is being used. If not then just exit.
193+
if (trim(musica_config_str) == "none") return
194+
195195
write(iulog,*) 'WARNING: Using placeholder data for MUSICA chemistry.'
196196

197197
call initialize_musica_species_constituents(constituents_properties, &
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
! Copyright (C) 2024-2025 University Corporation for Atmospheric Research
2+
! SPDX-License-Identifier: Apache-2.0
3+
module musica_sima_namelist
4+
!--------------------------------------------------------------------------
5+
!
6+
! This module provides namelist functionality for the "musica_ccpp_dependencies.F90"
7+
! file, which can't easily contain namelist read functionality directly due to CCPP
8+
! requirements.
9+
!
10+
! IMPORTANT: This module should be removed once "musica_ccpp_dependencies.F90",
11+
! which is a temporary file, has also been removed.
12+
!
13+
!--------------------------------------------------------------------------
14+
15+
use shr_kind_mod, only: shr_kind_cl
16+
use runtime_obj, only: unset_str
17+
18+
implicit none
19+
private
20+
21+
! public routines
22+
public :: musica_ccpp_dependencies_readnl
23+
24+
! public variables
25+
character(len=shr_kind_cl), public :: musica_config_str = unset_str
26+
27+
!==============================================================================
28+
contains
29+
!==============================================================================
30+
31+
subroutine musica_ccpp_dependencies_readnl(nlfile)
32+
33+
use shr_nl_mod, only: find_group_name => shr_nl_find_group_name
34+
use shr_kind_mod, only: shr_kind_cm
35+
use mpi, only: mpi_character
36+
use spmd_utils, only: mpicom
37+
use cam_logfile, only: iulog
38+
use cam_abortutils, only: endrun
39+
use spmd_utils, only: masterproc
40+
use string_utils, only: to_lower
41+
42+
!-----------------------------------------------------------------------
43+
!
44+
! Read CAM-SIMA's MUSICA dependencies namelist
45+
!
46+
!-----------------------------------------------------------------------
47+
48+
! filepath for file containing namelist input
49+
character(len=*), intent(in) :: nlfile
50+
51+
! Local variables
52+
integer :: unitn, ierr
53+
character(len=*), parameter :: subname = 'musica_ccpp_dependencies_readnl'
54+
character(len=shr_kind_cm) :: errmsg
55+
character(len=shr_kind_cl) :: musica_config
56+
57+
namelist /chemistry_nl/ musica_config
58+
59+
errmsg = ''
60+
61+
if (masterproc) then
62+
open(newunit=unitn, file=trim(nlfile), status='old')
63+
call find_group_name(unitn, 'chemistry_nl', status=ierr)
64+
if (ierr == 0) then
65+
read(unitn, chemistry_nl, iostat=ierr, iomsg=errmsg)
66+
if (ierr /= 0) then
67+
call endrun(subname // ':: ERROR reading namelist:' // errmsg)
68+
end if
69+
end if
70+
close(unitn)
71+
end if
72+
73+
! Broadcast namelist variable
74+
call mpi_bcast(musica_config, len(musica_config), mpi_character, 0, mpicom, ierr)
75+
76+
! Set module variable with lower case namelist-provided string
77+
musica_config_str = to_lower(musica_config)
78+
79+
! Print out namelist variables
80+
if (masterproc) then
81+
write(iulog,*) subname, ' options:'
82+
write(iulog,*) ' MUSICA Configuration option: ', trim(musica_config_str)
83+
endif
84+
85+
end subroutine musica_ccpp_dependencies_readnl
86+
87+
end module musica_sima_namelist

0 commit comments

Comments
 (0)