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+
1149program 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