From: Christophe Bourcier Date: Wed, 5 Jun 2024 13:55:32 +0000 (+0200) Subject: Be able to use library by setting MG_Hybrid_Parameters.SetToUseLibrary(True) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f63d5ff0dd7815701d64d0e22a04192c83da91ba;p=plugins%2Fhybridplugin.git Be able to use library by setting MG_Hybrid_Parameters.SetToUseLibrary(True) or setting environment variable MG_HYBRID_USE_LIB --- diff --git a/idl/HYBRIDPlugin_Algorithm.idl b/idl/HYBRIDPlugin_Algorithm.idl index 3b0b2a2..7c883e2 100644 --- a/idl/HYBRIDPlugin_Algorithm.idl +++ b/idl/HYBRIDPlugin_Algorithm.idl @@ -85,6 +85,11 @@ module HYBRIDPlugin */ void SetToMeshHoles(in boolean toMesh); boolean GetToMeshHoles(); + /*! + * To call MG-Hybrid by library. Default is no (i.e. by executable) + */ + void SetToUseLibrary(in boolean toUseLib); + boolean GetToUseLibrary(); /*! * To mesh layers on all wrap Default is yes. */ diff --git a/src/HYBRIDPlugin/HYBRIDPluginBuilder.py b/src/HYBRIDPlugin/HYBRIDPluginBuilder.py index 95315b8..49c29cf 100644 --- a/src/HYBRIDPlugin/HYBRIDPluginBuilder.py +++ b/src/HYBRIDPlugin/HYBRIDPluginBuilder.py @@ -91,6 +91,12 @@ class HYBRID_Algorithm(Mesh_Algorithm): pass return self.params + ## To call MG-Hybrid by library. Default is no (i.e. by executable) + # @param toUseLib "mesh layers on all wrap" flag value + def SetToUseLibrary(self, toUseLib): + self.Parameters().SetToUseLibrary(toUseLib) + pass + ## To mesh layers on all wrap. Default is to mesh. # @param toMesh "mesh layers on all wrap" flag value def SetLayersOnAllWrap(self, toMesh): diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx index d4baa74..c44fbd9 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx @@ -1493,6 +1493,12 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, MG_HYBRID_API mgHybrid( _computeCanceled, _progress ); + bool useLibrary = HYBRIDPlugin_Hypothesis::GetToUseLibrary(_hyp); + if (useLibrary) + mgHybrid.SetUseLibrary(); + else + mgHybrid.SetUseExecutable(); + Ok = writeGMFFile(&mgHybrid, aGMFFileName.c_str(), aRequiredVerticesFileName.c_str(), diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx index 98009ed..c228487 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx @@ -76,7 +76,8 @@ HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, SMESH_Gen * gen) myToCreateNewNodes(DefaultToCreateNewNodes()), myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()), myToUseFemCorrection(DefaultToUseFEMCorrection()), - myToRemoveCentralPoint(DefaultToRemoveCentralPoint()) + myToRemoveCentralPoint(DefaultToRemoveCentralPoint()), + myUseLib(DefaultToUseLib()) { _name = "HYBRID_Parameters"; _param_algo_dim = 3; @@ -163,6 +164,41 @@ void HYBRIDPlugin_Hypothesis::SetBoundaryLayersMaxElemAngle( double angle ) } } +//======================================================================= +//function : SetToUseLibrary +//======================================================================= + +void HYBRIDPlugin_Hypothesis::SetToUseLibrary(bool toUseLib) +{ + if ( myUseLib != toUseLib ) { + myUseLib = toUseLib; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetToUseLibrary +//======================================================================= + +bool HYBRIDPlugin_Hypothesis::GetToUseLibrary() const +{ + return myUseLib; +} + +//======================================================================= +//function : GetToUseLibrary +//======================================================================= + +bool HYBRIDPlugin_Hypothesis::GetToUseLibrary(const HYBRIDPlugin_Hypothesis* hyp) +{ + bool res; + if ( hyp ) + res = hyp->GetToUseLibrary(); + else + res = DefaultToUseLib(); + return res; +} + //======================================================================= //function : SetLayersOnAllWrap @@ -1187,6 +1223,17 @@ void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove() _groupsToRemove.clear(); } +//======================================================================= +//function : DefaultToUseLib +//======================================================================= + +bool HYBRIDPlugin_Hypothesis::DefaultToUseLib() +{ + // default is false but it can be change by environment variable + if (getenv("MG_HYBRID_USE_LIB")) + return true; + return false; +} //======================================================================= //function : DefaultLayersOnAllWrap diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx index 7d06f4b..7504815 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.hxx @@ -131,6 +131,11 @@ public: */ void SetBoundaryLayersMaxElemAngle( double angle ); double GetBoundaryLayersMaxElemAngle() const { return myBoundaryLayersMaxElemAngle; } + /*! + * To call MG-Hybrid by library. Default is no (i.e. by executable) + */ + void SetToUseLibrary(bool toUseLib); + bool GetToUseLibrary() const; /*! * To mesh layers on all wrap. Default is yes. */ @@ -386,11 +391,13 @@ public: static TID2SizeMap GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp); static TSetStrings GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp); static bool GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp); + static bool GetToUseLibrary(const HYBRIDPlugin_Hypothesis* hyp); void ClearGroupsToRemove(); static bool DefaultHeightIsRelative() { return false; } static double DefaultBoundaryLayersMaxElemAngle() { return 165.0; } static bool DefaultMeshHoles(); + static bool DefaultToUseLib(); static bool DefaultLayersOnAllWrap(); static bool DefaultToMakeGroupsOfDomains(); static double DefaultMaximumMemory(); @@ -449,6 +456,7 @@ private: short myElementGeneration; double myCoreSize; + bool myUseLib; bool myLayersOnAllWrap; std::vector myFacesWithImprinting; std::vector myFacesWithSnapping; diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx index 96cb379..818bd6e 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx @@ -105,6 +105,27 @@ CORBA::Double HYBRIDPlugin_Hypothesis_i::GetBoundaryLayersMaxElemAngle() return this->GetImpl()->GetBoundaryLayersMaxElemAngle(); } +//======================================================================= +//function : SetToUseLibrary +//======================================================================= + +void HYBRIDPlugin_Hypothesis_i::SetToUseLibrary(CORBA::Boolean toUseLib) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetToUseLibrary(toUseLib); + SMESH::TPythonDump() << _this() << ".SetToUseLibrary( " << toUseLib << " )"; +} + +//======================================================================= +//function : GetToUseLibrary +//======================================================================= + +CORBA::Boolean HYBRIDPlugin_Hypothesis_i::GetToUseLibrary() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetToUseLibrary(); +} + //======================================================================= //function : SetLayersOnAllWrap //======================================================================= diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx index 65765a3..6d0bf90 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.hxx @@ -79,6 +79,11 @@ class HYBRIDPLUGIN_EXPORT HYBRIDPlugin_Hypothesis_i: */ void SetFacesWithSnapping(const SMESH::long_array& faceIDs); SMESH::long_array* GetFacesWithSnapping(); + /*! + * To call MG-Hybrid by library. Default is no (i.e. by executable) + */ + void SetToUseLibrary(CORBA::Boolean toUseLib); + CORBA::Boolean GetToUseLibrary(); /*! * To mesh "layers on all wrap". Default is to mesh. */ diff --git a/src/HYBRIDPlugin/MG_HYBRID_API.cxx b/src/HYBRIDPlugin/MG_HYBRID_API.cxx index 41124a8..46909e0 100644 --- a/src/HYBRIDPlugin/MG_HYBRID_API.cxx +++ b/src/HYBRIDPlugin/MG_HYBRID_API.cxx @@ -860,12 +860,6 @@ MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress) { _useLib = false; _libData = new LibData( cancelled_flag, progress ); -#ifdef USE_MG_LIBS - _useLib = true; - _libData->Init(); - if ( getenv("MG_HYBRID_USE_EXE")) - _useLib = false; -#endif } //================================================================================ @@ -876,10 +870,8 @@ MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress) MG_HYBRID_API::~MG_HYBRID_API() { -#ifdef USE_MG_LIBS delete _libData; _libData = 0; -#endif std::set::iterator id = _openFiles.begin(); for ( ; id != _openFiles.end(); ++id ) ::GmfCloseMesh( *id ); @@ -897,6 +889,20 @@ bool MG_HYBRID_API::IsLibrary() return _useLib; } +//================================================================================ +/*! + * \brief Switch to usage of MG-HYBRID library + */ +//================================================================================ + +void MG_HYBRID_API::SetUseLibrary() +{ + _useLib = true; +#ifdef USE_MG_LIBS + _libData->Init(); +#endif +} + //================================================================================ /*! * \brief Switch to usage of MG-HYBRID executable @@ -920,7 +926,6 @@ bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr ) { if ( _useLib ) { #ifdef USE_MG_LIBS - // split cmdLine std::istringstream strm( cmdLine ); std::istream_iterator sIt( strm ), sEnd; @@ -970,6 +975,8 @@ bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr ) #endif } + // not library => call executable + // add MG license key { std::string errorTxt, meshIn; diff --git a/src/HYBRIDPlugin/MG_HYBRID_API.hxx b/src/HYBRIDPlugin/MG_HYBRID_API.hxx index f3ac38a..5af48f6 100644 --- a/src/HYBRIDPlugin/MG_HYBRID_API.hxx +++ b/src/HYBRIDPlugin/MG_HYBRID_API.hxx @@ -40,6 +40,7 @@ public: bool IsLibrary(); bool IsExecutable() { return !IsLibrary(); } + void SetUseLibrary(); void SetUseExecutable(); // IN to MESHGEMS diff --git a/tests/layers_imprinting.py b/tests/layers_imprinting.py index b7904c2..54b5080 100644 --- a/tests/layers_imprinting.py +++ b/tests/layers_imprinting.py @@ -85,6 +85,11 @@ geompy.addToStudyInFather( piquage, corner, 'corner' ) geom_groups = [Inlet_x, Inlet_z, Outlet, Wall] d_geom_groups = {} +for geom_group in geom_groups: + name = geom_group.GetName() + d_geom_groups[name] = geom_group + +shape_volume = geompy.BasicProperties(piquage)[2] ### ### SMESH component @@ -125,28 +130,35 @@ MG_Hybrid_Parameters_1.SetBoundaryLayersProgression( 1.1 ) MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 ) MG_Hybrid_Parameters_1.SetFacesWithLayers( wall_ids ) +Mesh_1.Compute() -isDone = Mesh_1.Compute() +def checkMesh_1(Mesh_1): + Mesh_1.CheckCompute() -if not isDone: - raise Exception("Error when computing Mesh_without_imprinting") + d_groups_1 = {} -d_groups_1 = {} + for geom_group in geom_groups: + name = geom_group.GetName() + gr = Mesh_1.Group(geom_group) + d_groups_1[name] = gr + d_geom_groups[name] = geom_group -for geom_group in geom_groups: - name = geom_group.GetName() - gr = Mesh_1.Group(geom_group) - d_groups_1[name] = gr - d_geom_groups[name] = geom_group + assert Mesh_1.NbQuadrangles() == 0 -assert Mesh_1.NbQuadrangles() == 0 + # Compare whole mesh volume + volume_error_1 = abs(shape_volume-Mesh_1.GetVolume())/shape_volume -shape_volume = geompy.BasicProperties(piquage)[2] + assert volume_error_1 < 0.02 -# Compare whole mesh volume -volume_error_1 = abs(shape_volume-Mesh_1.GetVolume())/shape_volume + return d_groups_1 -assert volume_error_1 < 0.02 +d_groups_1 = checkMesh_1(Mesh_1) + +# Compute same mesh with library +MG_Hybrid_Parameters_1.SetToUseLibrary(True) +Mesh_1.Clear() +Mesh_1.Compute() +d_groups_1 = checkMesh_1(Mesh_1) # Viscous layers with imprinting # ============================== @@ -170,42 +182,51 @@ MG_Hybrid_Parameters_2.SetFacesWithImprinting( [ Inlet_x_id, Inlet_z_id, Outlet_ isDone = Mesh_2.Compute() -if not isDone: - raise Exception("Error when computing Mesh_with_imprinting") +mesh_2_volume = Mesh_2.GetVolume() +faces_imprinted = ["Inlet_x", "Inlet_z", "Outlet"] + +def checkMesh_2(Mesh_2, d_groups_1): + Mesh_2.CheckCompute() + assert Mesh_2.NbQuadrangles() > 0 -assert Mesh_2.NbQuadrangles() > 0 + d_groups_2 = {} -d_groups_2 = {} + for geom_group in geom_groups: + name = geom_group.GetName() + gr = Mesh_2.Group(geom_group) + d_groups_2[name] = gr -for geom_group in geom_groups: - name = geom_group.GetName() - gr = Mesh_2.Group(geom_group) - d_groups_2[name] = gr + # Check viscous layers with imprinting + for name in faces_imprinted: + geom_area = geompy.BasicProperties(d_geom_groups[name])[1] + gr_1 = d_groups_1[name] + gr_2 = d_groups_2[name] + #assert gr_1.Size() > 0 + assert gr_2.Size() > 0 + # Nb of quadrangles is in 7th index of mesh info + assert gr_2.GetMeshInfo()[7] > 0 -faces_imprinted = ["Inlet_x", "Inlet_z", "Outlet"] + # Compare mesh group and geom group + area_error_1 = abs(geom_area-smesh.GetArea(gr_2))/geom_area + assert area_error_1 < 0.025 + # Compare mesh group with imprinting and mesh group without imprinting + area_error_2 = abs(smesh.GetArea(gr_1)-smesh.GetArea(gr_2))/smesh.GetArea(gr_1) + assert area_error_2 < 1e-08 -# Check viscous layers with imprinting -for name in faces_imprinted: - geom_area = geompy.BasicProperties(d_geom_groups[name])[1] - gr_1 = d_groups_1[name] - gr_2 = d_groups_2[name] - #assert gr_1.Size() > 0 - assert gr_2.Size() > 0 - # Nb of quadrangles is in 7th index of mesh info - assert gr_2.GetMeshInfo()[7] > 0 - - # Compare mesh group and geom group - area_error_1 = abs(geom_area-smesh.GetArea(gr_2))/geom_area - assert area_error_1 < 0.025 - # Compare mesh group with imprinting and mesh group without imprinting - area_error_2 = abs(smesh.GetArea(gr_1)-smesh.GetArea(gr_2))/smesh.GetArea(gr_1) - assert area_error_2 < 1e-08 - -# Compare whole mesh volume -mesh_2_volume = Mesh_2.GetVolume() -volume_error_2 = abs(shape_volume-mesh_2_volume)/shape_volume + # Compare whole mesh volume + volume_error_2 = abs(shape_volume-mesh_2_volume)/shape_volume + + assert volume_error_2 < 0.02 -assert volume_error_2 < 0.02 + return d_groups_2 + +d_groups_2 = checkMesh_2(Mesh_2, d_groups_1) + +# Compute same mesh with library +MG_Hybrid_Parameters_2.SetToUseLibrary(True) +Mesh_2.Clear() +Mesh_2.Compute() +d_groups_2 = checkMesh_2(Mesh_2, d_groups_1) # Viscous layers with imprinting set by groups # ============================================ @@ -227,30 +248,38 @@ MG_Hybrid_3.SetFacesWithImprinting( [ Inlet_x, Inlet_z, Outlet ] ) isDone = Mesh_3.Compute() -if not isDone: - raise Exception("Error when computing Mesh_with_imprinting_set_by_groups") +def checkMesh_3(Mesh_3, d_groups_2): + Mesh_3.CheckCompute() -d_groups_3 = {} + d_groups_3 = {} -for geom_group in geom_groups: - name = geom_group.GetName() - gr = Mesh_3.Group(geom_group) - d_groups_3[name] = gr + for geom_group in geom_groups: + name = geom_group.GetName() + gr = Mesh_3.Group(geom_group) + d_groups_3[name] = gr + + # Compare whole mesh volume + mesh_3_volume = Mesh_3.GetVolume() + volume_error_3 = abs(mesh_2_volume-mesh_3_volume)/mesh_2_volume + + assert math.isclose(mesh_3_volume,mesh_2_volume,rel_tol=1e-7) -# Compare whole mesh volume -mesh_3_volume = Mesh_3.GetVolume() -volume_error_3 = abs(mesh_2_volume-mesh_3_volume)/mesh_2_volume + # Check viscous layers with imprinting + for name in faces_imprinted: + gr_2 = d_groups_2[name] + gr_3 = d_groups_3[name] + assert gr_3.Size() > 0 + # Nb of quadrangles is in 7th index of mesh info + assert gr_2.GetMeshInfo()[7] == gr_3.GetMeshInfo()[7] -assert math.isclose(mesh_3_volume,mesh_2_volume,rel_tol=1e-7) + # Compare mesh group with imprinting set by ids and mesh group with imprinting set by geom group + assert math.isclose( smesh.GetArea(gr_2), smesh.GetArea(gr_3)) -# Check viscous layers with imprinting -for name in faces_imprinted: - gr_2 = d_groups_2[name] - gr_3 = d_groups_3[name] - assert gr_3.Size() > 0 - # Nb of quadrangles is in 7th index of mesh info - assert gr_2.GetMeshInfo()[7] == gr_3.GetMeshInfo()[7] +checkMesh_3(Mesh_3, d_groups_2) - # Compare mesh group with imprinting set by ids and mesh group with imprinting set by geom group - assert math.isclose( smesh.GetArea(gr_2), smesh.GetArea(gr_3)) +# Compute same mesh with library +MG_Hybrid_Parameters_3.SetToUseLibrary(True) +Mesh_3.Clear() +Mesh_3.Compute() +checkMesh_3(Mesh_3, d_groups_2)