Plot-Parameter study- Adsorption
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I am trying to do a parameter study (velocity and length) on an adsorbent. I had the following idea on how to do it but it doesnt work and I cant figure out how to solve the error.
I am relatively new in matlab so for any suggestion I am grateful.
velocity = [0.01 0.1 0.5 1 1.5 2 2.5 3 3.5]; % Diffferent velocity values
for ii=1:numel(velocity)
v=velocity(ii);
[T, Y] = Main(v);
plot(T,Y(:,n), 'linewidth', 1),
hold all
end
function [T, Y] = Main(~)
cFeed = 0.016; % Feed concentration in mol/m3
L = 0.3; % Column length in m
t0 = 0; % Initial Time in s
tf = 8000; % Final time in s
dt = 0.5; % Time step
z = 0:0.005:L; % Mesh generation
t = t0:dt:tf; % Time vector
n = numel(z); % Size of mesh grid
% Initial Conditions / Vector Creation
c0 = zeros(n,1); % c = 0 at t = 0 for all z
c0(1) = cFeed; % c = cFeed at z= 0 for all t
q0 = zeros(n,1); % q = 0 at t = 0 for all z
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode15s(@(t,Y) MyFun(t,Y,z,n),t,y0);
end
function DyDt=MyFun(~, y, z, n)
% Design parameters of the adsorbent bed
epsilon = 0.87; % bed porosity
%v = 3; % superficial velocity in m/s
rho = 500; % particle density in kg/m3
r_1 = 0.000525; % Channel inner radius in m
L = 0.3; % bed length in m
% General parameters
De = 1e-11; % effective diffusivity
Dm = 1.381e-5; % molecular diffusivity of co2 in air in m2/s
Dl = Dm +(v*r_1*2)^2/(192*Dm); % axial dipsersion coefficient in m2/sec
k = 0.005; % mass transfer coefficient in 1/sec
R = 8.314; % gas constant in J/mol-K
T = 298; % gas temp in K
% Parameters of the isotherm
qsat1 = 0.16; % mol/kg
b1 = 4.89e-2; % 1/pascal
qsat2 = 3.5; % mol/kg
b2 = 22e-2; % 1/pascal
b3 = 0.00062e-2; % mol/kg-pascal
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
D2cDz2(i) = ((c(i+1)-c(i))/(z(i+1)-z(i))-(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% time derivatives at z=0 and q*
if R*T*c(1) < 16
qstar=(qsat1*b1*R*T*c(1))/(1+b1*R*T*c(1));
else
qstar=(qsat2*b2*(R*T*c(1)-16))/(1+b2*(R*T*c(1)-16)) + b3*R*T*c(1);
end
DqDt(1) = k*(qstar - q(1) );
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
% q* for RTc < or > 16
if R*T*c(i) <16
qstar=(qsat1*b1*R*T*c(i))/(1+b1*R*T*c(i));
else
qstar=(qsat2*b2*(R*T*c(i)-16))/(1+b2*(R*T*c(i)-16)) + b3*R*T*c(i);
end
% Equation: dq/dt = k(q*-q)
DqDt(i) = k*(qstar - q(i) );
% Equation: dc/dt = Dl * d2c/dz2 - v*dc/dz - ((1-e)/(e))*roh*dq/dt
DcDt(i) = Dl*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*rho*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
0 commentaires
Réponses (1)
Torsten
le 12 Jan 2023
Modifié(e) : Torsten
le 12 Jan 2023
I don't know whether you and Sona Ghulami are the same person, but i suggest you start with the last code under
because several mistakes in the code have been eliminated.
Especially change
DcDz(n) = 0;
to
DcDz(n) = (c(n)-c(n-1))/(z(n)-z(n-1));
Concerning your question:
Change
function [T, Y] = Main(~)
to
function [T, Y] = Main(v)
and
[T, Y] = ode15s(@(t,Y) MyFun(t,Y,z,n),t,y0);
to
[T, Y] = ode15s(@(t,Y) MyFun(t,Y,z,n,v),t,y0);
and
function DyDt=MyFun(~, y, z, n)
to
function DyDt=MyFun(~, y, z, n, v)
And I explicitly suggest that you plot qstar over c before you continue.
5 commentaires
Torsten
le 18 Jan 2023
Modifié(e) : Torsten
le 18 Jan 2023
Read again my suggested changes in the answer above.
If you want to have T and Y as output from "Mainmmen", you must define them as output arguments within the function:
function [T,Y] = mainmmen(v)
And change
DqDt = k*(qstar(i) - q );
to
DqDt = k*(qstar - q );
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!