public class brayton
{
Gas g;
double TT1[],ss1[];
double TT2[],ss2[];
double Wturbin,Wkompresor,Wnet,Q,Qisi,eta,etaisi,etatoplam,T1,P1,T2,P2,T3,P3,T4,P4;
public brayton(double m,double T1,double P1, double P2, double T3,double etakompresor,double etaturbin)
{ TT1=new double[25];ss1=new double[25];
  TT2=new double[2];ss2=new double[2];
g=new Gas("air");
g.mole=false;
// 1 
double P3=P2;
double P4=P1;
double a1[]=g.property(T1,P1);
double h1=a1[3];
double s1=a1[5];
TT1[0]=T1;ss1[0]=s1;
double pr1=a1[17];
// 2i 
double pr2=P2/P1*pr1;
double T2i=g.Ti(pr2,P2);
double a2i[]=g.property(T2i,P2);
double h2i=a2i[3];
double s2i=a2i[5];
TT1[1]=T2i;ss1[1]=s2i;
double Cp2i=a2i[9];
// 2 
double h2=(h2i-h1)/etakompresor+h1;
double T2=(h2-h2i)/Cp2i+T2i;
double a2[]=g.property(T2,P2);
double s2=a2[5];
//3 noktası
double a3[]=g.property(T3,P3);
double h3=a3[3];
double s3=a3[5];
double pr3=a3[17];
double pr4=P1/P2*pr3;
//4i 
double T4i=g.Ti(pr4,P1);
double a4i[]=g.property(T4i,P1);
double h4i=a4i[3];
double s4i=a4i[5];
double Cp4i=a4i[9];
for(int i=0;i<10;i++)
{TT1[i+2]=T2i+i*(T3-T2)/10;
 a3=g.property(TT1[i+2],P3);
 ss1[i+2]=a3[5];
}
TT1[12]=T3;ss1[12]=s3;
TT2[0]=T3;ss2[0]=s3;

//System.out.println("pr3="+g.pr(T3));

TT2[1]=T4i;ss2[1]=s4i;
//System.out.println("t4i="+T4i+"h4i="+h4i+"Cp4i="+Cp4i);
//4 noktası
double h4=h3-etaturbin*(h3-h4i);
double T4=(h4-h4i)/Cp4i+T4i;
double a4[]=g.property(T4,P1);
double s4=a4[5];
for(int i=0;i<10;i++)
{TT1[i+13]=T4-i*(T4-T1)/10;
 a3=g.property(TT1[i+13],P1);
 ss1[i+13]=a3[5];
}
TT1[23]=T1;
ss1[23]=s1;
TT1[24]=T2;
ss1[24]=s2;
System.out.println("t4="+T4+"h4="+h4+"s4="+s4);
System.out.println("t4i="+T4i+"h4i="+h4i+"s4i="+s4i);
//System.out.println("t4="+T4+"h4="+h4+"s4="+s4);
Wturbin=m*(h3-h4);
Wkompresor=m*(h2-h1);
Q=m*(h3-h2);
Qisi=m*(h4-h1);
Wnet=Wturbin-Wkompresor;
eta=Wnet/Q;
etaisi=Qisi/Q;
etatoplam=eta+etaisi;
this.T1=T1;
this.P1=P1;
this.T2=T2;
this.P2=P2;
this.T3=T3;
this.P3=P3;
this.T4=T4;
this.P4=P4;
Plot pp=new Plot(ss1,TT1);
pp.addData(ss2,TT2);
pp.plot();
}
public String toString()
{
String s=" Brayton cycle \n";
s+="Turbine power output W turbine = "+Wturbin+" kW \n";
s+="Compressor power input W kompresor = "+Wkompresor+" kW\n";	
s+="Net power output  Wnet = "+Wnet+" kW\n";
s+="Combustion chamber heat input Q combustion = "+Q+" kW\n";
s+="Evailable exhaust heat energy Q exhaust available = "+Qisi+" kW \n";
s+="Cycle efficiency eta  = "+eta+"\n";
s+="Heat utilisation efficiency eta ısı = "+etaisi+" \n";
s+="Total heat energy utilisation efficiency = "+etatoplam+"\n";
s+="Compressor inlet temperature = "+(T1-273.15)+" degree C\n";
s+="Compressor inlet pressure  = "+P1+" bar\n";
s+="Combustion chamber inlet temperature = "+(T2-273.15)+" degree C\n";
s+="Combustion chamber inlet pressure   = "+P2+" bar\n";
s+="Turbine inlet temperature = "+(T3-273.15)+" degree C\n";
s+="Turbine inlet pressure   = "+P3+" bar\n";
s+="Turbine exit temperature = "+(T4-273.15)+" degree C\n";
s+="Turbine exit pressure   = "+P4+" bar\n";
Text.pribt(bry.
return s;
}

}
