1 // Copyright (C) 2004-2020 CEA/DEN, EDF R&D
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 <Utils_SALOME_Exception.hxx>
33 #include <meshgems/meshgems.h>
34 #include <meshgems/hybrid.h>
37 struct MG_HYBRID_API::LibData
41 hybrid_session_t *_session;
44 mesh_t * _hybrid_mesh;
47 std::vector<double> _xyz;
48 std::vector<double> _nodeSize; // required nodes
49 std::vector<int> _edgeNodesTags;
51 std::vector<int> _triaNodesTags;
53 std::vector<int> _quadNodes;
54 std::vector<int> _corners;
57 volatile bool& _cancelled_flag;
58 std::string _errorStr;
63 LibData( volatile bool & cancelled_flag, double& progress )
64 : _context(0), _session(0), _surf_mesh(0), _sizemap(0), _hybrid_mesh(0),
65 _nbRequiredEdges(0), _nbRequiredTria(0),
66 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
69 // methods setting callbacks implemented after callback definitions
76 hybrid_regain_mesh( _session, _hybrid_mesh );
78 hybrid_session_delete( _session );
80 mesh_delete( _surf_mesh );
82 sizemap_delete( _sizemap );
84 context_delete( _context );
93 void AddError( const char *txt )
101 const std::string& GetErrors()
106 void MG_Error(const char* txt="")
108 SMESH_Comment msg("\nMeshGems error. ");
110 AddError( msg.c_str() );
113 bool SetParam( const std::string& param, const std::string& value )
115 status_t ret = hybrid_set_param( _session, param.c_str(), value.c_str() );
117 //std::cout << param << " = " << value << std::endl;
119 return ( ret == STATUS_OK );
124 return _cancelled_flag;
127 int ReadNbSubDomains()
130 status_t ret = mesh_get_subdomain_count( _hybrid_mesh, & nb );
132 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
141 status_t ret = mesh_get_vertex_count( _hybrid_mesh, & nb );
143 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
150 status_t ret = mesh_get_edge_count( _hybrid_mesh, & nb );
152 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
159 status_t ret = mesh_get_triangle_count( _hybrid_mesh, & nb );
161 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
168 status_t ret = mesh_get_quadrangle_count( _hybrid_mesh, & nb );
170 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
177 status_t ret = mesh_get_tetrahedron_count( _hybrid_mesh, & nb );
179 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
186 status_t ret = mesh_get_hexahedron_count( _hybrid_mesh, & nb );
188 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
195 status_t ret = mesh_get_prism_count( _hybrid_mesh, & nb );
197 if ( ret != STATUS_OK ) MG_Error("mesh_get_prism_count problem");
203 return _corners.size();
211 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
213 integer tag, seed_type, seed_idx, seed_orientation;
214 status_t ret = mesh_get_subdomain_description( _hybrid_mesh, _count,
215 &tag, &seed_type, &seed_idx, &seed_orientation);
217 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
222 *ori = seed_orientation;
226 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
229 status_t ret = mesh_get_vertex_coordinates( _hybrid_mesh, _count, coo );
230 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
236 integer isCorner = 0;
237 ret = mesh_get_vertex_corner_property( _hybrid_mesh, _count, &isCorner);
238 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
240 _corners.push_back( _count );
245 void ReadEdgeNodes( int* node1, int* node2, int* domain )
248 status_t ret = mesh_get_edge_vertices( _hybrid_mesh, _count, vtx);
249 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
254 ret = mesh_get_edge_tag( _hybrid_mesh, _count, &tag );
255 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
262 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
265 status_t ret = mesh_get_triangle_vertices( _hybrid_mesh, _count, vtx);
266 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
272 ret = mesh_get_triangle_tag( _hybrid_mesh, _count, &tag );
273 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
280 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
283 status_t ret = mesh_get_quadrangle_vertices( _hybrid_mesh, _count, vtx);
284 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
291 ret = mesh_get_quadrangle_tag( _hybrid_mesh, _count, &tag );
292 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
299 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
302 status_t ret = mesh_get_tetrahedron_vertices( _hybrid_mesh, _count, vtx);
303 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
310 ret = mesh_get_tetrahedron_tag( _hybrid_mesh, _count, &tag );
311 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
318 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
319 int* node5, int* node6, int* node7, int* node8, int* domain )
322 status_t ret = mesh_get_hexahedron_vertices( _hybrid_mesh, _count, vtx);
323 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
334 ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
335 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
342 void ReadPrismNodes( int* node1, int* node2, int* node3, int* node4,
343 int* node5, int* node6, int* domain )
346 status_t ret = mesh_get_prism_vertices( _hybrid_mesh, _count, vtx);
347 if (ret != STATUS_OK) MG_Error( "unable to get resulting prism" );
357 // ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
358 // if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
365 void ReadPyramidNodes( int* node1, int* node2, int* node3, int* node4, int* node5, int* domain )
368 status_t ret = mesh_get_pyramid_vertices( _hybrid_mesh, _count, vtx);
369 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid" );
378 ret = mesh_get_pyramid_tag( _hybrid_mesh, _count, &tag );
379 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid tag" );
386 void ReadCorner( int* node )
388 if ( _count <= ReadNbCorners() )
389 *node = _corners[ _count - 1 ];
396 void SetNbVertices( int nb )
398 _xyz.reserve( _xyz.capacity() + nb );
401 void SetNbEdges( int nb )
403 _edgeNodesTags.reserve( nb * 3 );
406 void SetNbTria( int nb )
408 _triaNodesTags.reserve( nb * 4 );
411 void SetNbQuads( int nb )
413 _quadNodes.reserve( nb * 4 );
416 void SetNbReqVertices( int nb )
418 _nodeSize.reserve( nb );
421 void SetNbReqEdges( int nb )
423 _nbRequiredEdges = nb;
426 void SetNbReqTria( int nb )
428 _nbRequiredTria = nb;
431 void AddNode( double x, double y, double z, int domain )
438 void AddSizeAtNode( double size )
440 _nodeSize.push_back( size );
443 void AddEdgeNodes( int node1, int node2, int domain )
445 _edgeNodesTags.push_back( node1 );
446 _edgeNodesTags.push_back( node2 );
447 _edgeNodesTags.push_back( domain );
450 void AddTriaNodes( int node1, int node2, int node3, int domain )
452 _triaNodesTags.push_back( node1 );
453 _triaNodesTags.push_back( node2 );
454 _triaNodesTags.push_back( node3 );
455 _triaNodesTags.push_back( domain );
458 void AddQuadNodes( int node1, int node2, int node3, int node4 )
460 _quadNodes.push_back( node1 );
461 _quadNodes.push_back( node2 );
462 _quadNodes.push_back( node3 );
463 _quadNodes.push_back( node4 );
468 return _xyz.size() / 3;
471 double* NodeCoord( int iNode )
473 return & _xyz[ iNode * 3 ];
478 return _edgeNodesTags.size() / 3;
481 int* GetEdgeNodes( int iEdge )
483 return & _edgeNodesTags[ iEdge * 3 ];
486 int GetEdgeTag( int iEdge )
488 return _edgeNodesTags[ iEdge * 3 + 2 ];
493 return _triaNodesTags.size() / 4;
496 int * GetTriaNodes( int iTria )
498 return & _triaNodesTags[ iTria * 4 ];
501 int GetTriaTag( int iTria )
503 return _triaNodesTags[ iTria * 4 + 3 ];
508 return _quadNodes.size() / 4;
511 int * GetQuadNodes( int iQ )
513 return & _quadNodes[ iQ * 4 ];
516 int IsVertexRequired( int iNode )
518 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
521 double GetSizeAtVertex( int iNode )
523 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
527 namespace // functions called by MG library to exchange with the application
529 status_t get_vertex_count(integer * nbvtx, void *user_data)
531 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
532 *nbvtx = data->NbNodes();
537 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
539 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
540 double* coord = data->NodeCoord( ivtx-1 );
541 for (int j = 0; j < 3; j++)
546 status_t get_edge_count(integer * nbedge, void *user_data)
548 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
549 *nbedge = data->NbEdges();
554 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
556 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
557 int* nodes = data->GetEdgeNodes( iedge-1 );
564 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
566 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
567 * tag = data->GetEdgeTag( iedge-1 );
572 status_t get_triangle_count(integer * nbtri, void *user_data)
574 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
575 *nbtri = data->NbTriangles();
580 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
582 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
583 int* nodes = data->GetTriaNodes( itri-1 );
591 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
593 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
594 * tag = data->GetTriaTag( itri-1 );
599 status_t get_quadrangle_count(integer * nbq, void *user_data)
601 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
602 *nbq = data->NbQuads();
607 status_t get_quadrangle_vertices(integer iq, integer * vq, void *user_data)
609 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
610 int* nodes = data->GetQuadNodes( iq-1 );
619 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
621 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
622 *rvtx = data->IsVertexRequired( ivtx - 1 );
627 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
629 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
630 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
635 status_t my_message_cb(message_t * msg, void *user_data)
638 message_get_description(msg, &desc);
640 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
641 data->AddError( desc );
646 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
648 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
649 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
657 void MG_HYBRID_API::LibData::Init()
661 // Create the meshgems working context
662 _context = context_new();
663 if ( !_context ) MG_Error( "unable to create a new context" );
665 // Set the message callback for the _context.
666 ret = context_set_message_callback( _context, my_message_cb, this );
667 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
669 // Create the structure holding the callbacks giving access to triangle mesh
670 _surf_mesh = mesh_new( _context );
671 if ( !_surf_mesh ) MG_Error("unable to create a new mesh");
673 // Set callbacks to provide triangle mesh data
674 mesh_set_get_vertex_count( _surf_mesh, get_vertex_count, this );
675 mesh_set_get_vertex_coordinates( _surf_mesh, get_vertex_coordinates, this );
676 mesh_set_get_vertex_required_property( _surf_mesh, get_vertex_required_property, this );
677 mesh_set_get_edge_count( _surf_mesh, get_edge_count, this);
678 mesh_set_get_edge_vertices( _surf_mesh, get_edge_vertices, this );
679 mesh_set_get_edge_tag( _surf_mesh, get_edge_tag, this );
680 mesh_set_get_triangle_count( _surf_mesh, get_triangle_count, this );
681 mesh_set_get_triangle_vertices( _surf_mesh, get_triangle_vertices, this );
682 mesh_set_get_triangle_tag( _surf_mesh, get_triangle_tag, this );
683 mesh_set_get_quadrangle_count( _surf_mesh, get_quadrangle_count, this );
684 mesh_set_get_quadrangle_vertices( _surf_mesh, get_quadrangle_vertices, this );
686 // Create a hybrid session
687 _session = hybrid_session_new( _context );
688 if ( !_session ) MG_Error( "unable to create a new hybrid session");
690 ret = hybrid_set_interrupt_callback( _session, my_interrupt_callback, this );
691 if ( ret != STATUS_OK ) MG_Error("in hybrid_set_interrupt_callback");
695 bool MG_HYBRID_API::LibData::Compute()
698 status_t ret = hybrid_set_surface_mesh( _session, _surf_mesh );
699 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
703 if ( !_nodeSize.empty() )
705 _sizemap = meshgems_sizemap_new( _surf_mesh, meshgems_sizemap_type_iso_mesh_vertex,
706 (void*) &get_vertex_weight, this );
707 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
709 ret = hybrid_set_sizemap( _session, _sizemap );
710 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
714 //////////////////////////////////////////////////////////////////////////////////////////
715 // const char* file = "/tmp/ghs3d_IN.mesh";
716 // mesh_write_mesh( _surf_mesh,file);
717 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
719 ret = hybrid_compute_mesh( _session );
720 if ( ret != STATUS_OK ) return false;
722 ret = hybrid_get_mesh( _session, &_hybrid_mesh);
723 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
725 //////////////////////////////////////////////////////////////////////////////////////////
726 // file = "/tmp/ghs3d_OUT.mesh";
727 // mesh_write_mesh( _hybrid_mesh,file);
728 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
734 #endif // ifdef USE_MG_LIBS
737 //================================================================================
741 //================================================================================
743 MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress)
748 _libData = new LibData( cancelled_flag, progress );
750 if ( getenv("MG_HYBRID_USE_EXE"))
755 //================================================================================
759 //================================================================================
761 MG_HYBRID_API::~MG_HYBRID_API()
767 std::set<int>::iterator id = _openFiles.begin();
768 for ( ; id != _openFiles.end(); ++id )
769 ::GmfCloseMesh( *id );
773 //================================================================================
775 * \brief Return the way of MG usage
777 //================================================================================
779 bool MG_HYBRID_API::IsLibrary()
784 //================================================================================
786 * \brief Switch to usage of MG-HYBRID executable
788 //================================================================================
790 void MG_HYBRID_API::SetUseExecutable()
795 //================================================================================
797 * \brief Compute the hybrid mesh
798 * \param [in] cmdLine - a command to run mg_hybrid.exe
799 * \return bool - Ok or not
801 //================================================================================
803 bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
809 std::istringstream strm( cmdLine );
810 std::istream_iterator<std::string> sIt( strm ), sEnd;
811 std::vector< std::string > args( sIt, sEnd );
814 std::string param, value;
815 for ( size_t i = 1; i < args.size(); ++i )
817 // look for a param name; it starts from "-"
819 if ( param.size() < 2 || param[0] != '-')
821 while ( param[0] == '-')
822 param = param.substr( 1 );
825 while ( i+1 < args.size() && args[i+1][0] != '-' )
827 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
829 if ( !value.empty() ) value += " ";
832 if ( !_libData->SetParam( param, value ))
833 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
837 bool ok = _libData->Compute();
839 GetLog(); // write a log file
840 _logFile = ""; // not to write it again
846 int err = system( cmdLine.c_str() ); // run
849 errStr = SMESH_Comment("system(mg-hybrid.exe ...) command failed with error: ")
850 << strerror( errno );
856 //================================================================================
858 * \brief Prepare for reading a mesh data
860 //================================================================================
862 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
869 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
870 _openFiles.insert( id );
874 //================================================================================
876 * \brief Return nb of entities
878 //================================================================================
880 int MG_HYBRID_API::GmfStatKwd( int iMesh, GmfKwdCod what )
886 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
887 case GmfVertices: return _libData->ReadNbNodes();
888 case GmfEdges: return _libData->ReadNbEdges();
889 case GmfTriangles: return _libData->ReadNbTria();
890 case GmfQuadrilaterals: return _libData->ReadNbQuads();
891 case GmfTetrahedra: return _libData->ReadNbTetra();
892 case GmfPrisms: return _libData->ReadNbPrisms();
893 case GmfHexahedra: return _libData->ReadNbHexa();
894 case GmfCorners: return _libData->ReadNbCorners();
900 return ::GmfStatKwd( iMesh, what );
903 //================================================================================
905 * \brief Prepare for reading some data
907 //================================================================================
909 void MG_HYBRID_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
913 _libData->ResetCounter();
917 ::GmfGotoKwd( iMesh, what );
920 //================================================================================
922 * \brief Return index of a domain identified by a triangle normal
923 * \param [in] iMesh - mesh file index
924 * \param [in] what - must be GmfSubDomainFromGeom
925 * \param [out] nbNodes - nb nodes in a face
926 * \param [out] faceInd - face index
927 * \param [out] ori - face orientation
928 * \param [out] domain - domain index
929 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
932 //================================================================================
934 void MG_HYBRID_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
938 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
942 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
945 //================================================================================
947 * \brief Return coordinates of a next node
949 //================================================================================
951 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
952 double* x, double* y, double *z, int* domain )
956 _libData->ReadNodeXYZ( x, y, z, domain );
960 ::GmfGetLin(iMesh, what, x, y, z, domain );
963 //================================================================================
965 * \brief Return coordinates of a next node
967 //================================================================================
969 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
970 float* x, float* y, float *z, int* domain )
975 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
982 ::GmfGetLin(iMesh, what, x, y, z, domain );
985 //================================================================================
987 * \brief Return node index of a next corner
989 //================================================================================
991 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
995 _libData->ReadCorner( node );
999 ::GmfGetLin(iMesh, what, node );
1002 //================================================================================
1004 * \brief Return node indices of a next edge
1006 //================================================================================
1008 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1012 _libData->ReadEdgeNodes( node1, node2, domain );
1016 ::GmfGetLin( iMesh, what, node1, node2, domain );
1019 //================================================================================
1021 * \brief Return node indices of a next triangle
1023 //================================================================================
1025 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1026 int* node1, int* node2, int* node3, int* domain )
1030 _libData->ReadTriaNodes( node1, node2, node3, domain );
1034 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1037 //================================================================================
1039 * \brief Return node indices of a next tetrahedron or quadrangle
1041 //================================================================================
1043 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1044 int* node1, int* node2, int* node3, int* node4, int* domain )
1048 if ( what == GmfQuadrilaterals )
1049 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1051 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1055 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1058 //================================================================================
1060 * \brief Return node indices of a next hexahedron
1062 //================================================================================
1064 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1065 int* node1, int* node2, int* node3, int* node4,
1066 int* node5, int* node6, int* node7, int* node8,
1071 _libData->ReadHexaNodes( node1, node2, node3, node4, node5, node6, node7, node8, domain );
1075 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1078 //================================================================================
1080 * \brief Return node indices of a next pyramid
1082 //================================================================================
1084 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1085 int* node1, int* node2, int* node3, int* node4,
1086 int* node5, int* domain )
1090 _libData->ReadPyramidNodes( node1, node2, node3, node4, node5, domain );
1094 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, domain );
1097 //================================================================================
1099 * \brief Return node indices of a next prism
1101 //================================================================================
1103 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1104 int* node1, int* node2, int* node3, int* node4,
1105 int* node5, int* node6, int* domain )
1109 _libData->ReadPrismNodes( node1, node2, node3, node4, node5, node6, domain );
1113 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, domain );
1116 //================================================================================
1118 * \brief Prepare for passing data to MeshGems
1120 //================================================================================
1122 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1129 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1130 _openFiles.insert( id );
1134 //================================================================================
1136 * \brief Set number of entities
1138 //================================================================================
1140 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1145 case GmfVertices: _libData->SetNbVertices( nb ); break;
1146 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1147 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1148 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1149 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1155 ::GmfSetKwd(iMesh, what, nb );
1158 //================================================================================
1160 * \brief Add coordinates of a node
1162 //================================================================================
1164 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1168 _libData->AddNode( x, y, z, domain );
1172 ::GmfSetLin(iMesh, what, x, y, z, domain);
1175 //================================================================================
1177 * \brief Set number of field entities
1178 * \param [in] iMesh - solution file index
1179 * \param [in] what - solution type
1180 * \param [in] nbNodes - nb of entities
1181 * \param [in] nbTypes - nb of data entries in each entity
1182 * \param [in] type - types of the data entries
1184 * Used to prepare to storing size at nodes
1186 //================================================================================
1188 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1192 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1196 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1199 //================================================================================
1201 * \brief Add solution data
1203 //================================================================================
1205 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1209 _libData->AddSizeAtNode( vals[0] );
1213 ::GmfSetLin(iMesh, what, vals);
1216 //================================================================================
1218 * \brief Add edge nodes
1220 //================================================================================
1222 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1226 _libData->AddEdgeNodes( node1, node2, domain );
1230 ::GmfSetLin(iMesh, what, node1, node2, domain );
1233 //================================================================================
1235 * \brief Add a 'required' flag
1237 //================================================================================
1239 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1246 ::GmfSetLin(iMesh, what, id );
1249 //================================================================================
1251 * \brief Add triangle nodes
1253 //================================================================================
1255 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1259 _libData->AddTriaNodes( node1, node2, node3, domain );
1263 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1266 //================================================================================
1268 * \brief Add quadrangle nodes
1270 //================================================================================
1272 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int node4, int domain )
1276 _libData->AddQuadNodes( node1, node2, node3, node4 );
1280 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1283 //================================================================================
1285 * \brief Close a file
1287 //================================================================================
1289 void MG_HYBRID_API::GmfCloseMesh( int iMesh )
1296 ::GmfCloseMesh( iMesh );
1297 _openFiles.erase( iMesh );
1300 //================================================================================
1302 * \brief Return true if the log is not empty
1304 //================================================================================
1306 bool MG_HYBRID_API::HasLog()
1310 return !_libData->GetErrors().empty();
1313 SMESH_File file( _logFile );
1314 return file.size() > 0;
1317 //================================================================================
1319 * \brief Return log contents
1321 //================================================================================
1323 std::string MG_HYBRID_API::GetLog()
1327 const std::string& err = _libData->GetErrors();
1328 if ( !_logFile.empty() && !err.empty() )
1330 SMESH_File file( _logFile, /*openForReading=*/false );
1331 file.openForWriting();
1332 file.write( err.c_str(), err.size() );
1337 SMESH_File file( _logFile );
1338 return file.getPos();