Skip to content

Commit

Permalink
New const_get_index logic without cam_ccpp_cap dependency (in atmos_p…
Browse files Browse the repository at this point in the history
…hys) (ESCOMP#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.
  • Loading branch information
jimmielin authored Oct 18, 2024
2 parents 112cc2b + f96675a commit 1281928
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[submodule "ncar-physics"]
path = src/physics/ncar_ccpp
url = https://github.com/ESCOMP/atmospheric_physics
fxtag = atmos_phys0_05_001
fxtag = 67bb908e
fxrequired = AlwaysRequired
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics
[submodule "ccs_config"]
Expand Down
23 changes: 21 additions & 2 deletions cime_config/cam_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ def generate_physics_suites(build_cache, preproc_defs, host_name,

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

Expand All @@ -611,6 +611,25 @@ def generate_physics_suites(build_cache, preproc_defs, host_name,
for util_file in atm_phys_util_files:
shutil.copy(util_file, physics_blddir)
# end for

# Copy to_be_ccppized utility modules to the build directory,
# as SIMA cam_constituents depends on them.
# Note: to_be_ccppized utility modules to be removed once functionality is migrated
# to SIMA or CCPPized in atmospheric_physics.
atm_phys_to_be_ccppized_dir = os.path.join(atm_phys_top_dir, "to_be_ccppized")

# Check that the directory exists
if not os.path.isdir(atm_phys_to_be_ccppized_dir):
# CAM-SIMA will likely not run without this, so raise an error
emsg = "ERROR: Unable to find CCPP physics to_be_ccppized directory:\n"
emsg += f" {atm_phys_to_be_ccppized_dir}\n Have you run 'git-fleximod'?"
raise CamAutoGenError(emsg)
# end if

atm_phys_to_be_ccppized_files = glob.glob(os.path.join(atm_phys_to_be_ccppized_dir, "*.F90"))
for to_be_ccppized_file in atm_phys_to_be_ccppized_files:
shutil.copy(to_be_ccppized_file, physics_blddir)
# end for
# end if

if do_gen_ccpp or do_gen_nl:
Expand Down
2 changes: 1 addition & 1 deletion src/physics/ncar_ccpp
28 changes: 18 additions & 10 deletions src/physics/utils/cam_constituents.F90
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,14 @@ end function const_molec_weight
!#######################################################################

subroutine const_get_index(name, cindex, abort, warning, caller)
use shr_kind_mod, only: CX => SHR_KIND_CX
use cam_abortutils, only: endrun
use cam_logfile, only: iulog
use cam_ccpp_cap, only: cam_const_get_index
! from to_be_ccppized utility routine
use ccpp_const_utils, only: ccpp_const_get_idx

use shr_kind_mod, only: CX => SHR_KIND_CX
use cam_abortutils, only: endrun
use cam_logfile, only: iulog
use phys_vars_init_check, only: std_name_len
use string_utils, only: stringify

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

!-----------------------------Arguments---------------------------------
character(len=*), intent(in) :: name ! constituent name
integer, intent(out) :: cindex ! global constituent ind
logical, optional, intent(in) :: abort ! flag controlling abort
character(len=*), intent(in) :: name ! constituent name
integer, intent(out) :: cindex ! global constituent index
logical, optional, intent(in) :: abort ! flag controlling abort
logical, optional, intent(in) :: warning ! flag controlling warning
character(len=*), optional, intent(in) :: caller ! calling routine
character(len=*), optional, intent(in) :: caller ! calling routine

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

! Find tracer name in the master table
call cam_const_get_index(name, cindex, errcode=errcode, errmsg=errmsg)
call ccpp_const_get_idx(const_props, name, cindex, errmsg, errcode)

if (errcode /= 0) then
call endrun(subname//"Error "//stringify((/errcode/))//": "// &
trim(errmsg), file=__FILE__, line=__LINE__)
endif

if (cindex == -1) then
! Unrecognized name, set an error return and possibly abort
cindex = -1
if (present(abort)) then
Expand Down

0 comments on commit 1281928

Please sign in to comment.