From 07fac32e1831a021cd8139c2583e9240841c95be Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 4 Aug 2010 07:50:09 +0000 Subject: [PATCH] * set mesh file format to "automatic" by default + remove -format command line option * basic Abaqus INP mesh export --- Common/CommandLine.cpp | 44 +----------------------- Common/CreateFile.cpp | 7 ++++ Common/DefaultOptions.h | 4 +-- Common/Gmsh.cpp | 8 +++-- Common/GmshDefines.h | 1 + Fltk/menuWindow.cpp | 6 +++- Geo/GModel.cpp | 2 +- Geo/GModel.h | 4 +++ Geo/GModelIO_Mesh.cpp | 74 ++++++++++++++++++++++++++++------------- Geo/MElement.h | 4 +++ Geo/MHexahedron.h | 1 + Geo/MLine.h | 3 ++ Geo/MPrism.h | 1 + Geo/MQuadrangle.h | 2 ++ Geo/MTetrahedron.h | 1 + Geo/MTriangle.h | 2 ++ 16 files changed, 92 insertions(+), 72 deletions(-) diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index 12ebbcba3d..2d703baba6 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -61,9 +61,7 @@ void PrintUsage(const char *name) Msg::Direct(" -part int Partition after batch mesh generation"); Msg::Direct(" -renumber Renumber the mesh elements after batch mesh generation"); Msg::Direct(" -saveall Save all elements (discard physical group definitions)"); - Msg::Direct(" -o file Specify mesh output file name"); - Msg::Direct(" -format string Set output mesh format (msh, msh1, msh2, unv, vrml, stl, mesh,"); - Msg::Direct(" bdf, p3d, cgns, med, ir3)"); + Msg::Direct(" -o file Specify output file name"); Msg::Direct(" -bin Use binary format when available"); Msg::Direct(" -parametric Save vertices with their parametric coordinates"); Msg::Direct(" -numsubedges Set the number of subdivisions when displaying high order elements"); @@ -452,46 +450,6 @@ void GetOptions(int argc, char *argv[]) else Msg::Fatal("Missing argument"); } - else if(!strcmp(argv[i] + 1, "format") || !strcmp(argv[i] + 1, "f")) { - i++; - if(argv[i]) { - if(!strcmp(argv[i], "msh1")){ - CTX::instance()->mesh.format = FORMAT_MSH; - CTX::instance()->mesh.mshFileVersion = 1.0; - } - else if(!strcmp(argv[i], "msh2")){ - CTX::instance()->mesh.format = FORMAT_MSH; - CTX::instance()->mesh.mshFileVersion = 2.0; - } - else if(!strcmp(argv[i], "msh")) - CTX::instance()->mesh.format = FORMAT_MSH; - else if(!strcmp(argv[i], "unv")) - CTX::instance()->mesh.format = FORMAT_UNV; - else if(!strcmp(argv[i], "vrml")) - CTX::instance()->mesh.format = FORMAT_VRML; - else if(!strcmp(argv[i], "stl")) - CTX::instance()->mesh.format = FORMAT_STL; - else if(!strcmp(argv[i], "mesh")) - CTX::instance()->mesh.format = FORMAT_MESH; - else if(!strcmp(argv[i], "bdf")) - CTX::instance()->mesh.format = FORMAT_BDF; - else if(!strcmp(argv[i], "p3d")) - CTX::instance()->mesh.format = FORMAT_P3D; - else if(!strcmp(argv[i], "cgns")) - CTX::instance()->mesh.format = FORMAT_CGNS; - else if(!strcmp(argv[i], "diff")) - CTX::instance()->mesh.format = FORMAT_DIFF; - else if(!strcmp(argv[i], "med")) - CTX::instance()->mesh.format = FORMAT_MED; - else if(!strcmp(argv[i], "ir3")) - CTX::instance()->mesh.format = FORMAT_IR3; - else - Msg::Fatal("Unknown mesh format"); - i++; - } - else - Msg::Fatal("Missing format"); - } else if(!strcmp(argv[i] + 1, "bin")) { i++; CTX::instance()->mesh.binary = 1; diff --git a/Common/CreateFile.cpp b/Common/CreateFile.cpp index 1629b17a0b..dc15fcfca5 100644 --- a/Common/CreateFile.cpp +++ b/Common/CreateFile.cpp @@ -43,6 +43,7 @@ int GuessFileFormatFromFileName(std::string fileName) else if(ext == ".mesh") return FORMAT_MESH; else if(ext == ".bdf") return FORMAT_BDF; else if(ext == ".diff") return FORMAT_DIFF; + else if(ext == ".inp") return FORMAT_INP; else if(ext == ".nas") return FORMAT_BDF; else if(ext == ".p3d") return FORMAT_P3D; else if(ext == ".wrl") return FORMAT_VRML; @@ -86,6 +87,7 @@ std::string GetDefaultFileName(int format) case FORMAT_MESH: name += ".mesh"; break; case FORMAT_BDF: name += ".bdf"; break; case FORMAT_DIFF: name += ".diff"; break; + case FORMAT_INP: name += ".inp"; break; case FORMAT_P3D: name += ".p3d"; break; case FORMAT_VRML: name += ".wrl"; break; case FORMAT_GIF: name += ".gif"; break; @@ -238,6 +240,11 @@ void CreateOutputFile(std::string fileName, int format) CTX::instance()->mesh.scalingFactor); break; + case FORMAT_INP: + GModel::current()->writeINP + (fileName, CTX::instance()->mesh.saveAll, CTX::instance()->mesh.scalingFactor); + break; + case FORMAT_P3D: GModel::current()->writeP3D (fileName, CTX::instance()->mesh.saveAll, CTX::instance()->mesh.scalingFactor); diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 87228c0c7b..b4eb48b55d 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -1091,8 +1091,8 @@ StringXNumber MeshOptions_Number[] = { { F|O, "Explode" , opt_mesh_explode , 1.0 , "Element shrinking factor (between 0 and 1)" }, - { F|O, "Format" , opt_mesh_format , FORMAT_MSH , - "Mesh output format (1=msh, 2=unv, 19=vrml, 27=stl, 30=mesh, 31=bdf, " + { F|O, "Format" , opt_mesh_format , FORMAT_AUTO , + "Mesh output format (1=msh, 2=unv, 10=automatic, 19=vrml, 27=stl, 30=mesh, 31=bdf, " "32=cgns, 33=med)" }, { F|O, "Hexahedra" , opt_mesh_hexahedra , 1. , diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp index 39be0d9578..9574243e27 100644 --- a/Common/Gmsh.cpp +++ b/Common/Gmsh.cpp @@ -167,7 +167,9 @@ int GmshBatch() GModel::current()->checkMeshCoherence(CTX::instance()->geom.tolerance); } else if(CTX::instance()->batch == -1){ - CreateOutputFile(CTX::instance()->outputFileName, FORMAT_AUTO); + CreateOutputFile(CTX::instance()->outputFileName, + CTX::instance()->outputFileName.empty() ? FORMAT_GEO : + FORMAT_AUTO); } else if(CTX::instance()->batch > 0){ #if defined(HAVE_MESH) @@ -186,7 +188,9 @@ int GmshBatch() } #endif #endif - CreateOutputFile(CTX::instance()->outputFileName, CTX::instance()->mesh.format); + CreateOutputFile(CTX::instance()->outputFileName, + CTX::instance()->outputFileName.empty() ? FORMAT_MSH : + FORMAT_AUTO); } time_t now; diff --git a/Common/GmshDefines.h b/Common/GmshDefines.h index d4ebdd94fe..ff39bdc25d 100644 --- a/Common/GmshDefines.h +++ b/Common/GmshDefines.h @@ -42,6 +42,7 @@ #define FORMAT_STEP 36 #define FORMAT_IGES 37 #define FORMAT_IR3 38 +#define FORMAT_INP 39 // Element types #define TYPE_PNT 1 diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp index 8292212de5..39df2e0367 100644 --- a/Fltk/menuWindow.cpp +++ b/Fltk/menuWindow.cpp @@ -251,6 +251,8 @@ static int _save_vtk(const char *name){ return genericMeshFileDialog (name, "VTK Options", FORMAT_VTK, true, false); } static int _save_diff(const char *name){ return genericMeshFileDialog (name, "Diffpack Options", FORMAT_DIFF, true, false); } +static int _save_inp(const char *name){ return genericMeshFileDialog + (name, "Abaqus INP Options", FORMAT_INP, false, false); } static int _save_med(const char *name){ return genericMeshFileDialog (name, "MED Options", FORMAT_MED, false, false); } static int _save_mesh(const char *name){ return genericMeshFileDialog @@ -297,6 +299,7 @@ static int _save_auto(const char *name) case FORMAT_MESH : return _save_mesh(name); case FORMAT_BDF : return _save_bdf(name); case FORMAT_DIFF : return _save_diff(name); + case FORMAT_INP : return _save_inp(name); case FORMAT_P3D : return _save_p3d(name); case FORMAT_IR3 : return _save_ir3(name); case FORMAT_STL : return _save_stl(name); @@ -334,6 +337,7 @@ static void file_save_as_cb(Fl_Widget *w, void *data) {"Gmsh Unrolled Geometry" TT "*.geo", _save_geo}, SEPARATOR_OUT #if defined(HAVE_LIBCGNS) + {"Abaqus INP Mesh" TT "*.inp", _save_inp}, {"CGNS (Experimental)" TT "*.cgns", _save_cgns}, #endif {"Diffpack 3D Mesh" TT "*.diff", _save_diff}, @@ -1590,7 +1594,7 @@ static void mesh_save_cb(Fl_Widget *w, void *data) "Cancel", "Replace", 0, name.c_str())) return; } - CreateOutputFile(name, CTX::instance()->mesh.format); + CreateOutputFile(name, name.empty() ? FORMAT_MSH : CTX::instance()->mesh.format); } static void mesh_define_cb(Fl_Widget *w, void *data) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index a6c8872600..e90923f2af 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1557,7 +1557,7 @@ void GModel::load(std::string fileName) { GModel *temp = GModel::current(); GModel::setCurrent(this); - MergeFile(fileName.c_str(),true); + MergeFile(fileName, true); GModel::setCurrent(temp); } diff --git a/Geo/GModel.h b/Geo/GModel.h index 9138f7adfa..bfc416c9fd 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -536,6 +536,10 @@ class GModel int writeDIFF(const std::string &name, bool binary=false, bool saveAll=false, double scalingFactor=1.0); + // Abaqus + int writeINP(const std::string &name, bool saveAll=false, + double scalingFactor=1.0); + void save(std::string fileName); void load(std::string fileName); diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp index 7642d0829c..f931130018 100644 --- a/Geo/GModelIO_Mesh.cpp +++ b/Geo/GModelIO_Mesh.cpp @@ -539,7 +539,6 @@ static void writeElementMSH(FILE *fp, GModel *model, T *ele, bool saveAll, } template<class T> - static void writeElementsMSH(FILE *fp, GModel *model, std::vector<T*> &ele, bool saveAll, int saveSinglePartition, double version, bool binary, int &num, int elementary, @@ -2976,9 +2975,30 @@ int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, return 1; } -#if 0 // TODO check and test this -int GModel::writeAbaqus(const std::string &name, bool saveAll, - double scalingFactor) +template <class T> +static void writeElementsINP(FILE *fp, GEntity *ge, std::vector<T*> &elements, + bool saveAll, int &ne) +{ + if(elements.size() && (saveAll || ge->physicals.size())){ + const char *typ = elements[0]->getStringForINP(); + if(typ){ + int np = (saveAll ? 1 : ge->physicals.size()); + for(int p = 0; p < np; p++){ + int part = (saveAll ? ge->tag() : ge->physicals[p]); + fprintf(fp, "*Element, type=%s, ELSET=PART%d\n", typ, part); + for(unsigned int i = 0; i < elements.size(); i++){ + fprintf(fp, "%d", ne++); + for(int j = 0; j < elements[i]->getNumVertices(); j++) + fprintf(fp, ", %d", elements[i]->getVertexINP(j)->getIndex()); + fprintf(fp, "\n"); + } + } + } + } +} + +int GModel::writeINP(const std::string &name, bool saveAll, + double scalingFactor) { FILE *fp = fopen(name.c_str(), "w"); if(!fp){ @@ -2986,9 +3006,14 @@ int GModel::writeAbaqus(const std::string &name, bool saveAll, return 0; } + Msg::Error("Abaqus INP export has not been tested yet -- please give us" + "feedback!"); + if(noPhysicalGroups()) saveAll = true; - int numVertices = indexMeshVertices(saveAll); + indexMeshVertices(saveAll); + std::vector<GEntity*> entities; + getEntities(entities); fprintf(fp, "*Heading\n"); fprintf(fp, " %s\n", name.c_str()); @@ -2997,30 +3022,33 @@ int GModel::writeAbaqus(const std::string &name, bool saveAll, for(unsigned int i = 0; i < entities.size(); i++) if(entities[i]->physicals.size() || saveAll) for(unsigned int j = 0; j < entities[i]->getNumMeshVertices(); j++){ - MVertex *v = entities[i]->getNumMeshVertex(j); - fprintf(fp, "%d, %g, %g, %g\n", v->getIndex(), v->x(), v->y(), v->z()); + MVertex *v = entities[i]->getMeshVertex(j); + if(v->getIndex() >= 0) + fprintf(fp, "%d, %g, %g, %g\n", v->getIndex(), v->x() * scalingFactor, + v->y() * scalingFactor, v->z() * scalingFactor); } - + int ne = 1; - for(unsigned int i = 0; i < entities.size(); i++) - if(entities[i]->physicals.size() || saveAll){ - if(entities[i]->getNumMeshElements()){ - MElement *e = entities[i]->getMeshElement(0); - fprintf(fp, "*Element, type=C3D4, ELSET=PART%d\n", entities[i]->tag()); - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - MElement *e = entities[i]->getNumMeshElement(j); - fprintf(fp, "%d", ne++); - for(int k = 0; k < e->getNumVertices(); k++) - fpritnf(fp, ", %d", e->getVertex(k)->getIndex()); - fprintf(fp, "\n"); - } - } - } + for(viter it = firstVertex(); it != lastVertex(); ++it){ + writeElementsINP(fp, *it, (*it)->points, saveAll, ne); + } + for(eiter it = firstEdge(); it != lastEdge(); ++it){ + writeElementsINP(fp, *it, (*it)->lines, saveAll, ne); + } + for(fiter it = firstFace(); it != lastFace(); ++it){ + writeElementsINP(fp, *it, (*it)->triangles, saveAll, ne); + writeElementsINP(fp, *it, (*it)->quadrangles, saveAll, ne); + } + for(riter it = firstRegion(); it != lastRegion(); ++it){ + writeElementsINP(fp, *it, (*it)->tetrahedra, saveAll, ne); + writeElementsINP(fp, *it, (*it)->hexahedra, saveAll, ne); + writeElementsINP(fp, *it, (*it)->prisms, saveAll, ne); + writeElementsINP(fp, *it, (*it)->pyramids, saveAll, ne); + } fclose(fp); return 1; } -#endif GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap, std::vector<int> &elementNum, diff --git a/Geo/MElement.h b/Geo/MElement.h index 405388a24e..3e9494ca8b 100644 --- a/Geo/MElement.h +++ b/Geo/MElement.h @@ -96,6 +96,9 @@ class MElement // get the vertex using DIFF ordering virtual MVertex *getVertexDIFF(int num){ return getVertex(num); } + // get the vertex using INP ordering + virtual MVertex *getVertexINP(int num){ return getVertex(num); } + // get the number of vertices associated with edges, faces and // volumes (nonzero only for higher order elements, polygons or // polyhedra) @@ -285,6 +288,7 @@ class MElement virtual const char *getStringForPOS() const { return 0; } virtual const char *getStringForBDF() const { return 0; } virtual const char *getStringForDIFF() const { return 0; } + virtual const char *getStringForINP() const { return 0; } // return the number of vertices, as well as the element name if // 'name' != 0 diff --git a/Geo/MHexahedron.h b/Geo/MHexahedron.h index f077f7067f..68fcd89efc 100644 --- a/Geo/MHexahedron.h +++ b/Geo/MHexahedron.h @@ -119,6 +119,7 @@ class MHexahedron : public MElement { virtual const char *getStringForPOS() const { return "SH"; } virtual const char *getStringForBDF() const { return "CHEXA"; } virtual const char *getStringForDIFF() const { return "ElmB8n3D"; } + virtual const char *getStringForINP() const { return "C3D8"; } virtual void revert() { MVertex *tmp; diff --git a/Geo/MLine.h b/Geo/MLine.h index ff6de0647c..567414087f 100644 --- a/Geo/MLine.h +++ b/Geo/MLine.h @@ -64,6 +64,7 @@ class MLine : public MElement { virtual int getTypeForVTK() const { return 3; } virtual const char *getStringForPOS() const { return "SL"; } virtual const char *getStringForBDF() const { return "CBAR"; } + virtual const char *getStringForINP() const { return "C1D2"; } virtual void revert() { MVertex *tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; @@ -111,6 +112,7 @@ class MLine3 : public MLine { static const int map[3] = {0, 2, 1}; return getVertex(map[num]); } + virtual MVertex *getVertexINP(int num){ return getVertexUNV(num); } virtual int getNumEdgeVertices() const { return 1; } virtual int getNumEdgesRep(){ return 2; } virtual void getEdgeRep(int num, double *x, double *y, double *z, SVector3 *n) @@ -130,6 +132,7 @@ class MLine3 : public MLine { virtual int getTypeForUNV() const { return 24; } // parabolic beam //virtual int getTypeForVTK() const { return 21; } virtual const char *getStringForPOS() const { return "SL2"; } + virtual const char *getStringForINP() const { return "C1D3"; } }; /* diff --git a/Geo/MPrism.h b/Geo/MPrism.h index 13477e419a..9336a490ff 100644 --- a/Geo/MPrism.h +++ b/Geo/MPrism.h @@ -125,6 +125,7 @@ class MPrism : public MElement { virtual int getTypeForVTK() const { return 13; } virtual const char *getStringForPOS() const { return "SI"; } virtual const char *getStringForBDF() const { return "CPENTA"; } + virtual const char *getStringForINP() const { return "C3D6"; } virtual void revert() { MVertex *tmp; diff --git a/Geo/MQuadrangle.h b/Geo/MQuadrangle.h index 6b362d25d1..ea123cd7f7 100644 --- a/Geo/MQuadrangle.h +++ b/Geo/MQuadrangle.h @@ -117,6 +117,7 @@ class MQuadrangle : public MElement { virtual const char *getStringForPOS() const { return "SQ"; } virtual const char *getStringForBDF() const { return "CQUAD4"; } virtual const char *getStringForDIFF() const { return "ElmB4n2D"; } + virtual const char *getStringForINP() const { return "C2D4"; } virtual const polynomialBasis* getFunctionSpace(int o=-1) const; virtual void revert() { @@ -225,6 +226,7 @@ class MQuadrangle8 : public MQuadrangle { //virtual int getTypeForVTK() const { return 23; } virtual const char *getStringForBDF() const { return "CQUAD8"; } virtual const char *getStringForDIFF() const { return "ElmB8n2D"; } + virtual const char *getStringForINP() const { return "C2D8"; } virtual void revert() { MVertex *tmp; diff --git a/Geo/MTetrahedron.h b/Geo/MTetrahedron.h index f757f3d984..bd817daae5 100644 --- a/Geo/MTetrahedron.h +++ b/Geo/MTetrahedron.h @@ -108,6 +108,7 @@ class MTetrahedron : public MElement { virtual const char *getStringForPOS() const { return "SS"; } virtual const char *getStringForBDF() const { return "CTETRA"; } virtual const char *getStringForDIFF() const { return "ElmT4n3D"; } + virtual const char *getStringForINP() const { return "C3D4"; } virtual void revert() { MVertex *tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; diff --git a/Geo/MTriangle.h b/Geo/MTriangle.h index c1fe493607..091c583319 100644 --- a/Geo/MTriangle.h +++ b/Geo/MTriangle.h @@ -120,6 +120,7 @@ class MTriangle : public MElement { virtual const char *getStringForPOS() const { return "ST"; } virtual const char *getStringForBDF() const { return "CTRIA3"; } virtual const char *getStringForDIFF() const { return "ElmT3n2D"; } + virtual const char *getStringForINP() const { return "C2D3"; } virtual void revert() { MVertex *tmp = _v[1]; _v[1] = _v[2]; _v[2] = tmp; @@ -216,6 +217,7 @@ class MTriangle6 : public MTriangle { virtual const char *getStringForPOS() const { return "ST2"; } virtual const char *getStringForBDF() const { return "CTRIA6"; } virtual const char *getStringForDIFF() const { return "ElmT6n2D"; } + virtual const char *getStringForINP() const { return "C2D6"; } virtual void revert() { MVertex *tmp; -- GitLab