Salome HOME
23514: EDF 16031 - SMESH freezes
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.cxx
index dc1e094b02c31ed4ee97b1e0e4d64d48e8ca8a16..865e700c13332585d7087bbc0cf6195ac25c0bcd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -213,14 +213,13 @@ void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z
 
 //=======================================================================
 //function : ChangeElementNodes
-//purpose  : 
+//purpose  : Changed nodes of an element provided that nb of nodes does not change
 //=======================================================================
 
 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
                                       const SMDS_MeshNode    * nodes[],
                                       const int                nbnodes)
 {
-  //MESSAGE("SMESHDS_Mesh::ChangeElementNodes");
   if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
     return false;
 
@@ -708,9 +707,9 @@ SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (const std::vector<int>& nod
   return anElem;
 }
 
-SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
-                             (const std::vector<const SMDS_MeshNode*>& nodes,
-                              const int                                ID)
+SMDS_MeshFace*
+SMESHDS_Mesh::AddPolygonalFaceWithID (const std::vector<const SMDS_MeshNode*>& nodes,
+                                      const int                                ID)
 {
   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
   if (anElem) {
@@ -724,8 +723,8 @@ SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
   return anElem;
 }
 
-SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
-                             (const std::vector<const SMDS_MeshNode*>& nodes)
+SMDS_MeshFace*
+SMESHDS_Mesh::AddPolygonalFace (const std::vector<const SMDS_MeshNode*>& nodes)
 {
   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
   if (anElem) {
@@ -739,6 +738,53 @@ SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
   return anElem;
 }
 
+
+//=======================================================================
+//function : AddQuadPolygonalFace
+//purpose  : 
+//=======================================================================
+SMDS_MeshFace* SMESHDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector<int>& nodes_ids,
+                                                         const int               ID)
+{
+  SMDS_MeshFace *anElem = SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes_ids, ID);
+  if (anElem) {
+    myScript->AddQuadPolygonalFace(ID, nodes_ids);
+  }
+  return anElem;
+}
+
+SMDS_MeshFace*
+SMESHDS_Mesh::AddQuadPolygonalFaceWithID (const std::vector<const SMDS_MeshNode*>& nodes,
+                                          const int                                ID)
+{
+  SMDS_MeshFace *anElem = SMDS_Mesh::AddQuadPolygonalFaceWithID(nodes, ID);
+  if (anElem) {
+    int i, len = nodes.size();
+    std::vector<int> nodes_ids (len);
+    for (i = 0; i < len; i++) {
+      nodes_ids[i] = nodes[i]->GetID();
+    }
+    myScript->AddQuadPolygonalFace(ID, nodes_ids);
+  }
+  return anElem;
+}
+
+SMDS_MeshFace*
+SMESHDS_Mesh::AddQuadPolygonalFace (const std::vector<const SMDS_MeshNode*>& nodes)
+{
+  SMDS_MeshFace *anElem = SMDS_Mesh::AddQuadPolygonalFace(nodes);
+  if (anElem) {
+    int i, len = nodes.size();
+    std::vector<int> nodes_ids (len);
+    for (i = 0; i < len; i++) {
+      nodes_ids[i] = nodes[i]->GetID();
+    }
+    myScript->AddQuadPolygonalFace(anElem->GetID(), nodes_ids);
+  }
+  return anElem;
+}
+
+
 //=======================================================================
 //function : AddPolyhedralVolume
 //purpose  : 
@@ -847,16 +893,7 @@ void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
 {
   if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces()))
   {
-    SMESHDS_SubMesh* subMesh = MeshElements( n->getshapeId() );
-    SMESHDS_SubMeshIteratorPtr subIt;
-    if ( !subMesh )
-      subIt = SubMeshes();
-    for ( ; !subMesh && subIt->more(); ) {
-      subMesh = const_cast< SMESHDS_SubMesh* >( subIt->next() );
-      if ( subMesh->IsComplexSubmesh() || !subMesh->Contains( n ))
-        subMesh = 0;
-    }
-    RemoveFreeNode( n, subMesh, true);
+    RemoveFreeNode( n, 0, true );
     return;
   }
 
@@ -918,7 +955,7 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
     if ( elt->getshapeId() > 0 )
       subMesh = MeshElements( elt->getshapeId() );
 
-    RemoveFreeElement( elt, subMesh, true);
+    RemoveFreeElement( elt, subMesh, true );
     return;
   }
  
