1 // Copyright (C) 2004-2016 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"
22 #include <SMESH_Comment.hxx>
23 #include <SMESH_File.hxx>
24 #include <Utils_SALOME_Exception.hxx>
33 #include <meshgems/meshgems.h>
34 #include <meshgems/hexa.h>
37 struct MG_Hexotic_API::LibData
41 hexa_session_t * _session;
47 std::vector<double> _xyz;
48 std::vector<double> _nodeSize; // required nodes
49 std::vector<int> _edgeNodesTags;
51 std::vector<int> _triaNodesTags;
54 std::vector<int> _corners;
57 volatile bool& _cancelled_flag;
58 std::string _errorStr;
62 LibData( volatile bool & cancelled_flag, double& progress )
63 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _hexa_mesh(0),
64 _nbRequiredEdges(0), _nbRequiredTria(0),
65 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
68 // methods setting callbacks implemented after callback definitions
75 hexa_regain_mesh( _session, _hexa_mesh );
77 mesh_delete( _tria_mesh );
79 sizemap_delete( _sizemap );
81 hexa_session_delete( _session );
83 context_delete( _context );
92 void AddError( const char *txt )
100 const std::string& GetErrors()
105 void MG_Error(const char* txt="")
107 SMESH_Comment msg("\nMeshGems error. ");
109 AddError( msg.c_str() );
112 bool SetParam( const std::string& param, const std::string& value )
114 status_t ret = hexa_set_param( _session, param.c_str(), value.c_str() );
116 //std::cout << param << " = " << value << std::endl;
118 return ( ret == STATUS_OK );
123 return _cancelled_flag;
126 int ReadNbSubDomains()
129 status_t ret = mesh_get_subdomain_count( _hexa_mesh, & nb );
131 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
140 status_t ret = mesh_get_vertex_count( _hexa_mesh, & nb );
142 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
149 status_t ret = mesh_get_edge_count( _hexa_mesh, & nb );
151 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
158 status_t ret = mesh_get_triangle_count( _hexa_mesh, & nb );
160 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
167 status_t ret = mesh_get_quadrangle_count( _hexa_mesh, & nb );
169 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
176 status_t ret = mesh_get_tetrahedron_count( _hexa_mesh, & nb );
178 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
185 status_t ret = mesh_get_hexahedron_count( _hexa_mesh, & nb );
187 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
193 return _corners.size();
201 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
203 integer tag, seed_type, seed_idx, seed_orientation;
204 status_t ret = mesh_get_subdomain_description( _hexa_mesh, _count,
205 &tag, &seed_type, &seed_idx, &seed_orientation);
207 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
212 *ori = seed_orientation;
216 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
219 status_t ret = mesh_get_vertex_coordinates( _hexa_mesh, _count, coo );
220 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
226 integer isCorner = 0;
227 ret = mesh_get_vertex_corner_property( _hexa_mesh, _count, &isCorner);
228 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
230 _corners.push_back( _count );
235 void ReadEdgeNodes( int* node1, int* node2, int* domain )
238 status_t ret = mesh_get_edge_vertices( _hexa_mesh, _count, vtx);
239 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
244 ret = mesh_get_edge_tag( _hexa_mesh, _count, &tag );
245 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
252 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
255 status_t ret = mesh_get_triangle_vertices( _hexa_mesh, _count, vtx);
256 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
262 ret = mesh_get_triangle_tag( _hexa_mesh, _count, &tag );
263 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
270 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
273 status_t ret = mesh_get_quadrangle_vertices( _hexa_mesh, _count, vtx);
274 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
281 ret = mesh_get_quadrangle_tag( _hexa_mesh, _count, &tag );
282 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
289 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
292 status_t ret = mesh_get_tetrahedron_vertices( _hexa_mesh, _count, vtx);
293 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
300 ret = mesh_get_tetrahedron_tag( _hexa_mesh, _count, &tag );
301 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
308 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
309 int* node5, int* node6, int* node7, int* node8, int* domain )
312 status_t ret = mesh_get_hexahedron_vertices( _hexa_mesh, _count, vtx);
313 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
324 ret = mesh_get_hexahedron_tag( _hexa_mesh, _count, &tag );
325 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
332 void ReadCorner( int* node )
334 if ( _count <= ReadNbCorners() )
335 *node = _corners[ _count - 1 ];
342 void SetNbVertices( int nb )
344 _xyz.reserve( _xyz.capacity() + nb );
347 void SetNbEdges( int nb )
349 _edgeNodesTags.reserve( nb * 3 );
352 void SetNbTria( int nb )
354 _triaNodesTags.reserve( nb * 4 );
357 void SetNbReqVertices( int nb )
359 _nodeSize.reserve( nb );
362 void SetNbReqEdges( int nb )
364 _nbRequiredEdges = nb;
367 void SetNbReqTria( int nb )
369 _nbRequiredTria = nb;
372 void AddNode( double x, double y, double z, int domain )
379 void AddSizeAtNode( double size )
381 _nodeSize.push_back( size );
384 void AddEdgeNodes( int node1, int node2, int domain )
386 _edgeNodesTags.push_back( node1 );
387 _edgeNodesTags.push_back( node2 );
388 _edgeNodesTags.push_back( domain );
391 void AddTriaNodes( int node1, int node2, int node3, int domain )
393 _triaNodesTags.push_back( node1 );
394 _triaNodesTags.push_back( node2 );
395 _triaNodesTags.push_back( node3 );
396 _triaNodesTags.push_back( domain );
401 return _xyz.size() / 3;
404 double* NodeCoord( int iNode )
406 return & _xyz[ iNode * 3 ];
411 return _edgeNodesTags.size() / 3;
414 int* GetEdgeNodes( int iEdge )
416 return & _edgeNodesTags[ iEdge * 3 ];
419 int GetEdgeTag( int iEdge )
421 return _edgeNodesTags[ iEdge * 3 + 2 ];
426 return _triaNodesTags.size() / 4;
429 int * GetTriaNodes( int iTria )
431 return & _triaNodesTags[ iTria * 4 ];
434 int GetTriaTag( int iTria )
436 return _triaNodesTags[ iTria * 4 + 3 ];
439 int IsVertexRequired( int iNode )
441 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
444 double GetSizeAtVertex( int iNode )
446 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
450 namespace // functions called by MG library to exchange with the application
452 status_t get_vertex_count(integer * nbvtx, void *user_data)
454 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
455 *nbvtx = data->NbNodes();
460 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
462 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
463 double* coord = data->NodeCoord( ivtx-1 );
464 for (int j = 0; j < 3; j++)
469 status_t get_edge_count(integer * nbedge, void *user_data)
471 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
472 *nbedge = data->NbEdges();
477 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
479 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
480 int* nodes = data->GetEdgeNodes( iedge-1 );
487 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
489 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
490 * tag = data->GetEdgeTag( iedge-1 );
495 status_t get_triangle_count(integer * nbtri, void *user_data)
497 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
498 *nbtri = data->NbTriangles();
503 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
505 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
506 int* nodes = data->GetTriaNodes( itri-1 );
514 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
516 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
517 * tag = data->GetTriaTag( itri-1 );
522 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
523 // integer * evtri, void *user_data)
526 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
529 // /* We want to describe a linear "3 nodes" triangle */
530 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
532 // /* We want to describe a quadratic "6 nodes" triangle */
533 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
534 // for (j = 0; j < 3; j++)
535 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
541 // status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
543 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
545 // *nbtetra = 0; /* the number of tetra in your input mesh (0 if you describe a surface mesh) */
550 // status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
554 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
556 // for (j = 0; j < 4; j++)
557 // vtetra[j] = 0; /* the j'th vertex index of the itetra'th tetrahedron */
562 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
564 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
565 *rvtx = data->IsVertexRequired( ivtx - 1 );
570 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
572 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
573 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
578 status_t my_message_cb(message_t * msg, void *user_data)
581 message_get_description(msg, &desc);
583 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
584 data->AddError( desc );
587 //std::cout << desc << std::endl;
591 // corresponding messages are:
592 // " | Analyzing the surface mesh |" => 1 %
593 // " | Building and conforming the octree |" => 8 %
594 // " | Subdomains and boundary recovery |" => 15%
595 // " | Mesh bending and smoothing |" => 45%
596 // " | Final mesh statistics |" => 99%
598 double newProgress = std::min( 0.99, data->_progress + data->_msgCost );
599 if ( strlen( desc ) > 25 )
601 if ( strncmp( desc+3, "Analyzing the surface mesh", 26 ) == 0 )
602 newProgress = 0.01, data->_msgCost = ( 0.08 - 0.01 ) / 10;
603 else if ( strncmp( desc+3, "Building and conforming the octree", 34 ) == 0 )
604 newProgress = 0.08, data->_msgCost = ( 0.15 - 0.08 ) / 100;
605 else if ( strncmp( desc+3, "Subdomains and boundary recovery", 32 ) == 0 )
606 newProgress = 0.15, data->_msgCost = ( 0.45 - 0.15 ) / 20;
607 else if ( strncmp( desc+3, "Mesh bending and smoothing", 26 ) == 0 )
608 newProgress = 0.45, data->_msgCost = ( 0.99 - 0.45 ) / 65;
609 else if ( strncmp( desc+3, "Final mesh statistics", 21 ) == 0 )
612 data->_progress = std::max( data->_progress, newProgress );
617 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
619 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
620 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
628 void MG_Hexotic_API::LibData::Init()
632 // Create the meshgems working context
633 _context = context_new();
634 if ( !_context ) MG_Error( "unable to create a new context" );
636 // Set the message callback for the _context.
637 ret = context_set_message_callback( _context, my_message_cb, this );
638 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
640 // Create the structure holding the callbacks giving access to triangle mesh
641 _tria_mesh = mesh_new( _context );
642 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
644 // Set callbacks to provide triangle mesh data
645 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
646 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
647 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
648 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
649 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
650 mesh_set_get_edge_tag( _tria_mesh, get_edge_tag, this );
651 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
652 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
653 mesh_set_get_triangle_tag( _tria_mesh, get_triangle_tag, this );
655 // Create a hexa session
656 _session = hexa_session_new( _context );
657 if ( !_session ) MG_Error( "unable to create a new hexa session");
659 ret = hexa_set_interrupt_callback( _session, my_interrupt_callback, this );
660 if ( ret != STATUS_OK ) MG_Error("in hexa_set_interrupt_callback");
664 bool MG_Hexotic_API::LibData::Compute()
667 status_t ret = hexa_set_surface_mesh( _session, _tria_mesh );
668 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
671 if ( !_nodeSize.empty() )
673 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
674 (void*) &get_vertex_weight, this );
675 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
677 ret = hexa_set_sizemap( _session, _sizemap );
678 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
681 //////////////////////////////////////////////////////////////////////////////////////////
682 // const char* file = "/tmp/ghs3d_IN.mesh";
683 // mesh_write_mesh( _tria_mesh,file);
684 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
686 ret = hexa_compute_mesh( _session );
687 if ( ret != STATUS_OK ) return false;
689 ret = hexa_get_mesh( _session, &_hexa_mesh);
690 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
692 //////////////////////////////////////////////////////////////////////////////////////////
693 // file = "/tmp/ghs3d_OUT.mesh";
694 // mesh_write_mesh( _hexa_mesh,file);
695 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
701 #endif // ifdef USE_MG_LIBS
704 //================================================================================
708 //================================================================================
710 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress)
714 _libData = new LibData( cancelled_flag, progress );
717 if ( getenv("MG_HEXA_USE_EXE"))
721 //================================================================================
725 //================================================================================
727 MG_Hexotic_API::~MG_Hexotic_API()
733 std::set<int>::iterator id = _openFiles.begin();
734 for ( ; id != _openFiles.end(); ++id )
735 ::GmfCloseMesh( *id );
739 //================================================================================
741 * \brief Return the way of MG usage
743 //================================================================================
745 bool MG_Hexotic_API::IsLibrary()
750 //================================================================================
752 * \brief Switch to usage of MG-Hexa executable
754 //================================================================================
756 void MG_Hexotic_API::SetUseExecutable()
761 //================================================================================
763 * \brief Compute the hexa mesh
764 * \param [in] cmdLine - a command to run mg_hexa.exe
765 * \return bool - Ok or not
767 //================================================================================
769 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
775 std::istringstream strm( cmdLine );
776 std::istream_iterator<std::string> sIt( strm ), sEnd;
777 std::vector< std::string > args( sIt, sEnd );
780 std::string param, value;
781 for ( size_t i = 1; i < args.size(); ++i )
783 // look for a param name; it starts from "-"
785 if ( param.size() < 2 || param[0] != '-')
787 while ( param[0] == '-')
788 param = param.substr( 1 );
791 while ( i+1 < args.size() && args[i+1][0] != '-' )
793 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
795 if ( !value.empty() ) value += " ";
798 if ( !_libData->SetParam( param, value ))
799 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
803 bool ok = _libData->Compute();
805 GetLog(); // write a log file
806 _logFile = ""; // not to write it again
812 int err = system( cmdLine.c_str() ); // run
815 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
816 << strerror( errno );
822 //================================================================================
824 * \brief Prepare for reading a mesh data
826 //================================================================================
828 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
835 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
836 _openFiles.insert( id );
840 //================================================================================
842 * \brief Return nb of entities
844 //================================================================================
846 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
852 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
853 case GmfVertices: return _libData->ReadNbNodes();
854 case GmfEdges: return _libData->ReadNbEdges();
855 case GmfTriangles: return _libData->ReadNbTria();
856 case GmfQuadrilaterals: return _libData->ReadNbQuads();
857 case GmfTetrahedra: return _libData->ReadNbTetra();
858 case GmfHexahedra: return _libData->ReadNbHexa();
859 case GmfCorners: return _libData->ReadNbCorners();
865 return ::GmfStatKwd( iMesh, what );
868 //================================================================================
870 * \brief Prepare for reading some data
872 //================================================================================
874 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
878 _libData->ResetCounter();
882 ::GmfGotoKwd( iMesh, what );
885 //================================================================================
887 * \brief Return index of a domain identified by a triangle normal
888 * \param [in] iMesh - mesh file index
889 * \param [in] what - must be GmfSubDomainFromGeom
890 * \param [out] nbNodes - nb nodes in a face
891 * \param [out] faceInd - face index
892 * \param [out] ori - face orientation
893 * \param [out] domain - domain index
894 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
897 //================================================================================
899 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
903 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
907 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
910 //================================================================================
912 * \brief Return coordinates of a next node
914 //================================================================================
916 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
917 double* x, double* y, double *z, int* domain )
921 _libData->ReadNodeXYZ( x, y, z, domain );
925 ::GmfGetLin(iMesh, what, x, y, z, domain );
928 //================================================================================
930 * \brief Return coordinates of a next node
932 //================================================================================
934 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
935 float* x, float* y, float *z, int* domain )
940 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
947 ::GmfGetLin(iMesh, what, x, y, z, domain );
950 //================================================================================
952 * \brief Return node index of a next corner
954 //================================================================================
956 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
960 _libData->ReadCorner( node );
964 ::GmfGetLin(iMesh, what, node );
967 //================================================================================
969 * \brief Return node indices of a next edge
971 //================================================================================
973 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
977 _libData->ReadEdgeNodes( node1, node2, domain );
981 ::GmfGetLin( iMesh, what, node1, node2, domain );
984 //================================================================================
986 * \brief Return node indices of a next triangle
988 //================================================================================
990 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
991 int* node1, int* node2, int* node3, int* domain )
995 _libData->ReadTriaNodes( node1, node2, node3, domain );
999 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1002 //================================================================================
1004 * \brief Return node indices of a next tetrahedron or quadrangle
1006 //================================================================================
1008 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1009 int* node1, int* node2, int* node3, int* node4, int* domain )
1013 if ( what == GmfQuadrilaterals )
1014 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1016 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1020 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1023 //================================================================================
1025 * \brief Return node indices of a next hexahedron
1027 //================================================================================
1029 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1030 int* node1, int* node2, int* node3, int* node4,
1031 int* node5, int* node6, int* node7, int* node8,
1036 _libData->ReadHexaNodes( node1, node2, node3, node4,
1037 node5, node6, node7, node8, domain );
1041 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1044 //================================================================================
1046 * \brief Prepare for passing data to MeshGems
1048 //================================================================================
1050 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1057 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1058 _openFiles.insert( id );
1062 //================================================================================
1064 * \brief Set number of entities
1066 //================================================================================
1068 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1073 case GmfVertices: _libData->SetNbVertices( nb ); break;
1074 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1075 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1076 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1077 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1083 ::GmfSetKwd(iMesh, what, nb );
1086 //================================================================================
1088 * \brief Add coordinates of a node
1090 //================================================================================
1092 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1096 _libData->AddNode( x, y, z, domain );
1100 ::GmfSetLin(iMesh, what, x, y, z, domain);
1103 //================================================================================
1105 * \brief Set number of field entities
1106 * \param [in] iMesh - solution file index
1107 * \param [in] what - solution type
1108 * \param [in] nbNodes - nb of entities
1109 * \param [in] nbTypes - nb of data entries in each entity
1110 * \param [in] type - types of the data entries
1112 * Used to prepare to storing size at nodes
1114 //================================================================================
1116 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1120 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1124 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1127 //================================================================================
1129 * \brief Add solution data
1131 //================================================================================
1133 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1137 _libData->AddSizeAtNode( vals[0] );
1141 ::GmfSetLin(iMesh, what, vals);
1144 //================================================================================
1146 * \brief Add edge nodes
1148 //================================================================================
1150 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1154 _libData->AddEdgeNodes( node1, node2, domain );
1158 ::GmfSetLin(iMesh, what, node1, node2, domain );
1161 //================================================================================
1163 * \brief Add a 'required' flag
1165 //================================================================================
1167 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1174 ::GmfSetLin(iMesh, what, id );
1177 //================================================================================
1179 * \brief Add triangle nodes
1181 //================================================================================
1183 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1187 _libData->AddTriaNodes( node1, node2, node3, domain );
1191 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1194 //================================================================================
1196 * \brief Close a file
1198 //================================================================================
1200 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1207 ::GmfCloseMesh( iMesh );
1208 _openFiles.erase( iMesh );
1211 //================================================================================
1213 * \brief Return true if the log is not empty
1215 //================================================================================
1217 bool MG_Hexotic_API::HasLog()
1221 return !_libData->GetErrors().empty();
1224 SMESH_File file( _logFile );
1225 return file.size() > 0;
1228 //================================================================================
1230 * \brief Return log contents
1232 //================================================================================
1234 std::string MG_Hexotic_API::GetLog()
1238 const std::string& err = _libData->GetErrors();
1239 if ( !_logFile.empty() && !err.empty() )
1241 SMESH_File file( _logFile, /*openForReading=*/false );
1242 file.openForWriting();
1243 file.write( err.c_str(), err.size() );
1248 SMESH_File file( _logFile );
1249 return file.getPos();