Skip to content

Commit

Permalink
Merge pull request #2714 from GEOS-ESM/mapl3/tclune/clock-advance-phase
Browse files Browse the repository at this point in the history
Mapl3/tclune/clock advance phase
  • Loading branch information
mathomp4 authored Apr 10, 2024
2 parents 0d7986b + 5f774c5 commit a13878d
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 163 deletions.
29 changes: 14 additions & 15 deletions generic3g/GenericGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ subroutine set_entry_points(gridcomp, rc)
integer :: status
integer :: phase

associate (phases => outer_meta%get_phases(ESMF_METHOD_RUN))
do phase = 1, phases%size()
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_RUN, run, phase=phase, _RC)
end do
end associate

! Mandatory generic initialize phases
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_CLOCK, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_GEOM, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_ADVERTISE, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_POST_ADVERTISE, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_REALIZE, _RC)
!# call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_RESTORE, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_USER, _RC)

! Run phases, including mandatory
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_RUN, run, phase=GENERIC_RUN_CLOCK_ADVANCE, _RC)
associate (phases => outer_meta%get_phases(ESMF_METHOD_RUN))
do phase = 1, phases%size()
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_RUN, run, phase=phase, _RC)
end do
end associate

call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_FINALIZE, finalize, _RC)
!# call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_READRESTART, read_restart, _RC)
!# call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_WRITERESTART, write_restart, _RC)
Expand Down Expand Up @@ -149,20 +150,18 @@ recursive subroutine initialize(gridcomp, importState, exportState, clock, rc)
outer_meta => get_outer_meta(gridcomp, _RC)
call ESMF_GridCompGet(gridcomp, currentPhase=phase, _RC)
select case (phase)
case (GENERIC_INIT_CLOCK)
call outer_meta%initialize_clock(clock, _RC)
case (GENERIC_INIT_GEOM)
call outer_meta%initialize_geom(clock, _RC)
call outer_meta%initialize_geom(_RC)
case (GENERIC_INIT_ADVERTISE)
call outer_meta%initialize_advertise(clock, _RC)
call outer_meta%initialize_advertise(_RC)
case (GENERIC_INIT_POST_ADVERTISE)
call outer_meta%initialize_post_advertise(importState, exportState, clock, _RC)
case (GENERIC_INIT_REALIZE)
call outer_meta%initialize_realize(clock, _RC)
call outer_meta%initialize_realize(_RC)
!# case (GENERIC_INIT_RESTORE)
!# call outer_meta%initialize_realize(clock, _RC)
!# call outer_meta%initialize_realize(_RC)
case (GENERIC_INIT_USER)
call outer_meta%initialize_user(clock, _RC)
call outer_meta%initialize_user(_RC)
case default
_FAIL('Unknown generic phase ')
end select
Expand Down Expand Up @@ -191,7 +190,7 @@ recursive subroutine run(gridcomp, importState, exportState, clock, rc)
phases => outer_meta%get_phases(ESMF_METHOD_RUN)
phase_name => phases%of(phase)

call outer_meta%run(clock, phase_name=phase_name, _RC)
call outer_meta%run(phase_name=phase_name, _RC)

_RETURN(ESMF_SUCCESS)
end subroutine run
Expand Down
13 changes: 10 additions & 3 deletions generic3g/GenericPhases.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,43 @@ module mapl3g_GenericPhases

! Named constants
public :: GENERIC_INIT_PHASE_SEQUENCE
public :: GENERIC_INIT_CLOCK
public :: GENERIC_INIT_GEOM
public :: GENERIC_INIT_ADVERTISE
public :: GENERIC_INIT_POST_ADVERTISE
public :: GENERIC_INIT_REALIZE
public :: GENERIC_INIT_USER

public :: GENERIC_RUN_CLOCK_ADVANCE
public :: GENERIC_RUN_USER

public :: GENERIC_FINALIZE_USER

enum, bind(c)
!!!! IMPORTANT: USER phase must be "1" !!!!
enumerator :: GENERIC_INIT_USER = 1
enumerator :: GENERIC_INIT_CLOCK
enumerator :: GENERIC_INIT_GEOM
enumerator :: GENERIC_INIT_ADVERTISE
enumerator :: GENERIC_INIT_POST_ADVERTISE
enumerator :: GENERIC_INIT_REALIZE
end enum

enum, bind(c)
enumerator :: GENERIC_RUN_CLOCK_ADVANCE = 1
enumerator :: GENERIC_RUN_USER
end enum

enum, bind(c)
!!!! IMPORTANT: USER phase must be "1" !!!!
enumerator :: GENERIC_FINALIZE_USER = 1
end enum

integer, parameter :: GENERIC_INIT_PHASE_SEQUENCE(*) = [ &
GENERIC_INIT_CLOCK, &
GENERIC_INIT_GEOM, &
GENERIC_INIT_ADVERTISE, &
GENERIC_INIT_POST_ADVERTISE, &
GENERIC_INIT_REALIZE, &
GENERIC_INIT_USER &
]


end module mapl3g_GenericPhases
6 changes: 6 additions & 0 deletions generic3g/GriddedComponentDriver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module mapl3g_GriddedComponentDriver
procedure :: run
procedure :: initialize
procedure :: finalize
procedure :: clock_advance

! Accessors
procedure :: get_clock
Expand Down Expand Up @@ -97,6 +98,11 @@ recursive module subroutine run_import_couplers(this, rc)
integer, optional, intent(out) :: rc
end subroutine run_import_couplers

module subroutine clock_advance(this, rc)
class(GriddedComponentDriver), intent(inout) :: this
integer, optional, intent(out) :: rc
end subroutine clock_advance

end interface

contains
Expand Down
11 changes: 11 additions & 0 deletions generic3g/GriddedComponentDriver_smod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,15 @@ recursive module subroutine run_export_couplers(this, unusable, phase_idx, rc)
_RETURN(_SUCCESS)
end subroutine run_export_couplers

module subroutine clock_advance(this, rc)
class(GriddedComponentDriver), intent(inout) :: this
integer, optional, intent(out) :: rc

integer :: status

call ESMF_ClockAdvance(this%clock, _RC)

_RETURN(_SUCCESS)
end subroutine clock_advance

end submodule GriddedComponentDriver_run_smod
Loading

0 comments on commit a13878d

Please sign in to comment.