Skip to content

Commit

Permalink
Merge branch 'release/MAPL-v3' into feature/tclune/#3096-action-inval…
Browse files Browse the repository at this point in the history
…idate_phase
  • Loading branch information
tclune authored Oct 28, 2024
2 parents 910e9b9 + 34ef817 commit 43a694a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 14 deletions.
99 changes: 86 additions & 13 deletions esmf_utils/InfoUtilities.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ module mapl3g_InfoUtilities
public :: MAPL_InfoSet

public :: MAPL_InfoCreateFromInternal
public :: MAPL_InfoCreateFromShared

public :: MAPL_InfoGetShared
public :: MAPL_InfoSetShared
public :: MAPL_InfoCopyShared
public :: MAPL_InfoGetPrivate
public :: MAPL_InfoSetPrivate
public :: MAPL_InfoGetInternal
Expand All @@ -50,6 +52,10 @@ module mapl3g_InfoUtilities
procedure :: info_bundle_create_from_internal
end interface MAPL_InfoCreateFromInternal

interface MAPL_InfoCreateFromShared
procedure :: info_field_create_from_shared
end interface MAPL_InfoCreateFromShared

! Direct access through ESMF_Info object
interface MAPL_InfoGet
procedure :: info_get_string
Expand All @@ -62,7 +68,8 @@ module mapl3g_InfoUtilities

! Access info object from esmf stateitem
interface MAPL_InfoGetShared
procedure :: info_get_state_shared_string
procedure :: info_state_get_shared_string
procedure :: info_field_get_shared_i4
procedure :: info_stateitem_get_shared_string
procedure :: info_stateitem_get_shared_logical
procedure :: info_stateitem_get_shared_i4
Expand All @@ -72,7 +79,8 @@ module mapl3g_InfoUtilities
end interface MAPL_InfoGetShared

interface MAPL_InfoSetShared
procedure :: info_set_state_shared_string
procedure :: info_state_set_shared_string
procedure :: info_field_set_shared_i4
procedure :: info_stateitem_set_shared_string
procedure :: info_stateitem_set_shared_logical
procedure :: info_stateitem_set_shared_i4
Expand All @@ -81,6 +89,10 @@ module mapl3g_InfoUtilities
procedure :: info_stateitem_set_shared_r4_1d
end interface MAPL_InfoSetShared

interface MAPL_InfoCopyShared
procedure :: info_field_copy_shared
end interface MAPL_InfoCopyShared

interface MAPL_InfoGetPrivate
procedure :: info_stateitem_get_private_string
procedure :: info_stateitem_get_private_logical
Expand Down Expand Up @@ -275,28 +287,41 @@ end function info_field_create_from_internal
function info_bundle_create_from_internal(bundle, key, rc) result(info)
type(ESMF_Info) :: info
type(ESMF_FieldBundle), intent(in) :: bundle
character(*), optional, intent(in) :: key
character(*), optional, intent(in) :: key
integer, optional, intent(out) :: rc

type(ESMF_Info) :: host_info
integer :: status
character(:), allocatable :: key_

call ESMF_InfoGetFromHost(bundle, host_info, _RC)

integer :: status

key_ = INFO_INTERNAL_NAMESPACE
if (present(key)) then
key_ = concat(key_, key)
end if

call ESMF_InfoGetFromHost(bundle, host_info, _RC)
info = ESMF_InfoCreate(host_info, key=key_, _RC)

_RETURN(_SUCCESS)
end function info_bundle_create_from_internal

function info_field_create_from_shared(field, rc) result(info)
type(ESMF_Info) :: info
type(ESMF_Field), intent(in) :: field
integer, optional, intent(out) :: rc

integer :: status
type(ESMF_Info) :: host_info

call ESMF_InfoGetFromHost(field, host_info, _RC)
info = ESMF_InfoCreate(host_info, key=INFO_SHARED_NAMESPACE, _RC)

_RETURN(_SUCCESS)
end function info_field_create_from_shared

! MAPL_InfoGetShared

subroutine info_get_state_shared_string(state, key, value, unusable, rc)
! MAPL_InfoGetShared
subroutine info_state_get_shared_string(state, key, value, unusable, rc)
type(ESMF_State), intent(in) :: state
character(*), intent(in) :: key
character(:), allocatable, intent(out) :: value
Expand All @@ -310,7 +335,23 @@ subroutine info_get_state_shared_string(state, key, value, unusable, rc)
call MAPL_InfoGet(state_info, key=concat(INFO_SHARED_NAMESPACE,key), value=value, _RC)

_RETURN(_SUCCESS)
end subroutine info_get_state_shared_string
end subroutine info_state_get_shared_string

