Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::Utilities::InputGmsh Class Reference

#include <InputGmsh.h>

Inheritance diagram for Nektar::Utilities::InputGmsh:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::InputGmsh:
Collaboration graph
[legend]

Public Member Functions

 InputGmsh (MeshSharedPtr m)
 Set up InputGmsh object.
virtual ~InputGmsh ()
virtual void Process ()
- Public Member Functions inherited from Nektar::Utilities::InputModule
 InputModule (FieldSharedPtr p_m)
void AddFile (string fileType, string fileName)
 InputModule (MeshSharedPtr p_m)
void OpenStream ()
 Open a file for input.
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
virtual void Process (po::variables_map &vm)=0
void RegisterConfig (string key, string value)
 Register a configuration option with a module.
void PrintConfig ()
 Print out all configuration options for a module.
void SetDefaults ()
 Sets default configuration options for those which have not been set.
bool GetRequireEquiSpaced (void)
void SetRequireEquiSpaced (bool pVal)
 Module (MeshSharedPtr p_m)
void RegisterConfig (string key, string value)
void PrintConfig ()
void SetDefaults ()
MeshSharedPtr GetMesh ()
virtual void ProcessVertices ()
 Extract element vertices.

Static Public Member Functions

static ModuleSharedPtr create (MeshSharedPtr m)
 Creates an instance of this class.
static std::map< unsigned int,
ElmtConfig
GenElmMap ()

Static Public Attributes

static ModuleKey className
 ModuleKey for class.
static std::map< unsigned int,
ElmtConfig
elmMap

Private Member Functions

int GetNnodes (unsigned int InputGmshEntity)

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::InputModule
void PrintSummary ()
 Print summary of elements.
void PrintSummary ()
 Print summary of elements.
- Protected Attributes inherited from Nektar::Utilities::InputModule
set< string > m_allowedFiles
std::ifstream m_mshFile
 Input stream.

Detailed Description

Converter for Gmsh files.

Definition at line 48 of file InputGmsh.h.

Constructor & Destructor Documentation

Nektar::Utilities::InputGmsh::InputGmsh ( MeshSharedPtr  m)

Set up InputGmsh object.

Definition at line 60 of file InputGmsh.cpp.

{
}
Nektar::Utilities::InputGmsh::~InputGmsh ( )
virtual

Definition at line 65 of file InputGmsh.cpp.

{
}

Member Function Documentation

static ModuleSharedPtr Nektar::Utilities::InputGmsh::create ( MeshSharedPtr  m)
inlinestatic

Creates an instance of this class.

Definition at line 56 of file InputGmsh.h.

{
return MemoryManager<InputGmsh>::AllocateSharedPtr(m);
}
std::map< unsigned int, ElmtConfig > Nektar::Utilities::InputGmsh::GenElmMap ( )
static

Definition at line 320 of file InputGmsh.cpp.

References Nektar::LibUtilities::eHexahedron, Nektar::LibUtilities::ePoint, Nektar::LibUtilities::ePrism, Nektar::LibUtilities::ePyramid, Nektar::LibUtilities::eQuadrilateral, Nektar::LibUtilities::eSegment, Nektar::LibUtilities::eTetrahedron, and Nektar::LibUtilities::eTriangle.

