-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgmsh.cpp
More file actions
120 lines (103 loc) · 2.82 KB
/
gmsh.cpp
File metadata and controls
120 lines (103 loc) · 2.82 KB
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
#include "gmsh.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
mesh_data mesh;
std::map<int, medium_property> medium_conf;
void clear_mesh() {
mesh.node_num = 0;
mesh.triang_num = 0;
mesh.tetrah_num = 0;
mesh.segment_num = 0;
mesh.node.clear();
mesh.segment.clear();
mesh.triang.clear();
mesh.tetrah.clear();
}
void read_node(string line) {
istringstream iss(line);
Vector3d node;
int n;
iss >> n;
iss >> node(0);
iss >> node(1);
iss >> node(2);
mesh.node.push_back(node);
}
const int SEGMENT_TYPE = 1;
const int TRIANG_TYPE = 2;
const int TETRAH_TYPE = 4;
void read_element(string line) {
istringstream iss(line);
int n;
int code;
iss >> n;
iss >> code;
iss >> n;
if(code == SEGMENT_TYPE) {
msh_segment segment;
iss >> segment.physical_tag;
iss >> segment.geometrical_tag;
iss >> segment.node_number_list[0];
iss >> segment.node_number_list[1];
sort(segment.node_number_list.begin(), segment.node_number_list.end());
mesh.segment.push_back(segment);
mesh.segment_num++;
}
else if(code == TRIANG_TYPE) {
msh_triang triang;
iss >> triang.physical_tag;
iss >> triang.geometrical_tag;
iss >> triang.node_number_list[0];
iss >> triang.node_number_list[1];
iss >> triang.node_number_list[2];
sort(triang.node_number_list.begin(), triang.node_number_list.end());
mesh.triang.push_back(triang);
mesh.triang_num++;
}
else if(code == TETRAH_TYPE) {
msh_tetrah tetrah;
iss >> tetrah.physical_tag;
iss >> tetrah.geometrical_tag;
iss >> tetrah.node_number_list[0];
iss >> tetrah.node_number_list[1];
iss >> tetrah.node_number_list[2];
iss >> tetrah.node_number_list[3];
sort(tetrah.node_number_list.begin(), tetrah.node_number_list.end());
mesh.tetrah.push_back(tetrah);
mesh.tetrah_num++;
}
}
void load_gmsh_file(string filename) {
fstream fs(filename);
string line;
istringstream iss;
int element_num = 0;
clear_mesh();
if(!fs.good()) {
cout << "Broken mesh file or file doesn't exist..." << endl;
}
mesh.node.push_back(Vector3d());
for(int i = 0; i < 4; i++)
getline(fs, line);
getline(fs, line);
iss.str(line);
iss >> mesh.node_num;
mesh.node.reserve(mesh.node_num);
for(int i = 0; i < mesh.node_num; i++) {
getline(fs, line);
read_node(line);
}
getline(fs, line);
getline(fs, line);
getline(fs, line);
iss.clear();
iss.str(line);
iss >> element_num;
for (int i = 0; i < element_num; i++) {
getline(fs, line);
read_element(line);
}
}