ENH: polyTopoChange : store zone as DynamicList<label> to avoid HashTable::erase...
authormattijs <mattijs>
Tue, 8 Jun 2010 13:33:32 +0000 (8 14:33 +0100)
committermattijs <mattijs>
Tue, 8 Jun 2010 13:33:32 +0000 (8 14:33 +0100)
src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C
src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.H
src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChangeTemplates.C

index be84405..a85fd3b 100644 (file)
@@ -784,7 +784,10 @@ void Foam::polyTopoChange::reorderCompactFaces
     renumberKey(oldToNew, faceFromEdge_);
     inplaceReorder(oldToNew, flipFaceFlux_);
     flipFaceFlux_.setCapacity(newSize);
-    renumberKey(oldToNew, faceZone_);
+
+    reorder(oldToNew, faceZone_);
+    faceZone_.setCapacity(newSize);
+
     inplaceReorder(oldToNew, faceZoneFlip_);
     faceZoneFlip_.setCapacity(newSize);
 }
@@ -806,6 +809,7 @@ void Foam::polyTopoChange::compact
     points_.shrink();
     pointMap_.shrink();
     reversePointMap_.shrink();
+    pointZone_.shrink();
 
     faces_.shrink();
     region_.shrink();
@@ -813,6 +817,7 @@ void Foam::polyTopoChange::compact
     faceNeighbour_.shrink();
     faceMap_.shrink();
     reverseFaceMap_.shrink();
+    faceZone_.shrink();
 
     cellMap_.shrink();
     reverseCellMap_.shrink();
@@ -966,7 +971,8 @@ void Foam::polyTopoChange::compact
         pointMap_.setCapacity(newPointI);
         renumberReverseMap(localPointMap, reversePointMap_);
 
-        renumberKey(localPointMap, pointZone_);
+        reorder(localPointMap, pointZone_);
+        pointZone_.setCapacity(newPointI);
         renumber(localPointMap, retiredPoints_);
 
         // Use map to relabel face vertices
@@ -1475,21 +1481,25 @@ void Foam::polyTopoChange::resetZones
 
         labelList nPoints(pointZones.size(), 0);
 
-        forAllConstIter(Map<label>, pointZone_, iter)
+        forAll(pointZone_, pointI)
         {
-            label zoneI = iter();
+            label zoneI = pointZone_[pointI];
 
-            if (zoneI < 0 || zoneI >= pointZones.size())
+            if (zoneI >= pointZones.size())
             {
                 FatalErrorIn
                 (
                     "resetZones(const polyMesh&, polyMesh&, labelListList&"
                     "labelListList&, labelListList&)"
                 )   << "Illegal zoneID " << zoneI << " for point "
-                    << iter.key() << " coord " << mesh.points()[iter.key()]
+                    << pointI << " coord " << mesh.points()[pointI]
                     << abort(FatalError);
             }
-            nPoints[zoneI]++;
+
+            if (zoneI >= 0)
+            {
+                nPoints[zoneI]++;
+            }
         }
 
         // Distribute points per zone
@@ -1501,11 +1511,13 @@ void Foam::polyTopoChange::resetZones
         }
         nPoints = 0;
 
-        forAllConstIter(Map<label>, pointZone_, iter)
+        forAll(pointZone_, pointI)
         {
-            label zoneI = iter();
-
-            addressing[zoneI][nPoints[zoneI]++] = iter.key();
+            label zoneI = pointZone_[pointI];
+            if (zoneI >= 0)
+            {
+                addressing[zoneI][nPoints[zoneI]++] = pointI;
+            }
         }
         // Sort the addressing
         forAll(addressing, zoneI)
@@ -1562,21 +1574,24 @@ void Foam::polyTopoChange::resetZones
 
         labelList nFaces(faceZones.size(), 0);
 
-        forAllConstIter(Map<label>, faceZone_, iter)
+        forAll(faceZone_, faceI)
         {
-            label zoneI = iter();
+            label zoneI = faceZone_[faceI];
 
-            if (zoneI < 0 || zoneI >= faceZones.size())
+            if (zoneI >= faceZones.size())
             {
                 FatalErrorIn
                 (
                     "resetZones(const polyMesh&, polyMesh&, labelListList&"
                     "labelListList&, labelListList&)"
                 )   << "Illegal zoneID " << zoneI << " for face "
-                    << iter.key()
+                    << faceI
                     << abort(FatalError);
             }
-            nFaces[zoneI]++;
+            if (zoneI >= 0)
+            {
+                nFaces[zoneI]++;
+            }
         }
 
         labelListList addressing(faceZones.size());
@@ -1589,15 +1604,16 @@ void Foam::polyTopoChange::resetZones
         }
         nFaces = 0;
 
-        forAllConstIter(Map<label>, faceZone_, iter)
+        forAll(faceZone_, faceI)
         {
-            label zoneI = iter();
-            label faceI = iter.key();
-
-            label index = nFaces[zoneI]++;
+            label zoneI = faceZone_[faceI];
 
-            addressing[zoneI][index] = faceI;
-            flipMode[zoneI][index] = faceZoneFlip_[faceI];
+            if (zoneI >= 0)
+            {
+                label index = nFaces[zoneI]++;
+                addressing[zoneI][index] = faceI;
+                flipMode[zoneI][index] = faceZoneFlip_[faceI];
+            }
         }
         // Sort the addressing
         forAll(addressing, zoneI)
@@ -2212,7 +2228,7 @@ void Foam::polyTopoChange::addMesh
         points_.setCapacity(points_.size() + points.size());
         pointMap_.setCapacity(pointMap_.size() + points.size());
         reversePointMap_.setCapacity(reversePointMap_.size() + points.size());
