- bool Ok=false;
- TCollection_AsciiString pluginerror("ghs3dprl: ");
- SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
- //cout<<"GetMeshDS done\n";
- if (_countSubMesh==0){
- MESSAGE("GHS3DPRLPlugin_GHS3DPRL::Compute for tetra-hpc");
- _countTotal=0;
- TopExp_Explorer expf(meshDS->ShapeToMesh(), TopAbs_SOLID);
- for ( ; expf.More(); expf.Next() ) _countTotal++;
- }
- _countSubMesh++;
- //cout<<"Compute _countSubMesh "<<_countSubMesh<<endl;
- //no stuff if multiples submesh, multiple call compute
- //mesh all in one pass tepal (the last)
- if (_countSubMesh != _countTotal ) return true;
-
- //stuff on last call
- if (_hypothesis==NULL){
- pluginerror += "No existing parameters/hypothesis for GHS3DPRL";
- cout <<"\n"<<pluginerror<<"\n\n";
- error(COMPERR_ALGO_FAILED, pluginerror.ToCString() );
- return false;
- }
- SetParameters(_hypothesis);
- cout << "\n" << _name << " parameters:" << endl;
- cout << " generic path/name of MED Files = " << _MEDName << endl;
- cout << " number of partitions = " << _NbPart << endl;
- cout << " gradation = " << _Gradation << endl;
- cout << " min_size = " << _MinSize << endl;
- cout << " max_size = " << _MaxSize << endl;
- cout << " keep intermediates files (from tetra-hpc) = " << _KeepFiles << endl;
- cout << " background (from tetra-hpc) = " << _Background << "\n";
- cout << " multithread = " << _Multithread << "\n\n";
-
- //string tmpDir=getTmpDir_new();
- TCollection_AsciiString
- tmpDir=getTmpDir(),
- GHS3DPRL_In,
- GHS3DPRL_Out,
- GHS3DPRL_Outxml,
- run_GHS3DPRL("tetrahpc2med "),
- rm("rm -f "),
- run_nokeep_files,
- NbPart,
- Gradation,
- MinSize,
- MaxSize,
- fileskinmed(""),
- fileskinmesh(""),
- path,
- casenamemed; //_MEDName.c_str());
-
- casenamemed += (char *)_MEDName.c_str();
- int n=casenamemed.SearchFromEnd('/');
- if (n>0) {
- path=casenamemed.SubString(1,n);
- casenamemed=casenamemed.SubString(n+1,casenamemed.Length());
- }
- else
- path=tmpDir;
-
- if (casenamemed.Length()>20){
- casenamemed=casenamemed.SubString(1,20);
- cerr<<"MEDName truncated (no more 20 characters) = "<<casenamemed<<endl;
- }
- //cout<<"path="<<path<<endl;
- //cout<<"casenamemed="<<casenamemed<<endl;
-
- map <int,int> aSmdsToGHS3DPRLIdMap;
- map <int,const SMDS_MeshNode*> aGHS3DPRLIdToNodeMap;
- GHS3DPRL_In = path + "GHS3DPRL";
- GHS3DPRL_Out = path + casenamemed;
- GHS3DPRL_Outxml = path + casenamemed + ".xml"; //master file
- NbPart=_NbPart;
- Gradation=_Gradation;
- MinSize=_MinSize;
- MaxSize=_MaxSize;
-
- //an example:
- //tetrahpc2med --casename=/home/whoami/tmp/GHS3DPRL --number=5 --medname=DOMAIN
- // --gradation=1.05 --min_size=1e-3 --max_size=1e-2
- // --verbose=0 --menu=no --launchtetra=yes;
-
- run_GHS3DPRL = run_GHS3DPRL +
- " --casename=" + GHS3DPRL_In +
- " --number=" + NbPart +
- " --medname=" + GHS3DPRL_Out +
- " --launchtetra=yes" +
- " --gradation=" + Gradation +
- " --min_size=" + MinSize +
- " --max_size=" + MaxSize +
- " --verbose=3";
- if (_Background) run_GHS3DPRL += " --background=yes"; else run_GHS3DPRL += " --background=no";
- if (_Multithread) run_GHS3DPRL += " --multithread=yes"; else run_GHS3DPRL += " --multithread=no";
- run_nokeep_files = rm +GHS3DPRL_In + "* " + path + "tetrahpc.log";
- system( run_nokeep_files.ToCString() ); //clean files
- run_nokeep_files = rm + GHS3DPRL_In + "* ";
-
- cout<<"GHS3DPRL command :\n "<<run_GHS3DPRL.ToCString()<<endl;
- fileskinmesh=path + "GHS3DPRL.mesh";
- cout<<" Write input file for tetra_hpc.exe "<<fileskinmesh<<"...";
- GHS3DPRL_Out = path + casenamemed;
- removeFile( GHS3DPRL_Outxml ); //only the master xml file
- //Ok=writeGHS3DPRLFiles(GHS3DPRL_In, meshDS, aSmdsToGHS3DPRLIdMap, aGHS3DPRLIdToNodeMap);
- bool toCreateGroups = false;
- theMesh.ExportGMF(fileskinmesh.ToCString(), meshDS, toCreateGroups );
- cout<<" ...done\n";
- //else {
- // cout<<" ...NOT done\n";
- // pluginerror = pluginerror + "problem writing input tepal files " + GHS3DPRL_In + ".mesh";
-
- //Ecriture dans un fichier MED ?v2.? meme si not Ok
- //create empty file -> avoid warning message
- //med_idt fid=MEDouvrir((const char *)fileskinmed.ToCString(),MED_CREATION);
- //med_err ret=MEDfermer(fid);
- //fileskinmed=fileskinmed + "cp /home/wambeke/empty.med "+ path + "GHS3DPRL_skin.med";
- //system( fileskinmed.ToCString() );
- fileskinmed=path + "GHS3DPRL_skin.med";
- cout<<" Write file "<<fileskinmed<<"...";
- theMesh.ExportMED(fileskinmed.ToCString(),"SKIN_INITIAL",true,1);
- cout<<" ...done\n\n";
-
-
- //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
- system( run_GHS3DPRL.ToCString() );
- system( "sleep 3" );
-
- if (_Background) {
- pluginerror = pluginerror + "backgrounding... plugin is not waiting for output files "+ casenamemed + "_*.med";
- cout<<pluginerror<<endl;
- error(COMPERR_ALGO_FAILED, 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 = readResult( aResultFile, meshDS, theShape, aGHS3DPRLIdToNodeMap, GHS3DPRL_Out, _nodeRefNumber );
- Ok = true;
- Ok = false; //but it is not a problem but if true my message is overwritten
- fclose(aResultFile);
- cout<<"GHS3DPRL OK output master file "<<casenamemed<<".xml exist !\n\n";
- pluginerror = pluginerror + "new tetraedra not in memory, but stored in files "+ casenamemed + "_*.med";
- cout<<pluginerror<<endl;
- error(COMPERR_ALGO_FAILED, 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;
- }
- _countSubMesh=0;
-
-
- return Ok;
+ SMESH_MesherHelper helper( theMesh );
+ bool ok = Compute( theMesh, &helper );
+ return ok;
+}
+
+//=============================================================================
+// Here we are going to use the GHS3DPRL mesher for tetra-hpc (formerly tepal in v3 (2014))
+bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh& theMesh,
+ SMESH_MesherHelper* /*theHelper*/)
+{
+ bool Ok=false;
+ TCollection_AsciiString pluginerror("ghs3dprl: ");
+ SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
+ if ( theMesh.NbTriangles() == 0 )
+ return error( COMPERR_BAD_INPUT_MESH, "No triangles in the mesh" );
+
+ if (_hypothesis==NULL){
+ pluginerror += "No existing parameters/hypothesis for GHS3DPRL";
+ cout <<"\n"<<pluginerror<<"\n\n";
+ error(COMPERR_ALGO_FAILED, pluginerror.ToCString() );
+ return false;
+ }
+ SetParameters(_hypothesis);
+ cout << "\n" << _name << " parameters:" << endl;
+ cout << " generic path/name of MED Files = " << _MEDName << endl;
+ cout << " number of partitions = " << _NbPart << endl;
+ cout << " gradation = " << _Gradation << endl;
+ cout << " min_size = " << _MinSize << endl;
+ cout << " max_size = " << _MaxSize << endl;
+ cout << " keep intermediates files (from tetra-hpc) = " << _KeepFiles << endl;
+ cout << " background (from tetra-hpc) = " << _Background << "\n";
+ cout << " multithread = " << _Multithread << "\n\n";
+ cout << " adv. options = '" << _AdvOptions << "'\n\n";
+
+ TCollection_AsciiString
+ tmpDir=getTmpDir(),
+ GHS3DPRL_In,
+ GHS3DPRL_Out,
+ GHS3DPRL_Out_Mesh,
+ GHS3DPRL_Outxml,
+ logFileName,
+ run_GHS3DPRL("tetrahpc2med "),
+ rm("rm -f "),
+ run_nokeep_files,
+ NbPart,
+ Gradation,
+ MinSize,
+ MaxSize,
+ fileskinmed(""),
+ fileskinmesh(""),
+ path,
+ casenamemed; //_MEDName.c_str());
+ int res = 0; // 0 is OK
+
+ casenamemed += (char *)_MEDName.c_str();
+ int n=casenamemed.SearchFromEnd('/');
+ if (n>0) {
+ path=casenamemed.SubString(1,n);
+ casenamemed=casenamemed.SubString(n+1,casenamemed.Length());
+ }
+ else
+ path=tmpDir;
+
+ if (casenamemed.Length()>20){
+ casenamemed=casenamemed.SubString(1,20);
+ cerr<<"MEDName truncated (no more 20 characters) = "<<casenamemed<<endl;
+ }
+
+ map <int,int> aSmdsToGHS3DPRLIdMap;
+ map <int,const SMDS_MeshNode*> aGHS3DPRLIdToNodeMap;
+ GHS3DPRL_In = path + "GHS3DPRL";
+ GHS3DPRL_Out = path + casenamemed;
+ GHS3DPRL_Out_Mesh = path + casenamemed + "_out.mesh";
+ GHS3DPRL_Outxml = path + casenamemed + ".xml"; //master file
+ logFileName = path + casenamemed + ".log"; // MG library output
+ NbPart=_NbPart;
+ Gradation=_Gradation;
+ MinSize=_MinSize;
+ MaxSize=_MaxSize;
+
+ //an example:
+ //tetrahpc2med --casename=/home/whoami/tmp/GHS3DPRL --number=5 --medname=DOMAIN
+ // --gradation=1.05 --min_size=1e-3 --max_size=1e-2
+ // --verbose=0 --menu=no --launchtetra=yes;
+
+ run_GHS3DPRL = run_GHS3DPRL +
+ " --casename=" + GHS3DPRL_In +
+ " --number=" + NbPart +
+ " --medname=" + GHS3DPRL_Out +
+ " --launchtetra=yes" +
+ " --gradation=" + Gradation +
+ " --min_size=" + MinSize +
+ " --max_size=" + MaxSize +
+ " --verbose=3" +
+ " " + _AdvOptions.c_str();
+ if (_Background) run_GHS3DPRL += " --background=yes"; else run_GHS3DPRL += " --background=no";
+ if (_Multithread) run_GHS3DPRL += " --multithread=yes"; else run_GHS3DPRL += " --multithread=no";
+ run_nokeep_files = rm +GHS3DPRL_In + "* " + path + "tetrahpc.log";
+ 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 );
+ bool useLib = ( mgTetraHPC.IsLibrary() && !_Background && _Multithread );
+ if ( !useLib )
+ mgTetraHPC.SetUseExecutable();
+
+ exportGMF( &mgTetraHPC, fileskinmesh.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();
+
+ cout << endl
+ << " Run mg-tetra_hpc as library. Creating a mesh file " << GHS3DPRL_Out_Mesh << endl
+ << " Creating a log file : " << logFileName << endl << endl;
+ mgTetraHPC.SetLogFile( logFileName.ToCString() );
+
+ std::string log;
+ 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");
+
+ // set --launchtetra=no
+ int yesPos = run_GHS3DPRL.Search("launchtetra") + sizeof("launchtetra");
+ run_GHS3DPRL.SetValue( yesPos+0, 'n' );
+ run_GHS3DPRL.SetValue( yesPos+1, 'o' );
+ run_GHS3DPRL.SetValue( yesPos+2, ' ' );
+ }
+ else
+ {
+ 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)
+ {
+ 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,
+ }
+
+ // 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;
+ }
+
+ return Ok;