Salome HOME
Update methods SaveTo and LoadFrom to include new hypothesis options. Solve problems...
authorcconopoima <cesar.conopoima@gmail.com>
Mon, 27 Mar 2023 16:29:01 +0000 (13:29 -0300)
committercconopoima <cesar.conopoima@gmail.com>
Mon, 27 Mar 2023 16:29:01 +0000 (13:29 -0300)
doc/salome/examples/ghs3dSetParametersDemo.py [new file with mode: 0644]
src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx
src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx
src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx
src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx

diff --git a/doc/salome/examples/ghs3dSetParametersDemo.py b/doc/salome/examples/ghs3dSetParametersDemo.py
new file mode 100644 (file)
index 0000000..b2c6f4c
--- /dev/null
@@ -0,0 +1,49 @@
+import unittest
+
+import salome
+salome.salome_init()
+
+from salome.geom import geomBuilder
+geompy = geomBuilder.New()
+
+from salome.smesh import smeshBuilder
+smesh =  smeshBuilder.New()
+
+# create a box
+box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
+geompy.addToStudy(box, "box")
+
+# create a mesh on the box
+mgtetraMesh = smesh.Mesh(box,"box: MG-Tetra and NETGEN_1D_2D mesh")
+
+# create a NETGEN1D2D algorithm for faces and vertices
+NETGEN_1D_2D   = mgtetraMesh.Triangle(algo=smeshBuilder.NETGEN_1D2D)
+NETGEN_2D_Parameters_1 = NETGEN_1D_2D.Parameters()
+MG_Tetra       = mgtetraMesh.Tetrahedron(algo=smeshBuilder.MG_Tetra)
+MG_Tetra_Parameters_1 = MG_Tetra.Parameters()
+MG_Tetra_Parameters_1.SetAlgorithm( 1 )         # 1 MGTetra (Default) - 0 MGTetra HPC
+MG_Tetra_Parameters_1.SetUseNumOfThreads( 1 )   # 1 true - 0 false
+MG_Tetra_Parameters_1.SetNumOfThreads( 6 )      # Number of threads
+MG_Tetra_Parameters_1.SetPthreadMode( 1 )       # 0 - none, 1 - aggressive, 2 - safe
+
+# compute the mesh with MGTetra
+status = mgtetraMesh.Compute()
+assert( status )
+
+mgtetraHPCMesh       = smesh.Mesh(box,"box: MG-Tetra HPC and NETGEN_1D_2D mesh")
+status               = mgtetraHPCMesh.AddHypothesis(NETGEN_2D_Parameters_1)
+NETGEN_1D_2D_1       = mgtetraHPCMesh.Triangle(algo=smeshBuilder.NETGEN_1D2D)
+MG_Tetra_1           = mgtetraHPCMesh.Tetrahedron(algo=smeshBuilder.MG_Tetra)
+MG_Tetra_Parameters_2 = MG_Tetra_1.Parameters()
+MG_Tetra_Parameters_2.SetAlgorithm( 0 )         # 1 MGTetra (Default) - 0 MGTetra HPC
+MG_Tetra_Parameters_2.SetUseNumOfThreads( 1 )   # 1 true - 0 false
+MG_Tetra_Parameters_2.SetNumOfThreads( 6 )      # Number of threads
+MG_Tetra_Parameters_2.SetParallelMode( 1 )      # 0 - none, 1 - reproducible_given_max_num_of_threads, 2 - reproducible, 3 - aggressive
+
+# compute the mesh  with MGTetra HPC
+status = mgtetraHPCMesh.Compute()
+assert( status )
+
+
+# End of script
+
index 4bf5cef0d1103b22a069a66f6c4c738675024613..14c9f61dbb49d4d2c6250c72d997b2e8492c0e7d 100644 (file)
@@ -2295,7 +2295,7 @@ bool GHS3DPlugin_GHS3D::ComputeMGTetraHPC(SMESH_Mesh&         theMesh,
   if ( verbose )     cmd = cmd + " --verbose "                 + SMESH_Comment( _hyp->GetVerboseLevel() );
   if ( proximity )   cmd = cmd + " --volume_proximity_layers " + SMESH_Comment( _hyp->GetNbVolumeProximityLayers() );
 
-  _hyp->SetAdvancedOptionsInCommandLine( _AdvOptions, false );  
+  _hyp->SetAdvancedOptionsInCommandLine( _AdvOptions );  
   cmd = cmd + " "        + _AdvOptions.c_str();
   cmd = cmd + " --out="  + GHS3DPRL_Out_Mesh;    
   cmd = cmd + " 1>"      + logFileName;
index ef7a0d961af55371b6d9e6a46e1f3d436db5ce6a..d8b3b0a8763c7c7c09aaa3665c266c3602c7385b 100644 (file)
@@ -1352,6 +1352,13 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
   for ( o2v = _customOption2value.begin(); o2v != _customOption2value.end(); ++o2v )
     save << " -" << o2v->first << " -" << o2v->second;
 
+  // New options (issue #32737) 
+  save << " " << myAlgorithm;
+  save << " " << myUseNumOfThreads;
+  save << " " << myNumOfThreads;
+  save << " " << myPthreadModeMG;
+  save << " " << myPthreadModeMGHPC;
+
   return save;
 }
 
