subroutine ESMF_GridEmptyCompleteEConnA(grid, minIndex, maxIndex, &
arbIndexCount, arbIndexList, keywordEnforcer, &
connDim1, connDim2, connDim3, &
coordSys, coordTypeKind, &
coordDep1, coordDep2, coordDep3, &
distDim, name, rc)
!!
! !ARGUMENTS:
type (ESMF_Grid) :: grid
integer, intent(in), optional :: minIndex(:)
integer, intent(in) :: maxIndex(:)
integer, intent(in) :: arbIndexCount
integer, intent(in) :: arbIndexList(:,:)
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
type(ESMF_GridConn_Flag), intent(in), optional :: connDim1(:)
type(ESMF_GridConn_Flag), intent(in), optional :: connDim2(:)
type(ESMF_GridConn_Flag), intent(in), optional :: connDim3(:)
type(ESMF_CoordSys_Flag), intent(in), optional :: coordSys
type(ESMF_TypeKind_Flag), intent(in), optional :: coordTypeKind
integer, intent(in), optional :: coordDep1(:)
integer, intent(in), optional :: coordDep2(:)
integer, intent(in), optional :: coordDep3(:)
integer, intent(in), optional :: distDim(:)
character (len=*), intent(in), optional :: name
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
!
! This method takes in an empty Grid created by {\tt ESMF\_GridEmptyCreate()}.
! It then completes the grid to form a single tile, arbitrarily distributed grid
! (see Figure \ref{fig:GridDecomps}).
! To specify the arbitrary distribution, the user passes in an 2D array
! of local indices, where the first dimension is the number of local grid cells
! specified by {\tt localArbIndexCount} and the second dimension is the number of distributed
! dimensions.
!
! {\tt distDim} specifies which grid dimensions are arbitrarily distributed. The
! size of {\tt distDim} has to agree with the size of the second dimension of
! {\tt localArbIndex}.
!
! Currently this call
! only supports creating a 2D or 3D Grid, and thus, for example, {\tt maxIndex} must be of size 2 or 3.
!
! For consistency's sake the {\tt ESMF\_GridEmptyComplete()} call
! should be executed in the same set or a subset of the PETs in which the
! {\tt ESMF\_GridEmptyCreate()} call was made. If the call
! is made in a subset, the Grid objects outside that subset will
! still be "empty" and not usable.
!
! The arguments are:
! \begin{description}
! \item[grid]
! The empty {\tt ESMF\_Grid} to set information into and then commit.
! \item[{[minIndex]}]
! Tuple to start the index ranges at. If not present, defaults
! to /1,1,1,.../.
! \item[maxIndex]
! The upper extend of the grid index ranges.
! \item[arbIndexCount]
! The number of grid cells in the local DE. It is okay to have 0
! grid cell in a local DE.
! \item[arbIndexList]
! This 2D array specifies the indices of the PET LOCAL grid cells. The
! dimensions should be arbIndexCount * number of Distributed grid dimensions
! where arbIndexCount is the input argument specified below
! \item[{[connDim1]}]
! Fortran array describing the index dimension 1 connections.
! The first element represents the minimum end of dimension 1.
! The second element represents the maximum end of dimension 1.
! If array is only one element long, then that element is used
! for both the minimum and maximum end.
! Please see Section~\ref{const:gridconn} for a list of valid
! options. If not present, defaults to ESMF\_GRIDCONN\_NONE.
! \item[{[connDim2]}]
! Fortran array describing the index dimension 2 connections.
! The first element represents the minimum end of dimension 2.
! The second element represents the maximum end of dimension 2.
! If array is only one element long, then that element is used
! for both the minimum and maximum end.
! Please see Section~\ref{const:gridconn} for a list of valid
! options. If not present, defaults to ESMF\_GRIDCONN\_NONE.
! \item[{[connDim3]}]
! Fortran array describing the index dimension 3 connections.
! The first element represents the minimum end of dimension 3.
! The second element represents the maximum end of dimension 3.
! If array is only one element long, then that element is used
! for both the minimum and maximum end.
! Please see Section~\ref{const:gridconn} for a list of valid
! options. If not present, defaults to ESMF\_GRIDCONN\_NONE.
! \item[{[coordSys]}]
! The coordinate system of the grid coordinate data.
! For a full list of options, please see Section~\ref{const:coordsys}.
! If not specified then defaults to ESMF\_COORDSYS\_SPH\_DEG.
! \item[{[coordTypeKind]}]
! The type/kind of the grid coordinate data. All {\em numerical} types
! listed under section~\ref{const:typekind} are supported.
! If not specified then defaults to ESMF\_TYPEKIND\_R8.
! \item[{[coordDep1]}]
! The size of the array specifies the number of dimensions of the
! first coordinate component array. The values specify which
! of the index dimensions the corresponding coordinate
! arrays map to. The format should be /ESMF\_GRID\_ARBDIM/ where
! /ESMF\_GRID\_ARBDIM/ is mapped to the collapsed 1D dimension from all
! the arbitrarily distributed dimensions. n is the dimension that
! is not distributed (if exists).
! If not present the default is /ESMF\_GRID\_ARBDIM/ if the first dimension
! is arbitararily distributed, or /n/ if not distributed (i.e. n=1)
! Please see Section~\ref{const:arbdim} for a definition of ESMF\_GRID\_ARBDIM.
! \item[{[coordDep2]}]
! The size of the array specifies the number of dimensions of the
! second coordinate component array. The values specify which
! of the index dimensions the corresponding coordinate
! arrays map to. The format should be /ESMF\_GRID\_ARBDIM/ where
! /ESMF\_GRID\_ARBDIM/ is mapped to the collapsed 1D dimension from all
! the arbitrarily distributed dimensions. n is the dimension that
! is not distributed (if exists).
! If not present the default is /ESMF\_GRID\_ARBDIM/ if this dimension
! is arbitararily distributed, or /n/ if not distributed (i.e. n=2)
! Please see Section~\ref{const:arbdim} for a definition of ESMF\_GRID\_ARBDIM.
! \item[{[coordDep3]}]
! The size of the array specifies the number of dimensions of the
! third coordinate component array. The values specify which
! of the index dimensions the corresponding coordinate
! arrays map to. The format should be /ESMF\_GRID\_ARBDIM/ where
! /ESMF\_GRID\_ARBDIM/ is mapped to the collapsed 1D dimension from all
! the arbitrarily distributed dimensions. n is the dimension that
! is not distributed (if exists).
! If not present the default is /ESMF\_GRID\_ARBDIM/ if this dimension
! is arbitararily distributed, or /n/ if not distributed (i.e. n=3)
! Please see Section~\ref{const:arbdim} for a definition of ESMF\_GRID\_ARBDIM.
! \item[{[distDim]}]
! This array specifies which dimensions are arbitrarily distributed.
! The size of the array specifies the total distributed dimensions.
! if not specified, defaults is all dimensions will be arbitrarily
! distributed. The size has to agree with the size of the second
! dimension of {\tt localArbIndex}.
! \item[{[name]}]
! {\tt ESMF\_Grid} name.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
type(ESMF_DistGrid) :: distgrid
integer, pointer :: coordDimCount(:)
integer, pointer :: coordDimMap(:,:)
integer :: localrc
integer :: dimCount,distDimCount
integer :: i
integer, pointer :: indexArray(:,:)
logical, pointer :: isDistLocal(:)
integer, pointer :: distDimLocal(:)
integer, pointer :: minIndexLocal(:)
integer, pointer :: maxIndexLocal(:)
type(ESMF_DistgridConnection), pointer :: connList(:)
type(ESMF_CoordSys_Flag) :: coordSysLocal
! Initialize return code; assume failure until success is certain
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Get description of index space and what's undistributed
call GetIndexSpaceArb(minIndex, maxIndex, &
arbIndexCount, arbIndexList, distDim, &
dimCount, distDimCount, isDistLocal, distDimLocal, &
minIndexLocal, maxIndexLocal, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Build connection list
call SetupTileConn(dimCount, minIndexLocal, maxIndexLocal, &
connDim1, connDim2, connDim3, connList, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Create arbitrary distgrid
distgrid= ESMF_GridCreateDistgridArb(dimCount, distDimCount, isDistLocal, distDimLocal, &
minIndexLocal, maxIndexLocal, arbIndexCount, arbIndexList, connList, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Convert coordDeps to coordDimCount and coordDimMap
allocate(coordDimCount(dimCount), stat=localrc)
if (ESMF_LogFoundAllocError(localrc, msg="Allocating coordDimCount", &
ESMF_CONTEXT, rcToReturn=rc)) return
allocate(coordDimMap(dimCount,dimCount), stat=localrc)
if (ESMF_LogFoundAllocError(localrc, msg="Allocating coordDimMap", &
ESMF_CONTEXT, rcToReturn=rc)) return
call CoordInfoFromCoordDepArb(dimCount, isDistLocal, coordDep1, coordDep2, coordDep3,&
coordDimCount, coordDimMap, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Put minIndex, maxIndex into indexArray for create from distgrid
allocate(indexArray(2,dimCount), stat=localrc)
if (ESMF_LogFoundAllocError(localrc, msg="Allocating indexArray", &
ESMF_CONTEXT, rcToReturn=rc)) return
indexArray(1,:)=minIndexLocal(:)
indexArray(2,:)=maxIndexLocal(:)
! Set Default coordSys
if (present(coordSys)) then
coordSysLocal=coordSys
else
coordSysLocal=ESMF_COORDSYS_SPH_DEG
endif
! Create Grid from specification -----------------------------------------------
call ESMF_GridSetFromDistGrid(grid, coordTypeKind=coordTypeKind, &
distgrid=distgrid, &
minIndex=minIndexLocal, maxIndex=maxIndexLocal, &
distDim=distDimLocal, &
coordSys=coordSysLocal, &
coordDimCount=coordDimCount, coordDimMap=coordDimMap, &
localArbIndexCount=arbIndexCount, localArbIndex=arbIndexList, &
name=name, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Commit Grid -----------------------------------------------------------------
call ESMF_GridCommit(grid, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set internal items to be destroyed with grid
call ESMF_GridSetDestroyDistgrid(grid,destroy=.true., &
rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_GridSetDestroyDELayout(grid,destroy=.false., &
rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Clean up memory
deallocate(connList)
deallocate(minIndexLocal)
deallocate(maxIndexLocal)
deallocate(isDistLocal)
deallocate(indexArray)
deallocate(distDimLocal)
deallocate(coordDimCount)
deallocate(coordDimMap)
! Return successfully
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_GridEmptyCompleteEConnA