Skip to content

Commit 2752c0b

Browse files
committed
move the rebuild MPs test to createMPs
1 parent 68bc366 commit 2752c0b

File tree

2 files changed

+154
-148
lines changed

2 files changed

+154
-148
lines changed

test/readMPAS.f90

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -15,150 +15,6 @@ module readMPAS
1515
integer, parameter :: MPAS_RKIND = selected_real_kind(12)
1616

1717
contains
18-
19-
function epsilonDiff(a,b) result(isSame)
20-
implicit none
21-
real(kind=MPAS_RKIND) :: a,b,delta
22-
parameter (delta=1.0e-8)
23-
logical :: isSame
24-
if (abs(a-b) < delta) then
25-
isSame = .true.
26-
else
27-
isSame = .false.
28-
endif
29-
end function
30-
31-
32-
subroutine rebuildTests(mpMesh, numMPs, mp2Elm, isMPActive)
33-
use :: polympo
34-
use iso_c_binding
35-
implicit none
36-
type(c_ptr):: mpMesh
37-
integer :: numMPs, i, numMPsLarger
38-
integer, dimension(:), pointer :: mp2Elm, addedMPMask, isMPActive, mp2ElmFromPMPO
39-
integer, dimension(:), pointer :: mp2ElmLarger, addedMPMaskLarger, mp2ElmFromPMPOLarger, isMPActiveLarger
40-
integer, parameter :: MP_ACTIVE = 1
41-
integer, parameter :: MP_INACTIVE = 0
42-
integer, parameter :: MP_DELETE_ELM_ID = -1
43-
44-
! TEST: adding MP
45-
! Necessary pre-conditions for test
46-
call assert(numMPs >= 4, "not enough MPs for test")
47-
call assert(isMPActive(4) == MP_INACTIVE, "mp2Elm = 4 is active")
48-
! PREPARE DATA
49-
allocate(addedMPMask(numMPs))
50-
addedMPMask = MP_INACTIVE
51-
isMPActive(4) = MP_ACTIVE
52-
mp2Elm(4) = 7
53-
addedMPMask(4) = MP_ACTIVE
54-
! Rebuild MPs
55-
call polympo_rebuildMPs(mpMesh,numMPs,c_loc(mp2Elm),c_loc(addedMPMask))
56-
! Test values
57-
allocate(mp2ElmFromPMPO(numMPs))
58-
mp2ElmFromPMPO = MP_DELETE_ELM_ID
59-
call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2ElmFromPMPO))
60-
do i = 1, numMPs
61-
if (isMPActive(i) == MP_ACTIVE) then
62-
call assert(mp2Elm(i) .eq. mp2ElmFromPMPO(i), "wrong element ID for i'th MP after rebuild")
63-
endif
64-
end do
65-
66-
! TEST: deleting two MPs
67-
! Necessary pre-conditions for test
68-
call assert(numMPs >= 4, "not enough MPs for test")
69-
call assert(isMPActive(1) == MP_ACTIVE, "mp2Elm = 1 not active")
70-
call assert(isMPActive(4) == MP_ACTIVE, "mp2Elm = 4 not active")
71-
! PREPARE DATA
72-
isMPActive(1) = MP_INACTIVE
73-
isMPActive(4) = MP_INACTIVE
74-
mp2Elm(1) = MP_DELETE_ELM_ID
75-
mp2Elm(4) = MP_DELETE_ELM_ID
76-
addedMPMask = MP_INACTIVE
77-
! Rebuild MPs
78-
call polympo_rebuildMPs(mpMesh,numMPs,c_loc(mp2Elm),c_loc(addedMPMask))
79-
! Test values
80-
mp2ElmFromPMPO = MP_DELETE_ELM_ID
81-
call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2ElmFromPMPO))
82-
do i = 1, numMPs
83-
if (isMPActive(i) == MP_ACTIVE) then
84-
call assert(mp2Elm(i) .eq. mp2ElmFromPMPO(i), "wrong element ID for i'th MP after rebuild")
85-
endif
86-
end do
87-
88-
! TEST: adding 1, delete 1 and add in same index, removing 1
89-
! Necessary pre-conditions for test
90-
call assert(numMPs >= 3, "not enough MPs for test")
91-
call assert(isMPActive(1) == MP_INACTIVE, "mp2Elm = 1 not active")
92-
call assert(isMPActive(2) == MP_ACTIVE, "mp2Elm = 2 is active")
93-
call assert(isMPActive(3) == MP_ACTIVE, "mp2Elm = 3 not active")
94-
! PREPARE DATA
95-
isMPActive(1) = MP_ACTIVE
96-
isMPActive(2) = MP_ACTIVE
97-
isMPActive(3) = MP_INACTIVE
98-
addedMPMask(1) = MP_ACTIVE
99-
addedMPMask(2) = MP_ACTIVE
100-
mp2Elm(1) = 7 !ADDED
101-
mp2Elm(2) = 7 !REPLACED
102-
mp2Elm(3) = MP_DELETE_ELM_ID !DELETED
103-
! Rebuild MPs
104-
call polympo_rebuildMPs(mpMesh,numMPs,c_loc(mp2Elm),c_loc(addedMPMask))
105-
! Test values
106-
mp2ElmFromPMPO = MP_DELETE_ELM_ID
107-
call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2ElmFromPMPO))
108-
do i = 1, numMPs
109-
if (isMPActive(i) == MP_ACTIVE) then
110-
call assert(mp2Elm(i) .eq. mp2ElmFromPMPO(i), "wrong element ID for i'th MP after rebuild")
111-
endif
112-
end do
113-
114-
! TEST: increasing numMPs to numMPsLarger
115-
! TEST: adding 1 MP (within numMPs), removing 1 MP (within numMPs), adding 1 (after numMPs, but within numMPsLarger)
116-
! Necessary pre-conditions for test
117-
call assert(numMPs >= 5, "not enough MPs for test")
118-
call assert(isMPActive(4) == MP_INACTIVE, "mp2Elm = 4 not active")
119-
call assert(isMPActive(5) == MP_ACTIVE, "mp2Elm = 5 is active")
120-
! PREPARE DATA
121-
numMPsLarger = numMPs+10
122-
allocate(mp2ElmLarger(numMPsLarger))
123-
allocate(isMPActiveLarger(numMPsLarger))
124-
allocate(addedMPMaskLarger(numMPsLarger))
125-
126-
mp2ElmLarger = MP_DELETE_ELM_ID
127-
isMPActiveLarger = MP_INACTIVE
128-
addedMPMaskLarger = MP_INACTIVE
129-
do i = 1, numMPs
130-
mp2ElmLarger(i) = mp2Elm(i)
131-
isMPActiveLarger(i) = isMPActive(i)
132-
end do
133-
134-
isMPActiveLarger(4) = MP_ACTIVE ! within numMPs
135-
isMPActiveLarger(5) = MP_INACTIVE ! within numMPs
136-
isMPActiveLarger(numMPsLarger-2) = MP_ACTIVE ! within numMPsLarger
137-
mp2ElmLarger(4) = 7
138-
mp2ElmLarger(5) = MP_DELETE_ELM_ID
139-
mp2ElmLarger(numMPsLarger-2) = 7
140-
addedMPMaskLarger(4) = MP_ACTIVE
141-
addedMPMaskLarger(numMPsLarger-2) = MP_ACTIVE
142-
! Rebuild MPs
143-
call polympo_rebuildMPs(mpMesh,numMPsLarger,c_loc(mp2ElmLarger),c_loc(addedMPMaskLarger))
144-
! Test values
145-
allocate(mp2ElmFromPMPOLarger(numMPsLarger))
146-
mp2ElmFromPMPOLarger = MP_DELETE_ELM_ID
147-
call polympo_getMPCurElmID(mpMesh,numMPsLarger,c_loc(mp2ElmFromPMPOLarger))
148-
do i = 1, numMPs
149-
if (isMPActiveLarger(i) == MP_ACTIVE) then
150-
call assert(mp2ElmLarger(i) .eq. mp2ElmFromPMPOLarger(i), "wrong element ID for i'th MP after rebuild")
151-
endif
152-
end do
153-
! Cleanup
154-
deallocate(addedMPMask)
155-
deallocate(mp2ElmFromPMPO)
156-
deallocate(mp2ElmLarger)
157-
deallocate(isMPActiveLarger)
158-
deallocate(addedMPMaskLarger)
159-
deallocate(mp2ElmFromPMPOLarger)
160-
end subroutine
161-
16218
!---------------------------------------------------------------------------
16319
!> @brief get the MP positions array from a polympo array
16420
!> @param mpmesh(in/out) MPMesh object to fill, allocated by users

