1 // Copyright (C) 2004-2019 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_Tetra_API.hxx"
25 #include <SMESH_Comment.hxx>
26 #include <SMESH_File.hxx>
27 #include <Utils_SALOME_Exception.hxx>
36 #include <meshgems/meshgems.h>
37 #include <meshgems/tetra.h>
40 struct MG_Tetra_API::LibData
44 tetra_session_t * _session;
50 std::vector<double> _xyz;
51 std::vector<double> _nodeSize; // required nodes
52 std::vector<int> _edgeNodes;
54 std::vector<int> _triaNodes;
56 std::vector<int> _tetraNodes;
59 volatile bool& _cancelled_flag;
60 std::string _errorStr;
62 bool _progressInCallBack;
64 LibData( volatile bool & cancelled_flag, double& progress )
65 : _context(0), _session(0), _tria_mesh(0), _sizemap(0), _tetra_mesh(0),
66 _nbRequiredEdges(0), _nbRequiredTria(0),
67 _cancelled_flag( cancelled_flag ), _progress( progress ), _progressInCallBack( false )
70 // methods setting callbacks implemented after callback definitions
77 tetra_regain_mesh( _session, _tetra_mesh );
79 tetra_session_delete( _session );
81 mesh_delete( _tria_mesh );
83 sizemap_delete( _sizemap );
85 context_delete( _context );
94 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 = tetra_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( _tetra_mesh, & nb );
131 if ( ret != STATUS_OK ) MG_Error("mesh_get_subdomain_count problem");
138 status_t ret = mesh_get_vertex_count( _tetra_mesh, & nb );
140 if ( ret != STATUS_OK ) MG_Error("mesh_get_vertex_count problem");
147 status_t ret = mesh_get_edge_count( _tetra_mesh, & nb );
149 if ( ret != STATUS_OK ) MG_Error("mesh_get_edge_count problem");
156 status_t ret = mesh_get_triangle_count( _tetra_mesh, & nb );
158 if ( ret != STATUS_OK ) MG_Error("mesh_get_triangle_count problem");
165 status_t ret = mesh_get_quadrangle_count( _tetra_mesh, & nb );
167 if ( ret != STATUS_OK ) MG_Error("mesh_get_quadrangle_count problem");
174 status_t ret = mesh_get_tetrahedron_count( _tetra_mesh, & nb );
176 if ( ret != STATUS_OK ) MG_Error("mesh_get_tetrahedron_count problem");
183 status_t ret = mesh_get_hexahedron_count( _tetra_mesh, & nb );
185 if ( ret != STATUS_OK ) MG_Error("mesh_get_hexahedron_count problem");
194 void ReadSubDomain( int* nbNodes, int* faceInd, int* ori, int* domain )
196 integer tag, seed_type, seed_idx, seed_orientation;
197 status_t ret = mesh_get_subdomain_description( _tetra_mesh, _count,
198 &tag, &seed_type, &seed_idx, &seed_orientation);
200 if ( ret != STATUS_OK ) MG_Error( "unable to get a sub-domain description");
205 *ori = seed_orientation;
209 void ReadNodeXYZ( double* x, double* y, double *z, int* /*domain*/ )
212 status_t ret = mesh_get_vertex_coordinates( _tetra_mesh, _count, coo );
213 if ( ret != STATUS_OK ) MG_Error( "unable to get resulting vertices" );
222 void ReadEdgeNodes( int* node1, int* node2, int* domain )
225 status_t ret = mesh_get_edge_vertices( _tetra_mesh, _count, vtx);
226 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge" );
231 ret = mesh_get_edge_tag( _tetra_mesh, _count, &tag );
232 if (ret != STATUS_OK) MG_Error( "unable to get resulting edge tag" );
239 void ReadTriaNodes( int* node1, int* node2, int* node3, int* domain )
242 status_t ret = mesh_get_triangle_vertices( _tetra_mesh, _count, vtx);
243 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle" );
249 ret = mesh_get_triangle_tag( _tetra_mesh, _count, &tag );
250 if (ret != STATUS_OK) MG_Error( "unable to get resulting triangle tag" );
257 void ReadQuadNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
260 status_t ret = mesh_get_quadrangle_vertices( _tetra_mesh, _count, vtx);
261 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle" );
268 ret = mesh_get_quadrangle_tag( _tetra_mesh, _count, &tag );
269 if (ret != STATUS_OK) MG_Error( "unable to get resulting quadrangle tag" );
276 void ReadTetraNodes( int* node1, int* node2, int* node3, int* node4, int* domain )
279 status_t ret = mesh_get_tetrahedron_vertices( _tetra_mesh, _count, vtx);
280 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron" );
287 ret = mesh_get_tetrahedron_tag( _tetra_mesh, _count, &tag );
288 if (ret != STATUS_OK) MG_Error( "unable to get resulting tetrahedron tag" );
295 void ReadHexaNodes( int* node1, int* node2, int* node3, int* node4,
296 int* node5, int* node6, int* node7, int* node8, int* domain )
299 status_t ret = mesh_get_hexahedron_vertices( _tetra_mesh, _count, vtx);
300 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron" );
311 ret = mesh_get_hexahedron_tag( _tetra_mesh, _count, &tag );
312 if (ret != STATUS_OK) MG_Error( "unable to get resulting hexahedron tag" );
319 void SetNbVertices( int nb )
321 _xyz.reserve( _xyz.capacity() + nb );
324 void SetNbEdges( int nb )
326 _edgeNodes.reserve( nb * 2 );
329 void SetNbTria( int nb )
331 _triaNodes.reserve( nb * 3 );
334 void SetNbTetra( int nb )
336 _tetraNodes.reserve( nb * 4 );
339 void SetNbReqVertices( int nb )
341 _nodeSize.reserve( nb );
344 void SetNbReqEdges( int nb )
346 _nbRequiredEdges = nb;
349 void SetNbReqTria( int nb )
351 _nbRequiredTria = nb;
354 void AddNode( double x, double y, double z, int domain )
361 void AddSizeAtNode( double size )
363 _nodeSize.push_back( size );
366 void AddEdgeNodes( int node1, int node2, int domain )
368 _edgeNodes.push_back( node1 );
369 _edgeNodes.push_back( node2 );
372 void AddTriaNodes( int node1, int node2, int node3, int domain )
374 _triaNodes.push_back( node1 );
375 _triaNodes.push_back( node2 );
376 _triaNodes.push_back( node3 );
379 void AddTetraNodes( int node1, int node2, int node3, int node4, int domain )
381 _tetraNodes.push_back( node1 );
382 _tetraNodes.push_back( node2 );
383 _tetraNodes.push_back( node3 );
384 _tetraNodes.push_back( node4 );
389 return _xyz.size() / 3;
392 double* NodeCoord( int iNode )
394 return & _xyz[ iNode * 3 ];
399 return _edgeNodes.size() / 2;
402 int* GetEdgeNodes( int iEdge )
404 return & _edgeNodes[ iEdge * 2 ];
409 return _triaNodes.size() / 3;
414 return _tetraNodes.size() / 4;
417 int * GetTriaNodes( int iTria )
419 return & _triaNodes[ iTria * 3 ];
422 int * GetTetraNodes( int iTet )
424 return & _tetraNodes[ iTet * 4 ];
427 int IsVertexRequired( int iNode )
429 return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
432 double GetSizeAtVertex( int iNode )
434 return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
438 namespace // functions called by MG library to exchange with the application
440 status_t get_vertex_count(integer * nbvtx, void *user_data)
442 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
443 *nbvtx = data->NbNodes();
448 status_t get_vertex_coordinates(integer ivtx, real * xyz, void *user_data)
450 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
451 double* coord = data->NodeCoord( ivtx-1 );
452 for (int j = 0; j < 3; j++)
457 status_t get_edge_count(integer * nbedge, void *user_data)
459 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
460 *nbedge = data->NbEdges();
465 status_t get_edge_vertices(integer iedge, integer * vedge, void *user_data)
467 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
468 int* nodes = data->GetEdgeNodes( iedge-1 );
475 status_t get_triangle_count(integer * nbtri, void *user_data)
477 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
478 *nbtri = data->NbTriangles();
483 status_t get_triangle_vertices(integer itri, integer * vtri, void *user_data)
485 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
486 int* nodes = data->GetTriaNodes( itri-1 );
494 // status_t get_triangle_extra_vertices(integer itri, integer * typetri,
495 // integer * evtri, void *user_data)
498 // MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
501 // /* We want to describe a linear "3 nodes" triangle */
502 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA3;
504 // /* We want to describe a quadratic "6 nodes" triangle */
505 // *typetri = MESHGEMS_MESH_ELEMENT_TYPE_TRIA6;
506 // for (j = 0; j < 3; j++)
507 // evtri[j] = 0; /* the j'th quadratic vertex index of the itri'th triangle */
513 status_t get_tetrahedron_count(integer * nbtetra, void *user_data)
515 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
516 *nbtetra = data->NbTetra();
521 status_t get_tetrahedron_vertices(integer itetra, integer * vtetra,
525 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
526 int* nodes = data->GetTetraNodes( itetra-1 );
527 for (j = 0; j < 4; j++)
528 vtetra[j] = nodes[j];
533 status_t get_vertex_required_property(integer ivtx, integer * rvtx, void *user_data)
535 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
536 *rvtx = data->IsVertexRequired( ivtx - 1 );
541 status_t get_vertex_weight(integer ivtx, real * wvtx, void *user_data)
543 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
544 *wvtx = data->GetSizeAtVertex( ivtx - 1 );
549 status_t my_message_cb(message_t * msg, void *user_data)
552 message_get_description(msg, &desc);
554 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
555 data->AddError( desc );
558 //std::cout << desc << std::endl;
561 if ( strncmp( "MGMESSAGE 1009001 ", desc, 19 ) == 0 )
563 // progress message (10%): "MGMESSAGE 1009001 0 1 1.000000e+01"
564 data->_progress = atof( desc + 24 );
566 _progressInCallBack = true;
569 if ( !_progressInCallBack )
572 // corresponding messages are:
573 // " -- PHASE 1 COMPLETED" => 10 %
574 // " -- PHASE 2 COMPLETED" => 25 %
575 // " ** ITERATION 1" => 25.* %
576 // " ** ITERATION 2" => 25.* %
577 // " -- PHASE 3 COMPLETED" => 70 %
578 // " -- PHASE 4 COMPLETED" => 98 %
580 if ( strncmp( "-- PHASE ", desc + 2, 9 ) == 0 && desc[ 13 ] == 'C' )
582 const double progress[] = { 10., 25., 70., 98., 100., 100., 100. };
583 int phase = atoi( desc + 11 );
584 data->_progress = std::max( data->_progress, progress[ phase - 1 ] / 100. );
586 else if ( strncmp( "** ITERATION ", desc + 5, 13 ) == 0 )
588 int iter = atoi( desc + 20 );
589 double percent = 25. + iter * ( 70 - 25 ) / 20.;
590 data->_progress = std::max( data->_progress, ( percent / 100. ));
597 status_t my_interrupt_callback(integer *interrupt_status, void *user_data)
599 MG_Tetra_API::LibData* data = (MG_Tetra_API::LibData *) user_data;
600 *interrupt_status = ( data->Cancelled() ? INTERRUPT_STOP : INTERRUPT_CONTINUE );
609 void MG_Tetra_API::LibData::Init()
613 // Create the meshgems working context
614 _context = context_new();
615 if ( !_context ) MG_Error( "unable to create a new context" );
617 // Set the message callback for the _context.
618 ret = context_set_message_callback( _context, my_message_cb, this );
619 if ( ret != STATUS_OK ) MG_Error("in context_set_message_callback");
621 // Create the structure holding the callbacks giving access to triangle mesh
622 _tria_mesh = mesh_new( _context );
623 if ( !_tria_mesh ) MG_Error("unable to create a new mesh");
625 // Set callbacks to provide triangle mesh data
626 mesh_set_get_vertex_count( _tria_mesh, get_vertex_count, this );
627 mesh_set_get_vertex_coordinates( _tria_mesh, get_vertex_coordinates, this );
628 mesh_set_get_vertex_required_property( _tria_mesh, get_vertex_required_property, this );
629 mesh_set_get_edge_count( _tria_mesh, get_edge_count, this);
630 mesh_set_get_edge_vertices( _tria_mesh, get_edge_vertices, this );
631 mesh_set_get_triangle_count( _tria_mesh, get_triangle_count, this );
632 mesh_set_get_triangle_vertices( _tria_mesh, get_triangle_vertices, this );
633 mesh_set_get_tetrahedron_count( _tria_mesh, get_tetrahedron_count, this );
634 mesh_set_get_tetrahedron_vertices( _tria_mesh, get_tetrahedron_vertices, this );
636 // Create a tetra session
637 _session = tetra_session_new( _context );
638 if ( !_session ) MG_Error( "unable to create a new tetra session");
640 ret = tetra_set_interrupt_callback( _session, my_interrupt_callback, this );
641 if ( ret != STATUS_OK ) MG_Error("in tetra_set_interrupt_callback");
645 bool MG_Tetra_API::LibData::Compute()
649 if ( _tetraNodes.empty() )
652 ret = tetra_set_surface_mesh( _session, _tria_mesh );
653 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
657 ret = tetra_set_volume_mesh( _session, _tria_mesh );
658 if ( ret != STATUS_OK ) MG_Error( "unable to set volume mesh");
662 if ( !_nodeSize.empty() )
664 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
665 (void*) &get_vertex_weight, this );
666 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
668 ret = tetra_set_sizemap( _session, _sizemap );
669 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
672 //////////////////////////////////////////////////////////////////////////////////////////
673 // const char* file = "/tmp/ghs3d_IN.mesh";
674 // mesh_write_mesh( _tria_mesh,file);
675 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
677 ret = tetra_compute_mesh( _session );
678 if ( ret != STATUS_OK ) return false;
680 ret = tetra_get_mesh( _session, &_tetra_mesh);
681 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
683 //////////////////////////////////////////////////////////////////////////////////////////
685 // const char* file = "/tmp/ghs3d_OUT.mesh";
686 // mesh_write_mesh( _tetra_mesh,file);
687 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
693 #endif // ifdef USE_MG_LIBS
696 //================================================================================
700 //================================================================================
702 MG_Tetra_API::MG_Tetra_API(volatile bool& cancelled_flag, double& progress)
707 _libData = new LibData( cancelled_flag, progress );
709 if ( getenv("MG_TETRA_USE_EXE"))
714 //================================================================================
718 //================================================================================
720 MG_Tetra_API::~MG_Tetra_API()
726 std::set<int>::iterator id = _openFiles.begin();
727 for ( ; id != _openFiles.end(); ++id )
728 ::GmfCloseMesh( *id );
732 //================================================================================
734 * \brief Return the way of MG usage
736 //================================================================================
738 bool MG_Tetra_API::IsLibrary()
743 //================================================================================
745 * \brief Switch to usage of MG-Tetra executable
747 //================================================================================
749 void MG_Tetra_API::SetUseExecutable()
754 //================================================================================
756 * \brief Compute the tetra mesh
757 * \param [in] cmdLine - a command to run mg_tetra.exe
758 * \return bool - Ok or not
760 //================================================================================
762 bool MG_Tetra_API::Compute( const std::string& cmdLine, std::string& errStr )
768 std::istringstream strm( cmdLine );
769 std::istream_iterator<std::string> sIt( strm ), sEnd;
770 std::vector< std::string > args( sIt, sEnd );
773 std::string param, value;
774 for ( size_t i = 1; i < args.size(); ++i )
776 // look for a param name; it starts from "-"
778 if ( param.size() < 2 || param[0] != '-')
780 while ( param[0] == '-')
781 param = param.substr( 1 );
784 while ( i+1 < args.size() && args[i+1][0] != '-' )
786 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
788 if ( !value.empty() ) value += " ";
791 if ( !_libData->SetParam( param, value ))
792 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
796 bool ok = _libData->Compute();
798 GetLog(); // write a log file
799 _logFile = ""; // not to write it again
805 int err = system( cmdLine.c_str() ); // run
808 errStr = SMESH_Comment("system(mg-tetra.exe ...) command failed with error: ")
809 << strerror( errno );
815 //================================================================================
817 * \brief Prepare for reading a mesh data
819 //================================================================================
821 int MG_Tetra_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
828 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
829 _openFiles.insert( id );
833 //================================================================================
835 * \brief Return nb of entities
837 //================================================================================
839 int MG_Tetra_API::GmfStatKwd( int iMesh, GmfKwdCod what )
845 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
846 case GmfVertices: return _libData->ReadNbNodes();
847 case GmfEdges: return _libData->ReadNbEdges();
848 case GmfTriangles: return _libData->ReadNbTria();
849 case GmfQuadrilaterals: return _libData->ReadNbQuads();
850 case GmfTetrahedra: return _libData->ReadNbTetra();
851 case GmfHexahedra: return _libData->ReadNbHexa();
857 return ::GmfStatKwd( iMesh, what );
860 //================================================================================
862 * \brief Prepare for reading some data
864 //================================================================================
866 void MG_Tetra_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
870 _libData->ResetCounter();
874 ::GmfGotoKwd( iMesh, what );
877 //================================================================================
879 * \brief Return index of a domain identified by a triangle normal
880 * \param [in] iMesh - mesh file index
881 * \param [in] what - must be GmfSubDomainFromGeom
882 * \param [out] nbNodes - nb nodes in a face
883 * \param [out] faceInd - face index
884 * \param [out] ori - face orientation
885 * \param [out] domain - domain index
886 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
889 //================================================================================
891 void MG_Tetra_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
895 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
899 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
902 //================================================================================
904 * \brief Return coordinates of a next node
906 //================================================================================
908 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
909 double* x, double* y, double *z, int* domain )
913 _libData->ReadNodeXYZ( x, y, z, domain );
917 ::GmfGetLin(iMesh, what, x, y, z, domain );
920 //================================================================================
922 * \brief Return coordinates of a next node
924 //================================================================================
926 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
927 float* x, float* y, float *z, int* domain )
932 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
939 ::GmfGetLin(iMesh, what, x, y, z, domain );
942 //================================================================================
944 * \brief Return node index of a next corner
946 //================================================================================
948 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
956 ::GmfGetLin(iMesh, what, node );
959 //================================================================================
961 * \brief Return node indices of a next edge
963 //================================================================================
965 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
969 _libData->ReadEdgeNodes( node1, node2, domain );
973 ::GmfGetLin( iMesh, what, node1, node2, domain );
976 //================================================================================
978 * \brief Return node indices of a next triangle
980 //================================================================================
982 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
983 int* node1, int* node2, int* node3, int* domain )
987 _libData->ReadTriaNodes( node1, node2, node3, domain );
991 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
994 //================================================================================
996 * \brief Return node indices of a next tetrahedron or quadrangle
998 //================================================================================
1000 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1001 int* node1, int* node2, int* node3, int* node4, int* domain )
1005 if ( what == GmfQuadrilaterals )
1006 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1008 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1012 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1015 //================================================================================
1017 * \brief Return node indices of a next hexahedron
1019 //================================================================================
1021 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1022 int* node1, int* node2, int* node3, int* node4,
1023 int* node5, int* node6, int* node7, int* node8,
1028 _libData->ReadHexaNodes( node1, node2, node3, node4,
1029 node5, node6, node7, node8, domain );
1033 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1036 //================================================================================
1038 * \brief Prepare for passing data to MeshGems
1040 //================================================================================
1042 int MG_Tetra_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1049 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1050 _openFiles.insert( id );
1054 //================================================================================
1056 * \brief Set number of entities
1058 //================================================================================
1060 void MG_Tetra_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1065 case GmfVertices: _libData->SetNbVertices( nb ); break;
1066 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1067 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1068 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1069 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1075 ::GmfSetKwd(iMesh, what, nb );
1078 //================================================================================
1080 * \brief Add coordinates of a node
1082 //================================================================================
1084 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1088 _libData->AddNode( x, y, z, domain );
1092 ::GmfSetLin(iMesh, what, x, y, z, domain);
1095 //================================================================================
1097 * \brief Set number of field entities
1098 * \param [in] iMesh - solution file index
1099 * \param [in] what - solution type
1100 * \param [in] nbNodes - nb of entities
1101 * \param [in] nbTypes - nb of data entries in each entity
1102 * \param [in] type - types of the data entries
1104 * Used to prepare to storing size at nodes
1106 //================================================================================
1108 void MG_Tetra_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1112 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1116 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1119 //================================================================================
1121 * \brief Add solution data
1123 //================================================================================
1125 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1129 _libData->AddSizeAtNode( vals[0] );
1133 ::GmfSetLin(iMesh, what, vals);
1136 //================================================================================
1138 * \brief Add edge nodes
1140 //================================================================================
1142 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1146 _libData->AddEdgeNodes( node1, node2, domain );
1150 ::GmfSetLin(iMesh, what, node1, node2, domain );
1153 //================================================================================
1155 * \brief Add a 'required' flag
1157 //================================================================================
1159 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1166 ::GmfSetLin(iMesh, what, id );
1169 //================================================================================
1171 * \brief Add triangle nodes
1173 //================================================================================
1175 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1179 _libData->AddTriaNodes( node1, node2, node3, domain );
1183 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1186 //================================================================================
1188 * \brief Add tetra nodes
1190 //================================================================================
1192 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what,
1193 int node1, int node2, int node3, int node4, int domain )
1197 _libData->AddTetraNodes( node1, node2, node3, node4, domain );
1201 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1204 //================================================================================
1206 * \brief Close a file
1208 //================================================================================
1210 void MG_Tetra_API::GmfCloseMesh( int iMesh )
1217 ::GmfCloseMesh( iMesh );
1218 _openFiles.erase( iMesh );
1221 //================================================================================
1223 * \brief Return true if the log is not empty
1225 //================================================================================
1227 bool MG_Tetra_API::HasLog()
1231 return !_libData->GetErrors().empty();
1234 SMESH_File file( _logFile );
1235 return file.size() > 0;
1238 //================================================================================
1240 * \brief Return log contents
1242 //================================================================================
1244 std::string MG_Tetra_API::GetLog()
1248 const std::string& err = _libData->GetErrors();
1249 if ( !_logFile.empty() && !err.empty() )
1251 SMESH_File file( _logFile, /*openForReading=*/false );
1252 file.openForWriting();
1253 file.write( err.c_str(), err.size() );
1258 SMESH_File file( _logFile );
1259 return file.getPos();