-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbb.cpp
361 lines (312 loc) · 9.31 KB
/
bb.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include "servor.hpp"
#include "profitability.hpp"
using namespace std;
/*------------------------------------------------------------------------*/
/* fonction principale */
/*------------------------------------------------------------------------*/
int main ( int argc , char ** argv ) {
double g0 = 1e+20;
double g1 = 1e+20;
double g2 = 1e+20;
double g3 = 1e+20;
double g4 = 1e+20;
double g5 = 1e+20;
double g6 = 1e+20;
double g7 = 1e+20;
double g8 = 1e+20;
double g9 = 1e+20;
double g10 = 1e+20;
double f = 1e+20;
bool OK;
ifstream in;
double d;
int i;
int i_stream , i_chem;
double x [8];
long double tmp[8];
double raw_cost;
double util_cost;
double Itot;
double Coper;
double Rtot;
double max;
double mtot;
double m;
double purity;
int nb_chem = 7;
int nb_s = 15;
int nb_u = 11;
int n = 8;
double l [8] = { 600 , 2 , 0.0001 , 0.0001 , 2 , 0.01 , 0.1 , 300 };
double u [8] = { 1100 , 20 , 0.1 , 0.1 , 20 , 0.5 , 5 , 500 };
double list [7] = { 0.5 , 0 , 0 , 0 , 0 , 0 , 0 };
double price[7] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 };
profitability * P = NULL;
cashflow * F = NULL;
chemical ** chem = NULL;
stream ** s = NULL;
servor * units = NULL;
string * safe = NULL;
// verif. du nombre d'arguments :
if (argc!=2) {
// cout << "\nargc != 2\n\n";
goto TERMINATE;
}
// lecture et scaling de x :
// -------------------------
in.open (argv[1]);
for ( i = 0 ; i < n ; i++ )
in >> tmp[i];
in.close();
if (in.fail()) {
// cout << "\nin.fail (1)\n\n";
goto TERMINATE;
}
//for ( i = 0 ; i < n ; i++ )
// cout << "tmp[" << i << "] = " << tmp[i] << endl;
//cout << endl;
for ( i = 0 ; i < n ; i++ )
x[i] = (u[i]-l[i])*((double)tmp[i]/100.0) + l[i];
//for ( i = 0 ; i < n ; i++ )
// cout << "x[" << i << "] = " << x[i] << endl;
// verifs de x (j'ai pris ca dans checkup et c'est tout ce dont
// ca a besoin de checker ici) :
if ( x[6] < EPS || x[2] < 0 || x[2] > 1 || x[3] < 0 || x[3] > 1 )
goto TERMINATE;
// chemicals :
// -----------
chem = new chemical * [nb_chem];
chem[0] = new chemical ("100-41-4" );
chem[1] = new chemical ("1333-74-0");
chem[2] = new chemical ("108-88-3" );
chem[3] = new chemical ("74-82-8" );
chem[4] = new chemical ("71-43-2" );
chem[5] = new chemical ("74-85-1" );
chem[6] = new chemical ("100-42-5" );
price[6] = 1.39;
price[2] = 0.64;
price[0] = 0.11;
price[4] = 1.19;
// streams :
// ---------
s = new stream * [nb_s];
s[ 0] = new stream ( "feed" , nb_chem , chem );
s[ 1] = new stream ( "2" , nb_chem , chem );
s[ 2] = new stream ( "3" , nb_chem , chem );
s[ 3] = new stream ( "4" , nb_chem , chem );
s[ 4] = new stream ( "5" , nb_chem , chem );
s[ 5] = new stream ( "6" , nb_chem , chem );
s[ 6] = new stream ( "7" , nb_chem , chem );
s[ 7] = new stream ( "8" , nb_chem , chem );
s[ 8] = new stream ( "9" , nb_chem , chem );
s[ 9] = new stream ( "10" , nb_chem , chem );
s[10] = new stream ( "back" , nb_chem , chem );
s[11] = new stream ( "12" , nb_chem , chem );
s[12] = new stream ( "stack" , nb_chem , chem );
s[13] = new stream ( "out-bz" , nb_chem , chem );
s[14] = new stream ( "out-sty" , nb_chem , chem );
// initial conditions on streams :
// -------------------------------
s[0]->P = 1.0;
s[0]->T = 298;
s[0]->set(list);
// units settings and calculation sequence :
// -----------------------------------------
units = new servor ( nb_u , nb_s , s );
safe = new string[nb_u];
units->type[ 0] = "mix";
units->name[ 0] = safe[ 0] = "mixfeed";
units->type[ 1] = "pump";
units->name[ 1] = safe[ 1] = "pump";
units->type[ 2] = "heatx";
units->name[ 2] = safe[ 2] = "heater";
units->type[ 3] = "reactor";
units->name[ 3] = safe[ 3] = "pfr";
units->type[ 4] = "heatx";
units->name[ 4] = safe[ 4] = "cooler";
units->type[ 5] = "flash";
units->name[ 5] = safe[ 5] = "degasor";
units->type[ 6] = "column";
units->name[ 6] = safe[ 6] = "sep-sty";
units->type[ 7] = "split";
units->name[ 7] = safe[ 7] = "spliter";
units->type[ 8] = "column";
units->name[ 8] = safe[ 8] = "sep-bz";
units->type[ 9] = "loop";
units->name[ 9] = safe[ 9] = "looping";
units->type[10] = "burner";
units->name[10] = safe[10] = "fire";
// executing the calculation sequence :
//-------------------------------------
double y[14];
y[7] = y[8] = 1000.0;
if (!units->solve_process(x,y))
goto TERMINATE;
// on recupere les resultats :
// ---------------------------
y[6] = s[0]->m;
y[3] = s[13]->m;
y[2] = s[13]->chem[4]->m;
y[1] = s[14]->m;
y[0] = s[14]->chem[6]->m;
y[9 ] = 1e20;
y[10] = 1e20;
y[11] = units->get_costs_sum() * 6.192;
y[12] = 1e20;
y[13] = 1e20;
// arrondis :
if (ARRONDI) {
y[ 6] = arrondi ( y[ 6] , 4 );
y[ 3] = arrondi ( y[ 3] , 4 );
y[ 2] = arrondi ( y[ 2] , 4 );
y[ 1] = arrondi ( y[ 1] , 4 );
y[ 0] = arrondi ( y[ 0] , 4 );
y[11] = arrondi ( y[11] , 6 );
}
g0 = ( y[0] > 0 && y[0] < 1e+20 ) ? 0.0 : 1e20;
g1 = ( y[4] <= 80 ) ? 0.0 : 1.0;
g2 = ( y[5] <= 80 ) ? 0.0 : 1.0;
g3 = ( y[7] <= 200 && y[8] <= 8 ) ? 0.0 : 1.0;
g4 = ( y[1] > 0 && y[1] < 1e20 ) ? (0.99-y[0]/y[1])/0.99 : 1e20;
g5 = ( y[3] > 0 && y[3] < 1e20 ) ? (0.99-y[2]/y[3])/0.99 : 1e20;
g6 = ( y[6] > 0 && y[6] < 1e20 ) ? (0.6-y[0]/y[6])/0.6 : 1e20;
// bloc econo :
// ------------
// raw_cost :
raw_cost = 0.0;
if ( s[0]->m > EPS ) {
if ( s[0]->chem[6]->m > EPS ) {
d = (ARRONDI) ? arrondi ( s[0]->chem[6]->m , 4 ) : s[0]->chem[6]->m;
raw_cost += d * 1.39;
}
if ( s[0]->chem[2]->m > EPS ) {
d = (ARRONDI) ? arrondi ( s[0]->chem[2]->m , 4 ) : s[0]->chem[2]->m;
raw_cost += d * 0.64;
}
if ( s[0]->chem[0]->m > EPS ) {
d = (ARRONDI) ? arrondi ( s[0]->chem[0]->m , 4 ) : s[0]->chem[0]->m;
raw_cost += d * 0.11;
}
if ( s[0]->chem[4]->m > EPS ) {
d = (ARRONDI) ? arrondi ( s[0]->chem[4]->m , 4 ) : s[0]->chem[4]->m;
raw_cost += d * 1.19;
}
}
// raw_cost = raw_cost*3600.0*nb_h*nb_d :
raw_cost *= 25920000;
// util_cost :
util_cost = (units->get_power_sum() * 0.000125 + units->get_water_sum() * 0.00008) * 25920000;
// Coper :
Itot = y[11];
Coper = 0.16 * Itot + 2.26 * raw_cost + util_cost;
// Rtot :
Rtot = 0.0;
for ( i_stream = 13 ; i_stream < 15 ; i_stream++ ) {
i_chem = 0;
max = 0.0;
mtot = 0.0;
for ( i = 0 ; i < nb_chem ; i++ ) {
m = (ARRONDI) ? arrondi ( s[i_stream]->chem[i]->m , 4 ) : s[i_stream]->chem[i]->m;
if ( m > EPS ) {
mtot += m;
if ( m > max ) {
max = m;
i_chem = i;
}
}
}
if (mtot > EPS ) {
purity = max/mtot;
d = price[i_chem] * max;
if ( purity < 0.5 )
d = 0.0;
else if ( purity < 0.6 )
d *= 0.05;
else if ( purity < 0.7 )
d *= 0.1;
else if ( purity < 0.8 )
d *= 0.15;
else if ( purity < 0.9 )
d *= 0.3;
else if ( purity < 0.95 )
d *= 0.5;
else if ( purity < 0.98 )
d *= 0.6;
else if ( purity < 0.99 )
d *= 0.8;
else if ( purity > 0.995 )
d *= 1.1;
Rtot += d*25920000;
}
}
// cash flows :
F = new cashflow(15);
F->set_rates(0.1,0.4);
F->set_basics(Itot, Coper, Rtot);
OK = F->run();
// calculating profitability indicators :
if(OK) {
P = new profitability(F);
OK = P->run(y);
delete P;
}
delete F;
// arrondis :
if (ARRONDI) {
y[12] = round(y[12]);
y[13] = round(y[13]);
y[ 9] = round(y[ 9]*10)/10.0;
y[10] = round(y[10]*10)/10.0;
}
g7 = ( y[ 9] < 1e20 ) ? ( y[9] - 4.0 ) / 4.0 : 1e20;
g8 = ( y[10] < 1e20 ) ? (0.2-y[10])/0.2 : 1e20;
g9 = ( y[11] < 1e20 ) ? (y[11]-10e6)/10e6 : 1e20;
g10 = ( y[12] > 0 && y[12] < 1e20 ) ? (y[12]-15e6) / 15e6 : 1e20;
f = ( y[13] > 0 && y[13] < 1e20 ) ? -y[13] : 1e20;
// cout << setprecision(10);
// cout << "\n\n";
// for ( int i = 0 ; i < 14 ; i++ )
// cout << "y[" << i << "] = " << y[i] << endl;
// menage et affichage du resultat de la boite noire :
TERMINATE:
// cout << "\n\n";
// cout << " g0 = " << g0 << endl
// << " g1 = " << g1 << endl
// << " g2 = " << g2 << endl
// << " g3 = " << g3 << endl
// << " g4 = " << g4 << endl
// << " g5 = " << g5 << endl
// << " g6 = " << g6 << endl
// << " g7 = " << g7 << endl
// << " g8 = " << g8 << endl
// << " g9 = " << g9 << endl
// << "g10 = " << g10 << endl
// << " f = " << f << endl;
cout << g0 << " "
<< g1 << " "
<< g2 << " "
<< g3 << " "
<< g4 << " "
<< g5 << " "
<< g6 << " "
<< g7 << " "
<< g8 << " "
<< g9 << " "
<< g10 << " "
<< f << endl;
if (units)
delete units;
if (safe)
delete [] safe;
if (chem) {
for ( i = 0 ; i < nb_chem ; i++ )
delete chem[i];
delete [] chem;
}
if (s) {
for ( i = 0 ; i < nb_s ; i++ )
delete s[i];
delete [] s;
}
return 0;
}