@@ -927,7 +964,7 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
   list<const SMDS_MeshElement *> removedElems;
   list<const SMDS_MeshElement *> removedNodes;
 
-  SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
+  SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false );
   
   removeFromContainers( this, myGroups, removedElems, false );
 }
@@ -940,9 +977,8 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt,
                                      SMESHDS_SubMesh *        subMesh,
                                      bool                     fromGroups)
 {
-  //MESSAGE(" --------------------------------> SMESHDS_Mesh::RemoveFreeElement " << subMesh << " " << fromGroups);
   if (elt->GetType() == SMDSAbs_Node) {
-    RemoveFreeNode( static_cast<const SMDS_MeshNode*>(elt), subMesh);
+    RemoveFreeNode( static_cast<const SMDS_MeshNode*>(elt), subMesh, fromGroups);
     return;
   }
 
@@ -953,7 +989,7 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt,
   myScript->RemoveElement(elt->GetID());
 
   // Rm from group
-  // Node can belong to several groups
+  // Element can belong to several groups
   if ( fromGroups && !myGroups.empty() ) {
     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
     for (; GrIt != myGroups.end(); GrIt++) {
@@ -965,10 +1001,12 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt,
 
   // Rm from sub-mesh
   // Element should belong to only one sub-mesh
-  if( subMesh )
-    subMesh->RemoveElement(elt, /*deleted=*/false);
+  if ( !subMesh && elt->getshapeId() > 0 )
+    subMesh = MeshElements( elt->getshapeId() );
+  if ( subMesh )
+    subMesh->RemoveElement( elt, /*deleted=*/false );
 
-  SMDS_Mesh::RemoveFreeElement(elt);
+  SMDS_Mesh::RemoveFreeElement( elt );
 }
 
 //================================================================================
@@ -1305,7 +1343,6 @@ int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
     bool all = ( type == TopAbs_SHAPE );
     if ( all ) // corresponding simple submesh may exist
       aMainIndex = -aMainIndex;
-    //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
     SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
     if ( !aNewSub->IsComplexSubmesh() ) // is empty
     {
@@ -1337,7 +1374,7 @@ const TopoDS_Shape& SMESHDS_Mesh::IndexToShape(int ShapeIndex) const
     if ( ShapeIndex > 0 )
       return myIndexToShape.FindKey(ShapeIndex);
   }
-  catch ( Standard_OutOfRange )
+  catch ( ... )
   {
   }
   static TopoDS_Shape nullShape;
@@ -1361,11 +1398,7 @@ int SMESHDS_Mesh::MaxSubMeshIndex() const
 //=======================================================================
 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
 {
-  if (myShape.IsNull())
-    MESSAGE("myShape is NULL");
-
   int index = myIndexToShape.FindIndex(S);
-  
   return index;
 }
 
@@ -1829,7 +1862,7 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
 
 //=======================================================================
 //function : AddVolume
-//purpose  : 
+//purpose  : 2nd order pentahedron (prism) with 15 nodes
 //=======================================================================
 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
                                          const SMDS_MeshNode * n2, 
@@ -1860,7 +1893,7 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
 
 //=======================================================================
 //function : AddVolumeWithID
-//purpose  : 
+//purpose  : 2nd order pentahedron (prism) with 15 nodes
 //=======================================================================
 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
                                                int n4, int n5, int n6,
@@ -1876,10 +1909,96 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
                                  n45,n56,n64,n14,n25,n36);
   return anElem;
 }
