Java Wrapper¶
Pre-compiled Binaries¶
Pre-compiled binaries can be downloaded from Java. Development binaries coming from the buildbot server can be found at Java.
Download the platform-independent.7z
file and expand it to a folder called platform-independent
using 7-zip. Download the special Java shared library for your system architecture to the same location from either Java (release) or Java (development). Copy the Example.java file to the same location. You will need to have a copy of some version of java.
When you are finished, you should have a folder layout something like
main
|- CoolProp.dll
|- Example.java
|- platform-independent
|- AbstractState.java
|- Configuration.java
|- ...
Usage¶
At the console, run:
javac *.java
java Example
There is example code at the end of this page
User-Compiled Binaries¶
Common Requirements¶
Compilation of the Java wrapper requires a few common wrapper pre-requisites
Linux & OSX¶
Download a zip file of the Java Development Kit (JDK) for Java from Oracle downloads. If you are in a 32-bit system, download the 32-bit system, else download the 64-bit version.
Expand the zip file you downloaded
Add the
bin
folder of the JDK that you installed. For instance, add this:export /path/to/java/SDK/bin:$PATH
to
~/.profile
where the path/path/to/java/SDK/bin
points to the absolute path for thebin
folder of your Java installation.
Windows¶
Download and run the JDK installer from Oracle downloads. If you are in a 32-bit system, download the 32-bit system, else download the 64-bit version.
Build¶
Linux and OSX¶
Once the dependencies are installed, you can run the builder and tests using:
# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
mkdir -p CoolProp/build && cd CoolProp/build
# Build the makefile using CMake
cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release
# Make the java files
cmake --build .
# Run the integration tests
ctest --extra-verbose
If you want to change the package that CoolProp resides in, you can do so by changing the cmake call to read:
cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON -DCOOLPROP_SWIG_OPTIONS="-package package.name"
where package.name
is replaced with the desired name
Windows (32-bit and 64-bit)¶
You need to just slightly modify the building procedure:
# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Make a build folder
mkdir build && cd build
# Build the makefile using CMake
cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON
# Make the Java shared library
cmake --build . --config Release (drop the --config Release if you use MinGW)
# Run the integration tests
ctest --extra-verbose
If you want to change the package that CoolProp resides in, you can do so by changing the cmake call to read:
cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON -DCOOLPROP_SWIG_OPTIONS="-package package.name"
where package.name
is replaced with the desired name
Example Code¶
public class Example {
static {
System.loadLibrary("CoolProp");
}
public static void main(String argv[]){
System.out.println("**************** INFORMATION ***************");
System.out.println("This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell");
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"));
// See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface;
System.out.println("*********** HIGH LEVEL INTERFACE *****************");
System.out.println("Critical temperature of water:" + " " + CoolProp.Props1SI("Water", "Tcrit") + " " + "K");
System.out.println("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "Water") + " " + "K");
System.out.println("Phase of water at 101325 Pa and 300 K:" + " " + CoolProp.PhaseSI("P", 101325, "T", 300, "Water"));
System.out.println("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "Water") + " " + "J/kg/K");
System.out.println("c_p of water (using derivatives) at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("d(H)/d(T)|P", "P", 101325, "T", 300, "Water") + " " + "J/kg/K");
System.out.println("*********** HUMID AIR PROPERTIES *****************");
System.out.println("Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:" + " " + CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5) + " " + "kg_w/kg_da");
System.out.println("Relative humidity from last calculation:" + " " + CoolProp.HAPropsSI("R", "T", 300, "P", 101325, "W", CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5)) + " " + "(fractional)");
System.out.println("*********** INCOMPRESSIBLE FLUID AND BRINES *****************");
System.out.println("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:" + " " + CoolProp.PropsSI("D", "T", 300, "P", 101325, "INCOMP::MEG-50%") + " " + "kg/m^3");
System.out.println("Viscosity of Therminol D12 at 350 K, 101325 Pa:" + " " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12") + " " + "Pa-s");
// If you don't have REFPROP installed, disable the following lines;
System.out.println("*********** REFPROP *****************");
System.out.println("REFPROP version:" + " " + CoolProp.get_global_param_string("REFPROP_version"));
System.out.println("Critical temperature of water:" + " " + CoolProp.Props1SI("REFPROP::WATER", "Tcrit") + " " + "K");
System.out.println("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "REFPROP::WATER") + " " + "K");
System.out.println("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "REFPROP::WATER") + " " + "J/kg/K");
System.out.println("*********** TABULAR BACKENDS *****************");
AbstractState TAB = AbstractState.factory("BICUBIC&HEOS", "R245fa");
TAB.update(input_pairs.PT_INPUTS, 101325, 300);
System.out.println("Mass density of refrigerant R245fa at 300 K, 101325 Pa:" + " " + TAB.rhomass() + " " + "kg/m^3");
System.out.println("*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************");
AbstractState AS_SAT = AbstractState.factory("HEOS", "R245fa");
AS_SAT.update(input_pairs.PQ_INPUTS, 101325, 0);
System.out.println("First saturation derivative:" + " " + AS_SAT.first_saturation_deriv(parameters.iP, parameters.iT) + " " + "Pa/K");
System.out.println("*********** LOW-LEVEL INTERFACE *****************");
AbstractState AS = AbstractState.factory("HEOS", "Water&Ethanol");
DoubleVector z = new DoubleVector(); z.add(0.5); z.add(0.5);;
AS.set_mole_fractions(z);
AS.update(input_pairs.PQ_INPUTS, 101325, 1);
System.out.println("Normal boiling point temperature of water and ethanol:" + " " + AS.T() + " " + "K");
// If you don't have REFPROP installed, disable the following block;
System.out.println("*********** LOW-LEVEL INTERFACE (REFPROP) *****************");
AbstractState AS2 = AbstractState.factory("REFPROP", "METHANEÐANE");
DoubleVector z2 = new DoubleVector(); z2.add(0.2); z2.add(0.8);;
AS2.set_mole_fractions(z2);
AS2.update(input_pairs.QT_INPUTS, 1, 120);
System.out.println("Vapor molar density:" + " " + AS2.keyed_output(parameters.iDmolar) + " " + "mol/m^3");
}
}
Example Code Output¶
**************** INFORMATION ***************
This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell
CoolProp version: 6.6.0
CoolProp gitrevision: ba21c74fd1c3a4934bbecbf459936983dec424c2
CoolProp Fluids: n-Nonane,MethylLinolenate,DimethylCarbonate,R21,DiethylEther,trans-2-Butene,R245fa,ParaDeuterium,OrthoDeuterium,Isohexane,R365MFC,n-Dodecane,R410A,Deuterium,D4,R13,MD2M,n-Hexane,Methane,Ethane,CarbonylSulfide,EthylBenzene,CarbonMonoxide,Isopentane,Xenon,cis-2-Butene,R152A,Oxygen,EthyleneOxide,R1234ze(E),n-Octane,R404A,R236EA,CycloHexane,n-Heptane,R22,R113,n-Pentane,MethylLinoleate,R11,SulfurDioxide,R23,Helium,R32,R227EA,R407C,HydrogenSulfide,Air,R245ca,Novec649,R143a,D5,R507A,R134a,Dichloroethane,ParaHydrogen,R1233zd(E),Acetone,n-Decane,HeavyWater,MethylPalmitate,n-Propane,R115,R1234yf,R236FA,Ethylene,R116,MD4M,Benzene,Methanol,SulfurHexafluoride,o-Xylene,R125,Fluorine,R1234ze(Z),CarbonDioxide,IsoButane,n-Butane,NitrousOxide,DimethylEther,RC318,Toluene,IsoButene,MethylStearate,Ammonia,Argon,R218,R41,Neon,Propyne,CycloPropane,R12,Nitrogen,Water,MethylOleate,R161,D6,SES36,HFE143m,n-Undecane,R123,HydrogenChloride,m-Xylene,R141b,R124,1-Butene,Propylene,R14,p-Xylene,Cyclopentane,MDM,Hydrogen,Neopentane,Ethanol,OrthoHydrogen,R114,Krypton,MD3M,R1243zf,MM,R142b,R40,R13I1
*********** HIGH LEVEL INTERFACE *****************
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.1242958476844 K
Phase of water at 101325 Pa and 300 K: liquid
c_p of water at 101325 Pa and 300 K: 4180.6357765560715 J/kg/K
c_p of water (using derivatives) at 101325 Pa and 300 K: 4180.6357765560715 J/kg/K
*********** HUMID AIR PROPERTIES *****************
Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa: 0.011095529705199761 kg_w/kg_da
Relative humidity from last calculation: 0.5 (fractional)
*********** INCOMPRESSIBLE FLUID AND BRINES *****************
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: 1061.1793077204613 kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa: 5.228837990955358E-4 Pa-s
*********** REFPROP *****************
REFPROP version: 10.0
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.124295847701 K
c_p of water at 101325 Pa and 300 K: 4180.635776575593 J/kg/K
*********** TABULAR BACKENDS *****************
Mass density of refrigerant R245fa at 300 K, 101325 Pa: 5.648128257046375 kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
First saturation derivative: 4058.5197550507155 Pa/K
*********** LOW-LEVEL INTERFACE *****************
Normal boiling point temperature of water and ethanol: 357.2729801712649 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
Vapor molar density: 0.44146562665387795 mol/m^3