From e910b101869592c69b85e3db4b7dc3345b61d898 Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 24 Nov 2010 15:31:13 +0000 Subject: [PATCH] BR: debug on merge nodes and quadratic mixed operations --- src/SMDS/SMDS_Mesh.cxx | 11 +----- src/SMESH/SMESH_MeshEditor.cxx | 9 +++-- src/SMESH/SMESH_MesherHelper.cxx | 12 ------ src/SMESHDS/SMESHDS_Mesh.cxx | 2 +- src/SMESHDS/SMESHDS_SubMesh.cxx | 66 ++++++++++++++++++++++---------- 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index 132daa043..52452d0ee 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -1389,15 +1389,6 @@ bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element) int vtkId = cell->getVtkId(); if (vtkId == -1) vtkId = myElementIDFactory->SetInVtkGrid(element); - -// if (ID >= myCellIdSmdsToVtk.size()) // --- resize local vector -// { -// MESSAGE(" ------------------- resize myCellIdSmdsToVtk " << ID << " --> " << ID + SMDS_Mesh::chunkSize); -// myCellIdSmdsToVtk.resize(ID + SMDS_Mesh::chunkSize, -1); // fill new elements with -1 -// } -// -// myCellIdSmdsToVtk[ID] = vtkId; -// //MESSAGE("smds:" << ID << " vtk:" << vtkId ); if (vtkId >= myCellIdVtkToSmds.size()) // --- resize local vector { @@ -3095,7 +3086,7 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem) { int elemId = elem->GetID(); int vtkId = elem->getVtkId(); - //MESSAGE("SMDS_Mesh::RemoveFreeElement " << elemId); + //MESSAGE("RemoveFreeElement " << elemId); SMDSAbs_ElementType aType = elem->GetType(); SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem); if (aType == SMDSAbs_Node) { diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index f99b5ec51..b252fa009 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -7298,6 +7298,7 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) } // Regular elements + // TODO not all the possible cases are solved. Find something more generic? switch ( nbNodes ) { case 2: ///////////////////////////////////// EDGE isOk = false; break; @@ -7675,14 +7676,14 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) //MESSAGE("Change regular element or polygon " << elemId); SMDSAbs_ElementType etyp = elem->GetType(); uniqueNodes.resize(nbUniqueNodes); - aMesh->RemoveElement(elem); - SMDS_MeshElement* newElem = this->AddElement(uniqueNodes, etyp, false, elemId); + SMDS_MeshElement* newElem = this->AddElement(uniqueNodes, etyp, false); if (newElem) { myLastCreatedElems.Append(newElem); if ( aShapeId ) aMesh->SetMeshElementOnShape( newElem, aShapeId ); } + aMesh->RemoveElement(elem); } } else { @@ -7693,10 +7694,10 @@ void SMESH_MeshEditor::MergeNodes (TListOfListOfNodes & theGroupsOfNodes) } // loop on elements - // Remove equal nodes and bad elements + // Remove bad elements, then equal nodes (order important) - Remove( rmNodeIds, true ); Remove( rmElemIds, false ); + Remove( rmNodeIds, true ); } diff --git a/src/SMESH/SMESH_MesherHelper.cxx b/src/SMESH/SMESH_MesherHelper.cxx index 7945cc3a4..f708bccb0 100644 --- a/src/SMESH/SMESH_MesherHelper.cxx +++ b/src/SMESH/SMESH_MesherHelper.cxx @@ -740,19 +740,10 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1, const SMDS_PositionPtr Pos1 = n1->GetPosition(); const SMDS_PositionPtr Pos2 = n2->GetPosition(); - bool onGeom = true; - if ((Pos1->GetTypeOfPosition() != SMDS_TOP_FACE) && - (Pos1->GetTypeOfPosition() != SMDS_TOP_EDGE)) - onGeom = false; - if ((Pos2->GetTypeOfPosition() != SMDS_TOP_FACE) && - (Pos2->GetTypeOfPosition() != SMDS_TOP_EDGE)) - onGeom = false; - TopoDS_Edge E; double u [2]; TopoDS_Face F; gp_XY uv[2]; bool uvOK[2] = { false, false }; - if (onGeom) { if( myShape.IsNull() ) { if( Pos1->GetTypeOfPosition()==SMDS_TOP_FACE ) { @@ -843,7 +834,6 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1, } } } - } // onGeom // 3d variant double x = ( n1->X() + n2->X() )/2.; @@ -851,7 +841,6 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1, double z = ( n1->Z() + n2->Z() )/2.; n12 = meshDS->AddNode(x,y,z); - if (onGeom) { if ( !F.IsNull() ) { gp_XY UV = ( uv[0] + uv[1] ) / 2.; @@ -868,7 +857,6 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1, { meshDS->SetNodeInVolume(n12, myShapeID); } - } // onGeom myTLinkNodeMap.insert( make_pair( link, n12 )); return n12; diff --git a/src/SMESHDS/SMESHDS_Mesh.cxx b/src/SMESHDS/SMESHDS_Mesh.cxx index 1f20c437c..71b71045a 100644 --- a/src/SMESHDS/SMESHDS_Mesh.cxx +++ b/src/SMESHDS/SMESHDS_Mesh.cxx @@ -801,7 +801,7 @@ void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt) for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ ) if (!SubIt->second->IsComplexSubmesh() && SubIt->second->Contains( elt )) subMesh = SubIt->second; - + //MESSAGE("subMesh " << elt->getshapeId()); RemoveFreeElement( elt, subMesh, true); return; } diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index 1b5bbfd0c..aa85c9c96 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -54,6 +54,7 @@ void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) { if (!IsComplexSubmesh()) { + //MESSAGE("in " << myIndex << " AddElement "<< ME->GetID()); int idInSubShape = ME->getIdInShape(); if (idInSubShape != -1) { @@ -74,24 +75,29 @@ void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME) //======================================================================= bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted) { - // MESSAGE("--------------------------------------> RemoveElement " << isElemDeleted); + if (!ME) + { + MESSAGE("-----------------> Remove Null Element " << isElemDeleted); + return false; + } + //MESSAGE("-----------------> RemoveElement "<< ME->GetID() << " " << isElemDeleted); if (!IsComplexSubmesh()) { - if (!isElemDeleted) // alive element has valid ID and can be found + // if (!isElemDeleted) // alive element has valid ID and can be found + // { + int idInSubShape = ME->getIdInShape(); + //MESSAGE("in "<< myIndex << " RemoveElement " << ME->GetID() << " " << idInSubShape << " " << myUnusedIdElements); + SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME); + elem->setShapeId(0); + elem->setIdInShape(-1); + if ((idInSubShape >= 0) && (idInSubShape < myElements.size())) { - int idInSubShape = ME->getIdInShape(); - //MESSAGE("SMESHDS_SubMesh::RemoveElement " << idInSubShape << " " << ME->GetID() << " " << myUnusedIdElements); - assert(idInSubShape >= 0); - assert(idInSubShape < myElements.size()); - SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME); - elem->setShapeId(0); - elem->setIdInShape(-1); myElements[idInSubShape] = 0; // this vector entry is no more used myUnusedIdElements++; return true; } - //MESSAGE("Try to remove an already deleted element from a submesh "); return false; + // } } MESSAGE("Try to remove an element from a complex submesh "); return false; @@ -117,6 +123,7 @@ void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N) node->setShapeId(myIndex); node->setIdInShape(myNodes.size()); myNodes.push_back(N); + //MESSAGE("in "<< myIndex << " AddNode " << node->GetID()); } //MESSAGE("try to add node in a complex submesh " << N->GetID()); } @@ -130,22 +137,22 @@ bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted) { if (!IsComplexSubmesh()) { - if (!isNodeDeleted) // alive node has valid ID and can be found + // if (!isNodeDeleted) // alive node has valid ID and can be found + // { + int idInSubShape = N->getIdInShape(); + int shapeId = N->getshapeId(); + //MESSAGE("in "<< myIndex << " RemoveNode " << shapeId << " " << idInSubShape << " " << N->GetID()); + SMDS_MeshNode* node = (SMDS_MeshNode*) (N); + node->setShapeId(0); + node->setIdInShape(-1); + if ((idInSubShape >= 0) && (idInSubShape < myNodes.size())) { - int idInSubShape = N->getIdInShape(); - int shapeId = N->getshapeId(); - MESSAGE("SMESHDS_SubMesh::RemoveNode " << shapeId << " " << idInSubShape << " " << N->GetID()); - //assert(idInSubShape >= 0); - //assert(idInSubShape < myNodes.size()); - SMDS_MeshNode* node = (SMDS_MeshNode*) (N); - node->setShapeId(0); - node->setIdInShape(-1); myNodes[idInSubShape] = 0; // this vector entry is no more used myUnusedIdNodes++; return true; } - //MESSAGE("Try to remove an already deleted node from a submesh"); return false; + // } } MESSAGE("Try to remove a node from a complex submesh"); return false; @@ -424,7 +431,12 @@ int SMESHDS_SubMesh::getSize() void SMESHDS_SubMesh::compactList() { - MESSAGE("compactList old: nodes " << myNodes.size() << " elements " << myElements.size()); + //MESSAGE("compactList old: nodes " << myNodes.size() << " elements " << myElements.size()); + //stringstream a; + //stringstream b; + //stringstream c; + //stringstream d; + std::vector newElems; newElems.clear(); for (int i = 0; i < myElements.size(); i++) @@ -433,9 +445,15 @@ void SMESHDS_SubMesh::compactList() SMDS_MeshElement* elem = (SMDS_MeshElement*)myElements[i]; elem->setIdInShape(newElems.size()); newElems.push_back(elem); + //a << elem->GetID() << " "; + //b << elem->GetID() << " "; } + //else + // a << "_ "; myElements.swap(newElems); myUnusedIdElements = 0; + //MESSAGE("in " << myIndex << " oldElems " << a.str()); + //MESSAGE("in " << myIndex << " newElems " << b.str()); std::vector newNodes; newNodes.clear(); @@ -445,8 +463,14 @@ void SMESHDS_SubMesh::compactList() SMDS_MeshNode* node = (SMDS_MeshNode*)myNodes[i]; node->setIdInShape(newNodes.size()); newNodes.push_back(node); + //c << node->GetID() << " "; + //d << node->GetID() << " "; } + //else + // c << "_ "; myNodes.swap(newNodes); myUnusedIdNodes = 0; + //MESSAGE("in " << myIndex << " oldNodes " << c.str()); + //MESSAGE("in " << myIndex << " newNodes " << d.str()); //MESSAGE("compactList new: nodes " << myNodes.size() << " elements " << myElements.size()); } -- 2.39.2