]> SALOME platform Git repositories - plugins/hybridplugin.git/commitdiff
Salome HOME
Some fixes to be able to call MG-Hybrid from library.
authorChristophe Bourcier <christophe.bourcier@cea.fr>
Tue, 7 May 2024 14:52:11 +0000 (16:52 +0200)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Tue, 7 May 2024 14:52:11 +0000 (16:52 +0200)
Using the library allows to define boundary layers on shapes with thousand of faces.
When using the executable, we are limited by the command line max length.

CMakeLists.txt
src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx
src/HYBRIDPlugin/MG_HYBRID_API.cxx

index 5493515f8b848b94ecdb84bd596a0177ddc4a8e7..0f8fec0c35c28136265cccc28f8657a3a2484b07 100644 (file)
@@ -63,7 +63,7 @@ SET(BUILD_SHARED_LIBS TRUE)
 # ============
 OPTION(SALOME_BUILD_TESTS "Build SALOME tests" ON)
 OPTION(SALOME_BUILD_DOC "Generate SALOME HYBRIDPLUGIN documentation" ON)
-OPTION(SALOME_USE_MG_LIBS "Use MeshGems libraries" OFF)
+OPTION(SALOME_USE_MG_LIBS "Use MeshGems libraries" ON)
 MARK_AS_ADVANCED(SALOME_USE_MG_LIBS)
 
 IF(SALOME_BUILD_TESTS)
index 5216f340e2a5f61396c413b486c28afe3ad4e2fa..a8723a1315557a52c558ab722f44ee56fd8973d2 100644 (file)
@@ -2067,7 +2067,11 @@ std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis*
       if ( !faceLayersIDs.empty() )
         cmd << " --boundary_layer_surface_tags ";
       for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
-        cmd << faceLayersIDs[i] << ",";
+      {
+        cmd << faceLayersIDs[i];
+        if (i<faceLayersIDs.size()-1)
+          cmd << ",";
+      }
       // Don't need to set the height of the layer face by face since:
       // - the same height is already set on all the faces with boundary_layer_global_initial_height
       // - we don't allow the user to set different heights for specific faces for now
@@ -2082,14 +2086,22 @@ std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis*
       if ( !faceImprintingIDs.empty() )
         cmd << " --boundary_layer_imprinting yes --boundary_layer_imprinting_tags ";
       for ( size_t i = 0; i < faceImprintingIDs.size(); ++i )
-        cmd << faceImprintingIDs[i] << ",";
+      {
+        cmd << faceImprintingIDs[i];
+        if (i<faceImprintingIDs.size()-1)
+          cmd << ",";
+      }
 
       // faces with snapping
       const std::vector<int>& faceSnappingIDs = hyp->GetFacesWithSnapping();
       if ( !faceSnappingIDs.empty() )
         cmd << " --boundary_layer_snapping yes --boundary_layer_snapping_tags ";
       for ( size_t i = 0; i < faceSnappingIDs.size(); ++i )
-        cmd << faceSnappingIDs[i] << ",";
+      {
+        cmd << faceSnappingIDs[i];
+        if (i<faceSnappingIDs.size()-1)
+          cmd << ",";
+      }
     }
   }
 
index accb22b1d5ca5f83832094faf6656c86c564ca45..01ccb1a4f4783cad6feff67c3dc21fd98a23495c 100644 (file)
 #include <SMESH_File.hxx>
 #include <SMESH_MGLicenseKeyGen.hxx>
 #include <Utils_SALOME_Exception.hxx>
+#include "utilities.h"
 
 #include <cstring>
 #include <iostream>
 #include <iterator>
 #include <vector>
+#include <sstream>
 
 #ifdef USE_MG_LIBS
 
@@ -112,6 +114,14 @@ struct MG_HYBRID_API::LibData
     AddError( msg.c_str() );
   }
 
+  //================================================================================
+  /*!
+   * \brief SetParam to define a parameter by its value
+   *  \param [in] param - the parameter to set
+   *  \param [in] valus - its value
+   *  \return bool - Ok or not
+   */
+  //================================================================================
   bool SetParam( const std::string& param, const std::string& value )
   {
     status_t ret = hybrid_set_param( _session, param.c_str(), value.c_str() );
@@ -121,6 +131,38 @@ struct MG_HYBRID_API::LibData
     return ( ret == STATUS_OK );
   }
 
