public class ref_cycle5
{
// a R134 ideal refrigeration  cycle
// refrigerantEN b=new refrigerantEN("R134a");
// double a[]=b.property("tp",30.0,1.01325);
///---- String s values and meanings --------
//    tv=temperature-specific volume 
//    tp=temperature-pressure 
//    th=temperature-enthalpy
//    tu=temperature-internal energy
//    ts=temperature-entropy
//    tx=temperature quality
//    pv=pressure-specific volume
//    pt=pressure-temperature
//    ph=pressure-enthapy
//    pu=pressure-internal energy
//    ps=pressure-entropy
//    px=pressure-quality
//    vp=specific volume-pressure
//    vt=specific volume-temperature
//---- output values (method property) ---------
// r[0] P Pressure kPa
// r[1] t temperature degree C
// r[2] v specific volume m^3/kg
// r[3] h enthapy KJ/kg 
// r[4] u internal energy KJ/kg
// r[5] s entropy KJ/kgK
// r[6] x quality kg vapour/kg total
// r[7] ro density kg/m^3

double T[];
double P[];
double h[];
double s[];
double x[];
double v[];
double xx;//quality at liquid separator inlet
boolean supercritical=false;
String refname; //refrigerant name
double Tc,Pc;
double n;
double COP_condenser,COP_evaporator;
double m;//kg/s mass flow rate of refrigerant
double mliquid;//liquid extraction rate
double Wc;//net compressor work
double Qcompressor;
double Qintercooler;
double Qheatexchanger;
double Qevaporator,Qcondenser; //condenser and evaporator heat transfer
refrigerantEN b; //refrigerantEN class object for properties
public ref_cycle5(String refnamei,double mi,double P4,double P1,double T5,double T6,double xi,double ni)
{
m=mi;
n=ni;
xx=xi;
refname=refnamei;    // refrigerant name
b=new refrigerantEN(refname);
T=new double[14];
P=new double[14];
h=new double[14];
s=new double[14];
x=new double[14];
v=new double[14];
Tc=b.r.Tc;//critical temperature degree C
Pc=b.r.Pc;//critical pressure kPa
P[3]=P4;
P[4]=P4;
P[8]=P4;
P[6]=P4;
P[5]=P4;
P[7]=P4;
P[1]=P1;
P[2]=P1;
P[9]=P1;//point x
T[5]=T5;
T[6]=T6;
} 

public void cycle()
{
// separator saturation point 3 x=0
double a1[]=b.property("px",P[3],0.0);
T[3]=a1[1];
h[3]=a1[3];
s[3]=a1[5];
x[3]=a1[6];
v[3]=a1[2];
// separator saturation point 4 x=0
a1=b.property("px",P[4],1.0);
T[4]=a1[1];
h[4]=a1[3];
s[4]=a1[5];
x[4]=a1[6];
v[4]=a1[2];
// 8=a separator inlet point
a1=b.property("px",P[4],xx);
T[8]=a1[1];
h[8]=a1[3];
s[8]=a1[5];
x[8]=a1[6];
v[8]=a1[2];
// 2 heat exchanger exit-expansion inlet
h[2]=h[8];
a1=b.property("ph",P[2],h[2]);
T[2]=a1[1];
s[2]=a1[5];
x[2]=a1[6];
v[2]=a1[2];
// separator saturation point 5 x=0
a1=b.property("tp",T[5],P[5]);
h[5]=a1[3];
s[5]=a1[5];
x[5]=a1[6];
v[5]=a1[2];
// additional gas inlet point 6
a1=b.property("tp",P[6],T[6]);
h[6]=a1[3];
s[6]=a1[5];
x[6]=a1[6];
v[6]=a1[2];
// 9=x intercooler exit
h[9]=xx*(h[5]-h[4])+h[2];
a1=b.property("ph",P[9],h[9]);
T[9]=a1[1];
s[9]=a1[5];
x[9]=a1[6];
v[9]=a1[2];

// multistage compressor inlet point 7
h[7]=(1-xx)*h[6]+xx*h[5];
a1=b.property("ph",P[7],h[7]);
T[7]=a1[1];
h[7]=a1[3];
s[7]=a1[5];
x[7]=a1[6];
v[7]=a1[2];

// multistage compressor exit point 1
v[1]=Math.pow((P[7]/P[1]),(1.0/n))*v[7];
double TT1=P[1]*1e3*v[1]/(8314.5)-273.15;
a1=b.property("pv",P[1],v[1]);
T[1]=a1[1];
h[1]=a1[3];
s[1]=a1[5];
x[1]=a1[6];
v[1]=a1[2];
xx=(h[7]-h[6])/(h[5]-h[6]);
//point 8=a liquid separator inlet
a1=b.property("px",P[8],xx);
T[8]=a1[1];
h[8]=a1[3];
s[8]=a1[5];
x[8]=a1[6];
v[8]=a1[2];
//point 2 Heat exchanger exit
h[2]=h[8];
a1=b.property("ph",P[2],h[2]);
T[2]=a1[1];
h[2]=a1[3];
s[2]=a1[5];
x[2]=a1[6];
v[2]=a1[2];
 // multistage polytropic compressor
Wc=m*n/(n-1)*(P[1]*v[1]-P[7]*v[7]);
Qcompressor=m*(h[1]-h[7]);
Qintercooler=m*(h[1]-h[9]);
Qheatexchanger=m*(h[9]-h[2]);
mliquid=(1.0-xx)*m;//kg/s liquid extraction rate
}

public String toString()
{
cycle();
String ss="gas liquifying plant\n";
ss+="polytropic constant n="+n+"\n";
ss+="liquid extraction rate : "+mliquid+"\n";
ss+=" multistage compressor work = "+Wc+" kW\n";
ss+=" multistage compressor heat transfer = "+Qcompressor+" kW\n";
ss+=" intercooler heat transfer = "+Qintercooler+" kW\n";
ss+=" heat exchanger heat transfer = "+Qheatexchanger+" kW\n";

ss+=" h7 compressor inlet = "+h[7] +" kJ/kg\n";
ss+=" T7 compressor inlet = "+T[7] +" degree C\n";
ss+=" P7 compressor inlet = "+P[7] +" kPa \n";
ss+=" s7 compressor inlet = "+s[7] +" kJ/kgK\n";
ss+=" x7 compressor inlet = "+x[7] +" kgvapor/kgtotal"+"\n";
ss+=" v7 compressor inlet = "+v[7] +" m^3/kg"+"\n";
ss+=" h1 compressor exit = "+h[1] +" kJ/kg\n";
ss+=" T1 compressor exit = "+T[1] +" degree C\n";
ss+=" P1 compressor exit = "+P[1] +" kPa \n";
ss+=" s1 compressor exit = "+s[1] +" kJ/kgK\n";
ss+=" x1 compressor exit = "+x[1] +" kgvapor/kgtotal"+"\n";
ss+=" v1 compressor inlet = "+v[1] +" m^3/kg"+"\n";
ss+=" h6 gas feed = "+h[6] +" kJ/kg\n";
ss+=" T6 gas feed = "+T[6] +" degree C\n";
ss+=" P6 gas feed = "+P[6] +" kPa \n";
ss+=" s6 gas feed = "+s[6] +" kJ/kgK\n";
ss+=" x6 gas feed = "+x[6] +" kgvapor/kgtotal"+"\n";
ss+=" v6 compressor inlet = "+v[6] +" m^3/kg"+"\n";

ss+=" h5 heat exchager exit = "+h[5] +" kJ/kg\n";
ss+=" T5 heat exchager exit = "+T[5] +" degree C\n";
ss+=" P5 heat exchager exit = "+P[5] +" kPa \n";
ss+=" s5 heat exchager exit = "+s[5] +" kJ/kgK\n";
ss+=" x5 heat exchager exit = "+x[5] +" kgvapor/kgtotal"+"\n";
ss+=" v5 compressor inlet = "+v[5] +" m^3/kg"+"\n";

ss+=" h3 liquid separator liquid discharge = "+h[3] +" kJ/kg\n";
ss+=" T3 liquid separator liquid discharge = "+T[3] +" degree C\n";
ss+=" P3 liquid separator liquid discharge = "+P[3] +" kPa \n";
ss+=" s3 liquid separator liquid discharge = "+s[3] +" kJ/kgK\n";
ss+=" x3 liquid separator liquid discharge = "+x[3] +" kgvapor/kgtotal"+"\n";
ss+=" v3 compressor inlet = "+v[3] +" m^3/kg"+"\n";

ss+=" h4 liquid separator gas discharge = "+h[4] +" kJ/kg\n";
ss+=" T4 liquid separator gas discharge = "+T[4] +" degree C\n";
ss+=" P4 liquid separator gas discharge = "+P[4] +" kPa \n";
ss+=" s4 liquid separator gas discharge = "+s[4] +" kJ/kgK\n";
ss+=" x4 liquid separator gas discharge = "+x[4] +" kgvapor/kgtotal"+"\n";
ss+=" v4 compressor inlet = "+v[4] +" m^3/kg"+"\n";

ss+=" h2 expansion valve inlet = "+h[2] +" kJ/kg\n";
ss+=" T2 expansion valve inlet = "+T[2] +" degree C\n";
ss+=" P2 expansion valve inlet = "+P[2] +" kPa \n";
ss+=" s2 expansion valve inlet = "+s[2] +" kJ/kgK\n";
ss+=" x2 expansion valve inlet = "+x[2] +" kgvapor/kgtotal"+"\n";
ss+=" v2 compressor inlet = "+v[2] +" m^3/kg"+"\n";
return ss;
}

}