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_Hexotic_API.hxx"
26 #include <DriverGMF_Read.hxx>
27 #include <SMESH_Comment.hxx>
28 #include <SMESH_File.hxx>
29 #include <SMESH_MGLicenseKeyGen.hxx>
30 #include <Utils_SALOME_Exception.hxx>
40 #include <meshgems/meshgems.h>
41 #include <meshgems/hexa.h>
44 struct MG_Hexotic_API::LibData
48 hexa_session_t * _session;
54 std::vector<double> _xyz;
55 std::vector<double> _nodeSize; // required nodes
56 std::vector<int> _edgeNodesTags;
58 std::vector<int> _triaNodesTags;
61 std::vector<int> _corners;
64 volatile bool& _cancelled_flag;
65 std::string _errorStr;
69 LibData( volatile bool & cancelled_flag, double& progress )
70 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _hexa_mesh(0),
71 _nbRequiredEdges(0), _nbRequiredTria(0),
72 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
75 // methods setting callbacks implemented after callback definitions
82 hexa_regain_mesh( _session, _hexa_mesh );
84 mesh_delete( _tria_mesh );
86 sizemap_delete( _sizemap );
88 hexa_session_delete( _session );
90 context_delete( _context );
99 void AddError( const char *txt )
107 const std::string& GetErrors()
112 void MG_Error(const char* txt="")
114 SMESH_Comment msg("\nMeshGems error. ");
116 AddError( msg.c_str() );
119 bool SetParam( const std::string& param, const std::string& value )
121 status_t ret = hexa_set_param( _session, param.c_str(), value.c_str() );
123 //std::cout << param << " = " << value << std::endl;
125 return ( ret == STATUS_OK );
130 return _cancelled_flag;
133 int ReadNbSubDomains()
136 status_t ret = mesh_get_subdomain_count( _hexa_mesh, & nb );
138 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
147 status_t ret = mesh_get_vertex_count( _hexa_mesh, & nb );
149 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
156 status_t ret = mesh_get_edge_count( _hexa_mesh, & nb );
158 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
165 status_t ret = mesh_get_triangle_count( _hexa_mesh, & nb );
167 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
174 status_t ret = mesh_get_quadrangle_count( _hexa_mesh, & nb );
176 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
183 status_t ret = mesh_get_tetrahedron_count( _hexa_mesh, & nb );
185 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
192 status_t ret = mesh_get_hexahedron_count( _hexa_mesh, & nb );
194 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
200 return _corners.size();
208 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
210 integer tag, seed_type, seed_idx, seed_orientation;
211 status_t ret = mesh_get_subdomain_description( _hexa_mesh, _count,
212 &tag, &seed_type, &seed_idx, &seed_orientation);
214 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
219 *ori = seed_orientation;
223 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
226 status_t ret = mesh_get_vertex_coordinates( _hexa_mesh, _count, coo );
227 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
233 integer isCorner = 0;
234 ret = mesh_get_vertex_corner_property( _hexa_mesh, _count, &isCorner);
235 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
237 _corners.push_back( _count );
242 void ReadEdgeNodes( int* node1, int* node2, int* domain )
245 status_t ret = mesh_get_edge_vertices( _hexa_mesh, _count, vtx);
246 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
251 ret = mesh_get_edge_tag( _hexa_mesh, _count, &tag );
252 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
259 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
262 status_t ret = mesh_get_triangle_vertices( _hexa_mesh, _count, vtx);
263 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
269 ret = mesh_get_triangle_tag( _hexa_mesh, _count, &tag );
270 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
277 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
280 status_t ret = mesh_get_quadrangle_vertices( _hexa_mesh, _count, vtx);
281 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
288 ret = mesh_get_quadrangle_tag( _hexa_mesh, _count, &tag );
289 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
296 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
299 status_t ret = mesh_get_tetrahedron_vertices( _hexa_mesh, _count, vtx);
300 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
307 ret = mesh_get_tetrahedron_tag( _hexa_mesh, _count, &tag );
308 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
315 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
316 int* node5, int* node6, int* node7, int* node8, int* domain )
319 status_t ret = mesh_get_hexahedron_vertices( _hexa_mesh, _count, vtx);
320 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
331 ret = mesh_get_hexahedron_tag( _hexa_mesh, _count, &tag );
332 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
339 void ReadCorner( int* node )
341 if ( _count <= ReadNbCorners() )
342 *node = _corners[ _count - 1 ];
349 void SetNbVertices( int nb )
351 _xyz.reserve( _xyz.capacity() + nb );
354 void SetNbEdges( int nb )
356 _edgeNodesTags.reserve( nb * 3 );
359 void SetNbTria( int nb )
361 _triaNodesTags.reserve( nb * 4 );
364 void SetNbReqVertices( int nb )
366 _nodeSize.reserve( nb );
369 void SetNbReqEdges( int nb )
371 _nbRequiredEdges = nb;
374 void SetNbReqTria( int nb )
376 _nbRequiredTria = nb;
379 void AddNode( double x, double y, double z, int /*domain*/ )
386 void AddSizeAtNode( double size )
388 _nodeSize.push_back( size );
391 void AddEdgeNodes( int node1, int node2, int domain )
393 _edgeNodesTags.push_back( node1 );
394 _edgeNodesTags.push_back( node2 );
395 _edgeNodesTags.push_back( domain );
398 void AddTriaNodes( int node1, int node2, int node3, int domain )
400 _triaNodesTags.push_back( node1 );
401 _triaNodesTags.push_back( node2 );
402 _triaNodesTags.push_back( node3 );
403 _triaNodesTags.push_back( domain );
408 return _xyz.size() / 3;
411 double* NodeCoord( int iNode )
413 return & _xyz[ iNode * 3 ];
418 return _edgeNodesTags.size() / 3;
421 int* GetEdgeNodes( int iEdge )
423 return & _edgeNodesTags[ iEdge * 3 ];
426 int GetEdgeTag( int iEdge )
428 return _edgeNodesTags[ iEdge * 3 + 2 ];
433 return _triaNodesTags.size() / 4;
436 int * GetTriaNodes( int iTria )
438 return & _triaNodesTags[ iTria * 4 ];
441 int GetTriaTag( int iTria )
443 return _triaNodesTags[ iTria * 4 + 3 ];
446 int IsVertexRequired( int iNode )
448 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
451 double GetSizeAtVertex( int iNode )
453 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
457 namespace // functions called by MG library to exchange with the application
459 status_t get_vertex_count(integer * nbvtx, void *user_data)
461 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
462 *nbvtx = data->NbNodes();
467 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
469 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
470 double* coord = data->NodeCoord( ivtx-1 );
471 for (int j = 0; j < 3; j++)
476 status_t get_edge_count(integer * nbedge, void *user_data)
478 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
479 *nbedge = data->NbEdges();
484 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
486 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
487 int* nodes = data->GetEdgeNodes( iedge-1 );
494 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
496 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
497 * tag = data->GetEdgeTag( iedge-1 );
502 status_t get_triangle_count(integer * nbtri, void *user_data)
504 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
505 *nbtri = data->NbTriangles();
510 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
512 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
513 int* nodes = data->GetTriaNodes( itri-1 );
521 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
523 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
524 * tag = data->GetTriaTag( itri-1 );
529 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
530 // integer * evtri, void *user_data)
533 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
536 // /* We want to describe a linear "3 nodes" triangle */
537 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
539 // /* We want to describe a quadratic "6 nodes" triangle */
540 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
541 // for (j = 0; j < 3; j++)
542 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
548 // status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
550 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
552 // *nbtetra = 0; /* the number of tetra in your input mesh (0 if you describe a surface mesh) */
557 // status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
561 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
563 // for (j = 0; j < 4; j++)
564 // vtetra[j] = 0; /* the j'th vertex index of the itetra'th tetrahedron */
569 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
571 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
572 *rvtx = data->IsVertexRequired( ivtx - 1 );
577 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
579 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
580 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
585 status_t my_message_cb(message_t * msg, void *user_data)
588 message_get_description(msg, &desc);
590 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
591 data->AddError( desc );
594 //std::cout << desc << std::endl;
598 // corresponding messages are:
599 // " | Analyzing the surface mesh |" => 1 %
600 // " | Building and conforming the octree |" => 8 %
601 // " | Subdomains and boundary recovery |" => 15%
602 // " | Mesh bending and smoothing |" => 45%
603 // " | Final mesh statistics |" => 99%
605 double newProgress = std::min( 0.99, data->_progress + data->_msgCost );
606 if ( strlen( desc ) > 25 )
608 if ( strncmp( desc+3, "Analyzing the surface mesh", 26 ) == 0 )
609 newProgress = 0.01, data->_msgCost = ( 0.08 - 0.01 ) / 10;
610 else if ( strncmp( desc+3, "Building and conforming the octree", 34 ) == 0 )
611 newProgress = 0.08, data->_msgCost = ( 0.15 - 0.08 ) / 100;
612 else if ( strncmp( desc+3, "Subdomains and boundary recovery", 32 ) == 0 )
613 newProgress = 0.15, data->_msgCost = ( 0.45 - 0.15 ) / 20;
614 else if ( strncmp( desc+3, "Mesh bending and smoothing", 26 ) == 0 )
615 newProgress = 0.45, data->_msgCost = ( 0.99 - 0.45 ) / 65;
616 else if ( strncmp( desc+3, "Final mesh statistics", 21 ) == 0 )
619 data->_progress = std::max( data->_progress, newProgress );
624 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
626 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
627 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
635 void MG_Hexotic_API::LibData::Init()
639 // Create the meshgems working context
640 _context = context_new();
641 if ( !_context ) MG_Error( "unable to create a new context" );
643 // Set the message callback for the _context.
644 ret = context_set_message_callback( _context, my_message_cb, this );
645 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
647 // Create the structure holding the callbacks giving access to triangle mesh
648 _tria_mesh = mesh_new( _context );
649 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
651 // Set callbacks to provide triangle mesh data
652 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
653 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
654 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
655 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
656 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
657 mesh_set_get_edge_tag( _tria_mesh, get_edge_tag, this );
658 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
659 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
660 mesh_set_get_triangle_tag( _tria_mesh, get_triangle_tag, this );
662 // Create a hexa session
663 _session = hexa_session_new( _context );
664 if ( !_session ) MG_Error( "unable to create a new hexa session");
666 ret = hexa_set_interrupt_callback( _session, my_interrupt_callback, this );
667 if ( ret != STATUS_OK ) MG_Error("in hexa_set_interrupt_callback");
671 bool MG_Hexotic_API::LibData::Compute()
674 std::string errorTxt;
675 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, errorTxt ))
677 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
682 status_t ret = hexa_set_surface_mesh( _session, _tria_mesh );
683 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
686 if ( !_nodeSize.empty() )
688 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
689 (void*) &get_vertex_weight, this );
690 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
692 ret = hexa_set_sizemap( _session, _sizemap );
693 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
696 //////////////////////////////////////////////////////////////////////////////////////////
697 // const char* file = "/tmp/ghs3d_IN.mesh";
698 // mesh_write_mesh( _tria_mesh,file);
699 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
701 ret = hexa_compute_mesh( _session );
702 if ( ret != STATUS_OK ) return false;
704 ret = hexa_get_mesh( _session, &_hexa_mesh);
705 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
707 //////////////////////////////////////////////////////////////////////////////////////////
708 // file = "/tmp/ghs3d_OUT.mesh";
709 // mesh_write_mesh( _hexa_mesh,file);
710 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
715 #else // ifdef USE_MG_LIBS
717 struct MG_Hexotic_API::LibData // to avoid compiler warnings
719 volatile bool& _cancelled_flag;
721 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
724 #endif // ifdef USE_MG_LIBS
727 //================================================================================
731 //================================================================================
733 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress):
734 _isMesh(true), _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
737 _libData = new LibData( cancelled_flag, progress );
741 if ( getenv("MG_HEXA_USE_EXE"))
746 //================================================================================
750 //================================================================================
752 MG_Hexotic_API::~MG_Hexotic_API()
758 std::set<int>::iterator id = _openFiles.begin();
759 for ( ; id != _openFiles.end(); ++id )
760 ::GmfCloseMesh( *id );
764 //================================================================================
766 * \brief Return the way of MG usage
768 //================================================================================
770 bool MG_Hexotic_API::IsLibrary()
775 //================================================================================
777 * \brief Switch to usage of MG-Hexa executable
779 //================================================================================
781 void MG_Hexotic_API::SetUseExecutable()
786 //================================================================================
788 * \brief Compute the hexa mesh
789 * \param [in] cmdLine - a command to run mg_hexa.exe
790 * \return bool - Ok or not
792 //================================================================================
794 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
800 std::istringstream strm( cmdLine );
801 std::istream_iterator<std::string> sIt( strm ), sEnd;
802 std::vector< std::string > args( sIt, sEnd );
805 std::string param, value;
806 for ( size_t i = 1; i < args.size(); ++i )
808 // look for a param name; it starts from "-"
810 if ( param.size() < 2 || param[0] != '-')
812 while ( param[0] == '-')
813 param = param.substr( 1 );
816 while ( i+1 < args.size() && args[i+1][0] != '-' )
818 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
820 if ( !value.empty() ) value += " ";
823 if ( !_libData->SetParam( param, value ))
824 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
828 bool ok = _libData->Compute();
830 GetLog(); // write a log file
831 _logFile = ""; // not to write it again
836 // add MG license key
838 std::string errorTxt, meshIn;
839 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
840 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
844 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
848 const_cast< std::string& >( cmdLine ) += " --key " + key;
851 int err = system( cmdLine.c_str() ); // run
854 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
855 << strerror( errno );
861 //================================================================================
863 * \brief Prepare for reading a mesh data
865 //================================================================================
867 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
874 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
875 _openFiles.insert( id );
879 //================================================================================
881 * \brief Return nb of entities
883 //================================================================================
885 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
891 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
892 case GmfVertices: return _libData->ReadNbNodes();
893 case GmfEdges: return _libData->ReadNbEdges();
894 case GmfTriangles: return _libData->ReadNbTria();
895 case GmfQuadrilaterals: return _libData->ReadNbQuads();
896 case GmfTetrahedra: return _libData->ReadNbTetra();
897 case GmfHexahedra: return _libData->ReadNbHexa();
898 case GmfCorners: return _libData->ReadNbCorners();
904 return ::GmfStatKwd( iMesh, what );
907 //================================================================================
909 * \brief Prepare for reading some data
911 //================================================================================
913 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
917 _libData->ResetCounter();
921 ::GmfGotoKwd( iMesh, what );
924 //================================================================================
926 * \brief Return index of a domain identified by a triangle normal
927 * \param [in] iMesh - mesh file index
928 * \param [in] what - must be GmfSubDomainFromGeom
929 * \param [out] nbNodes - nb nodes in a face
930 * \param [out] faceInd - face index
931 * \param [out] ori - face orientation
932 * \param [out] domain - domain index
933 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
936 //================================================================================
938 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
942 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
946 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
949 //================================================================================
951 * \brief Return coordinates of a next node
953 //================================================================================
955 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
956 double* x, double* y, double *z, int* domain )
960 _libData->ReadNodeXYZ( x, y, z, domain );
964 ::GmfGetLin(iMesh, what, x, y, z, domain );
967 //================================================================================
969 * \brief Return coordinates of a next node
971 //================================================================================
973 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
974 float* x, float* y, float *z, int* domain )
979 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
986 ::GmfGetLin(iMesh, what, x, y, z, domain );
989 //================================================================================
991 * \brief Return node index of a next corner
993 //================================================================================
995 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
999 _libData->ReadCorner( node );
1003 ::GmfGetLin(iMesh, what, node );
1006 //================================================================================
1008 * \brief Return node indices of a next edge
1010 //================================================================================
1012 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1016 _libData->ReadEdgeNodes( node1, node2, domain );
1020 ::GmfGetLin( iMesh, what, node1, node2, domain );
1023 //================================================================================
1025 * \brief Return node indices of a next triangle
1027 //================================================================================
1029 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1030 int* node1, int* node2, int* node3, int* domain )
1034 _libData->ReadTriaNodes( node1, node2, node3, domain );
1038 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1041 //================================================================================
1043 * \brief Return node indices of a next tetrahedron or quadrangle
1045 //================================================================================
1047 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1048 int* node1, int* node2, int* node3, int* node4, int* domain )
1052 if ( what == GmfQuadrilaterals )
1053 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1055 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1059 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1062 //================================================================================
1064 * \brief Return node indices of a next hexahedron
1066 //================================================================================
1068 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1069 int* node1, int* node2, int* node3, int* node4,
1070 int* node5, int* node6, int* node7, int* node8,
1075 _libData->ReadHexaNodes( node1, node2, node3, node4,
1076 node5, node6, node7, node8, domain );
1080 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1083 //================================================================================
1085 * \brief Prepare for passing data to MeshGems
1087 //================================================================================
1089 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1096 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1097 _openFiles.insert( id );
1101 //================================================================================
1103 * \brief Set number of entities
1105 //================================================================================
1107 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1109 if ( iMesh == 1 && _isMesh )
1112 case GmfVertices: _nbNodes += nb; break;
1113 case GmfEdges: _nbEdges += nb; break;
1114 case GmfTriangles: _nbFaces += nb; break;
1122 case GmfVertices: _libData->SetNbVertices( nb ); break;
1123 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1124 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1125 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1126 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1132 ::GmfSetKwd(iMesh, what, nb );
1135 //================================================================================
1137 * \brief Set GMF file made by MG-CADSurf to get nb of mesh entities from it
1139 //================================================================================
1141 void MG_Hexotic_API::SetInputFile( const std::string mesh2DFile )
1143 DriverGMF_Read fileReader;
1144 fileReader.SetFile( mesh2DFile );
1146 smIdType nbVertex, nbEdge, nbFace, nbVol;
1147 if ( fileReader.GetMeshInfo(nbVertex, nbEdge, nbFace, nbVol))
1149 _nbNodes += nbVertex;
1155 //================================================================================
1157 * \brief Add coordinates of a node
1159 //================================================================================
1161 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1165 _libData->AddNode( x, y, z, domain );
1169 ::GmfSetLin(iMesh, what, x, y, z, domain);
1172 //================================================================================
1174 * \brief Set number of field entities
1175 * \param [in] iMesh - solution file index
1176 * \param [in] what - solution type
1177 * \param [in] nbNodes - nb of entities
1178 * \param [in] nbTypes - nb of data entries in each entity
1179 * \param [in] type - types of the data entries
1181 * Used to prepare to storing size at nodes
1183 //================================================================================
1185 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1189 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1193 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1196 //================================================================================
1198 * \brief Add solution data
1200 //================================================================================
1202 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1206 _libData->AddSizeAtNode( vals[0] );
1210 ::GmfSetLin(iMesh, what, vals);
1213 //================================================================================
1215 * \brief Add edge nodes
1217 //================================================================================
1219 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1223 _libData->AddEdgeNodes( node1, node2, domain );
1227 ::GmfSetLin(iMesh, what, node1, node2, domain );
1230 //================================================================================
1232 * \brief Add a 'required' flag
1234 //================================================================================
1236 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1243 ::GmfSetLin(iMesh, what, id );
1246 //================================================================================
1248 * \brief Add triangle nodes
1250 //================================================================================
1252 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1256 _libData->AddTriaNodes( node1, node2, node3, domain );
1260 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1263 //================================================================================
1265 * \brief Close a file
1267 //================================================================================
1269 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1279 ::GmfCloseMesh( iMesh );
1280 _openFiles.erase( iMesh );
1283 //================================================================================
1285 * \brief Return true if the log is not empty
1287 //================================================================================
1289 bool MG_Hexotic_API::HasLog()
1293 return !_libData->GetErrors().empty();
1296 SMESH_File file( _logFile );
1297 return file.size() > 0;
1300 //================================================================================
1302 * \brief Return log contents
1304 //================================================================================
1306 std::string MG_Hexotic_API::GetLog()
1310 const std::string& err = _libData->GetErrors();
1311 if ( !_logFile.empty() && !err.empty() )
1313 SMESH_File file( _logFile, /*openForReading=*/false );
1314 file.openForWriting();
1315 file.write( err.c_str(), err.size() );
1320 SMESH_File file( _logFile );
1321 return file.exists() ? file.getPos() : "";