Clean up of cout replaced by MESSAGE + minor corrections

This commit is contained in:
Yoann Audouin 2022-09-21 16:35:15 +02:00
parent f3fc21d3b2
commit c4f2013667
7 changed files with 84 additions and 105 deletions

View File

@ -25,6 +25,8 @@
// Module : SMESH // Module : SMESH
// //
#include "utilities.h"
#include "SMESH_DriverMesh.hxx" #include "SMESH_DriverMesh.hxx"
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
@ -53,7 +55,8 @@ bool diffMEDFile(const std::string mesh_file1, const std::string mesh_file2, con
} }
std::string getMeshName(std::string mesh_file){ std::string getMeshName(std::string mesh_file){
std::unique_ptr<MEDFileUMesh> myMedMesh=MEDFileUMesh::New(mesh_file); // TODO: Memory leak but desctructor private check with AG
MEDFileUMesh * myMedMesh = MEDFileUMesh::New(mesh_file);
return myMedMesh->getLevel0Mesh()->getName(); return myMedMesh->getLevel0Mesh()->getName();
} }
@ -70,7 +73,7 @@ std::string getMeshName(std::string mesh_file){
int importMesh(const std::string mesh_file, SMESH_Mesh& aMesh){ int importMesh(const std::string mesh_file, SMESH_Mesh& aMesh){
// TODO: change that as it depends on the language // TODO: change that as it depends on the language
std::string mesh_name = getMeshName(mesh_file); std::string mesh_name = getMeshName(mesh_file);
std::cout << "Importing mesh from " << mesh_file << " mesh " << mesh_name2 << std::endl; MESSAGE("Importing mesh from " << mesh_file << " mesh " << mesh_name);
int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str()); int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str());
return ret; return ret;
} }
@ -86,8 +89,7 @@ int importMesh(const std::string mesh_file, SMESH_Mesh& aMesh){
*/ */
int exportMesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){ int exportMesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
// TODO: See how to get the name of the mesh. Is it usefull ? MESSAGE("Exporting mesh to " << mesh_file);
std::cout << "Exporting mesh to " << mesh_file << std::endl;
aMesh.ExportMED(mesh_file.c_str(), // theFile aMesh.ExportMED(mesh_file.c_str(), // theFile
mesh_name.c_str(), // theMeshName mesh_name.c_str(), // theMeshName
false, // theAutoGroups false, // theAutoGroups

View File

@ -25,6 +25,7 @@
// Module : SMESH // Module : SMESH
// //
#include <utilities.h>
#include "SMESH_DriverShape.hxx" #include "SMESH_DriverShape.hxx"
// step include // step include
@ -53,22 +54,24 @@ namespace fs = boost::filesystem;
*/ */
int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){ int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){
std::cout << "Importing STEP shape from " << shape_file << std::endl; MESSAGE("Importing STEP shape from " << shape_file);
STEPControl_Reader reader; STEPControl_Reader reader;
// Forcing Unit in meter // Forcing Unit in meter
Interface_Static::SetCVal("xstep.cascade.unit","M"); Interface_Static::SetCVal("xstep.cascade.unit","M");
Interface_Static::SetIVal("read.step.ideas", 1); Interface_Static::SetIVal("read.step.ideas", 1);
Interface_Static::SetIVal("read.step.nonmanifold", 1); Interface_Static::SetIVal("read.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str()); IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str());
if(aStat != IFSelect_RetDone) if(aStat != IFSelect_RetDone){
std::cout << "Reading error for " << shape_file << std::endl; std::cerr << "Reading error for " << shape_file << std::endl;
return true;
}
int NbTrans = reader.TransferRoots(); int NbTrans = reader.TransferRoots();
// There should be only one shape within the file // There should be only one shape within the file
assert(NbTrans==1); assert(NbTrans==1);
aShape = reader.OneShape(); aShape = reader.OneShape();
return true; return false;
} }
/** /**
@ -81,7 +84,7 @@ int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){
*/ */
int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){ int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){
std::cout << "Exporting STEP shape to " << shape_file << std::endl; MESSAGE("Exporting STEP shape to " << shape_file);
STEPControl_Writer aWriter; STEPControl_Writer aWriter;
// Forcing Unit in meter // Forcing Unit in meter
@ -90,14 +93,17 @@ int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){
Interface_Static::SetIVal("write.step.nonmanifold", 1); Interface_Static::SetIVal("write.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs); IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs);
if(aStat != IFSelect_RetDone) if(aStat != IFSelect_RetDone){
std::cout << "Transfer error for " << shape_file << std::endl; std::cerr << "Transfer error for " << shape_file << std::endl;
return true;
}
aStat = aWriter.Write(shape_file.c_str()); aStat = aWriter.Write(shape_file.c_str());
if(aStat != IFSelect_RetDone) if(aStat != IFSelect_RetDone){
std::cout << "Writing error for " << shape_file << std::endl; std::cerr << "Writing error for " << shape_file << std::endl;
return true;
}
return aStat; return aStat;
} }
@ -111,11 +117,11 @@ int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){
*/ */
int importBREPShape(const std::string shape_file, TopoDS_Shape& aShape){ int importBREPShape(const std::string shape_file, TopoDS_Shape& aShape){
std::cout << "Importing BREP shape from " << shape_file << std::endl; MESSAGE("Importing BREP shape from " << shape_file);
BRep_Builder builder; BRep_Builder builder;
BRepTools::Read(aShape, shape_file.c_str(), builder); BRepTools::Read(aShape, shape_file.c_str(), builder);
return true; return false;
} }
/** /**
@ -128,10 +134,10 @@ int importBREPShape(const std::string shape_file, TopoDS_Shape& aShape){
*/ */
int exportBREPShape(const std::string shape_file, const TopoDS_Shape& aShape){ int exportBREPShape(const std::string shape_file, const TopoDS_Shape& aShape){
std::cout << "Exporting BREP shape to " << shape_file << std::endl; MESSAGE("Exporting BREP shape to " << shape_file);
BRepTools::Write(aShape, shape_file.c_str()); BRepTools::Write(aShape, shape_file.c_str());
return true; return false;
} }
/** /**
@ -150,8 +156,8 @@ int importShape(const std::string shape_file, TopoDS_Shape& aShape){
} else if (type == ".step"){ } else if (type == ".step"){
return importSTEPShape(shape_file, aShape); return importSTEPShape(shape_file, aShape);
} else { } else {
std::cout << "Unknow format: " << type << std::endl; std::cerr << "Unknow format: " << type << std::endl;
return false; return true;
} }
} }
@ -171,7 +177,7 @@ int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){
} else if (type == ".step"){ } else if (type == ".step"){
return exportSTEPShape(shape_file, aShape); return exportSTEPShape(shape_file, aShape);
} else { } else {
std::cout << "Unknow format: " << type << std::endl; std::cerr << "Unknow format: " << type << std::endl;
return false; return true;
} }
} }

View File

@ -48,7 +48,6 @@
#include <TopoDS_Iterator.hxx> #include <TopoDS_Iterator.hxx>
#include "memoire.h" #include "memoire.h"
#include <chrono>
#include <functional> #include <functional>
#ifdef WIN32 #ifdef WIN32
@ -249,8 +248,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX; TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
int nbThreads = aMesh.GetNbThreads(); int nbThreads = aMesh.GetNbThreads();
auto begin = std::chrono::high_resolution_clock::now(); MESSAGE("Running mesh with threads: " << nbThreads << " mesher: " << aMesh.GetMesherNbThreads());
std::cout << "Running mesh with threads: " << nbThreads << " mesher: " << aMesh.GetMesherNbThreads() << std::endl;
smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst); smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
@ -267,7 +265,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
aMesh.SetNbThreads(0); aMesh.SetNbThreads(0);
else else
aMesh.SetNbThreads(nbThreads); aMesh.SetNbThreads(nbThreads);
//DEBUG std::cout << "Shape Type" << shapeType << " previous" << previousShapeType << std::endl;
if ((aMesh.IsParallel()||nbThreads!=0) && shapeType != previousShapeType) { if ((aMesh.IsParallel()||nbThreads!=0) && shapeType != previousShapeType) {
// Waiting for all threads for the previous type to end // Waiting for all threads for the previous type to end
aMesh.wait(); aMesh.wait();
@ -312,8 +309,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
shapeSM, aShapeOnly, allowedSubShapes, shapeSM, aShapeOnly, allowedSubShapes,
aShapesId)); aShapesId));
} else { } else {
auto begin2 = std::chrono::high_resolution_clock::now();
compute_function(1 ,smToCompute, computeEvent, compute_function(1 ,smToCompute, computeEvent,
shapeSM, aShapeOnly, allowedSubShapes, shapeSM, aShapeOnly, allowedSubShapes,
aShapesId); aShapesId);
@ -333,13 +328,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
} }
aMesh.GetMeshDS()->Modified(); aMesh.GetMeshDS()->Modified();
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Time for All: " << elapsed.count()*1e-9 << std::endl;
// Pool of thread for computation
if(aMesh.IsParallel())
aMesh.DeletePoolThreads();
return ret; return ret;
} }
@ -351,7 +339,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
// the most complex shapes and collect sub-meshes with algos that // the most complex shapes and collect sub-meshes with algos that
// DO support sub-meshes // DO support sub-meshes
// ================================================================ // ================================================================
auto begin = std::chrono::high_resolution_clock::now();
list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim
// map to sort sm with same dim algos according to dim of // map to sort sm with same dim algos according to dim of
@ -547,11 +534,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
continue; continue;
sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes )); sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
setCurrentSubMesh( sm ); setCurrentSubMesh( sm );
auto begin = std::chrono::high_resolution_clock::now();
sm->ComputeStateEngine( computeEvent ); sm->ComputeStateEngine( computeEvent );
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Time for seq:alldim:compute: " << elapsed.count()*1e-9 << std::endl;
setCurrentSubMesh( NULL ); setCurrentSubMesh( NULL );
sm->SetAllowedSubShapes( nullptr ); sm->SetAllowedSubShapes( nullptr );
@ -565,9 +548,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
// mesh the rest sub-shapes starting from vertices // mesh the rest sub-shapes starting from vertices
// ----------------------------------------------- // -----------------------------------------------
ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes ); ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes );
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Time for All: " << elapsed.count()*1e-9 << std::endl;
} }

View File

@ -174,13 +174,11 @@ namespace
#ifndef WIN32 #ifndef WIN32
void deleteMeshDS(SMESHDS_Mesh* meshDS) void deleteMeshDS(SMESHDS_Mesh* meshDS)
{ {
//cout << "deleteMeshDS( " << meshDS << endl;
delete meshDS; delete meshDS;
} }
#else #else
static void* deleteMeshDS(void* meshDS) static void* deleteMeshDS(void* meshDS)
{ {
//cout << "deleteMeshDS( " << meshDS << endl;
SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS; SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
if(m) { if(m) {
delete m; delete m;
@ -240,10 +238,12 @@ SMESH_Mesh::~SMESH_Mesh()
pthread_t thread; pthread_t thread;
int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS); int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
#endif #endif
//fs::remove_all(tmp_folder);
} }
if(_pool)
DeletePoolThreads();
if (!MYDEBUG)
fs::remove_all(tmp_folder);
} }
//================================================================================ //================================================================================
@ -541,7 +541,7 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
Driver_Mesh::Status status = myReader.Perform(); Driver_Mesh::Status status = myReader.Perform();
#ifdef _DEBUG_ #ifdef _DEBUG_
SMESH_ComputeErrorPtr er = myReader.GetError(); SMESH_ComputeErrorPtr er = myReader.GetError();
if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl; if ( er && !er->IsOK() ) MESSAGE(er->myComment);
#endif #endif
// Reading groups (sub-meshes are out of scope of MED import functionality) // Reading groups (sub-meshes are out of scope of MED import functionality)
@ -1770,7 +1770,6 @@ double SMESH_Mesh::GetComputeProgress() const
rate = algo->GetProgressByTic(); rate = algo->GetProgressByTic();
computedCost += algoDoneCost + rate * algoNotDoneCost; computedCost += algoDoneCost + rate * algoNotDoneCost;
} }
// cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
} }
// get cost of already treated sub-meshes // get cost of already treated sub-meshes
@ -1791,9 +1790,6 @@ double SMESH_Mesh::GetComputeProgress() const
} }
} }
} }
// cout << "Total: " << totalCost
// << " computed: " << computedCost << " progress: " << computedCost / totalCost
// << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
return computedCost / totalCost; return computedCost / totalCost;
} }

View File

@ -3324,7 +3324,7 @@ double SMESH_MesherHelper::GetAngle( const TopoDS_Edge & theE1,
if ( ++nbLoops > 10 ) if ( ++nbLoops > 10 )
{ {
#ifdef _DEBUG_ #ifdef _DEBUG_
cout << "SMESH_MesherHelper::GetAngle(): Captured in a sigularity" << endl; MESSAGE("SMESH_MesherHelper::GetAngle(): Captured in a singularity");
#endif #endif
return angle; return angle;
} }
@ -5569,8 +5569,5 @@ void SMESH_MesherHelper::WriteShape(const TopoDS_Shape& s)
{ {
const char* name = "/tmp/shape.brep"; const char* name = "/tmp/shape.brep";
BRepTools::Write( s, name ); BRepTools::Write( s, name );
#ifdef _DEBUG_
std::cout << name << std::endl;
#endif
} }

View File

@ -1583,7 +1583,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
_computeError = SMESH_ComputeError::Worst( _computeError, algo->GetComputeError() ); _computeError = SMESH_ComputeError::Worst( _computeError, algo->GetComputeError() );
} }
catch ( ::SMESH_ComputeError& comperr ) { catch ( ::SMESH_ComputeError& comperr ) {
cout << " SMESH_ComputeError caught" << endl; MESSAGE(" SMESH_ComputeError caught");
if ( !_computeError ) _computeError = SMESH_ComputeError::New(); if ( !_computeError ) _computeError = SMESH_ComputeError::New();
*_computeError = comperr; *_computeError = comperr;
} }

View File

@ -6508,8 +6508,6 @@ CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType,
SMESH_CATCH( SMESH::doNothing ); SMESH_CATCH( SMESH::doNothing );
#ifdef _DEBUG_ MESSAGE("SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : ""));
cout << "SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "") << endl;
#endif
return true; return true;
} }