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 <SMESH_MGLicenseKeyGen.hxx>
29 #include <Utils_SALOME_Exception.hxx>
39 #include <meshgems/meshgems.h>
40 #include <meshgems/hexa.h>
43 struct MG_Hexotic_API::LibData
47 hexa_session_t * _session;
53 std::vector<double> _xyz;
54 std::vector<double> _nodeSize; // required nodes
55 std::vector<int> _edgeNodesTags;
57 std::vector<int> _triaNodesTags;
60 std::vector<int> _corners;
63 volatile bool& _cancelled_flag;
64 std::string _errorStr;
68 LibData( volatile bool & cancelled_flag, double& progress )
69 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _hexa_mesh(0),
70 _nbRequiredEdges(0), _nbRequiredTria(0),
71 _cancelled_flag( cancelled_flag ), _progress( progress ), _msgCost( 0.00015 )
74 // methods setting callbacks implemented after callback definitions
81 hexa_regain_mesh( _session, _hexa_mesh );
83 mesh_delete( _tria_mesh );
85 sizemap_delete( _sizemap );
87 hexa_session_delete( _session );
89 context_delete( _context );
98 void AddError( const char *txt )
106 const std::string& GetErrors()
111 void MG_Error(const char* txt="")
113 SMESH_Comment msg("\nMeshGems error. ");
115 AddError( msg.c_str() );
118 bool SetParam( const std::string& param, const std::string& value )
120 status_t ret = hexa_set_param( _session, param.c_str(), value.c_str() );
122 //std::cout << param << " = " << value << std::endl;
124 return ( ret == STATUS_OK );
129 return _cancelled_flag;
132 int ReadNbSubDomains()
135 status_t ret = mesh_get_subdomain_count( _hexa_mesh, & nb );
137 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
146 status_t ret = mesh_get_vertex_count( _hexa_mesh, & nb );
148 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
155 status_t ret = mesh_get_edge_count( _hexa_mesh, & nb );
157 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
164 status_t ret = mesh_get_triangle_count( _hexa_mesh, & nb );
166 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
173 status_t ret = mesh_get_quadrangle_count( _hexa_mesh, & nb );
175 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
182 status_t ret = mesh_get_tetrahedron_count( _hexa_mesh, & nb );
184 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
191 status_t ret = mesh_get_hexahedron_count( _hexa_mesh, & nb );
193 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
199 return _corners.size();
207 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
209 integer tag, seed_type, seed_idx, seed_orientation;
210 status_t ret = mesh_get_subdomain_description( _hexa_mesh, _count,
211 &tag, &seed_type, &seed_idx, &seed_orientation);
213 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
218 *ori = seed_orientation;
222 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
225 status_t ret = mesh_get_vertex_coordinates( _hexa_mesh, _count, coo );
226 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
232 integer isCorner = 0;
233 ret = mesh_get_vertex_corner_property( _hexa_mesh, _count, &isCorner);
234 if (ret != STATUS_OK) MG_Error( "unable to get resulting vertex property" );
236 _corners.push_back( _count );
241 void ReadEdgeNodes( int* node1, int* node2, int* domain )
244 status_t ret = mesh_get_edge_vertices( _hexa_mesh, _count, vtx);
245 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
250 ret = mesh_get_edge_tag( _hexa_mesh, _count, &tag );
251 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
258 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
261 status_t ret = mesh_get_triangle_vertices( _hexa_mesh, _count, vtx);
262 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
268 ret = mesh_get_triangle_tag( _hexa_mesh, _count, &tag );
269 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
276 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
279 status_t ret = mesh_get_quadrangle_vertices( _hexa_mesh, _count, vtx);
280 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
287 ret = mesh_get_quadrangle_tag( _hexa_mesh, _count, &tag );
288 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
295 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
298 status_t ret = mesh_get_tetrahedron_vertices( _hexa_mesh, _count, vtx);
299 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
306 ret = mesh_get_tetrahedron_tag( _hexa_mesh, _count, &tag );
307 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
314 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
315 int* node5, int* node6, int* node7, int* node8, int* domain )
318 status_t ret = mesh_get_hexahedron_vertices( _hexa_mesh, _count, vtx);
319 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
330 ret = mesh_get_hexahedron_tag( _hexa_mesh, _count, &tag );
331 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
338 void ReadCorner( int* node )
340 if ( _count <= ReadNbCorners() )
341 *node = _corners[ _count - 1 ];
348 void SetNbVertices( int nb )
350 _xyz.reserve( _xyz.capacity() + nb );
353 void SetNbEdges( int nb )
355 _edgeNodesTags.reserve( nb * 3 );
358 void SetNbTria( int nb )
360 _triaNodesTags.reserve( nb * 4 );
363 void SetNbReqVertices( int nb )
365 _nodeSize.reserve( nb );
368 void SetNbReqEdges( int nb )
370 _nbRequiredEdges = nb;
373 void SetNbReqTria( int nb )
375 _nbRequiredTria = nb;
378 void AddNode( double x, double y, double z, int /*domain*/ )
385 void AddSizeAtNode( double size )
387 _nodeSize.push_back( size );
390 void AddEdgeNodes( int node1, int node2, int domain )
392 _edgeNodesTags.push_back( node1 );
393 _edgeNodesTags.push_back( node2 );
394 _edgeNodesTags.push_back( domain );
397 void AddTriaNodes( int node1, int node2, int node3, int domain )
399 _triaNodesTags.push_back( node1 );
400 _triaNodesTags.push_back( node2 );
401 _triaNodesTags.push_back( node3 );
402 _triaNodesTags.push_back( domain );
407 return _xyz.size() / 3;
410 double* NodeCoord( int iNode )
412 return & _xyz[ iNode * 3 ];
417 return _edgeNodesTags.size() / 3;
420 int* GetEdgeNodes( int iEdge )
422 return & _edgeNodesTags[ iEdge * 3 ];
425 int GetEdgeTag( int iEdge )
427 return _edgeNodesTags[ iEdge * 3 + 2 ];
432 return _triaNodesTags.size() / 4;
435 int * GetTriaNodes( int iTria )
437 return & _triaNodesTags[ iTria * 4 ];
440 int GetTriaTag( int iTria )
442 return _triaNodesTags[ iTria * 4 + 3 ];
445 int IsVertexRequired( int iNode )
447 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
450 double GetSizeAtVertex( int iNode )
452 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
456 namespace // functions called by MG library to exchange with the application
458 status_t get_vertex_count(integer * nbvtx, void *user_data)
460 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
461 *nbvtx = data->NbNodes();
466 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
468 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
469 double* coord = data->NodeCoord( ivtx-1 );
470 for (int j = 0; j < 3; j++)
475 status_t get_edge_count(integer * nbedge, void *user_data)
477 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
478 *nbedge = data->NbEdges();
483 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
485 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
486 int* nodes = data->GetEdgeNodes( iedge-1 );
493 status_t get_edge_tag(integer iedge, integer * tag, void *user_data)
495 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
496 * tag = data->GetEdgeTag( iedge-1 );
501 status_t get_triangle_count(integer * nbtri, void *user_data)
503 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
504 *nbtri = data->NbTriangles();
509 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
511 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
512 int* nodes = data->GetTriaNodes( itri-1 );
520 status_t get_triangle_tag(integer itri, integer * tag, void *user_data)
522 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
523 * tag = data->GetTriaTag( itri-1 );
528 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
529 // integer * evtri, void *user_data)
532 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
535 // /* We want to describe a linear "3 nodes" triangle */
536 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
538 // /* We want to describe a quadratic "6 nodes" triangle */
539 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
540 // for (j = 0; j < 3; j++)
541 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
547 // status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
549 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
551 // *nbtetra = 0; /* the number of tetra in your input mesh (0 if you describe a surface mesh) */
556 // status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
560 // MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
562 // for (j = 0; j < 4; j++)
563 // vtetra[j] = 0; /* the j'th vertex index of the itetra'th tetrahedron */
568 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
570 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
571 *rvtx = data->IsVertexRequired( ivtx - 1 );
576 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
578 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
579 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
584 status_t my_message_cb(message_t * msg, void *user_data)
587 message_get_description(msg, &desc);
589 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
590 data->AddError( desc );
593 //std::cout << desc << std::endl;
597 // corresponding messages are:
598 // " | Analyzing the surface mesh |" => 1 %
599 // " | Building and conforming the octree |" => 8 %
600 // " | Subdomains and boundary recovery |" => 15%
601 // " | Mesh bending and smoothing |" => 45%
602 // " | Final mesh statistics |" => 99%
604 double newProgress = std::min( 0.99, data->_progress + data->_msgCost );
605 if ( strlen( desc ) > 25 )
607 if ( strncmp( desc+3, "Analyzing the surface mesh", 26 ) == 0 )
608 newProgress = 0.01, data->_msgCost = ( 0.08 - 0.01 ) / 10;
609 else if ( strncmp( desc+3, "Building and conforming the octree", 34 ) == 0 )
610 newProgress = 0.08, data->_msgCost = ( 0.15 - 0.08 ) / 100;
611 else if ( strncmp( desc+3, "Subdomains and boundary recovery", 32 ) == 0 )
612 newProgress = 0.15, data->_msgCost = ( 0.45 - 0.15 ) / 20;
613 else if ( strncmp( desc+3, "Mesh bending and smoothing", 26 ) == 0 )
614 newProgress = 0.45, data->_msgCost = ( 0.99 - 0.45 ) / 65;
615 else if ( strncmp( desc+3, "Final mesh statistics", 21 ) == 0 )
618 data->_progress = std::max( data->_progress, newProgress );
623 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
625 MG_Hexotic_API::LibData* data = (MG_Hexotic_API::LibData *) user_data;
626 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
634 void MG_Hexotic_API::LibData::Init()
638 // Create the meshgems working context
639 _context = context_new();
640 if ( !_context ) MG_Error( "unable to create a new context" );
642 // Set the message callback for the _context.
643 ret = context_set_message_callback( _context, my_message_cb, this );
644 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
646 // Create the structure holding the callbacks giving access to triangle mesh
647 _tria_mesh = mesh_new( _context );
648 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
650 // Set callbacks to provide triangle mesh data
651 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
652 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
653 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
654 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
655 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
656 mesh_set_get_edge_tag( _tria_mesh, get_edge_tag, this );
657 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
658 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
659 mesh_set_get_triangle_tag( _tria_mesh, get_triangle_tag, this );
661 // Create a hexa session
662 _session = hexa_session_new( _context );
663 if ( !_session ) MG_Error( "unable to create a new hexa session");
665 ret = hexa_set_interrupt_callback( _session, my_interrupt_callback, this );
666 if ( ret != STATUS_OK ) MG_Error("in hexa_set_interrupt_callback");
670 bool MG_Hexotic_API::LibData::Compute()
673 std::string errorTxt;
674 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, errorTxt ))
676 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
681 status_t ret = hexa_set_surface_mesh( _session, _tria_mesh );
682 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
685 if ( !_nodeSize.empty() )
687 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
688 (void*) &get_vertex_weight, this );
689 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
691 ret = hexa_set_sizemap( _session, _sizemap );
692 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
695 //////////////////////////////////////////////////////////////////////////////////////////
696 // const char* file = "/tmp/ghs3d_IN.mesh";
697 // mesh_write_mesh( _tria_mesh,file);
698 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
700 ret = hexa_compute_mesh( _session );
701 if ( ret != STATUS_OK ) return false;
703 ret = hexa_get_mesh( _session, &_hexa_mesh);
704 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
706 //////////////////////////////////////////////////////////////////////////////////////////
707 // file = "/tmp/ghs3d_OUT.mesh";
708 // mesh_write_mesh( _hexa_mesh,file);
709 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
714 #else // ifdef USE_MG_LIBS
716 struct MG_Hexotic_API::LibData // to avoid compiler warnings
718 volatile bool& _cancelled_flag;
720 LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
723 #endif // ifdef USE_MG_LIBS
726 //================================================================================
730 //================================================================================
732 MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress):
733 _isMesh(true), _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
736 _libData = new LibData( cancelled_flag, progress );
740 if ( getenv("MG_HEXA_USE_EXE"))
745 //================================================================================
749 //================================================================================
751 MG_Hexotic_API::~MG_Hexotic_API()
757 std::set<int>::iterator id = _openFiles.begin();
758 for ( ; id != _openFiles.end(); ++id )
759 ::GmfCloseMesh( *id );
763 //================================================================================
765 * \brief Return the way of MG usage
767 //================================================================================
769 bool MG_Hexotic_API::IsLibrary()
774 //================================================================================
776 * \brief Switch to usage of MG-Hexa executable
778 //================================================================================
780 void MG_Hexotic_API::SetUseExecutable()
785 //================================================================================
787 * \brief Compute the hexa mesh
788 * \param [in] cmdLine - a command to run mg_hexa.exe
789 * \return bool - Ok or not
791 //================================================================================
793 bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
799 std::istringstream strm( cmdLine );
800 std::istream_iterator<std::string> sIt( strm ), sEnd;
801 std::vector< std::string > args( sIt, sEnd );
804 std::string param, value;
805 for ( size_t i = 1; i < args.size(); ++i )
807 // look for a param name; it starts from "-"
809 if ( param.size() < 2 || param[0] != '-')
811 while ( param[0] == '-')
812 param = param.substr( 1 );
815 while ( i+1 < args.size() && args[i+1][0] != '-' )
817 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
819 if ( !value.empty() ) value += " ";
822 if ( !_libData->SetParam( param, value ))
823 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
827 bool ok = _libData->Compute();
829 GetLog(); // write a log file
830 _logFile = ""; // not to write it again
835 // add MG license key
837 std::string errorTxt, meshIn;
838 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
839 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
843 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
847 const_cast< std::string& >( cmdLine ) += " --key " + key;
850 int err = system( cmdLine.c_str() ); // run
853 errStr = SMESH_Comment("system(mg-hexa.exe ...) command failed with error: ")
854 << strerror( errno );
860 //================================================================================
862 * \brief Prepare for reading a mesh data
864 //================================================================================
866 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
873 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
874 _openFiles.insert( id );
878 //================================================================================
880 * \brief Return nb of entities
882 //================================================================================
884 int MG_Hexotic_API::GmfStatKwd( int iMesh, GmfKwdCod what )
890 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
891 case GmfVertices: return _libData->ReadNbNodes();
892 case GmfEdges: return _libData->ReadNbEdges();
893 case GmfTriangles: return _libData->ReadNbTria();
894 case GmfQuadrilaterals: return _libData->ReadNbQuads();
895 case GmfTetrahedra: return _libData->ReadNbTetra();
896 case GmfHexahedra: return _libData->ReadNbHexa();
897 case GmfCorners: return _libData->ReadNbCorners();
903 return ::GmfStatKwd( iMesh, what );
906 //================================================================================
908 * \brief Prepare for reading some data
910 //================================================================================
912 void MG_Hexotic_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
916 _libData->ResetCounter();
920 ::GmfGotoKwd( iMesh, what );
923 //================================================================================
925 * \brief Return index of a domain identified by a triangle normal
926 * \param [in] iMesh - mesh file index
927 * \param [in] what - must be GmfSubDomainFromGeom
928 * \param [out] nbNodes - nb nodes in a face
929 * \param [out] faceInd - face index
930 * \param [out] ori - face orientation
931 * \param [out] domain - domain index
932 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
935 //================================================================================
937 void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
941 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
945 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
948 //================================================================================
950 * \brief Return coordinates of a next node
952 //================================================================================
954 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
955 double* x, double* y, double *z, int* domain )
959 _libData->ReadNodeXYZ( x, y, z, domain );
963 ::GmfGetLin(iMesh, what, x, y, z, domain );
966 //================================================================================
968 * \brief Return coordinates of a next node
970 //================================================================================
972 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
973 float* x, float* y, float *z, int* domain )
978 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
985 ::GmfGetLin(iMesh, what, x, y, z, domain );
988 //================================================================================
990 * \brief Return node index of a next corner
992 //================================================================================
994 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
998 _libData->ReadCorner( node );
1002 ::GmfGetLin(iMesh, what, node );
1005 //================================================================================
1007 * \brief Return node indices of a next edge
1009 //================================================================================
1011 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1015 _libData->ReadEdgeNodes( node1, node2, domain );
1019 ::GmfGetLin( iMesh, what, node1, node2, domain );
1022 //================================================================================
1024 * \brief Return node indices of a next triangle
1026 //================================================================================
1028 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1029 int* node1, int* node2, int* node3, int* domain )
1033 _libData->ReadTriaNodes( node1, node2, node3, domain );
1037 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1040 //================================================================================
1042 * \brief Return node indices of a next tetrahedron or quadrangle
1044 //================================================================================
1046 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1047 int* node1, int* node2, int* node3, int* node4, int* domain )
1051 if ( what == GmfQuadrilaterals )
1052 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1054 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1058 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1061 //================================================================================
1063 * \brief Return node indices of a next hexahedron
1065 //================================================================================
1067 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
1068 int* node1, int* node2, int* node3, int* node4,
1069 int* node5, int* node6, int* node7, int* node8,
1074 _libData->ReadHexaNodes( node1, node2, node3, node4,
1075 node5, node6, node7, node8, domain );
1079 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1082 //================================================================================
1084 * \brief Prepare for passing data to MeshGems
1086 //================================================================================
1088 int MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1095 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1096 _openFiles.insert( id );
1100 //================================================================================
1102 * \brief Set number of entities
1104 //================================================================================
1106 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1108 if ( iMesh == 1 && _isMesh )
1111 case GmfVertices: _nbNodes = nb; break;
1112 case GmfEdges: _nbEdges = nb; break;
1113 case GmfTriangles: _nbFaces = nb; break;
1121 case GmfVertices: _libData->SetNbVertices( nb ); break;
1122 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1123 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1124 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1125 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1131 ::GmfSetKwd(iMesh, what, nb );
1134 //================================================================================
1136 * \brief Add coordinates of a node
1138 //================================================================================
1140 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1144 _libData->AddNode( x, y, z, domain );
1148 ::GmfSetLin(iMesh, what, x, y, z, domain);
1151 //================================================================================
1153 * \brief Set number of field entities
1154 * \param [in] iMesh - solution file index
1155 * \param [in] what - solution type
1156 * \param [in] nbNodes - nb of entities
1157 * \param [in] nbTypes - nb of data entries in each entity
1158 * \param [in] type - types of the data entries
1160 * Used to prepare to storing size at nodes
1162 //================================================================================
1164 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1168 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1172 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1175 //================================================================================
1177 * \brief Add solution data
1179 //================================================================================
1181 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1185 _libData->AddSizeAtNode( vals[0] );
1189 ::GmfSetLin(iMesh, what, vals);
1192 //================================================================================
1194 * \brief Add edge nodes
1196 //================================================================================
1198 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1202 _libData->AddEdgeNodes( node1, node2, domain );
1206 ::GmfSetLin(iMesh, what, node1, node2, domain );
1209 //================================================================================
1211 * \brief Add a 'required' flag
1213 //================================================================================
1215 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1222 ::GmfSetLin(iMesh, what, id );
1225 //================================================================================
1227 * \brief Add triangle nodes
1229 //================================================================================
1231 void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1235 _libData->AddTriaNodes( node1, node2, node3, domain );
1239 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1242 //================================================================================
1244 * \brief Close a file
1246 //================================================================================
1248 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
1258 ::GmfCloseMesh( iMesh );
1259 _openFiles.erase( iMesh );
1262 //================================================================================
1264 * \brief Return true if the log is not empty
1266 //================================================================================
1268 bool MG_Hexotic_API::HasLog()
1272 return !_libData->GetErrors().empty();
1275 SMESH_File file( _logFile );
1276 return file.size() > 0;
1279 //================================================================================
1281 * \brief Return log contents
1283 //================================================================================
1285 std::string MG_Hexotic_API::GetLog()
1289 const std::string& err = _libData->GetErrors();
1290 if ( !_logFile.empty() && !err.empty() )
1292 SMESH_File file( _logFile, /*openForReading=*/false );
1293 file.openForWriting();
1294 file.write( err.c_str(), err.size() );
1299 SMESH_File file( _logFile );
1300 return file.getPos();