A simple, full-featured, lightweight, cross-platform CoolProp wrapper for C#.
Run the following command in the Package Manager Console:
NuGet\Install-Package SharpProp -Version 4.4.1
Or add this to the .csproj
file:
<ItemGroup>
<PackageReference Include="SharpProp" Version="4.4.1"/>
</ItemGroup>
All calculations of thermophysical properties are unit safe (thanks to UnitsNet). This allows you to avoid errors associated with incorrect dimensions of quantities, and will help you save a lot of time on their search and elimination. In addition, you will be able to convert all values to many other dimensions without the slightest difficulty.
Fluid
class - for pure fluids and binary mixtures.Mixture
class - for mixtures with pure fluids components.FluidsList
enum - list of all available fluids.Input
record - inputs for theFluid
andMixture
classes.HumidAir
class - for humid air.InputHumidAir
record - inputs for theHumidAir
class.
If the required property is not present in the instance of the fluid, then you can add it by extending
the Fluid
, Mixture
or HumidAir
classes (see how to add other properties).
Compressibility
- compressibility factor (dimensionless).Conductivity
- thermal conductivity (by default, W/m/K).CriticalPressure
- absolute pressure at the critical point (by default, kPa).CriticalTemperature
- temperature at the critical point (by default, °C).Density
- mass density (by default, kg/m3).DynamicViscosity
- dynamic viscosity (by default, mPa*s).Enthalpy
- mass specific enthalpy (by default, kJ/kg).Entropy
- mass specific entropy (by default, kJ/kg/K).FreezingTemperature
- temperature at freezing point (for incompressible fluids) (by default, °C).InternalEnergy
- mass specific internal energy (by default, kJ/kg).KinematicViscosity
- kinematic viscosity (by default, cSt).MaxPressure
- maximum pressure limit (by default, kPa).MaxTemperature
- maximum temperature limit (by default, °C).MinPressure
- minimum pressure limit (by default, kPa).MinTemperature
- minimum temperature limit (by default, °C).MolarMass
- molar mass (by default, g/mol).Phase
- phase state (enum).Prandtl
- Prandtl number (dimensionless).Pressure
- absolute pressure (by default, kPa).Quality
- mass vapor quality (by default, %).SoundSpeed
- sound speed (by default, m/s).SpecificHeat
- mass specific constant pressure specific heat (by default, kJ/kg/K).SurfaceTension
- surface tension (by default, N/m).Temperature
- temperature (by default, °C).TriplePressure
- absolute pressure at the triple point (by default, kPa).TripleTemperature
- temperature at the triple point (by default, °C).
Compressibility
- compressibility factor (dimensionless).Conductivity
- thermal conductivity (by default, W/m/K).Density
- mass density per humid air unit (by default, kg/m3).DewTemperature
- dew-point temperature (by default, °C).DynamicViscosity
- dynamic viscosity (by default, mPa*s).Enthalpy
- mass specific enthalpy per humid air (by default, kJ/kg).Entropy
- mass specific entropy per humid air (by default, kJ/kg/K).Humidity
- absolute humidity ratio (by default, g/kg d.a.).KinematicViscosity
- kinematic viscosity (by default, cSt).PartialPressure
- partial pressure of water vapor (by default, kPa).Prandtl
- Prandtl number (dimensionless).Pressure
- absolute pressure (by default, kPa).RelativeHumidity
- relative humidity ratio (by default, %).SpecificHeat
- mass specific constant pressure specific heat per humid air (by default, kJ/kg/K).Temperature
- dry-bulb temperature (by default, °C).WetBulbTemperature
- wet-bulb temperature (by default, °C).
For more information, see the XML documentation.
Factory
- returns a new fluid object with no defined state.WithState
- returns a new fluid object with a defined state.Update
- update fluid state.Reset
- reset all non-trivial properties.Clone
- performs deep (full) copy of the fluid instance.IsentropicCompressionTo
- the process of isentropic compression to a given pressure.CompressionTo
- the process of compression to a given pressure.IsenthalpicExpansionTo
- the process of isenthalpic expansion to a given pressure.IsentropicExpansionTo
- the process of isentropic expansion to a given pressure.ExpansionTo
- the process of expansion to a given pressure.CoolingTo
- the process of cooling to a given temperature or enthalpy.HeatingTo
- the process of heating to a given temperature or enthalpy.BubblePointAt
- bubble point at a given pressure or temperature.DewPointAt
- dew point at a given pressure or temperature.TwoPhasePointAt
- two-phase point at a given pressure.Mixing
- the mixing process.AsJson
- converts the fluid instance to a JSON string.
Factory
- returns a new fluid object with no defined state.WithState
- returns a new fluid object with a defined state.Update
- update fluid state.Reset
- reset all non-trivial properties.Clone
- performs deep (full) copy of the mixture instance.CoolingTo
- the process of cooling to a given temperature.HeatingTo
- the process of heating to a given temperature.AsJson
- converts the mixture instance to a JSON string.
Factory
- returns a new humid air object with no defined state.WithState
- returns a new humid air object with a defined state.Update
- update humid air state.Reset
- reset all properties.Clone
- performs deep (full) copy of the humid air instance.DryCoolingTo
- the process of cooling without dehumidification to a given temperature or enthalpy.WetCoolingTo
- the process of cooling with dehumidification to a given temperature or enthalpy and relative or absolute humidity ratio.HeatingTo
- the process of heating to a given temperature or enthalpy.HumidificationByWaterTo
- the process of humidification by water (isenthalpic) to a given relative or absolute humidity ratio.HumidificationBySteamTo
- the process of humidification by steam (isothermal) to a given relative or absolute humidity ratio.Mixing
- the mixing process.AsJson
- converts the humid air instance to a JSON string.
To calculate the specific heat of saturated water vapor at 1 atm:
var waterVapour = new Fluid(FluidsList.Water)
.DewPointAt((1).Atmospheres());
Console.WriteLine(waterVapour.SpecificHeat.JoulesPerKilogramKelvin); // 2079.937085633241
Console.WriteLine(waterVapour.SpecificHeat); // 2.08 kJ/kg·K
Console.WriteLine(waterVapour.SpecificHeat
.ToUnit(SpecificEntropyUnit.CaloriePerGramKelvin)); // 0.5 cal/g·K
To calculate the dynamic viscosity of propylene glycol aqueous solution with 60 % mass fraction at 100 kPa and -20 °C:
var propyleneGlycol = new Fluid(FluidsList.MPG, (60).Percent())
.WithState(Input.Pressure((100).Kilopascals()),
Input.Temperature((-20).DegreesCelsius()));
Console.WriteLine(propyleneGlycol.DynamicViscosity?.PascalSeconds); // 0.13907391053938878
Console.WriteLine(propyleneGlycol.DynamicViscosity); // 139.07 mPa·s
Console.WriteLine(propyleneGlycol.DynamicViscosity?
.ToUnit(DynamicViscosityUnit.Poise)); // 1.39 P
To calculate the density of ethanol aqueous solution (with ethanol 40 % mass fraction) at 200 kPa and 277.15 K:
var mixture = new Mixture(
new List<FluidsList> {FluidsList.Water, FluidsList.Ethanol},
new List<Ratio> {(60).Percent(), (40).Percent()})
.WithState(Input.Pressure((200).Kilopascals()),
Input.Temperature((277.15).Kelvins()));
Console.WriteLine(mixture.Density.KilogramsPerCubicMeter); // 883.3922771627759
Console.WriteLine(mixture.Density); // 883.39 kg/m3
Console.WriteLine(mixture.Density.ToUnit(DensityUnit.GramPerDeciliter)); // 88.34 g/dl
To calculate the wet bulb temperature of humid air at 300 m above sea level, 30 °C and 50 % relative humidity:
var humidAir = new HumidAir().WithState(
InputHumidAir.Altitude((300).Meters()),
InputHumidAir.Temperature((30).DegreesCelsius()),
InputHumidAir.RelativeHumidity((50).Percent()));
Console.WriteLine(humidAir.WetBulbTemperature.Kelvins); // 295.06756903318154
Console.WriteLine(humidAir.WetBulbTemperature); // 21.92 °C
Console.WriteLine(humidAir.WetBulbTemperature
.ToUnit(TemperatureUnit.DegreeFahrenheit)); // 71.45 °F
You can simply determine the equality of Fluid
, Mixture
and HumidAir
instances by its state.
Just use the Equals
method or the equality operators (==
or !=
).
Exactly the same way you can compare inputs (Input
, InputHumidAir
or any IKeyedInput
record).
For example:
var humidAir = new HumidAir().WithState(
InputHumidAir.Pressure((1).Atmospheres()),
InputHumidAir.Temperature((20).DegreesCelsius()),
InputHumidAir.RelativeHumidity((50).Percent()));
var sameHumidAir = new HumidAir().WithState(
InputHumidAir.Pressure((101325).Pascals()),
InputHumidAir.Temperature((293.15).Kelvins()),
InputHumidAir.RelativeHumidity((50).Percent()));
Console.WriteLine(humidAir == sameHumidAir); // true
Console.WriteLine(
InputHumidAir.Pressure((1).Atmospheres()) ==
InputHumidAir.Pressure((101.325).Kilopascals())); // true
The Fluid
, Mixture
and HumidAir
classes have an extension method AsJson
,
which performs converting of instance to a JSON string.
For example, converting a Fluid
instance to an indented JSON string:
var refrigerant = new Fluid(FluidsList.R32)
.DewPointAt((5).DegreesCelsius());
Console.WriteLine(refrigerant.AsJson());
As a result:
{
"Name": "R32",
"Fraction": {
"Unit": "RatioUnit.Percent",
"Value": 100.0
},
"Compressibility": 0.8266625877210833,
"Conductivity": {
"Unit": "ThermalConductivityUnit.WattPerMeterKelvin",
"Value": 0.013435453854396475
},
"CriticalPressure": {
"Unit": "PressureUnit.Kilopascal",
"Value": 5782.0
},
"CriticalTemperature": {
"Unit": "TemperatureUnit.DegreeCelsius",
"Value": 78.10500000000002
},
"Density": {
"Unit": "DensityUnit.KilogramPerCubicMeter",
"Value": 25.89088151061046
},
"DynamicViscosity": {
"Unit": "DynamicViscosityUnit.MillipascalSecond",
"Value": 0.012606543144761657
},
"Enthalpy": {
"Unit": "SpecificEnergyUnit.KilojoulePerKilogram",
"Value": 516.1057800378023
},
"Entropy": {
"Unit": "SpecificEntropyUnit.KilojoulePerKilogramKelvin",
"Value": 2.1362654412978777
},
"FreezingTemperature": null,
"InternalEnergy": {
"Unit": "SpecificEnergyUnit.KilojoulePerKilogram",
"Value": 479.35739743435374
},
"KinematicViscosity": {
"Unit": "KinematicViscosityUnit.Centistokes",
"Value": 0.48691054182899535
},
"MaxPressure": {
"Unit": "PressureUnit.Kilopascal",
"Value": 70000.0
},
"MaxTemperature": {
"Unit": "TemperatureUnit.DegreeCelsius",
"Value": 161.85000000000002
},
"MinPressure": {
"Unit": "PressureUnit.Kilopascal",
"Value": 0.04799989387605937
},
"MinTemperature": {
"Unit": "TemperatureUnit.DegreeCelsius",
"Value": -136.80999999999997
},
"MolarMass": {
"Unit": "MolarMassUnit.GramPerMole",
"Value": 52.024
},
"Phase": "TwoPhase",
"Prandtl": 1.2252282243443504,
"Pressure": {
"Unit": "PressureUnit.Kilopascal",
"Value": 951.448019691762
},
"Quality": {
"Unit": "RatioUnit.Percent",
"Value": 100.0
},
"SoundSpeed": {
"Unit": "SpeedUnit.MeterPerSecond",
"Value": 209.6337575990297
},
"SpecificHeat": {
"Unit": "SpecificEntropyUnit.KilojoulePerKilogramKelvin",
"Value": 1.3057899441785379
},
"SurfaceTension": {
"Unit": "ForcePerLengthUnit.NewtonPerMeter",
"Value": 0.010110117241546162
},
"Temperature": {
"Unit": "TemperatureUnit.DegreeCelsius",
"Value": 5.0
},
"TriplePressure": {
"Unit": "PressureUnit.Kilopascal",
"Value": 0.04799989387605937
},
"TripleTemperature": {
"Unit": "TemperatureUnit.DegreeCelsius",
"Value": -136.80999999999997
}
}
The Fluid
, Mixture
and HumidAir
classes have an extension method Clone
,
which performs deep (full) copy of instance:
var origin = new Fluid(FluidsList.Water)
.WithState(Input.Pressure((1).Atmospheres()),
Input.Temperature((20).DegreesCelsius()));
var clone = origin.Clone();
Console.WriteLine(origin == clone); // true
clone.Update(Input.Pressure((1).Atmospheres()),
Input.Temperature((30).DegreesCelsius()));
Console.WriteLine(origin == clone); // false