1 // Copyright (C) 2004-2019 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 <SMESH_Comment.hxx>
27 #include <SMESH_File.hxx>
28 #include <Utils_SALOME_Exception.hxx>
37 #include <meshgems/meshgems.h>
38 #include <meshgems/hexa.h>
41 struct MG_Hexotic_API::LibData
45 hexa_session_t * _session;
51 std::vector<double> _xyz;
52 std::vector<double> _nodeSize; // required nodes
53 std::vector<int> _edgeNodesTags;
55 std::vector<int> _triaNodesTags;
58 std::vector<int> _corners;
61 volatile bool& _cancelled_flag;
62 std::string _errorStr;
66 LibData( volatile bool & cancelled_flag, double& progress )
67 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _hexa_mesh(0),
68 _nbRequiredEdges(0), _nbRequiredTria(0),
69 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
72 // methods setting callbacks implemented after callback definitions
79 hexa_regain_mesh( _session, _hexa_mesh );
81 mesh_delete( _tria_mesh );
83 sizemap_delete( _sizemap );
85 hexa_session_delete( _session );
87 context_delete( _context );
96 void AddError( const char *txt )
104 const std::string& GetErrors()
109 void MG_Error(const char* txt="")
111 SMESH_Comment msg("\nMeshGems error. ");
113 AddError( msg.c_str() );
116 bool SetParam( const std::string& param, const std::string& value )
118 status_t ret = hexa_set_param( _session, param.c_str(), value.c_str() );
120 //std::cout << param << " = " << value << std::endl;
122 return ( ret == STATUS_OK );
127 return _cancelled_flag;
130 int ReadNbSubDomains()
133 status_t ret = mesh_get_subdomain_count( _hexa_mesh, & nb );
135 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
144 status_t ret = mesh_get_vertex_count( _hexa_mesh, & nb );
146 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
153 status_t ret = mesh_get_edge_count( _hexa_mesh, & nb );
155 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
162 status_t ret = mesh_get_triangle_count( _hexa_mesh, & nb );
164 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
171 status_t ret = mesh_get_quadrangle_count( _hexa_mesh, & nb );
173 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
180 status_t ret = mesh_get_tetrahedron_count( _hexa_mesh, & nb );
182 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
189 status_t ret = mesh_get_hexahedron_count( _hexa_mesh, & nb );
191 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
197 return _corners.size();
205 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
207 integer tag, seed_type, seed_idx, seed_orientation;
208 status_t ret = mesh_get_subdomain_description( _hexa_mesh, _count,
209 &tag, &seed_type, &seed_idx, &seed_orientation);
211 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
216 *ori = seed_orientation;
220 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
223 status_t ret = mesh_get_vertex_coordinates( _hexa_mesh, _count, coo );
224 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
230 integer isCorner = 0;
231 ret = mesh_get_vertex_corner_property( _hexa_mesh, _count, &isCorner);
232 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
234 _corners.push_back( _count );
239 void ReadEdgeNodes( int* node1, int* node2, int* domain )
242 status_t ret = mesh_get_edge_vertices( _hexa_mesh, _count, vtx);
243 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
248 ret = mesh_get_edge_tag( _hexa_mesh, _count, &tag );
249 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
256 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
259 status_t ret = mesh_get_triangle_vertices( _hexa_mesh, _count, vtx);
260 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
266 ret = mesh_get_triangle_tag( _hexa_mesh, _count, &tag );
267 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
274 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
277 status_t ret = mesh_get_quadrangle_vertices( _hexa_mesh, _count, vtx);
278 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
285 ret = mesh_get_quadrangle_tag( _hexa_mesh, _count, &tag );
286 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
293 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
296 status_t ret = mesh_get_tetrahedron_vertices( _hexa_mesh, _count, vtx);
297 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
304 ret = mesh_get_tetrahedron_tag( _hexa_mesh, _count, &tag );
305 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
312 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
313 int* node5, int* node6, int* node7, int* node8, int* domain )
316 status_t ret = mesh_get_hexahedron_vertices( _hexa_mesh, _count, vtx);
317 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
328 ret = mesh_get_hexahedron_tag( _hexa_mesh, _count, &tag );
329 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
336 void ReadCorner( int* node )
338 if ( _count <= ReadNbCorners() )
339 *node = _corners[ _count - 1 ];
346 void SetNbVertices( int nb )
348 _xyz.reserve( _xyz.capacity() + nb );
351 void SetNbEdges( int nb )
353 _edgeNodesTags.reserve( nb * 3 );
356 void SetNbTria( int nb )
358 _triaNodesTags.reserve( nb * 4 );
361 void SetNbReqVertices( int nb )
363 _nodeSize.reserve( nb );
366 void SetNbReqEdges( int nb )
368 _nbRequiredEdges = nb;
371 void SetNbReqTria( int nb )
373 _nbRequiredTria = nb;
376 void AddNode( double x, double y, double z, int domain )
383 void AddSizeAtNode( double size )
385 _nodeSize.push_back( size );
388 void AddEdgeNodes( int node1, int node2, int domain )
390 _edgeNodesTags.push_back( node1 );
391 _edgeNodesTags.push_back( node2 );
392 _edgeNodesTags.push_back( domain );
395 void AddTriaNodes( int node1, int node2, int node3, int domain )
397 _triaNodesTags.push_back( node1 );
398 _triaNodesTags.push_back( node2 );
399 _triaNodesTags.push_back( node3 );
400 _triaNodesTags.push_back( domain );
405 return _xyz.size() / 3;
408 double* NodeCoord( int iNode )
410 return & _xyz[ iNode * 3 ];
415 return _edgeNodesTags.size() / 3;
418 int* GetEdgeNodes( int iEdge )
420 return & _edgeNodesTags[ iEdge * 3 ];
423 int GetEdgeTag( int iEdge )
425 return _edgeNodesTags[ iEdge * 3 + 2 ];
430 return _triaNodesTags.size() / 4;
433 int * GetTriaNodes( int iTria )
435 return & _triaNodesTags[ iTria * 4 ];
438 int GetTriaTag( int iTria )
440 return _triaNodesTags[ iTria * 4 + 3 ];
443 int IsVertexRequired( int iNode )
445 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
448 double GetSizeAtVertex( int iNode )
450 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
454 namespace // functions called by MG library to exchange with the application
456 status_t get_vertex_count(integer * nbvtx, void *user_data)
458 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
459 *nbvtx = data->NbNodes();
464 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
466 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
467 double* coord = data->NodeCoord( ivtx-1 );
468 for (int j = 0; j < 3; j++)
473 status_t get_edge_count(integer * nbedge, void *user_data)
475 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
476 *nbedge = data->NbEdges();
481 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
483 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
484 int* nodes = data->GetEdgeNodes( iedge-1 );
491 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
493 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
494 * tag = data->GetEdgeTag( iedge-1 );
499 status_t get_triangle_count(integer * nbtri, void *user_data)
501 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
502 *nbtri = data->NbTriangles();
507 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
509 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
510 int* nodes = data->GetTriaNodes( itri-1 );
518 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
520 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
521 * tag = data->GetTriaTag( itri-1 );
526 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
527 // integer * evtri, void *user_data)
530 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
533 // /* We want to describe a linear "3 nodes" triangle */
534 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
536 // /* We want to describe a quadratic "6 nodes" triangle */
537 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
538 // for (j = 0; j < 3; j++)
539 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
545 // status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
547 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
549 // *nbtetra = 0; /* the number of tetra in your input mesh (0 if you describe a surface mesh) */
554 // status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
558 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
560 // for (j = 0; j < 4; j++)
561 // vtetra[j] = 0; /* the j'th vertex index of the itetra'th tetrahedron */
566 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
568 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
569 *rvtx = data->IsVertexRequired( ivtx - 1 );
574 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
576 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
577 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
582 status_t my_message_cb(message_t * msg, void *user_data)
585 message_get_description(msg, &desc);
587 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
588 data->AddError( desc );
591 //std::cout << desc << std::endl;
595 // corresponding messages are:
596 // " | Analyzing the surface mesh |" => 1 %
597 // " | Building and conforming the octree |" => 8 %
598 // " | Subdomains and boundary recovery |" => 15%
599 // " | Mesh bending and smoothing |" => 45%
600 // " | Final mesh statistics |" => 99%
602 double newProgress = std::min( 0.99, data->_progress + data->_msgCost );
603 if ( strlen( desc ) > 25 )
605 if ( strncmp( desc+3, "Analyzing the surface mesh", 26 ) == 0 )
606 newProgress = 0.01, data->_msgCost = ( 0.08 - 0.01 ) / 10;
607 else if ( strncmp( desc+3, "Building and conforming the octree", 34 ) == 0 )
608 newProgress = 0.08, data->_msgCost = ( 0.15 - 0.08 ) / 100;
609 else if ( strncmp( desc+3, "Subdomains and boundary recovery", 32 ) == 0 )
610 newProgress = 0.15, data->_msgCost = ( 0.45 - 0.15 ) / 20;
611 else if ( strncmp( desc+3, "Mesh bending and smoothing", 26 ) == 0 )
612 newProgress = 0.45, data->_msgCost = ( 0.99 - 0.45 ) / 65;
613 else if ( strncmp( desc+3, "Final mesh statistics", 21 ) == 0 )
616 data->_progress = std::max( data->_progress, newProgress );
621 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
623 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
624 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
632 void MG_Hexotic_API::LibData::Init()
636 // Create the meshgems working context
637 _context = context_new();
638 if ( !_context ) MG_Error( "unable to create a new context" );
640 // Set the message callback for the _context.
641 ret = context_set_message_callback( _context, my_message_cb, this );
642 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
644 // Create the structure holding the callbacks giving access to triangle mesh
645 _tria_mesh = mesh_new( _context );
646 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
648 // Set callbacks to provide triangle mesh data
649 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
650 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
651 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
652 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
653 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
654 mesh_set_get_edge_tag( _tria_mesh, get_edge_tag, this );
655 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
656 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
657 mesh_set_get_triangle_tag( _tria_mesh, get_triangle_tag, this );
659 // Create a hexa session
660 _session = hexa_session_new( _context );
661 if ( !_session ) MG_Error( "unable to create a new hexa session");
663 ret = hexa_set_interrupt_callback( _session, my_interrupt_callback, this );
664 if ( ret != STATUS_OK ) MG_Error("in hexa_set_interrupt_callback");
668 bool MG_Hexotic_API::LibData::Compute()
671 status_t ret = hexa_set_surface_mesh( _session, _tria_mesh );
672 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
675 if ( !_nodeSize.empty() )
677 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
678 (void*) &get_vertex_weight, this );
679 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
681 ret = hexa_set_sizemap( _session, _sizemap );
682 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
685 //////////////////////////////////////////////////////////////////////////////////////////
686 // const char* file = "/tmp/ghs3d_IN.mesh";
687 // mesh_write_mesh( _tria_mesh,file);
688 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
690 ret = hexa_compute_mesh( _session );
691 if ( ret != STATUS_OK ) return false;
693 ret = hexa_get_mesh( _session, &_hexa_mesh);
694 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
696 //////////////////////////////////////////////////////////////////////////////////////////
697 // file = "/tmp/ghs3d_OUT.mesh";
698 // mesh_write_mesh( _hexa_mesh,file);
699 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
705 #endif // ifdef USE_MG_LIBS
708 //================================================================================
712 //================================================================================
714 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress)
719 _libData = new LibData( cancelled_flag, progress );
721 if ( getenv("MG_HEXA_USE_EXE"))
726 //================================================================================
730 //================================================================================
732 MG_Hexotic_API::~MG_Hexotic_API()
738 std::set<int>::iterator id = _openFiles.begin();
739 for ( ; id != _openFiles.end(); ++id )
740 ::GmfCloseMesh( *id );
744 //================================================================================
746 * \brief Return the way of MG usage
748 //================================================================================
750 bool MG_Hexotic_API::IsLibrary()
755 //================================================================================
757 * \brief Switch to usage of MG-Hexa executable
759 //================================================================================
761 void MG_Hexotic_API::SetUseExecutable()
766 //================================================================================
768 * \brief Compute the hexa mesh
769 * \param [in] cmdLine - a command to run mg_hexa.exe
770 * \return bool - Ok or not
772 //================================================================================
774 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
780 std::istringstream strm( cmdLine );
781 std::istream_iterator<std::string> sIt( strm ), sEnd;
782 std::vector< std::string > args( sIt, sEnd );
785 std::string param, value;
786 for ( size_t i = 1; i < args.size(); ++i )
788 // look for a param name; it starts from "-"
790 if ( param.size() < 2 || param[0] != '-')
792 while ( param[0] == '-')
793 param = param.substr( 1 );
796 while ( i+1 < args.size() && args[i+1][0] != '-' )
798 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
800 if ( !value.empty() ) value += " ";
803 if ( !_libData->SetParam( param, value ))
804 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
808 bool ok = _libData->Compute();
810 GetLog(); // write a log file
811 _logFile = ""; // not to write it again
817 int err = system( cmdLine.c_str() ); // run
820 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
821 << strerror( errno );
827 //================================================================================
829 * \brief Prepare for reading a mesh data
831 //================================================================================
833 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
840 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
841 _openFiles.insert( id );
845 //================================================================================
847 * \brief Return nb of entities
849 //================================================================================
851 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
857 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
858 case GmfVertices: return _libData->ReadNbNodes();
859 case GmfEdges: return _libData->ReadNbEdges();
860 case GmfTriangles: return _libData->ReadNbTria();
861 case GmfQuadrilaterals: return _libData->ReadNbQuads();
862 case GmfTetrahedra: return _libData->ReadNbTetra();
863 case GmfHexahedra: return _libData->ReadNbHexa();
864 case GmfCorners: return _libData->ReadNbCorners();
870 return ::GmfStatKwd( iMesh, what );
873 //================================================================================
875 * \brief Prepare for reading some data
877 //================================================================================
879 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
883 _libData->ResetCounter();
887 ::GmfGotoKwd( iMesh, what );
890 //================================================================================
892 * \brief Return index of a domain identified by a triangle normal
893 * \param [in] iMesh - mesh file index
894 * \param [in] what - must be GmfSubDomainFromGeom
895 * \param [out] nbNodes - nb nodes in a face
896 * \param [out] faceInd - face index
897 * \param [out] ori - face orientation
898 * \param [out] domain - domain index
899 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
902 //================================================================================
904 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
908 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
912 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
915 //================================================================================
917 * \brief Return coordinates of a next node
919 //================================================================================
921 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
922 double* x, double* y, double *z, int* domain )
926 _libData->ReadNodeXYZ( x, y, z, domain );
930 ::GmfGetLin(iMesh, what, x, y, z, domain );
933 //================================================================================
935 * \brief Return coordinates of a next node
937 //================================================================================
939 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
940 float* x, float* y, float *z, int* domain )
945 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
952 ::GmfGetLin(iMesh, what, x, y, z, domain );
955 //================================================================================
957 * \brief Return node index of a next corner
959 //================================================================================
961 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
965 _libData->ReadCorner( node );
969 ::GmfGetLin(iMesh, what, node );
972 //================================================================================
974 * \brief Return node indices of a next edge
976 //================================================================================
978 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
982 _libData->ReadEdgeNodes( node1, node2, domain );
986 ::GmfGetLin( iMesh, what, node1, node2, domain );
989 //================================================================================
991 * \brief Return node indices of a next triangle
993 //================================================================================
995 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
996 int* node1, int* node2, int* node3, int* domain )
1000 _libData->ReadTriaNodes( node1, node2, node3, domain );
1004 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1007 //================================================================================
1009 * \brief Return node indices of a next tetrahedron or quadrangle
1011 //================================================================================
1013 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1014 int* node1, int* node2, int* node3, int* node4, int* domain )
1018 if ( what == GmfQuadrilaterals )
1019 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1021 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1025 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1028 //================================================================================
1030 * \brief Return node indices of a next hexahedron
1032 //================================================================================
1034 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1035 int* node1, int* node2, int* node3, int* node4,
1036 int* node5, int* node6, int* node7, int* node8,
1041 _libData->ReadHexaNodes( node1, node2, node3, node4,
1042 node5, node6, node7, node8, domain );
1046 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1049 //================================================================================
1051 * \brief Prepare for passing data to MeshGems
1053 //================================================================================
1055 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1062 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1063 _openFiles.insert( id );
1067 //================================================================================
1069 * \brief Set number of entities
1071 //================================================================================
1073 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1078 case GmfVertices: _libData->SetNbVertices( nb ); break;
1079 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1080 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1081 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1082 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1088 ::GmfSetKwd(iMesh, what, nb );
1091 //================================================================================
1093 * \brief Add coordinates of a node
1095 //================================================================================
1097 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1101 _libData->AddNode( x, y, z, domain );
1105 ::GmfSetLin(iMesh, what, x, y, z, domain);
1108 //================================================================================
1110 * \brief Set number of field entities
1111 * \param [in] iMesh - solution file index
1112 * \param [in] what - solution type
1113 * \param [in] nbNodes - nb of entities
1114 * \param [in] nbTypes - nb of data entries in each entity
1115 * \param [in] type - types of the data entries
1117 * Used to prepare to storing size at nodes
1119 //================================================================================
1121 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1125 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1129 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1132 //================================================================================
1134 * \brief Add solution data
1136 //================================================================================
1138 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1142 _libData->AddSizeAtNode( vals[0] );
1146 ::GmfSetLin(iMesh, what, vals);
1149 //================================================================================
1151 * \brief Add edge nodes
1153 //================================================================================
1155 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1159 _libData->AddEdgeNodes( node1, node2, domain );
1163 ::GmfSetLin(iMesh, what, node1, node2, domain );
1166 //================================================================================
1168 * \brief Add a 'required' flag
1170 //================================================================================
1172 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1179 ::GmfSetLin(iMesh, what, id );
1182 //================================================================================
1184 * \brief Add triangle nodes
1186 //================================================================================
1188 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1192 _libData->AddTriaNodes( node1, node2, node3, domain );
1196 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1199 //================================================================================
1201 * \brief Close a file
1203 //================================================================================
1205 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1212 ::GmfCloseMesh( iMesh );
1213 _openFiles.erase( iMesh );
1216 //================================================================================
1218 * \brief Return true if the log is not empty
1220 //================================================================================
1222 bool MG_Hexotic_API::HasLog()
1226 return !_libData->GetErrors().empty();
1229 SMESH_File file( _logFile );
1230 return file.size() > 0;
1233 //================================================================================
1235 * \brief Return log contents
1237 //================================================================================
1239 std::string MG_Hexotic_API::GetLog()
1243 const std::string& err = _libData->GetErrors();
1244 if ( !_logFile.empty() && !err.empty() )
1246 SMESH_File file( _logFile, /*openForReading=*/false );
1247 file.openForWriting();
1248 file.write( err.c_str(), err.size() );
1253 SMESH_File file( _logFile );
1254 return file.getPos();