Skip to content

Commit

Permalink
Merge pull request #3001 from GEOS-ESM/mapl3/tclune/set-geometry-support
Browse files Browse the repository at this point in the history
Cleanup/refactor.
  • Loading branch information
tclune authored Aug 30, 2024
2 parents 2b13d85 + 88aacf9 commit b00e498
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 44 deletions.
41 changes: 41 additions & 0 deletions generic3g/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module mapl3g_Generic

public :: MAPL_GridCompGet
public :: MAPL_GridCompSetEntryPoint

public :: MAPL_AddChild
public :: MAPL_RunChild
public :: MAPL_RunChildren
Expand All @@ -78,6 +79,7 @@ module mapl3g_Generic
public :: MAPL_AddImportSpec
public :: MAPL_AddExportSpec
public :: MAPL_AddInternalSpec
public :: MAPL_SetGeometry
!!$
public :: MAPL_ResourceGet

Expand Down Expand Up @@ -148,6 +150,10 @@ module mapl3g_Generic
procedure :: add_internal_spec
end interface MAPL_AddInternalSpec

interface MAPL_SetGeometry
procedure :: set_geometry
end interface MAPL_SetGeometry

interface MAPL_GridCompSetEntryPoint
procedure gridcomp_set_entry_point
end interface MAPL_GridCompSetEntryPoint
Expand Down Expand Up @@ -924,4 +930,39 @@ logical function gridcomp_is_user(gridcomp, rc)
_RETURN(_SUCCESS)
end function gridcomp_is_user

subroutine set_geometry(gridcomp, state_intent, short_name, geom, vertical_grid, rc)
use mapl3g_VirtualConnectionPt
use mapl3g_ExtensionFamily
use mapl3g_StateItemExtension
type(ESMF_GridComp), intent(inout) :: gridcomp
type(Esmf_StateIntent_Flag), intent(in) :: state_intent
character(*), intent(in) :: short_name
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
integer, optional, intent(out) :: rc

integer :: status
type(StateRegistry), pointer :: registry
type(VirtualConnectionPt) :: v_pt
type(ExtensionFamily), pointer :: family
type(StateItemExtension), pointer :: primary
class(StateItemSpec), pointer :: spec

call MAPL_GridCompGet(gridcomp, registry=registry, _RC)
v_pt = VirtualConnectionPt(state_intent, short_name)

family => registry%get_extension_family(v_pt, _RC)
_ASSERT(family%has_primary(), 'Should not set geometry on vars from other components.')
_ASSERT(family%num_variants() == 1, 'No extensions should happen prior to this call.')

primary => family%get_primary(_RC)
_ASSERT(associated(primary), 'null pointer for primary')
spec => primary%get_spec()
_ASSERT(associated(spec), 'null pointer for spec')

call spec%set_geometry(geom=geom, vertical_grid=vertical_grid, _RC)

_RETURN(_SUCCESS)
end subroutine set_geometry

end module mapl3g_Generic
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ subroutine self_advertise(this, unusable, rc)

