//
/***************************************************************************/
/* Emptying process of a gas from a tank at elevated pressure tank */
/***************************************************************************/
#include "StdAfx.h"
#include
#include
#include
#include
#include // for exit function
using namespace std;
//R is the gas constant of gas in kJ/kg K
//m is the mass in the tank in kg
//K is cp/cv of the gas
//P is the pressure of the gas in the tank in kPa
//Pe is the pressure of the exiting gas kPa
//T is the temperature of the gas in the tank in K at time t
//Tdelt is the temperature of the gas in the tank in K at time delt (t + delta t)
//delT is the temperature increment in the tank in K
//Te is the temperature of the exiting gas
//CD is the coefficient of flow across the orfice
//D is the diameter of the orfice in m
//V is the tank volume in m3
//C1is a parameter in the flow equations
//CRIT is the critical flow presssure ratio
//mflow is the mass rate of flow of the gas in kg/s
//t is the time in s
//delt is the time increment in s
//mark is a marker for critical flow
int main()
{
ofstream outfile;
outfile.open("C:\\Users\\Owner\\Desktop\\outflow.txt");
//initialize variables
float R, K, P, Pe, T, delT, Te, CD, V, m, D, A, t, delt, sqrtK, C1, CRIT, mflow;
int mark;
R = 0.2865;
K = 1.4;
P = 600.0;
Pe = 100.0;
T = 293.0;
CD = 1.0;
V = 0.85;
D = 0.01;
A = 3.14*D*D/4;
t = 0.0;
delt = 1;
mark = 1;
m = (P*V)/(R*T);
sqrtK = sqrt(K);
//unit conversion - 31.6 equals sqrt(1000)
C1 = CD*A*P*31.6/sqrt(R*T);
CRIT = pow(2/(K+1),K/(K-1));
do
{
// when K=1.4 CRIT=0.528
if ((Pe/P) <= CRIT)
{
// Choked Flow
mflow = C1*sqrt(K)*pow((2/(K+1)),(K+1)/(2*(K-1)));
Te = 2/(K+1)*T;
}
else
{
// Normal Compressible Flow
mark = 0;
mflow = C1*pow((Pe/P),1/K)*sqrt((2*K/(K-1))*(1-pow((Pe/P),(K-1)/K)));
Te = T*pow(Pe/P,(K-1)/K);
}
cout
<< setw(10) << setprecision(6) << mark
<< setw(10) << setprecision(6) << t
<< setw(10) << setprecision(6) << T
<< setw(10) << setprecision(6) << P
<< setw(10) << setprecision(6) << m
<< setw(10) << setprecision(6) << mflow
<< setw(10) << setprecision(6) << Te
<= Pe );
//exit program
char stop;
cout<<" Enter q to quit program."<> stop;
if(stop=='q');
cout<