Salome HOME
Fix "Conditional jump or move depends on uninitialised value" valgrind error
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPlugin_Hypothesis.cxx
index 5f3e70d8bfff8e79e7f8482285b9ac4ca295bc30..5f1ee5dc357d42255922b9e48a02b70500b1b6c2 100644 (file)
@@ -42,32 +42,33 @@ using namespace std;
 
 GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
   : SMESH_Hypothesis(hypId, studyId, gen),
-  myToMeshHoles(DefaultMeshHoles()),
-  myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
-  myMaximumMemory(-1),
-  myInitialMemory(-1),
-  myOptimizationLevel(DefaultOptimizationLevel()),
-  myKeepFiles(DefaultKeepFiles()),
-  myWorkingDirectory(DefaultWorkingDirectory()),
-  myVerboseLevel(DefaultVerboseLevel()),
-  myToCreateNewNodes(DefaultToCreateNewNodes()),
-  myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
-  myToUseFemCorrection(DefaultToUseFEMCorrection()),
-  myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
-  myLogInStandardOutput(DefaultStandardOutputLog()),
-  myGradation(DefaultGradation()),
-  _enfVertexList(DefaultGHS3DEnforcedVertexList()),
-  _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()),
-  _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()),
-  _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()),
-  _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()),
-  _enfMeshList(DefaultGHS3DEnforcedMeshList()),
-  _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()),
-  _enfNodes(TIDSortedNodeGroupMap()),
-  _enfEdges(TIDSortedElemGroupMap()),
-  _enfTriangles(TIDSortedElemGroupMap()),
-  _nodeIDToSizeMap(DefaultID2SizeMap()),
-  _groupsToRemove(DefaultGroupsToRemove())
+    myToMeshHoles(DefaultMeshHoles()),
+    myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
+    myMaximumMemory(-1),
+    myInitialMemory(-1),
+    myOptimizationLevel(DefaultOptimizationLevel()),
+    myKeepFiles(DefaultKeepFiles()),
+    myWorkingDirectory(DefaultWorkingDirectory()),
+    myVerboseLevel(DefaultVerboseLevel()),
+    myToCreateNewNodes(DefaultToCreateNewNodes()),
+    myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
+    myToUseFemCorrection(DefaultToUseFEMCorrection()),
+    myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
+    myLogInStandardOutput(DefaultStandardOutputLog()),
+    myRemoveLogOnSuccess( DefaultRemoveLogOnSuccess() ),
+    myGradation(DefaultGradation()),
+    _enfVertexList(DefaultGHS3DEnforcedVertexList()),
+    _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()),
+    _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()),
+    _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()),
+    _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()),
+    _enfMeshList(DefaultGHS3DEnforcedMeshList()),
+    _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()),
+    _enfNodes(TIDSortedNodeGroupMap()),
+    _enfEdges(TIDSortedElemGroupMap()),
+    _enfTriangles(TIDSortedElemGroupMap()),
+    _nodeIDToSizeMap(DefaultID2SizeMap()),
+    _groupsToRemove(DefaultGroupsToRemove())
 {
   _name = GetHypType();
   _param_algo_dim = 3;
@@ -137,7 +138,7 @@ bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothes
 //function : SetMaximumMemory
 //=======================================================================
 
-void GHS3DPlugin_Hypothesis::SetMaximumMemory(long MB)
+void GHS3DPlugin_Hypothesis::SetMaximumMemory(float MB)
 {
   if ( myMaximumMemory != MB ) {
     myMaximumMemory = MB;
@@ -150,7 +151,7 @@ void GHS3DPlugin_Hypothesis::SetMaximumMemory(long MB)
 //           * automatic memory adjustment mode. Default is zero
 //=======================================================================
 
-long GHS3DPlugin_Hypothesis::GetMaximumMemory() const
+float GHS3DPlugin_Hypothesis::GetMaximumMemory() const
 {
   return myMaximumMemory;
 }
@@ -159,7 +160,7 @@ long GHS3DPlugin_Hypothesis::GetMaximumMemory() const
 //function : SetInitialMemory
 //=======================================================================
 
-void GHS3DPlugin_Hypothesis::SetInitialMemory(long MB)
+void GHS3DPlugin_Hypothesis::SetInitialMemory(float MB)
 {
   if ( myInitialMemory != MB ) {
     myInitialMemory = MB;
@@ -171,7 +172,7 @@ void GHS3DPlugin_Hypothesis::SetInitialMemory(long MB)
 //function : GetInitialMemory
 //=======================================================================
 
-long GHS3DPlugin_Hypothesis::GetInitialMemory() const
+float GHS3DPlugin_Hypothesis::GetInitialMemory() const
 {
   return myInitialMemory;
 }
@@ -432,8 +433,12 @@ bool GHS3DPlugin_Hypothesis::GetRemoveLogOnSuccess() const
 //function : SetEnforcedVertex
 //=======================================================================
 
-bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
-                                               double size, double x, double y, double z, bool isCompound)
+bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName,
+                                               std::string theEntry,
+                                               std::string theGroupName,
+                                               double      size,
+                                               double x, double y, double z,
+                                               bool        isCompound)
 {
   MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
                                                       << size << ", " << x << ", " << y << ", " << z  << ", "<< isCompound << ")");
@@ -847,32 +852,29 @@ bool GHS3DPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
 //function : DefaultMaximumMemory
 //=======================================================================
 
-#ifndef WIN32
-#include <sys/sysinfo.h>
-#else
+#if defined(WIN32)
 #include <windows.h>
+#elif !defined(__APPLE__)
+#include <sys/sysinfo.h>
 #endif
 
-long  GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
+float GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
 {
-#ifndef WIN32
-  struct sysinfo si;
-  long err = sysinfo( &si );
-  if ( err == 0 ) {
-    long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
-    return ( 0.7 * ramMB );
-  }
-#else
+#if defined(WIN32)
   // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
   MEMORYSTATUSEX statex;
   statex.dwLength = sizeof (statex);
   long err = GlobalMemoryStatusEx (&statex);
   if (err != 0) {
-    long totMB = 
-      statex.ullTotalPhys / 1024 / 1024 +
-      statex.ullTotalPageFile / 1024 / 1024 +
-      statex.ullTotalVirtual / 1024 / 1024;
-    return ( 0.7 * totMB );
+    double totMB = (double)statex.ullAvailPhys / 1024. / 1024.;
+    return (float)( 0.7 * totMB );
+  }
+#elif !defined(__APPLE__)
+  struct sysinfo si;
+  long err = sysinfo( &si );
+  if ( err == 0 ) {
+    long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
+    return ( 0.7 * ramMB );
   }
 #endif
   return 1024;
@@ -882,7 +884,7 @@ long  GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
 //function : DefaultInitialMemory
 //=======================================================================
 
-long  GHS3DPlugin_Hypothesis::DefaultInitialMemory()
+float GHS3DPlugin_Hypothesis::DefaultInitialMemory()
 {
   return DefaultMaximumMemory();
 }
@@ -891,7 +893,7 @@ long  GHS3DPlugin_Hypothesis::DefaultInitialMemory()
 //function : DefaultOptimizationLevel
 //=======================================================================
 
-short  GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
+short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
 {
   return Medium;
 }
@@ -1459,9 +1461,10 @@ bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
 //================================================================================
 
 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
-                                                 const bool         hasShapeToMesh)
+                                                 const bool                    hasShapeToMesh,
+                                                 const bool                    forExecutable)
 {
-  TCollection_AsciiString cmd = GetExeName().c_str();
+  std::string cmd = GetExeName();
   // check if any option is overridden by hyp->myTextOption
   bool max_memory   = hyp ? ( hyp->myTextOption.find("--max_memory")  == std::string::npos ) : true;
   bool auto_memory   = hyp ? ( hyp->myTextOption.find("--automatic_memory")  == std::string::npos ) : true;
@@ -1483,22 +1486,16 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h
   // Default memory is defined at MG-Tetra installation but it may be not enough,
   // so allow to use about all available memory
   if ( max_memory ) {
-    long aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
-    ostringstream tmpMaximumMemory;
+    float aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
     cmd += " --max_memory ";
-    if ( aMaximumMemory < 0 )
-      tmpMaximumMemory << DefaultMaximumMemory();
-    else
-      tmpMaximumMemory << aMaximumMemory;
-    cmd += tmpMaximumMemory.str().c_str();
+    if ( aMaximumMemory < 0 ) cmd += SMESH_Comment( DefaultMaximumMemory() );
+    else                      cmd += SMESH_Comment( aMaximumMemory );
   }
   if ( auto_memory && !useBndRecovery ) {
-    long aInitialMemory = hyp ? hyp->myInitialMemory : -1;
+    float aInitialMemory = hyp ? hyp->myInitialMemory : -1;
     cmd += " --automatic_memory ";
-    if ( aInitialMemory > 0 )
-      cmd += (int)aInitialMemory;
-    else
-      cmd += "100";
+    if ( aInitialMemory > 0 ) cmd += SMESH_Comment( aInitialMemory );
+    else                      cmd += "100";
   }
   // component to mesh
   if ( comp && !useBndRecovery ) {
@@ -1507,36 +1504,35 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h
       cmd += " --components all";
     else {
       bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
-      if ( aToMeshHoles )
-        cmd += " --components all";
-      else
-        cmd += " --components outside_components";
+      if ( aToMeshHoles ) cmd += " --components all";
+      else                cmd += " --components outside_components";
     }
   }
   const bool toCreateNewNodes = ( no_int_points && ( !hyp || hyp->myToCreateNewNodes ));
 
   // optimization level
-  // This option need to be improved concerning new mg-tetra version
-  if ( optim_level && hyp && !useBndRecovery && toCreateNewNodes ) {
+  if ( !toCreateNewNodes ) {
+    cmd += " --optimisation_level none"; // issue 22608
+  }
+  else if ( optim_level && hyp && !useBndRecovery ) {
     if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
       const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
       cmd += " --optimisation_level ";
       cmd += level[ hyp->myOptimizationLevel ];
     }
   }
-  if ( !toCreateNewNodes ) {
-    cmd += " --optimisation_level none"; // issue 22608
-  }
 
   // to create internal nodes
   if ( no_int_points && !toCreateNewNodes ) {
-    cmd += " --no_internal_points";
+    if ( forExecutable )
+      cmd += " --no_internal_points";
+    else
+      cmd += " --internalpoints no";
   }
 
   // verbose mode
   if ( verbose && hyp ) {
-    cmd += " --verbose ";
-    cmd += hyp->myVerboseLevel;
+    cmd += " --verbose " + SMESH_Comment( hyp->myVerboseLevel );
   }
 
   // boundary recovery version
@@ -1551,26 +1547,30 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h
 
   // to remove initial central point.
   if ( rem && hyp && hyp->myToRemoveCentralPoint) {
-    cmd += " --no_initial_central_point";
+    if ( forExecutable )
+      cmd += " --no_initial_central_point";
+    else
+      cmd += " --centralpoint no";
   }
 
   // options as text
   if ( hyp && !hyp->myTextOption.empty() ) {
-    cmd += " ";
-    cmd += (char*) hyp->myTextOption.c_str();
+    cmd += " " + hyp->myTextOption;
   }
 
   // to define volumic gradation.
-  if ( gra && hyp) {
-    cmd += " -Dcpropa=";
-    cmd += hyp->myGradation;
+  if ( gra && hyp ) {
+    if ( forExecutable )
+      cmd += " -Dcpropa=" + SMESH_Comment( hyp->myGradation );
+    else
+      cmd += " --gradation " + SMESH_Comment( hyp->myGradation );
   }
 
 #ifdef WIN32
   cmd += " < NUL";
 #endif
 
-  return cmd.ToCString();
+  return cmd;
 }
 
 //================================================================================