Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/development' into cam_sima_tes…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
cacraigucar committed Apr 24, 2024
2 parents e81d573 + a026181 commit 1c994e6
Show file tree
Hide file tree
Showing 62 changed files with 1,964 additions and 508 deletions.
9 changes: 4 additions & 5 deletions cime_config/cam_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ def _update_genccpp_dir(utility_files, genccpp_dir):

###############################################################################
def generate_registry(data_search, build_cache, atm_root, bldroot,
source_mods_dir, dycore, gen_fort_indent,
reg_config=None):
source_mods_dir, dycore, gen_fort_indent):
###############################################################################
"""
Generate the CAM data source and metadata from the registry,
Expand All @@ -382,14 +381,14 @@ def generate_registry(data_search, build_cache, atm_root, bldroot,
if os.path.exists(genreg_dir):
do_gen_registry = build_cache.registry_mismatch(gen_reg_file,
registry_files,
dycore, reg_config)
dycore)
else:
os.makedirs(genreg_dir)
do_gen_registry = True
# End if
if do_gen_registry:
for reg_file in registry_files:
retvals = gen_registry(reg_file, dycore, reg_config, genreg_dir,
retvals = gen_registry(reg_file, dycore, genreg_dir,
gen_fort_indent, source_mods_dir, atm_root,
logger=_LOGGER, schema_paths=data_search,
error_on_no_validate=True)
Expand All @@ -407,7 +406,7 @@ def generate_registry(data_search, build_cache, atm_root, bldroot,
# Save build details in the build cache
reg_file_paths = [x.file_path for x in reg_file_list if x.file_path]
build_cache.update_registry(gen_reg_file, registry_files, dycore,
reg_config, reg_file_paths, ic_names)
reg_file_paths, ic_names)
else:
# If we did not run the registry generator, retrieve info from cache
reg_file_paths = build_cache.reg_file_list()
Expand Down
19 changes: 6 additions & 13 deletions cime_config/cam_build_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def __init__(self, build_cache):
self.__gen_init_file = None
self.__registry_files = {}
self.__dycore = None
self.__config = None
self.__sdfs = {}
self.__schemes = {}
self.__host_files = {}
Expand Down Expand Up @@ -244,8 +243,6 @@ def __init__(self, build_cache):
self.__registry_files[new_entry.key] = new_entry
elif item.tag == 'dycore':
self.__dycore = item.text
elif item.tag == 'config':
self.__config = item.text
elif item.tag == 'reg_gen_file':
self.__reg_gen_files.append(clean_xml_text(item))
elif item.tag == 'ic_name_entry':
Expand Down Expand Up @@ -316,11 +313,10 @@ def __init__(self, build_cache):
# end if

def update_registry(self, gen_reg_file, registry_source_files,
dycore, config, reg_file_list, ic_names):
dycore, reg_file_list, ic_names):
"""Replace the registry cache data with input data
"""
self.__dycore = dycore
self.__config = config
self.__gen_reg_file = FileStatus(gen_reg_file, 'generate_registry_file')
self.__registry_files = {}
for rfile in registry_source_files:
Expand Down Expand Up @@ -393,8 +389,6 @@ def write(self):
# end for
dycore = ET.SubElement(registry, 'dycore')
dycore.text = self.__dycore
config = ET.SubElement(registry, 'config')
config.text = self.__config
for rgen_file in self.__reg_gen_files:
rgen_entry = ET.SubElement(registry, 'reg_gen_file')
rgen_entry.text = rgen_file
Expand Down Expand Up @@ -450,14 +444,13 @@ def write(self):
#End with

def registry_mismatch(self, gen_reg_file, registry_source_files,
dycore, config):
dycore):
"""
Determine if the registry input data differs from the data
stored in our cache. Return True if the data differs.
"""
mismatch = False
mismatch = (not self.__dycore) or (self.__dycore != dycore)
mismatch = mismatch or (self.__config != config)
if not mismatch:
mismatch = self.__gen_reg_file.hash_mismatch(gen_reg_file)
# end if
Expand All @@ -467,7 +460,7 @@ def registry_mismatch(self, gen_reg_file, registry_source_files,
my_reg_keys = set(self.__registry_files.keys())
test_reg_keys = {FileStatus.gen_key(x)
for x in registry_source_files}
mismatch = (my_reg_keys != test_reg_keys)
mismatch = my_reg_keys != test_reg_keys
for ref_file in registry_source_files:
if mismatch:
break
Expand Down Expand Up @@ -522,7 +515,7 @@ def ccpp_mismatch(self, sdfs, scheme_files, host_files,
if not mismatch:
my_scheme_keys = set(self.__schemes.keys())
test_scheme_keys = {FileStatus.gen_key(x) for x in scheme_files}
mismatch = (my_scheme_keys != test_scheme_keys)
mismatch = my_scheme_keys != test_scheme_keys
for ref_file in scheme_files:
if mismatch:
break
Expand All @@ -537,7 +530,7 @@ def ccpp_mismatch(self, sdfs, scheme_files, host_files,
if not mismatch:
my_host_keys = set(self.__host_files.keys())
test_host_keys = {FileStatus.gen_key(x) for x in host_files}
mismatch = (my_host_keys != test_host_keys)
mismatch = my_host_keys != test_host_keys
for ref_file in host_files:
if mismatch:
break
Expand All @@ -564,7 +557,7 @@ def xml_nl_mismatch(self, create_nl_file, xml_files):
# Note that this method will ignore duplicated files.
my_xml_keys = set(self.__xml_files.keys())
test_xml_keys = {FileStatus.gen_key(x) for x in xml_files.values()}
mismatch = (my_xml_keys != test_xml_keys)
mismatch = my_xml_keys != test_xml_keys
for ref_file in xml_files.values():
if mismatch:
break
Expand Down
72 changes: 58 additions & 14 deletions src/control/cam_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module cam_comp

use camsrfexch, only: cam_out_t, cam_in_t
use physics_types, only: phys_state, phys_tend
use physics_types, only: dtime_phys
use dyn_comp, only: dyn_import_t, dyn_export_t

use perf_mod, only: t_barrierf, t_startf, t_stopf
Expand All @@ -36,18 +37,18 @@ module cam_comp
implicit none
private

public cam_init ! First phase of CAM initialization
public cam_run1 ! CAM run method phase 1
public cam_run2 ! CAM run method phase 2
public cam_run3 ! CAM run method phase 3
public cam_run4 ! CAM run method phase 4
public cam_final ! CAM Finalization
public cam_init ! First phase of CAM initialization
public cam_timestep_init ! CAM timestep initialization
public cam_run1 ! CAM run method phase 1
public cam_run2 ! CAM run method phase 2
public cam_run3 ! CAM run method phase 3
public cam_run4 ! CAM run method phase 4
public cam_timestep_final ! CAM timestep finalization
public cam_final ! CAM Finalization

type(dyn_import_t) :: dyn_in ! Dynamics import container
type(dyn_export_t) :: dyn_out ! Dynamics export container

real(r8) :: dtime_phys ! Time step for physics tendencies.

logical :: BFB_CAM_SCAM_IOP = .false.

! Currently, the host (CAM-SIMA) adds only water vapor (specific humidity)
Expand Down Expand Up @@ -95,6 +96,7 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
use cam_ccpp_cap, only: cam_ccpp_initialize_constituents
use physics_grid, only: columns_on_task
use vert_coord, only: pver
use phys_vars_init_check, only: mark_as_initialized

! Arguments
character(len=cl), intent(in) :: caseid ! case ID
Expand Down Expand Up @@ -141,6 +143,9 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
character(len=cx) :: errmsg
!-----------------------------------------------------------------------

dtime_phys = 0.0_r8
call mark_as_initialized('timestep_for_physics')

call init_pio_subsystem()

! Initializations using data passed from coupler.
Expand Down Expand Up @@ -216,7 +221,7 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &
!!XXgoldyXX: ^ need to import this
end if

call phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out)
call phys_init()

!!XXgoldyXX: v need to import this
! call bldfld () ! master field list (if branch, only does hash tables)
Expand All @@ -233,6 +238,26 @@ subroutine cam_init(caseid, ctitle, model_doi_url, &

end subroutine cam_init

!
!-----------------------------------------------------------------------
!
subroutine cam_timestep_init()
!-----------------------------------------------------------------------
!
! Purpose: Timestep init runs at the start of each timestep
!
!-----------------------------------------------------------------------

use phys_comp, only: phys_timestep_init

!
!----------------------------------------------------------
! PHYS_TIMESTEP_INIT Call the Physics package
!----------------------------------------------------------
!
call phys_timestep_init()

end subroutine cam_timestep_init
!
!-----------------------------------------------------------------------
!
Expand Down Expand Up @@ -274,8 +299,7 @@ subroutine cam_run1(cam_in, cam_out)
!
call t_barrierf('sync_phys_run1', mpicom)
call t_startf('phys_run1')
call phys_run1(dtime_phys, cam_runtime_opts, phys_state, phys_tend, &
cam_in, cam_out)
call phys_run1()
call t_stopf('phys_run1')

end subroutine cam_run1
Expand Down Expand Up @@ -307,8 +331,7 @@ subroutine cam_run2(cam_out, cam_in)
!
call t_barrierf('sync_phys_run2', mpicom)
call t_startf('phys_run2')
call phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, &
cam_in, cam_out)
call phys_run2()
call t_stopf('phys_run2')

!
Expand Down Expand Up @@ -426,6 +449,27 @@ subroutine cam_run4(cam_out, cam_in, rstwr, nlend, &

end subroutine cam_run4

!
!-----------------------------------------------------------------------
!
subroutine cam_timestep_final()
!-----------------------------------------------------------------------
!
! Purpose: Timestep final runs at the end of each timestep
!
!-----------------------------------------------------------------------

use phys_comp, only: phys_timestep_final

!
!----------------------------------------------------------
! PHYS_TIMESTEP_FINAL Call the Physics package
!----------------------------------------------------------
!
call phys_timestep_final()

end subroutine cam_timestep_final

!
!-----------------------------------------------------------------------
!
Expand Down Expand Up @@ -455,7 +499,7 @@ subroutine cam_final(cam_out, cam_in)
integer :: nstep ! Current timestep number.
!-----------------------------------------------------------------------

call phys_final(cam_runtime_opts, phys_state, phys_tend)
call phys_final()
call stepon_final(cam_runtime_opts, dyn_in, dyn_out)
! call ionosphere_final()

Expand Down
18 changes: 12 additions & 6 deletions src/cpl/nuopc/atm_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ end subroutine InitializeRealize
subroutine DataInitialize(gcomp, rc)
use string_utils, only: to_str
use cam_comp, only: cam_run1
use cam_comp, only: cam_timestep_init

! Dummy arguments
type(ESMF_GridComp) :: gcomp
Expand Down Expand Up @@ -991,18 +992,16 @@ subroutine DataInitialize(gcomp, rc)
if (stepno == 0) then
call import_fields(gcomp, cam_in, rc=rc)
if (ChkErr(rc, __LINE__, u_FILE_u)) return
call cam_run1 (cam_in, cam_out)
call export_fields(gcomp, cam_out, rc=rc)
if (ChkErr(rc, __LINE__, u_FILE_u)) return
else
call cam_read_srfrest(gcomp, clock, rc=rc)
if (ChkErr(rc, __LINE__, u_FILE_u)) return
call import_fields(gcomp, cam_in, restart_init=.true., rc=rc)
if (ChkErr(rc, __LINE__, u_FILE_u)) return
call cam_run1 (cam_in, cam_out)
call export_fields(gcomp, cam_out, rc=rc)
if (ChkErr(rc, __LINE__, u_FILE_u)) return
end if
call cam_timestep_init ()
call cam_run1 (cam_in, cam_out)
call export_fields(gcomp, cam_out, rc=rc)
if (ChkErr(rc, __LINE__, u_FILE_u)) return

!CAMDEN TODO Remove once radiation has been fully implemented. -JN
! Also note that this will need to be refactored to reflect the
Expand Down Expand Up @@ -1072,6 +1071,7 @@ subroutine DataInitialize(gcomp, rc)
else ! mediator is not present
!---------------------------------------------------------------

call cam_timestep_init ()
call cam_run1 (cam_in, cam_out)

call NUOPC_CompAttributeSet(gcomp, name="InitializeDataComplete", &
Expand Down Expand Up @@ -1101,6 +1101,8 @@ subroutine ModelAdvance(gcomp, rc)
use cam_comp, only: cam_run1

use cam_comp, only: cam_run2, cam_run3, cam_run4
use cam_comp, only: cam_timestep_init
use cam_comp, only: cam_timestep_final

! Run CAM

Expand Down Expand Up @@ -1275,10 +1277,12 @@ subroutine ModelAdvance(gcomp, rc)
mon_spec=mon_sync, day_spec=day_sync, sec_spec=tod_sync)
call t_stopf ('CAM_run4')

call cam_timestep_final()
! Advance cam time step
call t_startf ('CAM_adv_timestep')
call advance_timestep()
call t_stopf ('CAM_adv_timestep')
call cam_timestep_init()

! Run CAM4,5,6 radiation/clouds (run1 / tphysbc)
call t_startf ('CAM_run1')
Expand Down Expand Up @@ -1521,6 +1525,7 @@ end subroutine ModelSetRunClock
!==========================================================================
subroutine ModelFinalize(gcomp, rc)
use cam_comp, only: cam_final
use cam_comp, only: cam_timestep_final

! Dummy arguments
type(ESMF_GridComp) :: gcomp
Expand Down Expand Up @@ -1564,6 +1569,7 @@ subroutine ModelFinalize(gcomp, rc)
call t_stopf('CAM_import')
end if

call cam_timestep_final()
call cam_final(cam_out, cam_in)

!CAMDEN TODO: export output state? Needed for finalize?
Expand Down
Loading

0 comments on commit 1c994e6

Please sign in to comment.