Skip to content

Commit

Permalink
Add the option to create nested State for NameSpace handling on a
Browse files Browse the repository at this point in the history
explicitly provided VM, and use this to target acceptor VM for field
mirroring with NameSpace.
  • Loading branch information
theurich committed Dec 6, 2024
1 parent 4c8fd1e commit e569cec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
50 changes: 32 additions & 18 deletions src/addon/NUOPC/src/NUOPC_Base.F90
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ module NUOPC_Base
! !IROUTINE: NUOPC_AddNamespace - Add a nested state with Namespace to a State
! !INTERFACE:
subroutine NUOPC_AddNamespace(state, Namespace, nestedStateName, &
nestedState, rc)
nestedState, vm, rc)
! !ARGUMENTS:
type(ESMF_State), intent(inout) :: state
character(len=*), intent(in) :: Namespace
character(len=*), intent(in), optional :: nestedStateName
type(ESMF_State), intent(out), optional :: nestedState
type(ESMF_VM), intent(in), optional :: vm
integer, intent(out), optional :: rc
! !DESCRIPTION:
! Add a Namespace to {\tt state}. Namespaces are implemented via nested
Expand All @@ -178,6 +179,10 @@ subroutine NUOPC_AddNamespace(state, Namespace, nestedStateName, &
! Name of the nested state. Defaults to {\tt Namespace}.
! \item[{[nestedState]}]
! Optional return of the newly created nested state.
! \item[{[vm]}]
! If present, the nested State created to hold the namespace is created on
! the specified {\tt ESMF\_VM} object. The default is to create the nested
! State on the VM of the current component context.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
Expand All @@ -189,9 +194,10 @@ subroutine NUOPC_AddNamespace(state, Namespace, nestedStateName, &
type(ESMF_State) :: nestedS
character(len=80) :: nestedSName
type(ESMF_StateIntent_Flag) :: stateIntent

logical :: stateIsCreated

if (present(rc)) rc = ESMF_SUCCESS

call ESMF_StateGet(state, stateIntent=stateIntent, rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out
Expand All @@ -201,31 +207,39 @@ subroutine NUOPC_AddNamespace(state, Namespace, nestedStateName, &
else
nestedSName = trim(Namespace)
endif

nestedS = ESMF_StateCreate(name=nestedSName, stateIntent=stateIntent, &
rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

call NUOPC_InitAttributes(nestedS, rc=localrc)
vm=vm, rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

call NUOPC_SetAttribute(nestedS, name="Namespace", &
value=trim(Namespace), rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

call ESMF_StateAdd(state, (/nestedS/), rc=localrc)
stateIsCreated = ESMF_StateIsCreated(nestedS, rc=rc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

if (stateIsCreated) then

call NUOPC_InitAttributes(nestedS, rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

call NUOPC_SetAttribute(nestedS, name="Namespace", &
value=trim(Namespace), rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

call ESMF_StateAdd(state, (/nestedS/), rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME, rcToReturn=rc)) return ! bail out

endif

if (present(nestedState)) &
nestedState = nestedS

end subroutine
!---------------------------------------------------------------------
!-----------------------------------------------------------------------------

!-----------------------------------------------------------------------------
!BOP
! !IROUTINE: NUOPC_AddNestedState - Add a nested state to a state with NUOPC attributes
Expand Down
8 changes: 4 additions & 4 deletions src/addon/NUOPC/src/NUOPC_Connector.F90
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,10 @@ subroutine InitializeIPDv05p1(connector, importState, exportState, clock, rc)
call ESMF_StateGet(exportState, name=stateName, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//FILENAME)) return ! bail out
! set namespace on exportState, creating a nestedState
! set namespace on exportState, creating a nestedState on acceptor VM
call NUOPC_AddNamespace(exportState, namespace=trim(namespace), &
nestedStateName=trim(stateName)//"-namespace:"//trim(namespace), &
nestedState=exportNestedState, rc=rc)
nestedState=exportNestedState, vm=vm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//FILENAME)) return ! bail out
! mirror importState items into exportNestedState
Expand Down Expand Up @@ -713,10 +713,10 @@ subroutine InitializeIPDv05p1(connector, importState, exportState, clock, rc)
call ESMF_StateGet(importState, name=stateName, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//FILENAME)) return ! bail out
! set namespace on importState, creating a nestedState
! set namespace on importState, creating a nestedState on acceptor VM
call NUOPC_AddNamespace(importState, namespace=trim(namespace), &
nestedStateName=trim(stateName)//"-namespace:"//trim(namespace), &
nestedState=importNestedState, rc=rc)
nestedState=importNestedState, vm=vm, rc=rc)
! mirror exportState items into importNestedState
call doMirror(exportState, importNestedState, acceptorVM=vm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
Expand Down

0 comments on commit e569cec

Please sign in to comment.