{
using namespace LibUtilities;
std::map<unsigned int, ElmtConfig> tmp;
// Elmt type, order, face, volume
tmp[ 1] = ElmtConfig(eSegment, 1, true, true);
tmp[ 2] = ElmtConfig(eTriangle, 1, true, true);
tmp[ 3] = ElmtConfig(eQuadrilateral, 1, true, true);
tmp[ 4] = ElmtConfig(eTetrahedron, 1, true, true);
tmp[ 5] = ElmtConfig(eHexahedron, 1, true, true);
tmp[ 6] = ElmtConfig(ePrism, 1, true, true);
tmp[ 7] = ElmtConfig(ePyramid, 1, true, true);
tmp[ 8] = ElmtConfig(eSegment, 2, true, true);
tmp[ 9] = ElmtConfig(eTriangle, 2, true, true);
tmp[ 10] = ElmtConfig(eQuadrilateral, 2, true, true);
tmp[ 11] = ElmtConfig(eTetrahedron, 2, true, true);
tmp[ 12] = ElmtConfig(eHexahedron, 2, true, true);
tmp[ 13] = ElmtConfig(ePrism, 2, true, true);
tmp[ 15] = ElmtConfig(ePoint, 1, true, false);
tmp[ 16] = ElmtConfig(eQuadrilateral, 2, false, false);
tmp[ 17] = ElmtConfig(eHexahedron, 2, false, false);
tmp[ 18] = ElmtConfig(ePrism, 2, false, false);
tmp[ 20] = ElmtConfig(eTriangle, 3, false, false);
tmp[ 21] = ElmtConfig(eTriangle, 3, true, false);
tmp[ 22] = ElmtConfig(eTriangle, 4, false, false);
tmp[ 23] = ElmtConfig(eTriangle, 4, true, false);
tmp[ 24] = ElmtConfig(eTriangle, 5, false, false);
tmp[ 25] = ElmtConfig(eTriangle, 5, true, false);
tmp[ 26] = ElmtConfig(eSegment, 3, true, false);
tmp[ 27] = ElmtConfig(eSegment, 4, true, false);
tmp[ 28] = ElmtConfig(eSegment, 5, true, false);
tmp[ 29] = ElmtConfig(eTetrahedron, 3, true, true);
tmp[ 30] = ElmtConfig(eTetrahedron, 4, true, true);
tmp[ 31] = ElmtConfig(eTetrahedron, 5, true, true);
tmp[ 32] = ElmtConfig(eTetrahedron, 4, true, false);
tmp[ 33] = ElmtConfig(eTetrahedron, 5, true, false);
tmp[ 36] = ElmtConfig(eQuadrilateral, 3, true, false);
tmp[ 37] = ElmtConfig(eQuadrilateral, 4, true, false);
tmp[ 38] = ElmtConfig(eQuadrilateral, 5, true, false);
tmp[ 39] = ElmtConfig(eQuadrilateral, 3, false, false);
tmp[ 40] = ElmtConfig(eQuadrilateral, 4, false, false);
tmp[ 41] = ElmtConfig(eQuadrilateral, 5, false, false);
tmp[ 42] = ElmtConfig(eTriangle, 6, true, false);
tmp[ 43] = ElmtConfig(eTriangle, 7, true, false);
tmp[ 44] = ElmtConfig(eTriangle, 8, true, false);
tmp[ 45] = ElmtConfig(eTriangle, 9, true, false);
tmp[ 46] = ElmtConfig(eTriangle, 10, true, false);
tmp[ 47] = ElmtConfig(eQuadrilateral, 6, true, false);
tmp[ 48] = ElmtConfig(eQuadrilateral, 7, true, false);
tmp[ 49] = ElmtConfig(eQuadrilateral, 8, true, false);
tmp[ 50] = ElmtConfig(eQuadrilateral, 9, true, false);
tmp[ 51] = ElmtConfig(eQuadrilateral, 10, true, false);
tmp[ 52] = ElmtConfig(eTriangle, 6, false, false);
tmp[ 53] = ElmtConfig(eTriangle, 7, false, false);
tmp[ 54] = ElmtConfig(eTriangle, 8, false, false);
tmp[ 55] = ElmtConfig(eTriangle, 9, false, false);
tmp[ 56] = ElmtConfig(eTriangle, 10, false, false);
tmp[ 57] = ElmtConfig(eQuadrilateral, 6, false, false);
tmp[ 58] = ElmtConfig(eQuadrilateral, 7, false, false);
tmp[ 59] = ElmtConfig(eQuadrilateral, 8, false, false);
tmp[ 60] = ElmtConfig(eQuadrilateral, 9, false, false);
tmp[ 61] = ElmtConfig(eQuadrilateral, 10, false, false);
tmp[ 62] = ElmtConfig(eSegment, 6, true, false);
tmp[ 63] = ElmtConfig(eSegment, 7, true, false);
tmp[ 64] = ElmtConfig(eSegment, 8, true, false);
tmp[ 65] = ElmtConfig(eSegment, 9, true, false);
tmp[ 66] = ElmtConfig(eSegment, 10, true, false);
tmp[ 71] = ElmtConfig(eTetrahedron, 6, true, true);
tmp[ 72] = ElmtConfig(eTetrahedron, 7, true, true);
tmp[ 73] = ElmtConfig(eTetrahedron, 8, true, true);
tmp[ 74] = ElmtConfig(eTetrahedron, 9, true, true);
tmp[ 75] = ElmtConfig(eTetrahedron, 10, true, true);
tmp[ 79] = ElmtConfig(eTetrahedron, 6, true, false);
tmp[ 80] = ElmtConfig(eTetrahedron, 7, true, false);
tmp[ 81] = ElmtConfig(eTetrahedron, 8, true, false);
tmp[ 82] = ElmtConfig(eTetrahedron, 9, true, false);
tmp[ 83] = ElmtConfig(eTetrahedron, 10, true, false);
tmp[ 90] = ElmtConfig(ePrism, 3, true, true);
tmp[ 91] = ElmtConfig(ePrism, 4, true, true);
tmp[ 92] = ElmtConfig(eHexahedron, 3, true, true);
tmp[ 93] = ElmtConfig(eHexahedron, 4, true, true);
tmp[ 94] = ElmtConfig(eHexahedron, 5, true, true);
tmp[ 95] = ElmtConfig(eHexahedron, 6, true, true);
tmp[ 96] = ElmtConfig(eHexahedron, 7, true, true);
tmp[ 97] = ElmtConfig(eHexahedron, 8, true, true);
tmp[ 98] = ElmtConfig(eHexahedron, 9, true, true);
tmp[ 99] = ElmtConfig(eHexahedron, 3, true, false);
tmp[100] = ElmtConfig(eHexahedron, 4, true, false);
tmp[101] = ElmtConfig(eHexahedron, 5, true, false);
tmp[102] = ElmtConfig(eHexahedron, 6, true, false);
tmp[103] = ElmtConfig(eHexahedron, 7, true, false);
tmp[104] = ElmtConfig(eHexahedron, 8, true, false);
tmp[105] = ElmtConfig(eHexahedron, 9, true, false);
tmp[106] = ElmtConfig(ePrism, 5, true, true);
tmp[107] = ElmtConfig(ePrism, 6, true, true);
tmp[108] = ElmtConfig(ePrism, 7, true, true);
tmp[109] = ElmtConfig(ePrism, 8, true, true);
tmp[110] = ElmtConfig(ePrism, 9, true, true);
tmp[111] = ElmtConfig(ePrism, 3, true, false);
tmp[112] = ElmtConfig(ePrism, 4, true, false);
tmp[113] = ElmtConfig(ePrism, 5, true, false);
tmp[114] = ElmtConfig(ePrism, 6, true, false);
tmp[115] = ElmtConfig(ePrism, 7, true, false);
tmp[116] = ElmtConfig(ePrism, 8, true, false);
tmp[117] = ElmtConfig(ePrism, 9, true, false);
return tmp;
}
int Nektar::Utilities::InputGmsh::GetNnodes ( unsigned int  InputGmshEntity)
private

