@@ -17,6 +17,59 @@ function epsilonDiff(a,b) result(isSame)
1717 endif
1818end function
1919
20+ subroutine createTest (mpMesh , nCells , numMPs , mp2Elm , isMPActive )
21+ implicit none
22+ type (c_ptr):: mpMesh
23+ integer :: nCells, numMPs, i
24+ integer , parameter :: nDims = 3
25+ real (kind= MPAS_RKIND) :: ptOne = 0.100_MPAS_RKIND
26+ integer , parameter :: MP_ACTIVE = 1
27+ integer , parameter :: MP_INACTIVE = 0
28+ integer , dimension (:), pointer :: mpsPerElm, mp2Elm, isMPActive
29+ real (kind= MPAS_RKIND), dimension (:,:), pointer :: mpPosition
30+ allocate (mpsPerElm(nCells))
31+ mpsPerElm = 1 ! all elements have 1 MP and some changed below
32+ mpsPerElm(1 ) = 0 ! 1st element has 0 MPs
33+ mpsPerElm(2 ) = 2 ! 2nd element has 2 MPs
34+ mpsPerElm(3 ) = 2 ! 3rd element has 2 MPs
35+
36+ call polympo_createMPs(mpMesh,nCells,numMPs,c_loc(mpsPerElm),c_loc(mp2Elm),c_loc(isMPActive))
37+
38+ ! set mp positions
39+ allocate (mpPosition(nDims,numMPs))
40+ do i = 1 ,numMPs
41+ mpPosition(1 ,i) = i+ ptOne
42+ mpPosition(2 ,i) = numMPs+ i+ ptOne
43+ mpPosition(3 ,i) = (2 * numMPs)+ i+ ptOne
44+ end do
45+
46+ call polympo_setMPPositions(mpMesh,nDims,numMPs,c_loc(mpPosition))
47+ mpPosition = 42
48+ call polympo_getMPPositions(mpMesh,nDims,numMPs,c_loc(mpPosition))
49+ do i = 1 ,numMPs
50+ if (isMPActive(i) .eq. MP_ACTIVE) then
51+ call assert(epsilonDiff(mpPosition(1 ,i),i+ ptOne), " x position of MP does not match" )
52+ call assert(epsilonDiff(mpPosition(2 ,i),numMPs+ i+ ptOne), " y position of MP does not match" )
53+ call assert(epsilonDiff(mpPosition(3 ,i),(2 * numMPs)+ i+ ptOne), " z position of MP does not match" )
54+ endif
55+ end do
56+
57+ mp2Elm = - 99 ! override values and then use get function below
58+ call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2Elm))
59+ call assert(mp2Elm(1 ) .eq. 2 , " wrong element ID for MP 1" )
60+ call assert(mp2Elm(2 ) .eq. 3 , " wrong element ID for MP 2" )
61+ call assert(mp2Elm(3 ) .eq. 2 , " wrong element ID for MP 3" )
62+ ! mp2Elm(4) is not needed/used since 4-th MP is inactive
63+ do i = 5 ,numMPs
64+ call assert(mp2Elm(i) .eq. i-2 , " wrong element ID for i'th MP" )
65+ end do
66+ ! test end
67+
68+ ! deallocate MP variables
69+ deallocate (mpPosition)
70+ deallocate (mpsPerElm)
71+ end subroutine
72+
2073subroutine rebuildTests (mpMesh , numMPs , mp2Elm , isMPActive )
2174 implicit none
2275 type (c_ptr):: mpMesh
@@ -157,16 +210,13 @@ program main
157210 integer :: ierr, self
158211 integer :: argc, i, arglen
159212 integer :: setMeshOption, setMPOption
160- integer , parameter :: nDims = 3
161- integer , parameter :: MP_ACTIVE = 1
162- integer , parameter :: MP_INACTIVE = 0
163- real (kind= MPAS_RKIND) :: ptOne = 0.100_MPAS_RKIND
164213 integer :: mpi_comm_handle = MPI_COMM_WORLD
165214 character (len= 2048 ) :: filename
166215 type (c_ptr) :: mpMesh
167216 integer :: numMPs
168- integer , dimension (:), pointer :: mpsPerElm, mp2Elm, isMPActive
169- real (kind= MPAS_RKIND), dimension (:,:), pointer :: mpPosition
217+ integer , dimension (:), pointer :: mp2Elm, isMPActive
218+ integer , parameter :: MP_ACTIVE = 1
219+ integer , parameter :: MP_INACTIVE = 0
170220 character (len= 64 ) :: onSphere, stringYes = " YES"
171221 real (kind= MPAS_RKIND) :: sphereRadius
172222 integer :: maxEdges, vertexDegree, nCells, nVertices
@@ -205,66 +255,28 @@ program main
205255 latVertex, &
206256 verticesOnCell, cellsOnCell)
207257
208- ! test on new createMPs
209- call assert(nCells .ge. 3 , " This test requires a mesh with at least three cells" )
210- numMPs = nCells+2 ;
211- allocate (mp2Elm(numMPs))
212- allocate (isMPActive(numMPs))
213-
214- allocate (mpsPerElm(nCells))
215- isMPActive = MP_ACTIVE ! no inactive MPs and some changed below
216- isMPActive(4 ) = MP_INACTIVE ! first/1-st MP is indexed 1 and 4-th MP is inactive
217-
218- mpsPerElm = 1 ! all elements have 1 MP and some changed below
219- mpsPerElm(1 ) = 0 ! 1st element has 0 MPs
220- mpsPerElm(2 ) = 2 ! 2nd element has 2 MPs
221- mpsPerElm(3 ) = 2 ! 3rd element has 2 MPs
222-
223- ! mp2Elm = [2,3,2,0,3,4,5,6,...]
224- mp2Elm(1 ) = 2
225- mp2Elm(2 ) = 3
226- mp2Elm(3 ) = 2
227- ! mp2Elm(4) is not needed/used since 4-th MP is inactive
228- do i = 5 ,numMPs
229- mp2Elm(i) = i-2 ! i=5 leads to mp2Elm(5)=3 (5-th MP in 3-rd element)
230- ! i=numMPs leads to mp2Elm(numMPs=nCells+2)=numMPs-2=nCells
231- end do
232- call polympo_createMPs(mpMesh,nCells,numMPs,c_loc(mpsPerElm),c_loc(mp2Elm),c_loc(isMPActive))
233-
234- ! set mp positions
235- allocate (mpPosition(nDims,numMPs))
236- do i = 1 ,numMPs
237- mpPosition(1 ,i) = i+ ptOne
238- mpPosition(2 ,i) = numMPs+ i+ ptOne
239- mpPosition(3 ,i) = (2 * numMPs)+ i+ ptOne
240- end do
241-
242- call polympo_setMPPositions(mpMesh,nDims,numMPs,c_loc(mpPosition))
243- mpPosition = 42
244- call polympo_getMPPositions(mpMesh,nDims,numMPs,c_loc(mpPosition))
245- do i = 1 ,numMPs
246- if (isMPActive(i) .eq. MP_ACTIVE) then
247- call assert(epsilonDiff(mpPosition(1 ,i),i+ ptOne), " x position of MP does not match" )
248- call assert(epsilonDiff(mpPosition(2 ,i),numMPs+ i+ ptOne), " y position of MP does not match" )
249- call assert(epsilonDiff(mpPosition(3 ,i),(2 * numMPs)+ i+ ptOne), " z position of MP does not match" )
250- endif
251- end do
252-
253- mp2Elm = - 99 ! override values and then use get function below
254- call polympo_getMPCurElmID(mpMesh,numMPs,c_loc(mp2Elm))
255- call assert(mp2Elm(1 ) .eq. 2 , " wrong element ID for MP 1" )
256- call assert(mp2Elm(2 ) .eq. 3 , " wrong element ID for MP 2" )
257- call assert(mp2Elm(3 ) .eq. 2 , " wrong element ID for MP 3" )
258- ! mp2Elm(4) is not needed/used since 4-th MP is inactive
259- do i = 5 ,numMPs
260- call assert(mp2Elm(i) .eq. i-2 , " wrong element ID for i'th MP" )
261- end do
262- ! test end
263-
264- ! deallocate MP variables
265- deallocate (mpPosition)
266- deallocate (mpsPerElm)
258+ ! test on new createMPs
259+ call assert(nCells .ge. 3 , " This test requires a mesh with at least three cells" )
260+ numMPs = nCells+2 ;
261+ allocate (mp2Elm(numMPs))
262+ allocate (isMPActive(numMPs))
263+
264+ isMPActive = MP_ACTIVE ! no inactive MPs and some changed below
265+ isMPActive(4 ) = MP_INACTIVE ! first/1-st MP is indexed 1 and 4-th MP is inactive
266+
267+ ! mp2Elm = [2,3,2,0,3,4,5,6,...]
268+ mp2Elm(1 ) = 2
269+ mp2Elm(2 ) = 3
270+ mp2Elm(3 ) = 2
271+ ! mp2Elm(4) is not needed/used since 4-th MP is inactive
272+ do i = 5 ,numMPs
273+ mp2Elm(i) = i-2 ! i=5 leads to mp2Elm(5)=3 (5-th MP in 3-rd element)
274+ ! i=numMPs leads to mp2Elm(numMPs=nCells+2)=numMPs-2=nCells
275+ end do
276+
277+ call createTest(mpMesh, nCells, numMPs, mp2Elm, isMPActive)
267278 call rebuildTests(mpMesh, numMPs, mp2Elm, isMPActive)
279+
268280 deallocate (mp2Elm)
269281 deallocate (isMPActive)
270282
0 commit comments