Skip to content

Lightweight CoolProp C# Wrapper - for easy fluid properties lookups

License

Notifications You must be signed in to change notification settings

MadsKirkFoged/SharpFluids

Repository files navigation

NuGet NuGet Platform License

SharpFluids

Unit-safe fluid properties using CoolProp and EngineeringUnits

Getting started

Looking up properties for Ammonia

using EngineeringUnits;
using EngineeringUnits.Units;
using SharpFluids;
.
.
.

Fluid R717 = new Fluid(FluidList.Ammonia);
R717.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(100));

Console.WriteLine(R717.Density); // 5.751 kg/m³
Console.WriteLine(R717.DynamicViscosity); // 1.286e-05 Pa·s

Available properties

  • Compressibility
  • Conductivity (W/m/K)
  • CriticalPressure (Pa)
  • CriticalTemperature (K)
  • Density - (kg/m3)
  • DynamicViscosity (Pa*s)
  • Enthalpy (J/kg)
  • Entropy (J/kg/K)
  • InternalEnergy (J/kg)
  • MolarMass (kg/mol)
  • Phase
  • Prandtl
  • Pressure(Pa)
  • Quality
  • SoundSpeed (m/s)
  • SpecificHeat (J/kg/K)
  • SurfaceTension (N/m)
  • Temperature (K)
  • TriplePressure (Pa)
  • TripleTemperature (K)

What is unit-safety?

"As long as you do all your calculation in SI-units.." is the normal saying but if you have tried spending days debugging code to figure out you 'just' had a wrong unit - then unit-safety is your new friend

This is an example of a common unit mistake - With unit-safety you get an error where you did the mistake.

Mass mass = new Mass(10, MassUnit.Kilogram);
Volume volume = new Volume(4, VolumeUnit.CubicMeter);

Density D1 = mass / volume; // 2.5 kg/m³
Density D2 = volume / mass; // WrongUnitException: 'This is NOT a [kg/m³] as expected! Your Unit is a [m³/kg]'

Converting between units is not your headache anymore

You just input the units you have and ask for the units you want:

Length length = new Length(5.485, LengthUnit.Inch);
Length height = new Length(12.4, LengthUnit.Centimeter);

Area area = length * height; // 0.01728 m²
Console.WriteLine(area.ToUnit(AreaUnit.SquareFoot)); // 0.186 ft²
Console.WriteLine(area.ToUnit(AreaUnit.SquareCentimeter)); // 172.8 cm²

Simple example simulating a heat pump

//Setting up the fluids
 Fluid CompressorIn = new Fluid(FluidList.Ammonia);
 Fluid CompressorOut = new Fluid(FluidList.Ammonia);

 Fluid CondenserIn = new Fluid(FluidList.Ammonia);
 Fluid CondenserOut = new Fluid(FluidList.Ammonia);

 Fluid ExpansionValveIn = new Fluid(FluidList.Ammonia);
 Fluid ExpansionValveOut = new Fluid(FluidList.Ammonia);

 Fluid EvaporatorIn = new Fluid(FluidList.Ammonia);
 Fluid EvaporatorOut = new Fluid(FluidList.Ammonia);

 //Setting for heatpump
 Pressure PEvap = Pressure.FromBar(10);
 Pressure Pcond = Pressure.FromBar(20);
 Temperature SuperHeat = Temperature.FromKelvins(10);
 Temperature SubCooling = Temperature.FromKelvins(5);

 //Starting guess for EvaporatorIn
 EvaporatorIn.UpdatePX(PEvap, 0);


 //Solving the heat pump
 while (true) 
 {
     EvaporatorOut.UpdatePX(PEvap, 1);

     //Adding superheat to evap
     EvaporatorOut.UpdatePT(EvaporatorOut.Pressure, EvaporatorOut.Temperature + SuperHeat);

     //Compresser
     CompressorIn.Copy(EvaporatorOut);
     CompressorOut.UpdatePS(Pcond, CompressorIn.Entropy);
     SpecificEnergy H2s = CompressorOut.Enthalpy;

     //Compressor equation
     SpecificEnergy h2 = ((H2s - CompressorIn.Enthalpy) / 0.85) + CompressorIn.Enthalpy;
     CompressorOut.UpdatePH(Pcond, h2);


     CondenserIn.Copy(CompressorOut);
     CondenserOut.UpdatePX(CondenserIn.Pressure, 0);
     CondenserOut.UpdatePT(CondenserOut.Pressure, CondenserOut.Temperature - SubCooling);

     ExpansionValveIn.Copy(CondenserOut);
     ExpansionValveOut.UpdatePH(EvaporatorIn.Pressure, ExpansionValveIn.Enthalpy);

     //Break out of the loop if it is stable
     if ((ExpansionValveOut.Enthalpy - EvaporatorIn.Enthalpy).Abs() < SpecificEnergy.FromKilojoulePerKilogram(1))
     {
         break;
     }

     EvaporatorIn.Copy(ExpansionValveOut);
 }

About

Lightweight CoolProp C# Wrapper - for easy fluid properties lookups

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages