Skip to content

Commit

Permalink
Merge pull request #2999 from GEOS-ESM/mapl3/tclune/init-phase-refact…
Browse files Browse the repository at this point in the history
…oring

Mapl3/tclune/init phase refactoring
  • Loading branch information
tclune authored Aug 29, 2024
2 parents 755082c + 2b8a24d commit 2b13d85
Show file tree
Hide file tree
Showing 27 changed files with 395 additions and 372 deletions.
4 changes: 2 additions & 2 deletions generic3g/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ esma_add_fortran_submodules(
get_child_by_name.F90 run_child_by_name.F90 run_children.F90
get_outer_meta_from_outer_gc.F90 attach_outer_meta.F90 free_outer_meta.F90
get_phases.F90 set_hconfig.F90 get_hconfig.F90 get_geom.F90
initialize_advertise_geom.F90
initialize_advertise.F90 initialize_modify_advertise.F90
initialize_advertise.F90
initialize_modify_advertised.F90 initialize_modify_advertised2.F90
initialize_realize.F90 recurse.F90 apply_to_children_custom.F90
initialize_user.F90 run_custom.F90 run_user.F90 run_clock_advance.F90
read_restart.F90 write_restart.F90 get_name.F90 get_gridcomp.F90
Expand Down
12 changes: 6 additions & 6 deletions generic3g/GenericGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ subroutine set_entry_points(gridcomp, rc)
integer, parameter :: NUM_GENERIC_RUN_PHASES = 1

! Mandatory generic initialize phases
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_ADVERTISE_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_MODIFY_ADVERTISE, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_MODIFY_ADVERTISED, _RC)
call ESMF_GridCompSetEntryPoint(gridcomp, ESMF_METHOD_INITIALIZE, initialize, phase=GENERIC_INIT_MODIFY_ADVERTISED2, _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)
Expand Down Expand Up @@ -159,12 +159,12 @@ 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_ADVERTISE_GEOM)
call outer_meta%initialize_advertise_geom(_RC)
case (GENERIC_INIT_ADVERTISE)
call outer_meta%initialize_advertise(_RC)
case (GENERIC_INIT_MODIFY_ADVERTISE)
call outer_meta%initialize_modify_advertise(importState, exportState, clock, _RC)
case (GENERIC_INIT_MODIFY_ADVERTISED)
call outer_meta%initialize_modify_advertised(importState, exportState, clock, _RC)
case (GENERIC_INIT_MODIFY_ADVERTISED2)
call outer_meta%initialize_modify_advertised2(importState, exportState, clock, _RC)
case (GENERIC_INIT_REALIZE)
call outer_meta%initialize_realize(_RC)
!# case (GENERIC_INIT_RESTORE)
Expand Down
11 changes: 6 additions & 5 deletions generic3g/GenericPhases.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module mapl3g_GenericPhases
! Named constants
! Init phases
public :: GENERIC_INIT_PHASE_SEQUENCE
public :: GENERIC_INIT_ADVERTISE_GEOM
public :: GENERIC_INIT_ADVERTISE
public :: GENERIC_INIT_MODIFY_ADVERTISE
public :: GENERIC_INIT_MODIFY_ADVERTISED
public :: GENERIC_INIT_MODIFY_ADVERTISED2
public :: GENERIC_INIT_REALIZE
public :: GENERIC_INIT_USER

Expand All @@ -24,7 +24,8 @@ module mapl3g_GenericPhases
enumerator :: GENERIC_INIT_USER = 1
enumerator :: GENERIC_INIT_ADVERTISE_GEOM
enumerator :: GENERIC_INIT_ADVERTISE
enumerator :: GENERIC_INIT_MODIFY_ADVERTISE
enumerator :: GENERIC_INIT_MODIFY_ADVERTISED
enumerator :: GENERIC_INIT_MODIFY_ADVERTISED2
enumerator :: GENERIC_INIT_REALIZE
end enum

Expand All @@ -44,9 +45,9 @@ module mapl3g_GenericPhases

