How do I estimate average of a variable over the discretized domain

9 views (last 30 days)
Dear Community, I have written th code (as attached) to compute water adsorption in silica gel bed. In the following part of the code I am calculating the relative humidity, phi.
for i = 1:n
P_sat = 610.78*exp((17.27*(Tair(i)-273.15))/(Tair(i)-35.85));
P_vap=(W(i)*R*rho_air*Tair(i))/M_w;
phi= (P_vap*100)/P_sat; % relative humidity
Q_eq = ((a*b1*phi)/1+(b1*phi)) + ((a*b2*(phi^q))/(1+(b2*(phi^n)))); % Langmuir-sips isotherm equation
DQDt(i) = K_LDF*(Q_eq - Q(i)); %LDF
end
In the equation of P_vap; W is the absolute humidity and Tair is the air temperature. The current codes uses W(i) and Tair(i) at each specifc n, where n is the number of discretization. I have used n=100, i.e., I have divided the whole air channel (length 0.2mm) into 100 divisions. The attached excel sheets are the outout of W and Tair.
Instead of W(i) and Tair(i), I would like to use the average of W and Tair for the discretized domain (i.e., the average value of columns B, C, D, E...in the excel sheets) at each time step in the equation of P_vap. Similarly, in the equation of P_sat, I want to use the average of Tair for the domain discretized in 'n' divisions.
I also want to outout two other parameters:1. average of Q for the 'n' discretized domain integrated at each time step (i.e., mass of water adsorbed in the bed), and 2. difference of the average of W of the 'n' discretized domain at the inlet and outlet (i.e., dehumidification capacity).
How can I implement this in the above section of the code?
I shall be highly grateful if someone can help.
  5 Comments
JUBAIR
JUBAIR on 27 Mar 2025
Hi Toresten, you are right. Unit of Q is kg/kg. Let me try to use your formula. I will get back to you if I am successful. Thanks.
Torsten
Torsten on 27 Mar 2025
Edited: Torsten on 27 Mar 2025
Be careful with rho_s. Usually, one uses rho_s = m_s/(V_s + V_p) as the solid density in the simulation where V_s is the volume of the (pure) solid and V_p is the intra-particle volume. That's what I used above in computing the mass of adsorbed water.
Since you don't use the finite-volume method, I guess, the formula from above can be adjusted for your case as
(1-epsilon) * rho_s * ((V_1 * Q_1) / 2 + ( sum_{i=1}^{i=N-1} (V_i*Q_i + V_(i+1)*Q_(i+1)) / 2 ) + V_N*Q_N / 2)

Sign in to comment.

Accepted Answer

Marie Anna NOVIELLO
Marie Anna NOVIELLO on 27 Mar 2025
  • Calculate W and Tair averages: Rather of utilizing W(i) and Tair(i) for each division, compute the average value of W and Tair throughout the discretised domain at each time step.
  • Use the following averages in the equations: Replace W(i) and Tair(i) with the derived averages when computing P_vap and P_sat to represent the overall domain conditions at each time step.
  • Calculate the total mass of water adsorbed. Integrate (average) the Q values over the domain at each time step to calculate the total mass of water adsorbed in the bed.
  • Calculate the dehumidification capacity: Calculate the difference between the average W at the inlet and outlet (first and last discretization points), which represents the dehumidification capacity.
% Initialize output arrays
Q_total = zeros(1, n); % to store total adsorbed water in the bed
W_dehumidification_capacity = zeros(1, n); % to store dehumidification capacity
for i = 1:n
% Calculate average W and Tair for the discretized domain
avg_W = mean(W_data(:, i)); % Average of W for the spatial domain at time step i
avg_Tair = mean(Tair_data(:, i)); % Average of Tair for the spatial domain at time step i
% Calculate P_vap and P_sat using average values
P_sat = 610.78 * exp((17.27 * (avg_Tair - 273.15)) / (avg_Tair - 35.85));
P_vap = (avg_W * R * rho_air * avg_Tair) / M_w;
phi = (P_vap * 100) / P_sat; % relative humidity
% Langmuir-sips isotherm equation
Q_eq = ((a * b1 * phi) / (1 + (b1 * phi))) + ((a * b2 * (phi^q)) / (1 + (b2 * (phi^n)))));
% LDF calculation
DQDt(i) = K_LDF * (Q_eq - Q(i));
% Calculate total mass of water adsorbed in the bed (integrated over the domain)
Q_total(i) = sum(Q) / n;
% Calculate dehumidification capacity
W_inlet = W_data(1, i); % Inlet (first column in W_data)
W_outlet = W_data(n, i); % Outlet (last column in W_data)
W_dehumidification_capacity(i) = mean(W_outlet) - mean(W_inlet);
end
  19 Comments
JUBAIR
JUBAIR on 30 Apr 2025

@Torsten, I am facing another simple problem in this code. Tried for hours today but couldn't solve. I want to save the values of "phi" at each time step in an excel file. It should be easy but I wasn't successful. Could you please provide the code to save phi in excel file? I shall remain grateful to you.

Torsten
Torsten on 1 May 2025
Save phi in an array Phi(i) and proceed as suggested for Qbed and DC:
[T,Y] = ode45 (@(t,y) solution(t,y,X,n),tspan,y0);
for i = 1:numel(T)
[~,Q_bed,DC,Phi] = solution(T(i),Y(:,i),X,n);
Q_bed_matrix(i,:) = Q_bed;
DC_matrix(i,:) = DC;
Phi_matrix(i,:) = Phi;
end
function [DyDt,Q_bed,DC,Phi] = solution(~,y,X,n)
...
for i = 1:n
% Calculate average W and Tair for the discretized domain
avg_W = mean (W(i)); % Average of W for the spatial domain
avg_Tair = mean(Tair(i)); % Average of Tair for the spatial domain
% Calculate P_vap and P_sat using average values
P_sat = 610.78 * exp((17.27 * (avg_Tair - 273.15)) / (avg_Tair - 35.85));
P_vap = (avg_W * R * rho_air * avg_Tair) / M_w;
phi = (P_vap * 100) / P_sat; % relative humidity
% Langmuir-sips isotherm equation
%Q_eq = ((a * b1 * phi) / (1 + (b1 * phi))) + ((a * b2 * (phi^q)) / (1 + (b2 * (phi^n)))));
Q_eq = ((a*b1*phi)/1+(b1*phi)) + ((a*b2*(phi^q))/(1+(b2*(phi^n)))); % Langmuir-sips isotherm equation
% LDF calculation
DQDt(i) = K_LDF * (Q_eq - Q(i));
% Calculate total mass of water adsorbed in the bed (integrated over the domain)
Q_bed(i) = sum(Q(i))/n;
% Calculate dehumidification capacity
W_inlet = W(2); % Inlet (first column in W_data)
W_outlet = W(n); % Outlet (last column in W_data)
DC(i) = W_inlet - W_outlet;
Phi(i) = phi;
end
...
end

Sign in to comment.

More Answers (0)

Categories

Find more on Propagation Channel Models in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!