matplotlib

Table Of Contents

Previous topic

Example Code for C#

Next topic

Example Code for Python

This Page

Example Code for Java

Code

// Example for Java
// Ian Bell, 2013

public class Example {
    static {
        System.loadLibrary("CoolProp");
    }
    
    public static void main(String argv[]){
        
        double T, h, p, D;
        int SI,KSI;
        System.out.println("CoolProp version: " + CoolProp.get_global_param_string("version"));
        System.out.println("CoolProp gitrevision: " + CoolProp.get_global_param_string("gitrevision"));
        System.out.println("CoolProp fluids: " + CoolProp.get_global_param_string("FluidsList"));

        System.out.println(" ");
        System.out.println("************ USING EOS *************");
        System.out.println(" ");
        System.out.println("FLUID STATE INDEPENDENT INPUTS");
        System.out.println("Critical Density Propane: " + CoolProp.Props1("Propane", "rhocrit") + "kg/m^3");
        System.out.println("TWO PHASE INPUTS (Pressure)");
        System.out.println("Density of saturated liquid Propane at 101325 kPa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3");
        System.out.println("Density of saturated vapor R290 at 101325 kPa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3");
        System.out.println("TWO PHASE INPUTS (Temperature)");
        System.out.println("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3");
        System.out.println("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3");
        System.out.println("SINGLE PHASE CYCLE (propane)");
        p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
        h = CoolProp.PropsSI("H", "T", 300, "D", 1, "Propane");
        System.out.println("T,D -> P,H " + 300 + "," + 1 + " --> " + p + "," + h);
        T = CoolProp.PropsSI("T", "P", p, "H", h, "Propane");
        D = CoolProp.PropsSI("D", "P", p, "H", h, "Propane");
        System.out.println("P,H -> T,D " + p + "," + h + " --> " + T + "," + D);

        System.out.println(" ");
        System.out.println("************ USING TTSE ***************");
        System.out.println(" ");
        CoolProp.enable_TTSE_LUT("Propane");
        System.out.println("TWO PHASE INPUTS (Pressure)");
        System.out.println("Density of saturated liquid Propane at 101325 kPa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3");
        System.out.println("Density of saturated vapor R290 at 101325 kPa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3");
        System.out.println("TWO PHASE INPUTS (Temperature)");
        System.out.println("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3");
        System.out.println("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3");
        System.out.println("SINGLE PHASE CYCLE (propane)");
        p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
        h = CoolProp.PropsSI("H", "T", 300, "D", 1, "Propane");
        System.out.println("T,D -> P,H " + 300 + ","+ 1+ " --> " + p + "," + h);
        T = CoolProp.PropsSI("T", "P", p, "H", h, "Propane");
        D = CoolProp.PropsSI("D", "P", p, "H", h, "Propane");
        System.out.println("P,H -> T,D " + p + "," + h + " --> " + T + "," + D);
        CoolProp.disable_TTSE_LUT("Propane");

        try
        {
            System.out.println(" ");
            System.out.println("************ USING REFPROP ***************");
            System.out.println(" ");
            System.out.println("TWO PHASE INPUTS (Pressure)");
            System.out.println("Density of saturated liquid Propane at 101325 kPa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3");
            System.out.println("Density of saturated vapor R290 at 101325 kPa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3");
            System.out.println("TWO PHASE INPUTS (Temperature)");
            System.out.println("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3");
            System.out.println("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3");
            System.out.println("SINGLE PHASE CYCLE (propane)");
            p = CoolProp.PropsSI("P","T",300,"D",1,"Propane"); 
            h = CoolProp.PropsSI("H","T",300,"D",1,"Propane");
            System.out.println("T,D -> P,H " + 300 + "," + 1 + " --> " + p + "," + h);
            T = CoolProp.PropsSI("T","P",p,"H",h,"Propane"); 
            D = CoolProp.PropsSI("D","P",p,"H",h,"Propane");
            System.out.println("P,H -> T,D " + p + "," + h + " --> " + T + "," + D);
        }
        catch(Exception e)
        {
            System.out.println(" ");
            System.out.println("************ CANT USE REFPROP ************");
            System.out.println(" ");
        }

        System.out.println(" ");
        System.out.println("************ BRINES AND SECONDARY WORKING FLUIDS *************");
        System.out.println(" ");
        System.out.println("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 kPa: " + CoolProp.PropsSI("D", "T", 300, "P", 101325, "EG-50%") + "kg/m^3");
        System.out.println("Viscosity of Therminol D12 at 350 K, 101325 kPa: " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "TD12") + "Pa-s");

