diff --git a/src/addon/NUOPC/src/NUOPC_Base.F90 b/src/addon/NUOPC/src/NUOPC_Base.F90 index 2f3bf35a4a..891b39f808 100644 --- a/src/addon/NUOPC/src/NUOPC_Base.F90 +++ b/src/addon/NUOPC/src/NUOPC_Base.F90 @@ -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 @@ -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} @@ -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 @@ -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 diff --git a/src/addon/NUOPC/src/NUOPC_Connector.F90 b/src/addon/NUOPC/src/NUOPC_Connector.F90 index 075734a624..7540b577fd 100644 --- a/src/addon/NUOPC/src/NUOPC_Connector.F90 +++ b/src/addon/NUOPC/src/NUOPC_Connector.F90 @@ -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 @@ -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, &