From aa574473cfc2112ef654904d6f2af9fd6e46d4c7 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 21 Aug 2018 15:06:54 +0300 Subject: [PATCH] Fix some tests regressions + time optimization of ex12_grid17partition.py --- src/SMESHDS/SMESHDS_SubMesh.cxx | 42 +++++++++++++++++++++----- src/SMESH_I/SMESH_Gen_i.cxx | 3 +- src/SMESH_I/SMESH_Gen_i.hxx | 2 ++ src/SMESH_I/SMESH_Gen_i_1.cxx | 11 +++++++ src/SMESH_SWIG/StdMeshersBuilder.py | 2 +- src/SMESH_SWIG/ex12_grid17partition.py | 14 +++++++-- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index 26c9ec128..cc5b6f7d3 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -142,8 +142,20 @@ bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * elem ) const SMDS_MeshElement* & elem1st = my1stElemNode[ ind1st( elem->GetType() )]; if ( elem1st == elem ) - elem1st = 0; - + { + if ( myNbElements > 0 ) + { + SMDS_ElemIteratorPtr it = myParent->shapeElementsIterator( myIndex, 1, elem1st ); + if ( it->more() ) + elem1st = it->next(); + else + throw SALOME_Exception(LOCALIZED("invalid myNbElements")); + } + else + { + elem1st = 0; + } + } return true; } return false; @@ -192,8 +204,21 @@ bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N) const SMDS_MeshElement* & node1st = my1stElemNode[ ind1st( SMDSAbs_Node )]; if ( node1st == N ) - node1st = 0; - + { + if ( myNbNodes > 0 ) + { + SMDS_NodeIteratorPtr it = + myParent->shapeNodesIterator( myIndex, 1, static_cast< PNode >( node1st )); + if ( it->more() ) + node1st = it->next(); + else + throw SALOME_Exception(LOCALIZED("invalid myNbNodes")); + } + else + { + node1st = 0; + } + } return true; } return false; @@ -309,9 +334,9 @@ SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements() const return SMDS_ElemIteratorPtr( new MyElemIterator( mySubMeshes )); const SMDS_MeshElement* const * elem1st = & my1stElemNode[ ind1st( SMDSAbs_All )]; - if ( myNbElements == 1 ) + if ( myNbElements < 2 ) { - return boost::make_shared< EArrayIterator >( elem1st, elem1st+1 ); + return boost::make_shared< EArrayIterator >( elem1st, elem1st + myNbElements ); } return myParent->shapeElementsIterator( myIndex, myNbElements, *elem1st ); @@ -329,9 +354,9 @@ SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const PNode const * node1st = reinterpret_cast< PNode const* >( & my1stElemNode[ ind1st( SMDSAbs_Node )] ); - if ( myNbNodes == 1 ) + if ( myNbNodes < 2 ) { - return boost::make_shared< NArrayIterator >( node1st, node1st+1 ); + return boost::make_shared< NArrayIterator >( node1st, node1st + myNbNodes ); } return myParent->shapeNodesIterator( myIndex, myNbNodes, *node1st ); @@ -459,6 +484,7 @@ void SMESHDS_SubMesh::Clear() myNbElements = 0; myNbNodes = 0; my1stElemNode[0] = my1stElemNode[1] = 0; + if ( NbSubMeshes() > 0 ) { SMESHDS_SubMeshIteratorPtr sub = GetSubMeshIterator(); diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index e6ebe05e9..f994b82f0 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -4965,8 +4965,7 @@ void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent ) if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" ); // Clear study contexts data - delete myStudyContext; - myStudyContext = 0; + myStudyContext->Clear(); // remove the tmp files meshes are loaded from SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent ); diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 2360fd4d1..21f55355e 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -79,6 +79,8 @@ public: void mapOldToNew( const int oldId, const int newId ); // get old id by a new one int getOldId( const int newId ); + // clear data + void Clear(); private: // get next free object identifier diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 9e54cbd49..af0dab97f 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -1401,3 +1401,14 @@ int StudyContext::getOldId( const int newId ) } return 0; } + +//======================================================================= +//function : Clear +//purpose : clear data +//======================================================================= + +void StudyContext::Clear() +{ + mapIdToIOR.Clear(); + mapIdToId.Clear(); +} diff --git a/src/SMESH_SWIG/StdMeshersBuilder.py b/src/SMESH_SWIG/StdMeshersBuilder.py index 26433141c..4b2999f26 100644 --- a/src/SMESH_SWIG/StdMeshersBuilder.py +++ b/src/SMESH_SWIG/StdMeshersBuilder.py @@ -458,7 +458,7 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm): hyp.SetFineness( fineness ) return hyp - def LengthNearVertex(self, length, vertex=0, UseExisting=0): + def LengthNearVertex(self, length, vertex=-1, UseExisting=0): """ Defines "SegmentLengthAroundVertex" hypothesis diff --git a/src/SMESH_SWIG/ex12_grid17partition.py b/src/SMESH_SWIG/ex12_grid17partition.py index 02e468333..49dc696b4 100644 --- a/src/SMESH_SWIG/ex12_grid17partition.py +++ b/src/SMESH_SWIG/ex12_grid17partition.py @@ -33,10 +33,13 @@ import SMESH, SALOMEDS from salome.smesh import smeshBuilder smesh = smeshBuilder.New() +import time +t1= time.time() + # Geometry # ======== -# grid compound of 17 x 17 elements +# grid compound of 3 x 3 elements # an element is compound of 3 concentric cylinders # an element is centered in a square of the grid @@ -56,7 +59,7 @@ g_rayon1 = 20 g_rayon2 = 30 g_rayon3 = 40 -g_grid = 17 +g_grid = 3 g_trim = 1000 @@ -120,6 +123,8 @@ piece = geompy.MakeMultiTranslation2D(c_element, geompy.MakeVectorDXDYDZ(1, 0, 0 piece_id = geompy.addToStudy(piece, "ex12_grid17partition") +t2= time.time() + # Meshing # ======= @@ -140,6 +145,11 @@ hexa.Hexahedron() hexa.Compute() +t3= time.time() + +print ("time geom",t2-t1) +print ("time mesh",t3-t2 ) + # Update object browser # --------------------- -- 2.39.2