+
+  //================================================================================
+  /*!
+   * \brief SetTags to define boundary layers
+   *  \param [in] param - the parameter to set
+   *  \param [in] values - a list of ids separated by a comma
+   *  \param [in] size - the size of the boundary layer
+   *  \return bool - Ok or not
+   */
+  //================================================================================
+  bool SetTags( const std::string& param, const std::string& values, const std::string& size )
+  {
+    // constructing stream from the string
+    std::stringstream ss(values);
+    std::string s;
+    // for each string value separated by ',' call hybrid API to set the tag
+    while (getline(ss, s, ','))
+    {
+      status_t ret;
+      int tag = stoi(s);
+      if ( param=="boundary_layer_imprinting_tags" )
+        ret = hybrid_set_boundary_layer_imprinting_tag(_session, tag);
+      else if ( param=="boundary_layer_snapping_tags" )
+        ret = hybrid_set_boundary_layer_snapping_tag(_session, tag);
+      else if ( param=="boundary_layer_surface_tags" )
+        ret = hybrid_set_initial_height_on_surface_tag(_session, tag, stod(size));
+      if ( ret != STATUS_OK )
+        return false;
+    }
+    return true;
+  }
+
   bool Cancelled()
   {
     return _cancelled_flag;
@@ -200,6 +242,15 @@ struct MG_HYBRID_API::LibData
     return nb;
   }
 
+  int ReadNbPyramids()
+  {
+    integer nb = 0;
+    status_t ret = mesh_get_pyramid_count( _hybrid_mesh, & nb );
+
+    if ( ret != STATUS_OK ) MG_Error("mesh_get_pyramid_count problem");
+    return nb;
+  }
+
   int ReadNbCorners()
   {
     return _corners.size();
@@ -833,24 +884,35 @@ bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
 
     // set parameters
     std::string param, value;
-    for ( size_t i = 1; i < args.size(); ++i )
+    std::string boundary_layer_size;
+
+    for ( size_t i = 1; i < args.size(); i=i+2 )
     {
-      // look for a param name; it starts from "-"
       param = args[i];
-      if ( param.size() < 2 || param[0] != '-')
+      value = args[i+1];
+      MESSAGE("param: " <<  param);
+      MESSAGE("value: " <<  value);
+
+      // skipping output redirection, it is not a param to set
+      if (param=="1>")
         continue;
+
+      // removing -- from param
       while ( param[0] == '-')
         param = param.substr( 1 );
 
-      value = "";
-      while ( i+1 < args.size() && args[i+1][0] != '-' )
+      // store this value for boundary layer definition (needed by setTags after)
+      if (param == "boundary_layer_global_initial_height")
+        boundary_layer_size = value;
+
+      // set parameters with list of tags (string of ids separated by a comma)
+      if (param=="boundary_layer_imprinting_tags" || param=="boundary_layer_snapping_tags" || param=="boundary_layer_surface_tags")
       {
-        if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
-          break;
-        if ( !value.empty() ) value += " ";
-        value += args[++i];
+        if (!_libData->SetTags(param, value, boundary_layer_size))
+          std::cout << "Warning: error in SetTags(" << param << ", " << value << ", " << boundary_layer_size << ")" << std::endl;
       }
-      if ( !_libData->SetParam( param, value ))
+      // set other parameters
+      else if ( !_libData->SetParam( param, value ))
         std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
     }
 
@@ -926,6 +988,7 @@ int MG_HYBRID_API::GmfStatKwd( int iMesh, GmfKwdCod what )
     case GmfQuadrilaterals:    return _libData->ReadNbQuads();
     case GmfTetrahedra:        return _libData->ReadNbTetra();
     case GmfPrisms:            return _libData->ReadNbPrisms();
+    case GmfPyramids:          return _libData->ReadNbPyramids();
     case GmfHexahedra:         return _libData->ReadNbHexa();
     case GmfCorners:           return _libData->ReadNbCorners();
     default:                   return 0;