-
Notifications
You must be signed in to change notification settings - Fork 1
/
GmshReader.cpp
121 lines (106 loc) · 2.73 KB
/
GmshReader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "GmshReader.h"
GmshReader::GmshReader()
{
this -> nbnode = 0;
this -> nbelm = 0;
this -> nbel_msh = 0;
this -> fname = "";
}
void GmshReader::GmshLoadMesh()
{
read_mesh();
construct_id_nodes();
}
void GmshReader::read_mesh()
{
// open input file
fname = "input.dat";
ifstream stream( fname );
if (stream.fail()) throw runtime_error( "could not open input file." );
string str;
str = ReadLine( stream );
fname = str;
// open mesh file .msh of GMSH
string str_msh = str + ".msh";
ifstream stream_msh(str_msh);
if (stream_msh.fail()) throw runtime_error("could not open mesh file");
string line;
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
stringstream(line) >> nbnode;
for (unsigned i = 0; i < nbnode; i++)
{
line = ReadLine(stream_msh);
unsigned ident;
double x, y, z;
stringstream(line) >> ident >> x >> y >> z;
MyPoint p(x, y, z, ident);
coord_nodes.push_back(p);
}
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
stringstream(line) >> nbel_msh;
for (unsigned i = 0; i < nbel_msh; i++)
{
line = ReadLine(stream_msh);
node_ident_msh node_msh;
// stringstream ss = stringstream(line); // no error with Visual C++ 2015, error with g++ 4.8.4
stringstream ss(line); // this shall work with g++ 4.8.4
vector <unsigned> line_number;
while (!ss.eof()) {
unsigned number;
ss >> number;
line_number.push_back(number);
//cout << number << " ";
}
//cout << endl;
node_msh.id_node = line_number;
node_msh.ident = line_number[0];
node_msh.elem_typ = line_number[1];
node_msh.nb_tags = line_number[2];
node_msh.tag1 = line_number[3];
node_msh.tag2 = line_number[4];
id_nodes_msh.push_back(node_msh);
unsigned elem_typ = id_nodes_msh[i].elem_typ;
switch (elem_typ)
{
case 1: // 2 - node line.
break;
case 3: // 4-node quadrangle.
nbelm = nbelm + 1;
break;
case 15: // 1-node point.
break;
case 37: // 5-node edge quadrangle.
nbelm = nbelm + 1;
break;
case 27: // boundary 5-node edge.
break;
default:
throw runtime_error("Element type is not suppoted. Comming soon !");
break;
}
}
}
void GmshReader::construct_id_nodes()
{
for (unsigned i = 0; i < nbel_msh; i++)
{
if (id_nodes_msh[i].elem_typ == 3)
{
node_ident node;
node.id_node = id_nodes_msh[i].id_node;
id_nodes.push_back(node);
}
if (id_nodes_msh[i].elem_typ == 37)
{
node_ident node;
node.id_node = id_nodes_msh[i].id_node;
id_nodes.push_back(node);
}
}
}