1 // Copyright (C) 2004-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MG_Hexotic_API.hxx"
26 #include <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;
704 #else // ifdef USE_MG_LIBS
706 struct MG_Hexotic_API::LibData // to avoid compiler warnings
708 volatile bool& _cancelled_flag;
710 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
713 #endif // ifdef USE_MG_LIBS
716 //================================================================================
720 //================================================================================
722 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress)
725 _libData = new LibData( cancelled_flag, progress );
729 if ( getenv("MG_HEXA_USE_EXE"))
734 //================================================================================
738 //================================================================================
740 MG_Hexotic_API::~MG_Hexotic_API()
746 std::set<int>::iterator id = _openFiles.begin();
747 for ( ; id != _openFiles.end(); ++id )
748 ::GmfCloseMesh( *id );
752 //================================================================================
754 * \brief Return the way of MG usage
756 //================================================================================
758 bool MG_Hexotic_API::IsLibrary()
763 //================================================================================
765 * \brief Switch to usage of MG-Hexa executable
767 //================================================================================
769 void MG_Hexotic_API::SetUseExecutable()
774 //================================================================================
776 * \brief Compute the hexa mesh
777 * \param [in] cmdLine - a command to run mg_hexa.exe
778 * \return bool - Ok or not
780 //================================================================================
782 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
788 std::istringstream strm( cmdLine );
789 std::istream_iterator<std::string> sIt( strm ), sEnd;
790 std::vector< std::string > args( sIt, sEnd );
793 std::string param, value;
794 for ( size_t i = 1; i < args.size(); ++i )
796 // look for a param name; it starts from "-"
798 if ( param.size() < 2 || param[0] != '-')
800 while ( param[0] == '-')
801 param = param.substr( 1 );
804 while ( i+1 < args.size() && args[i+1][0] != '-' )
806 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
808 if ( !value.empty() ) value += " ";
811 if ( !_libData->SetParam( param, value ))
812 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
816 bool ok = _libData->Compute();
818 GetLog(); // write a log file
819 _logFile = ""; // not to write it again
825 int err = system( cmdLine.c_str() ); // run
828 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
829 << strerror( errno );
835 //================================================================================
837 * \brief Prepare for reading a mesh data
839 //================================================================================
841 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
848 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
849 _openFiles.insert( id );
853 //================================================================================
855 * \brief Return nb of entities
857 //================================================================================
859 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
865 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
866 case GmfVertices: return _libData->ReadNbNodes();
867 case GmfEdges: return _libData->ReadNbEdges();
868 case GmfTriangles: return _libData->ReadNbTria();
869 case GmfQuadrilaterals: return _libData->ReadNbQuads();
870 case GmfTetrahedra: return _libData->ReadNbTetra();
871 case GmfHexahedra: return _libData->ReadNbHexa();
872 case GmfCorners: return _libData->ReadNbCorners();
878 return ::GmfStatKwd( iMesh, what );
881 //================================================================================
883 * \brief Prepare for reading some data
885 //================================================================================
887 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
891 _libData->ResetCounter();
895 ::GmfGotoKwd( iMesh, what );
898 //================================================================================
900 * \brief Return index of a domain identified by a triangle normal
901 * \param [in] iMesh - mesh file index
902 * \param [in] what - must be GmfSubDomainFromGeom
903 * \param [out] nbNodes - nb nodes in a face
904 * \param [out] faceInd - face index
905 * \param [out] ori - face orientation
906 * \param [out] domain - domain index
907 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
910 //================================================================================
912 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
916 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
920 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
923 //================================================================================
925 * \brief Return coordinates of a next node
927 //================================================================================
929 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
930 double* x, double* y, double *z, int* domain )
934 _libData->ReadNodeXYZ( x, y, z, domain );
938 ::GmfGetLin(iMesh, what, x, y, z, domain );
941 //================================================================================
943 * \brief Return coordinates of a next node
945 //================================================================================
947 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
948 float* x, float* y, float *z, int* domain )
953 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
960 ::GmfGetLin(iMesh, what, x, y, z, domain );
963 //================================================================================
965 * \brief Return node index of a next corner
967 //================================================================================
969 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
973 _libData->ReadCorner( node );
977 ::GmfGetLin(iMesh, what, node );
980 //================================================================================
982 * \brief Return node indices of a next edge
984 //================================================================================
986 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
990 _libData->ReadEdgeNodes( node1, node2, domain );
994 ::GmfGetLin( iMesh, what, node1, node2, domain );
997 //================================================================================
999 * \brief Return node indices of a next triangle
1001 //================================================================================
1003 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1004 int* node1, int* node2, int* node3, int* domain )
1008 _libData->ReadTriaNodes( node1, node2, node3, domain );
1012 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1015 //================================================================================
1017 * \brief Return node indices of a next tetrahedron or quadrangle
1019 //================================================================================
1021 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1022 int* node1, int* node2, int* node3, int* node4, int* domain )
1026 if ( what == GmfQuadrilaterals )
1027 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1029 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1033 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1036 //================================================================================
1038 * \brief Return node indices of a next hexahedron
1040 //================================================================================
1042 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1043 int* node1, int* node2, int* node3, int* node4,
1044 int* node5, int* node6, int* node7, int* node8,
1049 _libData->ReadHexaNodes( node1, node2, node3, node4,
1050 node5, node6, node7, node8, domain );
1054 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1057 //================================================================================
1059 * \brief Prepare for passing data to MeshGems
1061 //================================================================================
1063 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1070 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1071 _openFiles.insert( id );
1075 //================================================================================
1077 * \brief Set number of entities
1079 //================================================================================
1081 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1086 case GmfVertices: _libData->SetNbVertices( nb ); break;
1087 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1088 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1089 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1090 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1096 ::GmfSetKwd(iMesh, what, nb );
1099 //================================================================================
1101 * \brief Add coordinates of a node
1103 //================================================================================
1105 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1109 _libData->AddNode( x, y, z, domain );
1113 ::GmfSetLin(iMesh, what, x, y, z, domain);
1116 //================================================================================
1118 * \brief Set number of field entities
1119 * \param [in] iMesh - solution file index
1120 * \param [in] what - solution type
1121 * \param [in] nbNodes - nb of entities
1122 * \param [in] nbTypes - nb of data entries in each entity
1123 * \param [in] type - types of the data entries
1125 * Used to prepare to storing size at nodes
1127 //================================================================================
1129 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1133 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1137 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1140 //================================================================================
1142 * \brief Add solution data
1144 //================================================================================
1146 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1150 _libData->AddSizeAtNode( vals[0] );
1154 ::GmfSetLin(iMesh, what, vals);
1157 //================================================================================
1159 * \brief Add edge nodes
1161 //================================================================================
1163 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1167 _libData->AddEdgeNodes( node1, node2, domain );
1171 ::GmfSetLin(iMesh, what, node1, node2, domain );
1174 //================================================================================
1176 * \brief Add a 'required' flag
1178 //================================================================================
1180 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1187 ::GmfSetLin(iMesh, what, id );
1190 //================================================================================
1192 * \brief Add triangle nodes
1194 //================================================================================
1196 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1200 _libData->AddTriaNodes( node1, node2, node3, domain );
1204 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1207 //================================================================================
1209 * \brief Close a file
1211 //================================================================================
1213 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1220 ::GmfCloseMesh( iMesh );
1221 _openFiles.erase( iMesh );
1224 //================================================================================
1226 * \brief Return true if the log is not empty
1228 //================================================================================
1230 bool MG_Hexotic_API::HasLog()
1234 return !_libData->GetErrors().empty();
1237 SMESH_File file( _logFile );
1238 return file.size() > 0;
1241 //================================================================================
1243 * \brief Return log contents
1245 //================================================================================
1247 std::string MG_Hexotic_API::GetLog()
1251 const std::string& err = _libData->GetErrors();
1252 if ( !_logFile.empty() && !err.empty() )
1254 SMESH_File file( _logFile, /*openForReading=*/false );
1255 file.openForWriting();
1256 file.write( err.c_str(), err.size() );
1261 SMESH_File file( _logFile );
1262 return file.getPos();