For a given msh ID, return the corresponding number of nodes.

Definition at line 262 of file InputGmsh.cpp.

References Nektar::LibUtilities::eHexahedron, elmMap, Nektar::LibUtilities::ePoint, Nektar::LibUtilities::ePrism, Nektar::LibUtilities::ePyramid, Nektar::LibUtilities::eQuadrilateral, Nektar::LibUtilities::eSegment, Nektar::LibUtilities::eTetrahedron, Nektar::LibUtilities::eTriangle, Nektar::Utilities::Point::GetNumNodes(), Nektar::Utilities::Line::GetNumNodes(), Nektar::Utilities::Triangle::GetNumNodes(), Nektar::Utilities::Quadrilateral::GetNumNodes(), Nektar::Utilities::Tetrahedron::GetNumNodes(), Nektar::Utilities::Pyramid::GetNumNodes(), Nektar::Utilities::Prism::GetNumNodes(), Nektar::Utilities::Hexahedron::GetNumNodes(), and Nektar::iterator.

Referenced by Process().

{
int nNodes;
it = elmMap.find(InputGmshEntity);
if (it == elmMap.end())
{
cerr << "Unknown element type " << InputGmshEntity << endl;
abort();
}
switch(it->second.m_e)
{
nNodes = Point:: GetNumNodes(it->second);
break;
nNodes = Line:: GetNumNodes(it->second);
break;
nNodes = Triangle:: GetNumNodes(it->second);
break;
nNodes = Quadrilateral::GetNumNodes(it->second);
break;
nNodes = Tetrahedron:: GetNumNodes(it->second);
break;
nNodes = Pyramid:: GetNumNodes(it->second);
break;
nNodes = Prism:: GetNumNodes(it->second);
break;
nNodes = Hexahedron:: GetNumNodes(it->second);
break;
default:
cerr << "Unknown element type!" << endl;
abort();
break;
}
return nNodes;
}
void Nektar::Utilities::InputGmsh::Process ( )
virtual

