-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSA_biogas_upgrading_constrained.m
277 lines (241 loc) · 9.62 KB
/
PSA_biogas_upgrading_constrained.m
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
%% OPTIMIZATION OF SKARSTROM PRESSURE SWING PROCESSES
%% Case 2: Removal of (A) CO2 from (B) methane using zeolite 13X
%% (biogas upgrading)
clear all; clc; clf;
%% Thermodynamic variables
global R T PL cp cv kappa;
R=8.31446; % gas constant, J/(mol K)
T=298.15; % temperature, K
PL=101325; % low pressure, Pa
cp=2.22; % heat capacity at constant pressure, kJ/(kg K), *mass* basis
cv=1.70; % heat capacity at constant volume, kJ/(kg K), *mass* basis
kappa=cp/cv; % heat capacity ratio, dimensionless
%% Adsorber column
global L Lmargin V D area S E theta psi alower aupper Pmargin;
Lmargin=0.05; % robustness margin, m
D=0.1; % column diameter, m
area=pi*D^2/4; % column cross-sectional area, m^2
S=20*1000*6895; % maximum allowable stress of material used, Pa
E=0.70; % welded joint efficiency, dimensionless
theta=3.5e-3; % column wall thickness, m
psi=3e-3; % corrosion allowance, m
alower=2; % lower practical design limit of aspect ratio, dimensionless
aupper=10; % upper practical design limit of aspect ratio, dimensionless
Pmargin=0.9; % margin PH/MAWP (max allowable working P), dimensionless
%% Adsorbent bed
global rhoads eps nu Nads;
rhoads=1130; % adsorbent density, kg/m^3
eps=0.54; % adsorbent bed voidage, dimensionless
nu=(1-eps)/eps; % dimensionless packing ratio, dimensionless
Nads=1000; %adsorbent lifetime, number of regenerations (cycles)
%% Flow variables
global ufeed vfeed Qfeed phi;
ufeed=0.45; % superficial feed velocity, m/s
vfeed=ufeed/eps; % interstiatial feed velocity, m/s
Qfeed=area*ufeed; % superficial feed volumetric flow rate, m^3/s
phi=1.03; % purge ratio, dimensionless
%% Feed variables
global yAfeed;
yAfeed=0.005; % molar fraction of adsorbing species A, dimensionless
%% Adsorption data
global betaA betaB;
% linear adsorption constant, dimensionless
HA=15.3e-6*rhoads*R*T;
HB=3.2e-6*rhoads*R*T;
betaA=1+nu*HA; % adsorption factor for A, dimensionless
betaB=1+nu*HB; % adsorption factor for B, dimensionless
%% Compressor data
global etacomp tlife maxratio Pmaxdiff;
etacomp=0.8; % compressor efficiency, dimensionless
tlife=60^2*24*365*10; % compressor lifetime, dimensionless
maxratio=4; % maximum desirable compression ratio, dimensionless
Pmaxdiff=10e5; % maximum allowable pressure differential, Pa
%% Prices & costs
global KB Kelec Kads Ka Kb Kc K1 K2 K3;
KB=0.006; % retail price of B
Kelec=3.6e-8; % electricity tariff, USD/J
Kads=2.50; % adsorbent unit cost, USD/kg
% compressor cost correlating parameters, dimensionless
Ka=[5.8e5,2.6e5]; Kb=[2e4,2.7e3]; Kc=[0.6,0.75];
% column cost correlating parameters, dimensionless
K1=3.5565; K2=0.3776; K3=0.0905;
%% Optimisation type
% set true for PH/PL and L/D to be operationally constrained
% by safety / practical design limits
constrained = true;
%% Optimisation problem formulation and solving via fmincon
fun = @(x) objfun(x);
nonlcon = @(x) constraints(x);
x0 = [5,30,10];
A = [];
b = [];
Aeq = [];
beq = [];
if constrained
lb = [1,...
0,...
max(alower,Lmargin/D)];
ub = [1/PL*...
min(Pmaxdiff+PL,...
Pmargin*min(...
2*S*E*theta/(D+1.2*theta),...
4*S*E*theta/(D-0.8*theta))...
),...
tlife,...
aupper];
else
Lmargin=0; % Redundant in the absence of
% safety / practical design limits
lb = [1,0,Lmargin/D];
ub = [Inf,tlife,Inf];
end
options = optimoptions('fmincon','Algorithm','sqp','Display','iter',...
'StepTolerance',1e-12,'ConstraintTolerance',1e-9);
[x,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
%% Evaluate the remaining variables at optimal point
Pswing = x(1); tfeed = x(2); aspect = x(3);
L=aspect.*D; % column length, m
V=L.*area; % column volume, m^3
PH=Pswing.*PL; % high pressure, Pa
PB=PL.*Qfeed.*tfeed./(R.*T)...
.*(Pswing.*(1-yAfeed)...
-phi.*(1-yAfeed.*(Pswing).^(1-betaB./betaA))); % production per cycle, mol
Ncomp=max(1,log(Pswing)./log(maxratio)); % number of compression stages
Wcomp=Ncomp/etacomp.*kappa/(kappa-1).*R.*T...
.*(Pswing.^((kappa-1)./(kappa.*Ncomp))-1); % work done by compressor, J/mol
Pcomp=Wcomp.*(PH./(R.*T).*Qfeed); % power required by compressor, W
tpres=(1-1./Pswing).*V./Qfeed; % time for pressurisation, s
tcycle=2.*(tfeed+tpres); % total cycle time, s
Revenue=PB.*KB.*tlife./tcycle; % production revenue of B, USD
Celec=Pcomp.*(tlife./2).*Kelec; % cost of electricy, USD
% cost of compressor, USD
Ccomp=min(Ka+Kb.*(Pcomp./1000).^Kc);
% cost of column, USD
Ccolbase=10.^(K1+K2.*log10(V)+K3.*(log10(V)).^2);
Fcol=(PH.*D./(2.*S.*E-1.2.*PH)+psi)/(3.*D./1000+psi);
Ccol=Fcol.*Ccolbase;
% cost of adsorbent, USD
Cads=Kads.*rhoads.*(1-eps).*V.*tlife./(Nads.*tcycle);
cost=-Revenue+Celec+Ccomp+Ccol+Cads; % overall cost (should be negative!)
%% Display results
format bank
results.AspectRatio=x(3);
results.PressureSwing=x(1);
results.ProductionRate=PB;
results.FeedVelocity=vfeed;
results.CompressorWork=Wcomp;
results.CompressorPower=Pcomp;
results.PresTime=tpres;
results.FeedTime=x(2);
results.CycleTime=tcycle;
results.RevenueB=Revenue;
results.ElectricityCost=Celec;
results.CompressorCapital=Ccomp;
results.ColumnCapital=Ccol;
results.AdsorbentCost=Cads;
results.Profit=-cost;
results
format
%% Plot PH/PL vs tfeed global surface
figure(1); clf; hold on;
clearvars xcoord ycoord zcoord fcoord;
xcoord = linspace(1,20); % Pswing
ycoord = linspace(1,50); % tfeed
zcoord = x(3); % L/D
for i=1:length(xcoord)
for j=1:length(ycoord)
fcoord(j,i) = objfun([xcoord(i),ycoord(j),zcoord]);
end
end
%surf(xcoord,ycoord,-fcoord,'EdgeColor','none');
levels=[-0.25:0.25:2].*1e6;
contour(xcoord,ycoord,-fcoord,levels,'k--','ShowText','on');
contour(xcoord,ycoord,-fcoord,[0,0],'k-','ShowText','on');
xlabel('P_H/P_L'), ylabel('t_{feed} / s'), zlabel('Lifetime profit/USD');
plot([x(1) x(1)],[x(2) x(2)],'k*');
adsfrontcon = xcoord.^(-betaB./betaA).*betaA.*(L-Lmargin)./vfeed;
desfrontcon = (phi.^(betaA./betaB)).*ones(length(ycoord));
%moleboundcon = (1./yAfeed).^(1./(1-betaB./betaA)).*ones(length(ycoord));
compresscon = (Pmaxdiff+PL)./PL.*ones(length(ycoord));
plot(xcoord,adsfrontcon,'r-',desfrontcon,ycoord,'b-',...
compresscon,ycoord,'g-.');
legend('Lifetime profit/USD','Profit boundary','Optimal point');
title(strcat('CO_2/CH_4, Lifetime profit (L/D=',num2str(x(3)),')'));
hold off;
%% Plot PH/PL vs L/D global surface
figure(2); clf; hold on;
clearvars xcoord ycoord zcoord fcoord;
xcoord = linspace(1,1400); % Pswing
ycoord = x(2); % tfeed
zcoord = linspace(1,700); % L/D
for i=1:length(xcoord) % Pswing
for j=1:length(zcoord) % L/D
fcoord(j,i) = objfun([xcoord(i),ycoord,zcoord(j)]);
end
end
%surf(xcoord,zcoord,-fcoord,'EdgeColor','none');
levels=[-0.25,-0.1,0,0.1,0.25,0.5,1,2,4,8].*1e7;
contour(xcoord,zcoord,-fcoord,levels,'k--','ShowText','on');
contour(xcoord,zcoord,-fcoord,[0,0],'k-','ShowText','on');
xlabel('P_H/P_L'), ylabel('L/D'), zlabel('Lifetime profit/USD');
plot([x(1) x(1)],[x(3) x(3)],'k*');
adsfrontcon = (xcoord.^(betaB./betaA).*vfeed.*x(2)./betaA+Lmargin)./D;
desfrontcon = (phi.^(betaA/betaB)).*ones(length(zcoord));
%moleboundcon = (1./yAfeed).^(1./(1-betaB./betaA)).*ones(length(zcoord));
compresscon = (Pmaxdiff+PL)./PL.*ones(length(zcoord));
columncon = aupper.*ones(length(xcoord));
plot(xcoord,adsfrontcon,'r-',desfrontcon,zcoord,'b-',...
compresscon,zcoord,'g-.',...
xcoord,columncon,'m-.');
legend('Lifetime profit/USD','Profit boundary','Optimal point');
title(strcat('CO_2/CH_4, Lifetime profit (t_{feed} / s=',num2str(x(2)),')'));
hold off;
%% Plot PH/PL vs L/D global surface, zoomed in
figure(3); clf; hold on;
clearvars xcoord ycoord zcoord fcoord;
xcoord = linspace(1,12); % Pswing
ycoord = x(2); % tfeed
zcoord = linspace(1,15); % L/D
for i=1:length(xcoord) % Pswing
for j=1:length(zcoord) % L/D
fcoord(j,i) = objfun([xcoord(i),ycoord,zcoord(j)]);
end
end
%surf(xcoord,zcoord,-fcoord,'EdgeColor','none');
levels=[-2,0,4,8].*1e5;
contour(xcoord,zcoord,-fcoord,levels,'k--','ShowText','on');
contour(xcoord,zcoord,-fcoord,[0,0],'k-','ShowText','on');
xlabel('P_H/P_L'), ylabel('L/D'), zlabel('Lifetime profit/USD');
plot([x(1) x(1)],[x(3) x(3)],'k*');
adsfrontcon = (xcoord.^(betaB./betaA).*vfeed.*x(2)./betaA+Lmargin)./D;
desfrontcon = (phi.^(betaA/betaB)).*ones(length(zcoord));
%moleboundcon = (1./yAfeed).^(1./(1-betaB./betaA)).*ones(length(zcoord));
compresscon = (Pmaxdiff+PL)./PL.*ones(length(zcoord));
columncon = aupper.*ones(length(xcoord));
plot(xcoord,adsfrontcon,'r-',desfrontcon,zcoord,'b-',...
compresscon,zcoord,'g-.',xcoord,columncon,'m-.');
hold off;
%% Plot tfeed vs L/D global surface
figure(4); clf; hold on;
clearvars xcoord ycoord zcoord fcoord;
xcoord = x(1); % Pswing
ycoord = linspace(1,50); % tfeed
zcoord = linspace(1,12); % L/D
for i=1:length(ycoord)
for j=1:length(zcoord)
fcoord(j,i) = objfun([xcoord,ycoord(i),zcoord(j)]);
end
end
%surf(ycoord,zcoord,-fcoord,'EdgeColor','none');
levels=[0,4,6,7,8,8.5,9,9.25,9.5].*1e5;
contour(ycoord,zcoord,-fcoord,levels,'k--','ShowText','on');
contour(ycoord,zcoord,-fcoord,[0,0],'k-','ShowText','on');
xlabel('t_{feed} / s'), ylabel('L/D'), zlabel('Lifetime profit/USD');
plot([x(2) x(2)],[x(3) x(3)],'k*');
ylim([1 12]);
adsfrontcon = (vfeed.*ycoord./betaA.*(x(1)).^(betaB./betaA)+Lmargin)./D;
columncon = aupper.*ones(length(ycoord));
plot(ycoord,adsfrontcon,'r-',ycoord,columncon,'m-.');
legend('Lifetime profit/USD','Profit boundary','Optimal point');
title(strcat('CO_2/CH_4, Lifetime profit (P_H/P_L=',num2str(x(1)),')'));
hold off;