## Thermodynamic filling of tank. (matlab)

1. The problem statement, all variables and given/known data

A 70 ft3 rigid insulated tank contains air at 14.7 psia and 80 º F. The tank is connected to a supply line through a valve. Air is flowing in the supply line at 75 psia and 80 º F. The valve is opened, and air is allowed to enter the tank until the pressure in the tank reaches the line pressure, at which point the valve is closed. The diameter of the connecting pipe is 1 inch.

Write a computer program to model the pressurization process in the tank. The computer program will calculate the pressure, temperature, mass flowrate into the tank and resident mass during the process. Determine the final temperature, mass of air in the tank and time required to pressurize the tank.

2. Relevant equations

All the relevant equations are labeled in the coding

3. The attempt at a solution
Code:
P1=75; % in psi

T1=(80+459.67); %in R

A1=(pi*1)/(4*144); % Area in ft^2

D1=1; % Diameter in inch

P2=(14.7); % in psi

T2=T1; %in R

V2=70; % in ft^3

Cp=0.24; % in Btu/lb-R

Cv=0.17; % in Btu/lb-R

k=1.4;% gamma

Cd=0.6; % is unitless

R=53.33; % in ft-lb/lb/R

rho1=(P1*144)/(R*T1); % density in lb/ft^3

rho2=(P2*144)/(R*T2); % density in lb/ft^3

mass2=(rho2*V2); % mass in lb

g=32.174; % in ft/sec^2

dt=0.01; % change in time intervals

n=1;

m(1)=mass2;

P(1)=P2;

T(1)=T2;

while P2<P1-.01

error=1;

n=n+1;

while error>0.001

%Equations

mdot=A1*sqrt(((2*k)/(k-1))*P1*g*rho1*(P2/P1)^(2/k)*(1-(P2/P1))^(k-1/k));

mass2new=mass2+mdot*dt;

u=(mass2*Cv*T2+mdot*Cp*T1*dt)/mass2new; %energy equation

T2=u/Cv;

P2new=mass2new*R*T2/(V2*144);

error=abs(P2new-P2)/P2;

P2=P2new;

end

mass2=mass2new;

T(n)=T2;

P(n)=P2;

m(n)=mass2new;

t(n)=n*dt;

end

%% Output

fprintf('The final temperature = %7.3f R\n',T2)

fprintf('The mass of air in tank = %7.3f lb\n',mass2new)

fprintf('The time required to pressurize the tank = %7.3f s\n',t(n))

figure(1)

plot(t,T,'g','Linewidth',2)

grid

ylabel('Temperature (R)')

xlabel('Time (s)')

title('Time Vs Temperature')

figure(2)

plot(t,P,'b','Linewidth',2)

grid

xlabel('Time (s)')

ylabel('Pressure (psi)')

title('Time Vs Pressure')

figure(3)

plot(t,m,'r','Linewidth',2)

grid

xlabel('Time (s)')

ylabel('Mass (lb)')

title('Time Vs Mass')
Time around 8 seconds
Temperature around 700 Rankine
and I do not know what the mass should be.

The final temperature = 704.984 R
The mass of air in tank = 20.106 lb
The time required to pressurize the tank = 82.710 s

I do not know where the error in my coding is or if it is in one of my equations I have retyped them multiple times making sure the equations are correct and I am 99% correct that my algorithm is correct, any suggestions on where there error is coming from??
 PhysOrg.com science news on PhysOrg.com >> City-life changes blackbird personalities, study shows>> Origins of 'The Hoff' crab revealed (w/ Video)>> Older males make better fathers: Mature male beetles work harder, care less about female infidelity
 The final temperature and mass look right. I am not following your process for finding the time to fill the tank. It looks like you are trying to find the mass flow rate of a gas through a valve and then finding a new Mass2, U, T2 and P2 with a time step of .01 seconds but not sure.
 where is Cd in your mass flow rate equation?

## Thermodynamic filling of tank. (matlab)

 Quote by RTW69 where is Cd in your mass flow rate equation?