subroutine info_field_get_shared_i4(field, key, value, unusable, rc)
type(ESMF_Field), intent(in) :: field
character(*), intent(in) :: key
integer(kind=ESMF_KIND_I4), intent(out) :: value
class(KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

integer :: status
type(ESMF_Info) :: field_info

call ESMF_InfoGetFromHost(field, field_info, _RC)
call MAPL_InfoGet(field_info, key=concat(INFO_SHARED_NAMESPACE,key), value=value, _RC)

_RETURN(_SUCCESS)
end subroutine info_field_get_shared_i4

subroutine info_stateitem_get_shared_string(state, short_name, key, value, rc)
type(ESMF_State), intent(in) :: state
Expand Down Expand Up @@ -411,7 +452,7 @@ end subroutine info_stateitem_get_shared_r4_1d

! MAPL_InfoSetShared

subroutine info_set_state_shared_string(state, key, value, unusable, rc)
subroutine info_state_set_shared_string(state, key, value, unusable, rc)
type(ESMF_State), intent(in) :: state
character(*), intent(in) :: key
character(*), intent(in) :: value
Expand All @@ -425,7 +466,22 @@ subroutine info_set_state_shared_string(state, key, value, unusable, rc)
call MAPL_InfoSet(state_info, key=concat(INFO_SHARED_NAMESPACE,key), value=value, _RC)

_RETURN(_SUCCESS)
end subroutine info_set_state_shared_string
end subroutine info_state_set_shared_string

subroutine info_field_set_shared_i4(field, key, value, rc)
type(ESMF_Field), intent(in) :: field
character(*), intent(in) :: key
integer(kind=ESMF_KIND_I4), intent(in) :: value
integer, optional, intent(out) :: rc

integer :: status
type(ESMF_Info) :: field_info

call ESMF_InfoGetFromHost(field, field_info, _RC)
call MAPL_InfoSet(field_info, key=concat(INFO_SHARED_NAMESPACE,key), value=value, _RC)

_RETURN(_SUCCESS)
end subroutine info_field_set_shared_i4

subroutine info_stateitem_set_shared_string(state, short_name, key, value, rc)
type(ESMF_State), intent(in) :: state
Expand Down Expand Up @@ -1221,6 +1277,23 @@ function concat(namespace, key) result(full_key)
full_key = namespace // '/' //key

end function concat

subroutine info_field_copy_shared(field_in, field_out, rc)
type(ESMF_Field), intent(in) :: field_in
type(ESMF_Field), intent(inout) :: field_out
integer, optional, intent(out) :: rc

integer :: status
type(ESMF_Info) :: shared_info, info_out

shared_info = MAPL_InfoCreateFromShared(field_in, _RC)
call ESMF_InfoGetFromHost(field_out, info_out, _RC)
! 'force' may be needed in next, but ideally the import field will not yet have an shared space
call MAPL_InfoSet(info_out, INFO_SHARED_NAMESPACE, shared_info, _RC)

_RETURN(_SUCCESS)
end subroutine info_field_copy_shared


end module mapl3g_InfoUtilities

Expand Down
27 changes: 26 additions & 1 deletion esmf_utils/tests/Test_InfoUtilities.pf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contains

@test
subroutine test_info_get_internal_info()
type(ESMF_Info) :: info
type(ESMF_Info) :: subinfo
integer :: status
type(ESMF_Field) :: field
Expand Down Expand Up @@ -350,6 +349,10 @@ contains
call MAPL_InfoSetNameSpace(state_b, namespace='/compB', _RC)


! Same field goes in multiple states. Accesses to private
! attributes first retrieves the namespace from state.
! Note that this means "raw" access to private attributes is
! not supported as the context in not available.
field = ESMF_FieldEmptyCreate(name='f', _RC)
call ESMF_StateAdd(state_a, [field], _RC)
call ESMF_StateAdd(state_b, [field], _RC)
Expand Down Expand Up @@ -550,6 +553,28 @@ contains

end subroutine test_setInternal_bundle

@test
subroutine test_copy_shared_field()
type(ESMF_Field) :: f_in, f_out
integer :: status
integer :: ia, ib

f_in = ESMF_FieldEmptyCreate(name='f_in', _RC)
f_out= ESMF_FieldEmptyCreate(name='f_out', _RC)

call MAPL_InfoSetShared(f_in, key='a', value=1, _RC)
call MAPL_InfoSetShared(f_in, key='b', value=2, _RC)

call MAPL_InfoCopyShared(f_in, f_out, _RC)

call MAPL_InfoGetShared(f_out, key='a', value=ia, _RC)
call MAPL_InfoGetShared(f_out, key='b', value=ib, _RC)

@assert_that(ia, is(1))
@assert_that(ib, is(2))

end subroutine test_copy_shared_field

end module Test_InfoUtilities


0 comments on commit 43a694a

Please sign in to comment.