Skip to content

Commit

Permalink
move col_start and col_end to physics_grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Courtney Peverley committed Mar 11, 2024
1 parent c6398e8 commit be94bc9
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Externals_CAM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 5 additions & 2 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 @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 3 additions & 15 deletions src/data/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<metadata_file>$SRCROOT/src/control/camsrfexch.meta</metadata_file>
<metadata_file>$SRCROOT/src/control/runtime_obj.meta</metadata_file>
<metadata_file>$SRCROOT/src/data/physconst.meta</metadata_file>
<!-- <metadata_file>$SRCROOT/src/physics/utils/phys_comp.meta</metadata_file> -->
<metadata_file>$SRCROOT/src/physics/utils/physics_grid.meta</metadata_file>
<metadata_file>$SRCROOT/src/physics/utils/cam_constituents.meta</metadata_file>
<metadata_file>$SRCROOT/src/data/air_composition.meta</metadata_file>
Expand Down Expand Up @@ -314,24 +313,13 @@
phys_timestep_init_zero="true">
<long_name>Total tendency from physics suite</long_name>
</variable>
<!-- Physics run variables -->
<variable local_name="column_start"
standard_name="horizontal_loop_begin"
units="count" type="integer">
<long_name>horizontal loop begin</long_name>
<initial_value>-1</initial_value>
</variable>
<variable local_name="column_end"
standard_name="horizontal_loop_end"
units="count" type="integer">
<long_name>horizontal loop end</long_name>
<initial_value>-1</initial_value>
</variable>
<variable local_name="physics_timestep"
<!-- Physics timestep -->
<variable local_name="dtime_phys"
standard_name="timestep_for_physics"
units="s" type="real" kind="kind_phys">
<long_name>timestep for physics</long_name>
</variable>
<!-- Error handling variables -->
<variable local_name="errcode"
standard_name="ccpp_error_code"
units="1" type="integer">
Expand Down
91 changes: 23 additions & 68 deletions src/physics/utils/phys_comp.F90
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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, &
Expand All @@ -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

Expand All @@ -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()

Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/physics/utils/physics_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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(:)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/physics/utils/physics_grid.meta
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ", &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ", &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ", &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ", &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ", &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ", &
Expand Down
Loading

0 comments on commit be94bc9

Please sign in to comment.