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 ( !value.empty() ) value += " ";
796 if ( !_libData->SetParam( param, value ))
797 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
801 bool ok = _libData->Compute();
803 GetLog(); // write a log file
804 _logFile = ""; // not to write it again
810 int err = system( cmdLine.c_str() ); // run
813 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
814 << strerror( errno );
820 //================================================================================
822 * \brief Prepare for reading a mesh data
824 //================================================================================
826 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
833 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
834 _openFiles.insert( id );
838 //================================================================================
840 * \brief Return nb of entities
842 //================================================================================
844 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
850 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
851 case GmfVertices: return _libData->ReadNbNodes();
852 case GmfEdges: return _libData->ReadNbEdges();
853 case GmfTriangles: return _libData->ReadNbTria();
854 case GmfQuadrilaterals: return _libData->ReadNbQuads();
855 case GmfTetrahedra: return _libData->ReadNbTetra();
856 case GmfHexahedra: return _libData->ReadNbHexa();
857 case GmfCorners: return _libData->ReadNbCorners();
863 return ::GmfStatKwd( iMesh, what );
866 //================================================================================
868 * \brief Prepare for reading some data
870 //================================================================================
872 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
876 _libData->ResetCounter();
880 ::GmfGotoKwd( iMesh, what );
883 //================================================================================
885 * \brief Return index of a domain identified by a triangle normal
886 * \param [in] iMesh - mesh file index
887 * \param [in] what - must be GmfSubDomainFromGeom
888 * \param [out] nbNodes - nb nodes in a face
889 * \param [out] faceInd - face index
890 * \param [out] ori - face orientation
891 * \param [out] domain - domain index
892 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
895 //================================================================================
897 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
901 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
905 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
908 //================================================================================
910 * \brief Return coordinates of a next node
912 //================================================================================
914 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
915 double* x, double* y, double *z, int* domain )
919 _libData->ReadNodeXYZ( x, y, z, domain );
923 ::GmfGetLin(iMesh, what, x, y, z, domain );
926 //================================================================================
928 * \brief Return coordinates of a next node
930 //================================================================================
932 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
933 float* x, float* y, float *z, int* domain )
938 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
945 ::GmfGetLin(iMesh, what, x, y, z, domain );
948 //================================================================================
950 * \brief Return node index of a next corner
952 //================================================================================
954 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
958 _libData->ReadCorner( node );
962 ::GmfGetLin(iMesh, what, node );
965 //================================================================================
967 * \brief Return node indices of a next edge
969 //================================================================================
971 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
975 _libData->ReadEdgeNodes( node1, node2, domain );
979 ::GmfGetLin( iMesh, what, node1, node2, domain );
982 //================================================================================
984 * \brief Return node indices of a next triangle
986 //================================================================================
988 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
989 int* node1, int* node2, int* node3, int* domain )
993 _libData->ReadTriaNodes( node1, node2, node3, domain );
997 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1000 //================================================================================
1002 * \brief Return node indices of a next tetrahedron or quadrangle
1004 //================================================================================
1006 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1007 int* node1, int* node2, int* node3, int* node4, int* domain )
1011 if ( what == GmfQuadrilaterals )
1012 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1014 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1018 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1021 //================================================================================
1023 * \brief Return node indices of a next hexahedron
1025 //================================================================================
1027 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1028 int* node1, int* node2, int* node3, int* node4,
1029 int* node5, int* node6, int* node7, int* node8,
1034 _libData->ReadHexaNodes( node1, node2, node3, node4,
1035 node5, node6, node7, node8, domain );
1039 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1042 //================================================================================
1044 * \brief Prepare for passing data to MeshGems
1046 //================================================================================
1048 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1055 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1056 _openFiles.insert( id );
1060 //================================================================================
1062 * \brief Set number of entities
1064 //================================================================================
1066 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1071 case GmfVertices: _libData->SetNbVertices( nb ); break;
1072 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1073 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1074 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1075 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1081 ::GmfSetKwd(iMesh, what, nb );
1084 //================================================================================
1086 * \brief Add coordinates of a node
1088 //================================================================================
1090 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1094 _libData->AddNode( x, y, z, domain );
1098 ::GmfSetLin(iMesh, what, x, y, z, domain);
1101 //================================================================================
1103 * \brief Set number of field entities
1104 * \param [in] iMesh - solution file index
1105 * \param [in] what - solution type
1106 * \param [in] nbNodes - nb of entities
1107 * \param [in] nbTypes - nb of data entries in each entity
1108 * \param [in] type - types of the data entries
1110 * Used to prepare to storing size at nodes
1112 //================================================================================
1114 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1118 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1122 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1125 //================================================================================
1127 * \brief Add solution data
1129 //================================================================================
1131 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1135 _libData->AddSizeAtNode( vals[0] );
1139 ::GmfSetLin(iMesh, what, vals);
1142 //================================================================================
1144 * \brief Add edge nodes
1146 //================================================================================
1148 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1152 _libData->AddEdgeNodes( node1, node2, domain );
1156 ::GmfSetLin(iMesh, what, node1, node2, domain );
1159 //================================================================================
1161 * \brief Add a 'required' flag
1163 //================================================================================
1165 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1172 ::GmfSetLin(iMesh, what, id );
1175 //================================================================================
1177 * \brief Add triangle nodes
1179 //================================================================================
1181 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1185 _libData->AddTriaNodes( node1, node2, node3, domain );
1189 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1192 //================================================================================
1194 * \brief Close a file
1196 //================================================================================
1198 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1205 ::GmfCloseMesh( iMesh );
1206 _openFiles.erase( iMesh );
1209 //================================================================================
1211 * \brief Return true if the log is not empty
1213 //================================================================================
1215 bool MG_Hexotic_API::HasLog()
1219 return !_libData->GetErrors().empty();
1222 SMESH_File file( _logFile );
1223 return file.size() > 0;
1226 //================================================================================
1228 * \brief Return log contents
1230 //================================================================================
1232 std::string MG_Hexotic_API::GetLog()
1236 const std::string& err = _libData->GetErrors();
1237 if ( !_logFile.empty() && !err.empty() )
1239 SMESH_File file( _logFile, /*openForReading=*/false );
1240 file.openForWriting();
1241 file.write( err.c_str(), err.size() );
1246 SMESH_File file( _logFile );
1247 return file.getPos();