C# Wrapper

Pre-compiled Binaries

To Use

Pre-compiled binaries can be downloaded from Csharp. Development binaries coming from the buildbot server can be found at Csharp.

Download the platform-independent.7z file and expand it to a folder called platform-independent using 7-zip. Download the special C# shared library for your system architecture to the same location from either Csharp (release) or Csharp (development). Copy the Example.cs file to the same location. You will need to have a copy of some version of C#.

When you are finished, you should have a folder layout something like

main
 |- CoolProp.dll
 |- Example.cs
 |- platform-independent
    |- AbstractState.cs
    |- Configuration.cs
    |- ...

There is example code at the end of this page

Windows

At the command prompt, run:

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
csc Example.cs platform-independent/*.cs -platform:x64
Example

where you might need to update the path to visual studio depending on your version installed. Use -platform:x86 to tell C# that your DLL is 32-bit if you are on 32-bit, or -platform:x64 if you are on 64-bit.

Alternatively, you can add all the .cs files to a visual studio project. If you do that, add the DLL to the project as well, right-click on the DLL, and select the option to copy it to the output directory.

Linux/OSX

Same idea as windows, but command line is just a bit different:

mcs Example.cs platform-independent/*.cs -platform:x64
./Example

Use -platform:x86 to tell C# that your shared library is 32-bit if you are on 32-bit, or -platform:x64 if you are on a 64-bit platform.

User-Compiled Binaries

Common Requirements

Compilation of the C# wrapper requires a few common wrapper pre-requisites

Additionally, you will need: * SWIG (see common wrapper pre-requisites) * C#

OSX

For OSX, to install the necessary tools using homebrew, you can do:

homebrew install mono

Linux

For ubuntu and friends, you will need to install Mono C# as well as the compiler (and other dependencies) using:

sudo apt-get install swig mono-mcs mono-runtime

Windows

For Windows, download the Visual Studio 2010 version of C# (other versions should probably be fine too)

Compile

Once mono c# is 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
cd CoolProp
# Make a build folder
mkdir build && cd build
# Build the makefile using CMake
cmake .. -DCOOLPROP_CSHARP_MODULE=ON -DBUILD_TESTING=ON
# Make the C# files (by default files will be generated in folder install_root/Csharp relative to CMakeLists.txt file)
cmake --build .
# Run the integration tests (optional)
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_CSHARP_MODULE=ON -DBUILD_TESTING=ON -DCOOLPROP_SWIG_OPTIONS="-namespace package.name"

where package.name is replaced with the desired name

Example Code

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("**************** INFORMATION ***************" + "\n");
            Console.Write("This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell" + "\n");
            Console.Write("CoolProp version:" + " " + CoolProp.get_global_param_string("version") + "\n");
            Console.Write("CoolProp gitrevision:" + " " + CoolProp.get_global_param_string("gitrevision") + "\n");
            Console.Write("CoolProp Fluids:" + " " + CoolProp.get_global_param_string("FluidsList") + "\n");
            // See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface;
            Console.Write("*********** HIGH LEVEL INTERFACE *****************" + "\n");
            Console.Write("Critical temperature of water:" + " " + CoolProp.Props1SI("Water", "Tcrit") + " " + "K" + "\n");
            Console.Write("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "Water") + " " + "K" + "\n");
            Console.Write("Phase of water at 101325 Pa and 300 K:" + " " + CoolProp.PhaseSI("P", 101325, "T", 300, "Water") + "\n");
            Console.Write("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "Water") + " " + "J/kg/K" + "\n");
            Console.Write("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" + "\n");
            Console.Write("*********** HUMID AIR PROPERTIES *****************" + "\n");
            Console.Write("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" + "\n");
            Console.Write("Relative humidity from last calculation:" + " " + CoolProp.HAPropsSI("R", "T", 300, "P", 101325, "W", CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5)) + " " + "(fractional)" + "\n");
            Console.Write("*********** INCOMPRESSIBLE FLUID AND BRINES *****************" + "\n");
            Console.Write("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" + "\n");
            Console.Write("Viscosity of Therminol D12 at 350 K, 101325 Pa:" + " " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12") + " " + "Pa-s" + "\n");
            // If you don't have REFPROP installed, disable the following lines;
            Console.Write("*********** REFPROP *****************" + "\n");
            Console.Write("REFPROP version:" + " " + CoolProp.get_global_param_string("REFPROP_version") + "\n");
            Console.Write("Critical temperature of water:" + " " + CoolProp.Props1SI("REFPROP::Water", "Tcrit") + " " + "K" + "\n");
            Console.Write("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "REFPROP::Water") + " " + "K" + "\n");
            Console.Write("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "REFPROP::Water") + " " + "J/kg/K" + "\n");
            Console.Write("*********** TABULAR BACKENDS *****************" + "\n");
            AbstractState TAB = AbstractState.factory("BICUBIC&HEOS", "R245fa");
            TAB.update(input_pairs.PT_INPUTS, 101325, 300);
            Console.Write("Mass density of refrigerant R245fa at 300 K, 101325 Pa:" + " " + TAB.rhomass() + " " + "kg/m^3" + "\n");
            Console.Write("*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************" + "\n");
            AbstractState AS_SAT = AbstractState.factory("HEOS", "R245fa");
            AS_SAT.update(input_pairs.PQ_INPUTS, 101325, 0);
            Console.Write("First saturation derivative:" + " " + AS_SAT.first_saturation_deriv(parameters.iP, parameters.iT) + " " + "Pa/K" + "\n");
            Console.Write("*********** LOW-LEVEL INTERFACE *****************" + "\n");
            AbstractState AS = AbstractState.factory("HEOS", "Water&Ethanol");
            DoubleVector z = new DoubleVector(new double[]{0.5, 0.5});
            AS.set_mole_fractions(z);
            AS.update(input_pairs.PQ_INPUTS, 101325, 1);
            Console.Write("Normal boiling point temperature of water and ethanol:" + " " + AS.T() + " " + "K" + "\n");
            // If you don't have REFPROP installed, disable the following block;
            Console.Write("*********** LOW-LEVEL INTERFACE (REFPROP) *****************" + "\n");
            AbstractState AS2 = AbstractState.factory("REFPROP", "Methane&Ethane");
            DoubleVector z2 = new DoubleVector(new double[]{0.2, 0.8});
            AS2.set_mole_fractions(z2);
            AS2.update(input_pairs.QT_INPUTS, 1, 120);
            Console.Write("Vapor molar density:" + " " + AS2.keyed_output(parameters.iDmolar) + " " + "mol/m^3" + "\n");
        }
    }
}

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.1.0
CoolProp gitrevision: 7864c2614ce5a0ef972386ee7f39859f0d3f8038
CoolProp Fluids: 1-Butene,Acetone,Air,Ammonia,Argon,Benzene,CarbonDioxide,CarbonMonoxide,CarbonylSulfide,cis-2-Butene,CycloHexane,Cyclopentane,CycloPropane,D4,D5,D6,Deuterium,Dichloroethane,DiethylEther,DimethylCarbonate,DimethylEther,Ethane,Ethanol,EthylBenzene,Ethylene,EthyleneOxide,Fluorine,HeavyWater,Helium,HFE143m,Hydrogen,HydrogenChloride,HydrogenSulfide,IsoButane,IsoButene,Isohexane,Isopentane,Krypton,m-Xylene,MD2M,MD3M,MD4M,MDM,Methane,Methanol,MethylLinoleate,MethylLinolenate,MethylOleate,MethylPalmitate,MethylStearate,MM,n-Butane,n-Decane,n-Dodecane,n-Heptane,n-Hexane,n-Nonane,n-Octane,n-Pentane,n-Propane,n-Undecane,Neon,Neopentane,Nitrogen,NitrousOxide,Novec649,o-Xylene,OrthoDeuterium,OrthoHydrogen,Oxygen,p-Xylene,ParaDeuterium,ParaHydrogen,Propylene,Propyne,R11,R113,R114,R115,R116,R12,R123,R1233zd(E),R1234yf,R1234ze(E),R1234ze(Z),R124,R125,R13,R134a,R13I1,R14,R141b,R142b,R143a,R152A,R161,R21,R218,R22,R227EA,R23,R236EA,R236FA,R245ca,R245fa,R32,R365MFC,R40,R404A,R407C,R41,R410A,R507A,RC318,SES36,SulfurDioxide,SulfurHexafluoride,Toluene,trans-2-Butene,Water,Xenon
*********** 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: 9.1.1.10
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.124295847699 K
c_p of water at 101325 Pa and 300 K: 4180.63577657788 J/kg/K
*********** TABULAR BACKENDS *****************
Mass density of refrigerant R245fa at 300 K, 101325 Pa: 5.64812825704638 kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
First saturation derivative: 4058.51975505072 Pa/K
*********** LOW-LEVEL INTERFACE *****************
Normal boiling point temperature of water and ethanol: 357.272980172343 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
Vapor molar density: 0.441465625159452 mol/m^3