+
+//=======================================================================
+//function : AddVolumeWithID
+//purpose  : 2d order Pentahedron (prism) with 15 nodes
+//=======================================================================
+SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
+                                               const SMDS_MeshNode * n2,
+                                               const SMDS_MeshNode * n3,
+                                               const SMDS_MeshNode * n4,
+                                               const SMDS_MeshNode * n5,
+                                               const SMDS_MeshNode * n6,
+                                               const SMDS_MeshNode * n12,
+                                               const SMDS_MeshNode * n23,
+                                               const SMDS_MeshNode * n31,
+                                               const SMDS_MeshNode * n45,
+                                               const SMDS_MeshNode * n56,
+                                               const SMDS_MeshNode * n64,
+                                               const SMDS_MeshNode * n14,
+                                               const SMDS_MeshNode * n25,
+                                               const SMDS_MeshNode * n36,
+                                               int ID)
+{
+  return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
+                         n4->GetID(), n5->GetID(), n6->GetID(),
+                         n12->GetID(), n23->GetID(), n31->GetID(),
+                         n45->GetID(), n56->GetID(), n64->GetID(),
+                         n14->GetID(), n25->GetID(), n36->GetID(),
+                         ID);
+}
+//=======================================================================
+//function : AddVolume
+//purpose  : 2nd order pentahedron (prism) with 18 nodes
+//=======================================================================
+SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
+                                         const SMDS_MeshNode * n2,
+                                         const SMDS_MeshNode * n3,
+                                         const SMDS_MeshNode * n4,
+                                         const SMDS_MeshNode * n5,
+                                         const SMDS_MeshNode * n6,
+                                         const SMDS_MeshNode * n12,
+                                         const SMDS_MeshNode * n23,
+                                         const SMDS_MeshNode * n31,
+                                         const SMDS_MeshNode * n45,
+                                         const SMDS_MeshNode * n56,
+                                         const SMDS_MeshNode * n64,
+                                         const SMDS_MeshNode * n14,
+                                         const SMDS_MeshNode * n25,
+                                         const SMDS_MeshNode * n36,
+                                         const SMDS_MeshNode * n1245,
+                                         const SMDS_MeshNode * n2356,
+                                         const SMDS_MeshNode * n1346)
+{
+  SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n12,n23,n31,
+                                                 n45,n56,n64,n14,n25,n36,
+                                                 n1245, n2356, n1346);
+  if(anElem)
+    myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
+                        n3->GetID(), n4->GetID(), n5->GetID(), n6->GetID(),
+                        n12->GetID(), n23->GetID(), n31->GetID(),
+                        n45->GetID(), n56->GetID(), n64->GetID(),
+                        n14->GetID(), n25->GetID(), n36->GetID(),
+                        n1245->GetID(), n2356->GetID(), n1346->GetID());
+  return anElem;
+}
+
+//=======================================================================
+//function : AddVolumeWithID
+//purpose  : 2nd order pentahedron (prism) with 18 nodes
+//=======================================================================
+SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
+                                               int n4, int n5, int n6,
+                                               int n12,int n23,int n31,
+                                               int n45,int n56,int n64,
+                                               int n14,int n25,int n36,
+                                               int n1245, int n2356, int n1346,
+                                               int ID)
+{
+  SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,
+                                                       n12,n23,n31,
+                                                       n45,n56,n64,
+                                                       n14,n25,n36,
+                                                       n1245, n2356, n1346, ID);
+  if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n12,n23,n31,
+                                 n45,n56,n64,n14,n25,n36, n1245, n2356, n1346);
+  return anElem;
+}
         
 //=======================================================================
 //function : AddVolumeWithID
-//purpose  : 2d order Pentahedron with 15 nodes
+//purpose  : 2d order Pentahedron with 18 nodes
 //=======================================================================
 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
                                                const SMDS_MeshNode * n2,
@@ -1896,6 +2015,9 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
                                                const SMDS_MeshNode * n14,
                                                const SMDS_MeshNode * n25,
                                                const SMDS_MeshNode * n36,
+                                               const SMDS_MeshNode * n1245,
+                                               const SMDS_MeshNode * n2356,
+                                               const SMDS_MeshNode * n1346,
                                                int ID)
 {
   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
@@ -1903,7 +2025,7 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
                          n12->GetID(), n23->GetID(), n31->GetID(),
                          n45->GetID(), n56->GetID(), n64->GetID(),
                          n14->GetID(), n25->GetID(), n36->GetID(),
-                         ID);
+                         n1245->GetID(), n2356->GetID(), n1346->GetID(), ID);
 }
 
 
@@ -2076,18 +2198,18 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
                                                const SMDS_MeshNode * n2,
                                                const SMDS_MeshNode * n3,
                                                const SMDS_MeshNode * n4,
-                                               const SMDS_MeshNode * n5, 
-                                               const SMDS_MeshNode * n6, 
+                                               const SMDS_MeshNode * n5,
+                                               const SMDS_MeshNode * n6,
                                                const SMDS_MeshNode * n7,
-                                               const SMDS_MeshNode * n8, 
+                                               const SMDS_MeshNode * n8,
                                                const SMDS_MeshNode * n12,
                                                const SMDS_MeshNode * n23,
                                                const SMDS_MeshNode * n34,
-                                               const SMDS_MeshNode * n41, 
+                                               const SMDS_MeshNode * n41,
                                                const SMDS_MeshNode * n56,
                                                const SMDS_MeshNode * n67,
                                                const SMDS_MeshNode * n78,
