From 3d82214289fb45a8d1298fda4e10f2b3701787f5 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Mon, 3 Oct 2022 16:15:33 +0200 Subject: [PATCH] Adding control of netgen log file --- src/NETGENPlugin/NETGENPlugin_Mesher.cxx | 34 ++++++++++++------- src/NETGENPlugin/NETGENPlugin_Mesher.hxx | 1 + .../NETGENPlugin_NETGEN_3D_SA.cxx | 5 +++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index 615c970..44535f2 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -4437,18 +4437,7 @@ NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper(): _ngcerr = NULL; if ( !getenv( "KEEP_NETGEN_OUTPUT" )) { - // redirect all netgen output (mycout,myerr,cout) to _outputFileName - _outputFileName = getOutputFileName(); - _ngcout = netgen::mycout; - _ngcerr = netgen::myerr; - netgen::mycout = new ofstream ( _outputFileName.c_str() ); - netgen::myerr = netgen::mycout; - _coutBuffer = std::cout.rdbuf(); -#ifdef _DEBUG_ - std::cout << "NOTE: netgen output is redirected to file " << _outputFileName << std::endl; -#else - std::cout.rdbuf( netgen::mycout->rdbuf() ); -#endif + setOutputFile(getOutputFileName()); } setMesh( Ng_NewMesh() ); @@ -4569,6 +4558,27 @@ std::string NETGENPlugin_NetgenLibWrapper::getOutputFileName() return aGenericName.ToCString(); } +//================================================================================ +/*! + * \brief Set output file name for netgen log + */ +//================================================================================ + +void NETGENPlugin_NetgenLibWrapper::setOutputFile(std::string outputfile) +{ + // redirect all netgen output (mycout,myerr,cout) to _outputFileName + _outputFileName = outputfile; + _ngcout = netgen::mycout; + _ngcerr = netgen::myerr; + netgen::mycout = new ofstream ( _outputFileName.c_str() ); + netgen::myerr = netgen::mycout; + _coutBuffer = std::cout.rdbuf(); +#ifdef _DEBUG_ + std::cout << "NOTE: netgen output is redirected to file " << _outputFileName << std::endl; +#else + std::cout.rdbuf( netgen::mycout->rdbuf() ); +#endif +} //================================================================================ /*! diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx index 6d06f81..0a3f514 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx @@ -105,6 +105,7 @@ struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper static void RemoveTmpFiles(); static int& instanceCounter(); + void setOutputFile(std::string); private: std::string getOutputFileName(); diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_SA.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_SA.cxx index bddb65c..6dfc100 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_SA.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_SA.cxx @@ -202,6 +202,11 @@ bool NETGENPlugin_NETGEN_3D_SA::Compute(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, int endWith = netgen::MESHCONST_OPTVOLUME; int Netgen_NbOfNodes=0; + // Changing netgen log_file putting it next to new_element_file + fs::path netgen_log_file = fs::path(new_element_file).remove_filename() / fs::path("NETGEN.out"); + + ngLib.setOutputFile(netgen_log_file.string()); + NETGENPlugin_NETGEN_3D::computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, Netgen_NbOfNodes); netgen::OCCGeometry occgeo; -- 2.39.2