From 3908228c77a74588261ac6e9b3c8baf9440b547b Mon Sep 17 00:00:00 2001 From: gdd Date: Mon, 10 Sep 2012 11:48:01 +0000 Subject: [PATCH] First commit for porting GHS3DPLUGIN to MeshGems suite (MG-TETRA) --- .../unix/config_files/check_MESHGEMS_TETRA.m4 | 37 +++ configure.ac | 17 +- src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx | 60 ++-- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx | 5 +- src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx | 3 - src/GHS3DPlugin/Makefile.am | 54 ++-- src/GHS3DPlugin/libmesh5.c | 256 ++++++++++++++---- src/GHS3DPlugin/libmesh5.h | 51 ++-- 8 files changed, 328 insertions(+), 155 deletions(-) create mode 100644 adm_local/unix/config_files/check_MESHGEMS_TETRA.m4 diff --git a/adm_local/unix/config_files/check_MESHGEMS_TETRA.m4 b/adm_local/unix/config_files/check_MESHGEMS_TETRA.m4 new file mode 100644 index 0000000..ab354e0 --- /dev/null +++ b/adm_local/unix/config_files/check_MESHGEMS_TETRA.m4 @@ -0,0 +1,37 @@ +dnl Copyright (C) 2004-2012 CEA/DEN, EDF R&D +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +dnl + +AC_DEFUN([CHECK_MESHGEMS_TETRA],[ + +AC_CHECKING([for MeshGems-Tetra commercial product]) + +MeshGems_Tetra_ok=no + +AC_EXEEXT +AC_CHECK_PROG(MESHGEMS_TETRA, mg-tetra.exe$EXEEXT,found) + +if test "x$MESHGEMS_TETRA" == x ; then + AC_MSG_WARN(mg-tetra program not found in PATH variable) +else + MeshGems_Tetra_ok=yes +fi + +AC_MSG_RESULT(for MeshGems-Tetra: $MeshGems_Tetra_ok) + +])dnl diff --git a/configure.ac b/configure.ac index d39b98b..6c57482 100644 --- a/configure.ac +++ b/configure.ac @@ -349,18 +349,11 @@ CHECK_SMESH echo echo --------------------------------------------- -echo Testing GHS3D +echo Testing MeshGems-Tetra echo --------------------------------------------- echo -CHECK_GHS3D -if test "${GHS3D_ok}" = "yes"; then - if test "x$GHS3D_VERSION" = "x" - then - GHS3D_VERSION=`ghs3d -u |grep "TETMESH-GHS3D SOFTWARE"|awk '{print $3}'|awk -F- '{print $1}'|awk -F. '{print $1$2}'` - fi - AC_DEFINE_UNQUOTED(GHS3D_VERSION,${GHS3D_VERSION}) -fi +CHECK_MESHGEMS_TETRA echo echo --------------------------------------------- @@ -370,11 +363,11 @@ echo echo Configure if test "${gui_ok}" = "yes"; then - variables="cc_ok boost_ok threads_ok omniORB_ok occ_ok doxygen_ok Kernel_ok gui_ok Geom_ok Med_ok SMesh_ok GHS3D_ok OpenGL_ok qt_ok vtk_ok" + variables="cc_ok boost_ok threads_ok omniORB_ok occ_ok doxygen_ok Kernel_ok gui_ok Geom_ok Med_ok SMesh_ok MeshGems_Tetra_ok OpenGL_ok qt_ok vtk_ok" elif test "${SalomeGUI_need}" != "no"; then - variables="cc_ok boost_ok threads_ok omniORB_ok occ_ok doxygen_ok Kernel_ok gui_ok Geom_ok Med_ok SMesh_ok GHS3D_ok vtk_ok" + variables="cc_ok boost_ok threads_ok omniORB_ok occ_ok doxygen_ok Kernel_ok gui_ok Geom_ok Med_ok SMesh_ok MeshGems_Tetra_ok vtk_ok" else - variables="cc_ok boost_ok threads_ok omniORB_ok occ_ok doxygen_ok Kernel_ok Geom_ok Med_ok SMesh_ok GHS3D_ok vtk_ok" + variables="cc_ok boost_ok threads_ok omniORB_ok occ_ok doxygen_ok Kernel_ok Geom_ok Med_ok SMesh_ok MeshGems_Tetra_ok vtk_ok" fi for var in $variables diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 68d805e..3e467d8 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -107,10 +107,6 @@ extern "C" #define HOLE_ID -1 -#ifndef GHS3D_VERSION -#define GHS3D_VERSION 41 -#endif - typedef const list TTriaList; static void removeFile( const TCollection_AsciiString& fileName ) @@ -479,11 +475,11 @@ static int findShapeID(SMESH_Mesh& mesh, return meshDS->ShapeToIndex( solids(2) ); } -//======================================================================= -//function : countShape -//purpose : -//======================================================================= - +// //======================================================================= +// //function : countShape +// //purpose : +// //======================================================================= +// // template < class Mesh, class Shape > // static int countShape( Mesh* mesh, Shape shape ) { // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape ); @@ -496,12 +492,12 @@ static int findShapeID(SMESH_Mesh& mesh, // } // return nbShape; // } - -//======================================================================= -//function : getShape -//purpose : -//======================================================================= - +// +// //======================================================================= +// //function : getShape +// //purpose : +// //======================================================================= +// // template < class Mesh, class Shape, class Tab > // void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) { // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape ); @@ -514,11 +510,11 @@ static int findShapeID(SMESH_Mesh& mesh, // } // return; // } - -// //======================================================================= -// //function : findEdgeID -// //purpose : -// //======================================================================= +// +// // //======================================================================= +// // //function : findEdgeID +// // //purpose : +// // //======================================================================= // // static int findEdgeID(const SMDS_MeshNode* aNode, // const SMESHDS_Mesh* theMesh, @@ -552,16 +548,14 @@ static int findShapeID(SMESH_Mesh& mesh, // delete [] t_Dist; // return theMesh->ShapeToIndex( foundEdge ); // } - - -//======================================================================= -//function : readGMFFile -//purpose : read GMF file with geometry associated to mesh -// TODO -//======================================================================= - -// static bool readGMFFile( -// const int fileOpen, +// +// +// // ======================================================================= +// // function : readGMFFile +// // purpose : read GMF file with geometry associated to mesh +// // ======================================================================= +// +// static bool readGMFFile(const int fileOpen, // const char* theFileName, // SMESH_Mesh& theMesh, // const int nbShape, @@ -644,7 +638,7 @@ static int findShapeID(SMESH_Mesh& mesh, // // // // The keyword does not exist yet => to update when it is created -// // int nbTriangle = GmfStatKwd(InpMsh, GmfSubdomain); +// // int nbSubdomains = GmfStatKwd(InpMsh, GmfSubdomain); // // int id_tri[3]; // // @@ -828,11 +822,11 @@ static int findShapeID(SMESH_Mesh& mesh, // // case GmfHexahedra: // { // int nodeDim, shapeID, *nodeID; -// SMDS_MeshNode** node; +// const SMDS_MeshNode** node; // // std::vector< SMDS_MeshNode* > enfNode( nbRef ); // SMDS_MeshElement * aGMFElement; // -// node = new SMDS_MeshNode*[nbRef]; +// node = new const SMDS_MeshNode*[nbRef]; // nodeID = new int[ nbRef ]; // // for ( int iElem = 0; iElem < nbElem; iElem++ ) diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index 6910f8c..ef8349a 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -1274,10 +1274,7 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h const bool hasShapeToMesh) { TCollection_AsciiString cmd; - if (hasShapeToMesh) - cmd = "ghs3d-41"; // to use old mesh2 format - else - cmd = "ghs3d"; // to use new mesh format + cmd = "mg-tetra.exe"; // check if any option is overridden by hyp->myTextOption bool m = hyp ? ( hyp->myTextOption.find("-m") == std::string::npos ) : true; bool M = hyp ? ( hyp->myTextOption.find("-M") == std::string::npos ) : true; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index 2e7a37e..2c3b9ca 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -44,9 +44,6 @@ // #include // #include CORBA_SERVER_HEADER(SALOMEDS) -#ifndef GHS3D_VERSION -#define GHS3D_VERSION 41 -#endif //======================================================================= //function : GHS3DPlugin_Hypothesis_i //======================================================================= diff --git a/src/GHS3DPlugin/Makefile.am b/src/GHS3DPlugin/Makefile.am index a761826..a6e0509 100644 --- a/src/GHS3DPlugin/Makefile.am +++ b/src/GHS3DPlugin/Makefile.am @@ -27,42 +27,42 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # header files salomeinclude_HEADERS = \ - libmesh5.h \ - GHS3DPlugin_Defs.hxx \ - GHS3DPlugin_GHS3D.hxx \ - GHS3DPlugin_GHS3D_i.hxx \ - GHS3DPlugin_Hypothesis.hxx \ - GHS3DPlugin_Hypothesis_i.hxx + libmesh5.h \ + GHS3DPlugin_Defs.hxx \ + GHS3DPlugin_GHS3D.hxx \ + GHS3DPlugin_GHS3D_i.hxx \ + GHS3DPlugin_Hypothesis.hxx \ + GHS3DPlugin_Hypothesis_i.hxx # Libraries targets lib_LTLIBRARIES = libGHS3DEngine.la dist_libGHS3DEngine_la_SOURCES = \ - libmesh5.c \ - GHS3DPlugin_GHS3D.cxx \ - GHS3DPlugin_GHS3D_i.cxx \ - GHS3DPlugin_i.cxx \ - GHS3DPlugin_Hypothesis.cxx \ - GHS3DPlugin_Hypothesis_i.cxx + libmesh5.c \ + GHS3DPlugin_GHS3D.cxx \ + GHS3DPlugin_GHS3D_i.cxx \ + GHS3DPlugin_i.cxx \ + GHS3DPlugin_Hypothesis.cxx \ + GHS3DPlugin_Hypothesis_i.cxx libGHS3DEngine_la_CPPFLAGS = \ - $(KERNEL_CXXFLAGS) \ - $(CAS_CPPFLAGS) \ - $(GEOM_CXXFLAGS) \ - $(MED_CXXFLAGS) \ - $(SMESH_CXXFLAGS) \ - $(VTK_INCLUDES) \ - $(BOOST_CPPFLAGS) \ - $(CORBA_CXXFLAGS) \ - $(CORBA_INCLUDES) \ - -I$(top_builddir)/idl + $(KERNEL_CXXFLAGS) \ + $(CAS_CPPFLAGS) \ + $(GEOM_CXXFLAGS) \ + $(MED_CXXFLAGS) \ + $(SMESH_CXXFLAGS) \ + $(VTK_INCLUDES) \ + $(BOOST_CPPFLAGS) \ + $(CORBA_CXXFLAGS) \ + $(CORBA_INCLUDES) \ + -I$(top_builddir)/idl libGHS3DEngine_la_LDFLAGS = \ - ../../idl/libSalomeIDLGHS3DPLUGIN.la \ - $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKTopAlgo -lTKGeomBase -lTKGeomAlgo -lTKCDF \ - $(MED_LDFLAGS) -lSalomeIDLMED \ - $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lSMESHDS -lSMDS -lStdMeshers \ - $(KERNEL_LDFLAGS) -lSalomeGenericObj -lSALOMELocalTrace -lSALOMEBasics -lSalomeNS -lOpUtil + ../../idl/libSalomeIDLGHS3DPLUGIN.la \ + $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKTopAlgo -lTKGeomBase -lTKGeomAlgo -lTKCDF \ + $(MED_LDFLAGS) -lSalomeIDLMED \ + $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lSMESHDS -lSMDS -lStdMeshers \ + $(KERNEL_LDFLAGS) -lSalomeGenericObj -lSALOMELocalTrace -lSALOMEBasics -lSalomeNS -lOpUtil # Scripts to be installed. dist_salomescript_DATA= GHS3DPluginDC.py diff --git a/src/GHS3DPlugin/libmesh5.c b/src/GHS3DPlugin/libmesh5.c index 4277b97..b16c39c 100644 --- a/src/GHS3DPlugin/libmesh5.c +++ b/src/GHS3DPlugin/libmesh5.c @@ -2,14 +2,14 @@ /*----------------------------------------------------------*/ /* */ -/* LIBMESH V 5.45 */ +/* LIBMESH V 5.46 */ /* */ /*----------------------------------------------------------*/ /* */ /* Description: handle .meshb file format I/O */ /* Author: Loic MARECHAL */ /* Creation date: feb 16 2007 */ -/* Last modification: feb 08 2011 */ +/* Last modification: apr 03 2012 */ /* */ /*----------------------------------------------------------*/ @@ -58,7 +58,7 @@ typedef struct typedef struct { int dim, ver, mod, typ, cod, pos; - long NexKwdPos; + long NexKwdPos, siz; KwdSct KwdTab[ GmfMaxKwd + 1 ]; FILE *hdl; int *IntBuf; @@ -74,9 +74,9 @@ typedef struct /* Global variables */ /*----------------------------------------------------------*/ -int GmfIniFlg=0; -GmfMshSct *GmfMshTab[ MaxMsh + 1 ]; -char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] = +static int GmfIniFlg=0; +static GmfMshSct *GmfMshTab[ MaxMsh + 1 ]; +static const char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] = { {"Reserved", "", "", ""}, {"MeshVersionFormatted", "", "", "i"}, {"Reserved", "", "", ""}, @@ -106,36 +106,36 @@ char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] = {"SolAtPyramids", "SolAtPyramid", "i", "sr"}, {"QuadrilateralsQ2", "QuadrilateralQ2", "i", "iiiiiiiiii"}, {"ISolAtPyramids", "ISolAtPyramid", "i", "iiiii"}, - {"Reserved", "", "", ""}, + {"SubDomainFromGeom", "SubDomainFromGeom", "i", "iiii"}, {"TetrahedraP2", "TetrahedronP2", "i", "iiiiiiiiiii"}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, + {"Fault_NearTri", "Fault_NearTri", "i", "i"}, + {"Fault_Inter", "Fault_Inter", "i", "i"}, {"HexahedraQ2", "HexahedronQ2", "i", "iiiiiiiiiiiiiiiiiiiiiiiiiiii"}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, + {"ExtraVerticesAtEdges", "ExtraVerticesAtEdge", "i", "in"}, + {"ExtraVerticesAtTriangles", "ExtraVerticesAtTriangle", "i", "in"}, + {"ExtraVerticesAtQuadrilaterals", "ExtraVerticesAtQuadrilateral", "i", "in"}, + {"ExtraVerticesAtTetrahedra", "ExtraVerticesAtTetrahedron", "i", "in"}, + {"ExtraVerticesAtPrisms", "ExtraVerticesAtPrism", "i", "in"}, + {"ExtraVerticesAtHexahedra", "ExtraVerticesAtHexahedron", "i", "in"}, + {"VerticesOnGeometricVertices", "VertexOnGeometricVertex", "i", "iir"}, + {"VerticesOnGeometricEdges", "VertexOnGeometricEdge", "i", "iirr"}, + {"VerticesOnGeometricTriangles", "VertexOnGeometricTriangle", "i", "iirrr"}, + {"VerticesOnGeometricQuadrilaterals", "VertexOnGeometricQuadrilateral", "i", "iirrr"}, + {"EdgesOnGeometricEdges", "EdgeOnGeometricEdge", "i", "iir"}, + {"Fault_FreeEdge", "Fault_FreeEdge", "i", "i"}, {"Polyhedra", "Polyhedron", "i", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"}, {"Polygons", "Polygon", "", "iiiiiiiii"}, - {"Reserved", "", "", ""}, + {"Fault_Overlap", "Fault_Overlap", "i", "i"}, {"Pyramids", "Pyramid", "i", "iiiiii"}, {"BoundingBox", "", "", "drdr"}, {"Body","i", "drdrdrdr"}, {"PrivateTable", "PrivateTable", "i", "i"}, - {"Reserved", "", "", ""}, + {"Fault_BadShape", "Fault_BadShape", "i", "i"}, {"End", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, - {"Reserved", "", "", ""}, + {"TrianglesOnGeometricTriangles", "TriangleOnGeometricTriangle", "i", "iir"}, + {"TrianglesOnGeometricQuadrilaterals", "TriangleOnGeometricQuadrilateral", "i", "iir"}, + {"QuadrilateralsOnGeometricTriangles", "QuadrilateralOnGeometricTriangle", "i", "iir"}, + {"QuadrilateralsOnGeometricQuadrilaterals", "QuadrilateralOnGeometricQuadrilateral", "i", "iir"}, {"Tangents", "Tangent", "i", "dr"}, {"Normals", "Normal", "i", "dr"}, {"TangentAtVertices", "TangentAtVertex", "i", "ii"}, @@ -156,7 +156,8 @@ char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] = {"ISolAtHexahedra", "ISolAtHexahedron", "i", "iiiiiiii"}, {"Iterations", "","","i"}, {"Time", "","","r"}, - {"Reserved", "","",""} + {"Fault_SmallTri", "Fault_SmallTri","i","i"}, + {"CoarseHexahedra", "CoarseHexahedron", "i", "i"} }; @@ -187,6 +188,8 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) char str[ GmfStrSiz ]; va_list VarArg; GmfMshSct *msh; + char *ptr; + int k; if(!GmfIniFlg) { @@ -213,27 +216,36 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) /* Copy the FilNam into the structure */ if(strlen(FilNam) + 7 >= GmfStrSiz) + { + free (msh); return(0); + } strcpy(msh->FilNam, FilNam); /* Store the opening mod (read or write) and guess the filetype (binary or ascii) depending on the extension */ msh->mod = mod; - msh->buf = (void *)msh->DblBuf; - msh->FltBuf = (void *)msh->DblBuf; - msh->IntBuf = (void *)msh->DblBuf; - - if(strstr(msh->FilNam, ".meshb")) + msh->buf = (unsigned char *)msh->DblBuf; + msh->FltBuf = (float *)msh->DblBuf; + msh->IntBuf = (int *)msh->DblBuf; + + k = strlen(msh->FilNam) - 6; + if(k < 0) + k = 0; + ptr = msh->FilNam+k; + if(strstr(ptr, ".meshb")) msh->typ |= (Bin | MshFil); - else if(strstr(msh->FilNam, ".mesh")) + else if(strstr(ptr, ".mesh")) msh->typ |= (Asc | MshFil); - else if(strstr(msh->FilNam, ".solb")) + else if(strstr(ptr, ".solb")) msh->typ |= (Bin | SolFil); - else if(strstr(msh->FilNam, ".sol")) + else if(strstr(ptr, ".sol")) msh->typ |= (Asc | SolFil); - else + else { + free (msh); return(0); + } /* Open the file in the required mod and initialyse the mesh structure */ @@ -252,7 +264,10 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) /* Create the name string and open the file */ if(!(msh->hdl = fopen(msh->FilNam, "rb"))) + { + free (msh); return(0); + } /* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */ @@ -261,20 +276,32 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) fread((unsigned char *)&msh->cod, WrdSiz, 1, msh->hdl); if( (msh->cod != 1) && (msh->cod != 16777216) ) + { + free (msh); return(0); + } ScaWrd(msh, (unsigned char *)&msh->ver); if( (msh->ver < 1) || (msh->ver > 3) ) + { + free (msh); return(0); + } if( (msh->ver == 3) && (sizeof(long) == 4) ) + { + free (msh); return(0); + } ScaWrd(msh, (unsigned char *)&KwdCod); if(KwdCod != GmfDimension) + { + free (msh); return(0); + } GetPos(msh); ScaWrd(msh, (unsigned char *)&msh->dim); @@ -287,12 +314,18 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) }while( (res != EOF) && strcmp(str, "MeshVersionFormatted") ); if(res == EOF) + { + free (msh); return(0); + } fscanf(msh->hdl, "%d", &msh->ver); if( (msh->ver < 1) || (msh->ver > 3) ) + { + free (msh); return(0); + } do { @@ -300,13 +333,19 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) }while( (res != EOF) && strcmp(str, "Dimension") ); if(res == EOF) + { + free (msh); return(0); + } fscanf(msh->hdl, "%d", &msh->dim); } if( (msh->dim != 2) && (msh->dim != 3) ) + { + free (msh); return(0); + } (*PtrVer) = msh->ver; (*PtrDim) = msh->dim; @@ -318,7 +357,10 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) /* Read the list of kw present in the file */ if(!ScaKwdTab(msh)) + { + free (msh); return(0); + } GmfMshTab[ MshIdx ] = msh; @@ -341,18 +383,30 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) va_end(VarArg); if( (msh->ver < 1) || (msh->ver > 3) ) + { + free (msh); return(0); + } if( (msh->ver == 3) && (sizeof(long) == 4) ) + { + free (msh); return(0); + } if( (msh->dim != 2) && (msh->dim != 3) ) + { + free (msh); return(0); + } /* Create the mesh file */ if(!(msh->hdl = fopen(msh->FilNam, "wb"))) + { + free (msh); return(0); + } GmfMshTab[ MshIdx ] = msh; @@ -379,7 +433,10 @@ int GmfOpenMesh(const char *FilNam, int mod, ...) return(MshIdx); } else + { + free (msh); return(0); + } } @@ -400,13 +457,12 @@ int GmfCloseMesh(int MshIdx) /* In write down the "End" kw in write mode */ - if(msh->mod == GmfWrite) { + if(msh->mod == GmfWrite){ if(msh->typ & Asc) fprintf(msh->hdl, "\n%s\n", GmfKwdFmt[ GmfEnd ][0]); else GmfSetKwd(MshIdx, GmfEnd, 0); - } - + } /* Close the file and free the mesh structure */ if(fclose(msh->hdl)) @@ -596,8 +652,18 @@ int GmfSetKwd(int MshIdx, int KwdCod, ...) RecWrd(msh, (unsigned char *)&kwd->TypTab[i]); } } + + /* Reset write buffer position */ msh->pos = 0; - return(kwd->NmbLin); + + /* Estimate the total file size and check whether it crosses the 2GB threshold */ + + msh->siz += kwd->NmbLin * kwd->NmbWrd * WrdSiz; + + if(msh->siz > 2E9) + return(0); + else + return(kwd->NmbLin); } @@ -620,6 +686,8 @@ void GmfGetLin(int MshIdx, int KwdCod, ...) if(kwd->typ != SolKwd) { + int k, nb_repeat = 0; + if(msh->ver == 1) { if(msh->typ & Asc) @@ -627,18 +695,28 @@ void GmfGetLin(int MshIdx, int KwdCod, ...) for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') fscanf(msh->hdl, "%f", va_arg(VarArg, float *)); + else if(kwd->fmt[i] == 'n') { + fscanf(msh->hdl, "%d", &nb_repeat); + *(va_arg(VarArg, int *)) = nb_repeat; + for(k=0;khdl, "%d", va_arg(VarArg, int *)); + } else fscanf(msh->hdl, "%d", va_arg(VarArg, int *)); } else { - ScaBlk(msh, msh->buf, kwd->SolSiz); - for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') - *(va_arg(VarArg, float *)) = msh->FltBuf[i]; + ScaWrd(msh, (unsigned char *)va_arg(VarArg, float *)); + else if(kwd->fmt[i] == 'n') { + ScaWrd(msh, (unsigned char *)&nb_repeat); + *(va_arg(VarArg, int *)) = nb_repeat; + for(k=0;kIntBuf[i]; + ScaWrd(msh, (unsigned char *)va_arg(VarArg, int *)); } } else @@ -648,6 +726,12 @@ void GmfGetLin(int MshIdx, int KwdCod, ...) for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') fscanf(msh->hdl, "%lf", va_arg(VarArg, double *)); + else if(kwd->fmt[i] == 'n') { + fscanf(msh->hdl, "%d", &nb_repeat); + *(va_arg(VarArg, int *)) = nb_repeat; + for(k=0;khdl, "%d", va_arg(VarArg, int *)); + } else fscanf(msh->hdl, "%d", va_arg(VarArg, int *)); } @@ -655,6 +739,12 @@ void GmfGetLin(int MshIdx, int KwdCod, ...) for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') ScaDblWrd(msh, (unsigned char *)va_arg(VarArg, double *)); + else if(kwd->fmt[i] == 'n') { + ScaWrd(msh, (unsigned char *)&nb_repeat); + *(va_arg(VarArg, int *)) = nb_repeat; + for(k=0;ktyp != SolKwd) { + int k, nb_repeat = 0; + if(msh->ver == 1) { if(msh->typ & Asc) @@ -714,18 +806,33 @@ void GmfSetLin(int MshIdx, int KwdCod, ...) for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') fprintf(msh->hdl, "%g ", (float)va_arg(VarArg, double)); + else if(kwd->fmt[i] == 'n') { + nb_repeat = va_arg(VarArg, int); + fprintf(msh->hdl, "%d ", nb_repeat); + for(k=0;khdl, "%d ", va_arg(VarArg, int)); + } else fprintf(msh->hdl, "%d ", va_arg(VarArg, int)); } else { + int size_of_block = kwd->SolSiz; for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') msh->FltBuf[i] = va_arg(VarArg, double); + else if(kwd->fmt[i] == 'n') { + nb_repeat = va_arg(VarArg, int); + msh->FltBuf[i] = nb_repeat; + for(k=0;kIntBuf[i+1+k] = va_arg(VarArg, int); + size_of_block ++; + } + } else msh->IntBuf[i] = va_arg(VarArg, int); - RecBlk(msh, msh->buf, kwd->SolSiz); + RecBlk(msh, msh->buf, size_of_block); } } else @@ -735,6 +842,12 @@ void GmfSetLin(int MshIdx, int KwdCod, ...) for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') fprintf(msh->hdl, "%.15lg ", va_arg(VarArg, double)); + else if(kwd->fmt[i] == 'n') { + nb_repeat = va_arg(VarArg, int); + fprintf(msh->hdl, "%d ", nb_repeat); + for(k=0;khdl, "%d ", va_arg(VarArg, int)); + } else fprintf(msh->hdl, "%d ", va_arg(VarArg, int)); } @@ -745,17 +858,29 @@ void GmfSetLin(int MshIdx, int KwdCod, ...) for(i=0;iSolSiz;i++) if(kwd->fmt[i] == 'r') { - DblBuf = (void *)&msh->buf[ pos ]; + DblBuf = (double *)&msh->buf[ pos ]; *DblBuf = va_arg(VarArg, double); pos += 8; } + else if(kwd->fmt[i] == 'n') + { + IntBuf = (int *)&msh->buf[ pos ]; + nb_repeat = va_arg(VarArg, int); + *IntBuf = nb_repeat; + pos += 4; + for(k=0;kbuf[ pos ]; + *IntBuf = va_arg(VarArg, int); + pos += 4; + } + } else { - IntBuf = (void *)&msh->buf[ pos ]; + IntBuf = (int *)&msh->buf[ pos ]; *IntBuf = va_arg(VarArg, int); pos += 4; } - RecBlk(msh, msh->buf, kwd->NmbWrd); + RecBlk(msh, msh->buf, pos/4); } } } @@ -836,6 +961,34 @@ void GmfCpyLin(int InpIdx, int OutIdx, int KwdCod) else RecDblWrd(OutMsh, (unsigned char *)&d); } + else if(kwd->fmt[i] == 'n') + { + int k, nb_repeat = 0; + + if(InpMsh->typ & Asc) + fscanf(InpMsh->hdl, "%d", &a); + else + ScaWrd(InpMsh, (unsigned char *)&a); + + nb_repeat = a; + + if(OutMsh->typ & Asc) + fprintf(OutMsh->hdl, "%d ", a); + else + RecWrd(OutMsh, (unsigned char *)&a); + + for(k=0;ktyp & Asc) + fscanf(InpMsh->hdl, "%d", &a); + else + ScaWrd(InpMsh, (unsigned char *)&a); + + if(OutMsh->typ & Asc) + fprintf(OutMsh->hdl, "%d ", a); + else + RecWrd(OutMsh, (unsigned char *)&a); + } + } else { if(InpMsh->typ & Asc) @@ -975,7 +1128,8 @@ static void ScaKwdHdr(GmfMshSct *msh, int KwdCod) static void ExpFmt(GmfMshSct *msh, int KwdCod) { int i, j, TmpSiz=0; - char chr, *InpFmt = GmfKwdFmt[ KwdCod ][3]; + char chr; + const char *InpFmt = GmfKwdFmt[ KwdCod ][3]; KwdSct *kwd = &msh->KwdTab[ KwdCod ]; /* Set the kwd's type */ @@ -1175,7 +1329,7 @@ static void RecBlk(GmfMshSct *msh, unsigned char *blk, int siz) /*----------------------------------------------------------*/ -/* Read a 4 or 8 bytes position in mesh file */ +/* Write a 4 or 8 bytes position in a mesh file */ /*----------------------------------------------------------*/ static void SetPos(GmfMshSct *msh, long pos) diff --git a/src/GHS3DPlugin/libmesh5.h b/src/GHS3DPlugin/libmesh5.h index cfaf9fb..eddf200 100755 --- a/src/GHS3DPlugin/libmesh5.h +++ b/src/GHS3DPlugin/libmesh5.h @@ -2,14 +2,14 @@ /*----------------------------------------------------------*/ /* */ -/* LIBMESH V 5.45 */ +/* LIBMESH V 5.46 */ /* */ /*----------------------------------------------------------*/ /* */ /* Description: handle .meshb file format I/O */ /* Author: Loic MARECHAL */ /* Creation date: feb 16 2007 */ -/* Last modification: sep 27 2010 */ +/* Last modification: dec 09 2011 */ /* */ /*----------------------------------------------------------*/ @@ -20,7 +20,7 @@ #define GmfStrSiz 1024 #define GmfMaxTyp 1000 -#define GmfMaxKwd 79 +#define GmfMaxKwd 80 #define GmfMshVer 1 #define GmfRead 1 #define GmfWrite 2 @@ -62,36 +62,36 @@ enum GmfKwdCod GmfSolAtPyramids, \ GmfQuadrilateralsQ2, \ GmfISolAtPyramids, \ - GmfReserved6, \ + GmfSubDomainFromGeom, \ GmfTetrahedraP2, \ - GmfReserved7, \ - GmfReserved8, \ + GmfFault_NearTri, \ + GmfFault_Inter, \ GmfHexahedraQ2, \ - GmfReserved9, \ - GmfReserved10, \ - GmfReserved17, \ - GmfReserved18, \ - GmfReserved19, \ - GmfReserved20, \ - GmfReserved21, \ - GmfReserved22, \ - GmfReserved23, \ - GmfReserved24, \ - GmfReserved25, \ - GmfReserved26, \ + GmfExtraVerticesAtEdges, \ + GmfExtraVerticesAtTriangles, \ + GmfExtraVerticesAtQuadrilaterals, \ + GmfExtraVerticesAtTetrahedra, \ + GmfExtraVerticesAtPrisms, \ + GmfExtraVerticesAtHexahedra, \ + GmfVerticesOnGeometricVertices, \ + GmfVerticesOnGeometricEdges, \ + GmfVerticesOnGeometricTriangles, \ + GmfVerticesOnGeometricQuadrilaterals, \ + GmfEdgesOnGeometricEdges, \ + GmfFault_FreeEdge, \ GmfPolyhedra, \ GmfPolygons, \ - GmfReserved29, \ + GmfFault_Overlap, \ GmfPyramids, \ GmfBoundingBox, \ GmfBody, \ GmfPrivateTable, \ - GmfReserved33, \ + GmfFault_BadShape, \ GmfEnd, \ - GmfReserved34, \ - GmfReserved35, \ - GmfReserved36, \ - GmfReserved37, \ + GmfTrianglesOnGeometricTriangles, \ + GmfTrianglesOnGeometricQuadrilaterals, \ + GmfQuadrilateralsOnGeometricTriangles, \ + GmfQuadrilateralsOnGeometricQuadrilaterals, \ GmfTangents, \ GmfNormals, \ GmfTangentAtVertices, \ @@ -112,7 +112,8 @@ enum GmfKwdCod GmfISolAtHexahedra, \ GmfIterations, \ GmfTime, \ - GmfReserved38 + GmfFault_SmallTri, \ + GmfCoarseHexahedra }; -- 2.39.2