-                                               const SMDS_MeshNode * n85, 
+                                               const SMDS_MeshNode * n85,
                                                const SMDS_MeshNode * n15,
                                                const SMDS_MeshNode * n26,
                                                const SMDS_MeshNode * n37,
@@ -2112,51 +2234,41 @@ SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
 
 void SMESHDS_Mesh::compactMesh()
 {
+  if ( isCompacted() )
+    return;
+  SMDS_Mesh::compactMesh();
+
   int newNodeSize = 0;
-  int nbNodes = myNodes.size();
-  int nbVtkNodes = myGrid->GetNumberOfPoints();
-  MESSAGE("nbNodes=" << nbNodes << " nbVtkNodes=" << nbVtkNodes);
-  int nbNodeTemp = nbVtkNodes;
-  if (nbNodes > nbVtkNodes)
-    nbNodeTemp = nbNodes;
-  vector<int> idNodesOldToNew;
-  idNodesOldToNew.clear();
-  idNodesOldToNew.resize(nbNodeTemp, -1); // all unused id will be -1
+  int nbNodes     = myNodes.size();
+  int nbVtkNodes  = myGrid->GetNumberOfPoints();
+  int nbNodeTemp  = Max( nbVtkNodes, nbNodes );
+  vector<int> idNodesOldToNew(nbNodeTemp, -1); // all unused id will be -1
 
   for (int i = 0; i < nbNodes; i++)
+  {
+    if (myNodes[i])
     {
-      if (myNodes[i])
-        {
-          int vtkid = myNodes[i]->getVtkId();
-          idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0)
-          newNodeSize++;
-        }
+      int vtkid = myNodes[i]->getVtkId();
+      idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0)
+      newNodeSize++;
     }
-  bool areNodesModified = (newNodeSize < nbVtkNodes);
-  MESSAGE("------------------------- compactMesh Nodes Modified: " << areNodesModified);
+  }
+  bool areNodesModified = (newNodeSize != nbVtkNodes);
   areNodesModified = true;
 
   int newCellSize = 0;
-  int nbCells = myCells.size();
-  int nbVtkCells = myGrid->GetNumberOfCells();
-  MESSAGE("nbCells=" << nbCells << " nbVtkCells=" << nbVtkCells);
-  int nbCellTemp = nbVtkCells;
-  if (nbCells > nbVtkCells)
-    nbCellTemp = nbCells;
-  vector<int> idCellsOldToNew;
-  idCellsOldToNew.clear();
-  idCellsOldToNew.resize(nbCellTemp, -1); // all unused id will be -1
+  int nbCells     = myCells.size();
+  int nbVtkCells  = myGrid->GetNumberOfCells();
+  int nbCellTemp  = Max( nbVtkCells, nbCells );
+  vector<int> idCellsOldToNew(nbCellTemp, -1); // all unused id will be -1
 
   for (int i = 0; i < nbCells; i++)
+  {
+    if (myCells[i])
     {
-      if (myCells[i])
-        {
-//          //idCellsOldToNew[i] = myCellIdVtkToSmds[i]; // valid vtk indexes are > = 0
-//          int vtkid = myCells[i]->getVtkId();
-//          idCellsOldToNew[vtkid] = i; // old vtkId --> old smdsId (not used in input)
-          newCellSize++;
-        }
+      newCellSize++;
     }
+  }
   if (areNodesModified)
     myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize);
   else
@@ -2165,95 +2277,72 @@ void SMESHDS_Mesh::compactMesh()
   int nbVtkPts = myGrid->GetNumberOfPoints();
   nbVtkCells = myGrid->GetNumberOfCells();
   if (nbVtkPts != newNodeSize)
-    {
-      MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize);
-      if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id
-    }
+  {
+    MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize);
+    if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id
+  }
   if (nbVtkCells != newCellSize)
-    {
-      MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize);
-      if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id
-    }
+  {
+    MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize);
+    if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id
+  }
 
-  // --- SMDS_MeshNode and myNodes (id in SMDS and in VTK are the same), myNodeIdFactory
+  // --- SMDS_MeshNode and myNodes, myNodeIdFactory
 