integer, parameter :: GENERIC_INIT_PHASE_SEQUENCE(*) = &
[ &
GENERIC_INIT_ADVERTISE_GEOM, &
GENERIC_INIT_ADVERTISE, &
GENERIC_INIT_MODIFY_ADVERTISE, &
GENERIC_INIT_MODIFY_ADVERTISED, &
GENERIC_INIT_MODIFY_ADVERTISED2, &
GENERIC_INIT_REALIZE, &
GENERIC_INIT_USER &
]
Expand Down
23 changes: 13 additions & 10 deletions generic3g/OuterMetaComponent.F90
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ module mapl3g_OuterMetaComponent

procedure :: run_custom
procedure :: initialize_user
procedure :: initialize_advertise_geom
procedure :: initialize_advertise
procedure :: initialize_modify_advertise
procedure :: initialize_modify_advertised
procedure :: initialize_modify_advertised2
procedure :: initialize_realize

procedure :: run_user
Expand Down Expand Up @@ -234,29 +234,32 @@ module function get_geom(this) result(geom)
class(OuterMetaComponent), intent(inout) :: this
end function get_geom

module recursive subroutine initialize_advertise_geom(this, unusable, rc)
module recursive subroutine initialize_advertise(this, unusable, rc)
class(OuterMetaComponent), target, intent(inout) :: this
! optional arguments
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
end subroutine initialize_advertise_geom
end subroutine initialize_advertise

module recursive subroutine initialize_advertise(this, unusable, rc)
class(OuterMetaComponent), intent(inout) :: this
module recursive subroutine initialize_modify_advertised(this, importState, exportState, clock, unusable, rc)
class(OuterMetaComponent), target, intent(inout) :: this
! optional arguments
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
end subroutine initialize_advertise
end subroutine initialize_modify_advertised

module recursive subroutine initialize_modify_advertise(this, importState, exportState, clock, unusable, rc)
class(OuterMetaComponent), intent(inout) :: this
module recursive subroutine initialize_modify_advertised2(this, importState, exportState, clock, unusable, rc)
class(OuterMetaComponent), target, intent(inout) :: this
! optional arguments
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
end subroutine initialize_modify_advertise
end subroutine initialize_modify_advertised2

module recursive subroutine initialize_realize(this, unusable, rc)
class(OuterMetaComponent), intent(inout) :: this
Expand Down
58 changes: 30 additions & 28 deletions generic3g/OuterMetaComponent/initialize_advertise.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,45 @@
contains

module recursive subroutine initialize_advertise(this, unusable, rc)
class(OuterMetaComponent), intent(inout) :: this
class(OuterMetaComponent), target, intent(inout) :: this
! optional arguments
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

integer :: status
class(GriddedComponentDriver), pointer :: provider
type(ESMF_GridComp) :: provider_gc
type(OuterMetaComponent), pointer :: provider_meta
type(MaplGeom), pointer :: mapl_geom
type(GeomManager), pointer :: geom_mgr
character(*), parameter :: PHASE_NAME = 'GENERIC::INIT_ADVERTISE'

call apply_to_children(this, set_child_geom, _RC)


call this%run_custom(ESMF_METHOD_INITIALIZE, PHASE_NAME, _RC)
call self_advertise(this, _RC)

associate (geometry_spec => this%component_spec%geometry_spec)
if (allocated(geometry_spec%geom_spec)) then
geom_mgr => get_geom_manager()
mapl_geom => geom_mgr%get_mapl_geom(geometry_spec%geom_spec, _RC)
this%geom = mapl_geom%get_geom()
end if
if (allocated(geometry_spec%vertical_grid)) then
this%vertical_grid = geometry_spec%vertical_grid
end if
end associate

call recurse(this, phase_idx=GENERIC_INIT_ADVERTISE, _RC)

associate (geometry_spec => this%component_spec%geometry_spec)
if (geometry_spec%kind == GEOMETRY_FROM_CHILD) then
provider => this%children%at(geometry_spec%provider, _RC)
provider_gc = provider%get_gridcomp()
provider_meta => get_outer_meta(provider_gc, _RC)
_ASSERT(allocated(provider_meta%geom), 'Specified child does not provide a geom.')
this%geom = provider_meta%geom
end if
end associate

call process_connections(this, _RC)
call this%registry%propagate_unsatisfied_imports(_RC)
call this%registry%propagate_exports(_RC)
Expand All @@ -31,29 +55,8 @@ module recursive subroutine initialize_advertise(this, unusable, rc)
_UNUSED_DUMMY(unusable)
contains

