<p><b>croesch@ucar.edu</b> 2011-11-18 15:49:06 -0700 (Fri, 18 Nov 2011)</p><p>BRANCH COMMIT<br>
<br>
added code to differentiate halo cells and edges by layer<br>
<br>
M    mpas_io_input.F<br>
M    mpas_grid_types.F<br>
</p><hr noshade><pre><font color="gray">Modified: branches/halo/src/framework/mpas_grid_types.F
===================================================================
--- branches/halo/src/framework/mpas_grid_types.F        2011-11-18 21:02:50 UTC (rev 1203)
+++ branches/halo/src/framework/mpas_grid_types.F        2011-11-18 22:49:06 UTC (rev 1204)
@@ -84,6 +84,9 @@
    ! Derived type for storing grid meta-data
    type mesh_type
 
+      integer, dimension(3) :: nCellsHalo                 ! array dimension corresponds to the halo layer (where index 1 is own cells)  
+      integer, dimension(3) :: nEdgesWithinHaloPerimeter  ! array dimension corresponds to the halo layer (where index 1 is own cells perimeter)
+
 #include &quot;field_dimensions.inc&quot;
 
       logical :: on_a_sphere

Modified: branches/halo/src/framework/mpas_io_input.F
===================================================================
--- branches/halo/src/framework/mpas_io_input.F        2011-11-18 21:02:50 UTC (rev 1203)
+++ branches/halo/src/framework/mpas_io_input.F        2011-11-18 22:49:06 UTC (rev 1204)
@@ -97,6 +97,7 @@
       integer, dimension(:), pointer :: nEdgesOnCell_0Halo
       integer, dimension(:,:), pointer :: cellsOnCell_0Halo
    
+      integer, dimension(:), pointer :: nEdgesOnCell_2Halo
       integer, dimension(:,:), pointer :: edgesOnCell_2Halo
       integer, dimension(:,:), pointer :: verticesOnCell_2Halo
       integer, dimension(:,:), pointer :: cellsOnEdge_2Halo
@@ -130,6 +131,13 @@
       character(len=32) :: timeStamp
       character(len=1024) :: filename
 
+      integer, parameter :: nHalos = 3
+      integer, dimension(nHalos) :: nCellsHalo
+      integer, dimension(nHalos) :: nEdgesWithinHaloPerimeter
+      integer :: nOwnEdges, cellCount, edgeCount, iEdge
+      type (hashtable) :: hash
+
+
       if (config_do_restart) then
 
          ! this get followed by set is to ensure that the time is in standard format
@@ -524,6 +532,7 @@
       !   on each cell and which vertices are on each cell from the processes that read these
       !   fields for each cell to the processes that own the cells
       !
+      allocate(nEdgesOnCell_2Halo(block_graph_2Halo % nVerticesTotal))
       allocate(edgesOnCell_2Halo(maxEdges, block_graph_2Halo % nVerticesTotal))
       allocate(verticesOnCell_2Halo(maxEdges, block_graph_2Halo % nVerticesTotal))
    
@@ -531,6 +540,10 @@
                                 size(indexToCellIDField % array), block_graph_2Halo % nVerticesTotal, &amp;
                                 indexToCellIDField % array, block_graph_2Halo % vertexID, &amp;
                                 sendCellList, recvCellList)
+
+      call mpas_dmpar_alltoall_field(domain % dminfo, nEdgesOnCellField % array, nEdgesOnCell_2Halo, &amp;
+                                size(indexToCellIDField % array), size(local_cell_list), &amp;
+                                sendCellList, recvCellList)
    
       call mpas_dmpar_alltoall_field(domain % dminfo, edgesOnCellField % array, edgesOnCell_2Halo, &amp;
                                 maxEdges, nReadCells, block_graph_2Halo % nVerticesTotal, &amp;
@@ -540,7 +553,7 @@
                                 maxEdges, nReadCells, block_graph_2Halo % nVerticesTotal, &amp;
                                 sendCellList, recvCellList)
 
-   
+
       ! 
       ! Get a list of which edges and vertices are adjacent to cells (including halo cells) in block
       ! 
