C# Wrapper¶
NuGet packages (3-party wrappers)¶
Pre-compiled Binaries¶
To Use¶
Pre-compiled binaries can be downloaded from 6.8.1dev Csharp. Development binaries coming from the buildbot server can be found at nightly 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 6.8.1dev Csharp (release) or nightly 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ÐANE");
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.8.1dev
CoolProp gitrevision: 45fdfaa8ea5c29509af83810de83a0e9cd2c2f21
CoolProp Fluids: R13I1,cis-2-Butene,CycloPropane,MD3M,NitrousOxide,SulfurHexafluoride,R161,1-Butene,MethylStearate,MethylOleate,SES36,R245fa,Isopentane,Neopentane,R41,Neon,o-Xylene,HeavyWater,CarbonMonoxide,R124,Dichloroethane,ParaHydrogen,R11,R14,n-Butane,R236FA,Hydrogen,R134a,Air,n-Pentane,R227EA,R23,OrthoDeuterium,OrthoHydrogen,CarbonylSulfide,MD2M,Benzene,MethylPalmitate,Deuterium,R113,n-Hexane,Water,n-Dodecane,trans-2-Butene,R1243zf,Krypton,R152A,Novec649,R22,EthylBenzene,CarbonDioxide,D4,R125,RC318,ParaDeuterium,R143a,MethylLinoleate,R1233zd(E),Helium,R1336MZZE,Nitrogen,Acetone,R218,m-Xylene,MM,EthyleneOxide,R407C,n-Undecane,n-Propane,HFE143m,Propylene,R21,R142b,R32,R123,Toluene,DimethylCarbonate,R115,DimethylEther,R1234ze(E),R13,Fluorine,Ethylene,R365MFC,IsoButane,Cyclopentane,R141b,Isohexane,Ethane,DiethylEther,Argon,HydrogenSulfide,MethylLinolenate,n-Heptane,n-Decane,IsoButene,HydrogenChloride,Oxygen,R40,CycloHexane,p-Xylene,R404A,Ammonia,SulfurDioxide,R116,R245ca,Xenon,D5,R507A,Methane,Methanol,Propyne,MD4M,R1234ze(Z),Ethanol,n-Octane,R114,D6,R1234yf,n-Nonane,R410A,R236EA,R12,MDM
*********** 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 *****************
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.272980171265 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
Vapor molar density: 0.441465626653878 mol/m^3