1 // Copyright (C) 2004-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MG_HYBRID_API.hxx"
22 #include <SMESH_Comment.hxx>
23 #include <SMESH_File.hxx>
24 #include <SMESH_MGLicenseKeyGen.hxx>
25 #include <Utils_SALOME_Exception.hxx>
26 #include "utilities.h"
37 #include <meshgems/meshgems.h>
38 #include <meshgems/hybrid.h>
41 struct MG_HYBRID_API::LibData
45 hybrid_session_t *_session;
48 mesh_t * _hybrid_mesh;
51 std::vector<double> _xyz;
52 std::vector<double> _nodeSize; // required nodes
53 std::vector<int> _edgeNodesTags;
55 std::vector<int> _triaNodesTags;
57 std::vector<int> _quadNodes;
58 std::vector<int> _corners;
61 volatile bool& _cancelled_flag;
62 std::string _errorStr;
67 LibData( volatile bool & cancelled_flag, double& progress )
68 : _context(0), _session(0), _surf_mesh(0), _sizemap(0), _hybrid_mesh(0),
69 _nbRequiredEdges(0), _nbRequiredTria(0),
70 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
73 // methods setting callbacks implemented after callback definitions
80 hybrid_regain_mesh( _session, _hybrid_mesh );
82 hybrid_session_delete( _session );
84 mesh_delete( _surf_mesh );
86 sizemap_delete( _sizemap );
88 context_delete( _context );
97 void AddError( const char *txt )
105 const std::string& GetErrors()
110 void MG_Error(const char* txt="")
112 SMESH_Comment msg("\nMeshGems error. ");
115 AddError( msg.c_str() );
118 //================================================================================
120 * \brief SetParam to define a parameter by its value
121 * \param [in] param - the parameter to set
122 * \param [in] valus - its value
123 * \return bool - Ok or not
125 //================================================================================
126 bool SetParam( const std::string& param, const std::string& value )
128 status_t ret = hybrid_set_param( _session, param.c_str(), value.c_str() );
129 MESSAGE(param << " = " << value);
130 return ( ret == STATUS_OK );
134 //================================================================================
136 * \brief SetTags to define boundary layers
137 * \param [in] param - the parameter to set
138 * \param [in] values - a list of ids separated by a comma
139 * \param [in] size - the size of the boundary layer
140 * \return bool - Ok or not
142 //================================================================================
143 bool SetTags( const std::string& param, const std::string& values, const std::string& size )
145 // constructing stream from the string
146 std::stringstream ss(values);
148 // for each string value separated by ',' call hybrid API to set the tag
149 while (getline(ss, s, ','))
153 if ( param=="boundary_layer_imprinting_tags" )
155 ret = hybrid_set_boundary_layer_imprinting_tag(_session, tag);
156 MESSAGE("imprinting " << tag);
158 else if ( param=="boundary_layer_snapping_tags" )
160 ret = hybrid_set_boundary_layer_snapping_tag(_session, tag);
161 MESSAGE("snapping " << tag);
163 else if ( param=="boundary_layer_surface_tags" )
165 ret = hybrid_set_initial_height_on_surface_tag(_session, tag, stod(size));
166 MESSAGE("height " << tag << " = " << stod(size));
168 if ( ret != STATUS_OK )
170 MESSAGE("PBBBBBBBBBBBBBBBBBBBBBB STATUS not OK ");
179 return _cancelled_flag;
182 int ReadNbSubDomains()
185 status_t ret = mesh_get_subdomain_count( _hybrid_mesh, & nb );
187 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
196 status_t ret = mesh_get_vertex_count( _hybrid_mesh, & nb );
198 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
205 status_t ret = mesh_get_edge_count( _hybrid_mesh, & nb );
207 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
214 status_t ret = mesh_get_triangle_count( _hybrid_mesh, & nb );
216 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
223 status_t ret = mesh_get_quadrangle_count( _hybrid_mesh, & nb );
225 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
232 status_t ret = mesh_get_tetrahedron_count( _hybrid_mesh, & nb );
234 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
241 status_t ret = mesh_get_hexahedron_count( _hybrid_mesh, & nb );
243 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
250 status_t ret = mesh_get_prism_count( _hybrid_mesh, & nb );
252 if ( ret != STATUS_OK ) MG_Error("mesh_get_prism_count problem");
259 status_t ret = mesh_get_pyramid_count( _hybrid_mesh, & nb );
261 if ( ret != STATUS_OK ) MG_Error("mesh_get_pyramid_count problem");
267 return _corners.size();
275 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
277 integer tag, seed_type, seed_idx, seed_orientation;
278 status_t ret = mesh_get_subdomain_description( _hybrid_mesh, _count,
279 &tag, &seed_type, &seed_idx, &seed_orientation);
281 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
286 *ori = seed_orientation;
290 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
293 status_t ret = mesh_get_vertex_coordinates( _hybrid_mesh, _count, coo );
294 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
300 integer isCorner = 0;
301 ret = mesh_get_vertex_corner_property( _hybrid_mesh, _count, &isCorner);
302 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
304 _corners.push_back( _count );
309 void ReadEdgeNodes( int* node1, int* node2, int* domain )
312 status_t ret = mesh_get_edge_vertices( _hybrid_mesh, _count, vtx);
313 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
318 ret = mesh_get_edge_tag( _hybrid_mesh, _count, &tag );
319 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
326 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
329 status_t ret = mesh_get_triangle_vertices( _hybrid_mesh, _count, vtx);
330 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
336 ret = mesh_get_triangle_tag( _hybrid_mesh, _count, &tag );
337 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
344 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
347 status_t ret = mesh_get_quadrangle_vertices( _hybrid_mesh, _count, vtx);
348 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
355 ret = mesh_get_quadrangle_tag( _hybrid_mesh, _count, &tag );
356 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
363 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
366 status_t ret = mesh_get_tetrahedron_vertices( _hybrid_mesh, _count, vtx);
367 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
374 ret = mesh_get_tetrahedron_tag( _hybrid_mesh, _count, &tag );
375 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
382 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
383 int* node5, int* node6, int* node7, int* node8, int* domain )
386 status_t ret = mesh_get_hexahedron_vertices( _hybrid_mesh, _count, vtx);
387 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
398 ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
399 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
406 void ReadPrismNodes( int* node1, int* node2, int* node3, int* node4,
407 int* node5, int* node6, int* /*domain*/ )
410 status_t ret = mesh_get_prism_vertices( _hybrid_mesh, _count, vtx);
411 if (ret != STATUS_OK) MG_Error( "unable to get resulting prism" );
421 // ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
422 // if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
429 void ReadPyramidNodes( int* node1, int* node2, int* node3, int* node4, int* node5, int* domain )
432 status_t ret = mesh_get_pyramid_vertices( _hybrid_mesh, _count, vtx);
433 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid" );
442 ret = mesh_get_pyramid_tag( _hybrid_mesh, _count, &tag );
443 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid tag" );
450 void ReadCorner( int* node )
452 if ( _count <= ReadNbCorners() )
453 *node = _corners[ _count - 1 ];
460 void SetNbVertices( int nb )
462 _xyz.reserve( _xyz.capacity() + nb );
465 void SetNbEdges( int nb )
467 _edgeNodesTags.reserve( nb * 3 );
470 void SetNbTria( int nb )
472 _triaNodesTags.reserve( nb * 4 );
475 void SetNbQuads( int nb )
477 _quadNodes.reserve( nb * 4 );
480 void SetNbReqVertices( int nb )
482 _nodeSize.reserve( nb );
485 void SetNbReqEdges( int nb )
487 _nbRequiredEdges = nb;
490 void SetNbReqTria( int nb )
492 _nbRequiredTria = nb;
495 void AddNode( double x, double y, double z, int /*domain*/ )
502 void AddSizeAtNode( double size )
504 _nodeSize.push_back( size );
507 void AddEdgeNodes( int node1, int node2, int domain )
509 _edgeNodesTags.push_back( node1 );
510 _edgeNodesTags.push_back( node2 );
511 _edgeNodesTags.push_back( domain );
514 void AddTriaNodes( int node1, int node2, int node3, int domain )
516 _triaNodesTags.push_back( node1 );
517 _triaNodesTags.push_back( node2 );
518 _triaNodesTags.push_back( node3 );
519 _triaNodesTags.push_back( domain );
522 void AddQuadNodes( int node1, int node2, int node3, int node4 )
524 _quadNodes.push_back( node1 );
525 _quadNodes.push_back( node2 );
526 _quadNodes.push_back( node3 );
527 _quadNodes.push_back( node4 );
532 return _xyz.size() / 3;
535 double* NodeCoord( int iNode )
537 return & _xyz[ iNode * 3 ];
542 return _edgeNodesTags.size() / 3;
545 int* GetEdgeNodes( int iEdge )
547 return & _edgeNodesTags[ iEdge * 3 ];
550 int GetEdgeTag( int iEdge )
552 return _edgeNodesTags[ iEdge * 3 + 2 ];
557 return _triaNodesTags.size() / 4;
560 int * GetTriaNodes( int iTria )
562 return & _triaNodesTags[ iTria * 4 ];
565 int GetTriaTag( int iTria )
567 return _triaNodesTags[ iTria * 4 + 3 ];
572 return _quadNodes.size() / 4;
575 int * GetQuadNodes( int iQ )
577 return & _quadNodes[ iQ * 4 ];
580 int IsVertexRequired( int iNode )
582 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
585 double GetSizeAtVertex( int iNode )
587 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
591 namespace // functions called by MG library to exchange with the application
593 status_t get_vertex_count(integer * nbvtx, void *user_data)
595 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
596 *nbvtx = data->NbNodes();
601 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
603 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
604 double* coord = data->NodeCoord( ivtx-1 );
605 for (int j = 0; j < 3; j++)
610 status_t get_edge_count(integer * nbedge, void *user_data)
612 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
613 *nbedge = data->NbEdges();
618 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
620 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
621 int* nodes = data->GetEdgeNodes( iedge-1 );
628 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
630 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
631 * tag = data->GetEdgeTag( iedge-1 );
636 status_t get_triangle_count(integer * nbtri, void *user_data)
638 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
639 *nbtri = data->NbTriangles();
644 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
646 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
647 int* nodes = data->GetTriaNodes( itri-1 );
655 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
657 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
658 * tag = data->GetTriaTag( itri-1 );
663 status_t get_quadrangle_count(integer * nbq, void *user_data)
665 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
666 *nbq = data->NbQuads();
671 status_t get_quadrangle_vertices(integer iq, integer * vq, void *user_data)
673 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
674 int* nodes = data->GetQuadNodes( iq-1 );
683 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
685 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
686 *rvtx = data->IsVertexRequired( ivtx - 1 );
691 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
693 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
694 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
699 status_t my_message_cb(message_t * msg, void *user_data)
703 integer i, i_data[10];
706 message_get_description(msg, &desc);
707 message_get_number(msg, &e);
710 printf("mg-hybrid ERROR %i : %s", MESHGEMS_ABS_CODE(e), desc);
711 message_get_integer_data_count(msg, &n);
712 message_get_real_data_count(msg, &m);
713 printf("MGMESSAGE %i ", e);
716 message_get_integer_data(msg, 1, n, i_data);
717 for (i = 0; i < n; i++)
718 printf(" %i", i_data[i]);
722 message_get_real_data(msg, 1, m, r_data);
723 for (i = 0; i < m; i++)
724 printf(" %f", r_data[i]);
731 printf("\rmg-hybrid info : %s", desc);
733 printf("mg-hybrid info %i : %s", MESHGEMS_CODE(e), desc);
735 message_get_description(msg, &desc);
737 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
738 data->AddError( desc );
743 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
745 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
746 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
754 void MG_HYBRID_API::LibData::Init()
758 // Create the meshgems working context
759 _context = context_new();
760 if ( !_context ) MG_Error( "unable to create a new context" );
762 // Set the message callback for the _context.
763 ret = context_set_message_callback( _context, my_message_cb, this );
764 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
766 // Create the structure holding the callbacks giving access to triangle mesh
767 _surf_mesh = mesh_new( _context );
768 if ( !_surf_mesh ) MG_Error("unable to create a new mesh");
770 // Set callbacks to provide triangle mesh data
771 mesh_set_get_vertex_count( _surf_mesh, get_vertex_count, this );
772 mesh_set_get_vertex_coordinates( _surf_mesh, get_vertex_coordinates, this );
773 mesh_set_get_vertex_required_property( _surf_mesh, get_vertex_required_property, this );
774 mesh_set_get_edge_count( _surf_mesh, get_edge_count, this);
775 mesh_set_get_edge_vertices( _surf_mesh, get_edge_vertices, this );
776 mesh_set_get_edge_tag( _surf_mesh, get_edge_tag, this );
777 mesh_set_get_triangle_count( _surf_mesh, get_triangle_count, this );
778 mesh_set_get_triangle_vertices( _surf_mesh, get_triangle_vertices, this );
779 mesh_set_get_triangle_tag( _surf_mesh, get_triangle_tag, this );
780 mesh_set_get_quadrangle_count( _surf_mesh, get_quadrangle_count, this );
781 mesh_set_get_quadrangle_vertices( _surf_mesh, get_quadrangle_vertices, this );
783 // Create a hybrid session
784 _session = hybrid_session_new( _context );
785 if ( !_session ) MG_Error( "unable to create a new hybrid session");
787 ret = hybrid_set_interrupt_callback( _session, my_interrupt_callback, this );
788 if ( ret != STATUS_OK ) MG_Error("in hybrid_set_interrupt_callback");
792 bool MG_HYBRID_API::LibData::Compute()
795 std::string errorTxt;
798 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _surf_mesh, "hybrid", errorTxt ))
800 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
805 ret = hybrid_set_surface_mesh( _session, _surf_mesh );
806 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
810 if ( !_nodeSize.empty() )
812 _sizemap = meshgems_sizemap_new( _surf_mesh, meshgems_sizemap_type_iso_mesh_vertex,
813 (void*) &get_vertex_weight, this );
814 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
816 ret = hybrid_set_sizemap( _session, _sizemap );
817 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
821 //////////////////////////////////////////////////////////////////////////////////////////
822 // const char* file = "/tmp/ghs3d_IN.mesh";
823 // mesh_write_mesh( _surf_mesh,file);
824 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
826 ret = hybrid_compute_mesh( _session );
827 if ( ret != STATUS_OK ) return false;
829 ret = hybrid_get_mesh( _session, &_hybrid_mesh);
830 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
832 //////////////////////////////////////////////////////////////////////////////////////////
833 // file = "/tmp/ghs3d_OUT.mesh";
834 // mesh_write_mesh( _hybrid_mesh,file);
835 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
840 #else // ifdef USE_MG_LIBS
842 struct MG_HYBRID_API::LibData // to avoid compiler warnings
844 volatile bool& _cancelled_flag;
846 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
849 #endif // ifdef USE_MG_LIBS
852 //================================================================================
856 //================================================================================
858 MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress)
859 :_nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
862 _libData = new LibData( cancelled_flag, progress );
865 //================================================================================
869 //================================================================================
871 MG_HYBRID_API::~MG_HYBRID_API()
875 std::set<int>::iterator id = _openFiles.begin();
876 for ( ; id != _openFiles.end(); ++id )
877 ::GmfCloseMesh( *id );
881 //================================================================================
883 * \brief Return the way of MG usage
885 //================================================================================
887 bool MG_HYBRID_API::IsLibrary()
892 //================================================================================
894 * \brief Switch to usage of MG-HYBRID library
896 //================================================================================
898 void MG_HYBRID_API::SetUseLibrary()
906 //================================================================================
908 * \brief Switch to usage of MG-HYBRID executable
910 //================================================================================
912 void MG_HYBRID_API::SetUseExecutable()
917 //================================================================================
919 * \brief Compute the hybrid mesh
920 * \param [in] cmdLine - a command to run mg_hybrid.exe
921 * \return bool - Ok or not
923 //================================================================================
925 bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
930 std::istringstream strm( cmdLine );
931 std::istream_iterator<std::string> sIt( strm ), sEnd;
932 std::vector< std::string > args( sIt, sEnd );
935 std::string param, value;
936 std::string boundary_layer_size;
938 for ( size_t i = 1; i < args.size(); i=i+2 )
942 MESSAGE("param: " << param);
943 MESSAGE("value: " << value);
945 // skipping output redirection, it is not a param to set
949 // removing -- from param
950 while ( param[0] == '-')
951 param = param.substr( 1 );
953 // store this value for boundary layer definition (needed by setTags after)
954 if (param == "boundary_layer_global_initial_height")
955 boundary_layer_size = value;
957 // set parameters with list of tags (string of ids separated by a comma)
958 if (param=="boundary_layer_imprinting_tags" || param=="boundary_layer_snapping_tags" || param=="boundary_layer_surface_tags")
960 if (!_libData->SetTags(param, value, boundary_layer_size))
961 std::cout << "Warning: error in SetTags(" << param << ", " << value << ", " << boundary_layer_size << ")" << std::endl;
963 // set other parameters
964 else if ( !_libData->SetParam( param, value ))
965 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
969 bool ok = _libData->Compute();
971 GetLog(); // write a log file
972 _logFile = ""; // not to write it again
978 // not library => call executable
980 // add MG license key
982 std::string errorTxt, meshIn;
983 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
984 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
988 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
992 const_cast< std::string& >( cmdLine ) += " --key " + key;
995 int err = system( cmdLine.c_str() ); // run
998 errStr = SMESH_Comment("system(mg-hybrid.exe ...) command failed with error: ")
999 << strerror( errno );
1005 //================================================================================
1007 * \brief Prepare for reading a mesh data
1009 //================================================================================
1011 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
1018 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
1019 _openFiles.insert( id );
1023 //================================================================================
1025 * \brief Return nb of entities
1027 //================================================================================
1029 int MG_HYBRID_API::GmfStatKwd( int iMesh, GmfKwdCod what )
1035 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
1036 case GmfVertices: return _libData->ReadNbNodes();
1037 case GmfEdges: return _libData->ReadNbEdges();
1038 case GmfTriangles: return _libData->ReadNbTria();
1039 case GmfQuadrilaterals: return _libData->ReadNbQuads();
1040 case GmfTetrahedra: return _libData->ReadNbTetra();
1041 case GmfPrisms: return _libData->ReadNbPrisms();
1042 case GmfPyramids: return _libData->ReadNbPyramids();
1043 case GmfHexahedra: return _libData->ReadNbHexa();
1044 case GmfCorners: return _libData->ReadNbCorners();
1050 return ::GmfStatKwd( iMesh, what );
1053 //================================================================================
1055 * \brief Prepare for reading some data
1057 //================================================================================
1059 void MG_HYBRID_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
1063 _libData->ResetCounter();
1067 ::GmfGotoKwd( iMesh, what );
1070 //================================================================================
1072 * \brief Return index of a domain identified by a triangle normal
1073 * \param [in] iMesh - mesh file index
1074 * \param [in] what - must be GmfSubDomainFromGeom
1075 * \param [out] nbNodes - nb nodes in a face
1076 * \param [out] faceInd - face index
1077 * \param [out] ori - face orientation
1078 * \param [out] domain - domain index
1079 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
1082 //================================================================================
1084 void MG_HYBRID_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
1088 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
1092 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
1095 //================================================================================
1097 * \brief Return coordinates of a next node
1099 //================================================================================
1101 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1102 double* x, double* y, double *z, int* domain )
1106 _libData->ReadNodeXYZ( x, y, z, domain );
1110 ::GmfGetLin(iMesh, what, x, y, z, domain );
1113 //================================================================================
1115 * \brief Return coordinates of a next node
1117 //================================================================================
1119 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1120 float* x, float* y, float *z, int* domain )
1125 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
1132 ::GmfGetLin(iMesh, what, x, y, z, domain );
1135 //================================================================================
1137 * \brief Return node index of a next corner
1139 //================================================================================
1141 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
1145 _libData->ReadCorner( node );
1149 ::GmfGetLin(iMesh, what, node );
1152 //================================================================================
1154 * \brief Return node indices of a next edge
1156 //================================================================================
1158 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1162 _libData->ReadEdgeNodes( node1, node2, domain );
1166 ::GmfGetLin( iMesh, what, node1, node2, domain );
1169 //================================================================================
1171 * \brief Return node indices of a next triangle
1173 //================================================================================
1175 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1176 int* node1, int* node2, int* node3, int* domain )
1180 _libData->ReadTriaNodes( node1, node2, node3, domain );
1184 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1187 //================================================================================
1189 * \brief Return node indices of a next tetrahedron or quadrangle
1191 //================================================================================
1193 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1194 int* node1, int* node2, int* node3, int* node4, int* domain )
1198 if ( what == GmfQuadrilaterals )
1199 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1201 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1205 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1208 //================================================================================
1210 * \brief Return node indices of a next hexahedron
1212 //================================================================================
1214 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1215 int* node1, int* node2, int* node3, int* node4,
1216 int* node5, int* node6, int* node7, int* node8,
1221 _libData->ReadHexaNodes( node1, node2, node3, node4, node5, node6, node7, node8, domain );
1225 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1228 //================================================================================
1230 * \brief Return node indices of a next pyramid
1232 //================================================================================
1234 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1235 int* node1, int* node2, int* node3, int* node4,
1236 int* node5, int* domain )
1240 _libData->ReadPyramidNodes( node1, node2, node3, node4, node5, domain );
1244 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, domain );
1247 //================================================================================
1249 * \brief Return node indices of a next prism
1251 //================================================================================
1253 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1254 int* node1, int* node2, int* node3, int* node4,
1255 int* node5, int* node6, int* domain )
1259 _libData->ReadPrismNodes( node1, node2, node3, node4, node5, node6, domain );
1263 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, domain );
1266 //================================================================================
1268 * \brief Prepare for passing data to MeshGems
1270 //================================================================================
1272 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1279 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1280 _openFiles.insert( id );
1284 //================================================================================
1286 * \brief Set number of entities
1288 //================================================================================
1290 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1295 case GmfVertices: _nbNodes = nb; break;
1296 case GmfEdges: _nbEdges = nb; break;
1297 case GmfTriangles: _nbFaces += nb; break;
1298 case GmfQuadrilaterals: _nbFaces += nb; break;
1305 case GmfVertices: _libData->SetNbVertices( nb ); break;
1306 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1307 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1308 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1309 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1315 ::GmfSetKwd(iMesh, what, nb );
1318 //================================================================================
1320 * \brief Add coordinates of a node
1322 //================================================================================
1324 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1328 _libData->AddNode( x, y, z, domain );
1332 ::GmfSetLin(iMesh, what, x, y, z, domain);
1335 //================================================================================
1337 * \brief Set number of field entities
1338 * \param [in] iMesh - solution file index
1339 * \param [in] what - solution type
1340 * \param [in] nbNodes - nb of entities
1341 * \param [in] nbTypes - nb of data entries in each entity
1342 * \param [in] type - types of the data entries
1344 * Used to prepare to storing size at nodes
1346 //================================================================================
1348 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1352 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1356 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1359 //================================================================================
1361 * \brief Add solution data
1363 //================================================================================
1365 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1369 _libData->AddSizeAtNode( vals[0] );
1373 ::GmfSetLin(iMesh, what, vals);
1376 //================================================================================
1378 * \brief Add edge nodes
1380 //================================================================================
1382 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1386 _libData->AddEdgeNodes( node1, node2, domain );
1390 ::GmfSetLin(iMesh, what, node1, node2, domain );
1393 //================================================================================
1395 * \brief Add a 'required' flag
1397 //================================================================================
1399 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1406 ::GmfSetLin(iMesh, what, id );
1409 //================================================================================
1411 * \brief Add triangle nodes
1413 //================================================================================
1415 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1419 _libData->AddTriaNodes( node1, node2, node3, domain );
1423 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1426 //================================================================================
1428 * \brief Add quadrangle nodes
1430 //================================================================================
1432 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int node4, int domain )
1436 _libData->AddQuadNodes( node1, node2, node3, node4 );
1440 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1443 //================================================================================
1445 * \brief Close a file
1447 //================================================================================
1449 void MG_HYBRID_API::GmfCloseMesh( int iMesh )
1456 ::GmfCloseMesh( iMesh );
1457 _openFiles.erase( iMesh );
1460 //================================================================================
1462 * \brief Return true if the log is not empty
1464 //================================================================================
1466 bool MG_HYBRID_API::HasLog()
1470 return !_libData->GetErrors().empty();
1473 SMESH_File file( _logFile );
1474 return file.size() > 0;
1477 //================================================================================
1479 * \brief Return log contents
1481 //================================================================================
1483 std::string MG_HYBRID_API::GetLog()
1487 const std::string& err = _libData->GetErrors();
1488 if ( !_logFile.empty() && !err.empty() )
1490 SMESH_File file( _logFile, /*openForReading=*/false );
1491 file.openForWriting();
1492 file.write( err.c_str(), err.size() );
1497 SMESH_File file( _logFile );
1498 return file.getPos();