R Wrapper¶
Pre-compiled Binaries¶
Pre-compiled binaries can be downloaded from R. Development binaries coming from the buildbot server can be found at R. Download the shared library for your platform, as well as the CoolProp.R
module
Usage¶
At the R console, run:
dyn.load(paste("CoolProp", .Platform$dynlib.ext, sep=""))
source("CoolProp.R")
cacheMetaData(1)
PropsSI("T","P",101325,"Q",0,"Water")
There is example code at the end of this page
Warning
For OSX users that wish to call REFPROP, you may be required to set the environmental variable DYLD_LIBRARY_PATH
to the folder containing your REFPROP.dylib shared library, which is probably /opt/refprop
Warning
If you want to use Rscript
rather than R
, you need to pass the argument --default-packages=methods
to get it to load the necessary packages for calling SWIGG-ed code. Or call library(methods)
at the top of the file (before source("CoolProp.R")
). See also http://stackoverflow.com/a/19468533n
User-Compiled Binaries¶
Common Requirements¶
Compilation of the R wrapper requires a few common wrapper pre-requisites
Also, you need to install R
Windows¶
You must install the MINGW compiler suite. The TDM suite is recommended.
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_R_MODULE=ON -DR_BIN="/usr/bin" -DCMAKE_BUILD_TYPE=Release
# Make the R shared library
cmake --build .
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 (Must use MINGW since R is built with MINGW)
cmake .. -DCOOLPROP_R_MODULE=ON -G "MinGW Makefiles" -DR_BIN="c:\Program Files\R\R-3.2.1\bin\x64" -DCMAKE_BUILD_TYPE=Release
# Make the R shared library
cmake --build .
Example Code¶
dyn.load(paste("CoolProp", .Platform$dynlib.ext, sep=""))
library(methods) # See http://stackoverflow.com/a/19468533
source("CoolProp.R")
cacheMetaData(1)
writeLines(paste('**************** INFORMATION ***************'))
writeLines(paste('This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell'))
writeLines(paste('CoolProp version:', ' ', get_global_param_string('version')))
writeLines(paste('CoolProp gitrevision:', ' ', get_global_param_string('gitrevision')))
writeLines(paste('CoolProp Fluids:', ' ', 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
writeLines(paste('*********** HIGH LEVEL INTERFACE *****************'))
writeLines(paste('Critical temperature of water:', ' ', Props1SI('Water', 'Tcrit'), ' ', 'K'))
writeLines(paste('Boiling temperature of water at 101325 Pa:', ' ', PropsSI('T', 'P', 101325, 'Q', 0, 'Water'), ' ', 'K'))
writeLines(paste('Phase of water at 101325 Pa and 300 K:', ' ', PhaseSI('P', 101325, 'T', 300, 'Water')))
writeLines(paste('c_p of water at 101325 Pa and 300 K:', ' ', PropsSI('C', 'P', 101325, 'T', 300, 'Water'), ' ', 'J/kg/K'))
writeLines(paste('c_p of water (using derivatives) at 101325 Pa and 300 K:', ' ', PropsSI('d(H)/d(T)|P', 'P', 101325, 'T', 300, 'Water'), ' ', 'J/kg/K'))
writeLines(paste('*********** HUMID AIR PROPERTIES *****************'))
writeLines(paste('Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:', ' ', HAPropsSI('W', 'T', 300, 'P', 101325, 'R', 0.5), ' ', 'kg_w/kg_da'))
writeLines(paste('Relative humidity from last calculation:', ' ', HAPropsSI('R', 'T', 300, 'P', 101325, 'W', HAPropsSI('W', 'T', 300, 'P', 101325, 'R', 0.5)), ' ', '(fractional)'))
writeLines(paste('*********** INCOMPRESSIBLE FLUID AND BRINES *****************'))
writeLines(paste('Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:', ' ', PropsSI('D', 'T', 300, 'P', 101325, 'INCOMP::MEG-50%'), ' ', 'kg/m^3'))
writeLines(paste('Viscosity of Therminol D12 at 350 K, 101325 Pa:', ' ', PropsSI('V', 'T', 350, 'P', 101325, 'INCOMP::TD12'), ' ', 'Pa-s'))
# If you don't have REFPROP installed, disable the following lines
writeLines(paste('*********** REFPROP *****************'))
writeLines(paste('REFPROP version:', ' ', get_global_param_string('REFPROP_version')))
writeLines(paste('Critical temperature of water:', ' ', Props1SI('REFPROP::WATER', 'Tcrit'), ' ', 'K'))
writeLines(paste('Boiling temperature of water at 101325 Pa:', ' ', PropsSI('T', 'P', 101325, 'Q', 0, 'REFPROP::WATER'), ' ', 'K'))
writeLines(paste('c_p of water at 101325 Pa and 300 K:', ' ', PropsSI('C', 'P', 101325, 'T', 300, 'REFPROP::WATER'), ' ', 'J/kg/K'))
writeLines(paste('*********** TABULAR BACKENDS *****************'))
TAB = AbstractState_factory('BICUBIC&HEOS', 'R245fa')
TAB$update("PT_INPUTS", 101325, 300)
writeLines(paste('Mass density of refrigerant R245fa at 300 K, 101325 Pa:', ' ', TAB$rhomass(), ' ', 'kg/m^3'))
writeLines(paste('*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************'))
AS_SAT = AbstractState_factory('HEOS', 'R245fa')
AS_SAT$update("PQ_INPUTS", 101325, 0)
writeLines(paste('First saturation derivative:', ' ', AS_SAT$first_saturation_deriv("iP", "iT"), ' ', 'Pa/K'))
writeLines(paste('*********** LOW-LEVEL INTERFACE *****************'))
AS = AbstractState_factory('HEOS', 'Water&Ethanol')
z = c(0.5, 0.5)
AS$set_mole_fractions(z)
AS$update("PQ_INPUTS", 101325, 1)
writeLines(paste('Normal boiling point temperature of water and ethanol:', ' ', AS$T(), ' ', 'K'))
# If you don't have REFPROP installed, disable the following block
writeLines(paste('*********** LOW-LEVEL INTERFACE (REFPROP) *****************'))
AS2 = AbstractState_factory('REFPROP', 'METHANEÐANE')
z2 = c(0.2, 0.8)
AS2$set_mole_fractions(z2)
AS2$update("QT_INPUTS", 1, 120)
writeLines(paste('Vapor molar density:', ' ', AS2$keyed_output("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.1dev
CoolProp gitrevision: fb011601daf1c63dec6b394f3ae88850a1b09ffe
CoolProp Fluids: Xenon,Hydrogen,Ethylene,R365MFC,Air,1-Butene,IsoButene,D4,Methanol,R1243zf,MethylLinolenate,R124,ParaDeuterium,n-Propane,R40,Water,OrthoHydrogen,R143a,SulfurHexafluoride,R13I1,R23,HydrogenSulfide,D5,Ethane,n-Octane,SES36,cis-2-Butene,Isohexane,HFE143m,Neopentane,OrthoDeuterium,R227EA,R125,R116,n-Heptane,Ammonia,o-Xylene,R11,n-Nonane,Acetone,trans-2-Butene,R113,Cyclopentane,CarbonDioxide,R114,Propyne,Krypton,R410A,MethylPalmitate,p-Xylene,CycloHexane,DiethylEther,R507A,R123,R407C,CarbonylSulfide,R245fa,EthylBenzene,Oxygen,Fluorine,R32,IsoButane,MM,MDM,R1234ze(Z),CycloPropane,MethylLinoleate,Deuterium,Novec649,D6,R236FA,R1234ze(E),R41,HeavyWater,Ethanol,DimethylCarbonate,Neon,R1336MZZE,NitrousOxide,MD2M,MD4M,RC318,R218,n-Dodecane,n-Decane,Argon,EthyleneOxide,CarbonMonoxide,Toluene,n-Butane,ParaHydrogen,R1233zd(E),R115,R152A,R142b,Dichloroethane,Helium,R404A,R14,m-Xylene,Benzene,R13,SulfurDioxide,R236EA,MethylOleate,Methane,n-Pentane,DimethylEther,n-Undecane,R161,R141b,MD3M,R1234yf,R22,Nitrogen,HydrogenChloride,R21,MethylStearate,R134a,R245ca,Propylene,R12,Isopentane,n-Hexane
*********** HIGH LEVEL INTERFACE *****************
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.124295847684 K
Phase of water at 101325 Pa and 300 K: liquid
c_p of water at 101325 Pa and 300 K: 4180.63577655607 J/kg/K
c_p of water (using derivatives) at 101325 Pa and 300 K: 4180.63577655607 J/kg/K
*********** HUMID AIR PROPERTIES *****************
Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa: 0.0110955297051998 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.17930772046 kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa: 0.000522883799095536 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.63577657559 J/kg/K
*********** TABULAR BACKENDS *****************
NULL
Mass density of refrigerant R245fa at 300 K, 101325 Pa: 5.64812825704638 kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
NULL
First saturation derivative: 4058.51975505072 Pa/K
*********** LOW-LEVEL INTERFACE *****************
NULL
NULL
Normal boiling point temperature of water and ethanol: 357.272980171265 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
NULL
NULL
Vapor molar density: 0.441465626653878 mol/m^3
in method for ‘copyToR’ with signature ‘"_p_CoolProp::SimpleState"’: no definition for class “_p_CoolProp::SimpleState”
in method for ‘copyToR’ with signature ‘"_p_CoolProp::CriticalState"’: no definition for class “_p_CoolProp::CriticalState”
in method for ‘copyToR’ with signature ‘"_p_CoolProp::SsatSimpleState"’: no definition for class “_p_CoolProp::SsatSimpleState”