MSHParser.h
1 #include "stdafx.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "Node.h"
5 #include "T3Element.h"
6 #include "T6Element.h"
7 #include "Q4Element.h"
8 #include "Q9Element.h"
9 #include <fstream>
10 #include <string>
11 #include <vector>
12 
13 #ifndef MSHPARSER
14 #define MSHPARSER
15 
17 class MSHParser
18 {
19 public:
20 
21  static const int THREE_NODED_TRIANGLE = 2;
22  static const int SIX_NODED_TRIANGLE = 9;
23  static const int FOUR_NODED_QUAD = 3;
24  static const int NINE_NODED_QUAD = 10;
25 
37  MSHParser(std::string fileName, std::vector<Element*>& elements, std::vector<Node>& nodes);
38 
39 
40 private:
41  std::string line;
42 
52  void load_msh(std::ifstream&file, std::vector<Element*>& elements, std::vector<Node>& nodes);
53 
63  bool readMeshFormat(std::ifstream&in, double* version);
64 
76  bool readElements(std::ifstream& in, std::vector<Element*> *elements, std::vector<Node>& nodes);
77 
87  bool readNodes(std::ifstream& in, std::vector<Node> *nodes);
88 
95  void readInt(std::ifstream& in, int *number);
96 
103  void readDouble(std::ifstream& in, double* number);
104 
112  bool filePosEqualsLine(std::ifstream& line, std::string string);
113 
122  void createThreeNodeTriangleElement(std::ifstream& in, std::vector<Element*> *elements, int type, std::vector<Node>& nodes);
123 
132  void createSixNodeTriangleElement(std::ifstream& in, std::vector<Element*> *elements, int type, std::vector<Node>& nodes);
133 
142  void createFourNodeQuadElement(std::ifstream & in, std::vector<Element*> *elements, int type, std::vector<Node>& nodes);
143 
152  void createNineNodeQuadElement(std::ifstream & in, std::vector<Element*> *elements, int type, std::vector<Node>& nodes);
153 
154 };
155 
156 #endif
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.
Definition: MSHParser.cpp:76
bool readNodes(std::ifstream &in, std::vector< Node > *nodes)
Reads the nodes from the .msh file.
Definition: MSHParser.cpp:252
static const int THREE_NODED_TRIANGLE
Integer for selecting element type T3based on the .msh format.
Definition: MSHParser.h:21
static const int FOUR_NODED_QUAD
Integer for selecting element type Q4 based on the .msh format.
Definition: MSHParser.h:23
bool readElements(std::ifstream &in, std::vector< Element * > *elements, std::vector< Node > &nodes)
Reads the elements from .msh file.
Definition: MSHParser.cpp:277
static const int SIX_NODED_TRIANGLE
Integer for selecting element type T6 based on the .msh format.
Definition: MSHParser.h:22
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.
Definition: MSHParser.cpp:157
static const int NINE_NODED_QUAD
Integer for selecting element type Q9 based on the .msh format.
Definition: MSHParser.h:24
Interprets massive meshes structured in the ".msh" format.
Definition: MSHParser.h:17
MSHParser(std::string fileName, std::vector< Element * > &elements, std::vector< Node > &nodes)
Constructor.
Definition: MSHParser.cpp:7
void readInt(std::ifstream &in, int *number)
Assigns an integer value from the .msh file to the number pointer.
Definition: MSHParser.cpp:58
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.
Definition: MSHParser.cpp:195
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.
Definition: MSHParser.cpp:118
std::string line
Data on line in current position in file.
Definition: MSHParser.h:41
void load_msh(std::ifstream &file, std::vector< Element * > &elements, std::vector< Node > &nodes)
Loads the .msh data into the elements and nodes vectors.
Definition: MSHParser.cpp:21
void readDouble(std::ifstream &in, double *number)
Assigns a double value from the .msh file to the number pointer.
Definition: MSHParser.cpp:64
bool filePosEqualsLine(std::ifstream &line, std::string string)
Verifies that the line from the file matches with .msh format version.
Definition: MSHParser.cpp:70
bool readMeshFormat(std::ifstream &in, double *version)
Reads the mesh format.
Definition: MSHParser.cpp:235