subroutine test_mesh_create_gt_1localde(correct, rc)
type(ESMF_Mesh) :: mesh
logical :: correct
integer :: rc
integer, pointer :: nodeIds(:),nodeOwners(:)
real(ESMF_KIND_R8), pointer :: nodeCoords(:)
real(ESMF_KIND_R8), pointer :: ownedNodeCoords(:)
integer :: numNodes, numOwnedNodes, numOwnedNodesTst
integer :: numElems,numOwnedElemsTst
integer :: numElemConns, numTriElems, numQuadElems
real(ESMF_KIND_R8), pointer :: elemCoords(:)
integer, pointer :: elemIds(:),elemTypes(:),elemConn(:)
integer :: petCount, localPet
type(ESMF_VM) :: vm
type(ESMF_DistGrid) :: nodeDistgrid, elemDistgrid
type(ESMF_Field) :: nodeField, elemField
integer :: nodeLocalDECount
type(ESMF_PtrInt1D), allocatable :: nodeArbSeqIndexL(:)
integer :: elemLocalDECount
type(ESMF_PtrInt1D), allocatable :: elemArbSeqIndexL(:)
integer :: i
integer :: dimCount, localDECount
! get global VM
call ESMF_VMGetGlobal(vm, rc=rc)
if (rc /= ESMF_SUCCESS) return
call ESMF_VMGet(vm, localPet=localPet, petCount=petCount, rc=rc)
if (rc /= ESMF_SUCCESS) return
! return with an error if not 1 or 4 PETs
if ((petCount /= 1) .and. (petCount /=4)) then
rc=ESMF_FAILURE
return
endif
! Setup mesh info depending on the
! number of PETs
if (petCount .eq. 1) then
! Fill in node data
numNodes=16
!! node ids
allocate(nodeIds(numNodes))
nodeIds=(/1,2,3,4,5,6,7,8, &
9,10,11,12,13,14,&
15,16/)
!! node Coords
allocate(nodeCoords(numNodes*2))
nodeCoords=(/0.0,0.0, & ! 1
1.0,0.0, & ! 2
2.0,0.0, & ! 3
3.0,0.0, & ! 4
0.0,1.0, & ! 5
1.0,1.0, & ! 6
2.0,1.0, & ! 7
3.0,1.0, & ! 8
0.0,2.0, & ! 9
1.0,2.0, & ! 10
2.0,2.0, & ! 11
3.0,2.0, & ! 12
0.0,3.0, & ! 13
1.0,3.0, & ! 14
2.0,3.0, & ! 15
3.0,3.0 /) ! 16
!! node owners
allocate(nodeOwners(numNodes))
nodeOwners=0 ! everything on proc 0
!! Build node localDE lists
nodeLocalDECount=2
allocate(nodeArbSeqIndexL(nodeLocalDeCount))
!! Allocate and fill first list
allocate(nodeArbSeqIndexL(1)%ptr(6))
nodeArbSeqIndexL(1)%ptr=(/1,2,3,4,5,6/)
allocate(nodeArbSeqIndexL(2)%ptr(10))
nodeArbSeqIndexL(2)%ptr=(/7,8,9,10,11,12,13,14,15,16/)
! Fill in elem data
numTriElems=2
numQuadElems=8
numElems=numTriElems+numQuadElems
numElemConns=3*numTriElems+4*numQuadElems
!! elem ids
allocate(elemIds(numElems))
elemIds=(/1,2,3,4,5,6,7,8,9,10/)
!! elem types
allocate(elemTypes(numElems))
elemTypes=(/ESMF_MESHELEMTYPE_QUAD, & ! 1
ESMF_MESHELEMTYPE_QUAD, & ! 2
ESMF_MESHELEMTYPE_QUAD, & ! 3
ESMF_MESHELEMTYPE_QUAD, & ! 4
ESMF_MESHELEMTYPE_QUAD, & ! 5
ESMF_MESHELEMTYPE_QUAD, & ! 6
ESMF_MESHELEMTYPE_QUAD, & ! 7
ESMF_MESHELEMTYPE_QUAD, & ! 8
ESMF_MESHELEMTYPE_TRI, & ! 9
ESMF_MESHELEMTYPE_TRI/) ! 10
!! elem coords
allocate(elemCoords(2*numElems))
elemCoords=(/0.5,0.5, & ! 1
1.5,0.5, & ! 2
2.5,0.5, & ! 3
0.5,1.5, & ! 4
1.5,1.5, & ! 5
2.5,1.5, & ! 6
0.5,2.5, & ! 7
1.5,2.5, & ! 8
2.75,2.25,& ! 9
2.25,2.75/) ! 10
!! elem conn
allocate(elemConn(numElemConns))
elemConn=(/1,2,6,5, & ! 1
2,3,7,6, & ! 2
3,4,8,7, & ! 3
5,6,10,9, & ! 4
6,7,11,10, & ! 5
7,8,12,11, & ! 6
9,10,14,13, & ! 7
10,11,15,14, & ! 8
11,12,16, & ! 9
11,16,15/) ! 10
!! Build node localDE lists
elemLocalDECount=2
allocate(elemArbSeqIndexL(elemLocalDeCount))
!! Allocate and fill first list
allocate(elemArbSeqIndexL(1)%ptr(4))
elemArbSeqIndexL(1)%ptr=(/1,2,3,4/)
allocate(elemArbSeqIndexL(2)%ptr(6))
elemArbSeqIndexL(2)%ptr=(/5,6,7,8,9,10/)
else if (petCount .eq. 4) then
! Setup mesh data depending on PET
if (localPet .eq. 0) then
! Fill in node data
numNodes=4
!! node ids
allocate(nodeIds(numNodes))
nodeIds=(/1,2,5,6/)
!! node Coords
allocate(nodeCoords(numNodes*2))
nodeCoords=(/0.0,0.0, & ! 1
1.0,0.0, & ! 2
0.0,1.0, & ! 5
1.0,1.0 /) ! 6
!! node owners
allocate(nodeOwners(numNodes))
nodeOwners=0 ! everything on proc 0
!! Build node localDE lists
nodeLocalDECount=2
allocate(nodeArbSeqIndexL(nodeLocalDeCount))
!! Allocate and fill first list
allocate(nodeArbSeqIndexL(1)%ptr(2))
nodeArbSeqIndexL(1)%ptr=(/1,2/)
allocate(nodeArbSeqIndexL(2)%ptr(2))
nodeArbSeqIndexL(2)%ptr=(/5,6/)
! Fill in elem data
numTriElems=0
numQuadElems=1
numElems=numTriElems+numQuadElems
numElemConns=3*numTriElems+4*numQuadElems
!! elem ids
allocate(elemIds(numElems))
elemIds=(/1/)
!! elem types
allocate(elemTypes(numElems))
elemTypes=(/ESMF_MESHELEMTYPE_QUAD/) ! 1
!! elem coords
allocate(elemCoords(2*numElems))
elemCoords=(/0.5,0.5/) ! 1
!! elem conn
allocate(elemConn(numElemConns))
elemConn=(/1,2,4,3/) ! 1
!! Build node localDE lists
elemLocalDECount=1
allocate(elemArbSeqIndexL(elemLocalDeCount))
!! Allocate and fill first list
allocate(elemArbSeqIndexL(1)%ptr(1))
elemArbSeqIndexL(1)%ptr=(/1/)
else if (localPet .eq. 1) then
! Fill in node data
numNodes=6
!! node ids
allocate(nodeIds(numNodes))
nodeIds=(/2,3,4,6,7,8/)
!! node Coords
allocate(nodeCoords(numNodes*2))
nodeCoords=(/1.0,0.0, & ! 2
2.0,0.0, & ! 3
3.0,0.0, & ! 4
1.0,1.0, & ! 6
2.0,1.0, & ! 7
3.0,1.0 /) ! 8
!! node owners
allocate(nodeOwners(numNodes))
nodeOwners=(/0, & ! 2
1, & ! 3
1, & ! 4
0, & ! 6
1, & ! 7
1/) ! 8
!! Build node localDE lists
nodeLocalDECount=2
allocate(nodeArbSeqIndexL(nodeLocalDeCount))
!! Allocate and fill first list
allocate(nodeArbSeqIndexL(1)%ptr(2))
nodeArbSeqIndexL(1)%ptr=(/3,4/)
allocate(nodeArbSeqIndexL(2)%ptr(2))
nodeArbSeqIndexL(2)%ptr=(/7,8/)
! Fill in elem data
numTriElems=0
numQuadElems=2
numElems=numTriElems+numQuadElems
numElemConns=3*numTriElems+4*numQuadElems
!! elem ids
allocate(elemIds(numElems))
elemIds=(/2,3/)
!! elem types
allocate(elemTypes(numElems))
elemTypes=(/ESMF_MESHELEMTYPE_QUAD, & ! 2
ESMF_MESHELEMTYPE_QUAD/) ! 3
!! elem coords
allocate(elemCoords(2*numElems))
elemCoords=(/1.5,0.5, & ! 2
2.5,0.5/) ! 3
!! elem conn
allocate(elemConn(numElemConns))
elemConn=(/1,2,5,4, & ! 2
2,3,6,5/) ! 3
!! Build node localDE lists
elemLocalDECount=2
allocate(elemArbSeqIndexL(elemLocalDeCount))
!! Allocate and fill first list
allocate(elemArbSeqIndexL(1)%ptr(1))
elemArbSeqIndexL(1)%ptr=(/2/)
allocate(elemArbSeqIndexL(2)%ptr(1))
elemArbSeqIndexL(2)%ptr=(/3/)
else if (localPet .eq. 2) then
! Fill in node data
numNodes=9
!! node ids
allocate(nodeIds(numNodes))
nodeIds=(/5,6,7, &
9,10,11, &
13,14,15/)
!! node Coords
allocate(nodeCoords(numNodes*2))
nodeCoords=(/0.0,1.0, & ! 5
1.0,1.0, & ! 6
2.0,1.0, & ! 7
0.0,2.0, & ! 9
1.0,2.0, & ! 10
2.0,2.0, & ! 11
0.0,3.0, & ! 13
1.0,3.0, & ! 14
2.0,3.0/) ! 15
!! node owners
allocate(nodeOwners(numNodes))
nodeOwners=(/0, & ! 5
0, & ! 6
1, & ! 7
2, & ! 9
2, & ! 10
3, & ! 11
2, & ! 13
2, & ! 14
3/) ! 15
!! Build node localDE lists
nodeLocalDECount=2
allocate(nodeArbSeqIndexL(nodeLocalDeCount))
!! Allocate and fill first list
allocate(nodeArbSeqIndexL(1)%ptr(2))
nodeArbSeqIndexL(1)%ptr=(/9,10/)
allocate(nodeArbSeqIndexL(2)%ptr(2))
nodeArbSeqIndexL(2)%ptr=(/13,14/)
! Fill in elem data
numTriElems=0
numQuadElems=4
numElems=numTriElems+numQuadElems
numElemConns=3*numTriElems+4*numQuadElems
!! elem ids
allocate(elemIds(numElems))
elemIds=(/4,5,7,8/)
!! elem types
allocate(elemTypes(numElems))
elemTypes=(/ESMF_MESHELEMTYPE_QUAD, & ! 4
ESMF_MESHELEMTYPE_QUAD, & ! 5
ESMF_MESHELEMTYPE_QUAD, & ! 7
ESMF_MESHELEMTYPE_QUAD/) ! 8
!! elem coords
allocate(elemCoords(2*numElems))
elemCoords=(/0.5,1.5, & ! 4
1.5,1.5, & ! 5
0.5,2.5, & ! 7
1.5,2.5/) ! 8
!! elem conn
allocate(elemConn(numElemConns))
elemConn=(/1,2,5,4, & ! 4
2,3,6,5, & ! 5
4,5,8,7, & ! 7
5,6,9,8/) ! 8
!! Build node localDE lists
elemLocalDECount=2
allocate(elemArbSeqIndexL(elemLocalDeCount))
!! Allocate and fill first list
allocate(elemArbSeqIndexL(1)%ptr(3))
elemArbSeqIndexL(1)%ptr=(/4,5,7/)
allocate(elemArbSeqIndexL(2)%ptr(1))
elemArbSeqIndexL(2)%ptr=(/8/)
else if (localPet .eq. 3) then
! Fill in node data
numNodes=6
!! node ids
allocate(nodeIds(numNodes))
nodeIds=(/7,8,11,12,15,16/)
!! node Coords
allocate(nodeCoords(numNodes*2))
nodeCoords=(/2.0,1.0, & ! 7
3.0,1.0, & ! 8
2.0,2.0, & ! 11
3.0,2.0, & ! 12
2.0,3.0, & ! 15
3.0,3.0 /) ! 16
!! node owners
allocate(nodeOwners(numNodes))
nodeOwners=(/1, & ! 7
1, & ! 8
3, & ! 11
3, & ! 12
3, & ! 15
3/) ! 16
!! Build node localDE lists
nodeLocalDECount=1
allocate(nodeArbSeqIndexL(nodeLocalDeCount))
!! Allocate and fill first list
allocate(nodeArbSeqIndexL(1)%ptr(4))
nodeArbSeqIndexL(1)%ptr=(/11,12,15,16/)
! Fill in elem data
numTriElems=2
numQuadElems=1
numElems=numTriElems+numQuadElems
numElemConns=3*numTriElems+4*numQuadElems
!! elem ids
allocate(elemIds(numElems))
elemIds=(/6,9,10/)
!! elem types
allocate(elemTypes(numElems))
elemTypes=(/ESMF_MESHELEMTYPE_QUAD, & ! 6
ESMF_MESHELEMTYPE_TRI, & ! 9
ESMF_MESHELEMTYPE_TRI/) ! 10
!! elem coords
allocate(elemCoords(2*numElems))
elemCoords=(/2.5,1.5, & ! 6
2.75,2.25,& ! 9
2.25,2.75/) ! 10
!! elem conn
allocate(elemConn(numElemConns))
elemConn=(/1,2,4,3, & ! 6
3,4,6, & ! 9
3,6,5/) ! 10
!! Build node localDE lists
elemLocalDECount=2
allocate(elemArbSeqIndexL(elemLocalDeCount))
!! Allocate and fill first list
allocate(elemArbSeqIndexL(1)%ptr(1))
elemArbSeqIndexL(1)%ptr=(/6/)
allocate(elemArbSeqIndexL(2)%ptr(2))
elemArbSeqIndexL(2)%ptr=(/9,10/)
endif
endif
! Create node distgrid
nodeDistgrid = ESMF_DistGridCreate(arbSeqIndexList=nodeArbSeqIndexL, &
rc=rc)
if (rc /= ESMF_SUCCESS) return
! Create elem distgrid
elemDistgrid = ESMF_DistGridCreate(arbSeqIndexList=elemArbSeqIndexL, &
rc=rc)
if (rc /= ESMF_SUCCESS) return
! Create Mesh structure in 1 step
mesh=ESMF_MeshCreate(parametricDim=2,spatialDim=2, &
coordSys=ESMF_COORDSYS_CART, nodalDistgrid=nodeDistgrid, &
nodeIds=nodeIds, nodeCoords=nodeCoords, &
nodeOwners=nodeOwners, elementIds=elemIds,&
elementTypes=elemTypes, elementConn=elemConn, &
elementCoords=elemCoords, elementDistgrid=elemDistgrid, &
rc=rc)
if (rc /= ESMF_SUCCESS) return
! deallocate node data
deallocate(nodeIds)
deallocate(nodeCoords)
deallocate(nodeOwners)
! deallocate elem data
deallocate(elemIds)
deallocate(elemTypes)
deallocate(elemCoords)
deallocate(elemConn)
! Deallocate sequence lists
do i=1,nodeLocalDECount
deallocate(nodeArbSeqIndexL(i)%ptr)
enddo
deallocate(nodeArbSeqIndexL)
do i=1,elemLocalDECount
deallocate(elemArbSeqIndexL(i)%ptr)
enddo
deallocate(elemArbSeqIndexL)
! Init correct to true before looking for problems
correct=.true.
! Test creating field
nodeField = ESMF_FieldCreate(mesh, typekind=ESMF_TYPEKIND_R8, &
meshloc=ESMF_MESHLOC_NODE, &
rc=rc)
if (rc .ne. ESMF_SUCCESS) return
! check field
call ESMF_FieldValidate(nodeField, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
! Get Field info
call ESMF_FieldGet(nodeField, dimCount=dimCount, &
localDECount=localDECount, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
! check info
if (dimCount .ne. 1) correct=.false.
if (localDECount .ne. nodeLocalDECount) correct=.false.
! Test creating field
elemField = ESMF_FieldCreate(mesh, typekind=ESMF_TYPEKIND_R8, &
meshloc=ESMF_MESHLOC_ELEMENT, &
rc=rc)
if (rc .ne. ESMF_SUCCESS) return
! check field
call ESMF_FieldValidate(elemField, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
! Get Field info
call ESMF_FieldGet(elemField, dimCount=dimCount, &
localDECount=localDECount, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
! check info
if (dimCount .ne. 1) correct=.false.
if (localDECount .ne. elemLocalDECount) correct=.false.
! Get rid of node distgrid
call ESMF_DistgridDestroy(nodeDistgrid, rc=rc)
if (rc /= ESMF_SUCCESS) return
! Get rid of elem distgrid
call ESMF_DistgridDestroy(elemDistgrid, rc=rc)
if (rc /= ESMF_SUCCESS) return
! Get rid of test fields
call ESMF_FieldDestroy(nodeField, rc=rc)
if (rc /= ESMF_SUCCESS) return
call ESMF_FieldDestroy(elemField, rc=rc)
if (rc /= ESMF_SUCCESS) return
! Get rid of Mesh
call ESMF_MeshDestroy(mesh, rc=rc)
if (rc /= ESMF_SUCCESS) return
! Return success
rc=ESMF_SUCCESS
end subroutine test_mesh_create_gt_1localde