@@ -1708,6 +1715,36 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
     }
   }
 
+  isOK = static_cast<bool>(load >> i);
+  if (isOK)
+    myAlgorithm = (short) i;
+  else
+    load.clear(ios::badbit | load.rdstate());
+  
+  isOK = static_cast<bool>(load >> i);
+  if (isOK)
+    myUseNumOfThreads = (short) i;
+  else
+    load.clear(ios::badbit | load.rdstate());
+  
+  isOK = static_cast<bool>(load >> i);
+  if (isOK)
+    myNumOfThreads = (short) i;
+  else
+    load.clear(ios::badbit | load.rdstate());
+
+  isOK = static_cast<bool>(load >> i);
+  if (isOK)
+    myPthreadModeMG = (short) i;
+  else
+    load.clear(ios::badbit | load.rdstate());
+
+  isOK = static_cast<bool>(load >> i);
+  if (isOK)
+    myPthreadModeMGHPC = (short) i;
+  else
+    load.clear(ios::badbit | load.rdstate());
+
   return load;
 }
 
@@ -1739,7 +1776,7 @@ bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
   return true;
 }
 
-void GHS3DPlugin_Hypothesis::SetAdvancedOptionsInCommandLine( std::string & cmd, bool isMGTetra ) const
+void GHS3DPlugin_Hypothesis::SetAdvancedOptionsInCommandLine( std::string & cmd ) const
 {
   std::string option, value;
   bool isDefault;
@@ -1895,13 +1932,12 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h
       cmd += " --volume_proximity_layers " + SMESH_Comment( hyp->GetNbVolumeProximityLayers() );
     }
     
-    hyp->SetAdvancedOptionsInCommandLine( cmd, true );
+    hyp->SetAdvancedOptionsInCommandLine( cmd );
   }
 
 #ifdef WIN32
   cmd += " < NUL";
 #endif
-
   return cmd;
 }
 
index c2cfc2e8901dc7abe34a4fd53af8e61dfe8a38ff..b354445aec3bb57a1cf298e1c6f650b435bd61f1 100644 (file)
@@ -241,7 +241,7 @@ public:
    * To set hiden/undocumented/advanced options
    */
   void SetAdvancedOption(const std::string& option);
-  std::string GetAdvancedOption() const;
+  std::string GetAdvancedOption() const;  
   /*!
   * To define the volumic gradation
   */
@@ -271,11 +271,11 @@ public:
   TOptionValues        GetOptionValues()       const;
   const TOptionValues& GetCustomOptionValues() const { return _customOption2value; }
 
-  bool isMGTetraHPCOptions( std::string & option ) const;
+  // bool isMGTetraHPCOptions( std::string & option ) const;
   /*!
    * \brief To set the advanced options in the execution command line
    */
-  void SetAdvancedOptionsInCommandLine( std::string & cmd, bool isMGTetra ) const;
+  void SetAdvancedOptionsInCommandLine( std::string & cmd ) const;
   
   //static inline const char* NoValue() { return "_"; }  
 //   struct TEnforcedEdge {
