You are on page 1of 6

#include<stdio.

h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

float steamtablevalues(int c,float x)


{

float P[7] = {700,750,800,850,900,950,1000};int flag = 0,i=0, j;

float Ul[7] = {696.33,708.475,720.02,731.065,741.61,751.755,761.5};

float Uv[7] = {2570.9,2573.75,2576,2575.35,2578.5,2580.2,2582};

float Vl[7] = {0.0011,0.0011,0.0011,0.0011,0.0011,0.0011,0.0011};

float Vv[7] = {0.273,0.255,0.24,0.229,0.215,0.204,0.194};

float Hl[7] = {697.1,709.3,720.9,732,742.6,752.8,762.6};

float Hv[7] = {2762,2765,2768,2770,2772,2774,2776};

float x1,x2,y1,y2,z1,z2; int pos;

for(i=0; i<7; i++)

{
if(P[i] == x)
{ flag = 1;pos = i;
break;
}
}

if(flag == 1)
{

if(c == 21)
{
//printf("check1 %.6f \n",Vl[i]);
return Vl[i];
}

if(c == 22)
{
//printf("check1 %.6f \n" ,Vv[i]);

return Vv[i];
}

if(c == 11)
{
//printf("check1 %.6f \n",Ul[i]);
return Ul[i];
}
if(c == 12)
{
//printf("check1 %.6f \n" ,Uv[i]);
return Uv[i];
}

if(c == 32)
{
//printf("check1 %.6f \n" ,Hv[i]);

return Hv[i];
}

if(c == 31)
{
//printf("check1 %.6f \n" ,Hl[i]);

return Hl[i];
}
}

for(float q = 700; q<=1000; q+=50)


{
//printf("q = %f \n",q);

if((x>q) && x<(q+50))


{
j =( ( ( (q+50) - 700 ) / 50 ) - 1 ) ;

if(c == 21)
{

x1 = Vl[j] + ( (x - P[j])*(Vl[j+1] - Vl[j]) )/


(P[j+1] - P[j]);

if(x == 903)

{
//printf("q = %f j = %d vl[j] = %f x = %f P[j] =
%f Vl[j+1] = %f P[j+1] = %f P[j] = %f x1 = %f\
n" ,q,j,Vl[j],x,P[j],Vl[j+1],P[j+1],P[j],x1);
//printf("X1 = %f \n",x1);

}
return x1;
}

if(c == 22)
{

x2 = Vv[j] + ( (x - P[j])*(Vv[j+1] - Vv[j]) )/ (P[j+1] -


P[j]);

if(x == 903)

{
//printf("q = %f j = %d vv[j] = %f x =
%f P[j] = %f Vv[j+1] = %f P[j+1] = %f P[j] = %f \
n" ,q,j,Vv[j],x,P[j],Vv[j+1],P[j+1],P[j]);
//printf("X2 = %f \n",x2);
}

return x2;
}

if(c == 31)
{

y1 = Hl[j] + ( (x - P[j])*(Hl[j+1] - Hl[j]) )/ (P[j+1] -


P[j]);

return y1;
}

if(c == 32)

{
y2 = Hv[j] + ( (x - P[j])*(Hv[j+1] - Hv[j]) )/ (P[j+1] -
P[j]);
return y2;
}

if(c == 11)

{
z1 = Ul[j] + ( (x - P[j])*(Ul[j+1] - Ul[j]) )/
(P[j+1] - P[j]);

if(x == 903)

{
//printf("q = %f j = %d Ul[j] = %f x =
%f P[j] = %f Ul[j+1] = %f P[j+1] = %f P[j] = %f \
n" ,q,j,Ul[j],x,P[j],Ul[j+1],P[j+1],P[j]);
//printf("z1 = %f \n",z1);

return z1;
}

if(c == 12)
{
z2 = Uv[j] + ( (x - P[j])*(Uv[j+1] - Uv[j]) )/
(P[j+1] - P[j]);

if(x == 903)

{
//printf("q = %f j = %d Uv[j] = %f x =
%f P[j] = %f Uv[j+1] = %f P[j+1] = %f P[j] = %f \
n" ,q,j,Uv[j],x,P[j],Uv[j+1],P[j+1],P[j]);
//printf("z2 = %f \n",z2);

return z2;
}

}
}

void main()

{
FILE *fptr;

float c1,c2,c3,c4,c5,c6,c7,c8,num;int k=0;float e[8];

fptr = fopen("thermo","w");

if(fptr == NULL)
{
printf("file does not exist \n");

return ;
}
printf("Enter parameter for P1 P2 m1dot m2dot deltat pi alphai alphaf\n\n");

for(int q=0; q<8; q++)


scanf("%f",&e[q]);

//scanf("%f %f %f %f %f %f %f %f",&c1,&c2,&c3,&c4,&c5,&c6,&c7,&c8);

putw(e[0],fptr); putw(e[1],fptr); putw(e[2],fptr); putw(e[3],fptr);


putw(e[4],fptr); putw(e[5],fptr),putw(e[6],fptr), putw(e[7],fptr);

//fprintf(fptr,"P1 = %f P2 = %f m1dot = %f m2dot = %f deltat = %f Pi = %f


alphai = %f alphaf = %f \n",c1,c2,c3,c4,c5,c6,c7,c8);

fclose(fptr);

//fptr = fopen("thermo", "r");

fptr = fopen("thermo", "r");

//while(fscanf(fptr,"%f",&e[k]) )
// k++;
//fclose(fptr);

//e[i] = '\0';

//for(int p = 0; p<8 ;p++)


//printf("%f ",e[p]);

float P1=e[0], P2=e[1], m1dot=e[2], m2dot=e[3], deltat=e[4], Pi=e[5],


alphai=e[6], alphaf=e[7];char Vl, Vv;

if( (P1>=800) && (P1<=1000) && (P2>=700) && (P2<=750) )


{

float req_pf=0,reqg1_pfaf,req_m1,req_m2,assumed_mean;

float g1_piai = alphai/steamtablevalues(21,Pi) +


(1-alphai)/steamtablevalues(22,Pi);

printf("g1(piai) = %f \n\n",g1_piai);

float g2_piai = (alphai/steamtablevalues(21,Pi))*steamtablevalues(11,Pi) +


((1-alphai)/steamtablevalues(22,Pi))*steamtablevalues(12,Pi);

printf("g2(piai) = %f \n\n",g2_piai);

float a = (m1dot - m2dot)*deltat;

float b = (m1dot*steamtablevalues(32,P1) -
m2dot*steamtablevalues(32,P2))*deltat;

printf("a = %f\n\n",a);

printf("b = %f\n\n",b);

for(float Pf=P2; Pf<=P1; Pf++)

{ //printf("Pf = %f \n",Pf);

float g1_pfaf = ( alphaf/steamtablevalues(21,Pf) ) + (


(1-alphaf)/steamtablevalues(22,Pf) );

//printf("Pf = %f check 1 = %.5f check 2 = %.5f g1_pfaf = %f \n\


n",Pf,steamtablevalues(21,Pf),steamtablevalues(22,Pf),g1_pfaf);

float g2_pfaf =
(alphaf/steamtablevalues(21,Pf))*steamtablevalues(11,Pf) +
((1-alphaf)/steamtablevalues(22,Pf))*steamtablevalues(12,Pf);

float m1 = a*g2_piai - b*g1_piai;

float m2 = a*g2_pfaf - b*g1_pfaf;

if(Pf == 700)
{
assumed_mean = fabs(fabs(m2) - fabs(m1));
//printf("assumed mean = %f a = %f b = %f \n",
assumed_mean,fabs(m1),fabs(m2));

if( fabs(fabs(m2) - fabs(m1) ) < assumed_mean )


{
req_pf = Pf;

reqg1_pfaf = g1_pfaf;

req_m1 = m1;

req_m2 = m2;
//printf("diff = %f pf = %f \n",fabs(fabs(m2) -
fabs(m1)),Pf);

assumed_mean = fabs(fabs(m2) - fabs(m1));


}

//printf("pf = %f m1 = %.6f m2 = %.6f \n",Pf,m1,m2);

//float c1 = (g2_pfaf - g2_piai);

//printf(" Pf = g1_pfaf = g2_pfaf = ) %.7f %.7f %.7f\


n",Pf,g1_pfaf,g2_pfaf);

//float c2 = (g1_pfaf - g1_piai);

//printf(" g1(piai) = %f \n",g1_piai);


//if( (c1/c2) == (b/a) )
//{
//req_pf = Pf;
//break;

//}

if(fabs ( fabs(req_m1) - fabs(req_m2) ) < 100000 )


{

printf("Pf = %f\n\n",req_pf);

float vacc = ( a / (reqg1_pfaf - g1_piai ) );

printf("Vacc = %f\n\n",vacc);

else

printf("No physically valid solution obtained. Final accumulator pressure


needs to be greater than %f\n",(P1-50));

else

printf("Constraints on Boiler and plant pressure not satisfied\n");

You might also like