X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FNETGENPlugin%2FNETGENPlugin_NETGEN_3D_Remote.cxx;h=13516387436c37a35e23a009d534e1338b047847;hb=6f1ecd26cbaea68fe32900c45e9b54e41a57b8f4;hp=16311c7212513e35a237a9d8979f350afeefab3b;hpb=9bfa36efab8c9847238524fbaeb7313859f19583;p=plugins%2Fnetgenplugin.git diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_Remote.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_Remote.cxx index 16311c7..1351638 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_Remote.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D_Remote.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,6 @@ #include namespace fs = boost::filesystem; - /* Netgen include files */ @@ -110,6 +110,7 @@ NETGENPlugin_NETGEN_3D_Remote::~NETGENPlugin_NETGEN_3D_Remote() */ void NETGENPlugin_NETGEN_3D_Remote::fillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams) { + aParams.myType = hypoType::Hypo; aParams.maxh = hyp->GetMaxSize(); aParams.minh = hyp->GetMinSize(); aParams.segmentsperedge = hyp->GetNbSegPerEdge(); @@ -138,6 +139,7 @@ void NETGENPlugin_NETGEN_3D_Remote::fillParameters(const NETGENPlugin_Hypothesis // const char* aParams.meshsizefilename = hyp->GetMeshSizeFile(); aParams.closeedgefac = 0; + aParams.nbThreads = 0; #endif } @@ -223,13 +225,17 @@ bool NETGENPlugin_NETGEN_3D_Remote::Compute(SMESH_Mesh& aMesh, SMESH_Hypothesis::Hypothesis_Status hypStatus; NETGENPlugin_NETGEN_3D::CheckHypothesis(aMesh, aShape, hypStatus); } - + SMESH_ParallelMesh& aParMesh = dynamic_cast(aMesh); // Temporary folder for run - fs::path tmp_folder = aMesh.tmp_folder / fs::unique_path(fs::path("Volume-%%%%-%%%%")); +#ifdef WIN32 + fs::path tmp_folder = aParMesh.GetTmpFolder() / fs::path("Volume-%%%%-%%%%"); +#else + fs::path tmp_folder = aParMesh.GetTmpFolder() / fs::unique_path(fs::path("Volume-%%%%-%%%%")); +#endif fs::create_directories(tmp_folder); // Using MESH2D generated after all triangles where created. - fs::path mesh_file=aMesh.tmp_folder / fs::path("Mesh2D.med"); + fs::path mesh_file=aParMesh.GetTmpFolder() / fs::path("Mesh2D.med"); fs::path element_orientation_file=tmp_folder / fs::path("element_orientation.dat"); fs::path new_element_file=tmp_folder / fs::path("new_elements.dat"); fs::path tmp_mesh_file=tmp_folder / fs::path("tmp_mesh.med"); @@ -238,13 +244,14 @@ bool NETGENPlugin_NETGEN_3D_Remote::Compute(SMESH_Mesh& aMesh, fs::path shape_file=tmp_folder / fs::path("shape.brep"); fs::path param_file=tmp_folder / fs::path("netgen3d_param.txt"); fs::path log_file=tmp_folder / fs::path("run.log"); - fs::path cmd_file=tmp_folder / fs::path("cmd.log"); + fs::path cmd_file=tmp_folder / fs::path("cmd.txt"); + // TODO: See if we can retreived name from aMesh ? std::string mesh_name = "MESH"; { SMESH_MeshLocker myLocker(&aMesh); //Writing Shape - exportShape(shape_file.string(), aShape); + SMESH_DriverShape::exportShape(shape_file.string(), aShape); //Writing hypo netgen_params aParams; @@ -257,57 +264,72 @@ bool NETGENPlugin_NETGEN_3D_Remote::Compute(SMESH_Mesh& aMesh, } // Calling run_mesher - std::string cmd; - fs::path run_mesher_exe = - fs::path(std::getenv("NETGENPLUGIN_ROOT_DIR"))/ - fs::path("bin")/ - fs::path("salome")/ -#ifdef WIN32 - fs::path("NETGENPlugin_Runner.exe"); -#else - fs::path("NETGENPlugin_Runner"); -#endif - - cmd = run_mesher_exe.string() + - " NETGEN3D " + mesh_file.string() + " " - + shape_file.string() + " " - + param_file.string() + " " - + element_orientation_file.string() + " " - + new_element_file.string() + " " - + "NONE"; - // Writing command in log + // Path to mesher script + fs::path mesher_launcher = fs::path(std::getenv("SMESH_ROOT_DIR"))/ + fs::path("bin")/ + fs::path("salome")/ + fs::path("mesher_launcher.py"); + + + std::string s_program="python3"; + std::list params; + params.push_back(mesher_launcher.string()); + params.push_back("NETGEN3D"); + params.push_back(mesh_file.string()); + params.push_back(shape_file.string()); + params.push_back(param_file.string()); + params.push_back("--elem-orient-file=" + element_orientation_file.string()); + params.push_back("--new-element-file=" + new_element_file.string()); + + // Parallelism method parameters + int method = aParMesh.GetParallelismMethod(); + if(method == ParallelismMethod::MultiThread){ + params.push_back("--method=local"); + } else if (method == ParallelismMethod::MultiNode){ + params.push_back("--method=cluster"); + params.push_back("--resource="+aParMesh.GetResource()); + params.push_back("--wc-key="+aParMesh.GetWcKey()); + params.push_back("--nb-proc=1"); + params.push_back("--nb-proc-per-node="+to_string(aParMesh.GetNbProcPerNode())); + params.push_back("--nb-node="+to_string(aParMesh.GetNbNode())); + params.push_back("--walltime="+aParMesh.GetWalltime()); + } else { + throw SALOME_Exception("Unknown parallelism method "+method); + } + std::string cmd = ""; + cmd += s_program; + for(auto arg: params){ + cmd += " " + arg; + } + MESSAGE("Running command: "); + MESSAGE(cmd); + // Writing command in cmd.log { std::ofstream flog(cmd_file.string()); flog << cmd << endl; - flog << endl; } - MESSAGE("Running command: "); - MESSAGE(cmd); - // Building arguments for QProcess - QString program = run_mesher_exe.c_str(); + QString program = QString::fromStdString(s_program); QStringList arguments; - arguments << "NETGEN3D"; - arguments << mesh_file.c_str(); - arguments << shape_file.c_str(); - arguments << param_file.c_str(); - arguments << element_orientation_file.c_str(); - arguments << new_element_file.c_str(); - arguments << "NONE"; - QString out_file = log_file.c_str(); + for(auto arg : params){ + arguments << arg.c_str(); + } + + QString out_file = log_file.string().c_str(); QProcess myProcess; + myProcess.setProcessChannelMode(QProcess::MergedChannels); myProcess.setStandardOutputFile(out_file); myProcess.start(program, arguments); // Waiting for process to finish (argument -1 make it wait until the end of // the process otherwise it just waits 30 seconds) - myProcess.waitForFinished(-1); - int ret = myProcess.exitStatus(); + bool finished = myProcess.waitForFinished(-1); + int ret = myProcess.exitCode(); - if(ret != 0){ + if(ret != 0 || !finished){ // Run crahed - std::string msg = "Issue with command: \n"; + std::string msg = "Issue with mesh_launcher: \n"; msg += "See log for more details: " + log_file.string() + "\n"; msg += cmd + "\n"; throw SALOME_Exception(msg);