From 2bebe506c33a21426e3fdd23c14f4838da79f006 Mon Sep 17 00:00:00 2001 From: Louis Gombert Date: Wed, 21 Aug 2024 14:16:22 +0000 Subject: [PATCH] Debugging, changes to run C++ with Emscripten --- src/SMDS/SMDS_ElementFactory.cxx | 17 ++++++++++++++--- src/SMDS/SMDS_Mesh.cxx | 10 ++++++++++ src/SMESH/SMESH_Gen.cxx | 4 ++++ src/SMESH/SMESH_Mesh.cxx | 13 ++++++++++--- src/StdMeshers/StdMeshers_Hexa_3D.cxx | 1 + 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/SMDS/SMDS_ElementFactory.cxx b/src/SMDS/SMDS_ElementFactory.cxx index a90107433..68a420151 100644 --- a/src/SMDS/SMDS_ElementFactory.cxx +++ b/src/SMDS/SMDS_ElementFactory.cxx @@ -130,13 +130,14 @@ smIdType SMDS_ElementFactory::GetMaxID() { smIdType id = 0; TIndexRanges usedRanges; - for ( smIdType i = myChunks.size() - 1; i >= 0; --i ) + for ( smIdType i = myChunks.size() - 1; i >= 0 && !myChunks.empty(); --i ) if ( myChunks[i].GetUsedRanges().GetIndices( true, usedRanges )) { int index = usedRanges.back().second-1; id = myChunks[i].Get1stID() + index; break; } + std::cout << "Max id is " << id << std::endl; return id; } @@ -151,7 +152,7 @@ smIdType SMDS_ElementFactory::GetMinID() { smIdType id = 0; TIndexRanges usedRanges; - for ( size_t i = 0; i < myChunks.size(); ++i ) + for ( size_t i = 0; i < myChunks.size() && !myChunks.empty(); ++i ) if ( myChunks[i].GetUsedRanges().GetIndices( true, usedRanges )) { int index = usedRanges[0].first; @@ -171,6 +172,8 @@ smIdType SMDS_ElementFactory::GetMinID() SMDS_MeshElement* SMDS_ElementFactory::NewElement( const smIdType id ) { + // std::cout << "New element" << id << std::endl; + smIdType iChunk = ( id - 1 ) / theChunkSize; smIdType index = ( id - 1 ) % theChunkSize; while ((smIdType) myChunks.size() <= iChunk ) @@ -202,6 +205,7 @@ SMDS_MeshElement* SMDS_ElementFactory::NewElement( const smIdType id ) const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const smIdType id ) const { + // std::cout << "Find element, # chunks: " << myChunks.size() << std::endl; if ( id > 0 ) { smIdType iChunk = ( id - 1 ) / theChunkSize; @@ -212,7 +216,7 @@ const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const smIdType id ) co return e->IsNull() ? 0 : e; } } - return 0; + return nullptr; } //================================================================================ @@ -490,6 +494,7 @@ void SMDS_NodeFactory::Clear() void SMDS_NodeFactory::SetNbShapes( size_t nbShapes ) { + std::cout << "Set Nb Shapes node" << nbShapes << std::endl; clearVector( myShapeDim ); myShapeDim.resize( nbShapes+1, theDefaultShapeDim ); } @@ -513,6 +518,8 @@ int SMDS_NodeFactory::GetShapeDim( int shapeID ) const void SMDS_NodeFactory::SetShapeDim( int shapeID, int dim ) { + // std::cout << "Set shape dim node" << shapeID << " " << dim << std::endl; + if ( shapeID >= (int)myShapeDim.size() ) myShapeDim.resize( shapeID + 10, theDefaultShapeDim ); myShapeDim[ shapeID ] = dim; @@ -689,6 +696,8 @@ int SMDS_ElementChunk::GetShapeID( const SMDS_MeshElement* e ) const void SMDS_ElementChunk::SetShapeID( const SMDS_MeshElement* e, int shapeID ) const { + // std::cout << "Set shape ID node" << shapeID << std::endl; + //const size_t nbRanges = mySubIDRanges.Size(); SMDS_ElementChunk* me = const_cast( this ); @@ -794,6 +803,8 @@ SMDS_PositionPtr SMDS_ElementChunk::GetPosition( const SMDS_MeshNode* n ) const void SMDS_ElementChunk::SetPosition( const SMDS_MeshNode* n, const SMDS_PositionPtr& pos, int shapeID ) { + // std::cout << "Set node position" << shapeID << std::endl; + int shapeDim = pos ? pos->GetDim() : theDefaultShapeDim; if ( shapeID < 1 ) { diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index 04b495259..930c66831 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -2998,13 +2998,18 @@ void SMDS_Mesh::CompactMesh() { this->myCompactTime = this->myModifTime; + std::cout << "Start has holes" << std::endl; bool idsChange = HasNumerationHoles(); + std::cout << "done holes" << std::endl; + if ( idsChange ) { std::set< SMDS_ElementHolder* >::iterator holder = myElemHolders.begin(); for ( ; holder != myElemHolders.end(); ++holder ) (*holder)->beforeCompacting(); } + std::cout << "OldCellSize" << std::endl; + smIdType oldCellSize = myCellFactory->GetMaxID(); // remove "holes" in SMDS numeration @@ -3012,6 +3017,8 @@ void SMDS_Mesh::CompactMesh() myNodeFactory->Compact( idNodesOldToNew ); myCellFactory->Compact( idCellsNewToOld ); + std::cout << "removed holes" << std::endl; + // make VTK IDs correspond to SMDS IDs smIdType newNodeSize = myNodeFactory->NbUsedElements(); smIdType newCellSize = myCellFactory->NbUsedElements(); @@ -3028,6 +3035,8 @@ void SMDS_Mesh::CompactMesh() idCellsOldToNew[ idCellsNewToOld[ iNew ]] = iNew; } } + std::cout << "Restore elements" << std::endl; + std::set< SMDS_ElementHolder* >::iterator holder = myElemHolders.begin(); for ( ; holder != myElemHolders.end(); ++holder ) @@ -3084,5 +3093,6 @@ bool SMDS_Mesh::HasNumerationHoles() void SMDS_Mesh::setNbShapes( size_t nbShapes ) { + std::cout << "Set nb shapes to " << nbShapes << std::endl; myNodeFactory->SetNbShapes( nbShapes ); } diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index fd15c2c5e..6546b38f3 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -757,11 +757,15 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, } } + std::cout << "Start compact" << std::endl; if ( aCompactMesh ) { aMesh.GetMeshDS()->Modified(); + std::cout << "Done modified compact" << std::endl; aMesh.GetMeshDS()->CompactMesh(); } + std::cout << "Done compact" << std::endl; + return ret; } diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index e5356836b..c3123f2f3 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -643,12 +643,19 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape, anError->clear(); SMESH_subMesh *subMesh = GetSubMesh(aSubShape); - if ( !subMesh || !subMesh->GetId()) + if ( !subMesh || !subMesh->GetId()) { + // std::cout << "Could not get submesh" << std::endl; return SMESH_Hypothesis::HYP_BAD_SUBSHAPE; - + } + SMESH_Hypothesis *anHyp = GetHypothesis( anHypId ); - if ( !anHyp ) + if ( !anHyp ) { + // std::cout << "Could not get submesh" << std::endl; throw SALOME_Exception(LOCALIZED("hypothesis does not exist")); + } + + // std::cout << "All ok" << std::endl; + bool isGlobalHyp = IsMainShape( aSubShape ); diff --git a/src/StdMeshers/StdMeshers_Hexa_3D.cxx b/src/StdMeshers/StdMeshers_Hexa_3D.cxx index eb8cc3b09..337201dad 100644 --- a/src/StdMeshers/StdMeshers_Hexa_3D.cxx +++ b/src/StdMeshers/StdMeshers_Hexa_3D.cxx @@ -548,6 +548,7 @@ namespace bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) { + std::cout << "Start compute Hexa 3D" << std::endl; // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside //Unexpect aCatch(SalomeException); SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();