This repository has been archived by the owner on Sep 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigester.cpp
467 lines (338 loc) · 14.8 KB
/
digester.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/*
Continuous Digester Model
Author: Sanjiv Chemudupati
Ref: Fundamental continuous-pulp-digester model for simulation and control
Philip A Wisnewski; Francis J Doyle III; Ferhan Kayihan
American Institute of Chemical Engineers. AIChE Journal; Dec 1997; 43, 12; Research Library
pg. 3175
*/
#include <iostream>
#include <math.h>
#define R 0.0083144 // [kJ/mol. K]
#define N 50
#define O 6
#define P 5
template<class Init2D>
void init2Da(Init2D A[N][O])
{
for (int i=0; i<N; i++)
{
for (int j=0; j<O; j++){
A[i][j] = 0.0;
////std::cout <<i << " "<< A[i][j] << " " ;
}
////std::cout << "\n";
}
}
template<class Init2D>
void init2Db(Init2D A[N][P], double num)
{
for (int i=0; i<N; i++)
{
for (int j=0; j<P; j++){
A[i][j] = num;
////std::cout <<i << " "<< A[i][j] << " " ;
}
// //std::cout << "\n";
}
}
template<class Init1D>
void init1D(Init1D A[N], double num)
{
for (int i=0; i<N; i++)
{
A[i] = num;
////std::cout << i << " " << A[i] << " " << std::endl;
}
}
template<class Init1D>
double getVolume(Init1D Area[N], Init1D height[N]){
double volume = 0.0;
for(int i=0; i<N; i++)
{
volume += Area[i] * height[i];
}
return volume;
}
template<class Init1D>
double calculateHeight(Init1D height[N]){
double m_height =0.0;
for(int i=0; i<N; i++){
m_height += height[i];
}
}
template<class Init1D>
void cumVol(Init1D Area[N], Init1D height[N], Init1D cumVolCSTR[N]){
cumVolCSTR[N-1] = Area[N-1] * height[N-1];
for(int i = N-2; i>=0; i--){
cumVolCSTR[i] = cumVolCSTR[i+1] + Area[i] * height[i];
std::cout << cumVolCSTR[i]<<"\n";
}
}
int main(){
/*
Variables:
Cp_s = Heat capacity of solid phase [kJ/kg.K]
Cp_e = Heat capacity of entrapped-liquor phase [kJ/kg.K]
Cp_f = Heat capacity of free-liquor phase [kJ/kg.K]
dH_rxn = Heat of reaction [kJ/kg]
U = Heat transfer coefficient [kJ/min.K.m3]
D_E = Net energy transported into the chips per volume of diffusing mass
VARIABLES:
V_freef = Volume of free liquor [m3]
V = Volume of CSTR [m3]
V_chips = Volume of chip [m3]
Vs = Volume of solid [m3]
V_entrap = Volume of entrapped liquor [m3]
eta = Volume fraction of the free liquor and the wood chips
epsilon = volume fraction of the wood chip that is occupied by the entrapped liquor (porosity)
Area = Cross-sectional area of the CSTR corresponding to digester [m2]
Solid-phase components:
s1 = High-reactive lignin
s2 = Low-reactive lignin
s3 = Cellulose
s4 = Araboxylan
s5 = Galactoglucomman
Entrapped-liquor-phase components:
e1 = active effective alkali
e2 = passive effective alkali
e3 = active hydrosulfide
e4 = passive hydrosulfide
e5 = dissolved lignin
e6 = dissolved carbohydrates
Free-liquor-phase components:
f1 = active effective alkali
f2 = passive effective alkali
f3 = active hydrosulfide
f4 = passive hydrosulfide
f5 = dissolved lignin
f6 = dissolved carbohydrates
A1[i], A2[i] = pre-exponential factors for component, i [m3/ kg.min]
E1[i], E2[i] = activation energies for component, i [kJ/ mol.K]
k1[i], k2[i] = kinectic rate constants for component, i [m3/ kg.min]
mS[i] = mass fraction of solid component, i [kg/kg]
mS_in[i] = mass fraction of solid component, i, entering [kg/kg]
mS_ur[i] = mass fraction of solid component, i, unreacted [kg/kg]
mE[i] = mass fraction of entrapped-liquor component, i [kg/kg]
mF[i] = mass fraction of free-liquor component, i [kg/kg]
rhoS = density of solid material [kg/m3]
rhoS[i] = density of solid component, i [kg/m3]
rhoE = density of entrapped-liquor [kg/m3]
rhoE[i] = density of entrapped-liquor component, i [kg/m3]
rhoF = density of free-liquor [kg/m3]
rhoF[i] = density of free-liquor component, i [kg/m3]
Cp_S = Heat capacity of solid phase [kJ/kg.K]
Cp_E = Heat capacity of entrapped-liquor phase [kJ/kg.K]
Cp_F = Heat capacity of free-liquor phase [kJ/kg.K]
Vc_dot = Volumetric flow rate of chips [m3/s]
kappa = measure of residual lignin in wood chips
yield = measure of amount of wood substance recovered to amount of wood substance fed
*/
int sComp, eComp, fComp, CSTR, maxCSTR = 50;
double eta[50];
static double Area[] = {17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,17.9854,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,18.6793,19.865,19.865,19.865,21.0871,21.0871,21.0871,21.0871};
static double height[] = {0.623,0.623,0.623,0.623,0.623,0.5944,0.5944,0.5944,0.5944,0.4775,0.4775,0.4775,0.6096,0.6096,0.6096,0.5182,0.5182,0.5182,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.701,0.4877,0.4877,0.4877,0.6477,0.6477,0.6477,0.6477,0.6477,0.6477,0.6477,0.6477,0.3962,0.7925,0.3962,1.1278,0.6096,1.0058,1.0058};
double d_rhoS[50][5], rhoS[50][5], rhoS_un[50][5], R_S[50][5], sumR_S[50], rhoS_Total = 600.0, rho_water = 997.03;
double rhoS_sum[50], d_rhoS_sum[50];
double d_rhoE[50][6], rhoE[50][6], R_E[50][6], sumR_E[50];
double rhoEL_sum[50], rhoES_sum[50];
double d_rhoF[50][6], rhoF[50][6], rhoF_sum = 0.0;
double rhoFL_sum[50], rhoFS_sum[50], rhoF_ext[50];
double dT_free[50], dT_chips[50];
double e_f[50], D[50];
double k1[5], k2[5];
static double A1[] = {0.3954, 1.457E+11, 28.09, 7.075, 5826.7};
static double A2[] = {12.49, 1.873, 124.9, 47.86, 3.225E+16};
static double E1[] = {29.3, 115.0, 34.7, 25.1, 73.3};
static double E2[] = {31.4, 37.7, 41.9, 37.7, 167.0};
double b[6][5];
double Cp_s = 1.47, Cp_e[50], Cp_f[50], Cp_e0, Cp_f0, Cp_l, Cp_ext, Cp_x, Cp_fext[50];
double H_se = 0.0, dH_se, H_f = 0.0, dH_f, dH_rxn = -581.0;
double M_s[50], M_s0, M_e[50], M_e0, M_f[50], M_f0, M_ext, M_sdot[50], M_edot[50], M_fext[50];
double M_es[50], M_el[50], M_fs[50], M_fl[50], M_fdot[50];
double V_chips[50], V_entrap[50], V_free[50];
double T_chips[50], T_free[50], T_f0, T_ext;
double levelChips = 0.0;
double U = 827.0, Vcdot, Vbdot[50], Vfdot_0, Vfdot[50], Vfdot_in[50], Vfdot_out[50], Vextdot[50];
double epsilon[50], d_epsilon[50];
double betaOHL, betaHSL, betaOHC;
double k, A_T, D_sum[50], D_E[50], D_F[50];
double T_top, T_x;
double h_factor = 0.0;
double t, deltaT = 0.1;
double volDigester, heightTotal;
double cumVolCSTR[50];
//Initialize all the arrays
init1D(rhoS_sum, 0.0);
init1D(d_rhoS_sum, 0.0);
init1D(rhoEL_sum, 0.0);
init1D(rhoES_sum, 0.0);
init1D(rhoFL_sum, 0.0);
init1D(rhoFS_sum, 0.0);
init1D(rhoF_ext, 0.0);
init1D(dT_free, 0.0);
init1D(dT_chips, 0.0);
init1D(e_f, 0.9);
init1D(M_sdot, 0.0);
init1D(M_edot, 0.0);
init1D(eta, 0.99999);
init1D(sumR_S, 0.0);
init1D(sumR_E, 0.0);
init1D(T_chips, 273.15);
init1D(T_free, 273.15);
init1D(d_rhoS_sum, 0.0);
init2Db(d_rhoS, 0.0);
init2Db(rhoS, 0.001);
init2Db(rhoS_un, 0.0);
init2Db(R_S, 0.0);
init2Da(d_rhoE);
init2Da(rhoE);
init2Da(R_E);
init2Da(d_rhoF);
init2Da(rhoF);
volDigester = getVolume(Area, height);
std::cout << volDigester << "\n";
heightTotal = calculateHeight(height);
std::cout << heightTotal << "\n";
cumVol(Area, height, cumVolCSTR);
for(t = 0.0; t < 3; t += deltaT){
Vcdot = 10.0; //m3/min
levelChips += (Vcdot/volDigester) * deltaT/0.6;
std::cout << "%Level: " << levelChips <<std::endl;
for(CSTR = maxCSTR-1; CSTR >= 0; CSTR--){
//Area[CSTR] * height[CSTR]
V_chips[CSTR] = (1-eta[CSTR]) * Area[CSTR] * height[CSTR];
//std::cout << V_chips[CSTR] << " " << eta[CSTR] << std::endl;
//Solid-phase components
for(sComp = 0; sComp < 5; sComp++){
k1[sComp] = 60.0 * A1[sComp] * exp(-E1[sComp]/ (R * T_chips[CSTR]));
k2[sComp] = 60.0 * A2[sComp] * exp(-E2[sComp]/ (R * T_chips[CSTR]));
////std::cout << k1[sComp] << " " << k2[sComp] << std::endl;
rhoS_un[CSTR][0] = 0.0;
rhoS_un[CSTR][1] = 0.0;
rhoS_un[CSTR][2] = 0.65;
rhoS_un[CSTR][3] = 0.25;
rhoS_un[CSTR][4] = 0.0;
////std::cout << R_S[CSTR][sComp] << " " ;
R_S[CSTR][sComp] = -e_f[CSTR] * (k1[sComp] * rhoS[CSTR][0] + k2[sComp] * sqrt(rhoS[CSTR][0] * rhoS[CSTR][2])) * (rhoS[CSTR][sComp] - rhoS_un[CSTR][sComp]);
//std::cout << CSTR << " " <<rhoS[CSTR][0] <<" " << rhoS[CSTR][2] << std::endl;
////std::cout << Vcdot << " ";
/*if(CSTR == 0){
d_rhoS[CSTR][sComp] = (-(Vcdot/ V_chips[CSTR]) * (rhoS[CSTR][sComp]) + R_S[CSTR][sComp]) * deltaT;
}*/
//else{
d_rhoS[CSTR][sComp] = ((Vcdot/ V_chips[CSTR]) * (rhoS[CSTR-1][sComp] - rhoS[CSTR][sComp]) + R_S[CSTR][sComp]) * deltaT;
//}
rhoS[CSTR][sComp] += d_rhoS[CSTR][sComp];
//std::cout << rhoS[CSTR][sComp] << " ";
d_rhoS_sum[CSTR] += d_rhoS[CSTR][sComp];
rhoS_sum[CSTR] += rhoS[CSTR][sComp];
sumR_S[CSTR] += R_S[CSTR][sComp];
}
//Porosity Calculation
epsilon[CSTR] = 1 - rhoS_sum[CSTR]/ rhoS_Total;
//std::cout << "Epsilon: " << epsilon[CSTR] << "\n";
//Change in porosity
d_epsilon[CSTR] = -d_rhoS_sum[CSTR]/ rhoS_Total;
//std::cout << "Change Epsilon: " << d_epsilon[CSTR] << "\n";
V_entrap[CSTR] = epsilon[CSTR] * (1 - eta[CSTR]) * Area[CSTR] * height[CSTR];
//std::cout << "V entrap: " << V_entrap[CSTR] << " " << epsilon[CSTR] * (1 - eta[CSTR]) * Area[CSTR] * height[CSTR] << "\n";
//Entrapped-liquor-phase components
for(eComp = 0; eComp < 6; eComp++){
fComp = eComp;
betaOHC = 0.395;
betaHSL = 0.039;
betaOHL = 0.166;
b[0][0] = betaOHL - 0.5 * betaHSL;
b[0][1] = betaOHL - 0.5 * betaHSL;
b[0][2] = betaOHC;
b[0][3] = betaOHC;
b[0][4] = betaOHC;
b[1][0] = -b[0][0];
b[1][1] = -b[0][1];
b[1][2] = -b[0][2];
b[1][3] = -b[0][3];
b[1][4] = -b[0][4];
b[2][0] = 0.5 * betaHSL;
b[2][1] = 0.5 * betaHSL;
b[2][2] = 0.0;
b[2][3] = 0.0;
b[2][4] = 0.0;
b[3][0] = -b[2][0];
b[3][1] = -b[2][1];
b[3][2] = -b[2][2];
b[3][3] = -b[2][3];
b[3][4] = -b[2][4];
b[4][0] = -1.0;
b[4][1] = -1.0;
b[4][2] = 0.0;
b[4][3] = 0.0;
b[4][4] = 0.0;
b[5][0] = -1.0 - b[4][0];
b[5][1] = -1.0 - b[4][1];
b[5][2] = -1.0 - b[4][2];
b[5][3] = -1.0 - b[4][3];
b[5][4] = -1.0 - b[4][4];
//R_E[CSTR][eComp] =
for(sComp = 0; sComp < 5; sComp++){
sumR_E[eComp] += b[sComp][eComp] * R_S[CSTR][sComp];
}
R_E[CSTR][eComp] = sumR_E[eComp];
D[CSTR] = 6.1321 * sqrt(T_chips[CSTR]) * exp(-4870.0/(1.98 * T_chips[CSTR]));
Vbdot[CSTR] = -sumR_S[CSTR]/ rhoS_Total;
d_rhoE[CSTR][eComp] = ((-rhoE[CSTR][eComp] * d_epsilon[CSTR]/ epsilon[CSTR]) + Vcdot * (rhoE[CSTR-1][eComp] * epsilon[CSTR-1] - rhoE[CSTR][eComp] * epsilon[CSTR])/ V_entrap[CSTR] + D[CSTR] * (rhoF[CSTR][fComp] - rhoE[CSTR][eComp]) + (R_E[CSTR][eComp]/ epsilon[CSTR]) + (Vbdot[CSTR] * rhoF[CSTR][fComp])/V_entrap[CSTR]) * deltaT;
rhoE[CSTR][eComp] += d_rhoE[CSTR][eComp];
if(eComp < 5)
rhoEL_sum[CSTR] += rhoE[CSTR][eComp];
else
rhoES_sum[CSTR] += rhoE[CSTR][eComp];
}
V_free[CSTR] = eta[CSTR] * Area[CSTR] * height[CSTR];
//free-liquor-phase components
for(fComp = 0; fComp < 6; fComp++){
//External flows into the digester
Vfdot_in[CSTR] = Vfdot_out[CSTR -1];
Vfdot_out[CSTR] = Vfdot_in[CSTR] - Vbdot[CSTR] + Vextdot[CSTR];
d_rhoF[CSTR][fComp] = ((Vfdot_in[CSTR] * rhoF[CSTR-1][fComp] - Vfdot_out[CSTR] * rhoF[CSTR][fComp])/V_free[CSTR] + (D[CSTR] * epsilon[CSTR] * (1 - eta[CSTR]) * (rhoE[CSTR][fComp] - rhoF[CSTR][fComp])/ eta[CSTR]) + (Vbdot[CSTR] * rhoF[CSTR][fComp] + Vextdot[CSTR] * rhoF_ext[CSTR])/ V_free[CSTR]) * deltaT;
rhoF[CSTR][fComp] += d_rhoF[CSTR][fComp];
if(fComp < 5)
Cp_x = Cp_l;
else
Cp_x = Cp_s;
if(rhoF[CSTR][fComp] > rhoE[CSTR][fComp])
T_x = T_free[CSTR];
else
T_x = T_chips[CSTR];
D_sum[CSTR] += (rhoF[CSTR][fComp] - rhoE[CSTR][fComp]) * Cp_x * T_x ;
}
M_s[CSTR] = rhoS_sum[CSTR];
M_el[CSTR] = rhoEL_sum[CSTR] + rho_water;
M_es[CSTR] = rhoES_sum[CSTR];
M_fl[CSTR] = rhoFL_sum[CSTR] + rho_water;
M_fs[CSTR] = rhoFS_sum[CSTR];
M_e[CSTR] = M_el[CSTR] + M_es[CSTR];
M_f[CSTR] = M_fl[CSTR] + M_fs[CSTR];
//Mixing Rule
Cp_e[CSTR] = Cp_s * M_es[CSTR]/ M_e[CSTR] + Cp_l * M_el[CSTR]/M_e[CSTR];
Cp_f[CSTR] = Cp_s * M_fs[CSTR]/ M_f[CSTR] + Cp_l * M_fl[CSTR]/M_f[CSTR];
D_E[CSTR] = D_sum[CSTR];
D_F[CSTR] = -D_sum[CSTR];
//Wood chips temperature
dT_chips[CSTR] = ((Cp_s * M_sdot[CSTR] + Cp_e[CSTR] * M_e[CSTR] * d_epsilon[CSTR] + Cp_e[CSTR] * M_edot[CSTR] * epsilon[CSTR]) * T_chips[CSTR]/ (Cp_s * M_s[CSTR] + Cp_e[CSTR] * M_e[CSTR] * epsilon[CSTR]) + Vcdot * (Cp_s * M_s[CSTR-1] + Cp_e[CSTR-1] * M_e[CSTR-1] * epsilon[CSTR-1]) * (T_chips[CSTR-1] - T_chips[CSTR])/ (V_chips[CSTR] * (Cp_s * M_s[CSTR] + Cp_e[CSTR] * M_e[CSTR] * epsilon[CSTR])) + dH_rxn * sumR_S[CSTR]/ (Cp_s * M_s[CSTR] + Cp_e[CSTR] * M_e[CSTR] * epsilon[CSTR]) + U * (T_free[CSTR] - T_chips[CSTR])/ (Cp_s * M_s[CSTR] + Cp_e[CSTR] * M_e[CSTR] * epsilon[CSTR]) + Vbdot[CSTR] * (Cp_f[CSTR] * M_f[CSTR] * T_free[CSTR])/ (V_chips[CSTR] * (Cp_s * M_s[CSTR] + Cp_e[CSTR] * M_e[CSTR] * epsilon[CSTR])) + D[CSTR] * D_E[CSTR]/ (Cp_s * M_s[CSTR] + Cp_e[CSTR] * M_e[CSTR] * epsilon[CSTR])) * deltaT;
T_chips[CSTR] += dT_chips[CSTR];
//Free-liquor temperature
dT_free[CSTR] = ((M_fdot[CSTR] * T_free[CSTR]) * M_f[CSTR] + (Vfdot[CSTR+1] * Cp_f[CSTR+1] * M_f[CSTR+1]) * T_free[CSTR+1]/ (V_free[CSTR] * Cp_f[CSTR] * M_f[CSTR]) - (Vfdot[CSTR]/ V_free[CSTR]) * T_free[CSTR] + U * (T_chips[CSTR] - T_free[CSTR]) * (1 - eta[CSTR])/ (Cp_f[CSTR] * M_f[CSTR] * eta[CSTR]) - Vbdot[CSTR] * T_free[CSTR]/ V_free[CSTR] + (D[CSTR] * D_F[CSTR] * (1 - eta[CSTR]))/ (Cp_f[CSTR] * M_f[CSTR] * eta[CSTR]) + (Cp_fext[CSTR] * M_fext[CSTR] * Vextdot[CSTR]) * T_ext/ (Cp_f[CSTR] * M_f[CSTR] * V_free[CSTR])) * deltaT;
T_free[CSTR] += dT_free[CSTR];
}
eta[CSTR] = V_free[CSTR]/ (Area[CSTR] * height[CSTR]);
//std::cout << "End of cycle \n" ;
}
return 0;
}
/* for(int i = 0; i < 5; ++i){
std::cin >> rhoS[i];
}
kappa = (rhoS[0] + rhoS[1])/(0.00153* (rhoS[0] + rhoS[1] + rhoS[2] + rhoS[3] + rhoS[4]));
yield = 600.0/ (rhoS[0] + + rhoS[1] + rhoS[2] + rhoS[3] + rhoS[4]);
//std::cout << A1[0] << " " << kappa << " " << yield << std::endl;
*/