index 096742ab23550311a8385676c77c1b80ea49836c..f9bf94baac5e277142b55d6f24976959051c77ad 100644 (file)
@@ -241,7 +241,7 @@ void GHS3DPlugin_Hypothesis_i::SetOptimizationLevel(CORBA::Short level)
     (::GHS3DPlugin_Hypothesis::OptimizationLevel) level;
   if ( l < ::GHS3DPlugin_Hypothesis::None ||
        l > ::GHS3DPlugin_Hypothesis::Strong )
-    THROW_SALOME_CORBA_EXCEPTION( "Invalid optimization level",SALOME::BAD_PARAM );
+    THROW_SALOME_CORBA_EXCEPTION( "Invalid optimization level", SALOME::BAD_PARAM );
     
   ASSERT(myBaseImpl);
   this->GetImpl()->SetOptimizationLevel(l);
@@ -263,7 +263,11 @@ CORBA::Short GHS3DPlugin_Hypothesis_i::GetOptimizationLevel()
 //=======================================================================
 void GHS3DPlugin_Hypothesis_i::SetAlgorithm(CORBA::Short algoId)
 { 
-  ::GHS3DPlugin_Hypothesis::ImplementedAlgorithms algo = (::GHS3DPlugin_Hypothesis::ImplementedAlgorithms) algoId;
+  ::GHS3DPlugin_Hypothesis::ImplementedAlgorithms algo =
+    (::GHS3DPlugin_Hypothesis::ImplementedAlgorithms) algoId;
+  if ( algo != ::GHS3DPlugin_Hypothesis::MGTetra && algo != ::GHS3DPlugin_Hypothesis::MGTetraHPC )
+    THROW_SALOME_CORBA_EXCEPTION( "Invalid algorithm type", SALOME::BAD_PARAM );
+
   ASSERT(myBaseImpl);
   this->GetImpl()->SetAlgorithm(algo);
   SMESH::TPythonDump() << _this() << ".SetAlgorithm( " << algoId << " )";
@@ -321,7 +325,14 @@ CORBA::Short GHS3DPlugin_Hypothesis_i::GetNumOfThreads()
 //=======================================================================
 void GHS3DPlugin_Hypothesis_i::SetPthreadMode(CORBA::Short pThreadMode)
 { 
-  ::GHS3DPlugin_Hypothesis::PThreadMode mode = (::GHS3DPlugin_Hypothesis::PThreadMode) pThreadMode;
+  ::GHS3DPlugin_Hypothesis::PThreadMode mode =
+    (::GHS3DPlugin_Hypothesis::PThreadMode) pThreadMode;
+  
+   if ( mode < ::GHS3DPlugin_Hypothesis::PThreadNone ||
+       mode > ::GHS3DPlugin_Hypothesis::Safe )
+    THROW_SALOME_CORBA_EXCEPTION( "Invalid pthreadMode type", SALOME::BAD_PARAM );
+
+
   ASSERT(myBaseImpl);
   this->GetImpl()->SetPthreadMode(mode);
   SMESH::TPythonDump() << _this() << ".SetPthreadMode( " << pThreadMode << " )";
@@ -341,7 +352,13 @@ CORBA::Short GHS3DPlugin_Hypothesis_i::GetPthreadMode()
 //=======================================================================
 void GHS3DPlugin_Hypothesis_i::SetParallelMode(CORBA::Short parallelMode)
 { 
-  ::GHS3DPlugin_Hypothesis::ParallelMode mode = (::GHS3DPlugin_Hypothesis::ParallelMode) parallelMode;
+    ::GHS3DPlugin_Hypothesis::ParallelMode mode =
+    (::GHS3DPlugin_Hypothesis::ParallelMode) parallelMode;
+  
+   if ( mode < ::GHS3DPlugin_Hypothesis::ParallelNone ||
+       mode > ::GHS3DPlugin_Hypothesis::ParallelAggressive )
+    THROW_SALOME_CORBA_EXCEPTION( "Invalid parallelMode type", SALOME::BAD_PARAM );
+
   ASSERT(myBaseImpl);
   this->GetImpl()->SetParallelMode(mode);
   SMESH::TPythonDump() << _this() << ".SetParallelMode( " << parallelMode << " )";