From 01afecee316c9fd4759eb1175be12740d196fc9b Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Tue, 13 Sep 2022 16:46:00 +0200 Subject: [PATCH] Renaming functions and files + minor corrections in runner_main to detect what to do --- src/NETGENPlugin/CMakeLists.txt | 19 +- ...param.cxx => NETGENPlugin_DriverParam.cxx} | 14 +- ...param.hxx => NETGENPlugin_DriverParam.hxx} | 16 +- .../NETGENPlugin_NETGEN_2D_ONLY.cxx | 16 +- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx | 26 +- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx | 3 +- src/NETGENPlugin/NETGENPlugin_Provider.hxx | 152 ----------- ...gen_mesher.cxx => NETGENPlugin_Runner.cxx} | 101 ++++---- ...gen_mesher.hxx => NETGENPlugin_Runner.hxx} | 18 +- src/NETGENPlugin/NETGENPlugin_Runner_main.cxx | 105 ++++++++ src/NETGENPlugin/run_mesher.cxx | 242 ------------------ 11 files changed, 214 insertions(+), 498 deletions(-) rename src/NETGENPlugin/{netgen_param.cxx => NETGENPlugin_DriverParam.cxx} (95%) rename src/NETGENPlugin/{netgen_param.hxx => NETGENPlugin_DriverParam.hxx} (85%) delete mode 100644 src/NETGENPlugin/NETGENPlugin_Provider.hxx rename src/NETGENPlugin/{netgen_mesher.cxx => NETGENPlugin_Runner.cxx} (92%) rename src/NETGENPlugin/{netgen_mesher.hxx => NETGENPlugin_Runner.hxx} (85%) create mode 100644 src/NETGENPlugin/NETGENPlugin_Runner_main.cxx delete mode 100644 src/NETGENPlugin/run_mesher.cxx diff --git a/src/NETGENPlugin/CMakeLists.txt b/src/NETGENPlugin/CMakeLists.txt index e2c27db..7a57bb0 100644 --- a/src/NETGENPlugin/CMakeLists.txt +++ b/src/NETGENPlugin/CMakeLists.txt @@ -93,9 +93,8 @@ SET(NETGENEngine_HEADERS NETGENPlugin_Mesher.hxx NETGENPlugin_Remesher_2D.hxx NETGENPlugin_Defs.hxx - NETGENPlugin_Provider.hxx - netgen_param.hxx - netgen_mesher.hxx + NETGENPlugin_DriverParam.hxx + NETGENPlugin_Runner.hxx ) # --- sources --- @@ -123,12 +122,12 @@ SET(NETGENEngine_SOURCES NETGENPlugin_SimpleHypothesis_3D_i.cxx NETGENPlugin_Remesher_2D.cxx NETGENPlugin_i.cxx - netgen_mesher.cxx - netgen_param.cxx + NETGENPlugin_Runner.cxx + NETGENPlugin_DriverParam.cxx ) -SET(Run_Mesher_SOURCES - run_mesher.cxx +SET(NetgenRunner_SOURCES + NETGENPlugin_Runner_main.cxx ) # --- scripts --- @@ -145,9 +144,9 @@ ADD_LIBRARY(NETGENEngine ${NETGENEngine_SOURCES}) TARGET_LINK_LIBRARIES(NETGENEngine ${_link_LIBRARIES} ) INSTALL(TARGETS NETGENEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) -ADD_EXECUTABLE(run_mesher ${Run_Mesher_SOURCES}) -TARGET_LINK_LIBRARIES(run_mesher ${_link_LIBRARIES} NETGENEngine ) -INSTALL(TARGETS run_mesher EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) +ADD_EXECUTABLE(NETGENPlugin_Runner ${NetgenRunner_SOURCES}) +TARGET_LINK_LIBRARIES(NETGENPlugin_Runner ${_link_LIBRARIES} NETGENEngine ) +INSTALL(TARGETS NETGENPlugin_Runner EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) INSTALL(FILES ${NETGENEngine_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/NETGENPlugin/netgen_param.cxx b/src/NETGENPlugin/NETGENPlugin_DriverParam.cxx similarity index 95% rename from src/NETGENPlugin/netgen_param.cxx rename to src/NETGENPlugin/NETGENPlugin_DriverParam.cxx index 0c69081..2ddf398 100644 --- a/src/NETGENPlugin/netgen_param.cxx +++ b/src/NETGENPlugin/NETGENPlugin_DriverParam.cxx @@ -20,11 +20,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : netgen_param.hxx +// File : NETGENPlugin_DriverParam.hxx // Author : Yoann AUDOUIN, EDF -// Module : SMESH +// Module : NETGEN // -#include "netgen_param.hxx" +#include "NETGENPlugin_DriverParam.hxx" #include #include @@ -39,7 +39,7 @@ * * @param aParams The object to display */ -void print_netgen_params(netgen_params& aParams){ +void printNetgenParams(netgen_params& aParams){ // TODO: prettier print // TODO: Add call to print in log std::cout << "has_netgen_param: " << aParams.has_netgen_param << std::endl; @@ -76,7 +76,7 @@ void print_netgen_params(netgen_params& aParams){ * @param param_file Name of the file * @param aParams Structure to fill */ -void import_netgen_params(const std::string param_file, netgen_params& aParams){ +void importNetgenParams(const std::string param_file, netgen_params& aParams){ std::ifstream myfile(param_file); std::string line; @@ -142,7 +142,7 @@ void import_netgen_params(const std::string param_file, netgen_params& aParams){ * @param param_file the file * @param aParams the object */ -void export_netgen_params(const std::string param_file, netgen_params& aParams){ +void exportNetgenParams(const std::string param_file, netgen_params& aParams){ std::ofstream myfile(param_file); myfile << aParams.has_netgen_param << std::endl; myfile << aParams.maxh << std::endl; @@ -182,7 +182,7 @@ void export_netgen_params(const std::string param_file, netgen_params& aParams){ * @return true if the two object are identical */ -bool diff_netgen_params(netgen_params params1, netgen_params params2){ +bool diffNetgenParams(netgen_params params1, netgen_params params2){ bool ret = true; ret &= params1.maxh == params2.maxh; ret &= params1.minh == params2.minh; diff --git a/src/NETGENPlugin/netgen_param.hxx b/src/NETGENPlugin/NETGENPlugin_DriverParam.hxx similarity index 85% rename from src/NETGENPlugin/netgen_param.hxx rename to src/NETGENPlugin/NETGENPlugin_DriverParam.hxx index 0958931..0f53512 100644 --- a/src/NETGENPlugin/netgen_param.hxx +++ b/src/NETGENPlugin/NETGENPlugin_DriverParam.hxx @@ -20,13 +20,13 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : netgen_param.hxx +// File : NETGENPlugin_DriverParam.hxx // Author : Yoann AUDOUIN, EDF -// Module : SMESH +// Module : NETGEN // -#ifndef _NETGEN_PARAM_HXX_ -#define _NETGEN_PARAM_HXX_ +#ifndef _NETGENPLUGIN_DRIVERPARAM_HXX_ +#define _NETGENPLUGIN_DRIVERPARAM_HXX_ #include @@ -86,11 +86,11 @@ struct netgen_params{ int nbThreads; }; -void print_netgen_params(netgen_params& aParams); +void printNetgenParams(netgen_params& aParams); -void import_netgen_params(const std::string param_file, netgen_params& aParams); -void export_netgen_params(const std::string param_file, netgen_params& aParams); +void importNetgenParams(const std::string param_file, netgen_params& aParams); +void exportNetgenParams(const std::string param_file, netgen_params& aParams); -bool diff_netgen_params(netgen_params params1, netgen_params params2); +bool diffNetgenParams(netgen_params params1, netgen_params params2); #endif \ No newline at end of file diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index a5b7765..d8db3de 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -1,4 +1,3 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -25,8 +24,7 @@ #include "NETGENPlugin_Mesher.hxx" #include "NETGENPlugin_Hypothesis_2D.hxx" -#include "NETGENPlugin_Provider.hxx" -#include "netgen_param.hxx" +#include "NETGENPlugin_DriverParam.hxx" #include #include @@ -41,8 +39,8 @@ #include #include #include -#include "DriverStep.hxx" -#include "DriverMesh.hxx" +#include "SMESH_DriverStep.hxx" +#include "SMESH_DriverMesh.hxx" #include @@ -324,17 +322,17 @@ bool NETGENPlugin_NETGEN_2D_ONLY::RemoteCompute(SMESH_Mesh& aMesh, fs::path output_mesh_file=tmp_folder / fs::path("output_mesh.med"); fs::path shape_file=tmp_folder / fs::path("shape.step"); fs::path param_file=tmp_folder / fs::path("netgen2d_param.txt"); - fs::path log_file=tmp_folder / fs::path("run_mesher.log"); + fs::path log_file=tmp_folder / fs::path("run.log"); //TODO: Handle variable mesh_name std::string mesh_name = "Maillage_1"; //Writing Shape - export_shape(shape_file.string(), aShape); + exportShape(shape_file.string(), aShape); //Writing hypo netgen_params aParams; FillParameters(_hypParameters, aParams); - export_netgen_params(param_file.string(), aParams); + exportNetgenParams(param_file.string(), aParams); // Exporting element orientation exportElementOrientation(aMesh, aShape, aParams, element_orientation_file.string()); @@ -347,7 +345,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::RemoteCompute(SMESH_Mesh& aMesh, fs::path(std::getenv("NETGENPLUGIN_ROOT_DIR"))/ fs::path("bin")/ fs::path("salome")/ - fs::path("run_mesher"); + fs::path("NETGENPlugin_Runner"); cmd = run_mesher_exe.string() + " NETGEN2D " + mesh_file.string() + " " + shape_file.string() + " " diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index b3d624f..f08232e 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -32,9 +32,7 @@ #include "NETGENPlugin_Hypothesis.hxx" -#include "DriverStep.hxx" -#include "DriverMesh.hxx" -#include "netgen_param.hxx" +#include "NETGENPlugin_DriverParam.hxx" #include #include @@ -50,6 +48,9 @@ #include #include #include +#include +#include + #include #include @@ -196,7 +197,7 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, } -void NETGENPlugin_NETGEN_3D::FillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams) +void NETGENPlugin_NETGEN_3D::fillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams) { aParams.maxh = hyp->GetMaxSize(); aParams.minh = hyp->GetMinSize(); @@ -315,21 +316,21 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, fs::path output_mesh_file=tmp_folder / fs::path("output_mesh.med"); fs::path shape_file=tmp_folder / fs::path("shape.step"); fs::path param_file=tmp_folder / fs::path("netgen3d_param.txt"); - fs::path log_file=tmp_folder / fs::path("run_mesher.log"); + fs::path log_file=tmp_folder / fs::path("run.log"); //TODO: Handle variable mesh_name std::string mesh_name = "Maillage_1"; //Writing Shape - export_shape(shape_file.string(), aShape); + exportShape(shape_file.string(), aShape); auto time2 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time2-time1); - std::cout << "Time for export_shape: " << elapsed.count() * 1e-9 << std::endl; + std::cout << "Time for exportShape: " << elapsed.count() * 1e-9 << std::endl; //Writing hypo netgen_params aParams; - FillParameters(_hypParameters, aParams); + fillParameters(_hypParameters, aParams); - export_netgen_params(param_file.string(), aParams); + exportNetgenParams(param_file.string(), aParams); auto time3 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time3-time2); std::cout << "Time for fill+export param: " << elapsed.count() * 1e-9 << std::endl; @@ -338,7 +339,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, exportElementOrientation(aMesh, aShape, aParams, element_orientation_file.string()); auto time4 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time4-time3); - std::cout << "Time for exportElemnOrient: " << elapsed.count() * 1e-9 << std::endl; + std::cout << "Time for exportElemOrient: " << elapsed.count() * 1e-9 << std::endl; aMesh.Unlock(); // Calling run_mesher @@ -348,7 +349,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, fs::path(std::getenv("NETGENPLUGIN_ROOT_DIR"))/ fs::path("bin")/ fs::path("salome")/ - fs::path("run_mesher"); + fs::path("NETGENPlugin_Runner"); cmd = run_mesher_exe.string() + " NETGEN3D " + mesh_file.string() + " " + shape_file.string() + " " @@ -356,8 +357,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, + element_orientation_file.string() + " " + std::to_string(aMesh.GetMesherNbThreads()) + " " + new_element_file.string() + " " - + std::to_string(0) + " " - + output_mesh_file.string() + + + "NONE" + " >> " + log_file.string(); //std::cout << "Running command: " << std::endl; diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx index bff3634..0fa04a0 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx @@ -31,7 +31,6 @@ #ifndef _NETGENPlugin_NETGEN_3D_HXX_ #define _NETGENPlugin_NETGEN_3D_HXX_ -#include "NETGENPlugin_Provider.hxx" #include "NETGENPlugin_Defs.hxx" #include "NETGENPlugin_Mesher.hxx" @@ -75,7 +74,7 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo netgen_params& aParams, const std::string output_file); - void FillParameters(const NETGENPlugin_Hypothesis* hyp, + void fillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams); int RemoteCompute(SMESH_Mesh& aMesh, diff --git a/src/NETGENPlugin/NETGENPlugin_Provider.hxx b/src/NETGENPlugin/NETGENPlugin_Provider.hxx deleted file mode 100644 index d262789..0000000 --- a/src/NETGENPlugin/NETGENPlugin_Provider.hxx +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : NETGENPlugin_Provider.hxx -// Author : Yoann AUDOUIN (EDF) -// Project : SALOME -// -#ifndef _NETGENPlugin_Provider_HXX_ -#define _NETGENPlugin_Provider_HXX_ - -#include -#include -#include -#include -#include -#include - -namespace nglib { -#include -} -#ifndef OCCGEOMETRY -#define OCCGEOMETRY -#endif -#include -#include - -template -class ProviderPtr{ - public: - - ProviderPtr(){ - for(int i=0;i_mydata[i] = nullptr; - this->_useddata[i] = false; - } - } - - int take(T** data){ - - this->_mymutex.lock(); - *data = nullptr; - for(int i=0;i_useddata[i]){ - if (this->_mydata[i] == nullptr) - this->_mydata[i] = new T(); - this->_useddata[i] = true; - *data = this->_mydata[i]; - this->_mymutex.unlock(); - return i; - } - } - this->_mymutex.unlock(); - return -1; - }; - - - bool release(int i, bool clean){ - - this->_mymutex.lock(); - - if(clean){ - delete this->_mydata[i]; - this->_mydata[i] = nullptr; - } - - this->_useddata[i] = false; - - this->_mymutex.unlock(); - - return true; - }; - - void dump(){ - std::cout << "Dumping provider:" << std::endl; - for(int i=0;i_useddata[i] << std::endl; - std::cout << " - adress: " << this->_mydata[i] << std::endl; - if (this->_mydata[i] != nullptr) - std::cout << " - i: " << this->_mydata[i]->i << " d: " << this->_mydata[i]->d << std::endl; - } - }; - - private: - std::array _mydata; - std::array _useddata; - std::mutex _mymutex; - -}; - -template -class Provider{ - public: - - Provider() = default; - - int take(T& data){ - - this->_mymutex.lock(); - for(int i=0;i_useddata[i]){ - this->_useddata[i] = true; - data = this->_mydata[i]; - this->_mymutex.unlock(); - return i; - } - } - this->_mymutex.unlock(); - return -1; - }; - - - bool release(int i){ - - this->_mymutex.lock(); - this->_useddata[i] = false; - this->_mymutex.unlock(); - - return true; - }; - - void dump(){ - std::cout << "Dumping provider:" << std::endl; - for(int i=0;i_useddata[i] << std::endl; - std::cout << " - i: " << this->_mydata[i].i << " d: " << this->_mydata[i].d << std::endl; - } - }; - - private: - std::array _mydata; - std::array _useddata; - std::mutex _mymutex; - -}; - -#endif \ No newline at end of file diff --git a/src/NETGENPlugin/netgen_mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Runner.cxx similarity index 92% rename from src/NETGENPlugin/netgen_mesher.cxx rename to src/NETGENPlugin/NETGENPlugin_Runner.cxx index d867f3b..e69dcd5 100644 --- a/src/NETGENPlugin/netgen_mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Runner.cxx @@ -20,21 +20,20 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : netgen_mesher.cxx +// File : NETGENPlugin_Runner.cxx // Author : Yoann AUDOUIN, EDF // Module : SMESH // -#include "netgen_mesher.hxx" +#include "NETGENPlugin_Runner.hxx" -#include "DriverStep.hxx" -#include "DriverMesh.hxx" -#include "netgen_param.hxx" + +#include "NETGENPlugin_DriverParam.hxx" #include #include -#include -namespace fs = std::filesystem; +#include +namespace fs = boost::filesystem; #include // SMESH include @@ -51,6 +50,8 @@ namespace fs = std::filesystem; #include #include #include +#include +#include // NETGENPlugin @@ -186,7 +187,6 @@ int netgen3d(const std::string input_mesh_file, const std::string hypo_file, const std::string element_orientation_file, const std::string new_element_file, - bool output_mesh, const std::string output_mesh_file, int nbThreads) { @@ -198,22 +198,22 @@ int netgen3d(const std::string input_mesh_file, //TODO: To define std::string mesh_name = "Maillage_1"; - import_mesh(input_mesh_file, *myMesh, mesh_name); + importMesh(input_mesh_file, *myMesh, mesh_name); auto time1 = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast(time1-time0); - std::cout << "Time for import_mesh: " << elapsed.count() * 1e-9 << std::endl; + std::cout << "Time for importMesh: " << elapsed.count() * 1e-9 << std::endl; // Importing shape TopoDS_Shape myShape; - import_shape(shape_file, myShape); + importShape(shape_file, myShape); auto time2 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time2-time1); - std::cout << "Time for import_shape: " << elapsed.count() * 1e-9 << std::endl; + std::cout << "Time for importShape: " << elapsed.count() * 1e-9 << std::endl; // Importing hypothesis netgen_params myParams; - import_netgen_params(hypo_file, myParams); + importNetgenParams(hypo_file, myParams); auto time3 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time3-time2); std::cout << "Time for import_netgen_param: " << elapsed.count() * 1e-9 << std::endl; @@ -221,9 +221,9 @@ int netgen3d(const std::string input_mesh_file, myParams.nbThreads = nbThreads; std::cout << "Meshing with netgen3d" << std::endl; - int ret = netgen3d_internal(myShape, *myMesh, myParams, + int ret = netgen3dInternal(myShape, *myMesh, myParams, new_element_file, element_orientation_file, - output_mesh); + !output_mesh_file.empty()); if(!ret){ @@ -231,12 +231,12 @@ int netgen3d(const std::string input_mesh_file, return ret; } - if(output_mesh){ + if(!output_mesh_file.empty()){ auto time4 = std::chrono::high_resolution_clock::now(); - export_mesh(output_mesh_file, *myMesh, mesh_name); + exportMesh(output_mesh_file, *myMesh, mesh_name); auto time5 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time5-time4); - std::cout << "Time for export_mesh: " << elapsed.count() * 1e-9 << std::endl; + std::cout << "Time for exportMesh: " << elapsed.count() * 1e-9 << std::endl; } return ret; @@ -249,10 +249,12 @@ int netgen3d(const std::string input_mesh_file, * @param aMesh the mesh * @param aParams the netgen parameters * @param new_element_file file containing data on the new point/tetra added by netgen + * @param element_orientation_file file containing data on the orientation of each element to add to netgen + * @param output_mesh if true add element created by netgen into aMesh * * @return error code */ -int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams, +int netgen3dInternal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams, std::string new_element_file, std::string element_orientation_file, bool output_mesh) { @@ -317,20 +319,31 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP // Get list of elements + their orientation from element_orientation file std::map elemOrientation; { - std::ifstream df(element_orientation_file, ios::binary|ios::in); - int nbElement; - bool orient; - - // Warning of the use of vtkIdType (I had issue when run_mesher was compiled with internal vtk) and salome not - // Sizeof was the same but how he othered the type was different - // Maybe using another type (uint64_t) instead would be better - vtkIdType id; - df.read((char*)&nbElement, sizeof(int)); - - for(int ielem=0;ielemelementsIterator(SMDSAbs_Face); + while ( iteratorElem->more() ) // loop on elements on a geom face + { + // check mesh face + const SMDS_MeshElement* elem = iteratorElem->next(); + elemOrientation[elem->GetID()] = false; + } + } else { + std::ifstream df(element_orientation_file, ios::binary|ios::in); + int nbElement; + bool orient; + + // Warning of the use of vtkIdType (I had issue when run_mesher was compiled with internal vtk) and salome not + // Sizeof was the same but how he othered the type was different + // Maybe using another type (uint64_t) instead would be better + vtkIdType id; + df.read((char*)&nbElement, sizeof(int)); + + for(int ielem=0;ielemGetID()]; @@ -542,7 +554,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP std::cout << "Time for netgen_compute: " << elapsed.count() * 1e-9 << std::endl; bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built - if ( isOK ) + if ( isOK && !new_element_file.empty() ) { std::ofstream df(new_element_file, ios::out|ios::binary); @@ -581,7 +593,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP std::cout << "Time for write_new_elem: " << elapsed.count() * 1e-9 << std::endl; - // Adding new files in aMesh as well + // Adding new elements in aMesh as well if ( output_mesh ) { double Netgen_point[3]; @@ -639,7 +651,6 @@ int netgen2d(const std::string input_mesh_file, const std::string hypo_file, const std::string element_orientation_file, const std::string new_element_file, - bool output_mesh, const std::string output_mesh_file) { @@ -650,29 +661,29 @@ int netgen2d(const std::string input_mesh_file, //TODO: To define std::string mesh_name = "Maillage_1"; - import_mesh(input_mesh_file, *myMesh, mesh_name); + importMesh(input_mesh_file, *myMesh, mesh_name); // Importing shape TopoDS_Shape myShape; - import_shape(shape_file, myShape); + importShape(shape_file, myShape); // Importing hypothesis netgen_params myParams; - import_netgen_params(hypo_file, myParams); + importNetgenParams(hypo_file, myParams); std::cout << "Meshing with netgen3d" << std::endl; - int ret = netgen2d_internal(myShape, *myMesh, myParams, + int ret = netgen2dInternal(myShape, *myMesh, myParams, new_element_file, element_orientation_file, - output_mesh); + !output_mesh_file.empty()); if(!ret){ std::cout << "Meshing failed" << std::endl; return ret; } - if(output_mesh) - export_mesh(output_mesh_file, *myMesh, mesh_name); + if(!output_mesh_file.empty()) + exportMesh(output_mesh_file, *myMesh, mesh_name); return ret; } @@ -689,7 +700,7 @@ int netgen2d(const std::string input_mesh_file, * * @return error code */ -int netgen2d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams, +int netgen2dInternal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams, std::string new_element_file, std::string element_orientation_file, bool output_mesh) { diff --git a/src/NETGENPlugin/netgen_mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Runner.hxx similarity index 85% rename from src/NETGENPlugin/netgen_mesher.hxx rename to src/NETGENPlugin/NETGENPlugin_Runner.hxx index 996b1ac..fe4d6c9 100644 --- a/src/NETGENPlugin/netgen_mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Runner.hxx @@ -20,13 +20,13 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : netgen_mesher.hxx +// File : NETGENPlugin_Runner.hxx // Author : Yoann AUDOUIN, EDF -// Module : SMESH +// Module : NETGEN // -#ifndef _NETGEN_MESHER_HXX_ -#define _NETGEN_MESHER_HXX_ +#ifndef _NETGENPLUGIN_RUNNER_HXX_ +#define _NETGENPLUGIN_RUNNER_HXX_ #include #include @@ -36,7 +36,7 @@ class SMESH_Mesh; class SMESH_Comment; class netgen_params; -int netgen2d_internal(TopoDS_Shape &aShape, +int netgen2dInternal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams, std::string new_element_file, @@ -45,12 +45,11 @@ int netgen2d_internal(TopoDS_Shape &aShape, int netgen2d(const std::string input_mesh_file, const std::string shape_file, const std::string hypo_file, - const std::string element_orienation_file, + const std::string element_orientation_file, const std::string new_element_file, - bool output_mesh, const std::string output_mesh_file); -int netgen3d_internal(TopoDS_Shape &aShape, +int netgen3dInternal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams, std::string new_element_file, @@ -59,9 +58,8 @@ int netgen3d_internal(TopoDS_Shape &aShape, int netgen3d(const std::string input_mesh_file, const std::string shape_file, const std::string hypo_file, - const std::string element_orienation_file, + const std::string element_orientation_file, const std::string new_element_file, - bool output_mesh, const std::string output_mesh_file, int nbThreads); diff --git a/src/NETGENPlugin/NETGENPlugin_Runner_main.cxx b/src/NETGENPlugin/NETGENPlugin_Runner_main.cxx new file mode 100644 index 0000000..709e118 --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_Runner_main.cxx @@ -0,0 +1,105 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : NETGENplugin_Runnner_main.cxx +// Author : Yoann AUDOUIN, EDF +// Module : NETGEN +// + + +#include "NETGENPlugin_Runner.hxx" + +#include +#include +#include +#include + +/** + * @brief Main function + * + * @param argc Number of arguments + * @param argv Arguments + * + * @return error code + */ +int main(int argc, char *argv[]){ + + if(argc!=9||(argc==2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help")==0))){ + std::cout << "Error in number of arguments "<< argc<<" given expected 8" <(end - begin); + std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl; + } else if (mesher=="NETGEN2D"){ + netgen2d(input_mesh_file, + shape_file, + hypo_file, + element_orientation_file, + new_element_file, + output_mesh_file); + } else { + std::cerr << "Unknown mesher:" << mesher << std::endl; + } + return 0; +} diff --git a/src/NETGENPlugin/run_mesher.cxx b/src/NETGENPlugin/run_mesher.cxx deleted file mode 100644 index a1a1fbc..0000000 --- a/src/NETGENPlugin/run_mesher.cxx +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -// File : run_mesher.cxx -// Author : Yoann AUDOUIN, EDF -// Module : SMESH -// - -#include "DriverStep.hxx" -#include "DriverMesh.hxx" -#include "netgen_param.hxx" -#include "netgen_mesher.hxx" - -#include -#include - -#include -#include - -#include - -/** - * @brief Test of shape Import/Export - * - * @param shape_file - */ -void test_shape(){ - - std::cout << "Testing Shape Import/Export" << std::endl; - std::string shape_file = "box.step"; - - TopoDS_Shape myShape; - - // Test 1 import -> export cmp files - std::string shape_file2 = "/tmp/shape.step"; - - import_shape(shape_file, myShape); - export_shape(shape_file2, myShape); - - assert(diff_step_file(shape_file, shape_file2)); - - // Test 2 import->export->import cmp TopoDS_Shape - std::string shape_file3 = "/tmp/shape2.step"; - TopoDS_Shape myShape1, myShape2; - - import_shape(shape_file, myShape1); - - export_shape(shape_file3, myShape1); - - import_shape(shape_file3, myShape2); - - // TODO: See why this does not work - // TShape seems to be different - //assert(myShape1.IsSame(myShape2)); - -} - -/** - * @brief test of mesh import/export - * - * @param mesh_file - */ -void test_mesh(){ - - std::cout << "Testing Mesh Import/Export" << std::endl; - std::string mesh_file = "box.med"; - SMESH_Gen gen; - - SMESH_Mesh *myMesh = gen.CreateMesh(false); - std::string mesh_name = "Maillage_1"; - - // Test 1 import -> export cmp files - std::string mesh_file2 = "/tmp/mesh.med"; - - import_mesh(mesh_file, *myMesh, mesh_name); - export_mesh(mesh_file2, *myMesh, mesh_name); - - assert(diff_med_file(mesh_file, mesh_file2, mesh_name)); - - // TODO: Compare the two med files via dump ? - - // Test 2 import->export->import cmp TopoDS_Shape - std::string mesh_file3 = "/tmp/mesh2.med"; - SMESH_Mesh *myMesh1 = gen.CreateMesh(false); - SMESH_Mesh *myMesh2 = gen.CreateMesh(false); - - import_mesh(mesh_file, *myMesh1, mesh_name); - - export_mesh(mesh_file3, *myMesh1, mesh_name); - - import_mesh(mesh_file3, *myMesh2, mesh_name); - - // TODO: Compare SMESH_Mesh - //assert(myMesh1==myMesh2); -} - -/** - * @brief Test of import/export of netgen param - * - */ -void test_netgen_params(){ - - std::string param_file = "/tmp/netgen_param.txt"; - netgen_params myParams, myParams2; - myParams.has_netgen_param = true; - myParams.maxh = 34.64; - myParams.minh = 0.14; - myParams.segmentsperedge = 15; - myParams.grading = 0.2; - myParams.curvaturesafety = 1.5; - myParams.secondorder = false; - myParams.quad = false; - myParams.optimize = true; - myParams.fineness = 5; - myParams.uselocalh = true; - myParams.merge_solids = true; - myParams.chordalError = -1; - myParams.optsteps2d = 3; - myParams.optsteps3d = 3; - myParams.elsizeweight = 0.2; - myParams.opterrpow = 2; - myParams.delaunay = true; - myParams.checkoverlap = true; - myParams.checkchartboundary = false; - myParams.closeedgefac = 2; - myParams.has_local_size = false; - myParams.meshsizefilename = ""; - myParams.has_maxelementvolume_hyp = false; - myParams.maxElementVolume = 0.0; - - export_netgen_params(param_file, myParams); - import_netgen_params(param_file, myParams2); - - assert(diff_netgen_params(myParams, myParams2)); - -}; - -void test_netgen3d(){ - - std::cout << "Testing NETGEN 3D mesher" << std::endl; - netgen3d("box_partial2D1D-2.med", - "box-2.step", - "box_param.txt", - "element_orient.dat", - "new_element.dat", - true, - "box_with3D.med", - 1); - - // TODO: Check result -} - -/** - * @brief Main function - * - * @param argc Number of arguments - * @param argv Arguments - * - * @return error code - */ -int main(int argc, char *argv[]){ - - if(argc!=10||(argc==2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help")==0))){ - std::cout << "Error in number of argument"<(end - begin); - std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl; - } else if (mesher=="NETGEN2D"){ - netgen2d(input_mesh_file, - shape_file, - hypo_file, - element_orientation_file, - new_element_file, - output_mesh, - output_mesh_file); - } else { - std::cerr << "Unknown mesher:" << mesher << std::endl; - } - return 0; -} -- 2.39.2