-
Notifications
You must be signed in to change notification settings - Fork 0
/
Agelem.cpp
220 lines (192 loc) · 6.82 KB
/
Agelem.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
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
215
216
217
218
219
220
using namespace std;
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <stdlib.h>
#include "Agelem.h"
Agelem::Agelem(const string a_nev, const double a_Aref, const double a_mp, const double a_ro) {
// tipus
string tipus;
// tomegaram es suruseg
mp = a_mp;
ro = a_ro;
// azonosito
nev = a_nev;
Aref = a_Aref;
// Csomopontok vektora
cspe_index = -1, cspv_index = -1;
string cspe_nev = "nincs_cspe_nev", cspv_nev = "nincs_cspv_nev";
FolyTerf = 0;
debug_level = 0;
tt_start = 0.;
tt_end = 0.;
if (fabs(a_ro) < 1.0e-3)
error("Agelem constructor", "Density (ro) is zero up to machine precision!");
force_more_iter = false;
update_diameter = false;
user1=0.;
user2=0.;
}
//--------------------------------------------------------------
Agelem::Agelem(const string a_nev, const double a_Aref, const double a_mp, const double a_ro, const double a_tt) {
// tipus
string tipus;
// tomegaram es suruseg
mp = a_mp;
ro = a_ro;
// azonosito
nev = a_nev;
Aref = a_Aref;
// Csomopontok vektora
cspe_index = -1, cspv_index = -1;
string cspe_nev = "nincs_cspe_nev", cspv_nev = "nincs_cspv_nev";
FolyTerf = 0;
debug_level = 0;
tt_start = a_tt * 3600; // Az adatfajlbol oraban olvassuk ki, oraban
tt_end = a_tt * 3600; // Az adatfajlbol oraban olvassuk ki, oraban
if (fabs(a_ro) < 1.0e-3)
error("Agelem constructor", "Density (ro) is zero up to machine precision!");
}
//--------------------------------------------------------------
Agelem::~Agelem() {
}
//--------------------------------------------------------------
string Agelem::Info() {
ostringstream strstrm;
strstrm << "\n Agelem neve : " << nev;
// strstrm << "\n tipusa: " << tipus;
strstrm << "\n ro : " << ro << " [kg/m^3]";
strstrm << "\n Aref : " << Aref << " [m^2]";
strstrm << "\n mp : " << mp / ro * 3600 << " [m3/h]";
return strstrm.str();
}
//--------------------------------------------------------------
void Agelem::add_csp(const int a_cspe_index, const int a_cspv_index) {
cspe_index = a_cspe_index;
cspv_index = a_cspv_index;
}
//--------------------------------------------------------------
vector<double> Agelem::Get_res(string mit) {
vector<double> x;
return x;
}
//--------------------------------------------------------------
vector<double> Agelem::interp(vector<double> x, vector<double> y, vector<double> xg) {
vector<double> yg;
double xp, xn, yp, yn;
double xmin = 1e100, xmax = -1e100;
for (unsigned int i = 0; i < x.size(); i++) {
if (x.at(i) < xmin)
xmin = x.at(i);
if (x.at(i) > xmax)
xmax = x.at(i);
}
if (abs(xmin) < 1e-8)
xmin = 0.0;
for (unsigned int i = 0; i < xg.size(); i++) {
if (xg.at(i) < xmin || xg.at(i) > xmax) {
cout << endl << endl
<< "!!!element/basic/interp interp hiba!!! Interpolacio kiserlet a tartmanyon kivulre:";
cout << endl << "\t xmin=" << xmin << " <? " << xg.at(i) << " <? xmax=" << xmax
<< endl;
}
// if (xg.at(i)<xmin*0.999)
// xg.at(i)=xmin;
// if (xg.at(i)>xmax*1.001)
// xg.at(i)=xmax;
}
for (unsigned int i = 0; i < xg.size(); i++) {
unsigned int j = 0;
bool megvan = false;
while ((!megvan) && (j < x.size() - 1)) {
double ize = (xg.at(i) - x.at(j)) * (xg.at(i) - x.at(j + 1));
//cout<<endl<<"xg="<<xg.at(i)<<" x.at("<<j<<")="<<x.at(j)<<" x.at("<<j+1<<")="<<x.at(j+1)<<" y.at("<<j<<")="<<y.at(j)<<" y.at("<<j+1<<")="<<y.at(j+1)<<" ize="<<ize;
if (ize < 1e-10)
megvan = true;
else
j++;
}
if (j == x.size() - 1)
j--;
xp = x.at(j);
xn = x.at(j + 1);
yp = y.at(j);
yn = y.at(j + 1);
yg.push_back(yp + (xg.at(i) - xp) * (yn - yp) / (xn - xp));
//cout<<endl<<"==>xg="<<xg.at(i)<<" x.at(j)="<<x.at(j)<<" x.at(j+1)="<<x.at(j+1)<<" y.at(j)="<<y.at(j)<<" y.at(j+1)="<<y.at(j+1)<<" yi="<<yg.at(i);
//int int1; cin>>int1;
}
/*
cout<<endl<<endl<<"Csatorna::interp, az eredeti vektorok:";
for (int i=0; i<x.size(); i++) cout<<endl<<scientific<<"\t x ="<<x.at(i)<<" y ="<<y.at(i);
cout<<endl<<"Az interpolalt ertekek ";
for (int i=0; i<xg.size(); i++) cout<<endl<<scientific<<"\t xg="<<xg.at(i)<<" yg="<<yg.at(i);
cout<<endl<<"Csatorna::interp: kesz (kerek egy egesz erteket...)"<<endl<<endl;
int int1; cin>>int1;
*/
return yg;
}
//--------------------------------------------------------------
void Agelem::set_up_grid(double a_konc, vector<double> a_vel, double a_cL) {
//konc.clear(); vel.clear();
// Vizminoseg adatok:
for (unsigned int i = 0; i < a_vel.size(); i++)
konc.push_back(a_konc);
for (unsigned int i = 0; i < a_vel.size(); i++)
vel.push_back(a_vel.at(i));
cL = a_cL;
cT = cL / fabs(mean(vel));
cdt = cT / vel.size();
}
//--------------------------------------------------------------
string Agelem::show_grid(double ido) {
ostringstream strstrm;
strstrm << endl << "A " << nev << " agelem seb.- es konc.eloszlasa t=" << ido
<< "s-ban, cL=" << cL << "m, cT=" << cT << "s, cdt=" << cdt << "s\n";
strstrm << "\n\tv= ";
for (unsigned int i = 0; i < vel.size(); i++)
strstrm << scientific << showpos << setprecision(2) << vel.at(i) << " ";
strstrm << "\n\tc= ";
for (unsigned int i = 0; i < vel.size(); i++)
strstrm << konc.at(i) << " ";
strstrm << "\n";
return strstrm.str();
}
//--------------------------------------------------------------
double Agelem::mean(vector<double> x) {
double mean = 0;
for (unsigned int i = 0; i < x.size(); i++)
mean += x.at(i);
return mean / x.size();
}
//--------------------------------------------------------------
void Agelem::error(string fv, string msg) {
ostringstream strstrm;
strstrm.str("");
strstrm << "\n\n******** ERROR *********";
strstrm << "\n\telement name: " << nev;
strstrm << "\n\tmethod : " << fv;
strstrm << "\n\tmessage : " << msg << "\n\n";
logfile_write(strstrm.str(), 0);
cout << strstrm.str();
exit(0);
}
//--------------------------------------------------------------
void Agelem::logfile_write(string msg, int msg_debug_level) {
if (debug_level >= msg_debug_level) {
ofstream outfile(out_file.c_str(), ios::app);
outfile << msg;
outfile.close();
}
}
void Agelem::SetLogFile()
{
out_file = nev + ".out";
ofstream outputFile;
outputFile.open(out_file.c_str());
outputFile.close();
};