subroutine set_child_geom(this, child_meta, rc)
class(OuterMetaComponent), target, intent(inout) :: this
type(OuterMetaComponent), target, intent(inout) :: child_meta
integer, optional, intent(out) :: rc

integer :: status

associate(kind => child_meta%component_spec%geometry_spec%kind)
_RETURN_IF(kind /= GEOMETRY_FROM_PARENT)

if (allocated(this%geom)) then
call child_meta%set_geom(this%geom)
end if
if (allocated(this%vertical_grid)) then
call child_meta%set_vertical_grid(this%vertical_grid)
end if
end associate

_RETURN(ESMF_SUCCESS)
end subroutine set_child_geom

subroutine self_advertise(this, unusable, rc)
class(OuterMetaComponent), intent(inout) :: this
class(OuterMetaComponent), target, intent(inout) :: this
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

Expand Down Expand Up @@ -96,8 +99,7 @@ subroutine advertise_variable(var_spec, registry, geom, vertical_grid, unusable,
allocate(item_spec, source=make_ItemSpec(var_spec, registry, rc=status))
_VERIFY(status)
call item_spec%create(_RC)
call item_spec%initialize(geom, vertical_grid, _RC)

!# call item_spec%initialize(geom, vertical_grid, _RC)

virtual_pt = var_spec%make_virtualPt()
call registry%add_primary_spec(virtual_pt, item_spec)
Expand Down
60 changes: 0 additions & 60 deletions generic3g/OuterMetaComponent/initialize_advertise_geom.F90

This file was deleted.

89 changes: 89 additions & 0 deletions generic3g/OuterMetaComponent/initialize_modify_advertised.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "MAPL_Generic.h"

submodule (mapl3g_OuterMetaComponent) initialize_modify_advertised_smod
implicit none

contains

module recursive subroutine initialize_modify_advertised(this, importState, exportState, clock, unusable, rc)
class(OuterMetaComponent), target, intent(inout) :: this
! optional arguments
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

integer :: status
character(*), parameter :: PHASE_NAME = 'GENERIC::INIT_MODIFY_ADVERTISED'
type(MultiState) :: outer_states, user_states

call apply_to_children(this, set_child_geom, _RC)
call this%run_custom(ESMF_METHOD_INITIALIZE, PHASE_NAME, _RC)
call recurse(this, phase_idx=GENERIC_INIT_MODIFY_ADVERTISED, _RC)

call self_advertise(this, _RC)
call process_connections(this, _RC)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
contains

subroutine set_child_geom(this, child_meta, rc)
class(OuterMetaComponent), target, intent(inout) :: this
type(OuterMetaComponent), target, intent(inout) :: child_meta
integer, optional, intent(out) :: rc

integer :: status

associate(kind => child_meta%component_spec%geometry_spec%kind)
_RETURN_IF(kind /= GEOMETRY_FROM_PARENT)

if (allocated(this%geom)) then
call child_meta%set_geom(this%geom)
end if
if (allocated(this%vertical_grid)) then
call child_meta%set_vertical_grid(this%vertical_grid)
end if
end associate

_RETURN(ESMF_SUCCESS)
end subroutine set_child_geom

end subroutine initialize_modify_advertised


subroutine self_advertise(this, unusable, rc)
class(OuterMetaComponent), target, intent(inout) :: this
class(KE), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

integer :: status

call this%registry%initialize_specs(this%geom, this%vertical_grid, _RC)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine self_advertise

subroutine process_connections(this, rc)
class(OuterMetaComponent), intent(inout) :: this
integer, optional, intent(out) :: rc

integer :: status
type(ConnectionVectorIterator) :: iter
class(Connection), pointer :: c

associate (e => this%component_spec%connections%end())
iter = this%component_spec%connections%begin()
do while (iter /= e)
c => iter%of()
call c%connect(this%registry, _RC)
call iter%next()
end do
end associate

_RETURN(_SUCCESS)
end subroutine process_connections

end submodule initialize_modify_advertised_smod
Loading

0 comments on commit 2b13d85

Please sign in to comment.