http://ntrs.nasa.gov/archive/nasa/ca...1997030443.pdf

The above line is more information on the problem however the reason I am sending it is because on page 3 is the flow equation.

To answer your other reply yes, I believe my final temperature and mass are correct I tried inserting an if loop directly under my flow equation
Code:
if (P2/P1) <= (2/(k+1))^(k/(k-1))
(P2/P1)= (2/(k+1))^(k/(k-1))

(2/(k+1))^(k/(k-1)) is the pressure critical.

However this only made my time increase.

Any idea what could be going on?
 i have almost the same problem and i can't solve it ;( plz any body help me A Rigid tank is filled with refrigerant R-134a at 300 K. An electric current of 0.1 Amps over 120 Volts is passed through the refrigerant for 1 minute. The tank is not very well insulated. After many hours, the temperature is measured to be 300 K again. How much heat (if any) the refrigerant lost?
 Figure 4, Case 3 of the NASA document shows 80 seconds to fill 2 CU.liters. Are you sure your 8 seconds is correct?
 Yes I am sure 8 seconds is correct, however I realized in my flow equation I have P1 in psi not psf so I multiplied it by 144, but I did not change the values for p1 or p2 because (p1/p2) if both are in psf or psi is the same to better demonstrate what I did the code is below, however I am closer to the answer I must just have a simple error somewhere. Code: P1=75; % in psi T1=(80+459.67); %in R A1=(pi*1)/(4*144); % Area in ft^2 D1=1; % Diameter in inch P2=(14.7); % in psi T2=T1; %in R V2=70; % in ft^3 Cp=0.24; % in Btu/lb-R Cv=0.17; % in Btu/lb-R k=1.4;% gamma Cd=0.6; % is unitless R=53.33; % in ft-lb/lb/R rho1=(P1*144)/(R*T1); % density in lb/ft^3 rho2=(P2*144)/(R*T2); % density in lb/ft^3 mass2=(rho2*V2); % mass in lb g=32.174; % in ft/sec^2 dt=0.01; % change in time intervals n=1; m(1)=mass2; P(1)=P2; T(1)=T2; Pcrit=(2/(k+1))^(k/(k-1)); Prat= (P2/P1); while P20.001 %Equations mdot=A1*sqrt(((2*k)/(k-1))*P1*144*g*rho1*Prat^(2/k)*(1-(Prat))^(k-1/k)); if Prat <= Pcrit; Prat= Pcrit; end mass2new=mass2+mdot*dt; u=(mass2*Cv*T2+mdot*Cp*T1*dt)/mass2new; %energy equation T2=u/Cv; P2new=mass2new*R*T2/(V2*144); error=abs(P2new-P2)/P2; P2=P2new; end mass2=mass2new; T(n)=T2; P(n)=P2; m(n)=mass2new; t(n)=n*dt; end %% Output fprintf('The final temperature = %7.3f R\n',T2) fprintf('The mass of air in tank = %7.3f lb\n',mass2new) fprintf('The time required to pressurize the tank = %7.3f s\n',t(n)) figure(1) plot(t,T,'g','Linewidth',2) grid ylabel('Temperature (R)') xlabel('Time (s)') title('Time Vs Temperature') figure(2) plot(t,P,'b','Linewidth',2) grid xlabel('Time (s)') ylabel('Pressure (psi)') title('Time Vs Pressure') figure(3) plot(t,m,'r','Linewidth',2) grid xlabel('Time (s)') ylabel('Mass (lb)') title('Time Vs Mass')
 Did you try a hand calculation on either side of 8 seconds and then have your program print the results for the same time period. You might be able to find the error that way.
 I am currently hand calculating the first two iterations, just to see if the values I calculate match what the program is outputting for the first two iterations.

 Similar discussions for: Thermodynamic filling of tank. (matlab) Thread Forum Replies Math & Science Software 0 Calculus & Beyond Homework 2 Precalculus Mathematics Homework 2 Classical Physics 5 Calculus & Beyond Homework 18