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_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 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, errorTxt ))
657 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
661 ret = tetra_set_surface_mesh( _session, _tria_mesh );
662 if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
666 if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, errorTxt ))
668 AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
671 ret = tetra_set_volume_mesh( _session, _tria_mesh );
672 if ( ret != STATUS_OK ) MG_Error( "unable to set volume mesh");
676 if ( !_nodeSize.empty() )
678 _sizemap = meshgems_sizemap_new( _tria_mesh, meshgems_sizemap_type_iso_mesh_vertex,
679 (void*) &get_vertex_weight, this );
680 if ( !_sizemap ) MG_Error("unable to create a new sizemap");
682 ret = tetra_set_sizemap( _session, _sizemap );
683 if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
686 //////////////////////////////////////////////////////////////////////////////////////////
687 // const char* file = "/tmp/ghs3d_IN.mesh";
688 // mesh_write_mesh( _tria_mesh,file);
689 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
691 ret = tetra_compute_mesh( _session );
692 if ( ret != STATUS_OK ) return false;
694 ret = tetra_get_mesh( _session, &_tetra_mesh);
695 if (ret != STATUS_OK) MG_Error( "unable to get resulting mesh");
697 //////////////////////////////////////////////////////////////////////////////////////////
699 // const char* file = "/tmp/ghs3d_OUT.mesh";
700 // mesh_write_mesh( _tetra_mesh,file);
701 // std::cout << std::endl << std::endl << "Write " << file << std::endl << std::endl << std::endl;
706 #else // ifdef USE_MG_LIBS
708 struct MG_Tetra_API::LibData // to avoid compiler warnings
710 volatile bool& _cancelled_flag;
712 LibData(volatile bool& cancelled_flag, double& progress):
713 _cancelled_flag{cancelled_flag}, _progress{progress}
717 #endif // ifdef USE_MG_LIBS
720 //================================================================================
724 //================================================================================
726 MG_Tetra_API::MG_Tetra_API(volatile bool& cancelled_flag, double& progress):
727 _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
730 _libData = new LibData( cancelled_flag, progress );
734 if ( getenv("MG_TETRA_USE_EXE"))
739 //================================================================================
743 //================================================================================
745 MG_Tetra_API::~MG_Tetra_API()
751 std::set<int>::iterator id = _openFiles.begin();
752 for ( ; id != _openFiles.end(); ++id )
753 ::GmfCloseMesh( *id );
757 //================================================================================
759 * \brief Return the way of MG usage
761 //================================================================================
763 bool MG_Tetra_API::IsLibrary()
768 //================================================================================
770 * \brief Switch to usage of MG-Tetra executable
772 //================================================================================
774 void MG_Tetra_API::SetUseExecutable()
779 //================================================================================
781 * \brief Compute the tetra mesh
782 * \param [in] cmdLine - a command to run mg_tetra.exe
783 * \return bool - Ok or not
785 //================================================================================
787 bool MG_Tetra_API::Compute( const std::string& cmdLine, std::string& errStr )
793 std::istringstream strm( cmdLine );
794 std::istream_iterator<std::string> sIt( strm ), sEnd;
795 std::vector< std::string > args( sIt, sEnd );
798 std::string param, value;
799 for ( size_t i = 1; i < args.size(); ++i )
801 // look for a param name; it starts from "-"
803 if ( param.size() < 2 || param[0] != '-')
805 while ( param[0] == '-')
806 param = param.substr( 1 );
809 while ( i+1 < args.size() && args[i+1][0] != '-' )
811 if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
813 if ( !value.empty() ) value += " ";
816 if ( !_libData->SetParam( param, value ))
817 std::cout << "Warning: wrong param: '" << param <<"' = '" << value << "'" << std::endl;
821 bool ok = _libData->Compute();
823 GetLog(); // write a log file
824 _logFile = ""; // not to write it again
830 // add MG license key
832 std::string errorTxt, meshIn;
833 std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
834 _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
838 errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
842 const_cast< std::string& >( cmdLine ) += " --key " + key;
845 int err = system( cmdLine.c_str() ); // run
848 errStr = SMESH_Comment("system(mg-tetra.exe ...) command failed with error: ")
849 << strerror( errno );
855 //================================================================================
857 * \brief Prepare for reading a mesh data
859 //================================================================================
861 int MG_Tetra_API::GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim)
868 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim );
869 _openFiles.insert( id );
873 //================================================================================
875 * \brief Return nb of entities
877 //================================================================================
879 int MG_Tetra_API::GmfStatKwd( int iMesh, GmfKwdCod what )
885 case GmfSubDomainFromGeom: return _libData->ReadNbSubDomains();
886 case GmfVertices: return _libData->ReadNbNodes();
887 case GmfEdges: return _libData->ReadNbEdges();
888 case GmfTriangles: return _libData->ReadNbTria();
889 case GmfQuadrilaterals: return _libData->ReadNbQuads();
890 case GmfTetrahedra: return _libData->ReadNbTetra();
891 case GmfHexahedra: return _libData->ReadNbHexa();
897 return ::GmfStatKwd( iMesh, what );
900 //================================================================================
902 * \brief Prepare for reading some data
904 //================================================================================
906 void MG_Tetra_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
910 _libData->ResetCounter();
914 ::GmfGotoKwd( iMesh, what );
917 //================================================================================
919 * \brief Return index of a domain identified by a triangle normal
920 * \param [in] iMesh - mesh file index
921 * \param [in] what - must be GmfSubDomainFromGeom
922 * \param [out] nbNodes - nb nodes in a face
923 * \param [out] faceInd - face index
924 * \param [out] ori - face orientation
925 * \param [out] domain - domain index
926 * \param [in] dummy - an artificial param used to discriminate from GmfGetLin() reading
929 //================================================================================
931 void MG_Tetra_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
935 _libData->ReadSubDomain( nbNodes, faceInd, ori, domain );
939 ::GmfGetLin( iMesh, what, nbNodes, faceInd, ori, domain );
942 //================================================================================
944 * \brief Return coordinates of a next node
946 //================================================================================
948 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
949 double* x, double* y, double *z, int* domain )
953 _libData->ReadNodeXYZ( x, y, z, domain );
957 ::GmfGetLin(iMesh, what, x, y, z, domain );
960 //================================================================================
962 * \brief Return coordinates of a next node
964 //================================================================================
966 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
967 float* x, float* y, float *z, int* domain )
972 _libData->ReadNodeXYZ( &X, &Y, &Z, domain );
979 ::GmfGetLin(iMesh, what, x, y, z, domain );
982 //================================================================================
984 * \brief Return node index of a next corner
986 //================================================================================
988 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node )
996 ::GmfGetLin(iMesh, what, node );
999 //================================================================================
1001 * \brief Return node indices of a next edge
1003 //================================================================================
1005 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2, int* domain )
1009 _libData->ReadEdgeNodes( node1, node2, domain );
1013 ::GmfGetLin( iMesh, what, node1, node2, domain );
1016 //================================================================================
1018 * \brief Return node indices of a next triangle
1020 //================================================================================
1022 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1023 int* node1, int* node2, int* node3, int* domain )
1027 _libData->ReadTriaNodes( node1, node2, node3, domain );
1031 ::GmfGetLin(iMesh, what, node1, node2, node3, domain );
1034 //================================================================================
1036 * \brief Return node indices of a next tetrahedron or quadrangle
1038 //================================================================================
1040 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1041 int* node1, int* node2, int* node3, int* node4, int* domain )
1045 if ( what == GmfQuadrilaterals )
1046 _libData->ReadQuadNodes( node1, node2, node3, node4, domain );
1048 _libData->ReadTetraNodes( node1, node2, node3, node4, domain );
1052 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, domain );
1055 //================================================================================
1057 * \brief Return node indices of a next hexahedron
1059 //================================================================================
1061 void MG_Tetra_API::GmfGetLin(int iMesh, GmfKwdCod what,
1062 int* node1, int* node2, int* node3, int* node4,
1063 int* node5, int* node6, int* node7, int* node8,
1068 _libData->ReadHexaNodes( node1, node2, node3, node4,
1069 node5, node6, node7, node8, domain );
1073 ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
1076 //================================================================================
1078 * \brief Prepare for passing data to MeshGems
1080 //================================================================================
1082 int MG_Tetra_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim)
1089 int id = ::GmfOpenMesh(theFile, rdOrWr, ver, dim);
1090 _openFiles.insert( id );
1094 //================================================================================
1096 * \brief Set number of entities
1098 //================================================================================
1100 void MG_Tetra_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
1105 case GmfVertices: _nbNodes = nb; break;
1106 case GmfEdges: _nbEdges = nb; break;
1107 case GmfTriangles: _nbFaces = nb; break;
1115 case GmfVertices: _libData->SetNbVertices( nb ); break;
1116 case GmfEdges: _libData->SetNbEdges ( nb ); break;
1117 case GmfRequiredEdges: _libData->SetNbReqEdges( nb ); break;
1118 case GmfTriangles: _libData->SetNbTria ( nb ); break;
1119 case GmfRequiredTriangles: _libData->SetNbReqTria ( nb ); break;
1125 ::GmfSetKwd(iMesh, what, nb );
1128 //================================================================================
1130 * \brief Add coordinates of a node
1132 //================================================================================
1134 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, double x, double y, double z, int domain)
1138 _libData->AddNode( x, y, z, domain );
1142 ::GmfSetLin(iMesh, what, x, y, z, domain);
1145 //================================================================================
1147 * \brief Set number of field entities
1148 * \param [in] iMesh - solution file index
1149 * \param [in] what - solution type
1150 * \param [in] nbNodes - nb of entities
1151 * \param [in] nbTypes - nb of data entries in each entity
1152 * \param [in] type - types of the data entries
1154 * Used to prepare to storing size at nodes
1156 //================================================================================
1158 void MG_Tetra_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nbNodes, int dummy, int type[] )
1162 if ( what == GmfSolAtVertices ) _libData->SetNbReqVertices( nbNodes );
1166 ::GmfSetKwd(iMesh, what, nbNodes, dummy, type );
1169 //================================================================================
1171 * \brief Add solution data
1173 //================================================================================
1175 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, double vals[])
1179 _libData->AddSizeAtNode( vals[0] );
1183 ::GmfSetLin(iMesh, what, vals);
1186 //================================================================================
1188 * \brief Add edge nodes
1190 //================================================================================
1192 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int domain )
1196 _libData->AddEdgeNodes( node1, node2, domain );
1200 ::GmfSetLin(iMesh, what, node1, node2, domain );
1203 //================================================================================
1205 * \brief Add a 'required' flag
1207 //================================================================================
1209 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int id )
1216 ::GmfSetLin(iMesh, what, id );
1219 //================================================================================
1221 * \brief Add triangle nodes
1223 //================================================================================
1225 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain )
1229 _libData->AddTriaNodes( node1, node2, node3, domain );
1233 ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
1236 //================================================================================
1238 * \brief Add tetra nodes
1240 //================================================================================
1242 void MG_Tetra_API::GmfSetLin(int iMesh, GmfKwdCod what,
1243 int node1, int node2, int node3, int node4, int domain )
1247 _libData->AddTetraNodes( node1, node2, node3, node4, domain );
1251 ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
1254 //================================================================================
1256 * \brief Close a file
1258 //================================================================================
1260 void MG_Tetra_API::GmfCloseMesh( int iMesh )
1267 ::GmfCloseMesh( iMesh );
1268 _openFiles.erase( iMesh );
1271 //================================================================================
1273 * \brief Return true if the log is not empty
1275 //================================================================================
1277 bool MG_Tetra_API::HasLog()
1281 return !_libData->GetErrors().empty();
1284 SMESH_File file( _logFile );
1285 return file.size() > 0;
1288 //================================================================================
1290 * \brief Return log contents
1292 //================================================================================
1294 std::string MG_Tetra_API::GetLog()
1298 const std::string& err = _libData->GetErrors();
1299 if ( !_logFile.empty() && !err.empty() )
1301 SMESH_File file( _logFile, /*openForReading=*/false );
1302 file.openForWriting();
1303 file.write( err.c_str(), err.size() );
1308 SMESH_File file( _logFile );
1309 return file.getPos();