-  if (areNodesModified)
+  if ( true )
+  {
+    SetOfNodes newNodes(newNodeSize+1,NULL); // 0 not used, SMDS numbers 1..n
+    int newSmdsId = 0;
+    for (int i = 0; i < nbNodes; i++)
     {
-      MESSAGE("-------------- modify myNodes");
-      SetOfNodes newNodes;
-      newNodes.resize(newNodeSize+1,0); // 0 not used, SMDS numbers 1..n
-      int newSmdsId = 0;
-      for (int i = 0; i < nbNodes; i++)
-        {
-          if (myNodes[i])
-            {
-              newSmdsId++; // SMDS id start to 1
-              int oldVtkId = myNodes[i]->getVtkId();
-              int newVtkId = idNodesOldToNew[oldVtkId];
-              //MESSAGE("myNodes["<< i << "] vtkId " << oldVtkId << " --> " << newVtkId);
-              myNodes[i]->setVtkId(newVtkId);
-              myNodes[i]->setId(newSmdsId);
-              newNodes[newSmdsId] = myNodes[i];
-              //MESSAGE("myNodes["<< i << "] --> newNodes[" << newSmdsId << "]");
-            }
-        }
-      myNodes.swap(newNodes);
-      this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes
-      MESSAGE("myNodes.size " << myNodes.size());
+      if (myNodes[i])
+      {
+        newSmdsId++; // SMDS id starts from 1
+        int oldVtkId = myNodes[i]->getVtkId();
+        int newVtkId = idNodesOldToNew[oldVtkId];
+        myNodes[i]->setVtkId(newVtkId);
+        myNodes[i]->setId(newSmdsId);
+        newNodes[newSmdsId] = myNodes[i];
+      }
     }
+    myNodes.swap(newNodes);
+    this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes
+  }
 
   // --- SMDS_MeshCell, myCellIdVtkToSmds, myCellIdSmdsToVtk, myCells
 
   int vtkIndexSize = myCellIdVtkToSmds.size();
-  int maxVtkId = -1;
   for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++)
+  {
+    int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId];
+    if (oldSmdsId > 0)
     {
-      int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId];
-      if (oldSmdsId > 0)
-        {
-          int newVtkId = idCellsOldToNew[oldVtkId];
-          if (newVtkId > maxVtkId)
-            maxVtkId = newVtkId;
-          //MESSAGE("myCells["<< oldSmdsId << "] vtkId " << oldVtkId << " --> " << newVtkId);
-          myCells[oldSmdsId]->setVtkId(newVtkId);
-        }
+      int newVtkId = idCellsOldToNew[oldVtkId];
+      myCells[oldSmdsId]->setVtkId(newVtkId);
     }
-//  MESSAGE("myCells.size()=" << myCells.size()
-//          << " myCellIdSmdsToVtk.size()=" << myCellIdSmdsToVtk.size()
-//          << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
-
-  SetOfCells newCells;
-  //vector<int> newSmdsToVtk;
-  vector<int> newVtkToSmds;
+  }
 
-  assert(maxVtkId < newCellSize);
-  newCells.resize(newCellSize+1, 0); // 0 not used, SMDS numbers 1..n
-  //newSmdsToVtk.resize(newCellSize+1, -1);
-  newVtkToSmds.resize(newCellSize+1, -1);
+  SetOfCells      newCells(newCellSize+1, NULL); // 0 not used, SMDS numbers 1..n
+  vector<int> newVtkToSmds(newCellSize+1, -1);
 
   int myCellsSize = myCells.size();
   int newSmdsId = 0;
   for (int i = 0; i < myCellsSize; i++)
   {
-    if (myCells[i])
+    if ( myCells[i] )
     {
-      newSmdsId++; // SMDS id start to 1
+      newSmdsId++; // SMDS id starts from 1
       assert(newSmdsId <= newCellSize);
       newCells[newSmdsId] = myCells[i];
       newCells[newSmdsId]->setId(newSmdsId);
-      //MESSAGE("myCells["<< i << "] --> newCells[" << newSmdsId << "]");
       int idvtk = myCells[i]->getVtkId();
-      //newSmdsToVtk[newSmdsId] = idvtk;
       assert(idvtk < newCellSize);
       newVtkToSmds[idvtk] = newSmdsId;
     }
   }
 
   myCells.swap(newCells);
-  //myCellIdSmdsToVtk.swap(newSmdsToVtk);
   myCellIdVtkToSmds.swap(newVtkToSmds);
-  MESSAGE("myCells.size()=" << myCells.size()
-          << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
   this->myElementIDFactory->emptyPool(newSmdsId);
 
   this->myScript->SetModified(true); // notify GUI client for buildPrs when update