Skip to content

Commit 1281928

Browse files
authoredOct 18, 2024··
New const_get_index logic without cam_ccpp_cap dependency (in atmos_phys) (#314)
Companion atmospheric_physics PR: ESCOMP/atmospheric_physics#135 This avoids a circular dependency if schemes require const_get_index, which presently depends on cam_ccpp_cap, which depends on individual schemes.
2 parents 112cc2b + f96675a commit 1281928

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed
 

‎.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[submodule "ncar-physics"]
1515
path = src/physics/ncar_ccpp
1616
url = https://github.com/ESCOMP/atmospheric_physics
17-
fxtag = atmos_phys0_05_001
17+
fxtag = 67bb908e
1818
fxrequired = AlwaysRequired
1919
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics
2020
[submodule "ccs_config"]

‎cime_config/cam_autogen.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ def generate_physics_suites(build_cache, preproc_defs, host_name,
600600

601601
# Check that directory exists
602602
if not os.path.isdir(atm_phys_util_dir):
603-
#CAM-SIMA will likely not run without this, so raise an error
603+
# CAM-SIMA will likely not run without this, so raise an error
604604
emsg = "ERROR: Unable to find CCPP physics utilities directory:\n"
605-
emsg += f" {atm_phys_util_dir}\n Have you run 'checkout_externals'?"
605+
emsg += f" {atm_phys_util_dir}\n Have you run 'git-fleximod'?"
606606
raise CamAutoGenError(emsg)
607607
# end if
608608

@@ -611,6 +611,25 @@ def generate_physics_suites(build_cache, preproc_defs, host_name,
611611
for util_file in atm_phys_util_files:
612612
shutil.copy(util_file, physics_blddir)
613613
# end for
614+
615+
# Copy to_be_ccppized utility modules to the build directory,
616+
# as SIMA cam_constituents depends on them.
617+
# Note: to_be_ccppized utility modules to be removed once functionality is migrated
618+
# to SIMA or CCPPized in atmospheric_physics.
619+
atm_phys_to_be_ccppized_dir = os.path.join(atm_phys_top_dir, "to_be_ccppized")
620+
621+
# Check that the directory exists
622+
if not os.path.isdir(atm_phys_to_be_ccppized_dir):
623+
# CAM-SIMA will likely not run without this, so raise an error
624+
emsg = "ERROR: Unable to find CCPP physics to_be_ccppized directory:\n"
625+
emsg += f" {atm_phys_to_be_ccppized_dir}\n Have you run 'git-fleximod'?"
626+
raise CamAutoGenError(emsg)
627+
# end if
628+
629+
atm_phys_to_be_ccppized_files = glob.glob(os.path.join(atm_phys_to_be_ccppized_dir, "*.F90"))
630+
for to_be_ccppized_file in atm_phys_to_be_ccppized_files:
631+
shutil.copy(to_be_ccppized_file, physics_blddir)
632+
# end for
614633
# end if
615634

616635
if do_gen_ccpp or do_gen_nl:

‎src/physics/utils/cam_constituents.F90

+18-10
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,14 @@ end function const_molec_weight
285285
!#######################################################################
286286

287287
subroutine const_get_index(name, cindex, abort, warning, caller)
288-
use shr_kind_mod, only: CX => SHR_KIND_CX
289-
use cam_abortutils, only: endrun
290-
use cam_logfile, only: iulog
291-
use cam_ccpp_cap, only: cam_const_get_index
288+
! from to_be_ccppized utility routine
289+
use ccpp_const_utils, only: ccpp_const_get_idx
290+
291+
use shr_kind_mod, only: CX => SHR_KIND_CX
292+
use cam_abortutils, only: endrun
293+
use cam_logfile, only: iulog
294+
use phys_vars_init_check, only: std_name_len
295+
use string_utils, only: stringify
292296

293297
! Get the index of a constituent with standard name, <name>.
294298
! Setting optional <abort> argument to .false. returns control to
@@ -298,11 +302,11 @@ subroutine const_get_index(name, cindex, abort, warning, caller)
298302
! instead of <subname> in messages.
299303

300304
!-----------------------------Arguments---------------------------------
301-
character(len=*), intent(in) :: name ! constituent name
302-
integer, intent(out) :: cindex ! global constituent ind
303-
logical, optional, intent(in) :: abort ! flag controlling abort
305+
character(len=*), intent(in) :: name ! constituent name
306+
integer, intent(out) :: cindex ! global constituent index
307+
logical, optional, intent(in) :: abort ! flag controlling abort
304308
logical, optional, intent(in) :: warning ! flag controlling warning
305-
character(len=*), optional, intent(in) :: caller ! calling routine
309+
character(len=*), optional, intent(in) :: caller ! calling routine
306310

307311
!---------------------------Local workspace-----------------------------
308312
logical :: warning_on_error
@@ -312,10 +316,14 @@ subroutine const_get_index(name, cindex, abort, warning, caller)
312316
character(len=*), parameter :: subname = 'const_get_index: '
313317
!-----------------------------------------------------------------------
314318

315-
! Find tracer name in the master table
316-
call cam_const_get_index(name, cindex, errcode=errcode, errmsg=errmsg)
319+
call ccpp_const_get_idx(const_props, name, cindex, errmsg, errcode)
317320

318321
if (errcode /= 0) then
322+
call endrun(subname//"Error "//stringify((/errcode/))//": "// &
323+
trim(errmsg), file=__FILE__, line=__LINE__)
324+
endif
325+
326+
if (cindex == -1) then
319327
! Unrecognized name, set an error return and possibly abort
320328
cindex = -1
321329
if (present(abort)) then

0 commit comments

Comments
 (0)
Please sign in to comment.