Thermodynamic filling of tank. (matlab)

In summary, the problem involves pressurizing a rigid insulated tank with air from a supply line. The tank starts at 14.7 psia and 80 ºF and is connected to the supply line through a valve. The valve is opened and air flows into the tank until the pressure reaches 75 psia, at which point the valve is closed. The diameter of the connecting pipe is 1 inch. A computer program is needed to model this pressurization process and calculate the final temperature, mass of air in the tank, and time required to pressurize the tank. The program uses equations for pressure, temperature, mass flowrate, and resident mass, and outputs the results in a graph for temperature, pressure, and
  • #1
Juanka
40
0

Homework Statement



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.

Homework Equations



All the relevant equations are labeled in the coding

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')

correct answer should be
Time around 8 seconds
Temperature around 700 Rankine
and I do not know what the mass should be.

my answers are:
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??
 
Physics news on Phys.org
  • #2
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.
 
  • #3
where is Cd in your mass flow rate equation?
 
  • #4
RTW69 said:
where is Cd in your mass flow rate equation?

http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19970032263_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?
 
Last edited by a moderator:
  • #5
i have almost the same problem and i can't solve it ;( please anybody 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?
 
  • #6
Figure 4, Case 3 of the NASA document shows 80 seconds to fill 2 CU.liters. Are you sure your 8 seconds is correct?
 
  • #7
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 P2<P1-.01

    error=1;

       n=n+1;

    while error>0.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')
 
  • #8
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.
 
  • #9
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.
 

Related to Thermodynamic filling of tank. (matlab)

1. What is the purpose of using MATLAB for thermodynamic filling of a tank?

MATLAB is a powerful software tool commonly used in scientific and engineering applications. It allows for efficient and accurate mathematical calculations, making it an ideal choice for simulating and analyzing the thermodynamic filling process of a tank.

2. How does MATLAB assist in the thermodynamic filling process?

MATLAB has built-in functions and tools that can help in modeling and simulating the filling of a tank, such as solving differential equations, plotting graphs, and performing numerical calculations. These features make it easier to understand and analyze the complex thermodynamic processes involved.

3. Are there any limitations to using MATLAB for thermodynamic filling of a tank?

While MATLAB is a powerful tool, it is important to note that it is only as accurate as the inputs and assumptions made by the user. It is essential to carefully consider all the parameters and assumptions used in the simulation to ensure accurate results.

4. Can MATLAB be used to optimize the filling process?

Yes, MATLAB can be used to optimize the thermodynamic filling process by adjusting various parameters and running simulations to find the most efficient and effective filling strategy. This can help to save time and resources in real-world applications.

5. Is MATLAB suitable for beginners in thermodynamics?

MATLAB can be a useful tool for beginners in thermodynamics as it provides a visual representation of the processes and allows for easy manipulation of parameters. However, it is important to have a basic understanding of thermodynamics principles before using MATLAB for simulations and analysis.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
14
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
874
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top