From d8c2d6e645be97a029c0c21b40333d8c3ad308d9 Mon Sep 17 00:00:00 2001 From: Courtney Peverley Date: Thu, 29 Feb 2024 01:36:10 -0700 Subject: [PATCH 1/5] split run phase via groups --- src/control/cam_comp.F90 | 63 +++++++++- src/cpl/nuopc/atm_comp_nuopc.F90 | 10 ++ src/data/registry.xml | 32 ++++- src/data/registry_v1_0.xsd | 2 +- src/data/write_init_files.py | 3 +- src/physics/utils/phys_comp.F90 | 209 ++++++++++++++++++++++--------- src/physics/utils/phys_comp.meta | 37 ------ 7 files changed, 249 insertions(+), 107 deletions(-) delete mode 100644 src/physics/utils/phys_comp.meta diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 9ac8f179..f13db6c9 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -36,12 +36,14 @@ 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 @@ -233,6 +235,30 @@ subroutine cam_init(caseid, ctitle, model_doi_url, & end subroutine cam_init + ! + !----------------------------------------------------------------------- + ! + subroutine cam_timestep_init(cam_in, cam_out) + !----------------------------------------------------------------------- + ! + ! Purpose: Timestep init runs at the start of each timestep + ! + !----------------------------------------------------------------------- + + use phys_comp, only: phys_timestep_init + + type(cam_in_t), pointer, intent(inout) :: cam_in ! Input from surface to CAM + type(cam_out_t), pointer, intent(inout) :: cam_out ! Output from CAM to surface + + ! + !---------------------------------------------------------- + ! PHYS_TIMESTEP_INIT Call the Physics package + !---------------------------------------------------------- + ! + call phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & + cam_in, cam_out) + + end subroutine cam_timestep_init ! !----------------------------------------------------------------------- ! @@ -426,6 +452,31 @@ subroutine cam_run4(cam_out, cam_in, rstwr, nlend, & end subroutine cam_run4 + ! + !----------------------------------------------------------------------- + ! + subroutine cam_timestep_final(cam_in, cam_out) + !----------------------------------------------------------------------- + ! + ! Purpose: Timestep final runs at the start of each timestep + ! + !----------------------------------------------------------------------- + + use phys_comp, only: phys_timestep_final + + type(cam_in_t), pointer, intent(inout) :: cam_in ! Input from surface to CAM + type(cam_out_t), pointer, intent(inout) :: cam_out ! Output from CAM to surface + + ! + !---------------------------------------------------------- + ! PHYS_TIMESTEP_FINAL Call the Physics package + !---------------------------------------------------------- + ! + call phys_timestep_final(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & + cam_in, cam_out) + + end subroutine cam_timestep_final + ! !----------------------------------------------------------------------- ! diff --git a/src/cpl/nuopc/atm_comp_nuopc.F90 b/src/cpl/nuopc/atm_comp_nuopc.F90 index 37f669f7..07252e0d 100644 --- a/src/cpl/nuopc/atm_comp_nuopc.F90 +++ b/src/cpl/nuopc/atm_comp_nuopc.F90 @@ -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 @@ -991,6 +992,7 @@ 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_timestep_init (cam_in, cam_out) call cam_run1 (cam_in, cam_out) call export_fields(gcomp, cam_out, rc=rc) if (ChkErr(rc, __LINE__, u_FILE_u)) return @@ -999,6 +1001,7 @@ subroutine DataInitialize(gcomp, 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_timestep_init (cam_in, cam_out) call cam_run1 (cam_in, cam_out) call export_fields(gcomp, cam_out, rc=rc) if (ChkErr(rc, __LINE__, u_FILE_u)) return @@ -1072,6 +1075,7 @@ subroutine DataInitialize(gcomp, rc) else ! mediator is not present !--------------------------------------------------------------- + call cam_timestep_init (cam_in, cam_out) call cam_run1 (cam_in, cam_out) call NUOPC_CompAttributeSet(gcomp, name="InitializeDataComplete", & @@ -1101,6 +1105,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 @@ -1275,10 +1281,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(cam_in, cam_out) ! Advance cam time step call t_startf ('CAM_adv_timestep') call advance_timestep() call t_stopf ('CAM_adv_timestep') + call cam_timestep_init(cam_in, cam_out) ! Run CAM4,5,6 radiation/clouds (run1 / tphysbc) call t_startf ('CAM_run1') @@ -1521,6 +1529,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 @@ -1564,6 +1573,7 @@ subroutine ModelFinalize(gcomp, rc) call t_stopf('CAM_import') end if + call cam_timestep_final(cam_in, cam_out) call cam_final(cam_out, cam_in) !CAMDEN TODO: export output state? Needed for finalize? diff --git a/src/data/registry.xml b/src/data/registry.xml index 8c6c0890..c23847c9 100644 --- a/src/data/registry.xml +++ b/src/data/registry.xml @@ -8,7 +8,7 @@ $SRCROOT/src/control/camsrfexch.meta $SRCROOT/src/control/runtime_obj.meta $SRCROOT/src/data/physconst.meta - $SRCROOT/src/physics/utils/phys_comp.meta + $SRCROOT/src/physics/utils/physics_grid.meta $SRCROOT/src/physics/utils/cam_constituents.meta $SRCROOT/src/data/air_composition.meta @@ -314,6 +314,36 @@ phys_timestep_init_zero="true"> Total tendency from physics suite + + + horizontal loop begin + -1 + + + horizontal loop end + -1 + + + timestep for physics + + + ccpp error code + 0 + + + ccpp error message + '' + - + diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index 0431184c..d646b92e 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -27,7 +27,8 @@ 'ccpp_constituent_minimum_values', 'log_output_unit', 'do_log_output', 'mpi_communicator', 'mpi_root', 'mpi_rank', - 'number_of_mpi_tasks'} + 'number_of_mpi_tasks', 'ccpp_error_message', + 'ccpp_error_code'} # Variable input types _INPUT_TYPES = set(['in', 'inout']) diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index 663a8b06..365eec54 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -2,15 +2,19 @@ module phys_comp use ccpp_kinds, only: kind_phys use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL - use runtime_obj, only: unset_str + use runtime_obj, only: unset_str, unset_int, unset_real + use physics_types, only: errmsg, errcode, physics_timestep + use physics_types, only: column_start, column_end implicit none private public :: phys_readnl public :: phys_init + public :: phys_timestep_init public :: phys_run1 public :: phys_run2 + public :: phys_timestep_final public :: phys_final ! Public module data @@ -19,6 +23,7 @@ module phys_comp ! Private module data character(len=SHR_KIND_CS), allocatable :: suite_names(:) + character(len=SHR_KIND_CS) :: suite_parts_expect(2) = (/"physics_before_coupler", "physics_after_coupler "/) character(len=SHR_KIND_CS), allocatable :: suite_parts(:) character(len=SHR_KIND_CL) :: ncdata_check = unset_str character(len=SHR_KIND_CL) :: cam_physics_mesh = unset_str @@ -26,6 +31,11 @@ module phys_comp character(len=SHR_KIND_CS) :: cam_take_snapshot_after = unset_str real(kind_phys) :: min_difference = HUGE(1.0_kind_phys) real(kind_phys) :: min_relative_value = HUGE(1.0_kind_phys) +! integer :: column_start = unset_int +! integer :: column_end = unset_int +! real(kind_phys) :: physics_timestep = unset_real +! integer :: errcode = 0 +! character(len=512) :: errmsg = '' !============================================================================== CONTAINS @@ -138,6 +148,7 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) use physics_types, only: allocate_physics_types_fields use cam_ccpp_cap, only: cam_ccpp_physics_initialize use cam_ccpp_cap, only: ccpp_physics_suite_part_list + use phys_vars_init_check, only: mark_as_initialized ! Dummy arguments type(runtime_options), intent(in) :: cam_runtime_opts @@ -147,16 +158,23 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) ! Local variables real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not set yet - character(len=512) :: errmsg - integer :: errcode + integer :: i_group + logical :: match errcode = 0 + errmsg = '' + ! Threading vars + column_start = 1 + column_end = columns_on_task + physics_timestep = dtime_phys + call mark_as_initialized('horizontal_loop_begin') + call mark_as_initialized('horizontal_loop_end') + call mark_as_initialized('timestep_for_physics') call cam_thermo_init(columns_on_task, pver, pverp) call allocate_physics_types_fields(columns_on_task, pver, pverp, & set_init_val_in=.true., reallocate_in=.false.) - call cam_ccpp_physics_initialize(phys_suite_name, dtime_phys, & - errmsg, errcode) + call cam_ccpp_physics_initialize(phys_suite_name) if (errcode /= 0) then call endrun('cam_ccpp_physics_initialize: '//trim(errmsg)) end if @@ -165,65 +183,65 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) if (errcode /= 0) then call endrun('cam_ccpp_suite_part_list: '//trim(errmsg)) end if + ! Confirm that the suite parts are as expected + match = .false. + if (size(suite_parts) > size(suite_parts_expect)) then + write(errmsg, *) 'phys_init: SDF suite groups MUST be ', & + 'only `physics_before_coupler` and/or `physics_after_coupler`' + call endrun(errmsg) + else if (size(suite_parts) < size(suite_parts_expect)) then + if (any(suite_parts(1) == suite_parts_expect)) then + match = .true. + else + write(errmsg, *) 'phys_init: SDF suite groups MUST be ', & + '`physics_before_coupler` and/or `physics_after_coupler`' + call endrun(errmsg) + end if + else + do i_group = 1, size(suite_parts_expect) + if (any(suite_parts_expect(i_group) == suite_parts)) then + match = .true. + else + match = .false. + end if + end do + if (.not. match) then + write(errmsg, *) 'phys_init: SDF suite groups MUST be ', & + 'ONLY `physics_before_coupler` and/or `physics_after_coupler`' + call endrun(errmsg) + end if + end if end subroutine phys_init - subroutine phys_run1(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) - use cam_abortutils, only: endrun - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend - use camsrfexch, only: cam_in_t, cam_out_t - - ! Dummy arguments - real(kind_phys), intent(in) :: dtime_phys - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - type(cam_in_t), intent(inout) :: cam_in - type(cam_out_t), intent(inout) :: cam_out - - end subroutine phys_run1 - - !> \section arg_table_phys_run2 Argument Table - !! \htmlinclude arg_table_phys_run2.html - !! - subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & + subroutine phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & cam_in, cam_out) use pio, only: file_desc_t + use cam_initfiles, only: initial_file_get_id + use physics_types, only: physics_types_tstep_init + use physics_inputs, only: physics_read_data + use time_manager, only: is_first_restart_step + use time_manager, only: get_nstep use cam_abortutils, only: endrun use runtime_obj, only: runtime_options use physics_types, only: physics_state, physics_tend - use physics_types, only: physics_types_tstep_init - use physics_grid, only: columns_on_task - use camsrfexch, only: cam_in_t, cam_out_t use cam_ccpp_cap, only: cam_ccpp_physics_timestep_initial - use cam_ccpp_cap, only: cam_ccpp_physics_run - use cam_ccpp_cap, only: cam_ccpp_physics_timestep_final - use physics_inputs, only: physics_read_data - use cam_initfiles, only: initial_file_get_id, unset_path_str - use time_manager, only: get_nstep + use camsrfexch, only: cam_in_t, cam_out_t use time_manager, only: is_first_step - use time_manager, only: is_first_restart_step - use physics_inputs, only: physics_check_data ! Dummy arguments real(kind_phys), intent(in) :: dtime_phys type(runtime_options), intent(in) :: cam_runtime_opts type(physics_state), intent(inout) :: phys_state type(physics_tend), intent(inout) :: phys_tend - type(cam_out_t), intent(inout) :: cam_out type(cam_in_t), intent(inout) :: cam_in + type(cam_out_t), intent(inout) :: cam_out ! Local variables type(file_desc_t), pointer :: ncdata - character(len=512) :: errmsg - integer :: errcode - integer :: part_ind - integer :: col_start - integer :: col_end integer :: data_frame logical :: use_init_variables + physics_timestep = dtime_phys errcode = 0 ! Physics needs to read in all data not read in by the dycore ncdata => initial_file_get_id() @@ -245,39 +263,113 @@ subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & read_initialized_variables=use_init_variables) ! Initialize the physics time step - call cam_ccpp_physics_timestep_initial(phys_suite_name, dtime_phys, & - errmsg, errcode) + call cam_ccpp_physics_timestep_initial(phys_suite_name) if (errcode /= 0) then call endrun('cam_ccpp_physics_timestep_initial: '//trim(errmsg)) end if - ! Threading vars - col_start = 1 - col_end = columns_on_task + end subroutine phys_timestep_init + + subroutine phys_run1(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & + cam_in, cam_out) + use runtime_obj, only: runtime_options + use physics_types, only: physics_state, physics_tend + use cam_ccpp_cap, only: cam_ccpp_physics_run + use camsrfexch, only: cam_in_t, cam_out_t + use cam_abortutils, only: endrun + + ! Dummy arguments + real(kind_phys), intent(in) :: dtime_phys + type(runtime_options), intent(in) :: cam_runtime_opts + type(physics_state), intent(inout) :: phys_state + type(physics_tend), intent(inout) :: phys_tend + type(cam_in_t), intent(inout) :: cam_in + type(cam_out_t), intent(inout) :: cam_out + + physics_timestep = dtime_phys + errcode = 0 - ! Run CCPP suite - do part_ind = 1, size(suite_parts, 1) - call cam_ccpp_physics_run(phys_suite_name, suite_parts(part_ind), & - col_start, col_end, dtime_phys, errmsg, errcode) + ! Run before coupler group if it exists + if (any('physics_before_coupler' == suite_parts)) then + call cam_ccpp_physics_run(phys_suite_name, 'physics_before_coupler') if (errcode /= 0) then call endrun('cam_ccpp_physics_run: '//trim(errmsg)) end if - end do + end if + + end subroutine phys_run1 + + subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & + cam_in, cam_out) + use runtime_obj, only: runtime_options + use physics_types, only: physics_state, physics_tend + use camsrfexch, only: cam_in_t, cam_out_t + use cam_ccpp_cap, only: cam_ccpp_physics_run + use cam_abortutils, only: endrun + + ! Dummy arguments + real(kind_phys), intent(in) :: dtime_phys + type(runtime_options), intent(in) :: cam_runtime_opts + type(physics_state), intent(inout) :: phys_state + type(physics_tend), intent(inout) :: phys_tend + type(cam_out_t), intent(inout) :: cam_out + type(cam_in_t), intent(inout) :: cam_in + + physics_timestep = dtime_phys + errcode = 0 + ! Run after coupler group if it exists + if (any('physics_after_coupler' == suite_parts)) then + call cam_ccpp_physics_run(phys_suite_name, 'physics_after_coupler') + if (errcode /= 0) then + call endrun('cam_ccpp_physics_run: '//trim(errmsg)) + end if + end if + + end subroutine phys_run2 + + subroutine phys_timestep_final(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & + cam_in, cam_out) + use time_manager, only: get_nstep + use cam_abortutils, only: endrun + use runtime_obj, only: runtime_options + use physics_types, only: physics_state, physics_tend + use camsrfexch, only: cam_in_t, cam_out_t + use cam_initfiles, only: unset_path_str + use cam_ccpp_cap, only: cam_ccpp_physics_timestep_final + use physics_inputs, only: physics_check_data + + ! Dummy arguments + real(kind_phys), intent(in) :: dtime_phys + type(runtime_options), intent(in) :: cam_runtime_opts + type(physics_state), intent(inout) :: phys_state + type(physics_tend), intent(inout) :: phys_tend + type(cam_in_t), intent(inout) :: cam_in + type(cam_out_t), intent(inout) :: cam_out + ! Local variables + integer :: data_frame + + errcode = 0 + physics_timestep = dtime_phys ! Finalize the time step - call cam_ccpp_physics_timestep_final(phys_suite_name, dtime_phys, & - errmsg, errcode) + call cam_ccpp_physics_timestep_final(phys_suite_name) if (errcode /= 0) then call endrun('cam_ccpp_physics_timestep_final: '//trim(errmsg)) end if + ! data_frame is the next input frame for physics input fields + ! Frame 1 is skipped for snapshot files + !!XXgoldyXX: This section needs to have better logic once we know if + !! this is a physics test bench run. + data_frame = get_nstep() + 2 + ! Determine if physics_check should be run: if (trim(ncdata_check) /= trim(unset_path_str)) then call physics_check_data(ncdata_check, suite_names, data_frame, & min_difference, min_relative_value) end if - end subroutine phys_run2 + end subroutine phys_timestep_final subroutine phys_final(cam_runtime_opts, phys_state, phys_tend) use cam_abortutils, only: endrun @@ -292,13 +384,8 @@ subroutine phys_final(cam_runtime_opts, phys_state, phys_tend) type(physics_tend), intent(inout) :: phys_tend ! Local variables real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not used - character(len=512) :: errmsg - integer :: errcode - errcode = 0 - - call cam_ccpp_physics_finalize(phys_suite_name, dtime_phys, & - errmsg, errcode) + call cam_ccpp_physics_finalize(phys_suite_name) if (errcode /= 0) then call endrun('cam_ccpp_physics_finalize: '//trim(errmsg)) end if diff --git a/src/physics/utils/phys_comp.meta b/src/physics/utils/phys_comp.meta deleted file mode 100644 index 84d0673d..00000000 --- a/src/physics/utils/phys_comp.meta +++ /dev/null @@ -1,37 +0,0 @@ -[ccpp-table-properties] - name = phys_run2 - type = host -[ccpp-arg-table] - name = phys_run2 - type = host -[ col_start ] - standard_name = horizontal_loop_begin - type = integer - units = count - dimensions = () - protected = True -[ col_end ] - standard_name = horizontal_loop_end - type = integer - units = count - dimensions = () - protected = True -[ dtime_phys ] - standard_name = timestep_for_physics - type = real | kind = kind_phys - units = s - dimensions = () - protected = True -[ errmsg ] - standard_name = ccpp_error_message - long_name = Error message for error handling in CCPP - units = 1 - dimensions = () - type = character - kind = len=512 -[ errcode ] - standard_name = ccpp_error_code - long_name = Error flag for error handling in CCPP - units = flag - dimensions = () - type = integer From be94bc9fa45f98137bcd5607a05b1480a57d3a74 Mon Sep 17 00:00:00 2001 From: Courtney Peverley Date: Mon, 11 Mar 2024 17:36:50 -0600 Subject: [PATCH 2/5] move col_start and col_end to physics_grid --- Externals_CAM.cfg | 2 +- src/control/cam_comp.F90 | 7 +- src/data/registry.xml | 18 +--- src/physics/utils/phys_comp.F90 | 91 +++++-------------- src/physics/utils/physics_grid.F90 | 3 + src/physics/utils/physics_grid.meta | 12 +++ .../phys_vars_init_check_4D.F90 | 4 +- .../phys_vars_init_check_bvd.F90 | 4 +- .../phys_vars_init_check_ddt.F90 | 4 +- .../phys_vars_init_check_ddt2.F90 | 4 +- .../phys_vars_init_check_ddt_array.F90 | 4 +- .../phys_vars_init_check_host_var.F90 | 4 +- .../phys_vars_init_check_mf.F90 | 4 +- .../phys_vars_init_check_no_horiz.F90 | 4 +- .../phys_vars_init_check_noreq.F90 | 4 +- .../phys_vars_init_check_param.F90 | 4 +- .../phys_vars_init_check_protect.F90 | 4 +- .../phys_vars_init_check_scalar.F90 | 4 +- .../phys_vars_init_check_simple.F90 | 4 +- 19 files changed, 86 insertions(+), 99 deletions(-) diff --git a/Externals_CAM.cfg b/Externals_CAM.cfg index 377c3732..8dd66555 100644 --- a/Externals_CAM.cfg +++ b/Externals_CAM.cfg @@ -2,7 +2,7 @@ local_path = ccpp_framework protocol = git repo_url = https://github.com/peverwhee/ccpp-framework -tag = CPF_0.2.054 +tag = CPF_0.2.056 required = True [mpas] diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 493506ce..9a2c8bbf 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -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 @@ -48,8 +49,6 @@ module cam_comp 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) @@ -97,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 @@ -143,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. diff --git a/src/data/registry.xml b/src/data/registry.xml index 3e95ac09..f0e3f708 100644 --- a/src/data/registry.xml +++ b/src/data/registry.xml @@ -8,7 +8,6 @@ $SRCROOT/src/control/camsrfexch.meta $SRCROOT/src/control/runtime_obj.meta $SRCROOT/src/data/physconst.meta - $SRCROOT/src/physics/utils/physics_grid.meta $SRCROOT/src/physics/utils/cam_constituents.meta $SRCROOT/src/data/air_composition.meta @@ -314,24 +313,13 @@ phys_timestep_init_zero="true"> Total tendency from physics suite - - - horizontal loop begin - -1 - - - horizontal loop end - -1 - - + timestep for physics + diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index 365eec54..98bc7ea3 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -1,10 +1,10 @@ module phys_comp - use ccpp_kinds, only: kind_phys - use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL - use runtime_obj, only: unset_str, unset_int, unset_real - use physics_types, only: errmsg, errcode, physics_timestep - use physics_types, only: column_start, column_end + use ccpp_kinds, only: kind_phys + use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL + use runtime_obj, only: unset_str + use physics_types, only: errmsg, errcode + use physics_grid, only: col_start, col_end implicit none private @@ -31,11 +31,6 @@ module phys_comp character(len=SHR_KIND_CS) :: cam_take_snapshot_after = unset_str real(kind_phys) :: min_difference = HUGE(1.0_kind_phys) real(kind_phys) :: min_relative_value = HUGE(1.0_kind_phys) -! integer :: column_start = unset_int -! integer :: column_end = unset_int -! real(kind_phys) :: physics_timestep = unset_real -! integer :: errcode = 0 -! character(len=512) :: errmsg = '' !============================================================================== CONTAINS @@ -137,17 +132,16 @@ subroutine phys_readnl(nlfilename) end subroutine phys_readnl subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) - use pio, only: file_desc_t - use cam_abortutils, only: endrun - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend - use camsrfexch, only: cam_out_t - use physics_grid, only: columns_on_task - use vert_coord, only: pver, pverp - use cam_thermo, only: cam_thermo_init - use physics_types, only: allocate_physics_types_fields - use cam_ccpp_cap, only: cam_ccpp_physics_initialize - use cam_ccpp_cap, only: ccpp_physics_suite_part_list + use cam_abortutils, only: endrun + use runtime_obj, only: runtime_options + use physics_types, only: physics_state, physics_tend + use camsrfexch, only: cam_out_t + use physics_grid, only: columns_on_task + use vert_coord, only: pver, pverp + use cam_thermo, only: cam_thermo_init + use physics_types, only: allocate_physics_types_fields + use cam_ccpp_cap, only: cam_ccpp_physics_initialize + use cam_ccpp_cap, only: ccpp_physics_suite_part_list use phys_vars_init_check, only: mark_as_initialized ! Dummy arguments @@ -159,17 +153,7 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) ! Local variables real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not set yet integer :: i_group - logical :: match - - errcode = 0 - errmsg = '' - ! Threading vars - column_start = 1 - column_end = columns_on_task - physics_timestep = dtime_phys - call mark_as_initialized('horizontal_loop_begin') - call mark_as_initialized('horizontal_loop_end') - call mark_as_initialized('timestep_for_physics') + call cam_thermo_init(columns_on_task, pver, pverp) call allocate_physics_types_fields(columns_on_task, pver, pverp, & @@ -183,34 +167,15 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) if (errcode /= 0) then call endrun('cam_ccpp_suite_part_list: '//trim(errmsg)) end if + ! Confirm that the suite parts are as expected - match = .false. - if (size(suite_parts) > size(suite_parts_expect)) then - write(errmsg, *) 'phys_init: SDF suite groups MUST be ', & - 'only `physics_before_coupler` and/or `physics_after_coupler`' - call endrun(errmsg) - else if (size(suite_parts) < size(suite_parts_expect)) then - if (any(suite_parts(1) == suite_parts_expect)) then - match = .true. - else - write(errmsg, *) 'phys_init: SDF suite groups MUST be ', & - '`physics_before_coupler` and/or `physics_after_coupler`' - call endrun(errmsg) - end if - else - do i_group = 1, size(suite_parts_expect) - if (any(suite_parts_expect(i_group) == suite_parts)) then - match = .true. - else - match = .false. - end if - end do - if (.not. match) then + do i_group = 1, size(suite_parts) + if (.not. any(suite_parts(i_group) == suite_parts_expect)) then write(errmsg, *) 'phys_init: SDF suite groups MUST be ', & 'ONLY `physics_before_coupler` and/or `physics_after_coupler`' call endrun(errmsg) end if - end if + end do end subroutine phys_init @@ -237,12 +202,10 @@ subroutine phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_ten type(cam_in_t), intent(inout) :: cam_in type(cam_out_t), intent(inout) :: cam_out ! Local variables - type(file_desc_t), pointer :: ncdata - integer :: data_frame - logical :: use_init_variables + type(file_desc_t), pointer :: ncdata + integer :: data_frame + logical :: use_init_variables - physics_timestep = dtime_phys - errcode = 0 ! Physics needs to read in all data not read in by the dycore ncdata => initial_file_get_id() @@ -286,9 +249,6 @@ subroutine phys_run1(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & type(cam_in_t), intent(inout) :: cam_in type(cam_out_t), intent(inout) :: cam_out - physics_timestep = dtime_phys - errcode = 0 - ! Run before coupler group if it exists if (any('physics_before_coupler' == suite_parts)) then call cam_ccpp_physics_run(phys_suite_name, 'physics_before_coupler') @@ -315,9 +275,6 @@ subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & type(cam_out_t), intent(inout) :: cam_out type(cam_in_t), intent(inout) :: cam_in - physics_timestep = dtime_phys - errcode = 0 - ! Run after coupler group if it exists if (any('physics_after_coupler' == suite_parts)) then call cam_ccpp_physics_run(phys_suite_name, 'physics_after_coupler') @@ -349,8 +306,6 @@ subroutine phys_timestep_final(dtime_phys, cam_runtime_opts, phys_state, phys_te ! Local variables integer :: data_frame - errcode = 0 - physics_timestep = dtime_phys ! Finalize the time step call cam_ccpp_physics_timestep_final(phys_suite_name) if (errcode /= 0) then diff --git a/src/physics/utils/physics_grid.F90 b/src/physics/utils/physics_grid.F90 index 0528cb0c..5e9f950e 100644 --- a/src/physics/utils/physics_grid.F90 +++ b/src/physics/utils/physics_grid.F90 @@ -74,6 +74,8 @@ module physics_grid !! integer, protected, public :: num_global_phys_cols = 0 integer, protected, public :: columns_on_task = 0 + integer, protected, public :: col_start = 1 + integer, protected, public :: col_end = 0 logical, protected, public :: phys_grid_initialized = .false. real(kind_phys), protected, allocatable, public :: lat_rad(:) @@ -164,6 +166,7 @@ subroutine phys_grid_init(hdim1_d_in, hdim2_d_in, dycore_name_in, & ! Calculate number of columns on tasks: columns_on_task = size(dyn_columns) + col_end = size(dyn_columns) ! Allocate phys_columns: allocate(phys_columns(columns_on_task), stat=ierr) diff --git a/src/physics/utils/physics_grid.meta b/src/physics/utils/physics_grid.meta index 9f5b3719..fcf934b5 100644 --- a/src/physics/utils/physics_grid.meta +++ b/src/physics/utils/physics_grid.meta @@ -18,6 +18,18 @@ dimensions = () type = integer protected = True +[ col_start ] + standard_name = horizontal_loop_begin + units = count + dimensions = () + type = integer + protected = True +[ col_end ] + standard_name = horizontal_loop_end + units = count + dimensions = () + type = integer + protected = True [ phys_grid_initialized ] standard_name = flag_for_physics_grid_initialization units = flag diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_4D.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_4D.F90 index cfd4fc65..a13f32c0 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_4D.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_4D.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_4D integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_4D "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_bvd.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_bvd.F90 index 34e76d4c..da57da0a 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_bvd.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_bvd.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_bvd integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_bvd "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt.F90 index f5cffb84..386aa066 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_ddt integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_ddt "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt2.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt2.F90 index f2609f43..027b422f 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt2.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt2.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_ddt2 integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_ddt2 "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt_array.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt_array.F90 index fae6709f..6290f927 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt_array.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_ddt_array.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_ddt_array integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_ddt_array "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_host_var.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_host_var.F90 index d3b75546..344b299e 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_host_var.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_host_var.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_host_var integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 1 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -50,6 +50,8 @@ module phys_vars_init_check_host_var "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_mf.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_mf.F90 index 2f8c83b5..e71a22a0 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_mf.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_mf.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_mf integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_mf "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_no_horiz.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_no_horiz.F90 index fb7e8ffe..962c9ddd 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_no_horiz.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_no_horiz.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_no_horiz integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_no_horiz "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_noreq.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_noreq.F90 index 2529f1d3..b5f92ab5 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_noreq.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_noreq.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_noreq integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 0 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 0 @@ -49,6 +49,8 @@ module phys_vars_init_check_noreq "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_param.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_param.F90 index ee45bf5a..b3a471b9 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_param.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_param.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_param integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 3 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 26 @@ -52,6 +52,8 @@ module phys_vars_init_check_param "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_protect.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_protect.F90 index 0e9c553d..35ab2551 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_protect.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_protect.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_protect integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_protect "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_scalar.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_scalar.F90 index 23ed4f0b..e4a28525 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_scalar.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_scalar.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_scalar integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_scalar "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & diff --git a/test/unit/sample_files/write_init_files/phys_vars_init_check_simple.F90 b/test/unit/sample_files/write_init_files/phys_vars_init_check_simple.F90 index 8f5885ce..a144fc5e 100644 --- a/test/unit/sample_files/write_init_files/phys_vars_init_check_simple.F90 +++ b/test/unit/sample_files/write_init_files/phys_vars_init_check_simple.F90 @@ -34,7 +34,7 @@ module phys_vars_init_check_simple integer, public, parameter :: READ_FROM_FILE = 3 !Total number of physics-related variables: integer, public, parameter :: phys_var_num = 2 - integer, public, parameter :: phys_const_num = 13 + integer, public, parameter :: phys_const_num = 15 !Max length of physics-related variable standard names: integer, public, parameter :: std_name_len = 25 @@ -51,6 +51,8 @@ module phys_vars_init_check_simple "ccpp_constituent_minimum_values ", & "ccpp_constituent_properties ", & "ccpp_constituents ", & + "ccpp_error_code ", & + "ccpp_error_message ", & "do_log_output ", & "log_output_unit ", & "mpi_communicator ", & From a097e4e270f9ad071fbe07eaf25a4b91640fa74b Mon Sep 17 00:00:00 2001 From: Courtney Peverley Date: Fri, 15 Mar 2024 16:45:43 -0600 Subject: [PATCH 3/5] address reviewer comments; clean-up code --- src/control/cam_comp.F90 | 18 +++---- src/data/write_init_files.py | 5 +- src/physics/utils/phys_comp.F90 | 75 ++++-------------------------- src/physics/utils/physics_grid.F90 | 2 +- 4 files changed, 19 insertions(+), 81 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index 9a2c8bbf..c4a6ba69 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -221,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) @@ -258,8 +258,7 @@ subroutine cam_timestep_init(cam_in, cam_out) ! PHYS_TIMESTEP_INIT Call the Physics package !---------------------------------------------------------- ! - call phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) + call phys_timestep_init(dtime_phys) end subroutine cam_timestep_init ! @@ -303,8 +302,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(dtime_phys) call t_stopf('phys_run1') end subroutine cam_run1 @@ -336,8 +334,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(dtime_phys) call t_stopf('phys_run2') ! @@ -461,7 +458,7 @@ end subroutine cam_run4 subroutine cam_timestep_final(cam_in, cam_out) !----------------------------------------------------------------------- ! - ! Purpose: Timestep final runs at the start of each timestep + ! Purpose: Timestep final runs at the end of each timestep ! !----------------------------------------------------------------------- @@ -475,8 +472,7 @@ subroutine cam_timestep_final(cam_in, cam_out) ! PHYS_TIMESTEP_FINAL Call the Physics package !---------------------------------------------------------- ! - call phys_timestep_final(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) + call phys_timestep_final(dtime_phys) end subroutine cam_timestep_final @@ -509,7 +505,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() diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index d646b92e..c07b6535 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -25,10 +25,11 @@ 'ccpp_constituents', 'ccpp_constituent_properties', 'ccpp_constituent_minimum_values', + 'ccpp_error_message', + 'ccpp_error_code', 'log_output_unit', 'do_log_output', 'mpi_communicator', 'mpi_root', 'mpi_rank', - 'number_of_mpi_tasks', 'ccpp_error_message', - 'ccpp_error_code'} + 'number_of_mpi_tasks'} # Variable input types _INPUT_TYPES = set(['in', 'inout']) diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index 98bc7ea3..c4278744 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -38,10 +38,8 @@ module phys_comp subroutine phys_readnl(nlfilename) ! Read physics options, such as suite to run - use shr_kind_mod, only: r8 => shr_kind_r8 use shr_nl_mod, only: find_group_name => shr_nl_find_group_name - use shr_flux_mod, only: shr_flux_adjust_constants - use mpi, only: mpi_character, mpi_real8, mpi_logical + use mpi, only: mpi_character, mpi_real8 use spmd_utils, only: masterproc, masterprocid, mpicom use cam_logfile, only: iulog use cam_abortutils, only: endrun @@ -131,27 +129,16 @@ subroutine phys_readnl(nlfilename) end subroutine phys_readnl - subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) + subroutine phys_init() use cam_abortutils, only: endrun - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend - use camsrfexch, only: cam_out_t use physics_grid, only: columns_on_task use vert_coord, only: pver, pverp use cam_thermo, only: cam_thermo_init use physics_types, only: allocate_physics_types_fields use cam_ccpp_cap, only: cam_ccpp_physics_initialize use cam_ccpp_cap, only: ccpp_physics_suite_part_list - use phys_vars_init_check, only: mark_as_initialized - - ! Dummy arguments - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - type(cam_out_t), intent(inout) :: cam_out ! Local variables - real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not set yet integer :: i_group call cam_thermo_init(columns_on_task, pver, pverp) @@ -179,8 +166,7 @@ subroutine phys_init(cam_runtime_opts, phys_state, phys_tend, cam_out) end subroutine phys_init - subroutine phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) + subroutine phys_timestep_init(dtime_phys) use pio, only: file_desc_t use cam_initfiles, only: initial_file_get_id use physics_types, only: physics_types_tstep_init @@ -188,19 +174,11 @@ subroutine phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_ten use time_manager, only: is_first_restart_step use time_manager, only: get_nstep use cam_abortutils, only: endrun - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend use cam_ccpp_cap, only: cam_ccpp_physics_timestep_initial - use camsrfexch, only: cam_in_t, cam_out_t use time_manager, only: is_first_step ! Dummy arguments real(kind_phys), intent(in) :: dtime_phys - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - type(cam_in_t), intent(inout) :: cam_in - type(cam_out_t), intent(inout) :: cam_out ! Local variables type(file_desc_t), pointer :: ncdata integer :: data_frame @@ -233,21 +211,12 @@ subroutine phys_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_ten end subroutine phys_timestep_init - subroutine phys_run1(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend + subroutine phys_run1(dtime_phys) use cam_ccpp_cap, only: cam_ccpp_physics_run - use camsrfexch, only: cam_in_t, cam_out_t use cam_abortutils, only: endrun ! Dummy arguments real(kind_phys), intent(in) :: dtime_phys - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - type(cam_in_t), intent(inout) :: cam_in - type(cam_out_t), intent(inout) :: cam_out ! Run before coupler group if it exists if (any('physics_before_coupler' == suite_parts)) then @@ -259,21 +228,12 @@ subroutine phys_run1(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & end subroutine phys_run1 - subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend - use camsrfexch, only: cam_in_t, cam_out_t + subroutine phys_run2(dtime_phys) use cam_ccpp_cap, only: cam_ccpp_physics_run use cam_abortutils, only: endrun ! Dummy arguments real(kind_phys), intent(in) :: dtime_phys - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - type(cam_out_t), intent(inout) :: cam_out - type(cam_in_t), intent(inout) :: cam_in ! Run after coupler group if it exists if (any('physics_after_coupler' == suite_parts)) then @@ -285,24 +245,15 @@ subroutine phys_run2(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & end subroutine phys_run2 - subroutine phys_timestep_final(dtime_phys, cam_runtime_opts, phys_state, phys_tend, & - cam_in, cam_out) + subroutine phys_timestep_final(dtime_phys) use time_manager, only: get_nstep use cam_abortutils, only: endrun - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend - use camsrfexch, only: cam_in_t, cam_out_t use cam_initfiles, only: unset_path_str use cam_ccpp_cap, only: cam_ccpp_physics_timestep_final use physics_inputs, only: physics_check_data ! Dummy arguments real(kind_phys), intent(in) :: dtime_phys - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - type(cam_in_t), intent(inout) :: cam_in - type(cam_out_t), intent(inout) :: cam_out ! Local variables integer :: data_frame @@ -326,19 +277,9 @@ subroutine phys_timestep_final(dtime_phys, cam_runtime_opts, phys_state, phys_te end subroutine phys_timestep_final - subroutine phys_final(cam_runtime_opts, phys_state, phys_tend) - use cam_abortutils, only: endrun - use runtime_obj, only: runtime_options - use physics_types, only: physics_state, physics_tend - use camsrfexch, only: cam_in_t, cam_out_t + subroutine phys_final() use cam_ccpp_cap, only: cam_ccpp_physics_finalize - - ! Dummy arguments - type(runtime_options), intent(in) :: cam_runtime_opts - type(physics_state), intent(inout) :: phys_state - type(physics_tend), intent(inout) :: phys_tend - ! Local variables - real(kind_phys) :: dtime_phys = 0.0_kind_phys ! Not used + use cam_abortutils, only: endrun call cam_ccpp_physics_finalize(phys_suite_name) if (errcode /= 0) then diff --git a/src/physics/utils/physics_grid.F90 b/src/physics/utils/physics_grid.F90 index 5e9f950e..de59b560 100644 --- a/src/physics/utils/physics_grid.F90 +++ b/src/physics/utils/physics_grid.F90 @@ -166,7 +166,7 @@ subroutine phys_grid_init(hdim1_d_in, hdim2_d_in, dycore_name_in, & ! Calculate number of columns on tasks: columns_on_task = size(dyn_columns) - col_end = size(dyn_columns) + col_end = columns_on_task ! Allocate phys_columns: allocate(phys_columns(columns_on_task), stat=ierr) From 7bc36cf2fc9b1d03f6de12debff519ef9d6527a0 Mon Sep 17 00:00:00 2001 From: Courtney Peverley Date: Mon, 18 Mar 2024 12:02:31 -0600 Subject: [PATCH 4/5] clean up phys_comp routines --- src/control/cam_comp.F90 | 8 ++++---- src/physics/utils/phys_comp.F90 | 18 ++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index c4a6ba69..a37c8d0c 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -258,7 +258,7 @@ subroutine cam_timestep_init(cam_in, cam_out) ! PHYS_TIMESTEP_INIT Call the Physics package !---------------------------------------------------------- ! - call phys_timestep_init(dtime_phys) + call phys_timestep_init() end subroutine cam_timestep_init ! @@ -302,7 +302,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) + call phys_run1() call t_stopf('phys_run1') end subroutine cam_run1 @@ -334,7 +334,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) + call phys_run2() call t_stopf('phys_run2') ! @@ -472,7 +472,7 @@ subroutine cam_timestep_final(cam_in, cam_out) ! PHYS_TIMESTEP_FINAL Call the Physics package !---------------------------------------------------------- ! - call phys_timestep_final(dtime_phys) + call phys_timestep_final() end subroutine cam_timestep_final diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index c4278744..c3e91bf9 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -166,7 +166,7 @@ subroutine phys_init() end subroutine phys_init - subroutine phys_timestep_init(dtime_phys) + subroutine phys_timestep_init() use pio, only: file_desc_t use cam_initfiles, only: initial_file_get_id use physics_types, only: physics_types_tstep_init @@ -177,8 +177,6 @@ subroutine phys_timestep_init(dtime_phys) use cam_ccpp_cap, only: cam_ccpp_physics_timestep_initial use time_manager, only: is_first_step - ! Dummy arguments - real(kind_phys), intent(in) :: dtime_phys ! Local variables type(file_desc_t), pointer :: ncdata integer :: data_frame @@ -211,13 +209,10 @@ subroutine phys_timestep_init(dtime_phys) end subroutine phys_timestep_init - subroutine phys_run1(dtime_phys) + subroutine phys_run1() use cam_ccpp_cap, only: cam_ccpp_physics_run use cam_abortutils, only: endrun - ! Dummy arguments - real(kind_phys), intent(in) :: dtime_phys - ! Run before coupler group if it exists if (any('physics_before_coupler' == suite_parts)) then call cam_ccpp_physics_run(phys_suite_name, 'physics_before_coupler') @@ -228,13 +223,10 @@ subroutine phys_run1(dtime_phys) end subroutine phys_run1 - subroutine phys_run2(dtime_phys) + subroutine phys_run2() use cam_ccpp_cap, only: cam_ccpp_physics_run use cam_abortutils, only: endrun - ! Dummy arguments - real(kind_phys), intent(in) :: dtime_phys - ! Run after coupler group if it exists if (any('physics_after_coupler' == suite_parts)) then call cam_ccpp_physics_run(phys_suite_name, 'physics_after_coupler') @@ -245,15 +237,13 @@ subroutine phys_run2(dtime_phys) end subroutine phys_run2 - subroutine phys_timestep_final(dtime_phys) + subroutine phys_timestep_final() use time_manager, only: get_nstep use cam_abortutils, only: endrun use cam_initfiles, only: unset_path_str use cam_ccpp_cap, only: cam_ccpp_physics_timestep_final use physics_inputs, only: physics_check_data - ! Dummy arguments - real(kind_phys), intent(in) :: dtime_phys ! Local variables integer :: data_frame From 813cbb2897a74def263bf560b82a860a9d6c5b4e Mon Sep 17 00:00:00 2001 From: Courtney Peverley Date: Wed, 10 Apr 2024 13:44:34 -0600 Subject: [PATCH 5/5] code cleanup; review comments --- src/control/cam_comp.F90 | 10 ++-------- src/cpl/nuopc/atm_comp_nuopc.F90 | 20 ++++++++------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index a37c8d0c..a36f4cca 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -241,7 +241,7 @@ end subroutine cam_init ! !----------------------------------------------------------------------- ! - subroutine cam_timestep_init(cam_in, cam_out) + subroutine cam_timestep_init() !----------------------------------------------------------------------- ! ! Purpose: Timestep init runs at the start of each timestep @@ -250,9 +250,6 @@ subroutine cam_timestep_init(cam_in, cam_out) use phys_comp, only: phys_timestep_init - type(cam_in_t), pointer, intent(inout) :: cam_in ! Input from surface to CAM - type(cam_out_t), pointer, intent(inout) :: cam_out ! Output from CAM to surface - ! !---------------------------------------------------------- ! PHYS_TIMESTEP_INIT Call the Physics package @@ -455,7 +452,7 @@ end subroutine cam_run4 ! !----------------------------------------------------------------------- ! - subroutine cam_timestep_final(cam_in, cam_out) + subroutine cam_timestep_final() !----------------------------------------------------------------------- ! ! Purpose: Timestep final runs at the end of each timestep @@ -464,9 +461,6 @@ subroutine cam_timestep_final(cam_in, cam_out) use phys_comp, only: phys_timestep_final - type(cam_in_t), pointer, intent(inout) :: cam_in ! Input from surface to CAM - type(cam_out_t), pointer, intent(inout) :: cam_out ! Output from CAM to surface - ! !---------------------------------------------------------- ! PHYS_TIMESTEP_FINAL Call the Physics package diff --git a/src/cpl/nuopc/atm_comp_nuopc.F90 b/src/cpl/nuopc/atm_comp_nuopc.F90 index 07252e0d..387a1660 100644 --- a/src/cpl/nuopc/atm_comp_nuopc.F90 +++ b/src/cpl/nuopc/atm_comp_nuopc.F90 @@ -992,20 +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_timestep_init (cam_in, cam_out) - 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_timestep_init (cam_in, cam_out) - 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 @@ -1075,7 +1071,7 @@ subroutine DataInitialize(gcomp, rc) else ! mediator is not present !--------------------------------------------------------------- - call cam_timestep_init (cam_in, cam_out) + call cam_timestep_init () call cam_run1 (cam_in, cam_out) call NUOPC_CompAttributeSet(gcomp, name="InitializeDataComplete", & @@ -1281,12 +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(cam_in, cam_out) + 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(cam_in, cam_out) + call cam_timestep_init() ! Run CAM4,5,6 radiation/clouds (run1 / tphysbc) call t_startf ('CAM_run1') @@ -1573,7 +1569,7 @@ subroutine ModelFinalize(gcomp, rc) call t_stopf('CAM_import') end if - call cam_timestep_final(cam_in, cam_out) + call cam_timestep_final() call cam_final(cam_out, cam_in) !CAMDEN TODO: export output state? Needed for finalize?