function ESMF_GridCreate2PeriDimA(minIndex, maxIndex, &
arbIndexCount, arbIndexList, keywordEnforcer, &
coordSys, coordTypeKind, &
coordDep1, coordDep2, coordDep3, &
distDim, name, rc)
!
! !RETURN VALUE:
type(ESMF_Grid) :: ESMF_GridCreate2PeriDimA
!
! !ARGUMENTS:
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_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 creates a single tile, arbitrarily distributed grid
! (see Figure \ref{fig:GridDecomps}) with two periodic dimensions.
! 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.
!
!
! The arguments are:
! \begin{description}
! \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[{[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\_DIM\_ARB/ where
! /ESMF\_DIM\_ARB/ 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\_DIM\_ARB/ 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\_DIM\_ARB.
! \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\_DIM\_ARB/ where
! /ESMF\_DIM\_ARB/ 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\_DIM\_ARB/ 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\_DIM\_ARB.
! \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\_DIM\_ARB/ where
! /ESMF\_DIM\_ARB/ 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\_DIM\_ARB/ 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\_DIM\_ARB.
! \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 Setup2PeriodicConn(dimCount, minIndexLocal, maxIndexLocal, &
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
if (present(name)) then
call ESMF_DistGridSet(distgrid, name="DG-"//trim(name), rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
! 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 -----------------------------------------------
ESMF_GridCreate2PeriDimA=ESMF_GridCreateFrmDistGridArb( &
distgrid, indexArray, &
distDim=distDimLocal, &
coordSys=coordSysLocal, &
coordTypeKind=coordTypeKind, &
coordDimCount=coordDimCount, coordDimMap=coordDimMap, &
name=name, 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(ESMF_GridCreate2PeriDimA,destroy=.true., &
rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_GridSetDestroyDELayout(ESMF_GridCreate2PeriDimA,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 function ESMF_GridCreate2PeriDimA