integer :: status

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

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
Expand Down
13 changes: 0 additions & 13 deletions generic3g/OuterMetaComponent/initialize_modify_advertised2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ module recursive subroutine initialize_modify_advertised2(this, importState, exp
_UNUSED_DUMMY(unusable)
end subroutine initialize_modify_advertised2

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
Expand Down
8 changes: 4 additions & 4 deletions generic3g/registry/StateRegistry.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module mapl3g_StateRegistry

! Actions on specs
procedure :: allocate
procedure :: initialize_specs
procedure :: set_blanket_geometry
procedure :: add_to_states

procedure :: filter ! for MatchConnection
Expand Down Expand Up @@ -625,7 +625,7 @@ subroutine allocate(this, rc)
_RETURN(_SUCCESS)
end subroutine allocate

subroutine initialize_specs(this, geom, vertical_grid, rc)
subroutine set_blanket_geometry(this, geom, vertical_grid, rc)
class(StateRegistry), target, intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
Expand All @@ -643,13 +643,13 @@ subroutine initialize_specs(this, geom, vertical_grid, rc)
extension => iter%of()
spec => extension%get_spec()
if (spec%is_active()) then
call spec%initialize(geom, vertical_grid, _RC)
call spec%set_geometry(geom, vertical_grid, _RC)
end if
end do
end associate

_RETURN(_SUCCESS)
end subroutine initialize_specs
end subroutine set_blanket_geometry

subroutine add_to_states(this, multi_state, mode, rc)
use esmf
Expand Down
6 changes: 3 additions & 3 deletions generic3g/specs/BracketSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module mapl3g_BracketSpec

procedure :: extension_cost
procedure :: make_extension
procedure :: initialize => initialize_bracket_spec
procedure :: set_geometry
end type BracketSpec

interface BracketSpec
Expand Down Expand Up @@ -292,14 +292,14 @@ subroutine make_extension(this, dst_spec, new_spec, action, rc)
_FAIL('not implemented')
end subroutine make_extension

subroutine initialize_bracket_spec(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(BracketSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_SUCCESS)
end subroutine initialize_bracket_spec
end subroutine set_geometry

end module mapl3g_BracketSpec
6 changes: 3 additions & 3 deletions generic3g/specs/FieldSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module mapl3g_FieldSpec
procedure :: make_extension

procedure :: set_info
procedure :: initialize => initialize_field_spec
procedure :: set_geometry

end type FieldSpec

Expand Down Expand Up @@ -234,7 +234,7 @@ function get_regrid_method_(stdname, rc) result(regrid_method)
_RETURN(_SUCCESS)
end function get_regrid_method_

subroutine initialize_field_spec(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(FieldSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
Expand All @@ -259,7 +259,7 @@ subroutine initialize_field_spec(this, geom, vertical_grid, rc)

_RETURN(_SUCCESS)

end subroutine initialize_field_spec
end subroutine set_geometry

!# function new_FieldSpec_defaults(ungridded_dims, geom, units) result(field_spec)
!# type(FieldSpec) :: field_spec
Expand Down
6 changes: 3 additions & 3 deletions generic3g/specs/InvalidSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module mapl3g_InvalidSpec

procedure :: make_extension
procedure :: extension_cost
procedure :: initialize => initialize_invalid_spec
procedure :: set_geometry => set_geometry
end type InvalidSpec


Expand Down Expand Up @@ -156,7 +156,7 @@ integer function extension_cost(this, src_spec, rc) result(cost)

end function extension_cost

subroutine initialize_invalid_spec(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(InvalidSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
Expand All @@ -166,6 +166,6 @@ subroutine initialize_invalid_spec(this, geom, vertical_grid, rc)

_FAIL('Attempt to initialize item of type InvalidSpec')

end subroutine initialize_invalid_spec
end subroutine set_geometry

end module mapl3g_InvalidSpec
6 changes: 3 additions & 3 deletions generic3g/specs/ServiceSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module mapl3g_ServiceSpec
procedure :: extension_cost
procedure :: add_to_state
procedure :: add_to_bundle
procedure :: initialize => initialize_service_spec
procedure :: set_geometry
!!$ procedure :: check_complete
end type ServiceSpec

Expand Down Expand Up @@ -205,7 +205,7 @@ integer function extension_cost(this, src_spec, rc) result(cost)
_RETURN(_SUCCESS)
end function extension_cost

subroutine initialize_service_spec(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(ServiceSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
Expand All @@ -231,6 +231,6 @@ subroutine initialize_service_spec(this, geom, vertical_grid, rc)
this%dependency_specs = specs

_RETURN(_SUCCESS)
end subroutine initialize_service_spec
end subroutine set_geometry

end module mapl3g_ServiceSpec
6 changes: 3 additions & 3 deletions generic3g/specs/StateItemSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module mapl3g_StateItemSpec

procedure(I_add_to_state), deferred :: add_to_state
procedure(I_add_to_bundle), deferred :: add_to_bundle
procedure(I_initialize), deferred :: initialize
procedure(I_set_geometry), deferred :: set_geometry

procedure, non_overridable :: set_allocated
procedure, non_overridable :: is_allocated
Expand Down Expand Up @@ -122,15 +122,15 @@ subroutine I_add_to_bundle(this, bundle, rc)
integer, optional, intent(out) :: rc
end subroutine I_add_to_bundle

subroutine I_initialize(this, geom, vertical_grid, rc)
subroutine I_set_geometry(this, geom, vertical_grid, rc)
use esmf, only: ESMF_Geom
use mapl3g_VerticalGrid, only: VerticalGrid
import StateItemSpec
class(StateItemSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
integer, optional, intent(out) :: rc
end subroutine I_initialize
end subroutine I_set_geometry

end interface

Expand Down
6 changes: 3 additions & 3 deletions generic3g/specs/StateSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module mapl3g_StateSpec
type(ESMF_State) :: payload
type(StateItemSpecMap) :: item_specs
contains
procedure :: initialize
procedure :: set_geometry
procedure :: add_item
procedure :: get_item

Expand All @@ -44,7 +44,7 @@ module mapl3g_StateSpec
contains

! Nothing defined at this time.
subroutine initialize(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(StateSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
Expand All @@ -54,7 +54,7 @@ subroutine initialize(this, geom, vertical_grid, rc)
integer :: status

_RETURN(_SUCCESS)
end subroutine initialize
end subroutine set_geometry

subroutine add_item(this, name, item)
class(StateSpec), target, intent(inout) :: this
Expand Down
8 changes: 4 additions & 4 deletions generic3g/specs/WildcardSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module mapl3g_WildcardSpec
procedure :: add_to_state
procedure :: add_to_bundle
procedure :: extension_cost
procedure :: initialize => initialize_wildcard_spec
procedure :: set_geometry

end type WildcardSpec

Expand Down Expand Up @@ -236,17 +236,17 @@ integer function extension_cost(this, src_spec, rc) result(cost)
_RETURN(_SUCCESS)
end function extension_cost

subroutine initialize_wildcard_spec(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(WildcardSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
integer, optional, intent(out) :: rc

integer :: status

call this%reference_spec%initialize(geom, vertical_grid, _RC)
call this%reference_spec%set_geometry(geom, vertical_grid, _RC)

_RETURN(_SUCCESS)
end subroutine initialize_wildcard_spec
end subroutine set_geometry

end module mapl3g_WildcardSpec
6 changes: 3 additions & 3 deletions generic3g/tests/MockItemSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module MockItemSpecMod
procedure :: create
procedure :: destroy
procedure :: allocate
procedure :: initialize => initialize_mockspec
procedure :: set_geometry

procedure :: connect_to
procedure :: can_connect_to
Expand Down Expand Up @@ -64,14 +64,14 @@ function new_MockItemSpec(name, subtype) result(spec)

end function new_MockItemSpec

subroutine initialize_mockspec(this, geom, vertical_grid, rc)
subroutine set_geometry(this, geom, vertical_grid, rc)
class(MockItemSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
integer, optional, intent(out) :: rc

_RETURN(_SUCCESS)
end subroutine initialize_mockspec
end subroutine set_geometry

subroutine create(this, rc)
class(MockItemSpec), intent(inout) :: this
Expand Down
2 changes: 1 addition & 1 deletion generic3g/tests/Test_ModelVerticalGrid.pf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contains
default_value=3.)
allocate(ple_spec, source=make_itemSpec(var_spec, r, rc=status))
_VERIFY(status)
call ple_spec%initialize(geom=geom, vertical_grid=vgrid, _RC)
call ple_spec%set_geometry(geom=geom, vertical_grid=vgrid, _RC)

call r%add_primary_spec(ple_pt, ple_spec)

Expand Down

0 comments on commit b00e498

Please sign in to comment.