public class rankine1
{
// steam sınıfını kullanır
// çağrı
// 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[
double v[];
double T[];
double P[];
double h[];
double s[];
double x[];
double etait,etaip;
double etacevrim,etaisi,etatoplam;
double m;//kg/s
double Wt,Wp,W;//iş
double Qkazan,Qyogusturucu;
steam b;
double c1[][];
double c3[][];
public rankine1(double mi,double t1,double P1, double P2, double etaiti, double etaipi)
{
m=mi;
b=new steam();
T=new double[7];
P=new double[7];
v=new double[7];
h=new double[7];
s=new double[7];
x=new double[7];
T[1]=t1;//türbin girişi
P[1]=P1;
P[2]=P2;//türbin çıkış basıncı
etait=etaiti;//türbin isentropik verimi
etaip=etaipi;//pompa isentropik verimi
c1=new double[2][40];
c3=new double[2][40];
} 
public void cevrimhesabi()
{
// Türbin girişi
double a1[]=b.property("tp",T[1],P[1]);
h[1]=a1[3];
s[1]=a1[5];
// isentropik Türbin çıkışı
s[0]=s[1];
P[0]=P[2];
double a0[]=b.property("ps",P[0],s[0]);
T[0]=a0[1];
h[0]=a0[3];
// gerçek türbin çıkışı
h[2]=h[1]-etait*(h[1]-h[0]);
double a2[]=b.property("ph",P[2],h[2]);
T[2]=a2[1];
x[2]=a2[6];
s[2]=a2[5];
// yoğuşturucu çıkışı
P[3]=P[2];
x[3]=0.0;
double a3[]=b.property("px",P[3],x[3]);
v[3]=a3[2];
T[3]=a3[1];	
h[3]=a3[3];
s[3]=a3[5];


// isentropik pompa
P[5]=P[1];
s[5]=s[3];
double a5[]=b.property("ps",P[5],s[5]);
h[5]=a5[3];
s[5]=a5[5];
double dh=v[3]*(P[5]-P[3])*1e2;
double dh1=h[5]-h[3];
System.out.println("dh="+dh+"dh1="+dh1);
// gerçek pompa
h[4]=h[3]+(h[5]-h[3])/etaip;
P[4]=P[1];
double a4[]=b.property("ph",P[4],h[4]);
T[4]=a4[1];
s[4]=a4[5];
// yoğuşturucu kızgın buhar bölgesi çıkışı
P[6]=P[2];
x[6]=1.0;
double a6[]=b.property("px",P[6],x[6]);
T[6]=a6[1];
s[6]=a6[5];

if(s[2]>s[6])
{double dt1=(T[1]-T[4])/39;
double t=T[4];
for(int i=0;i<40;i++)
{double b8[]=b.property("tp",t,P[1]);
c3[0][i]=b8[5];c3[1][i]=t;t+=dt1;
}
}

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;
etaisi=Qyogusturucu/Qkazan;
etatoplam=etacevrim+etaisi;
}

public String cikti()
{
cevrimhesabi();
String s="Simple Rankine cycle\n";
s+=" cycle efficiency    = " + etacevrim+"\n";
s+=" heat energy utilisation rate = "+etaisi+"\n";
s+=" total heat+power efficiency = "+etatoplam+"\n";
s+=" Turbine power output    = " + Wt+" kW\n";
s+=" Pump power input    = " + Wp+" kW\n";	
s+=" Net power output    = " + W +" kW\n";
s+=" Boiler heat input = " + Qkazan +" kW\n";
s+=" Condenser heat  = "+Qyogusturucu +" kW\n";
s+=" h1 turbine input = "+h[1] +" kJ/kg\n";
s+=" T1 turbine input = "+T[1] +" derece C\n";
s+=" P1 turbine input = "+P[1] +" bar \n";
s+=" h2 turbine output = "+h[2] +" kJ/kg\n";
s+=" T2 turbine output = "+T[3] +" derece C\n";
s+=" P2 turbine output = "+P[3] +" bar \n";
s+=" h3 condenser output = "+h[3] +" kJ/kg\n";
s+=" T3 condenser output = "+T[3] +" derece C\n";
s+=" P3 condenser output = "+P[3] +" bar \n";
s+=" h4 pump output = "+h[4] +" kJ/kg\n";
s+=" T4 pump output = "+T[4] +" derece C\n";
s+=" P4 pump output = "+P[4] +" bar \n";
return s;
}

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 double[][] line1(double T1,double T2,double Pi,int n)
{
double TT1[]=new double[n];
double ss1[]=new double[n];
double aa[];
aa=b.property("tp",T1,Pi);
double v1=aa[2];
aa=b.property("tp",T2,Pi);
double v2=aa[2];
double v;
for(int i=0;i<n;i++)
{v=v1+i*(v2-v1)/(n-1);
 aa=b.property("pv",Pi,v);
 ss1[i]=aa[5];
 TT1[i]=aa[1];
}
double a[][]={ss1,TT1};
return a;
}
public double[][] line(double T1,double T2,double Pi,int n)
{
double TT1[]=new double[n];
double ss1[]=new double[n];
double aa[];
for(int i=0;i<n;i++)
{TT1[i]=T1+i*(T2-T1)/(n-1);
 aa=b.property("tp",TT1[i],Pi);
 ss1[i]=aa[5];
}
double a[][]={ss1,TT1};
return a;
}

public void plot()
{
 Plot pp=new Plot(TS1());
 double t1[]={T[1],T[2],T[6],T[3],T[4]};
 double s1[]={s[1],s[2],s[6],s[3],s[4]};

 pp.addData(s1,t1);
 double a[][]=line(T[4],T[1],P[1],30);
 Text.printT(a);
 pp.addData(a[0],a[1]);
 //pp.addData(s2,t2);
 //pp.addData(c3[0],c3[1]);

 pp.setPlabel("Rankine Cycle");
 pp.setYlabel("T, degree C");
 pp.setXlabel("s entropy kJ/kgK");
 pp.plot();
}

}