From: Christophe Bourcier Date: Tue, 7 May 2024 14:52:11 +0000 (+0200) Subject: Some fixes to be able to call MG-Hybrid from library. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3ca9778886f0fb155273cd71c142da987dd1cd6c;p=plugins%2Fhybridplugin.git Some fixes to be able to call MG-Hybrid from library. 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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5493515..0f8fec0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx index 5216f34..a8723a1 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx @@ -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& 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 #include #include +#include "utilities.h" #include #include #include #include +#include #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;