Skip to content

Commit

Permalink
Merge pull request #253 from peverwhee/split_up_phys_run
Browse files Browse the repository at this point in the history
Split run into phys_run1 and phys_run2
  • Loading branch information
peverwhee committed Apr 12, 2024
2 parents d809cf1 + 813cbb2 commit a54b646
Show file tree
Hide file tree
Showing 22 changed files with 230 additions and 183 deletions.
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
20 changes: 19 additions & 1 deletion 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,6 +313,25 @@
phys_timestep_init_zero="true">
<long_name>Total tendency from physics suite</long_name>
</variable>
<!-- 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">
<long_name>ccpp error code</long_name>
<initial_value>0</initial_value>
</variable>
<variable local_name="errmsg"
standard_name="ccpp_error_message"
units="none" type="character" kind="len=512">
<long_name>ccpp error message</long_name>
<initial_value>''</initial_value>
</variable>
<!-- Composition-dependent Variables -->
<variable local_name="cpairv"
standard_name="composition_dependent_specific_heat_of_dry_air_at_constant_pressure"
Expand Down
2 changes: 1 addition & 1 deletion src/data/registry_v1_0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<xs:simpleType name="fortran_id_type">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z][A-Za-z0-9_]{0,63}"/>
<xs:pattern value="[A-Za-z][A-Za-z0-9_=]{0,63}"/>
</xs:restriction>
</xs:simpleType>

Expand Down
2 changes: 2 additions & 0 deletions src/data/write_init_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
'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'}
Expand Down
Loading

0 comments on commit a54b646

Please sign in to comment.