mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 22:20:35 +05:00
Adding Gmsh v2.xx Mesh Export Capability - Currently upto 2nd Order Triangles, Quadrangles and Tetrahedra
This commit is contained in:
parent
00bc4a1220
commit
af9d554ecb
@ -6,6 +6,6 @@ noinst_LTLIBRARIES = libinterface.la
|
||||
libinterface_la_SOURCES = read_fnf_mesh.cpp readtetmesh.cpp readuser.cpp writeabaqus.cpp writediffpack.cpp \
|
||||
writedolfin.cpp writeelmer.cpp writefeap.cpp writefluent.cpp writegmsh.cpp writejcm.cpp \
|
||||
writepermas.cpp writetecplot.cpp writetet.cpp writetochnog.cpp writeuser.cpp \
|
||||
wuchemnitz.cpp
|
||||
wuchemnitz.cpp writegmsh2.cpp
|
||||
|
||||
|
||||
|
261
libsrc/interface/writegmsh2.cpp
Normal file
261
libsrc/interface/writegmsh2.cpp
Normal file
@ -0,0 +1,261 @@
|
||||
/*! \file writegmsh2.cpp
|
||||
* \brief Export Netgen Mesh in the GMSH v2.xx File format
|
||||
* \author Philippose Rajan
|
||||
* \date 02 November 2008
|
||||
*
|
||||
* This function extends the export capabilities of
|
||||
* Netgen to include the GMSH v2.xx File Format.
|
||||
*
|
||||
* Current features of this function include:
|
||||
*
|
||||
* 1. Exports Triangles, Quadrangles and Tetrahedra \n
|
||||
* 2. Supports upto second order elements of each type
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <mystdlib.h>
|
||||
|
||||
#include <myadt.hpp>
|
||||
#include <linalg.hpp>
|
||||
#include <csg.hpp>
|
||||
#include <meshing.hpp>
|
||||
|
||||
namespace netgen
|
||||
{
|
||||
#include "writeuser.hpp"
|
||||
|
||||
// Mapping of entities from Netgen definitions to GMSH definitions
|
||||
enum GMSH_ELEMENTS {GMSH_TRIG = 2, GMSH_TRIG6 = 9,
|
||||
GMSH_QUAD = 3, GMSH_QUAD8 = 16,
|
||||
GMSH_TET = 4, GMSH_TET10 = 11};
|
||||
const int triGmsh[7] = {0,1,2,3,6,4,5};
|
||||
const int quadGmsh[9] = {0,1,2,3,4,5,8,6,7};
|
||||
const int tetGmsh[11] = {0,1,2,3,4,5,8,6,7,10,9};
|
||||
|
||||
|
||||
/*! GMSH v2.xx mesh format export function
|
||||
*
|
||||
* This function extends the export capabilities of
|
||||
* Netgen to include the GMSH v2.xx File Format.
|
||||
*
|
||||
* Current features of this function include:
|
||||
*
|
||||
* 1. Exports Triangles, Quadrangles and Tetrahedra \n
|
||||
* 2. Supports upto second order elements of each type
|
||||
*
|
||||
*/
|
||||
void WriteGmsh2Format (const Mesh & mesh,
|
||||
const CSGeometry & geom,
|
||||
const string & filename)
|
||||
{
|
||||
ofstream outfile (filename.c_str());
|
||||
outfile.precision(6);
|
||||
outfile.setf (ios::fixed, ios::floatfield);
|
||||
outfile.setf (ios::showpoint);
|
||||
|
||||
int np = mesh.GetNP(); /// number of points in mesh
|
||||
int ne = mesh.GetNE(); /// number of 3D elements in mesh
|
||||
int nse = mesh.GetNSE(); /// number of surface elements (BC)
|
||||
int i, j, k, l;
|
||||
|
||||
|
||||
/*
|
||||
* 3D section : Volume elements (currently only tetrahedra)
|
||||
*/
|
||||
|
||||
if ((ne > 0)
|
||||
&& (mesh.VolumeElement(1).GetNP() <= 10)
|
||||
&& (mesh.SurfaceElement(1).GetNP() <= 6))
|
||||
{
|
||||
cout << "Write GMSH v2.xx Format \n";
|
||||
cout << "The GMSH v2.xx export is currently available for elements upto 2nd Order\n" << endl;
|
||||
|
||||
int inverttets = mparam.inverttets;
|
||||
int invertsurf = mparam.inverttrigs;
|
||||
|
||||
/// Prepare GMSH 2.0 file (See GMSH 2.0 Documentation)
|
||||
outfile << "$MeshFormat\n";
|
||||
outfile << (float)2.0 << " "
|
||||
<< (int)0 << " "
|
||||
<< (int)sizeof(double) << "\n";
|
||||
outfile << "$EndMeshFormat\n";
|
||||
|
||||
/// Write nodes
|
||||
outfile << "$Nodes\n";
|
||||
outfile << np << "\n";
|
||||
|
||||
for (i = 1; i <= np; i++)
|
||||
{
|
||||
const Point3d & p = mesh.Point(i);
|
||||
outfile << i << " "; /// node number
|
||||
outfile << p.X() << " ";
|
||||
outfile << p.Y() << " ";
|
||||
outfile << p.Z() << "\n";
|
||||
}
|
||||
|
||||
outfile << "$EndNodes\n";
|
||||
|
||||
/// write elements (both, surface elements and volume elements)
|
||||
outfile << "$Elements\n";
|
||||
outfile << ne + nse << "\n"; //// number of elements + number of surfaces BC
|
||||
|
||||
for (i = 1; i <= nse; i++)
|
||||
{
|
||||
int elType = 0;
|
||||
|
||||
Element2d el = mesh.SurfaceElement(i);
|
||||
if(invertsurf) el.Invert();
|
||||
|
||||
if(el.GetNP() == 3) elType = GMSH_TRIG; //// GMSH Type for a 3 node triangle
|
||||
if(el.GetNP() == 6) elType = GMSH_TRIG6; //// GMSH Type for a 6 node triangle
|
||||
if(elType == 0)
|
||||
{
|
||||
cout << " Invalid surface element type for Gmsh 2.0 3D-Mesh Export Format !\n";
|
||||
return;
|
||||
}
|
||||
|
||||
outfile << i;
|
||||
outfile << " ";
|
||||
outfile << elType;
|
||||
outfile << " ";
|
||||
outfile << "2"; //// Number of tags (2 => Physical and elementary entities)
|
||||
outfile << " ";
|
||||
outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";
|
||||
/// that means that physical entity = elementary entity (arbitrary approach)
|
||||
outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";
|
||||
for (j = 1; j <= el.GetNP(); j++)
|
||||
{
|
||||
outfile << " ";
|
||||
outfile << el.PNum(triGmsh[j]);
|
||||
}
|
||||
outfile << "\n";
|
||||
}
|
||||
|
||||
|
||||
for (i = 1; i <= ne; i++)
|
||||
{
|
||||
int elType = 0;
|
||||
|
||||
Element el = mesh.VolumeElement(i);
|
||||
if (inverttets) el.Invert();
|
||||
|
||||
if(el.GetNP() == 4) elType = GMSH_TET; //// GMSH Element type for 4 node tetrahedron
|
||||
if(el.GetNP() == 10) elType = GMSH_TET10; //// GMSH Element type for 10 node tetrahedron
|
||||
if(elType == 0)
|
||||
{
|
||||
cout << " Invalid volume element type for Gmsh 2.0 3D-Mesh Export Format !\n";
|
||||
return;
|
||||
}
|
||||
|
||||
outfile << nse + i; //// element number (Remember to add on surface elements)
|
||||
outfile << " ";
|
||||
outfile << elType;
|
||||
outfile << " ";
|
||||
outfile << "2"; //// Number of tags (2 => Physical and elementary entities)
|
||||
outfile << " ";
|
||||
outfile << 100000 + el.GetIndex();
|
||||
/// that means that physical entity = elementary entity (arbitrary approach)
|
||||
outfile << " ";
|
||||
outfile << 100000 + el.GetIndex(); /// volume number
|
||||
outfile << " ";
|
||||
for (j = 1; j <= el.GetNP(); j++)
|
||||
{
|
||||
outfile << " ";
|
||||
outfile << el.PNum(tetGmsh[j]);
|
||||
}
|
||||
outfile << "\n";
|
||||
}
|
||||
outfile << "$EndElements\n";
|
||||
}
|
||||
/*
|
||||
* End of 3D section
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* 2D section : available for triangles and quadrangles
|
||||
* upto 2nd Order
|
||||
*/
|
||||
else if(ne == 0) /// means that there's no 3D element
|
||||
{
|
||||
cout << "\n Write Gmsh v2.xx Surface Mesh (triangle and/or quadrangles upto 2nd Order)" << endl;
|
||||
|
||||
/// Prepare GMSH 2.0 file (See GMSH 2.0 Documentation)
|
||||
outfile << "$MeshFormat\n";
|
||||
outfile << (float)2.0 << " "
|
||||
<< (int)0 << " "
|
||||
<< (int)sizeof(double) << "\n";
|
||||
outfile << "$EndMeshFormat\n";
|
||||
|
||||
/// Write nodes
|
||||
outfile << "$Nodes\n";
|
||||
outfile << np << "\n";
|
||||
|
||||
for (i = 1; i <= np; i++)
|
||||
{
|
||||
const Point3d & p = mesh.Point(i);
|
||||
outfile << i << " "; /// node number
|
||||
outfile << p.X() << " ";
|
||||
outfile << p.Y() << " ";
|
||||
outfile << p.Z() << "\n";
|
||||
}
|
||||
outfile << "$EndNodes\n";
|
||||
|
||||
/// write triangles & quadrangles
|
||||
outfile << "$Elements\n";
|
||||
outfile << nse << "\n";
|
||||
|
||||
for (k = 1; k <= nse; k++)
|
||||
{
|
||||
int elType = 0;
|
||||
|
||||
const Element2d & el = mesh.SurfaceElement(k);
|
||||
|
||||
if(el.GetNP() == 3) elType = GMSH_TRIG; //// GMSH Type for a 3 node triangle
|
||||
if(el.GetNP() == 6) elType = GMSH_TRIG6; //// GMSH Type for a 6 node triangle
|
||||
if(el.GetNP() == 4) elType = GMSH_QUAD; //// GMSH Type for a 4 node quadrangle
|
||||
if(el.GetNP() == 8) elType = GMSH_QUAD8; //// GMSH Type for an 8 node quadrangle
|
||||
if(elType == 0)
|
||||
{
|
||||
cout << " Invalid surface element type for Gmsh 2.0 2D-Mesh Export Format !\n";
|
||||
return;
|
||||
}
|
||||
|
||||
outfile << k;
|
||||
outfile << " ";
|
||||
outfile << elType;
|
||||
outfile << " ";
|
||||
outfile << "2";
|
||||
outfile << " ";
|
||||
outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";
|
||||
/// that means that physical entity = elementary entity (arbitrary approach)
|
||||
outfile << mesh.GetFaceDescriptor (el.GetIndex()).BCProperty() << " ";
|
||||
for (l = 1; l <= el.GetNP(); l++)
|
||||
{
|
||||
outfile << " ";
|
||||
if((elType == GMSH_TRIG) || (elType == GMSH_TRIG6))
|
||||
{
|
||||
outfile << el.PNum(triGmsh[l]);
|
||||
}
|
||||
else if((elType == GMSH_QUAD) || (elType == GMSH_QUAD8))
|
||||
{
|
||||
outfile << el.PNum(quadGmsh[l]);
|
||||
}
|
||||
}
|
||||
outfile << "\n";
|
||||
}
|
||||
outfile << "$EndElements\n";
|
||||
}
|
||||
/*
|
||||
* End of 2D section
|
||||
*/
|
||||
|
||||
else
|
||||
{
|
||||
cout << " Invalid element type for Gmsh v2.xx Export Format !\n";
|
||||
}
|
||||
} // End: WriteGmsh2Format
|
||||
} // End: namespace netgen
|
||||
|
||||
|
@ -32,6 +32,7 @@ void RegisterUserFormats (Array<const char*> & names)
|
||||
"STL Format",
|
||||
"VRML Format",
|
||||
"Gmsh Format",
|
||||
"Gmsh2 Format"
|
||||
"JCMwave Format",
|
||||
"TET Format",
|
||||
// { "Chemnitz Format" },
|
||||
@ -101,6 +102,11 @@ bool WriteUserFormat (const string & format,
|
||||
else if (format == "Gmsh Format")
|
||||
WriteGmshFormat (mesh, geom, filename);
|
||||
|
||||
// Philippose - 29/01/2009
|
||||
// Added Gmsh v2.xx export capability
|
||||
else if (format == "Gmsh2 Format")
|
||||
WriteGmsh2Format (mesh, geom, filename);
|
||||
|
||||
else if (format == "JCMwave Format")
|
||||
WriteJCMFormat (mesh, geom, filename);
|
||||
|
||||
|
@ -55,6 +55,14 @@ void WriteGmshFormat (const Mesh & mesh,
|
||||
const CSGeometry & geom,
|
||||
const string & filename);
|
||||
|
||||
|
||||
// Philippose - 29/01/2009
|
||||
// Added GMSH v2.xx Mesh Export support
|
||||
void WriteGmsh2Format (const Mesh & mesh,
|
||||
const CSGeometry & geom,
|
||||
const string & filename);
|
||||
|
||||
|
||||
extern
|
||||
void WriteUserChemnitz (const Mesh & mesh,
|
||||
const string & filename);
|
||||
|
Loading…
Reference in New Issue
Block a user