From: cconopoima Date: Mon, 27 Mar 2023 16:29:01 +0000 (-0300) Subject: Update methods SaveTo and LoadFrom to include new hypothesis options. Solve problems... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=62795855cfb901b5b1529989ded4ec4cac5965f3;p=plugins%2Fghs3dplugin.git Update methods SaveTo and LoadFrom to include new hypothesis options. Solve problems observed with hdf dumped files. --- diff --git a/doc/salome/examples/ghs3dSetParametersDemo.py b/doc/salome/examples/ghs3dSetParametersDemo.py new file mode 100644 index 0000000..b2c6f4c --- /dev/null +++ b/doc/salome/examples/ghs3dSetParametersDemo.py @@ -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 + diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 4bf5cef..14c9f61 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -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; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index ef7a0d9..d8b3b0a 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -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(load >> i); + if (isOK) + myAlgorithm = (short) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = static_cast(load >> i); + if (isOK) + myUseNumOfThreads = (short) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = static_cast(load >> i); + if (isOK) + myNumOfThreads = (short) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = static_cast(load >> i); + if (isOK) + myPthreadModeMG = (short) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = static_cast(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; } diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index c2cfc2e..b354445 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -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 { diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index 096742a..f9bf94b 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -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 << " )";