Gmsh file contains a list of nodes and their coordinates, along with a list of elements and those nodes which define them. We read in and store the list of nodes in #m_node and store the list of elements in #m_element. Each new element is supplied with a list of entries from #m_node which defines the element. Finally some mesh statistics are printed.

Parameters
pFilenameFilename of Gmsh file to read.

Implements Nektar::Utilities::Module.

Definition at line 80 of file InputGmsh.cpp.

References elmMap, Nektar::LibUtilities::ePrism, Nektar::Utilities::GetElementFactory(), GetNnodes(), Nektar::iterator, Nektar::Utilities::Module::m_mesh, Nektar::Utilities::InputModule::m_mshFile, Nektar::Utilities::InputModule::OpenStream(), Nektar::Utilities::Module::ProcessComposites(), Nektar::Utilities::Module::ProcessEdges(), Nektar::Utilities::Module::ProcessElements(), Nektar::Utilities::Module::ProcessFaces(), and Nektar::Utilities::Module::ProcessVertices().

{
// Open the file stream.
m_mesh->m_expDim = 0;
m_mesh->m_spaceDim = 0;
string line;
int nVertices = 0;
int nEntities = 0;
int elm_type = 0;
int prevId = -1;
if (m_mesh->m_verbose)
{
cout << "InputGmsh: Start reading file..." << endl;
}
while (!m_mshFile.eof())
{
getline(m_mshFile, line);
stringstream s(line);
string word;
s >> word;
// Process nodes.
if (word == "$Nodes")
{
getline(m_mshFile, line);
stringstream s(line);
s >> nVertices;
int id = 0;
for (int i = 0; i < nVertices; ++i)
{
getline(m_mshFile, line);
stringstream st(line);
double x = 0, y = 0, z = 0;
st >> id >> x >> y >> z;
if ((x * x) > 0.000001 && m_mesh->m_spaceDim < 1)
{
m_mesh->m_spaceDim = 1;
}
if ((y * y) > 0.000001 && m_mesh->m_spaceDim < 2)
{
m_mesh->m_spaceDim = 2;
}
if ((z * z) > 0.000001 && m_mesh->m_spaceDim < 3)
{
m_mesh->m_spaceDim = 3;
}
id -= 1; // counter starts at 0
if (id-prevId != 1)
{
cerr << "Gmsh vertex ids should be contiguous" << endl;
abort();
}
prevId = id;
m_mesh->m_node.push_back(boost::shared_ptr<Node>(new Node(id, x, y, z)));
}
}
// Process elements
else if (word == "$Elements")
{
getline(m_mshFile, line);
stringstream s(line);
s >> nEntities;
for (int i = 0; i < nEntities; ++i)
{
getline(m_mshFile, line);
stringstream st(line);
int id = 0, num_tag = 0, num_nodes = 0;
st >> id >> elm_type >> num_tag;
id -= 1; // counter starts at 0
it = elmMap.find(elm_type);
if (it == elmMap.end())
{
cerr << "Error: element type " << elm_type
<< " not supported" << endl;
abort();
}
// Read element tags
vector<int> tags;
for (int j = 0; j < num_tag; ++j)
{
int tag = 0;
st >> tag;
tags.push_back(tag);
}
tags.resize(1);
// Read element node list
vector<NodeSharedPtr> nodeList;
num_nodes = GetNnodes(elm_type);
for (int k = 0; k < num_nodes; ++k)
{
int node = 0;
st >> node;
node -= 1; // counter starts at 0
nodeList.push_back(m_mesh->m_node[node]);
}
// Prism nodes need re-ordering for Nektar++.
if (it->second.m_e == LibUtilities::ePrism)
{
// Mirror first in uv plane to swap around
// triangular faces
swap(nodeList[0], nodeList[3]);
swap(nodeList[1], nodeList[4]);
swap(nodeList[2], nodeList[5]);
// Reorder base points so that face/vertices map
// correctly.
swap(nodeList[4], nodeList[2]);
if (it->second.m_order == 2)
{
vector<NodeSharedPtr> nodemap(18);
// Vertices remain unchanged.
nodemap[ 0] = nodeList[ 0];
nodemap[ 1] = nodeList[ 1];
nodemap[ 2] = nodeList[ 2];
nodemap[ 3] = nodeList[ 3];
nodemap[ 4] = nodeList[ 4];
nodemap[ 5] = nodeList[ 5];
// Reorder edge nodes: first mirror in uv
// plane and then place in Nektar++ ordering.
nodemap[ 6] = nodeList[12];
nodemap[ 7] = nodeList[10];
nodemap[ 8] = nodeList[ 6];
nodemap[ 9] = nodeList[ 8];
nodemap[10] = nodeList[13];
nodemap[11] = nodeList[14];
nodemap[12] = nodeList[ 9];
nodemap[13] = nodeList[ 7];
nodemap[14] = nodeList[11];
// Face vertices remain unchanged.
nodemap[15] = nodeList[15];
nodemap[16] = nodeList[16];
nodemap[17] = nodeList[17];
nodeList = nodemap;
}
else if (it->second.m_order > 2)
{
cerr << "Error: gmsh prisms only supported up "
<< "to second order." << endl;
abort();
}
}
// Create element
CreateInstance(it->second.m_e,it->second,nodeList,tags);
// Determine mesh expansion dimension
if (E->GetDim() > m_mesh->m_expDim) {
m_mesh->m_expDim = E->GetDim();
}
m_mesh->m_element[E->GetDim()].push_back(E);
}
}
}
m_mshFile.close();
// Process rest of mesh.
}

Member Data Documentation

ModuleKey Nektar::Utilities::InputGmsh::className
static
Initial value:

ModuleKey for class.

Definition at line 60 of file InputGmsh.h.

std::map< unsigned int, ElmtConfig > Nektar::Utilities::InputGmsh::elmMap
static
Initial value:

Element map; takes a msh id to an ElmtConfig object.

Definition at line 66 of file InputGmsh.h.

Referenced by GetNnodes(), Nektar::Utilities::OutputGmsh::OutputGmsh(), and Process().