-        pointZone_.resize(pointZone_.size() + points.size()/100);
+        pointZone_.setCapacity(pointZone_.size() + points.size());
 
         // Precalc offset zones
         labelList newZoneID(points.size(), -1);
@@ -2319,9 +2335,9 @@ void Foam::polyTopoChange::addMesh
         reverseFaceMap_.setCapacity(reverseFaceMap_.size() + nAllFaces);
         faceFromPoint_.resize(faceFromPoint_.size() + nAllFaces/100);
         faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/100);
-        flipFaceFlux_.setCapacity(faces_.size() + nAllFaces);
-        faceZone_.resize(faceZone_.size() + nAllFaces/100);
-        faceZoneFlip_.setCapacity(faces_.size() + nAllFaces);
+        flipFaceFlux_.setCapacity(flipFaceFlux_.size() + nAllFaces);
+        faceZone_.setCapacity(faceZone_.size() + nAllFaces);
+        faceZoneFlip_.setCapacity(faceZoneFlip_.size() + nAllFaces);
 
 
         // Precalc offset zones
@@ -2411,7 +2427,7 @@ void Foam::polyTopoChange::setCapacity
     points_.setCapacity(nPoints);
     pointMap_.setCapacity(nPoints);
     reversePointMap_.setCapacity(nPoints);
-    pointZone_.resize(pointZone_.size() + nPoints/100);
+    pointZone_.setCapacity(nPoints);
 
     faces_.setCapacity(nFaces);
     region_.setCapacity(nFaces);
@@ -2422,7 +2438,7 @@ void Foam::polyTopoChange::setCapacity
     faceFromPoint_.resize(faceFromPoint_.size() + nFaces/100);
     faceFromEdge_.resize(faceFromEdge_.size() + nFaces/100);
     flipFaceFlux_.setCapacity(nFaces);
-    faceZone_.resize(faceZone_.size() + nFaces/100);
+    faceZone_.setCapacity(nFaces);
     faceZoneFlip_.setCapacity(nFaces);
 
     cellMap_.setCapacity(nCells);
@@ -2577,11 +2593,7 @@ Foam::label Foam::polyTopoChange::addPoint
     points_.append(pt);
     pointMap_.append(masterPointID);
     reversePointMap_.append(pointI);
-
-    if (zoneID >= 0)
-    {
-        pointZone_.insert(pointI, zoneID);
-    }
+    pointZone_.append(zoneID);
 
     if (!inCell)
     {
@@ -2618,24 +2630,7 @@ void Foam::polyTopoChange::modifyPoint
             << abort(FatalError);
     }
     points_[pointI] = pt;
-
-    Map<label>::iterator pointFnd = pointZone_.find(pointI);
-
-    if (pointFnd != pointZone_.end())
-    {
-        if (newZoneID >= 0)
-        {
-            pointFnd() = newZoneID;
-        }
-        else
-        {
-            pointZone_.erase(pointFnd);
-        }
-    }
-    else if (newZoneID >= 0)
-    {
-        pointZone_.insert(pointI, newZoneID);
-    }
+    pointZone_[pointI] = newZoneID;
 
     if (inCell)
     {
@@ -2709,7 +2704,7 @@ void Foam::polyTopoChange::removePoint
     {
         reversePointMap_[pointI] = -1;
     }
-    pointZone_.erase(pointI);
+    pointZone_[pointI] = -1;
     retiredPoints_.erase(pointI);
 }
 
@@ -2767,11 +2762,7 @@ Foam::label Foam::polyTopoChange::addFace
     reverseFaceMap_.append(faceI);
 
     flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0);
-
-    if (zoneID >= 0)
-    {
-        faceZone_.insert(faceI, zoneID);
-    }
+    faceZone_.append(zoneID);
     faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
 
     return faceI;
@@ -2802,24 +2793,7 @@ void Foam::polyTopoChange::modifyFace
     region_[faceI] = patchID;
 
     flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0);
-
-    Map<label>::iterator faceFnd = faceZone_.find(faceI);
-
-    if (faceFnd != faceZone_.end())
-    {
-        if (zoneID >= 0)
-        {
-            faceFnd() = zoneID;
-        }
-        else
-        {
-            faceZone_.erase(faceFnd);
-        }
-    }
-    else if (zoneID >= 0)
-    {
-        faceZone_.insert(faceI, zoneID);
-    }
+    faceZone_[faceI] = zoneID;
     faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
 }
 
@@ -2862,7 +2836,7 @@ void Foam::polyTopoChange::removeFace(const label faceI, const label mergeFaceI)
     faceFromEdge_.erase(faceI);
     faceFromPoint_.erase(faceI);
     flipFaceFlux_[faceI] = 0;
-    faceZone_.erase(faceI);
+    faceZone_[faceI] = -1;
     faceZoneFlip_[faceI] = 0;
 }
 
index 0406085..00e8e0a 100644 (file)
@@ -134,7 +134,7 @@ class polyTopoChange
             DynamicList<label> reversePointMap_;
 
             //- Zone of point
-            Map<label> pointZone_;
+            DynamicList<label> pointZone_;
 
             //- Retired points
             labelHashSet retiredPoints_;
@@ -174,7 +174,7 @@ class polyTopoChange
             PackedBoolList flipFaceFlux_;
 
             //- Zone of face
-            Map<label> faceZone_;
+            DynamicList<label> faceZone_;
 
             //- Orientation of face in zone
             PackedBoolList faceZoneFlip_;
index 53129b2..527138e 100644 (file)
@@ -22,8 +22,6 @@ License
     along with OpenFOAM; if not, write to the Free Software Foundation,
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
-Description
-
 \*---------------------------------------------------------------------------*/
 
 #include "polyTopoChange.H"