Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
MSHParser Class Reference

Interprets massive meshes structured in the ".msh" format. More...

#include <MSHParser.h>

Public Member Functions

 MSHParser (std::string fileName, std::vector< Element * > &elements, std::vector< Node > &nodes)
 Constructor. More...
 

Static Public Attributes

static const int THREE_NODED_TRIANGLE = 2
 Integer for selecting element type T3based on the .msh format.
 
static const int SIX_NODED_TRIANGLE = 9
 Integer for selecting element type T6 based on the .msh format.
 
static const int FOUR_NODED_QUAD = 3
 Integer for selecting element type Q4 based on the .msh format.
 
static const int NINE_NODED_QUAD = 10
 Integer for selecting element type Q9 based on the .msh format.
 

Private Member Functions

void load_msh (std::ifstream &file, std::vector< Element * > &elements, std::vector< Node > &nodes)
 Loads the .msh data into the elements and nodes vectors. More...
 
bool readMeshFormat (std::ifstream &in, double *version)
 Reads the mesh format. More...
 
bool readElements (std::ifstream &in, std::vector< Element * > *elements, std::vector< Node > &nodes)
 Reads the elements from .msh file. More...
 
bool readNodes (std::ifstream &in, std::vector< Node > *nodes)
 Reads the nodes from the .msh file. More...
 
void readInt (std::ifstream &in, int *number)
 Assigns an integer value from the .msh file to the number pointer. More...
 
void readDouble (std::ifstream &in, double *number)
 Assigns a double value from the .msh file to the number pointer. More...
 
bool filePosEqualsLine (std::ifstream &line, std::string string)
 Verifies that the line from the file matches with .msh format version. More...
 
void createThreeNodeTriangleElement (std::ifstream &in, std::vector< Element * > *elements, int type, std::vector< Node > &nodes)
 Creates a three-node triangle and appends it to the element list. More...
 
void createSixNodeTriangleElement (std::ifstream &in, std::vector< Element * > *elements, int type, std::vector< Node > &nodes)
 Creates a six-node triangle and appends it to the element list. More...
 
void createFourNodeQuadElement (std::ifstream &in, std::vector< Element * > *elements, int type, std::vector< Node > &nodes)
 Creates a four-node quadrilateral element and appends it to the element list. More...
 
void createNineNodeQuadElement (std::ifstream &in, std::vector< Element * > *elements, int type, std::vector< Node > &nodes)
 Creates a nine-node quadrilateral element and appends it to the element list. More...
 

Private Attributes

std::string line
 Data on line in current position in file.
 

Detailed Description

Interprets massive meshes structured in the ".msh" format.

Constructor & Destructor Documentation

MSHParser::MSHParser ( std::string  fileName,
std::vector< Element * > &  elements,
std::vector< Node > &  nodes 
)

Constructor.

The constructor takes the filename, and the elements vector and nodes vector from Mesh as arguments. It opens the .msh file and loads the elements and nodes into the respective vector.

Parameters
fileNameis the fileName of the .msh file.
elementsis a list of element pointers found in Mesh
nodesis a list of node pointers found in Mesh

Member Function Documentation

void MSHParser::createFourNodeQuadElement ( std::ifstream &  in,
std::vector< Element * > *  elements,
int  type,
std::vector< Node > &  nodes 
)
private

Creates a four-node quadrilateral element and appends it to the element list.

Parameters
ininput stream
elementspointer to a vector with all the elements in cross-section
typeensures correct element type is created
nodesvector of all nodes in cross-section
void MSHParser::createNineNodeQuadElement ( std::ifstream &  in,
std::vector< Element * > *  elements,
int  type,
std::vector< Node > &  nodes 
)
private

Creates a nine-node quadrilateral element and appends it to the element list.

Parameters
ininput stream
elementspointer to a vector with all the elements in cross-section
typeensures correct element type is created
nodesvector of all nodes in cross-section
void MSHParser::createSixNodeTriangleElement ( std::ifstream &  in,
std::vector< Element * > *  elements,
int  type,
std::vector< Node > &  nodes 
)
private

Creates a six-node triangle and appends it to the element list.

Parameters
ininput stream
elementspointer to a vector with all the elements in cross-section
typeensures correct element type is created
nodesvector of all nodes in cross-section
void MSHParser::createThreeNodeTriangleElement ( std::ifstream &  in,
std::vector< Element * > *  elements,
int  type,
std::vector< Node > &  nodes 
)
private

Creates a three-node triangle and appends it to the element list.

Parameters
ininput stream
elementspointer to a vector with all the elements in cross-section
typeensures correct element type is created
nodesvector of all nodes in cross-section
bool MSHParser::filePosEqualsLine ( std::ifstream &  line,
std::string  string 
)
private

Verifies that the line from the file matches with .msh format version.

Parameters
lineinput line to check
stringused to verify input line
Returns
true if line matches string
void MSHParser::load_msh ( std::ifstream &  file,
std::vector< Element * > &  elements,
std::vector< Node > &  nodes 
)
private

Loads the .msh data into the elements and nodes vectors.

Interprets the mesh data in the datastream and creates two vectors, containing nodes and elements respectively.

Parameters
fileinput file
elementslist of element pointers from Mesh
nodeslist of node pointers from Mesh
void MSHParser::readDouble ( std::ifstream &  in,
double *  number 
)
private

Assigns a double value from the .msh file to the number pointer.

Parameters
ininput stream
numberpointer is assigned value of in
bool MSHParser::readElements ( std::ifstream &  in,
std::vector< Element * > *  elements,
std::vector< Node > &  nodes 
)
private

Reads the elements from .msh file.

Reads the section of file containg element definitions, and creates a vector containing all supported elements.

Currently, only triangle elements are supported. All other element types are ignored

Parameters
ininput stream
elementslist of element pointers
nodeslist of node pointers
Returns
true if input line is at the end of the elements in .msh, false otherwise
void MSHParser::readInt ( std::ifstream &  in,
int *  number 
)
private

Assigns an integer value from the .msh file to the number pointer.

Parameters
ininput stream
numberpointer is assigned value of in
bool MSHParser::readMeshFormat ( std::ifstream &  in,
double *  version 
)
private

Reads the mesh format.

Ensures that the mesh is of correct format

Parameters
ininput stream
meshversion
Returns
true if mesh is correct format, false otherwiseVerifies the mesh format of the file
bool MSHParser::readNodes ( std::ifstream &  in,
std::vector< Node > *  nodes 
)
private

Reads the nodes from the .msh file.

Reads node data from .msh file and creates a corresponding node with x- and y-coordinates, as well as a unique node id.

Parameters
ininput stream
nodeslist of node pointers
Returns
true if input line is at the end of the nodes in .msh, false otherwise

The documentation for this class was generated from the following files: