1 // Copyright (C) 2004-2024 CEA, EDF
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_Tetra_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/tetra.h>
43 struct MG_Tetra_API::LibData
47 tetra_session_t * _session;
53 std::vector<double> _xyz;
54 std::vector<double> _nodeSize; // required nodes
55 std::vector<int> _edgeNodes;
57 std::vector<int> _triaNodes;
59 std::vector<int> _tetraNodes;
62 volatile bool& _cancelled_flag;
63 std::string _errorStr;
65 bool _progressInCallBack;
67 LibData( volatile bool & cancelled_flag, double& progress )
68 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _tetra_mesh(0),
69 _nbRequiredEdges(0), _nbRequiredTria(0),
70 _cancelled_flag( cancelled_flag ), _progress( progress ), _progressInCallBack( false )
73 // methods setting callbacks implemented after callback definitions
80 tetra_regain_mesh( _session, _tetra_mesh );
82 tetra_session_delete( _session );
84 mesh_delete( _tria_mesh );
86 sizemap_delete( _sizemap );
88 context_delete( _context );
97 void AddError( const char *txt )
103 const std::string& GetErrors()
108 void MG_Error(const char* txt="")
110 SMESH_Comment msg("\nMeshGems error. ");
112 AddError( msg.c_str() );
115 bool SetParam( const std::string& param, const std::string& value )
117 status_t ret = tetra_set_param( _session, param.c_str(), value.c_str() );
119 //std::cout << param << " = " << value << std::endl;
121 return ( ret == STATUS_OK );
126 return _cancelled_flag;
129 int ReadNbSubDomains()
132 status_t ret = mesh_get_subdomain_count( _tetra_mesh, & nb );
134 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
141 status_t ret = mesh_get_vertex_count( _tetra_mesh, & nb );
143 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
150 status_t ret = mesh_get_edge_count( _tetra_mesh, & nb );
152 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
159 status_t ret = mesh_get_triangle_count( _tetra_mesh, & nb );
161 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
168 status_t ret = mesh_get_quadrangle_count( _tetra_mesh, & nb );
170 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
177 status_t ret = mesh_get_tetrahedron_count( _tetra_mesh, & nb );
179 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
186 status_t ret = mesh_get_hexahedron_count( _tetra_mesh, & nb );
188 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
197 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
199 integer tag, seed_type, seed_idx, seed_orientation;
200 status_t ret = mesh_get_subdomain_description( _tetra_mesh, _count,
201 &tag, &seed_type, &seed_idx, &seed_orientation);
203 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
208 *ori = seed_orientation;
212 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
215 status_t ret = mesh_get_vertex_coordinates( _tetra_mesh, _count, coo );
216 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
225 void ReadEdgeNodes( int* node1, int* node2, int* domain )
228 status_t ret = mesh_get_edge_vertices( _tetra_mesh, _count, vtx);
229 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
234 ret = mesh_get_edge_tag( _tetra_mesh, _count, &tag );
235 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
242 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
245 status_t ret = mesh_get_triangle_vertices( _tetra_mesh, _count, vtx);
246 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
252 ret = mesh_get_triangle_tag( _tetra_mesh, _count, &tag );
253 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
260 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
263 status_t ret = mesh_get_quadrangle_vertices( _tetra_mesh, _count, vtx);
264 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
271 ret = mesh_get_quadrangle_tag( _tetra_mesh, _count, &tag );
272 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
279 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
282 status_t ret = mesh_get_tetrahedron_vertices( _tetra_mesh, _count, vtx);
283 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
290 ret = mesh_get_tetrahedron_tag( _tetra_mesh, _count, &tag );
291 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
298 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
299 int* node5, int* node6, int* node7, int* node8, int* domain )
302 status_t ret = mesh_get_hexahedron_vertices( _tetra_mesh, _count, vtx);
303 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
314 ret = mesh_get_hexahedron_tag( _tetra_mesh, _count, &tag );
315 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
322 void SetNbVertices( int nb )
324 _xyz.reserve( _xyz.capacity() + nb );
327 void SetNbEdges( int nb )
329 _edgeNodes.reserve( nb * 2 );
332 void SetNbTria( int nb )
334 _triaNodes.reserve( nb * 3 );
337 void SetNbTetra( int nb )
339 _tetraNodes.reserve( nb * 4 );
342 void SetNbReqVertices( int nb )
344 _nodeSize.reserve( nb );
347 void SetNbReqEdges( int nb )
349 _nbRequiredEdges = nb;
352 void SetNbReqTria( int nb )
354 _nbRequiredTria = nb;
357 void AddNode( double x, double y, double z, int /*domain*/ )
364 void AddSizeAtNode( double size )
366 _nodeSize.push_back( size );
369 void AddEdgeNodes( int node1, int node2, int /*domain*/ )
371 _edgeNodes.push_back( node1 );
372 _edgeNodes.push_back( node2 );
375 void AddTriaNodes( int node1, int node2, int node3, int /*domain*/ )
377 _triaNodes.push_back( node1 );
378 _triaNodes.push_back( node2 );
379 _triaNodes.push_back( node3 );
382 void AddTetraNodes( int node1, int node2, int node3, int node4, int /*domain*/ )
384 _tetraNodes.push_back( node1 );
385 _tetraNodes.push_back( node2 );
386 _tetraNodes.push_back( node3 );
387 _tetraNodes.push_back( node4 );
392 return _xyz.size() / 3;
395 double* NodeCoord( int iNode )
397 return & _xyz[ iNode * 3 ];
402 return _edgeNodes.size() / 2;
405 int* GetEdgeNodes( int iEdge )
407 return & _edgeNodes[ iEdge * 2 ];
412 return _triaNodes.size() / 3;
417 return _tetraNodes.size() / 4;
420 int * GetTriaNodes( int iTria )
422 return & _triaNodes[ iTria * 3 ];
425 int * GetTetraNodes( int iTet )
427 return & _tetraNodes[ iTet * 4 ];
430 int IsVertexRequired( int iNode )
432 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
435 double GetSizeAtVertex( int iNode )
437 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
441 namespace // functions called by MG library to exchange with the application
443 status_t get_vertex_count(integer * nbvtx, void *user_data)
445 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
446 *nbvtx = data->NbNodes();
451 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
453 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
454 double* coord = data->NodeCoord( ivtx-1 );
455 for (int j = 0; j < 3; j++)
460 status_t get_edge_count(integer * nbedge, void *user_data)
462 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
463 *nbedge = data->NbEdges();
468 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
470 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
471 int* nodes = data->GetEdgeNodes( iedge-1 );
478 status_t get_triangle_count(integer * nbtri, void *user_data)
480 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
481 *nbtri = data->NbTriangles();
486 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
488 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
489 int* nodes = data->GetTriaNodes( itri-1 );
497 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
498 // integer * evtri, void *user_data)
501 // MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
504 // /* We want to describe a linear "3 nodes" triangle */
505 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
507 // /* We want to describe a quadratic "6 nodes" triangle */
508 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
509 // for (j = 0; j < 3; j++)
510 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
516 status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
518 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
519 *nbtetra = data->NbTetra();
524 status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
528 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
529 int* nodes = data->GetTetraNodes( itetra-1 );
530 for (j = 0; j < 4; j++)
531 vtetra[j] = nodes[j];
536 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
538 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
539 *rvtx = data->IsVertexRequired( ivtx - 1 );
544 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
546 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
547 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
552 status_t my_message_cb(message_t * msg, void *user_data)
555 message_get_description(msg, &desc);
557 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
558 data->AddError( desc );
561 //std::cout << desc << std::endl;
564 if ( strncmp( "MGMESSAGE 1009001 ", desc, 19 ) == 0 )
566 // progress message (10%): "MGMESSAGE 1009001 0 1 1.000000e+01"
567 data->_progress = atof( desc + 24 );
569 data->_progressInCallBack = true;
572 if ( !data->_progressInCallBack )
575 // corresponding messages are:
576 // " -- PHASE 1 COMPLETED" => 10 %
577 // " -- PHASE 2 COMPLETED" => 25 %
578 // " ** ITERATION 1" => 25.* %
579 // " ** ITERATION 2" => 25.* %
580 // " -- PHASE 3 COMPLETED" => 70 %
581 // " -- PHASE 4 COMPLETED" => 98 %
583 if ( strncmp( "-- PHASE ", desc + 2, 9 ) == 0 && desc[ 13 ] == 'C' )
585 const double progress[] = { 10., 25., 70., 98., 100., 100., 100. };
586 int phase = atoi( desc + 11 );
587 data->_progress = std::max( data->_progress, progress[ phase - 1 ] / 100. );
589 else if ( strncmp( "** ITERATION ", desc + 5, 13 ) == 0 )
591 int iter = atoi( desc + 20 );
592 double percent = 25. + iter * ( 70 - 25 ) / 20.;
593 data->_progress = std::max( data->_progress, ( percent / 100. ));
600 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
602 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
603 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
612 void MG_Tetra_API::LibData::Init()
616 // Create the meshgems working context
617 _context = context_new();
618 if ( !_context ) MG_Error( "unable to create a new context" );
620 // Set the message callback for the _context.
621 ret = context_set_message_callback( _context, my_message_cb, this );
622 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
624 // Create the structure holding the callbacks giving access to triangle mesh
625 _tria_mesh = mesh_new( _context );
626 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
628 // Set callbacks to provide triangle mesh data
629 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
630 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
631 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
632 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
633 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
634 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
635 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
636 mesh_set_get_tetrahedron_count( _tria_mesh, get_tetrahedron_count, this );
637 mesh_set_get_tetrahedron_vertices( _tria_mesh, get_tetrahedron_vertices, this );
639 // Create a tetra session
640 _session = tetra_session_new( _context );
641 if ( !_session ) MG_Error( "unable to create a new tetra session");
643 ret = tetra_set_interrupt_callback( _session, my_interrupt_callback, this );
644 if ( ret != STATUS_OK ) MG_Error("in tetra_set_interrupt_callback");
648 bool MG_Tetra_API::LibData::Compute()
651 std::string errorTxt;
653 if ( _tetraNodes.empty() )
655 // Sign the surface mesh
656 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, "tetra", errorTxt ))
658 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
662 ret = tetra_set_surface_mesh( _session, _tria_mesh );
663 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
667 // Sign the volume mesh
668 // TOOD: check if there is a typo here. Should be _tetra_mesh ?
669 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, "tetra", errorTxt ))
671 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
674 // TOOD: check if there is a typo here. Should be _tetra_mesh ?
675 ret = tetra_set_volume_mesh( _session, _tria_mesh );
676 if ( ret != STATUS_OK ) MG_Error( "unable to set volume mesh");
680 if ( !_nodeSize.empty() )
682 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
683 (void*) &get_vertex_weight, this );
684 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
686 ret = tetra_set_sizemap( _session, _sizemap );
687 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
690 //////////////////////////////////////////////////////////////////////////////////////////
691 // const char* file = "/tmp/ghs3d_IN.mesh";
692 // mesh_write_mesh( _tria_mesh,file);
693 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
695 ret = tetra_compute_mesh( _session );
696 if ( ret != STATUS_OK ) return false;
698 ret = tetra_get_mesh( _session, &_tetra_mesh);
699 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
701 //////////////////////////////////////////////////////////////////////////////////////////
703 // const char* file = "/tmp/ghs3d_OUT.mesh";
704 // mesh_write_mesh( _tetra_mesh,file);
705 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
710 #else // ifdef USE_MG_LIBS
712 struct MG_Tetra_API::LibData // to avoid compiler warnings
714 volatile bool& _cancelled_flag;
716 LibData(volatile bool& cancelled_flag, double& progress):
717 _cancelled_flag{cancelled_flag}, _progress{progress}
721 #endif // ifdef USE_MG_LIBS
724 //================================================================================
728 //================================================================================
730 MG_Tetra_API::MG_Tetra_API(volatile bool& cancelled_flag, double& progress):
731 _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
734 _libData = new LibData( cancelled_flag, progress );
738 if ( getenv("MG_TETRA_USE_EXE"))
743 //================================================================================
747 //================================================================================
749 MG_Tetra_API::~MG_Tetra_API()
755 std::set<int>::iterator id = _openFiles.begin();
756 for ( ; id != _openFiles.end(); ++id )
757 ::GmfCloseMesh( *id );
761 //================================================================================
763 * \brief Return the way of MG usage
765 //================================================================================
767 bool MG_Tetra_API::IsLibrary()
772 //================================================================================
774 * \brief Switch to usage of MG-Tetra executable
776 //================================================================================
778 void MG_Tetra_API::SetUseExecutable()
783 //================================================================================
785 * \brief Compute the tetra mesh
786 * \param [in] cmdLine - a command to run mg_tetra.exe
787 * \return bool - Ok or not
789 //================================================================================
791 bool MG_Tetra_API::Compute( const std::string& cmdLine, std::string& errStr )
797 std::istringstream strm( cmdLine );
798 std::istream_iterator<std::string> sIt( strm ), sEnd;
799 std::vector< std::string > args( sIt, sEnd );
802 std::string param, value;
803 for ( size_t i = 1; i < args.size(); ++i )
805 // look for a param name; it starts from "-"
807 if ( param.size() < 2 || param[0] != '-')
809 while ( param[0] == '-')
810 param = param.substr( 1 );
813 while ( i+1 < args.size() && args[i+1][0] != '-' )
815 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
817 if ( !value.empty() ) value += " ";
820 if ( !_libData->SetParam( param, value ))
821 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
825 bool ok = _libData->Compute();
827 GetLog(); // write a log file
828 _logFile = ""; // not to write it again
834 // add MG license key
836 std::string errorTxt, meshIn;
837 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
838 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
842 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-tetra.exe ...) command failed with error: ")
854 << strerror( errno );
860 //================================================================================
862 * \brief Prepare for reading a mesh data
864 //================================================================================
866 int MG_Tetra_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_Tetra_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();
902 return ::GmfStatKwd( iMesh, what );
905 //================================================================================
907 * \brief Prepare for reading some data
909 //================================================================================
911 void MG_Tetra_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
915 _libData->ResetCounter();
919 ::GmfGotoKwd( iMesh, what );
922 //================================================================================
924 * \brief Return index of a domain identified by a triangle normal
925 * \param [in] iMesh - mesh file index
926 * \param [in] what - must be GmfSubDomainFromGeom
927 * \param [out] nbNodes - nb nodes in a face
928 * \param [out] faceInd - face index
929 * \param [out] ori - face orientation
930 * \param [out] domain - domain index
931 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
934 //================================================================================
936 void MG_Tetra_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
940 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
944 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
947 //================================================================================
949 * \brief Return coordinates of a next node
951 //================================================================================
953 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
954 double* x, double* y, double *z, int* domain )
958 _libData->ReadNodeXYZ( x, y, z, domain );
962 ::GmfGetLin(iMesh, what, x, y, z, domain );
965 //================================================================================
967 * \brief Return coordinates of a next node
969 //================================================================================
971 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
972 float* x, float* y, float *z, int* domain )
977 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
984 ::GmfGetLin(iMesh, what, x, y, z, domain );
987 //================================================================================
989 * \brief Return node index of a next corner
991 //================================================================================
993 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
1001 ::GmfGetLin(iMesh, what, node );
1004 //================================================================================
1006 * \brief Return node indices of a next edge
1008 //================================================================================
1010 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1014 _libData->ReadEdgeNodes( node1, node2, domain );
1018 ::GmfGetLin( iMesh, what, node1, node2, domain );
1021 //================================================================================
1023 * \brief Return node indices of a next triangle
1025 //================================================================================
1027 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1028 int* node1, int* node2, int* node3, int* domain )
1032 _libData->ReadTriaNodes( node1, node2, node3, domain );
1036 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1039 //================================================================================
1041 * \brief Return node indices of a next tetrahedron or quadrangle
1043 //================================================================================
1045 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1046 int* node1, int* node2, int* node3, int* node4, int* domain )
1050 if ( what == GmfQuadrilaterals )
1051 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1053 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1057 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1060 //================================================================================
1062 * \brief Return node indices of a next hexahedron
1064 //================================================================================
1066 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1067 int* node1, int* node2, int* node3, int* node4,
1068 int* node5, int* node6, int* node7, int* node8,
1073 _libData->ReadHexaNodes( node1, node2, node3, node4,
1074 node5, node6, node7, node8, domain );
1078 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1081 //================================================================================
1083 * \brief Prepare for passing data to MeshGems
1085 //================================================================================
1087 int MG_Tetra_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1094 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1095 _openFiles.insert( id );
1099 //================================================================================
1101 * \brief Set number of entities
1103 //================================================================================
1105 void MG_Tetra_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1110 case GmfVertices: _nbNodes += nb; break;
1111 case GmfEdges: _nbEdges += nb; break;
1112 case GmfTriangles: _nbFaces += nb; break;
1113 case GmfTetrahedra: _nbVolumes += 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_Tetra_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_Tetra_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_Tetra_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_Tetra_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_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1222 ::GmfSetLin(iMesh, what, id );
1225 //================================================================================
1227 * \brief Add triangle nodes
1229 //================================================================================
1231 void MG_Tetra_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 Add tetra nodes
1246 //================================================================================
1248 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what,
1249 int node1, int node2, int node3, int node4, int domain )
1253 _libData->AddTetraNodes( node1, node2, node3, node4, domain );
1257 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1260 //================================================================================
1262 * \brief Close a file
1264 //================================================================================
1266 void MG_Tetra_API::GmfCloseMesh( int iMesh )
1273 ::GmfCloseMesh( iMesh );
1274 _openFiles.erase( iMesh );
1277 //================================================================================
1279 * \brief Return true if the log is not empty
1281 //================================================================================
1283 bool MG_Tetra_API::HasLog()
1287 return !_libData->GetErrors().empty();
1290 SMESH_File file( _logFile );
1291 return file.size() > 0;
1294 //================================================================================
1296 * \brief Return log contents
1298 //================================================================================
1300 std::string MG_Tetra_API::GetLog()
1304 const std::string& err = _libData->GetErrors();
1305 if ( !_logFile.empty() && !err.empty() )
1307 SMESH_File file( _logFile, /*openForReading=*/false );
1308 file.openForWriting();
1309 file.write( err.c_str(), err.size() );
1314 SMESH_File file( _logFile );
1315 return file.getPos();