-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_data.cpp
More file actions
214 lines (192 loc) · 4.94 KB
/
load_data.cpp
File metadata and controls
214 lines (192 loc) · 4.94 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include "data.h"
using namespace std;
typedef double number;
enum Section { NONE, NODE, ELEMENTS, BC };
void load_data(int& isDataLoaded, GlobalData& data, vector<Node>& nodes, vector<Element>& elements, Grid& grid, vector<int>& borders) //wczytywanie danych z pliku
{
//Wczytywanie pliku:
ifstream file("../../../Test1_4_4.txt");
//ifstream file("../../../Test2_4_4_MixGrid.txt");
//ifstream file("../../../Test3_31_31_kwadrat.txt");
//ifstream file("../../../Test1_4_4_HG_bez_i_z_BC_wektor_PG.txt");
//ifstream file("../../../Test2_4_4_MixGrid HG_bez_i_z_BC_wektor_PG.txt");
if (!file.is_open())
{
cout << "Error: Could not open the file or it does not exist!" << endl;
isDataLoaded = 1;
return;
}
nodes.clear();
elements.clear();
borders.clear();
string line;
Section curr_section = NONE;
while (getline(file, line))
{
if (line.empty())
{
continue;
}
//Sekcje
if (line.find("*Node") != string::npos)
{
curr_section = NODE;
continue;
}
else if (line.find("*Element") != string::npos)
{
curr_section = ELEMENTS;
continue;
}
else if (line.find("*BC") != string::npos)
{
curr_section = BC;
continue;
}
if (curr_section == NODE)
{
istringstream iss(line);
int index;
number x, y;
char comma;
if (iss >> index >> comma >> x >> comma >> y)
{
nodes.push_back({ x, y, 0.0 });
}
}
else if (curr_section == ELEMENTS)
{
istringstream iss(line);
int index;
char comma;
Element e;
if (iss >> index >> comma >> e.ID[0] >> comma >> e.ID[1] >> comma >> e.ID[2] >> comma >> e.ID[3])
{
elements.push_back(e);
}
}
else if (curr_section == BC)
{
istringstream iss(line);
int nodeID;
while (iss >> nodeID) //bo w lini s? boarders
{
borders.push_back(nodeID); //miedzy przecinkami
if (nodeID - 1 < nodes.size())
{
nodes[nodeID - 1].BC = 1.0;
}
if (iss.peek() == ',') iss.ignore();
}
}
//Pozostale parametry
else if (curr_section == NONE)
{
istringstream iss(line);
string parameterName;
if (line.find("SimulationTime") != string::npos)
{
if (iss >> parameterName >> data.SimulationTime)
continue;
}
if (line.find("SimulationStepTime") != string::npos)
{
if (iss >> parameterName >> data.TimeStep)
continue;
}
if (line.find("Conductivity") != string::npos)
{
if (iss >> parameterName >> data.Conductivity)
continue;
}
if (line.find("Alfa") != string::npos)
{
if (iss >> parameterName >> data.Alfa)
continue;
}
if (line.find("Tot") != string::npos)
{
if (iss >> parameterName >> data.Tot)
continue;
}
if (line.find("InitialTemp") != string::npos)
{
if (iss >> parameterName >> data.InitialTemp)
continue;
}
if (line.find("Density") != string::npos)
{
if (iss >> parameterName >> data.Density)
continue;
}
if (line.find("SpecificHeat") != string::npos)
{
if (iss >> parameterName >> data.SpecificHeat)
continue;
}
if (line.find("Nodes number") != string::npos)
{
string parameterName2;
if (iss >> parameterName >> parameterName2 >> data.nN)
continue;
}
if (line.find("Elements number") != string::npos)
{
string parameterName2;
if (iss >> parameterName >> parameterName2 >> data.nE)
continue;
}
}
//grid.nN = nodes;
//grid.nE = elements;
}
file.close();
cout << "Wczytano " << nodes.size() << " wezlow i " << elements.size() << " elementow!" << endl;
isDataLoaded = 0;
return;
}
void printData(int& isDataLoaded, GlobalData& data, vector<Node>& nodes, vector<Element>& elements, Grid& grid, vector<int>& borders) //wypisywanie danych
{
if (isDataLoaded == 1)
{
return;
}
cout << fixed << setprecision(2);
cout << "Simulation Time: " << data.SimulationTime << endl;
cout << "Time Step: " << data.TimeStep << endl;
cout << "Conductivity: " << data.Conductivity << endl;
cout << "Alfa: " << data.Alfa << endl;
cout << "Tot: " << data.Tot << endl;
cout << "Initial Temp: " << data.InitialTemp << endl;
cout << "Density: " << data.Density << endl;
cout << "Specific Heat: " << data.SpecificHeat << endl;
cout << "Number of Nodes: " << data.nN << endl;
cout << "Number of Elements: " << data.nE << endl;
cout << "\nNodes:" << endl;
for (size_t i = 0; i < nodes.size(); ++i)
{
cout << "Node " << i + 1 << ": (" << nodes[i].x << ", " << nodes[i].y << ")" << endl;
}
cout << "\nElements:" << endl;
for (size_t i = 0; i < elements.size(); ++i)
{
cout << "Element " << i + 1 << ": IDs(" << elements[i].ID[0] << ", " << elements[i].ID[1] << ", "
<< elements[i].ID[2] << ", " << elements[i].ID[3] << ")" << endl;
}
cout << "\nBoundary Conditions (BC) Node IDs:" << endl;
for (size_t i = 0; i < borders.size(); ++i)
{
cout << borders[i] << " ";
}
cout << endl;
isDataLoaded = 0;
return;
}