1 // Copyright (C) 2004-2021 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 <SMESH_MGLicenseKeyGen.hxx>
25 #include <Utils_SALOME_Exception.hxx>
35 #include <meshgems/meshgems.h>
36 #include <meshgems/hybrid.h>
39 struct MG_HYBRID_API::LibData
43 hybrid_session_t *_session;
46 mesh_t * _hybrid_mesh;
49 std::vector<double> _xyz;
50 std::vector<double> _nodeSize; // required nodes
51 std::vector<int> _edgeNodesTags;
53 std::vector<int> _triaNodesTags;
55 std::vector<int> _quadNodes;
56 std::vector<int> _corners;
59 volatile bool& _cancelled_flag;
60 std::string _errorStr;
65 LibData( volatile bool & cancelled_flag, double& progress )
66 : _context(0), _session(0), _surf_mesh(0), _sizemap(0), _hybrid_mesh(0),
67 _nbRequiredEdges(0), _nbRequiredTria(0),
68 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
71 // methods setting callbacks implemented after callback definitions
78 hybrid_regain_mesh( _session, _hybrid_mesh );
80 hybrid_session_delete( _session );
82 mesh_delete( _surf_mesh );
84 sizemap_delete( _sizemap );
86 context_delete( _context );
95 void AddError( const char *txt )
103 const std::string& GetErrors()
108 void MG_Error(const char* txt="")
110 SMESH_Comment msg("\nMeshGems error. ");
112 AddError( msg.c_str() );
115 bool SetParam( const std::string& param, const std::string& value )
117 status_t ret = hybrid_set_param( _session, param.c_str(), value.c_str() );
119 //std::cout << param << " = " << value << std::endl;
121 return ( ret == STATUS_OK );
126 return _cancelled_flag;
129 int ReadNbSubDomains()
132 status_t ret = mesh_get_subdomain_count( _hybrid_mesh, & nb );
134 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
143 status_t ret = mesh_get_vertex_count( _hybrid_mesh, & nb );
145 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
152 status_t ret = mesh_get_edge_count( _hybrid_mesh, & nb );
154 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
161 status_t ret = mesh_get_triangle_count( _hybrid_mesh, & nb );
163 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
170 status_t ret = mesh_get_quadrangle_count( _hybrid_mesh, & nb );
172 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
179 status_t ret = mesh_get_tetrahedron_count( _hybrid_mesh, & nb );
181 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
188 status_t ret = mesh_get_hexahedron_count( _hybrid_mesh, & nb );
190 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
197 status_t ret = mesh_get_prism_count( _hybrid_mesh, & nb );
199 if ( ret != STATUS_OK ) MG_Error("mesh_get_prism_count problem");
205 return _corners.size();
213 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
215 integer tag, seed_type, seed_idx, seed_orientation;
216 status_t ret = mesh_get_subdomain_description( _hybrid_mesh, _count,
217 &tag, &seed_type, &seed_idx, &seed_orientation);
219 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
224 *ori = seed_orientation;
228 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
231 status_t ret = mesh_get_vertex_coordinates( _hybrid_mesh, _count, coo );
232 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
238 integer isCorner = 0;
239 ret = mesh_get_vertex_corner_property( _hybrid_mesh, _count, &isCorner);
240 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
242 _corners.push_back( _count );
247 void ReadEdgeNodes( int* node1, int* node2, int* domain )
250 status_t ret = mesh_get_edge_vertices( _hybrid_mesh, _count, vtx);
251 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
256 ret = mesh_get_edge_tag( _hybrid_mesh, _count, &tag );
257 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
264 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
267 status_t ret = mesh_get_triangle_vertices( _hybrid_mesh, _count, vtx);
268 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
274 ret = mesh_get_triangle_tag( _hybrid_mesh, _count, &tag );
275 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
282 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
285 status_t ret = mesh_get_quadrangle_vertices( _hybrid_mesh, _count, vtx);
286 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
293 ret = mesh_get_quadrangle_tag( _hybrid_mesh, _count, &tag );
294 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
301 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
304 status_t ret = mesh_get_tetrahedron_vertices( _hybrid_mesh, _count, vtx);
305 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
312 ret = mesh_get_tetrahedron_tag( _hybrid_mesh, _count, &tag );
313 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
320 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
321 int* node5, int* node6, int* node7, int* node8, int* domain )
324 status_t ret = mesh_get_hexahedron_vertices( _hybrid_mesh, _count, vtx);
325 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
336 ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
337 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
344 void ReadPrismNodes( int* node1, int* node2, int* node3, int* node4,
345 int* node5, int* node6, int* /*domain*/ )
348 status_t ret = mesh_get_prism_vertices( _hybrid_mesh, _count, vtx);
349 if (ret != STATUS_OK) MG_Error( "unable to get resulting prism" );
359 // ret = mesh_get_hexahedron_tag( _hybrid_mesh, _count, &tag );
360 // if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
367 void ReadPyramidNodes( int* node1, int* node2, int* node3, int* node4, int* node5, int* domain )
370 status_t ret = mesh_get_pyramid_vertices( _hybrid_mesh, _count, vtx);
371 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid" );
380 ret = mesh_get_pyramid_tag( _hybrid_mesh, _count, &tag );
381 if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid tag" );
388 void ReadCorner( int* node )
390 if ( _count <= ReadNbCorners() )
391 *node = _corners[ _count - 1 ];
398 void SetNbVertices( int nb )
400 _xyz.reserve( _xyz.capacity() + nb );
403 void SetNbEdges( int nb )
405 _edgeNodesTags.reserve( nb * 3 );
408 void SetNbTria( int nb )
410 _triaNodesTags.reserve( nb * 4 );
413 void SetNbQuads( int nb )
415 _quadNodes.reserve( nb * 4 );
418 void SetNbReqVertices( int nb )
420 _nodeSize.reserve( nb );
423 void SetNbReqEdges( int nb )
425 _nbRequiredEdges = nb;
428 void SetNbReqTria( int nb )
430 _nbRequiredTria = nb;
433 void AddNode( double x, double y, double z, int /*domain*/ )
440 void AddSizeAtNode( double size )
442 _nodeSize.push_back( size );
445 void AddEdgeNodes( int node1, int node2, int domain )
447 _edgeNodesTags.push_back( node1 );
448 _edgeNodesTags.push_back( node2 );
449 _edgeNodesTags.push_back( domain );
452 void AddTriaNodes( int node1, int node2, int node3, int domain )
454 _triaNodesTags.push_back( node1 );
455 _triaNodesTags.push_back( node2 );
456 _triaNodesTags.push_back( node3 );
457 _triaNodesTags.push_back( domain );
460 void AddQuadNodes( int node1, int node2, int node3, int node4 )
462 _quadNodes.push_back( node1 );
463 _quadNodes.push_back( node2 );
464 _quadNodes.push_back( node3 );
465 _quadNodes.push_back( node4 );
470 return _xyz.size() / 3;
473 double* NodeCoord( int iNode )
475 return & _xyz[ iNode * 3 ];
480 return _edgeNodesTags.size() / 3;
483 int* GetEdgeNodes( int iEdge )
485 return & _edgeNodesTags[ iEdge * 3 ];
488 int GetEdgeTag( int iEdge )
490 return _edgeNodesTags[ iEdge * 3 + 2 ];
495 return _triaNodesTags.size() / 4;
498 int * GetTriaNodes( int iTria )
500 return & _triaNodesTags[ iTria * 4 ];
503 int GetTriaTag( int iTria )
505 return _triaNodesTags[ iTria * 4 + 3 ];
510 return _quadNodes.size() / 4;
513 int * GetQuadNodes( int iQ )
515 return & _quadNodes[ iQ * 4 ];
518 int IsVertexRequired( int iNode )
520 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
523 double GetSizeAtVertex( int iNode )
525 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
529 namespace // functions called by MG library to exchange with the application
531 status_t get_vertex_count(integer * nbvtx, void *user_data)
533 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
534 *nbvtx = data->NbNodes();
539 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
541 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
542 double* coord = data->NodeCoord( ivtx-1 );
543 for (int j = 0; j < 3; j++)
548 status_t get_edge_count(integer * nbedge, void *user_data)
550 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
551 *nbedge = data->NbEdges();
556 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
558 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
559 int* nodes = data->GetEdgeNodes( iedge-1 );
566 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
568 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
569 * tag = data->GetEdgeTag( iedge-1 );
574 status_t get_triangle_count(integer * nbtri, void *user_data)
576 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
577 *nbtri = data->NbTriangles();
582 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
584 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
585 int* nodes = data->GetTriaNodes( itri-1 );
593 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
595 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
596 * tag = data->GetTriaTag( itri-1 );
601 status_t get_quadrangle_count(integer * nbq, void *user_data)
603 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
604 *nbq = data->NbQuads();
609 status_t get_quadrangle_vertices(integer iq, integer * vq, void *user_data)
611 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
612 int* nodes = data->GetQuadNodes( iq-1 );
621 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
623 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
624 *rvtx = data->IsVertexRequired( ivtx - 1 );
629 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
631 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
632 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
637 status_t my_message_cb(message_t * msg, void *user_data)
640 message_get_description(msg, &desc);
642 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
643 data->AddError( desc );
648 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
650 MG_HYBRID_API::LibData* data = (MG_HYBRID_API::LibData *) user_data;
651 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
659 void MG_HYBRID_API::LibData::Init()
663 // Create the meshgems working context
664 _context = context_new();
665 if ( !_context ) MG_Error( "unable to create a new context" );
667 // Set the message callback for the _context.
668 ret = context_set_message_callback( _context, my_message_cb, this );
669 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
671 // Create the structure holding the callbacks giving access to triangle mesh
672 _surf_mesh = mesh_new( _context );
673 if ( !_surf_mesh ) MG_Error("unable to create a new mesh");
675 // Set callbacks to provide triangle mesh data
676 mesh_set_get_vertex_count( _surf_mesh, get_vertex_count, this );
677 mesh_set_get_vertex_coordinates( _surf_mesh, get_vertex_coordinates, this );
678 mesh_set_get_vertex_required_property( _surf_mesh, get_vertex_required_property, this );
679 mesh_set_get_edge_count( _surf_mesh, get_edge_count, this);
680 mesh_set_get_edge_vertices( _surf_mesh, get_edge_vertices, this );
681 mesh_set_get_edge_tag( _surf_mesh, get_edge_tag, this );
682 mesh_set_get_triangle_count( _surf_mesh, get_triangle_count, this );
683 mesh_set_get_triangle_vertices( _surf_mesh, get_triangle_vertices, this );
684 mesh_set_get_triangle_tag( _surf_mesh, get_triangle_tag, this );
685 mesh_set_get_quadrangle_count( _surf_mesh, get_quadrangle_count, this );
686 mesh_set_get_quadrangle_vertices( _surf_mesh, get_quadrangle_vertices, this );
688 // Create a hybrid session
689 _session = hybrid_session_new( _context );
690 if ( !_session ) MG_Error( "unable to create a new hybrid session");
692 ret = hybrid_set_interrupt_callback( _session, my_interrupt_callback, this );
693 if ( ret != STATUS_OK ) MG_Error("in hybrid_set_interrupt_callback");
697 bool MG_HYBRID_API::LibData::Compute()
700 std::string errorTxt;
701 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _surf_mesh, errorTxt ))
703 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
708 status_t ret = hybrid_set_surface_mesh( _session, _surf_mesh );
709 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
713 if ( !_nodeSize.empty() )
715 _sizemap = meshgems_sizemap_new( _surf_mesh, meshgems_sizemap_type_iso_mesh_vertex,
716 (void*) &get_vertex_weight, this );
717 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
719 ret = hybrid_set_sizemap( _session, _sizemap );
720 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
724 //////////////////////////////////////////////////////////////////////////////////////////
725 // const char* file = "/tmp/ghs3d_IN.mesh";
726 // mesh_write_mesh( _surf_mesh,file);
727 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
729 ret = hybrid_compute_mesh( _session );
730 if ( ret != STATUS_OK ) return false;
732 ret = hybrid_get_mesh( _session, &_hybrid_mesh);
733 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
735 //////////////////////////////////////////////////////////////////////////////////////////
736 // file = "/tmp/ghs3d_OUT.mesh";
737 // mesh_write_mesh( _hybrid_mesh,file);
738 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
743 #else // ifdef USE_MG_LIBS
745 struct MG_HYBRID_API::LibData // to avoid compiler warnings
747 volatile bool& _cancelled_flag;
749 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
752 #endif // ifdef USE_MG_LIBS
755 //================================================================================
759 //================================================================================
761 MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress)
762 :_nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
765 _libData = new LibData( cancelled_flag, progress );
769 if ( getenv("MG_HYBRID_USE_EXE"))
774 //================================================================================
778 //================================================================================
780 MG_HYBRID_API::~MG_HYBRID_API()
786 std::set<int>::iterator id = _openFiles.begin();
787 for ( ; id != _openFiles.end(); ++id )
788 ::GmfCloseMesh( *id );
792 //================================================================================
794 * \brief Return the way of MG usage
796 //================================================================================
798 bool MG_HYBRID_API::IsLibrary()
803 //================================================================================
805 * \brief Switch to usage of MG-HYBRID executable
807 //================================================================================
809 void MG_HYBRID_API::SetUseExecutable()
814 //================================================================================
816 * \brief Compute the hybrid mesh
817 * \param [in] cmdLine - a command to run mg_hybrid.exe
818 * \return bool - Ok or not
820 //================================================================================
822 bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
828 std::istringstream strm( cmdLine );
829 std::istream_iterator<std::string> sIt( strm ), sEnd;
830 std::vector< std::string > args( sIt, sEnd );
833 std::string param, value;
834 for ( size_t i = 1; i < args.size(); ++i )
836 // look for a param name; it starts from "-"
838 if ( param.size() < 2 || param[0] != '-')
840 while ( param[0] == '-')
841 param = param.substr( 1 );
844 while ( i+1 < args.size() && args[i+1][0] != '-' )
846 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
848 if ( !value.empty() ) value += " ";
851 if ( !_libData->SetParam( param, value ))
852 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
856 bool ok = _libData->Compute();
858 GetLog(); // write a log file
859 _logFile = ""; // not to write it again
865 // add MG license key
867 std::string errorTxt, meshIn;
868 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
869 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
873 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
877 const_cast< std::string& >( cmdLine ) += " --key " + key;
880 int err = system( cmdLine.c_str() ); // run
883 errStr = SMESH_Comment("system(mg-hybrid.exe ...) command failed with error: ")
884 << strerror( errno );
890 //================================================================================
892 * \brief Prepare for reading a mesh data
894 //================================================================================
896 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
903 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
904 _openFiles.insert( id );
908 //================================================================================
910 * \brief Return nb of entities
912 //================================================================================
914 int MG_HYBRID_API::GmfStatKwd( int iMesh, GmfKwdCod what )
920 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
921 case GmfVertices: return _libData->ReadNbNodes();
922 case GmfEdges: return _libData->ReadNbEdges();
923 case GmfTriangles: return _libData->ReadNbTria();
924 case GmfQuadrilaterals: return _libData->ReadNbQuads();
925 case GmfTetrahedra: return _libData->ReadNbTetra();
926 case GmfPrisms: return _libData->ReadNbPrisms();
927 case GmfHexahedra: return _libData->ReadNbHexa();
928 case GmfCorners: return _libData->ReadNbCorners();
934 return ::GmfStatKwd( iMesh, what );
937 //================================================================================
939 * \brief Prepare for reading some data
941 //================================================================================
943 void MG_HYBRID_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
947 _libData->ResetCounter();
951 ::GmfGotoKwd( iMesh, what );
954 //================================================================================
956 * \brief Return index of a domain identified by a triangle normal
957 * \param [in] iMesh - mesh file index
958 * \param [in] what - must be GmfSubDomainFromGeom
959 * \param [out] nbNodes - nb nodes in a face
960 * \param [out] faceInd - face index
961 * \param [out] ori - face orientation
962 * \param [out] domain - domain index
963 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
966 //================================================================================
968 void MG_HYBRID_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
972 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
976 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
979 //================================================================================
981 * \brief Return coordinates of a next node
983 //================================================================================
985 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
986 double* x, double* y, double *z, int* domain )
990 _libData->ReadNodeXYZ( x, y, z, domain );
994 ::GmfGetLin(iMesh, what, x, y, z, domain );
997 //================================================================================
999 * \brief Return coordinates of a next node
1001 //================================================================================
1003 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1004 float* x, float* y, float *z, int* domain )
1009 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
1016 ::GmfGetLin(iMesh, what, x, y, z, domain );
1019 //================================================================================
1021 * \brief Return node index of a next corner
1023 //================================================================================
1025 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
1029 _libData->ReadCorner( node );
1033 ::GmfGetLin(iMesh, what, node );
1036 //================================================================================
1038 * \brief Return node indices of a next edge
1040 //================================================================================
1042 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1046 _libData->ReadEdgeNodes( node1, node2, domain );
1050 ::GmfGetLin( iMesh, what, node1, node2, domain );
1053 //================================================================================
1055 * \brief Return node indices of a next triangle
1057 //================================================================================
1059 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1060 int* node1, int* node2, int* node3, int* domain )
1064 _libData->ReadTriaNodes( node1, node2, node3, domain );
1068 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1071 //================================================================================
1073 * \brief Return node indices of a next tetrahedron or quadrangle
1075 //================================================================================
1077 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1078 int* node1, int* node2, int* node3, int* node4, int* domain )
1082 if ( what == GmfQuadrilaterals )
1083 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1085 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1089 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1092 //================================================================================
1094 * \brief Return node indices of a next hexahedron
1096 //================================================================================
1098 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1099 int* node1, int* node2, int* node3, int* node4,
1100 int* node5, int* node6, int* node7, int* node8,
1105 _libData->ReadHexaNodes( node1, node2, node3, node4, node5, node6, node7, node8, domain );
1109 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1112 //================================================================================
1114 * \brief Return node indices of a next pyramid
1116 //================================================================================
1118 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1119 int* node1, int* node2, int* node3, int* node4,
1120 int* node5, int* domain )
1124 _libData->ReadPyramidNodes( node1, node2, node3, node4, node5, domain );
1128 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, domain );
1131 //================================================================================
1133 * \brief Return node indices of a next prism
1135 //================================================================================
1137 void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
1138 int* node1, int* node2, int* node3, int* node4,
1139 int* node5, int* node6, int* domain )
1143 _libData->ReadPrismNodes( node1, node2, node3, node4, node5, node6, domain );
1147 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, domain );
1150 //================================================================================
1152 * \brief Prepare for passing data to MeshGems
1154 //================================================================================
1156 int MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1163 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1164 _openFiles.insert( id );
1168 //================================================================================
1170 * \brief Set number of entities
1172 //================================================================================
1174 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1179 case GmfVertices: _nbNodes = nb; break;
1180 case GmfEdges: _nbEdges = nb; break;
1181 case GmfTriangles: _nbFaces += nb; break;
1182 case GmfQuadrilaterals: _nbFaces += nb; break;
1189 case GmfVertices: _libData->SetNbVertices( nb ); break;
1190 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1191 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1192 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1193 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1199 ::GmfSetKwd(iMesh, what, nb );
1202 //================================================================================
1204 * \brief Add coordinates of a node
1206 //================================================================================
1208 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1212 _libData->AddNode( x, y, z, domain );
1216 ::GmfSetLin(iMesh, what, x, y, z, domain);
1219 //================================================================================
1221 * \brief Set number of field entities
1222 * \param [in] iMesh - solution file index
1223 * \param [in] what - solution type
1224 * \param [in] nbNodes - nb of entities
1225 * \param [in] nbTypes - nb of data entries in each entity
1226 * \param [in] type - types of the data entries
1228 * Used to prepare to storing size at nodes
1230 //================================================================================
1232 void MG_HYBRID_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1236 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1240 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1243 //================================================================================
1245 * \brief Add solution data
1247 //================================================================================
1249 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1253 _libData->AddSizeAtNode( vals[0] );
1257 ::GmfSetLin(iMesh, what, vals);
1260 //================================================================================
1262 * \brief Add edge nodes
1264 //================================================================================
1266 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1270 _libData->AddEdgeNodes( node1, node2, domain );
1274 ::GmfSetLin(iMesh, what, node1, node2, domain );
1277 //================================================================================
1279 * \brief Add a 'required' flag
1281 //================================================================================
1283 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1290 ::GmfSetLin(iMesh, what, id );
1293 //================================================================================
1295 * \brief Add triangle nodes
1297 //================================================================================
1299 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1303 _libData->AddTriaNodes( node1, node2, node3, domain );
1307 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1310 //================================================================================
1312 * \brief Add quadrangle nodes
1314 //================================================================================
1316 void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int node4, int domain )
1320 _libData->AddQuadNodes( node1, node2, node3, node4 );
1324 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1327 //================================================================================
1329 * \brief Close a file
1331 //================================================================================
1333 void MG_HYBRID_API::GmfCloseMesh( int iMesh )
1340 ::GmfCloseMesh( iMesh );
1341 _openFiles.erase( iMesh );
1344 //================================================================================
1346 * \brief Return true if the log is not empty
1348 //================================================================================
1350 bool MG_HYBRID_API::HasLog()
1354 return !_libData->GetErrors().empty();
1357 SMESH_File file( _logFile );
1358 return file.size() > 0;
1361 //================================================================================
1363 * \brief Return log contents
1365 //================================================================================
1367 std::string MG_HYBRID_API::GetLog()
1371 const std::string& err = _libData->GetErrors();
1372 if ( !_logFile.empty() && !err.empty() )
1374 SMESH_File file( _logFile, /*openForReading=*/false );
1375 file.openForWriting();
1376 file.write( err.c_str(), err.size() );
1381 SMESH_File file( _logFile );
1382 return file.getPos();