test/testFortranCreateMPs.f90

Lines changed: 154 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,155 @@
1+
module testCreateRebuildMPs
2+
use :: polympo
3+
use :: readMPAS
4+
use iso_c_binding
5+
implicit none
6+
7+
contains
8+
function epsilonDiff(a,b) result(isSame)
9+
implicit none
10+
real(kind=MPAS_RKIND) :: a,b,delta
11+
parameter (delta=1.0e-8)
12+
logical :: isSame
13+
if (abs(a-b) < delta) then
14+
isSame = .true.
15+
else
16+
isSame = .false.
17+
endif
18+
end function
19+
20+
subroutine rebuildTests(mpMesh, numMPs, mp2Elm, isMPActive)
21+
implicit none
22+
type(c_ptr):: mpMesh
23+
integer :: numMPs, i, numMPsLarger
24+
integer, dimension(:), pointer :: mp2Elm, addedMPMask, isMPActive, mp2ElmFromPMPO
25+
integer, dimension(:), pointer :: mp2ElmLarger, addedMPMaskLarger, mp2ElmFromPMPOLarger, isMPActiveLarger
26+
integer, parameter :: MP_ACTIVE = 1
27+
integer, parameter :: MP_INACTIVE = 0
28+
integer, parameter :: MP_DELETE_ELM_ID = -1
29+
30+
! TEST: adding MP
31+
! Necessary pre-conditions for test
32+
call assert(numMPs >= 4, "not enough MPs for test")
33+
call assert(isMPActive(4) == MP_INACTIVE, "mp2Elm = 4 is active")
34+
! PREPARE DATA
35+
allocate(addedMPMask(numMPs))
36+
addedMPMask = MP_INACTIVE
37+
isMPActive(4) = MP_ACTIVE
38+
mp2Elm(4) = 7
39+
addedMPMask(4) = MP_ACTIVE
40+
! Rebuild MPs
41+
call polympo_rebuildMPs(mpMesh,numMPs,c_loc(mp2Elm),c_loc(addedMPMask))
42+
! Test values
43+
allocate(mp2ElmFromPMPO(numMPs))
44+
mp2ElmFromPMPO = MP_DELETE_ELM_ID
45+
call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2ElmFromPMPO))
46+
do i = 1, numMPs
47+
if (isMPActive(i) == MP_ACTIVE) then
48+
call assert(mp2Elm(i) .eq. mp2ElmFromPMPO(i), "wrong element ID for i'th MP after rebuild")
49+
endif
50+
end do
51+
52+
! TEST: deleting two MPs
53+
! Necessary pre-conditions for test
54+
call assert(numMPs >= 4, "not enough MPs for test")
55+
call assert(isMPActive(1) == MP_ACTIVE, "mp2Elm = 1 not active")
56+
call assert(isMPActive(4) == MP_ACTIVE, "mp2Elm = 4 not active")
57+
! PREPARE DATA
58+
isMPActive(1) = MP_INACTIVE
59+
isMPActive(4) = MP_INACTIVE
60+
mp2Elm(1) = MP_DELETE_ELM_ID
61+
mp2Elm(4) = MP_DELETE_ELM_ID
62+
addedMPMask = MP_INACTIVE
63+
! Rebuild MPs
64+
call polympo_rebuildMPs(mpMesh,numMPs,c_loc(mp2Elm),c_loc(addedMPMask))
65+
! Test values
66+
mp2ElmFromPMPO = MP_DELETE_ELM_ID
67+
call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2ElmFromPMPO))
68+
do i = 1, numMPs
69+
if (isMPActive(i) == MP_ACTIVE) then
70+
call assert(mp2Elm(i) .eq. mp2ElmFromPMPO(i), "wrong element ID for i'th MP after rebuild")
71+
endif
72+
end do
73+
74+
! TEST: adding 1, delete 1 and add in same index, removing 1
75+
! Necessary pre-conditions for test
76+
call assert(numMPs >= 3, "not enough MPs for test")
77+
call assert(isMPActive(1) == MP_INACTIVE, "mp2Elm = 1 not active")
78+
call assert(isMPActive(2) == MP_ACTIVE, "mp2Elm = 2 is active")
79+
call assert(isMPActive(3) == MP_ACTIVE, "mp2Elm = 3 not active")
80+
! PREPARE DATA
81+
isMPActive(1) = MP_ACTIVE
82+
isMPActive(2) = MP_ACTIVE
83+
isMPActive(3) = MP_INACTIVE
84+
addedMPMask(1) = MP_ACTIVE
85+
addedMPMask(2) = MP_ACTIVE
86+
mp2Elm(1) = 7 !ADDED
87+
mp2Elm(2) = 7 !REPLACED
88+
mp2Elm(3) = MP_DELETE_ELM_ID !DELETED
89+
! Rebuild MPs
90+
call polympo_rebuildMPs(mpMesh,numMPs,c_loc(mp2Elm),c_loc(addedMPMask))
91+
! Test values
92+
mp2ElmFromPMPO = MP_DELETE_ELM_ID
93+
call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2ElmFromPMPO))
94+
do i = 1, numMPs
95+
if (isMPActive(i) == MP_ACTIVE) then
96+
call assert(mp2Elm(i) .eq. mp2ElmFromPMPO(i), "wrong element ID for i'th MP after rebuild")
97+
endif
98+
end do
99+
100+
! TEST: increasing numMPs to numMPsLarger
101+
! TEST: adding 1 MP (within numMPs), removing 1 MP (within numMPs), adding 1 (after numMPs, but within numMPsLarger)
102+
! Necessary pre-conditions for test
103+
call assert(numMPs >= 5, "not enough MPs for test")
104+
call assert(isMPActive(4) == MP_INACTIVE, "mp2Elm = 4 not active")
105+
call assert(isMPActive(5) == MP_ACTIVE, "mp2Elm = 5 is active")
106+
! PREPARE DATA
107+
numMPsLarger = numMPs+10
108+
allocate(mp2ElmLarger(numMPsLarger))
109+
allocate(isMPActiveLarger(numMPsLarger))
110+
allocate(addedMPMaskLarger(numMPsLarger))
111+
112+
mp2ElmLarger = MP_DELETE_ELM_ID
113+
isMPActiveLarger = MP_INACTIVE
114+
addedMPMaskLarger = MP_INACTIVE
115+
do i = 1, numMPs
116+
mp2ElmLarger(i) = mp2Elm(i)
117+
isMPActiveLarger(i) = isMPActive(i)
118+
end do
119+
120+
isMPActiveLarger(4) = MP_ACTIVE ! within numMPs
121+
isMPActiveLarger(5) = MP_INACTIVE ! within numMPs
122+
isMPActiveLarger(numMPsLarger-2) = MP_ACTIVE ! within numMPsLarger
123+
mp2ElmLarger(4) = 7
124+
mp2ElmLarger(5) = MP_DELETE_ELM_ID
125+
mp2ElmLarger(numMPsLarger-2) = 7
126+
addedMPMaskLarger(4) = MP_ACTIVE
127+
addedMPMaskLarger(numMPsLarger-2) = MP_ACTIVE
128+
! Rebuild MPs
129+
call polympo_rebuildMPs(mpMesh,numMPsLarger,c_loc(mp2ElmLarger),c_loc(addedMPMaskLarger))
130+
! Test values
131+
allocate(mp2ElmFromPMPOLarger(numMPsLarger))
132+
mp2ElmFromPMPOLarger = MP_DELETE_ELM_ID
133+
call polympo_getMPCurElmID(mpMesh,numMPsLarger,c_loc(mp2ElmFromPMPOLarger))
134+
do i = 1, numMPs
135+
if (isMPActiveLarger(i) == MP_ACTIVE) then
136+
call assert(mp2ElmLarger(i) .eq. mp2ElmFromPMPOLarger(i), "wrong element ID for i'th MP after rebuild")
137+
endif
138+
end do
139+
! Cleanup
140+
deallocate(addedMPMask)
141+
deallocate(mp2ElmFromPMPO)
142+
deallocate(mp2ElmLarger)
143+
deallocate(isMPActiveLarger)
144+
deallocate(addedMPMaskLarger)
145+
deallocate(mp2ElmFromPMPOLarger)
146+
end subroutine
147+
end module testCreateRebuildMPs
148+
1149
program main
2150
use :: polympo
3151
use :: readMPAS
152+
use :: testCreateRebuildMPs
4153
use :: iso_c_binding
5154
implicit none
6155
include 'mpif.h'
@@ -11,7 +160,7 @@ program main
11160
integer, parameter :: nDims = 3
12161
integer, parameter :: MP_ACTIVE = 1
13162
integer, parameter :: MP_INACTIVE = 0
14-
real(kind=MPAS_RKIND) :: ptOne = 0.100000000000000000
163+
real(kind=MPAS_RKIND) :: ptOne = 0.100_MPAS_RKIND
15164
integer :: mpi_comm_handle = MPI_COMM_WORLD
16165
character (len=2048) :: filename
17166
type(c_ptr) :: mpMesh
@@ -59,10 +208,10 @@ program main
59208
!test on new createMPs
60209
call assert(nCells .ge. 3, "This test requires a mesh with at least three cells")
61210
numMPs = nCells+2;
62-
allocate(mpsPerElm(nCells))
63211
allocate(mp2Elm(numMPs))
64212
allocate(isMPActive(numMPs))
65213

214+
allocate(mpsPerElm(nCells))
66215
isMPActive = MP_ACTIVE !no inactive MPs and some changed below
67216
isMPActive(4) = MP_INACTIVE !first/1-st MP is indexed 1 and 4-th MP is inactive
68217

@@ -115,8 +264,9 @@ program main
115264
!deallocate MP variables
116265
deallocate(mpPosition)
117266
deallocate(mpsPerElm)
118-
deallocate(mp2Elm)
119-
deallocate(isMPActive)
267+
call rebuildTests(mpMesh, numMPs, mp2Elm, isMPActive)
268+
deallocate(mp2Elm)
269+
deallocate(isMPActive)
120270

121271
call polympo_deleteMPMesh(mpMesh)
122272
call polympo_finalize()

0 commit comments

Comments
 (0)