public class carnot
{
// a steam ideal carnot cycle
// steam b=new steam();
// double a[]=b.property("tp",30.0,1.01325);
// girdi parametreleri
// termodinamik set "tv" "tp" "th" "tu" "ts"tx"
//                  "pv" "pt" "ph" "pu" "ps" "px"
// çıkış parametreleri(a) 
// a[0]=P a[1]=T a[2]=V a[3]=h
// a[4]u a[5]=s a[6]=x
double T[];
double P[];
double h[];
double s[];
double x[];
double etait,etaip;
double etacevrim,etacevrim1,etaisi,etatoplam;
double m;//kg/s
double Wt,Wp,W;//iş
double Qkazan,Qyogusturucu;
steam b;
double c1[][];
double c3[][];
public carnot(double mi,double P1, double P2)
{
m=mi;
b=new steam();
T=new double[9];
P=new double[9];
h=new double[9];
s=new double[9];
x=new double[9];

P[1]=P1;//turbine inlet
P[2]=P2;//turbine outlet
c1=new double[2][20];
c3=new double[2][20];
} 
public void cycle()
{
// Turbine input
double a1[]=b.property("px",P[1],1.0);
h[1]=a1[3];
s[1]=a1[5];
T[1]=a1[1];
// isentropik turbine output
s[2]=s[1];
P[2]=P[2];
double a2[]=b.property("ps",P[2],s[2]);
T[2]=a2[1];
h[2]=a2[3];
//compressor output
P[4]=P[1];
double a4[]=b.property("px",P[4],0.0);
h[4]=a4[3];
s[4]=a4[5];
T[4]=a4[1];
// condenser output
P[3]=P[2];
s[3]=s[4];
double a3[]=b.property("ps",P[3],s[3]);
h[3]=a3[3];
s[3]=a3[5];
T[3]=a3[1];
P[3]=P[4];
x[3]=a3[6];


// isentropik pompa
Wt=m*(h[1]-h[2]);
Wp=m*(h[4]-h[3]);
W=Wt-Wp;
Qkazan=m*(h[1]-h[4]);
Qyogusturucu=m*(h[2]-h[3]);
etacevrim=W/Qkazan;
etacevrim1=1.0-(T[2]+273.15)/(T[1]+273.15);
etaisi=Qyogusturucu/Qkazan;
etatoplam=etacevrim+etaisi;
}

public String toString()
{
cycle();
String ss="steam carnot cycle\n";
ss+=" cycle efficiency by using eta=1-Tlow/Thigh = "+etacevrim1+"\n";
ss+=" cycle efficiency    = " + etacevrim+"\n";
ss+=" heat energy utilisation rate = "+etaisi+"\n";
ss+=" total heat+power efficiency = "+etatoplam+"\n";
ss+=" Turbine power output    = " + Wt+" kW\n";
ss+=" Net power output    = " + W +" kW\n";
ss+=" Boiler heat input = " + Qkazan +" kW\n";
ss+=" Condenser heat  = "+Qyogusturucu +" kW\n";
ss+=" h1 turbine input = "+h[1] +" kJ/kg\n";
ss+=" T1 turbine input = "+T[1] +" derece C\n";
ss+=" P1 turbine input = "+P[1] +" bar \n";
ss+=" s1 turbine input = "+s[1] +" kJ/kgK\n";
ss+=" x1 turbine input = "+x[1] +" kgvapor/kgtotal"+"\n";
ss+=" T2 turbine output = "+T[3] +" derece C\n";
ss+=" P2 turbine output = "+P[3] +" bar \n";
ss+=" s2 turbine output = "+s[2] +" kJ/kgK\n";
ss+=" x2 turbine output = "+x[2] +" kgvapor/kgtotal"+"\n";
ss+=" h3 condenser output = "+h[3] +" kJ/kg\n";
ss+=" T3 condenser output = "+T[3] +" derece C\n";
ss+=" P3 condenser output = "+P[3] +" bar \n";
ss+=" s3 condenser output = "+s[3] +" kJ/kgK\n";
ss+=" x3 condenser output = "+x[3] +" kgvapor/kgtotal"+"\n";
ss+=" h4 pump output = "+h[4] +" kJ/kg\n";
ss+=" T4 pump output = "+T[4] +" derece C\n";
ss+=" s4 pump output = "+s[4] +" kJ/kgK\n";
ss+=" x4 pump output = "+x[4] +" kgvapor/kgtotal"+"\n";
return ss;
}
public double[][] TS1()
{
double a[][]=Text.readDoubleT("steam.txt");
return a;
}	
	
public double[][] TS()
{
double a[][]=new double[2][201];
double tc=b.Tc-273.15;
double dt=(tc-10.0)/100.0;
int i=0;
double t;
for(t=10.0;t<=tc;t+=dt)
{double a1[]=b.property("tx",t,0.0);
 a[1][i]=t;
 a[0][i]=a1[5];
 i++;
}
double a3[]=b.property("tx",tc,1.0);
 a[1][i]=t;
 a[0][i]=a3[5];
 i++;
for(t=tc;t>=10;t-=dt)
{double a2[]=b.property("tx",t,1.0);
 a[1][i]=t;
 a[0][i]=a2[5];
 i++;
}
return a;	
}

public void plot()
{
 Plot pp=new Plot(TS1());
 double t1[]={T[1],T[2],T[3],T[4],T[1]};
 double s1[]={s[1],s[2],s[3],s[4],s[1]};
 pp.setPlabel("Ideal Carnot steam Cycle");
 pp.setYlabel("T, degree C");
 pp.setXlabel("s entropy kJ/kgK");
 pp.addData(s1,t1);
 pp.plot();
}
}