@@ -558,9 +571,9 @@
                                 size(indexToVertexIDField % array), nlocal_vertices, &amp;
                                 indexToVertexIDField % array, local_vertex_list, &amp;
                                 sendVertexList, recvVertexList)
-   
-   
-   
+
+
+
       ! 
       ! Work out which edges and vertices are owned by this process, and which are ghost
       ! 
@@ -584,6 +597,43 @@
                                               vertexDegree, nlocal_vertices, cellsOnVertex_2Halo, local_vertex_list, ghostVertexStart)
 
 
+      nCellsHalo(1) = block_graph_2Halo % nVertices
+      nCellsHalo(2) = block_graph_1Halo % nVerticesTotal
+      nCellsHalo(3) = block_graph_2Halo % nVerticesTotal
+
+      nOwnEdges = ghostEdgeStart-1
+
+      !------- determin the perimeter and owned edges of own cells and halos -------!  

+      ! skip the own edges found at the beginning of local_edge_list
+      call mpas_hash_init(hash)
+      do i=1,nOwnEdges
+         call mpas_hash_insert(hash, local_edge_list(i))
+      end do
+
+      edgeCount = nOwnEdges !tracks where to insert the next local edge
+      cellCount = 1         !tracks the index of the local cell array
+
+
+      !Order the local local_edge_list accordingly and set the bounds of each perimeter ---- 
+      do i = 1, nHalos ! for the own cells and each halo...
+         do j = cellCount, nCellsHalo(i)
+            do k = 1, nEdgesOnCell_2Halo(j)
+               iEdge = edgesOnCell_2Halo(k,j)
+               if (.not. mpas_hash_search(hash, iEdge)) then
+                  edgeCount = edgeCount + 1
+                  local_edge_list(edgeCount) = iEdge
+                  call mpas_hash_insert(hash, iEdge)
+               end if
+            end do
+         end do
+
+         nEdgesWithinHaloPerimeter(i) = edgeCount
+         cellCount = nCellsHalo(i) + 1
+
+      end do
+
+
       ! At this point, local_edge_list(1;ghostEdgeStart-1) contains all of the owned edges for this block
       !   and local_edge_list(ghostEdgeStart:nlocal_edges) contains all of the ghost edges
 
@@ -968,7 +1018,34 @@
       domain % blocklist % mesh % nVerticesSolve = ghostVertexStart-1
       domain % blocklist % mesh % nVertLevelsSolve = domain % blocklist % mesh % nVertLevels   ! No vertical decomp yet...
 
-   
+      domain % blocklist % mesh % nCellsHalo = nCellsHalo
+      domain % blocklist % mesh % nEdgesWithinHaloPerimeter = nEdgesWithinHaloPerimeter
+
+
+!CR:TODO: REMOVE THIS TEST CODE:
+!----------- Test Code ----------------
+
+ if(1 == 2) then
+      write(*,*) nCellsHalo(1)
+      write(*,*) nCellsHalo(2)
+      write(*,*) nCellsHalo(3)
+
+      do i=1, nCellsHalo(3)
+         write(*,*) domain % blocklist % mesh % indexToCellID % array(i)
+      end do
+ else
+      write(*,*) nOwnEdges
+      write(*,*) nEdgesWithinHaloPerimeter(1)
+      write(*,*) nEdgesWithinHaloPerimeter(2)
+      write(*,*) nEdgesWithinHaloPerimeter(3)

+      do i=1, nEdgesWithinHaloPerimeter(3)
+         write(*,*) domain % blocklist % mesh % indexToEdgeID % array(i)
+      end do
+ end if
+!-------------------------------------
+
+
       !
       ! Deallocate fields, graphs, and other memory
       !
@@ -1003,6 +1080,7 @@
       deallocate(indexToCellID_0Halo)
       deallocate(cellsOnEdge_2Halo)
       deallocate(cellsOnVertex_2Halo)
+      deallocate(nEdgesOnCell_2Halo)
       deallocate(edgesOnCell_2Halo)
       deallocate(verticesOnCell_2Halo)
       deallocate(block_graph_0Halo % vertexID)

</font>
</pre>