Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writegmsh.cpp
3206 views
/*************************************1* Write Gmsh file2* First issue the 04/26/2004 by Paul CARRICO ([email protected])3* At the moment, the GMSH format is available for4* linear tetrahedron elements i.e. in 3D5* (based on Neutral Format)6*7* Second issue the 05/05/2004 by Paul CARRICO8* Thanks to Joachim Schoeberl for the correction of a minor bug9* the 2 initial Gmsh Format (i.e. volume format and surface format) are group together)10* in only one file11**************************************/1213#include <mystdlib.h>1415#include <myadt.hpp>16#include <linalg.hpp>17#include <csg.hpp>18#include <meshing.hpp>1920namespace netgen21{22#include "writeuser.hpp"23242526/*27* GMSH mesh format28* points, elements, surface elements and physical entities29*/3031void WriteGmshFormat (const Mesh & mesh,32const CSGeometry & geom,33const string & filename)34{35ofstream outfile (filename.c_str());36outfile.precision(6);37outfile.setf (ios::fixed, ios::floatfield);38outfile.setf (ios::showpoint);3940int np = mesh.GetNP(); /// number of point41int ne = mesh.GetNE(); /// number of element42int nse = mesh.GetNSE(); /// number of surface element (BC)43int i, j, k, l;444546/*47* 3D section : Linear volume elements (only tetrahedra)48*/4950if (ne > 0 && mesh.VolumeElement(1).GetNP() == 4)51{52cout << "Write GMSH Format \n";53cout << "The GMSH format is available for linear tetrahedron elements only in 3D\n" << endl;5455int inverttets = mparam.inverttets;56int invertsurf = mparam.inverttrigs;575859/// Write nodes60outfile << "$NOD\n";61outfile << np << "\n";6263for (i = 1; i <= np; i++)64{65const Point3d & p = mesh.Point(i);66outfile << i << " "; /// node number67outfile << p.X() << " ";68outfile << p.Y() << " ";69outfile << p.Z() << "\n";70}71outfile << "$ENDNOD\n";7273/// write elements74outfile << "$ELM\n";75outfile << ne + nse << "\n"; //// number of elements + number of surfaces BC7677for (i = 1; i <= nse; i++)78{79Element2d el = mesh.SurfaceElement(i);80if (invertsurf) el.Invert();81outfile << i;82outfile << " ";83outfile << "2";84outfile << " ";85outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";86/// that means that physical entity = elementary entity (arbitrary approach)87outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";88outfile << "3";89outfile << " ";90for (j = 1; j <= el.GetNP(); j++)91{92outfile << " ";93outfile << el.PNum(j);94}95outfile << "\n";96}979899for (i = 1; i <= ne; i++)100{101Element el = mesh.VolumeElement(i);102if (inverttets) el.Invert();103outfile << nse + i; /// element number104outfile << " ";105outfile << "4"; /// element type i.e. Tetraedron == 4106outfile << " ";107outfile << 100000 + el.GetIndex();108/// that means that physical entity = elementary entity (arbitrary approach)109outfile << " ";110outfile << 100000 + el.GetIndex(); /// volume number111outfile << " ";112outfile << "4"; /// number of nodes i.e. 4 for a tetrahedron113114for (j = 1; j <= el.GetNP(); j++)115{116outfile << " ";117outfile << el.PNum(j);118}119outfile << "\n";120}121122123outfile << "$ENDELM\n";124}125126/*127* End of 3D section128*/129130131132133134/*135* 2D section : available for triangles and quadrangles136*/137else if (ne == 0) /// means that there's no 3D element138{139cout << "\n Write Gmsh Surface Mesh (triangle and/or quadrangles)" << endl;140141/// Write nodes142outfile << "$NOD\n";143outfile << np << "\n";144145for (i = 1; i <= np; i++)146{147const Point3d & p = mesh.Point(i);148outfile << i << " "; /// node number149outfile << p.X() << " ";150outfile << p.Y() << " ";151outfile << p.Z() << "\n";152}153outfile << "$ENDNOD\n";154155156/// write triangles & quadrangles157outfile << "$ELM\n";158outfile << nse << "\n";159160for (k = 1; k <= nse; k++)161{162const Element2d & el = mesh.SurfaceElement(k);163164165outfile << k;166outfile << " ";167outfile << (el.GetNP()-1); // 2 for a triangle and 3 for a quadrangle168outfile << " ";169outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";170/// that means that physical entity = elementary entity (arbitrary approach)171outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";172outfile << (el.GetNP()); // number of node per surfacic element173outfile << " ";174175for (l = 1; l <= el.GetNP(); l++)176{177outfile << " ";178outfile << el.PNum(l);179}180outfile << "\n";181182}183outfile << "$ENDELM$ \n";184}185186/*187* End of 2D section188*/189190else191{192cout << " Invalide element type for Gmsh volume Format !\n";193}194195196}197}198199200201202