forked from CCSI-Toolset/fixed_bed_adsorption
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fixed_bed_model.py
2392 lines (1903 loc) · 77.7 KB
/
fixed_bed_model.py
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import matplotlib.pyplot as plt
import pyomo.environ as pyo
from pyomo.dae import ContinuousSet, DerivativeVar
import numpy as np
from scipy.interpolate import interp2d
import pandas as pd
### Reference list
#[Hughes et al., 2011] Hughes, R., Kotamreddy, G., Ostace, A., Bhattacharyya, D., Siegelman, R. L., Parker, S. T., ... & Matuszewski, M. (2021).
#Isotherm, Kinetic, Process Modeling, and Techno-Economic Analysis of a Diamine-Appended Metal–Organic Framework for CO2 Capture Using Fixed Bed Contactors. Energy & Fuels, 35(7), 6040-6055.
#[Dowling et al., 2012] Dowling, A. W., Vetukuri, S. R., & Biegler, L. T. (2012). Large‐scale optimization strategies for pressure swing adsorption cycle synthesis. AIChE journal, 58(12), 3777-3791.
#[Cavenati et al., 2006] Cavenati, S., Grande, C. A., & Rodrigues, A. E. (2006). Separation of CH4/CO2/N2 mixtures by layered pressure swing adsorption for upgrade of natural gas. Chemical engineering science, 61(12), 3893-3906.
### Process options
# Options related to the sigmoid function
# two sigmoid functions, or 0/1.
alpha_option = 2
# If alpha is treating as a variable or a parameter
alpha_variable = False
# eps_alpha: small number used in smoothed absolute value for alpha
eps_alpha = 1.0E-6
# scale alpha. [??-bar]^2. When alpha_scale = 100, then [??-bar] is [hecto-bar].
alpha_scale = 500
print("alpha option:")
if alpha_option == 1:
print("1 / sqrt(eps + x*x)")
elif alpha_option == 2:
print("1 / (1 + exp(-x))")
else:
print("WARNING! Not Supported")
### Data and model constants
# Molecular weight [g/mol]
MW = {'N2':28.013, 'CO2':44.010}
# Number of axial grid elements
Ngrid = 20
# R as gas constant [kJ/mol/K]
RPV = 8.31446261815324E-3
# CO2 partial pressure when the pressure is too low , 0.003[MPa]
# Value from [Hughes et al., 2021]
plin = 0.03
# Radius of the bed [m]
# Value from [Hughes et al., 2021]
rbed = 2.3E-3
# Inlet gas volume rate [m^3/min]
# Value from [Hughes et al., 2021]
# Value is given as 10 sccm (standard cubic centimeters per minute), 1 m^3 = 1E6 cm^3
volume_in_standard = 1.0E-5
# Inlet assumption 1
# volume converted
# inlet temp 313.15
# inlet pressure unchanged
totp_f = 1
# CO2 viscosity, [Pa*s] = [kg/m/s]
# Viscosity data from the Physics Hypertextbook
# Get from interpolation for CO2 at 313.15K
mu_co2 = 1.56E-5
# CO2 mole mass, [kg/mol]
M_co2 = 0.044010
# Total feed concentration [kmol/m^3]
# Calculation result is consistent with [Hughes et al., 2021]
# Helpful converstions: J = kg*m2/s2, Pa = kg/m/s2, 1 MPa = 1000 * 1000 Pa
# LHS: mol/m3
# RHS: kPa/ (kJ/mol) = mol/m3 = mol/m3
###totden_f = totp_f*100/(den_feed_temp*RPV)
# Inlet velocity [cm/s]
# RHS: m3/min/(m2)/(60s/min) *100cm/m = cm/s
#vel_f = volume_in* 100 /(np.pi*rbed*rbed) / 60
vel_f = 1.16638
# Check inlet molar flowrate (which should be 0.4467mmol/min)
# LHS: mmol/min
# RHS: mol/m3 * 1000 mmol/mol * m3/min
#mol_in = 0.4467
# Porosity of the bed [\]
# The interparticle voidage, value from [Hughes et al., 2021]
ads_epsb = 0.68
# Porosity of the particle [\]
# Intra-particle voidage, value from [Hughes et al., 2021]
ads_epsp = 0.33
# Density of the solid (no external voidage, only internal voidage) [kg/m3]
# Value from [Hughes et al., 2021]
den_s = 1000
# Solid density [kg/m3]
# Value of \rho_b in [Hughes et al., 2021]
den_b = den_s*(1-ads_epsb)
# sorbent specific heat [J/kg/K]
# value from [Hughes et al., 2021]
cps = 1457
# Length of bed [m]
# Value from [Hughes et al., 2021]
Lbed = 0.1334
# Length of each axial element [m]
dz = Lbed/Ngrid
# Viscosity [Pa*s]
# Viscosity data from the Physics Hypertextbook
# fp_mu = (n2_mu(313k,1atm) + co2_mu(313k,1atm))/2, kg/m/s = Pa * s
fp_mu = 1.7035E-5
# Initialization for the axial dispersion coefficients
Dax = {'N2':0.0001, 'CO2':0.00005}
## Bounds
# Used to use as a tighter bound[bar]
#P_low = 0.9
#P_high = 1.1
P_low = 0.1
P_high = 21
# Total density, mol/m3, MPa/RPV/temp
# LHS: mol/m3 # RHS: kPa/(kJ/mol) = mol/m3
tden_low = P_low*100 / RPV / 313.15
tden_high = P_high*100 / RPV / 313.15
# Adsorption kinetics constants
# Values from [Hughes et al., 2021]
n_max = 3.82 # mol/kg
nmax_p1 = 3.52 # mol/kg
Ka = -0.92 # dimensionless
Kb = 324.86 # K
Kc = -71.14 # dimensionless
Kd = 28386.66 # K
b_a0 = 28.56 # 1/bar
b_b0 = 0.62 # 1/bar
Q_sta = 72.56 # kJ/mol
Q_stb = 43.83 # kJ/mol
T0 = 318 # K
n_a1 = 0.21 # dimensionless
E_na = 11.29 # kJ/mol
# Use kinetic parameters in [Hughes et al., 2021]
K_c0 = 0.011882 #1/s
K_p0 = 0.07895 #1/s
E_c = 23.20784 #kJ/mol
E_p = 7.17967 #kJ/mol
# Radius of particles [m]
# Value from [Hughes et al., 2021]
radp = 2625.0E-7
# Film mass transfer coefficient [m/s]
# N2 and CO2 values from [Cavenati et al., 2006]
k_f ={'N2':2.56E-4, 'CO2':1.92E-4}
# Value from [Hughes et al., 2021] [m^2/s]
# D_m = 0.53cm2/s = 0.53 E-4 m2/s = 5.3E-5 m^2/s
D_m = 5.3E-5
# Small number used in isotherm
spp_small_number = 1E-8
#spp_small_number=1E-6
# Replace 0 for every lower bound to be this number
small_bound = 1E-8
#small_bound=1E-6
#small_initial = 1E-6
small_initial=0.01
# Initialize alpha
alpha0 = 1
# pore diameter
# fitted value from [Hughes et al., 2021], [m]
rpore = 1.13E-11
# tortuosity
# fitted value from [Hughes et al., 2021], [dimensionless]
tort = 50
# Reference temperature for calculation of h
temp_base = 298.15
def create_model(scena, temp_feed=313.15, temp_bath=313.15, y=0.15, Q_init=0, doe_model=True, k_aug=False, opt = False, optimize_trace=True, diff=0, eps=0.01):
'''
Creates a concrete Pyomo model and adds sets/parameters.
Toggles are saved into the model object.
Arguments:
scena: achieved from DOE package. Containing the parameter values in each scenario and scenario names.
Three design variables:
temp_feed: the gas feed temperature, [K]
temp_bath: the water bathing temperature, [K]. If the energy balance is not included, temp == temp_bath
y: CO2 feed composition, [0,1]
Q_init: Q initial value, default is 0 [kW/m3]
Options:
doe_model: if this model is for DOE package. if True, it is formed as a input-output square model:
objective being 0
Parameters are defined as Param (... mutable=True)
k_aug: (active when doe_model is True) if this model is for k_aug mode for DOE package. Same as doe_model except that parameters are defined as Var.
Note: this k_aug model can also be used for parameter estimation
opt: Form it as a DOE optimization problem
calculate FIM invasively
objective being trace or det
optimize_trace: if True, optimize trace. if not, optimize det.
diff: 0: no derivative estimate, 1: forward, -1: backward, 2: central
eps: step size for the finite difference perturbation
energy: decide if energy balance is added to the model
isotherm: decide if isotherm part is True. Must open if one of the chemsorb/physsorb is opened.
chemsorb: decide if chemical adsorption part is opened to calculate adsorption kinetics
physsorb: decide if physical adsorption part is opened to calculate adsorption kinetics
dispersion: decide if dispersion part is included in gas molar balance calculation
fix_pres: decide if fixing the pressure and removing the ergun equation. For debugging
v_fix: decide if fixing the velocity and removing the ergun equation. For debugging
Return: the model
'''
# create concrete Pyomo model
m = pyo.ConcreteModel()
# Store model toggles
m.scena_all = scena
m.doe_model = doe_model
m.k_aug = k_aug
m.opt = opt
m.optimize_trace = optimize_trace
m.diff = diff
m.eps = eps
# existing toggles for debugging
m.energy = True
m.isotherm = True
m.chemsorb = True
m.physsorb = True
m.dispersion = False
m.fix_pres = False
m.v_fix = False
m.Q_init = Q_init
# define scenario
m.scena = pyo.Set(initialize=scena['scena-name'])
# declare components set
m.COMPS = pyo.Set(initialize=['N2','CO2'])
# declare components that adsorb
m.SCOMPS = pyo.Set(initialize=['CO2'], within=m.COMPS)
# components that didn't adsorb
m.USCOMP = pyo.Set(initialize=['N2'], within=m.COMPS)
# composition of feed
yfeed = {'N2':1-y, 'CO2':y}
# Original bed temperature, [K]
if m.doe_model:
m.temp_feed = pyo.Var(initialize=temp_feed, bounds=(293.15, 373.15))
m.temp_bath = pyo.Var(initialize=temp_bath, bounds=(274, 600))
m.yfeed = pyo.Var(initialize=y, bounds=(0,0.4), within=pyo.NonNegativeReals)
m.temp_bath.fix()
# Film mass transfer coefficient, m/s
m.kf = pyo.Param(m.COMPS, initialize=k_f)
# Molecular weight [kg/kmol]
m.MW = pyo.Param(m.COMPS,initialize=MW)
# Dax, the dispersion efficient
m.Dax = pyo.Param(m.COMPS,initialize=Dax)
# Manually discretize axial dimension
m.zgrid = pyo.Set(initialize=range(0,Ngrid))
# Initial bed N2 concentration at time 0.0 [mol/m3]
# LHS: mol/m3
# RHS: [kPa] / ([K] * [kJ/mol/K]) = Pa/(J/mol) = mol/m^3
m.den_inert = pyo.Expression(initialize=totp_f * 100 / (m.temp_bath * RPV))
# Total feed density, [mol/m3]
m.totden_f = pyo.Expression(initialize=totp_f*100/(m.temp_feed*RPV))
print('The inlet feed density is', pyo.value(m.totden_f), '[mol/m3]')
def den_f_rule_doe(m,i):
if i=='CO2':
return m.yfeed*pyo.value(m.totden_f)
elif i=='N2':
return (1-m.yfeed)*pyo.value(m.totden_f)
m.den_f = pyo.Expression(m.COMPS, rule=den_f_rule_doe)
# Estimate coefficient for parameter estimation
if ((m.doe_model) and (not m.k_aug)):
m.fitted_transport_coefficient = pyo.Param(m.scena, initialize=m.scena_all['fitted_transport_coefficient'], mutable=True)
elif m.k_aug:
m.fitted_transport_coefficient = pyo.Var(m.scena, initialize=m.scena_all['fitted_transport_coefficient'], bounds=(100,300))
# energy balance is added
if not m.energy:
# For continuous, temp and yfeed will be variable
if m.conti:
m.temp = pyo.Var(initialize = m.temp_feed, bounds=(293.15, 373.15), within=pyo.NonNegativeReals)
else:
m.temp = pyo.Param(initialize=m.temp_feed)
# define inv_k_oc, inv_k_op according to perturbation
# inv_k_oc is in [1/s], therefore the k_trans is in [1/s]
def inv_k_oc_init(m, i):
return m.fitted_transport_coefficient[i]+1/(K_c0*exp(-E_c/(RPV*m.temp) + E_c/(RPV*T0)))
def inv_k_op_init(m, i):
return m.fitted_transport_coefficient[i]+1/(K_p0*exp(-E_p/(RPV*m.temp) + E_p/(RPV*T0)))
# For square problem/optimization problem, parameter, k_oc/p are parameters
if not m.est_tr:
m.inv_K_oc = pyo.Param(m.perturb,initialize=inv_k_oc_init)
m.inv_K_op = pyo.Param(m.perturb,initialize=inv_k_op_init)
# LHS: [1/bar]
# RHS: [1/bar] * exp( [kJ/mol]/[kJ/mol/K * K] ) = [1/b] * exp( [ dimensionless ] )
m.b_a = pyo.Param(initialize=b_a0*exp(Q_sta/(RPV*T0)*(T0/m.temp-1)))
# LHS: dimensionless
# RHS: dimensionless * exp( [kJ/mol]/[kJ/mol/K * K] ) = [dimensionless] * exp([dimensionless ])
m.n_a = pyo.Param(initialize=n_a1*exp(E_na/(RPV*T0)*(T0/m.temp-1)))
#m.inv_n_a = Param(initialize=1/m.n_a)
inv_n_a = 1/m.n_a
# LHS: dimensionless
# RHS: dimensionless + K/K
m.K_eq = pyo.Param(initialize=exp(Ka + Kb/m.temp))
### Physical adsorption isotherm
# LHS: bar-1
# RHS: bar-1 * (kJ/mol)/(kJ/mol/K * K)
m.b_b = pyo.Param(initialize = b_b0*exp(Q_stb/(RPV*T0)*(T0/m.temp-1)))
# LHS: mol/kg
# RHS: mol/kg * 1
m.nmax_p = pyo.Param(initialize=nmax_p1*(exp(Kc+Kd/m.temp)/(1+exp(Kc+Kd/m.temp))))
# LHS: mol/kg
# RHS: mol/kg * 1 / 1 = mol/kg
m.nmax_c = pyo.Param(initialize=n_max*m.K_eq/(1+m.K_eq))
# Linear pressure adsorption when P < Plinear
# According to [Hughes et al., 2021]
# LHS: mol/kg
# RHS: mol/kg * ((1/bar * bar )/ (bar^-1 * 10bar))
nplin_num = (m.b_a*plin)**(inv_n_a)
nplin_de = 1+(m.b_a*plin)**(inv_n_a)
m.nplin = pyo.Param(initialize=m.nmax_c*(nplin_num/nplin_de))
return m
def bounds_velocity_pert(m, j, z, t):
''' Add bounds to velocity [cm/s]
'''
# Change to cm/s
if t == 0.0:
#return (1E-4, 0.3) # bounds for 313K, 0.15
return (1E-2, 30) # bounds for DoE problem
else:
#return (0.8,1.4) # bounds for 313K, 0.15
return (0.01, 5.0) # bounds for DoE problem
def breakthrough_bounds(z,t):
''' Check if position and time coordinates in region with
no breakthrough.
We draw a line between (t = 50% breakthrough, end of bed) and
(t=0, z = 25% bed length). Anything "above" this line we designate as in the
region of no breakthrough and return True. We impose tighter bounds if true.
'''
t50 = 1500 # 50% breakthrough time [s]
t0_intercept = 0.4
# used only for testing breakthrough curve.
# return (t0_intercept - 1)/t50*value(t) + t0_intercept > value(z)/Ngrid
# Inactivate this function for the model now
return False
def den_bounds_pert(m,j,c,t,z):
'''
density bounds, [mol/m3]
'''
if breakthrough_bounds(z,t):
if c == 'N2':
return (0.9*tden_low, tden_high)
elif c == 'CO2':
return (small_bound, 0.1*tden_high)
else:
return (small_bound, tden_high)
else:
return (small_bound, tden_high)
def surface_partial_pressure_bounds_pert(m,j,c,z,t):
''' Partial pressure bounds, [bar]
'''
if breakthrough_bounds(z,t):
return (1E-5, 0.5)
else:
return (small_bound, P_high)
def phys_star_bounds_pert(m,j,c,z,t):
''' Pysical equilibrium pressure bounds, [mol/kg]
'''
if breakthrough_bounds(z,t):
return (small_bound, 0.1)
else:
#return (0.0, 0.8) # bounds for 313K, 0.15
return (small_bound, 10.0)
def chem_star_bounds_pert(m,j,c,z,t):
''' Chemical equilibrium pressure bounds, [mol/kg][mol/kg]
'''
if breakthrough_bounds(z,t):
return (small_bound, 0.3)
else:
#return (0.0, 2.6) # bounds for 313K, 0.15
return (small_bound, 10.0)
def phys_loading_bounds_pert(m,j,c,z,t):
''' Pysical loading pressure bounds, [mol/kg]
'''
if breakthrough_bounds(z,t):
return (small_bound, 0.1)
else:
#return (0.0, 0.8) # bounds for 313K, 0.15
return (small_bound, 10.0)
def chem_loading_bounds_pert(m,j,c,z,t):
''' Pysical loading pressure bounds, [mol/kg]
'''
if breakthrough_bounds(z,t):
return (small_bound, 2.0)
else:
#return (0.0, 2.6) # bounds for 313K, 0.15
return (small_bound, 10.0)
def jac_bounds(m, t):
''' very wide bounds based on units. Used for MBDoE only, not a part of the fixed-bed model.
'''
return (-1, 1)
def add_variables(m,tf=3200, timesteps=None, start=0):
'''
Add variables to the Pyomo model using the toggles previously specified.
Arguments:
m: the model
tf: the time scale [s]
timesteps: time of the process, [s].
single number: final time
array: time points (non-uniform discretization)
Return: None
'''
# Time [s]
if timesteps is None:
m.t = ContinuousSet(bounds=(0,tf))
m.tf = tf
else:
m.t = ContinuousSet(bounds=(start,max(timesteps)), initialize=timesteps)
m.tf = max(timesteps)
m.t0 = min(timesteps)
# Gas phase density (concentration) [mol/m^3]
m.C = pyo.Var(m.scena, m.COMPS, m.zgrid, m.t, bounds=den_bounds_pert)
# Gas phase density derivative, [mol/m^3] / [s]
m.dCdt = DerivativeVar(m.C, wrt=m.t)
# Total gas phase density [mol/m3]
m.total_den = pyo.Var(m.scena, m.zgrid, m.t, bounds=(tden_low, tden_high))
# Gas phase velocity [cm/s]
m.v = pyo.Var(m.scena, m.zgrid, m.t, initialize=0.1, bounds=bounds_velocity_pert)
if m.v_fix:
m.v.fix()
# Gas pressure [bar]
#m.kfilm = Var(m.perturb, m.zgrid, m.t, initialize=1.92E-4, bounds=(0,1))
# Gas pressure [bar]
m.P = pyo.Var(m.scena, m.zgrid, m.t,initialize=1, bounds=(P_low, P_high))
if m.fix_pres:
m.P.fix()
# Temperature [K]
if m.energy:
# temperature is initialized to be the T_inlet. As this is the gas temperature, it should be started to be the inlet gas temperature.
m.temp = pyo.Var(m.scena, m.zgrid, m.t, initialize=m.temp_bath, bounds=(273.15,500.15), within=pyo.NonNegativeReals)
m.dTdt = DerivativeVar(m.temp, wrt=m.t)
# add external heat
m.Q = pyo.Var(m.t, initialize=m.Q_init, bounds=(0,80000), within=pyo.Reals)
# W/m3/K, value 0.2839 from [Dowling, 2012]
# Estimated value 1.4E7 W/m3/K (DOE run2)
# 1.4E4 kW/m3/K --> 1.4E1 W/cm3/K
if ((m.doe_model) and (not m.k_aug)):
m.ua = pyo.Param(m.scena, initialize=m.scena_all['ua'], mutable=True)
elif m.k_aug:
m.ua = pyo.Var(m.scena, initialize=m.scena_all['ua'], bounds=(5, 12))
# define inv_k_oc, inv_k_op according to perturbation
def inv_k_oc_init_en(m, j, z, t):
'''
Calculating 1/k_oc in [1/s]
'''
return m.fitted_transport_coefficient[j]+1/(K_c0*pyo.exp(-E_c/(RPV*m.temp[j,z,t]) + E_c/(RPV*T0)))
def inv_k_op_init_en(m, j, z, t):
'''
Calculating 1/k_op in [1/s]
'''
return m.fitted_transport_coefficient[j]+1/(K_p0*pyo.exp(-E_p/(RPV*m.temp[j,z,t]) + E_p/(RPV*T0)))
# For square problem/optimization problem, parameter, k_oc/p are parameters
#if not m.k_aug:
m.inv_K_oc = pyo.Expression(m.scena, m.zgrid, m.t, rule=inv_k_oc_init_en)
m.inv_K_op = pyo.Expression(m.scena, m.zgrid, m.t, rule=inv_k_op_init_en)
# If not square problem, k_oc/p are defined as parameters variable with temperature, defined in add_model()
# J/mol/K
def cpg_rule(m,j,i,z,t):
'''
Give Cpg in [J/mol/K]
'''
trans_t = m.temp[j,z,t]*0.001
if i=='N2':
return 29 + 1.85*trans_t - 9.65*trans_t**2 + 16.64*trans_t**3 + 0.000117/trans_t/trans_t
elif i=='CO2':
return 25 + 55.19*trans_t - 33.69*trans_t**2 + 7.95*trans_t**3 -0.1366/trans_t/trans_t
m.cpg = pyo.Expression(m.scena, m.COMPS, m.zgrid, m.t, rule=cpg_rule)
def h_rule(m,j,i,z,t):
'''
Calculate the flow heat based on the bed temperature. The reference temperature is 298.15K
h in [J/mol]
'''
if i=='N2':
return 29*(m.temp[j,z,t] - temp_base) + 1.85E-3/2*(m.temp[j,z,t]**2-temp_base**2) - 9.65E-6/3*(m.temp[j,z,t]**3-temp_base**3) + 16.64E-9/4*(m.temp[j,z,t]**4 - temp_base**4) -117/m.temp[j,z,t] + 117/temp_base
elif i=='CO2':
return 25*(m.temp[j,z,t] - temp_base) + 55.19E-3/2*(m.temp[j,z,t]**2-temp_base**2) - 33.69E-6/3*(m.temp[j,z,t]**3 - temp_base**3) + 7.95E-9/4*(m.temp[j,z,t]**4 - temp_base**4) +136638/m.temp[j,z,t] - 136638/temp_base
m.h = pyo.Expression(m.scena, m.COMPS, m.zgrid, m.t, rule=h_rule)
# Feed heat at the feed temperature [W/m2/K]
def h_feed_rule(m,i):
'''
Calculating feed heat based on the inlet temperature. The reference temperature is 298.15K
h in [J/mol]
'''
if i=='N2':
return 29*(m.temp_feed-temp_base) + 1.85E-3/2*(m.temp_feed**2-temp_base**2) - 9.65E-6/3*(m.temp_feed**3-temp_base**3) + 16.64E-9/4*(m.temp_feed**4-temp_base**4) -117/m.temp_feed + 117/temp_base
elif i=='CO2':
return 25*(m.temp_feed-temp_base) + 55.19E-3/2*(m.temp_feed**2 - temp_base**2) - 33.69E-6/3*(m.temp_feed**3 - temp_base**3) + 7.95E-9/4*(m.temp_feed**4 - temp_base**4) +136638/m.temp_feed - 136638/temp_base
m.h_feed = pyo.Expression(m.COMPS, rule=h_feed_rule)
# Adsorption heat, -65 kJ/mol
m.H_ads = pyo.Param(m.SCOMPS, initialize={'CO2': -65.0})
if m.isotherm:
# Surface partial pressure, [bar]
m.spp = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize=small_initial, bounds=surface_partial_pressure_bounds_pert)
# Chemical adsorption equilibrium, [mol / kg]
m.nchemstar = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize = small_initial, bounds=chem_star_bounds_pert)
# Chemical adsorption equilibrium, modified [mol / kg]
m.nchemstar_mod = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize = small_initial, bounds=chem_star_bounds_pert)
# Physical adsorption equilibrium, [mol / kg]
m.nphysstar = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize = small_initial, bounds=phys_star_bounds_pert)
# Physical adsorption equilibrium with linear region [mol/kg]
m.nphysstar_mod = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize =small_initial, bounds=phys_star_bounds_pert)
# alpha used to form linearized pressure
if alpha_variable:
m.alpha = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize = small_initial, bounds=(small_bound,1.0))
if m.chemsorb:
# Chemical adsorption loading, [mol of gas/ kg of sorbent]
m.nchem = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize = small_initial, bounds=chem_star_bounds_pert)
# Time derivative, [mol/kg/s]
m.dnchemdt = DerivativeVar(m.nchem, wrt=m.t)
if m.physsorb:
# Physical adsorption equilibrium loading, [mol of gas/kg of sorbent]
m.nphys = pyo.Var(m.scena, m.SCOMPS, m.zgrid, m.t, initialize = small_initial, bounds=phys_star_bounds_pert)
# Time derivative, [mol/kg/s]
m.dnphysdt = DerivativeVar(m.nphys, wrt=m.t)
m.dv = pyo.Set(initialize=['k', 'ua'])
if m.energy:
def b_a_en(m,j,z,t):
return b_a0*pyo.exp(Q_sta/(RPV*T0)*(T0/m.temp[j,z,t]-1))
# Eq 14 in Aug. 2018 WVU report
# LHS: [1/bar]
# RHS: [1/bar] * exp( [kJ/mol]/[kJ/mol/K * K] ) = [1/b] * exp( [ dimensionless ] )
m.b_a = pyo.Expression(m.scena, m.zgrid, m.t, rule=b_a_en)
# Eq 15 in Aug. 2018 WVU report
# LHS: dimensionless
# RHS: dimensionless * exp( [kJ/mol]/[kJ/mol/K * K] ) = [dimensionless] * exp( [ dimensionless ])
def n_a_en(m,j,z,t):
return n_a1*pyo.exp(E_na/(RPV*T0)*(T0/m.temp[j,z,t]-1) + small_bound)
m.n_a = pyo.Expression(m.scena, m.zgrid, m.t, rule=n_a_en)
def inv_n_a_en(m,j,z,t):
return 1/m.n_a[j,z,t]
m.inv_n_a = pyo.Expression(m.scena, m.zgrid, m.t, rule=inv_n_a_en)
# Eq 13 in Aug. 2018 WVU report
# LHS: dimensionless
# RHS: dimensionless + K/K
def k_eq_en(m,j,z,t):
return pyo.exp(Ka + Kb/m.temp[j,z,t] + small_bound)
m.K_eq = pyo.Expression(m.scena, m.zgrid, m.t, rule=k_eq_en)
### Physical adsorption isotherm
# Eq 14 in Aug. 2018 WVU report
# LHS: bar-1
# RHS: bar-1 * (kJ/mol)/(kJ/mol/K * K)
def b_b_en(m,j,z,t):
return b_b0*pyo.exp(Q_stb/(RPV*T0)*(T0/m.temp[j,z,t]-1) + small_bound)
m.b_b = pyo.Expression(m.scena, m.zgrid, m.t, rule=b_b_en)
# Eq 16 in Aug. 2018 WVU report
# LHS: mol/kg
# RHS: mol/kg * 1
def nmax_p_en(m,j,z,t):
return nmax_p1*(pyo.exp(Kc+Kd/m.temp[j,z,t] + small_bound)/(1+pyo.exp(Kc+Kd/m.temp[j,z,t] + small_bound)))
m.nmax_p = pyo.Expression(m.scena, m.zgrid, m.t, rule=nmax_p_en)
# Eq 12 in Aug. 2018 WVU report
# LHS: mol/kg
# RHS: mol/kg * 1 / 1 = mol/kg
def nmax_c_en(m,j,z,t):
return n_max*m.K_eq[j,z,t]/(1+m.K_eq[j,z,t])
m.nmax_c = pyo.Expression(m.scena, m.zgrid, m.t, rule=nmax_c_en)
# Linear pressure adsorption when P < Plinear
# According to ACM
# LHS: mol/kg
# RHS: mol/kg * ((1/bar * bar )/ (bar^-1 * 10bar))
def nplin_en(m,j,z,t):
nplin_num = (m.b_a[j,z,t]*plin)**(m.inv_n_a[j,z,t])
nplin_de = 1+(m.b_a[j,z,t]*plin)**(m.inv_n_a[j,z,t])
return m.nmax_c[j,z,t]*(nplin_num/nplin_de)
m.nplin = pyo.Expression(m.scena, m.zgrid, m.t, rule=nplin_en)
### DEFINE EQUATION FUNCTION
def gas_comp_mb(m, j, i, z, t):
'''
Calculate bulk gas phase species balances.
Used when diffusion is not considered.
Arguments:
m: model
j: model.perturb
i: model.SCOMPS or model.COMPS
z: model.zgrid
t: model.t
Return: ODE for calculating component species density
'''
# Eq 1 in Aug.report
# LHS: mol/m3/s
# RHS: (cm/s * mol/m3 / (100cm/m) - cm/s * mol/m3 / (100cm/m))/m = mol/m3/s
if z == 0:
dvCdz = (m.v[j,z,t]*0.01*m.C[j,i,z,t] - vel_f*0.01*m.totden_f*m.yfeed[i])/dz
else:
dvCdz = (m.v[j,z,t]*0.01*m.C[j,i,z,t] - m.v[j,z-1,t]*0.01*m.C[j,i,z-1,t])/dz
diff_term = 0
# LDF from ACM code
if i in m.SCOMPS:
if m.chemsorb:
diff_term += (1-ads_epsb)*(den_s)*m.dnchemdt[j, i, z, t]
if m.physsorb:
diff_term += (1-ads_epsb)*(den_s)*m.dnphysdt[j, i, z, t]
disp_term = 0
if m.dispersion:
# LHS: mol/m3/s
# RHS: m2/s * mol/m3/m2
# combine the two gas mas balances, so it can be toggled on and off
if z == 0:
disp_term = Dax[i] * (m.C[j,i,z+2,t]-2*m.C[j,i,z+1,t]+m.C[j,i,z,t])/(dz*dz)
elif z == 19:
disp_term = Dax[i] * (m.C[j,i,z,t]-2*m.C[j,i,z-1,t]+m.C[j,i,z-2,t])/(dz*dz)
else:
disp_term = Dax[i] * (m.C[j,i,z+1,t]-2*m.C[j,i,z,t]+m.C[j,i,z-1,t])/(dz*dz)
# LHS: mol/m3/s; # RHS: mol/m3/s - mol/m3/s
return m.dCdt[j,i,z,t] == -dvCdz / (ads_epsb) - diff_term/ (ads_epsb) - disp_term
def gas_comp_mb_doe(m, j, i, z, t):
'''
Calculate bulk gas phase species balances.
Used when diffusion is not considered.
Arguments:
m: model
j: model.perturb
i: model.SCOMPS or model.COMPS
z: model.zgrid
t: model.t
Return: ODE for calculating component species density
'''
# Eq 1 in Aug.report
# LHS: mol/m3/s
# RHS: (cm/s * mol/m3 / (100cm/m) - cm/s * mol/m3 / (100cm/m))/m = mol/m3/s
if z == 0:
if i=='CO2':
dvCdz = (m.v[j,z,t]*0.01*m.C[j,i,z,t] - vel_f*0.01*m.totden_f*m.yfeed)/dz
elif i=='N2':
dvCdz = (m.v[j,z,t]*0.01*m.C[j,i,z,t] - vel_f*0.01*m.totden_f*(1-m.yfeed))/dz
else:
dvCdz = (m.v[j,z,t]*0.01*m.C[j,i,z,t] - m.v[j,z-1,t]*0.01*m.C[j,i,z-1,t])/dz
diff_term = 0
# LDF from ACM code
if i in m.SCOMPS:
if m.chemsorb:
diff_term += (1-ads_epsb)*(den_s)*m.dnchemdt[j, i, z, t]
if m.physsorb:
diff_term += (1-ads_epsb)*(den_s)*m.dnphysdt[j, i, z, t]
disp_term = 0
if m.dispersion:
# LHS: mol/m3/s
# RHS: m2/s * mol/m3/m2
# combine the two gas mas balances, so it can be toggled on and off
if z == 0:
disp_term = Dax[i] * (m.C[j,i,z+2,t]-2*m.C[j,i,z+1,t]+m.C[j,i,z,t])/(dz*dz)
else:
disp_term = Dax[i] * (m.C[j,i,z+1,t]-2*m.C[j,i,z,t]+m.C[j,i,z-1,t])/(dz*dz)
# LHS: mol/m3/s; # RHS: mol/m3/s - mol/m3/s
return m.dCdt[j,i,z,t] == -dvCdz / (ads_epsb) - diff_term/ (ads_epsb) - disp_term
def energy_balance(m, j, z, t):
'''
Energy balance assuming Tambient = Twall, Tg=Ts
Equation from [Dowling et al., 2012]
Arguments:
m: model
j: model.perturb
i: model.SCOMPS or model.COMPS
z: model.zgrid
t: model.t
Return: ODE for calculating component species density
'''
# calculate sum(ci*cpg)
# mol/m3 * J/mol/K = J/m3/K
sum_c = sum(m.C[j,i,z,t]*m.cpg[j,i,z,t] for i in m.COMPS)
# calculate the coefficient of dT/dt
# J/m3/K + kg/m3 * J/kg/K = J/m3/K
dividant = ads_epsb*sum_c + den_b*cps
# calculate the sum of Hi*dni/dt
# kJ/mol * mol/kg/s = kJ/kg/s
sum_hdn = sum(-m.H_ads[a]*(m.dnchemdt[j,a,z,t]+m.dnphysdt[j,a,z,t]) for a in m.SCOMPS)
# sum of heat flow, [J/m3]
# RHS: mol/m3 * J/mol = J/m3
h_sum = sum(m.C[j,b,z,t]*m.h[j,b,z,t] for b in m.COMPS)
# heat flow feed, [J/m3]
h_sum_feed = sum(m.den_f[p]*m.h_feed[p] for p in m.COMPS)
# LHS: W/m3 = J/s/m3
# RHS: cm/s * 1m/100cm * J/m3 * 1/m = J/s/m3
if z==0:
duhdz = (m.v[j,z,t]*0.01*h_sum - vel_f*0.01*h_sum_feed)/dz
else:
# heat flow of the previous grid, [J/m3]
h_sum_back = sum(m.C[j,b,z-1,t]*m.h[j,b,z-1,t] for b in m.COMPS)
duhdz = (m.v[j,z,t]*0.01*h_sum - m.v[j,z-1,t]*0.01*h_sum_back)/dz
# LHS: K/s
# RHS: (kg/m3 * kJ/kg/s * 1000J/1kJ - J/m3/s - J/s/m3/K *K)/ (J/m3/K) = K/s
return m.dTdt[j,z,t] == (den_b*sum_hdn*1000 - duhdz - pyo.exp(m.ua[j])*(m.temp[j,z,t]-m.temp_bath)+m.Q[t])/dividant
def dalton(m, j, z, t):
'''
Calculate total gas density from component gas densities.
Arguments:
m: model
j: model.perturb
z: model.zgrid
t: model.t
Return: Total gas density
'''
# LHS & RHS: [mol/m3]
return m.total_den[j,z,t] == sum(m.C[j,i,z,t] for i in m.COMPS)
def ideal(m,j, z, t):
'''
Calculate total pressure from ideal gas law.
Arguments:
m: model
j: model.perturb
z: model.zgrid
t: model.t
Return: total gas pressure in the bulk phase
'''
# LHS: mol/m3 * kJ/mol/K * K * 0.01 bar/kPa = kJ/m3 *100 kPa/bar = [bar]
# RHS: [bar]
if m.energy:
return m.total_den[j,z,t]*0.01 * RPV * m.temp[j,z,t] == m.P[j,z,t]
else:
return m.total_den[j,z,t]*0.01 * RPV * m.temp == m.P[j,z,t]
def ergun(m, j, z, t):
'''
Calculate velocity with Ergun equation.
An assumption was made: velocity is always positive
Arguments:
m: model
j: model.perturb
z: model.zgrid
t: model.t
Return: an ODE for velocity
'''
# LHS: kg/m4
# RHS: mol/m3*g/mol / m /(1000g/kg) = g/m4 / (1000g/kg) = kg/m4
mass_den=sum(m.C[j,i,z,t]*MW[i] for i in m.COMPS)
aeff = 1.75*mass_den*(1-ads_epsb)/(2*radp*ads_epsb*ads_epsb*ads_epsb)/1000
# LHS: kg/m3/s
# RHS: [Pa*s]/[m^2] = [kg/m/s]/[m^2] = kg / m^3 / s
beff = 150*fp_mu*(1-ads_epsb)*(1-ads_epsb)/(4*radp*radp*ads_epsb*ads_epsb*ads_epsb)
if z == 0:
dPdz = (m.P[j,z,t] - totp_f) / dz
else:
dPdz = (m.P[j,z,t] - m.P[j,z-1,t]) / dz
# Assumption: velocity is always positive
# LHS: [bar/m]
# RHS: [kg/m^4] * ([cm/s]*0.01m/cm)^2 + [kg / m^3 / s] * [cm/s*0.01m/cm] = [kg / m^2 / s^2] = [Pa/m] / (1E5Pa/bar)
return -dPdz == (aeff*(m.v[j,z,t]*0.01)**2 + beff*m.v[j,z,t]*0.01)/1.0E5
'''
def kf_calc(m,j,z,t):
Calculate the k_f with the dimensionless number equations.
Not used for now.
# RHS: m*m/s*kg/mol*mol/m3*m*s/kg = 1
Re = 2*radp*m.v[j,z,t]*0.01*M_co2*m.C[j,'CO2',z,t]/mu_co2
# RHS: kg/m/s * s/m2 * m3/mol * mol/kg = 1
Sc = mu_co2/D_m/m.C[j,'CO2',z,t]/M_co2
return 2*radp*m.kfilm[j,z,t]/D_m == 2+1.1*Re**(0.6)*Sc**(1/3)
'''
def calc_surface_pressure(m, j, i, z, t):
'''
Calculate surface partial pressure in solid phase (particle void).
For now, surface partial pressure is not bulk gas pressure.
Arguments:
m: model
j: model.perturb
i: model.SCOMPS or model.COMPS
z: model.zgrid
t: model.t
Return: surface partial pressure
'''
if m.energy:
return m.spp[j,i,z,t] == RPV*m.temp[j,z,t]*0.01*m.C[j,i,z,t]
else:
return m.spp[j,i,z,t] == RPV*m.temp*0.01*m.C[j,i,z,t]
def chem_isotherm(m, j, i, z, t):
'''
Calculate chemical equilibrium adsorption.
Arguments:
m: model
j: model.perturb
i: model.SCOMPS or model.COMPS
z: model.zgrid
t: model.t
Return: chemical equilibrium adsorption
'''
# Eq.11 in Aug.report
if m.energy:
nchem_num = (m.b_a[j,z,t]*m.spp[j,i,z,t])**(m.inv_n_a[j,z,t])
nchem_de = 1+(m.b_a[j,z,t]*m.spp[j,i,z,t])**(m.inv_n_a[j,z,t])
# LHS: unit of m.nchemstar = unit of nmax_c = mmol/g = mol/kg
return m.nchemstar[j,i,z,t]*nchem_de == m.nmax_c[j,z,t]*nchem_num
else:
inv_n_a = 1/m.n_a
nchem_num = (m.b_a*m.spp[j,i,z,t])**(inv_n_a)
nchem_de = 1+(m.b_a*m.spp[j,i,z,t])**(inv_n_a)
# LHS: unit of m.nchemstar = unit of nmax_c = mmol/g = mol/kg
return m.nchemstar[j,i,z,t]*nchem_de == m.nmax_c*nchem_num
def chem_isotherm_mod(m, j, i, z, t):
'''
Calculate MODIFIED chemical equilibrium adsorption
Arguments:
m: model
j: model.perturb
i: model.SCOMPS or model.COMPS
z: model.zgrid
t: model.t
Return: chemical equilibrium adsorption
'''
# RHS: [mol/kg] * [bar]/[bar] + [mol/kg]
# LHS: [mol/kg]
if m.energy:
return m.nchemstar_mod[j,i,z,t] == m.alpha[j,i,z,t] * m.nplin[j,z,t] *m.spp[j,i,z,t]/plin + (1-m.alpha[j,i,z,t])*m.nchemstar[j,i,z,t]
else:
return m.nchemstar_mod[j,i,z,t] == m.alpha[j,i,z,t] * m.nplin*m.spp[j,i,z,t]/plin + (1-m.alpha[j,i,z,t])*m.nchemstar[j,i,z,t]