        System.out.println(" ");
        System.out.println("************ HUMID AIR PROPERTIES *************");
        System.out.println(" ");
        System.out.println("Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa: " + CoolProp.HAProps("W", "T", 300, "P", 101.325, "R", 0.5) + " kg_w/kg_da");
        System.out.println("Relative humidity from last calculation: " + CoolProp.HAProps("R", "T", 300, "P", 101.325, "W", CoolProp.HAProps("W", "T", 300, "P", 101.325, "R", 0.5)) + "(fractional)");
    }
}

Output

CoolProp version: 4.2.5
CoolProp gitrevision: b'7fd51d2f3821338fb4c27d2cd1ffad52d3efc23e'
CoolProp fluids: Water,R134a,Helium,Oxygen,Hydrogen,ParaHydrogen,OrthoHydrogen,Argon,CarbonDioxide,Nitrogen,n-Propane,Ammonia,R1234yf,R1234ze(E),R32,R22,SES36,Ethylene,SulfurHexafluoride,Ethanol,DimethylEther,DimethylCarbonate,R143a,R23,n-Dodecane,Propylene,Cyclopentane,R236FA,R236EA,R227EA,R365MFC,R161,HFE143m,Benzene,n-Undecane,R125,CycloPropane,Neon,R124,Propyne,Fluorine,Methanol,RC318,R21,R114,R13,R14,R12,R113,R1234ze(Z),R1233zd(E),AceticAcid,R245fa,R41,CarbonMonoxide,CarbonylSulfide,n-Decane,HydrogenSulfide,Isopentane,Neopentane,Isohexane,Krypton,n-Nonane,Toluene,Xenon,R116,Acetone,NitrousOxide,SulfurDioxide,R141b,R142b,R218,Methane,Ethane,n-Butane,IsoButane,n-Pentane,n-Hexane,n-Heptane,n-Octane,CycloHexane,R152A,R123,R11,MDM,MD2M,MD3M,D6,MM,MD4M,D4,D5,1-Butene,IsoButene,cis-2-Butene,trans-2-Butene,MethylPalmitate,MethylStearate,MethylOleate,MethylLinoleate,MethylLinolenate,o-Xylene,m-Xylene,p-Xylene,EthylBenzene,Deuterium,ParaDeuterium,OrthoDeuterium,Air,R404A,R410A,R407C,R507A,R407F
 
************ USING EOS *************
 
FLUID STATE INDEPENDENT INPUTS
Critical Density Propane: 220.4781kg/m^3
TWO PHASE INPUTS (Pressure)
Density of saturated liquid Propane at 101325 kPa: 580.8829519548199 kg/m^3
Density of saturated vapor R290 at 101325 kPa: 2.416136008788165 kg/m^3
TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.4473752519588 kg/m^3
Density of saturated vapor R290 at 300 K: 21.629532018462186 kg/m^3
SINGLE PHASE CYCLE (propane)
T,D -> P,H 300,1 --> 56072.76274829289,634733.6259284773
P,H -> T,D 56072.76274829289,634733.6259284773 --> 300.00000000000017,0.9999999999999992
 
************ USING TTSE ***************
 
TWO PHASE INPUTS (Pressure)
0.203 to build both two phase tables
Density of saturated liquid Propane at 101325 kPa: 580.8936995566997 kg/m^3
Density of saturated vapor R290 at 101325 kPa: 2.416296228381877 kg/m^3
TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.44737744117043 kg/m^3
Density of saturated vapor R290 at 300 K: 21.629531877303968 kg/m^3
SINGLE PHASE CYCLE (propane)
T,D -> P,H 300,1 --> 56072.76440582185,634733.625854333
P,H -> T,D 56072.76440582185,634733.625854333 --> 299.99999990675275,0.9999999797332718
 
************ USING REFPROP ***************
 
TWO PHASE INPUTS (Pressure)
Density of saturated liquid Propane at 101325 kPa: 580.8829519548199 kg/m^3
Density of saturated vapor R290 at 101325 kPa: 2.416136008788165 kg/m^3
TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.4473752519588 kg/m^3
Density of saturated vapor R290 at 300 K: 21.629532018462186 kg/m^3
SINGLE PHASE CYCLE (propane)
T,D -> P,H 300,1 --> 56072.76274829289,634733.6259284773
P,H -> T,D 56072.76274829289,634733.6259284773 --> 300.00000000000017,0.9999999999999992
 
************ BRINES AND SECONDARY WORKING FLUIDS *************
 
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 kPa: 1061.1793077204613kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 kPa: 5.228849410507948E-4Pa-s
 
************ HUMID AIR PROPERTIES *************
 
Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa: 0.011096223750095191 kg_w/kg_da
Relative humidity from last calculation: 0.49999999999999994(fractional)