-
Notifications
You must be signed in to change notification settings - Fork 3
/
GmshReader.cpp
166 lines (137 loc) · 3.83 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <sstream>
#include "streamIO.h"
#include "GmshReader.h"
using namespace std;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
GmshReader::GmshReader() {
this -> setNbNode(0);
this -> setNbElm(0);
this -> setNbElMsh(0);
this -> setFname("");
}
GmshReader* GmshReader::setNbNode(unsigned nbNode) {
this->nbNode = nbNode;
return this;
}
unsigned GmshReader::getNbNode() {
return this->nbNode;
}
GmshReader* GmshReader::setNbElm(unsigned nbElm) {
this->nbElm = nbElm;
return this;
}
unsigned GmshReader::getNbElm() {
return this->nbElm;
}
GmshReader* GmshReader::setNbElMsh(unsigned nbElMsh) {
this->nbElMsh = nbElMsh;
return this;
}
unsigned GmshReader::getNbElMsh() {
return this->nbElMsh;
}
GmshReader* GmshReader::setFname(string fName) {
this->fName = fName;
return this;
}
string GmshReader::getFname() {
return this->fName;
}
vector<NodeIdent> & GmshReader::getIdNodes() {
return this->idNodes;
}
vector<NodeIdentMsh> & GmshReader::getIdNodesMsh() {
return this->idNodesMsh;
}
vector<Point> & GmshReader::getCoordNodes() {
return this->coordNodes;
}
void GmshReader::readMesh() {
// open input file
setFname("input.dat");
ifstream stream( getFname() );
if (stream.fail()) throw runtime_error( "could not open input file." );
string str;
str = ReadLine( stream );
setFname(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;
Point p(x, y, z, ident);
coordNodes.push_back(p);
}
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
stringstream(line) >> nbElMsh;
for (unsigned i = 0; i < nbElMsh; i++) {
line = ReadLine(stream_msh);
NodeIdentMsh node_msh;
//stringstream ss = stringstream(line); // no error with Visual C++ 2015, error with g++
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.setIdNode(line_number);
node_msh.setIdent(line_number[0]);
node_msh.setElemTyp(line_number[1]);
node_msh.setNbTags(line_number[2]);
node_msh.setTag1(line_number[3]);
node_msh.setTag2(line_number[4]);
idNodesMsh.push_back(node_msh);
unsigned elem_typ = idNodesMsh[i].getElemTyp();
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 supported. Coming soon !");
break;
}
}
}
void GmshReader::constructIdNodes() {
for (unsigned i = 0; i < nbElMsh; i++) {
unsigned elmTyp = idNodesMsh[i].getElemTyp();
switch (elmTyp) {
case 3:
case 37:
NodeIdent node;
node.setIdNode(idNodesMsh[i].getIdNode());
idNodes.push_back(node);
break;
}
}
}