subroutine user_init(comp, importState, exportState, clock, rc)
type(ESMF_CplComp) :: comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local variables
integer :: itemcount, localPet
type(ESMF_ArrayBundle):: srcArraybundle, dstArraybundle
type(ESMF_VM) :: vm
real(ESMF_KIND_R8):: factorList(10000)
integer:: i, factorIndexList(2,10000)
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Coupler Init starting"
call ESMF_StateGet(importState, itemcount=itemcount, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
print *, "Import State contains ", itemcount, " items."
! Need to reconcile import and export states
call ESMF_CplCompGet(comp, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StateReconcile(importState, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StateReconcile(exportState, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Get source ArrayBundle out of import state
call ESMF_StateGet(importState, "srcAryBndl", srcArraybundle, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Get destination ArrayBundle out of export state
call ESMF_StateGet(exportState, "dstAryBndl", dstArraybundle, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! get localPet
call ESMF_VMGet(vm, localPet=localPet, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Setup identity sparse matrix as a combination of PET 0 and PET 4
! there are 15000 elements on the diagonal, defined as two overlapping
! lists of each 10000 elements (overlapping 5000).
if (localPet==0) then
factorIndexList(1,:) = (/(i,i=1,10000)/)
factorIndexList(2,:) = factorIndexList(1,:)
do i=1, 5000
factorList(i) = 1.d0
enddo
do i=5001, 10000
factorList(i) = .253d0
enddo
endif
if (localPet==4) then
factorIndexList(1,:) = (/(i,i=5001,15000)/)
factorIndexList(2,:) = factorIndexList(1,:)
do i=1, 5000
factorList(i) = .747d0
enddo
do i=5001, 10000
factorList(i) = 1.d0
enddo
endif
! Precompute and store an ArrayBundleSMM operation
if (localPet==0 .or. localPet==4) then
! only PET 0 and PET 4 provide factors
call ESMF_ArrayBundleSMMStore(&
srcArrayBundle=srcArraybundle, dstArrayBundle=dstArraybundle, &
routehandle=routehandle, factorList=factorList, &
factorIndexList=factorIndexList, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
else
call ESMF_ArrayBundleSMMStore(&
srcArrayBundle=srcArraybundle, dstArrayBundle=dstArraybundle, &
routehandle=routehandle, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
endif
print *, "User Coupler Init returning"
end subroutine user_init