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 hexa_session_delete( _session );
79 mesh_delete( _tria_mesh );
81 sizemap_delete( _sizemap );
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( _xyz.size() - _nodeSize.size() ));
444 double GetSizeAtVertex( int iNode )
446 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - _xyz.size() + _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 // corresponding messages are:
588 // " | Analyzing the surface mesh |" => 1 %
589 // " | Building and conforming the octree |" => 8 %
590 // " | Subdomains and boundary recovery |" => 15%
591 // " | Mesh bending and smoothing |" => 45%
592 // " | Final mesh statistics |" => 99%
594 double newProgress = std::min( 0.99, data->_progress + data->_msgCost );
595 if ( strlen( desc ) > 25 )
597 if ( strncmp( desc+3, "Analyzing the surface mesh", 26 ) == 0 )
598 newProgress = 0.01, data->_msgCost = ( 0.08 - 0.01 ) / 10;
599 else if ( strncmp( desc+3, "Building and conforming the octree", 34 ) == 0 )
600 newProgress = 0.08, data->_msgCost = ( 0.15 - 0.08 ) / 100;
601 else if ( strncmp( desc+3, "Subdomains and boundary recovery", 32 ) == 0 )
602 newProgress = 0.15, data->_msgCost = ( 0.45 - 0.15 ) / 20;
603 else if ( strncmp( desc+3, "Mesh bending and smoothing", 26 ) == 0 )
604 newProgress = 0.45, data->_msgCost = ( 0.99 - 0.45 ) / 65;
605 else if ( strncmp( desc+3, "Final mesh statistics", 21 ) == 0 )
608 data->_progress = std::max( data->_progress, newProgress );
613 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
615 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
616 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
624 void MG_Hexotic_API::LibData::Init()
628 // Create the meshgems working context
629 _context = context_new();
630 if ( !_context ) MG_Error( "unable to create a new context" );
632 // Set the message callback for the _context.
633 ret = context_set_message_callback( _context, my_message_cb, this );
634 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
636 // Create the structure holding the callbacks giving access to triangle mesh
637 _tria_mesh = mesh_new( _context );
638 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
640 // Set callbacks to provide triangle mesh data
641 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
642 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
643 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
644 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
645 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
646 mesh_set_get_edge_tag( _tria_mesh, get_edge_tag, this );
647 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
648 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
649 mesh_set_get_triangle_tag( _tria_mesh, get_triangle_tag, this );
651 // Create a hexa session
652 _session = hexa_session_new( _context );
653 if ( !_session ) MG_Error( "unable to create a new hexa session");
655 ret = hexa_set_interrupt_callback( _session, my_interrupt_callback, this );
656 if ( ret != STATUS_OK ) MG_Error("in hexa_set_interrupt_callback");
660 bool MG_Hexotic_API::LibData::Compute()
663 status_t ret = hexa_set_surface_mesh( _session, _tria_mesh );
664 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
667 if ( !_nodeSize.empty() )
669 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
670 (void*) &get_vertex_weight, this );
671 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
673 ret = hexa_set_sizemap( _session, _sizemap );
674 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
677 //////////////////////////////////////////////////////////////////////////////////////////
678 // const char* file = "/tmp/ghs3d_IN.mesh";
679 // mesh_write_mesh( _tria_mesh,file);
680 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
682 ret = hexa_compute_mesh( _session );
683 if ( ret != STATUS_OK ) return false;
685 ret = hexa_get_mesh( _session, &_hexa_mesh);
686 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
688 //////////////////////////////////////////////////////////////////////////////////////////
689 // file = "/tmp/ghs3d_OUT.mesh";
690 // mesh_write_mesh( _hexa_mesh,file);
691 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
697 #endif // ifdef USE_MG_LIBS
700 //================================================================================
704 //================================================================================
706 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress)
710 _libData = new LibData( cancelled_flag, progress );
713 if ( getenv("MG_HEXA_USE_EXE"))
717 //================================================================================
721 //================================================================================
723 MG_Hexotic_API::~MG_Hexotic_API()
729 std::set<int>::iterator id = _openFiles.begin();
730 for ( ; id != _openFiles.end(); ++id )
731 ::GmfCloseMesh( *id );
735 //================================================================================
737 * \brief Return the way of MG usage
739 //================================================================================
741 bool MG_Hexotic_API::IsLibrary()
746 //================================================================================
748 * \brief Switch to usage of MG-Hexa executable
750 //================================================================================
752 void MG_Hexotic_API::SetUseExecutable()
757 //================================================================================
759 * \brief Compute the hexa mesh
760 * \param [in] cmdLine - a command to run mg_hexa.exe
761 * \return bool - Ok or not
763 //================================================================================
765 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
771 std::istringstream strm( cmdLine );
772 std::istream_iterator<std::string> sIt( strm ), sEnd;
773 std::vector< std::string > args( sIt, sEnd );
776 std::string param, value;
777 for ( size_t i = 1; i < args.size(); ++i )
779 // look for a param name; it starts from "-"
781 if ( param.size() < 2 || param[0] != '-')
783 while ( param[0] == '-')
784 param = param.substr( 1 );
787 while ( i+1 < args.size() && args[i+1][0] != '-' )
789 if ( !value.empty() ) value += " ";
792 if ( !_libData->SetParam( param, value ))
793 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
797 return _libData->Compute();
801 int err = system( cmdLine.c_str() ); // run
804 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
805 << strerror( errno );
807 GetLog(); // write a log file
808 _logFile = ""; // not to write it again
814 //================================================================================
816 * \brief Prepare for reading a mesh data
818 //================================================================================
820 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
827 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
828 _openFiles.insert( id );
832 //================================================================================
834 * \brief Return nb of entities
836 //================================================================================
838 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
844 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
845 case GmfVertices: return _libData->ReadNbNodes();
846 case GmfEdges: return _libData->ReadNbEdges();
847 case GmfTriangles: return _libData->ReadNbTria();
848 case GmfQuadrilaterals: return _libData->ReadNbQuads();
849 case GmfTetrahedra: return _libData->ReadNbTetra();
850 case GmfHexahedra: return _libData->ReadNbHexa();
851 case GmfCorners: return _libData->ReadNbCorners();
857 return ::GmfStatKwd( iMesh, what );
860 //================================================================================
862 * \brief Prepare for reading some data
864 //================================================================================
866 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
870 _libData->ResetCounter();
874 ::GmfGotoKwd( iMesh, what );
877 //================================================================================
879 * \brief Return index of a domain identified by a triangle normal
880 * \param [in] iMesh - mesh file index
881 * \param [in] what - must be GmfSubDomainFromGeom
882 * \param [out] nbNodes - nb nodes in a face
883 * \param [out] faceInd - face index
884 * \param [out] ori - face orientation
885 * \param [out] domain - domain index
886 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
889 //================================================================================
891 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
895 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
899 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
902 //================================================================================
904 * \brief Return coordinates of a next node
906 //================================================================================
908 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
909 double* x, double* y, double *z, int* domain )
913 _libData->ReadNodeXYZ( x, y, z, domain );
917 ::GmfGetLin(iMesh, what, x, y, z, domain );
920 //================================================================================
922 * \brief Return coordinates of a next node
924 //================================================================================
926 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
927 float* x, float* y, float *z, int* domain )
932 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
939 ::GmfGetLin(iMesh, what, x, y, z, domain );
942 //================================================================================
944 * \brief Return node index of a next corner
946 //================================================================================
948 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
952 _libData->ReadCorner( node );
956 ::GmfGetLin(iMesh, what, node );
959 //================================================================================
961 * \brief Return node indices of a next edge
963 //================================================================================
965 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
969 _libData->ReadEdgeNodes( node1, node2, domain );
973 ::GmfGetLin( iMesh, what, node1, node2, domain );
976 //================================================================================
978 * \brief Return node indices of a next triangle
980 //================================================================================
982 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
983 int* node1, int* node2, int* node3, int* domain )
987 _libData->ReadTriaNodes( node1, node2, node3, domain );
991 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
994 //================================================================================
996 * \brief Return node indices of a next tetrahedron or quadrangle
998 //================================================================================
1000 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1001 int* node1, int* node2, int* node3, int* node4, int* domain )
1005 if ( what == GmfQuadrilaterals )
1006 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1008 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1012 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1015 //================================================================================
1017 * \brief Return node indices of a next hexahedron
1019 //================================================================================
1021 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1022 int* node1, int* node2, int* node3, int* node4,
1023 int* node5, int* node6, int* node7, int* node8,
1028 _libData->ReadHexaNodes( node1, node2, node3, node4,
1029 node5, node6, node7, node8, domain );
1033 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1036 //================================================================================
1038 * \brief Prepare for passing data to MeshGems
1040 //================================================================================
1042 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1049 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1050 _openFiles.insert( id );
1054 //================================================================================
1056 * \brief Set number of entities
1058 //================================================================================
1060 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1065 case GmfVertices: _libData->SetNbVertices( nb ); break;
1066 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1067 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1068 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1069 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1075 ::GmfSetKwd(iMesh, what, nb );
1078 //================================================================================
1080 * \brief Add coordinates of a node
1082 //================================================================================
1084 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1088 _libData->AddNode( x, y, z, domain );
1092 ::GmfSetLin(iMesh, what, x, y, z, domain);
1095 //================================================================================
1097 * \brief Set number of field entities
1098 * \param [in] iMesh - solution file index
1099 * \param [in] what - solution type
1100 * \param [in] nbNodes - nb of entities
1101 * \param [in] nbTypes - nb of data entries in each entity
1102 * \param [in] type - types of the data entries
1104 * Used to prepare to storing size at nodes
1106 //================================================================================
1108 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1112 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1116 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1119 //================================================================================
1121 * \brief Add solution data
1123 //================================================================================
1125 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1129 _libData->AddSizeAtNode( vals[0] );
1133 ::GmfSetLin(iMesh, what, vals);
1136 //================================================================================
1138 * \brief Add edge nodes
1140 //================================================================================
1142 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1146 _libData->AddEdgeNodes( node1, node2, domain );
1150 ::GmfSetLin(iMesh, what, node1, node2, domain );
1153 //================================================================================
1155 * \brief Add a 'required' flag
1157 //================================================================================
1159 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1166 ::GmfSetLin(iMesh, what, id );
1169 //================================================================================
1171 * \brief Add triangle nodes
1173 //================================================================================
1175 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1179 _libData->AddTriaNodes( node1, node2, node3, domain );
1183 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1186 //================================================================================
1188 * \brief Close a file
1190 //================================================================================
1192 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1199 ::GmfCloseMesh( iMesh );
1200 _openFiles.erase( iMesh );
1203 //================================================================================
1205 * \brief Return true if the log is not empty
1207 //================================================================================
1209 bool MG_Hexotic_API::HasLog()
1213 return !_libData->GetErrors().empty();
1216 SMESH_File file( _logFile );
1217 return file.size() > 0;
1220 //================================================================================
1222 * \brief Return log contents
1224 //================================================================================
1226 std::string MG_Hexotic_API::GetLog()
1230 const std::string& err = _libData->GetErrors();
1231 if ( !_logFile.empty() && !err.empty() )
1233 SMESH_File file( _logFile, /*openForReading=*/false );
1234 file.openForWriting();
1235 file.write( err.c_str(), err.size() );
1240 SMESH_File file( _logFile );
1241 return file.getPos();