map <int,int> aSmdsToGHS3DPRLIdMap;
map <int,const SMDS_MeshNode*> aGHS3DPRLIdToNodeMap;
- GHS3DPRL_In = path + "GHS3DPRL";
+ _genericName = GHS3DPRLPlugin_Hypothesis::GetFileName(_hypothesis);
+ TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
+ GHS3DPRL_In = aGenericName + ".mesh";
GHS3DPRL_Out = path + casenamemed;
- GHS3DPRL_Out_Mesh = path + casenamemed + "_out.mesh";
+ GHS3DPRL_Out_Mesh = aGenericName + "_out.mesh";
GHS3DPRL_Outxml = path + casenamemed + ".xml"; //master file
- logFileName = path + casenamemed + ".log"; // MG library output
+ logFileName = aGenericName + ".log"; // MG library output
NbPart=_NbPart;
Gradation=_Gradation;
MinSize=_MinSize;
// --verbose=0 --menu=no --launchtetra=yes;
run_GHS3DPRL = run_GHS3DPRL +
- " --casename=" + GHS3DPRL_In +
+ " --casename=" + aGenericName +
" --number=" + NbPart +
" --medname=" + GHS3DPRL_Out +
" --launchtetra=yes" +
system( run_nokeep_files.ToCString() ); //clean files
run_nokeep_files = rm + GHS3DPRL_In + "* ";
- fileskinmesh=path + "GHS3DPRL.mesh";
- GHS3DPRL_Out = path + casenamemed;
removeFile( GHS3DPRL_Outxml ); //only the master xml file
MG_TetraHPC_API mgTetraHPC( _computeCanceled, _progress );
if ( !useLib )
mgTetraHPC.SetUseExecutable();
- exportGMF( &mgTetraHPC, fileskinmesh.ToCString(), meshDS );
+ exportGMF( &mgTetraHPC, GHS3DPRL_In.ToCString(), meshDS );
if ( true /*useLib*/ )
{
- TCollection_AsciiString cmd = TCollection_AsciiString("mg-tetra_hpc.exe") +
- " --number_of_subdomains=" + NbPart +
- " --gradation=" + Gradation +
- " --min_size=" + MinSize +
- " --max_size=" + MaxSize +
- " --verbose=3" +
- " --out=" + GHS3DPRL_Out_Mesh +
- " " + _AdvOptions.c_str();
+ TCollection_AsciiString cmd = TCollection_AsciiString();
+ if (_Multithread)
+ cmd += "mg-tetra_hpc.exe";
+ else
+ cmd = cmd + "mpirun --n " + NbPart + " mg-tetra_hpc_mpi.exe";
+ cmd = cmd + " --in=" + GHS3DPRL_In;
+ if (_Multithread)
+ cmd = cmd +" --max_number_of_threads=" + NbPart;
+ cmd = cmd + " --gradation=" + Gradation;
+ cmd = cmd + " --min_size=" + MinSize;
+ cmd = cmd + " --max_size=" + MaxSize;
+ cmd = cmd + " --verbose=3";
+ cmd = cmd + " --out=" + GHS3DPRL_Out_Mesh;
+ cmd = cmd + " " + _AdvOptions.c_str();
+ cmd = cmd + " 1>" + logFileName;
cout << endl
<< " Run mg-tetra_hpc as library. Creating a mesh file " << GHS3DPRL_Out_Mesh << endl
mgTetraHPC.SetLogFile( logFileName.ToCString() );
std::string log;
- mgTetraHPC.Compute( cmd.ToCString(), log );
+ Ok = mgTetraHPC.Compute( cmd.ToCString(), log );
- if ( log.empty() )
- log = mgTetraHPC.GetLog();
- if ( log.find(" Dlim " ) != std::string::npos ||
- log.find(" license ") != std::string::npos )
- return error("License problem");
+ if (!Ok)
+ {
+ std::cout << "Error: " << std::endl;
+ std::cout << log << std::endl;
+ // try to guess an error from the output log
+ std::string log2 = mgTetraHPC.GetLog();
+ if ( log2.find(" Dlim " ) != std::string::npos ||
+ log2.find(" license ") != std::string::npos )
+ return error("License problem");
+ std::cout << log2 << std::endl;
+ if ( log2.find("You are using an empty MPI stubs library") != std::string::npos )
+ {
+ std:string msg = "You are using an empty MPI stubs library. Please build it first to be able to use mg-tetra_hpc_mpi.exe.\n";
+ msg += "./salome context\n";
+ msg += "cd $MESHGEMSHOME/stubs\n";
+ msg += "mpicc meshgems_mpi.c -DMESHGEMS_LINUX_BUILD -I../include -shared -fPIC -o $MESHGEMSHOME/lib/Linux_64/libmeshgems_mpi.so";
+ return error(msg);
+ }
+ return error(log);
+ }
// set --launchtetra=no
int yesPos = run_GHS3DPRL.Search("launchtetra") + sizeof("launchtetra");
cout<<" Write input file for mg-tetra_hpc "<<fileskinmesh<<"...";
cout<<" ...done\n";
}
- fileskinmed=path + "GHS3DPRL_skin.med";
- cout<<" Write file "<<fileskinmed<<"...";
- theMesh.ExportMED(fileskinmed.ToCString(),"SKIN_INITIAL",true);
- cout<<" ...done\n\n";
-
- cout<<"GHS3DPRL command :\n "<<run_GHS3DPRL.ToCString()<<endl;
- //sometimes it is better to wait flushing files on slow filesystem...
- system( "sleep 3" );
- //launch tetrahpc2med which launch mg-tetra_hpc.py which launch mg-tetra_hpc(_mpi?).exe
- res = system( run_GHS3DPRL.ToCString() );
- if (res > 0)
+ // if mpi, convert meshes to med with xml master file
+ if (!_Multithread)
{
- pluginerror = pluginerror + "PROBLEM tetrahpc2med command";
- cout<<pluginerror<<endl;
- error(COMPERR_ALGO_FAILED, pluginerror.ToCString());
- return false; //but it is not a problem but if true my message is overwritten
- }
- system( "sleep 3" );
-
- if (_Background) {
- pluginerror = pluginerror + "backgrounding... plugin is not waiting for output files "+ casenamemed + "_*.med";
- cout<<pluginerror<<endl;
- error(COMPERR_NO_MESH_ON_SHAPE, pluginerror.ToCString());
- return false; //but it is not a problem but if true my message is overwritten
- //return true; //but it is not a problem,
- }
+ fileskinmed=path + casenamemed + "_skin.med";
+ cout<<" Write file "<<fileskinmed<<"...";
+ theMesh.ExportMED(fileskinmed.ToCString(),"SKIN_INITIAL",true);
+ cout<<" ...done\n\n";
+
+ cout<<"GHS3DPRL command :\n "<<run_GHS3DPRL.ToCString()<<endl;
+ //sometimes it is better to wait flushing files on slow filesystem...
+ system( "sleep 3" );
+ //launch tetrahpc2med which launch mg-tetra_hpc.py which launch mg-tetra_hpc(_mpi?).exe
+ std::cout << "run_GHS3DPRL cmd: " << run_GHS3DPRL << std::endl;
+ res = system( run_GHS3DPRL.ToCString() );
+ if (res > 0)
+ {
+ pluginerror = pluginerror + "PROBLEM tetrahpc2med command";
+ cout<<pluginerror<<endl;
+ error(COMPERR_ALGO_FAILED, pluginerror.ToCString());
+ return false; //but it is not a problem but if true my message is overwritten
+ }
+ system( "sleep 3" );
+
+ if (_Background) {
+ pluginerror = pluginerror + "backgrounding... plugin is not waiting for output files "+ path +casenamemed + "_*.med";
+ cout<<pluginerror<<endl;
+ error(COMPERR_NO_MESH_ON_SHAPE, pluginerror.ToCString());
+ return false; //but it is not a problem but if true my message is overwritten
+ //return true; //but it is not a problem,
+ }
- // read a result, GHS3DPRL_Out is the name of master file (previous xml format)
- FILE * aResultFile = fopen( GHS3DPRL_Outxml.ToCString(), "r" );
- if (aResultFile){
- Ok = true;
- fclose(aResultFile);
- cout<<"GHS3DPRL OK output master file "<<casenamemed<<".xml exist !\n\n";
- pluginerror = pluginerror + "MG-tetra_hpc mesh(es) not loaded in memory, are stored in files "+ casenamemed + "_*.med";
- cout<<pluginerror<<endl;
- error(COMPERR_WARNING, pluginerror.ToCString() );
- if (!_KeepFiles) system( run_nokeep_files.ToCString() );
- }
- else{
- Ok = false; //it is a problem AND my message is NOT overwritten
- pluginerror = pluginerror + "output master file " + casenamemed + ".xml do not exist";
- cout<<pluginerror<<endl;
- error(COMPERR_ALGO_FAILED, pluginerror.ToCString() );
- cout<<"GHS3DPRL KO output files "<<GHS3DPRL_Out<<" do not exist ! see intermediates files keeped:\n";
- TCollection_AsciiString run_list_files("ls -alt ");
- run_list_files += GHS3DPRL_Out + "* " + GHS3DPRL_In + "* " + path + "tetrahpc.log";
- system( run_list_files.ToCString() );
- cout<<endl;
+ // read a result, GHS3DPRL_Out is the name of master file (previous xml format)
+ FILE * aResultFile = fopen( GHS3DPRL_Outxml.ToCString(), "r" );
+ if (aResultFile){
+ Ok = true;
+ fclose(aResultFile);
+ cout<<"GHS3DPRL OK output master file "<<casenamemed<<".xml exist !\n\n";
+ pluginerror = pluginerror + "MG-tetra_hpc mesh(es) not loaded in memory, are stored in files "+ path + casenamemed + "_*.med";
+ cout<<pluginerror<<endl;
+ error(COMPERR_WARNING, pluginerror.ToCString() );
+ if (!_KeepFiles) system( run_nokeep_files.ToCString() );
+ }
+ else{
+ Ok = false; //it is a problem AND my message is NOT overwritten
+ pluginerror = pluginerror + "output master file " + casenamemed + ".xml do not exist";
+ cout<<pluginerror<<endl;
+ error(COMPERR_ALGO_FAILED, pluginerror.ToCString() );
+ cout<<"GHS3DPRL KO output files "<<GHS3DPRL_Out<<" do not exist ! see intermediates files keeped:\n";
+ TCollection_AsciiString run_list_files("ls -alt ");
+ run_list_files += GHS3DPRL_Out + "* " + GHS3DPRL_In + "* " + logFileName;
+ system( run_list_files.ToCString() );
+ cout<<endl;
+ }
}
+ else
+ Ok = true;
return Ok;
}
// ---
//
#include "GHS3DPRLPlugin_Hypothesis.hxx"
+#include <Basics_DirUtils.hxx>
+#include <SMESH_File.hxx>
#include <utilities.h>
+#include <unistd.h>
+
+#ifdef WIN32
+#include <process.h>
+#define getpid _getpid
+#endif
//=============================================================================
/*!
_param_algo_dim = 3;
}
+//=======================================================================
+//function : DefaultWorkingDirectory
+//=======================================================================
+
+std::string GHS3DPRLPlugin_Hypothesis::DefaultWorkingDirectory()
+{
+ TCollection_AsciiString aTmpDir;
+
+ char *Tmp_dir = getenv("SALOME_TMP_DIR");
+ if(Tmp_dir != NULL) {
+ aTmpDir = Tmp_dir;
+ }
+ else {
+#ifdef WIN32
+ aTmpDir = TCollection_AsciiString("C:\\");
+#else
+ aTmpDir = TCollection_AsciiString("/tmp/");
+#endif
+ }
+ return aTmpDir.ToCString();
+}
+
+//================================================================================
+/*!
+ * \brief Return a unique file name
+ */
+//================================================================================
+
+std::string GHS3DPRLPlugin_Hypothesis::GetFileName(const GHS3DPRLPlugin_Hypothesis* hyp)
+{
+ std::string aTmpDir = DefaultWorkingDirectory();
+ if ( !SMESH_File( aTmpDir ).exists() )
+ aTmpDir = Kernel_Utils::GetTmpDirByPath( aTmpDir );
+
+ const char lastChar = *aTmpDir.rbegin();
+#ifdef WIN32
+ if(lastChar != '\\') aTmpDir+='\\';
+#else
+ if(lastChar != '/') aTmpDir+='/';
+#endif
+
+ TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
+ aGenericName += "MGTETRAHPC_";
+ aGenericName += getpid();
+ aGenericName += "_";
+ aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
+
+ return aGenericName.ToCString();
+}
+
//=============================================================================
/*!
*
//=============================================================================
int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
{
- return 16;
+ return 8;
}
//=============================================================================