Giter VIP home page Giter VIP logo

sharpfluids's Introduction

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);
 }

sharpfluids's People

Contributors

madskirkfoged avatar madsfoged avatar wiwalsh avatar jbahraa avatar attemainio avatar romarro avatar theodoreonzgit avatar

Stargazers

 avatar GuanQH avatar 姜志远 avatar  avatar  avatar  avatar Asheesh Maheshwari avatar  avatar  avatar KarsusAvatar avatar theangkko avatar  avatar  avatar  avatar geffzhang avatar  avatar Jarno Honkanen avatar tobony avatar Michael Lippy avatar  avatar  avatar  avatar  avatar GITHAE KEVIN  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sharpfluids's Issues

Phase property not working properly

Hello,

I'm trying to retrieve Phase property from a fluid after update it's thermophysic state.
Here's the code:

Fluid r134a = new Fluid(FluidList.R134a);
r134a.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(75));
var phase = r134a.Phase;

The issue is that phase variable (enum integer) is always equal to -2147483648.
I've tried several refrigerants (water, ammonia, etc.) but the issue is the same.

Is possible to resolve that or i'm doing something wrong?
Thanks in advance.
Mattia

Updating Fluid Volume

Why is it not possible to update the volume of the fluid? I can update the presure, density, temperature, enthalpy, etc, but the volume is set to 'get;' only. Is there another way to set the property of the fluid to either constant or to update the volume? Sorry if I posted this in the wrong section and thanks for your help.

Mix of multiple Fluids

Hello,

Currently it seems mix of multiple fluids is not supported in SharFluids.
I see that .addTo() function exists but it does not create a mixture further use.

Can you advise how we can create a mixture and use it with SharpFluids?

Thanks.

Linux .NET6.0 SharpFluids Thew System.DllNotFoundException

Hi MadsKirkFoged,

Thanks for making this library,

I've run code similar to this in a unit test on a windows PC, it works beautifully.

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

// make a new therminol-VP1 fluid object

Fluid therminol = new Fluid(FluidList.InCompTherminolVP1);

// set temperature and pressure

Pressure atmosphericPressure = new Pressure(1.1013e5, PressureUnit.Pascal);
EngineeringUnits.Temperature roomTemperature 
= new EngineeringUnits.Temperature(293, TemperatureUnit.Kelvin);

// update PT of therminol
// updates the temperature and pressure of therminol

therminol.UpdatePT(atmosphericPressure, roomTemperature);

// obtain prandtl number
Console.WriteLine(therminol.Prandtl);

Unfortunately, i ran the same code on my linux machine and it threw me a DllnotFoundException.

I looked in my binary files and the dll was there...

watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.
watch : Building...
  Determining projects to restore...
  All projects are up-to-date for restore.
  linuxCoolPropTest -> /home/teddy0/Documents/youTube/spiceSharpFluidFlowSolver/linuxCoolPropTest/bin/Debug/net6.0/linuxCoolPropTest.dll
watch : Started
Unhandled exception. System.TypeInitializationException: The type initializer for 'CoolPropPINVOKE64' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'CoolProp64' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libCoolProp64: cannot open shared object file: No such file or directory
   at CoolPropPINVOKE64.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_CoolProp(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
   at CoolPropPINVOKE64.SWIGExceptionHelper..cctor()
   --- End of inner exception stack trace ---
   at CoolPropPINVOKE64.SWIGExceptionHelper..ctor()
   at CoolPropPINVOKE64..cctor()
   --- End of inner exception stack trace ---
   at CoolPropPINVOKE64.AbstractState_factory__SWIG_0(String jarg1, String jarg2)
   at AbstractState.factory(String backend, String fluid_names)
   at SharpFluids.Fluid.SetNewMedia(MediaType Type)
   at SharpFluids.Fluid..ctor(MediaType Media)
   at SharpFluids.Fluid..ctor(FluidList Type)
   at Program.<Main>$(String[] args) in /home/teddy0/Documents/youTube/spiceSharpFluidFlowSolver/linuxCoolPropTest/Program.cs:line 9
watch : Exited with error code 134
watch : Waiting for a file to change before restarting dotnet...

I can of course take a look at it, but have limited time to do so and try and debug this.

I do hope you can take a look also.

But once again, thank you for this package.

Doesn't work in Blazor WebAssembly

Hello,
unfortunately library doesn't work with .netcore console app on my computer.
Error on the line
Fluid air=new Fluid(FluidList.Air);
Details below:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'CoolPropPINVOKE' threw an exception.
  Source=SharpFluids
  StackTrace:
   at CoolPropPINVOKE.AbstractState_factory__SWIG_0(String jarg1, String jarg2)
   at AbstractState.factory(String backend, String fluid_names)
   at SharpFluids.Fluid..ctor(FluidList Type)
   at c03.Program.Main(String[] args) in C:\Users\Danil\Documents\CodingTrainer\c03\Program.cs:line 11

Inner Exception 1:
TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.

Inner Exception 2:
BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)

dll not found when integrating coolprop with unity 3d on mac

After downloading the NuGet package, for some reason the CoolProp dll did not download (though all of the others did). However, when I tried downloading the DLLs from github manually and placing them in my packages (along with the other dll), it still says dll not found exception: coolprop64 cannot be found

using SharpFluids: could not be found in .NET Core

Hello,
on my computer in the console application using SharpFluids; directive doesn't see the library,
in the same time using UnitsNet; points to the library without problem
.NET Core framework version 3.1.302

Thank you

Bug : UpdateAir Moist Air faillure

Hello,

Moist Air Update with HumidityRatio and RelativeHumidity doesn't work.
The exception message is:
Value was either too small or too large for a Decimal.

I try with this :
Air.UpdateAir(Pressure.FromSI(101325), HumidityRatio: ParamIn2Value, RelativeHumidity: ParamIn1Value);
ParamIn2Value is double, 0.011
ParamIn1Value is double, 0.8

Thank you

R407F.mix

Calculating the enthalpy of a mix gas like R407F. Gives an error.

Dim X As New SharpFluids.MediaType("HEOS", "R407F.mix")
Dim R407F As New SharpFluids.Fluid(X)

Exception
System.ApplicationException: 'critical point finding routine found 3 critical points'

Coolprops can calc the enthalpy for this gas, maybe I am using the SharpFluids package wrong.

Thanks

Application breaks when UpdatePT is called in loop after using SetFraction

I'm trying to build an app to get specific heat, density and dynamic viscosity of a mixture based on temperature, pressure and fraction. The way I do it is first SetFraction then call UpdatePT in a loop. However, the application always enter break mode after UpdatePT is called for a number of time.

Here's some simple code that I use to debug the problem:
`
using EngineeringUnits;
using EngineeringUnits.Units;
using SharpFluids;

Fluid Meg = new Fluid(FluidList.MixEthyleneGlycolAQ);
Meg.SetFraction(0.1);
for (var i = 0; i <= 100; i++)
{
Meg.UpdatePT(Pressure.FromAtmospheres(1), Temperature.FromDegreesCelsius(i));
Console.WriteLine("Specific Heat of MEG at " + i + " °C and fraction 0.1: " + Meg.Cp.ToUnit(SpecificEntropyUnit.KilojoulePerKilogramKelvin));
Console.WriteLine("Density of MEG at " + i + " °C and fraction 0.1: " + Meg.Density.KilogramsPerCubicMeter);
Console.WriteLine("Dynamic Viscosity of MEG at " + i + " °C and fraction 0.1: " + Meg.DynamicViscosity.MillipascalSeconds);
}

Meg.SetFraction(0.2);
for (var i = 0; i <= 100; i++)
{
Meg.UpdatePT(Pressure.FromAtmospheres(1), Temperature.FromDegreesCelsius(i));
Console.WriteLine("Specific Heat of MEG at " + i + " °C and fraction 0.2: " + Meg.Cp.ToUnit(SpecificEntropyUnit.KilojoulePerKilogramKelvin));
Console.WriteLine("Density of MEG at " + i + " °C and fraction 0.2: " + Meg.Density.KilogramsPerCubicMeter);
Console.WriteLine("Dynamic Viscosity of MEG at " + i + " °C and fraction 0.2: " + Meg.DynamicViscosity.MillipascalSeconds);
}
`

The error is:
`
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'CoolPropPINVOKE' threw an exception.
Source=SharpFluids
StackTrace:
at CoolPropPINVOKE.delete_DoubleVector(HandleRef jarg1)
at DoubleVector.Dispose()
at DoubleVector.Finalize()

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.

Inner Exception 2:
BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
`

It seems that the application will enter break mode when the second loop reach ~51st time. Even if I use a different fluid, the result is still the same.
Am I doing something wrong or is it a bug?

Fluid Enthalpy should return an Enthalpy type not SpecificEnergy

If I Have the following:
wg = new Fluid(...)

Enthalpy H = wg.Enthalpy

gives an error:
cannot convert from 'EngineeringUnits.SpecificEnergy' to 'EngineeringUnits.Enthalpy'

Why the Fluid doesn't return Enthalpy and a SpecificEnergy?
I can explicitly convert the SpecificEnergy to Enthalpy, I know that, but it ads complexity to the code.

Problem with Thermal Conductivity and Dynamic Viscosity for some refrigerants?

I was performing some refrigerants mapping in order to evaluate the error of CoolProp correlations with respect to Refprop.
For some refrigerants, like R134a and N-Propane, the results match is ok with differences in quantities like enthalpy, density, conductivity and viscosity that are below 1% for the entire subcritical area (i've evaluated the whole temperature field available with pressures up to critical pressure).
On the other hand, for some other refrigerants, like R32, R407C, R410A and R1234ze(Z) i've found that:

  • enthalpy and density are in the +-1% difference range w.r.t. Refprop
  • thermal conductivity and dynamic viscosity have high differnce from Refprop

For example let's consider saturation condition of R407C. In order to retrieve data, I used a for loop where for each iteration the thermo-physical state of the fluid is updated and data of my interest is stored in matrix:

fluid.UpdatePX(Pressure.FromPascals(P[i]), 0);

temperatureSat[i, 0] = fluid.Temperature.As(TemperatureUnit.Kelvin);
enthalpySat[i, 0] = fluid.Enthalpy.As(SpecificEnergyUnit.JoulePerKilogram);
densitySat[i, 0] = fluid.Density.As(DensityUnit.KilogramPerCubicMeter);
conductivitySat[i, 0] = fluid.Conductivity.As(ThermalConductivityUnit.WattPerMeterKelvin);
viscositySat[i, 0] = fluid.DynamicViscosity.As(DynamicViscosityUnit.PascalSecond);

In the code, P[i] is the i-th element of a pressure array ranging from min available pressure for the fluid and critical pressure, and 0 is the quality of the fluid (in this example is reported equal to 0 for saturated liquid curve, but I've done the same for gas phase imposing it to 1).

Performing a comparison between data obtained with the previous code and data retrieved from refprop i obtain the following results ( err X [%] = (value_Refprop - value_code) / (value_Refprop) * 100) where the refprop data is obtained with the same pressure and temperatures obtained from the previous code):
immagine

I've tried to use also a different update approach specifing pressure and saturation temperature but the result is the same.
In order to verify that it's not a CoolProp problem, I've also perform a comparison with data obtained with another wrapper (the one for matlab/octave). In this case the Refprop and Coolprop data are consistent in the whole temperature and pressure range considered.

Furthermore, for R1234ze(Z) conductivity and viscosity are always equal to 0, for any point considered (saturation, subcooled or superheated).

Am I doing something wrong or there's a problem?
Thank you in advance

Added 32bit and 64bit DLLs

Coolprop have both 32bit and 64bit dlls that we can use.
Right now we are only using the 32bit one.

I have tried without luck to add the 64bit dll.

The two tasks to do (As I see it):

  1. When the project builds it should only copy one of the dlls to the Output folder dependent on the chosen architecture
  2. When creating the Nuget Package it should also take the architecture into account

CO2 cannot get the Surface Tension value

#r "nuget: SharpFluids, 3.0.404"

using System.Data;
using EngineeringUnits;
using SharpFluids;

var fluid = new Fluid(FluidList.CO2);
fluid.UpdateXT(1, temperature: Temperature.FromDegreesCelsius(-40.8));

fluid.SurfaceTension.Dump();

the result is 0

but Refprop Excel result =SurfaceTension("co2.fld","tliq","SI with C",-40.8) is 12.86026325 dyne /cm

how can i do next?
thanks

Store FluidList on instantiation?

It would be nice to have a property that contains the FluidList in the object Fluid when Fluid is created. It looks like all that happens is the FluidList in the ctor is used to set up the AbstractState.factory. Any reason this can't be stored in a property?

'The type initializer for 'CoolPropPINVOKE' threw an exception.'

Hello,

Thince few days I have this exception when I test my soft :

System.TypeInitializationException : 'The type initializer for 'CoolPropPINVOKE' threw an exception.'
1/2 : TypeInitializationException : The type initializer for 'SWIGExceptionHelper' threw an exception.
2/2 : BadImageFormatException : Tentative de chargement d’un programme de format incorrect. (0x8007000B)

This exception appear during test but is not exactly during a coolprop calcul.

Thank you,

Fluid.Pressure is counting for 1/10 the expected value

I've been testing some code meant to take user-generated Temperatures and Pressures and a selected fluid and automatically generate a Density and Dynamic Viscosity, and this NuGet package is basically perfect.
However, when testing my code against expected values, I found that I was running pretty far behind them.

For example, Water at 20C and 2300 Pa should give about 998 kg/m3 Density and .0010014 Pas Dyn Visc, but to get those correct outputs, I need the user to put Water at 20*C and 23000 Pa, 10x the Pressure.

For the code, all I'm calling is fluid.UpdatePT(inputPressure, inputTemp), then calling fluid.Density and fluid.DynVisc later. I can confirm that the pressure and Temperature are the correct values when calling this method, and that the properties are properly updated, that is that fluid.Temperature and fluid.Pressure return the same values as the input.

As far as I can tell, it appears that the Pressure is counting for 1/10 the value it should when being used to calculate Density and Dynamic Viscosity at a minimum. I've also tested using different units, double checking the units of the output and the input, and so on. When I call fluid.UpdatePT(inputPressure * 10, inputTemp), I get the expected Density and DynVisc values, but of course the Density is then set to be 10x what the user selected. Any insight into what could be causing this or how to resolve it without changing the Pressure like that would be really appreciated.

some problem in getsattemperature

Why the saturation temperature values obtained using the GetSatTemperature() method cannot be used for the next step of the UpDatePT method? Here is an example of my partially error-free code:
using EngineeringUnits;
using SharpFluids;

namespace methane
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double Qg, Ql, Vg, Vl, P, N, k, Tg, Tl, tk,Pg, Pl, densG,densL,satT,Dg,Ds,I1,I2,r;
private void button1_Click(object sender, EventArgs e)
{

        Qg = double.Parse(textBox1.Text);
        k = double.Parse(textBox2.Text);
        Vg = double.Parse(textBox6.Text);
        Vl = double.Parse(textBox7.Text);
        Tg = double.Parse(textBox3.Text);
        Tl = double.Parse(textBox4.Text);
        P = double.Parse(textBox5.Text) * 0.001;
        Pg = double.Parse(textBox8.Text) + 0.101325;
        Pl = double.Parse(textBox9.Text) + 0.101325;
        //tk = double.Parse(textBox10.Text);
        Fluid fluid = new(FluidList.Methane);
        fluid.UpdatePT(Pressure.FromMegapascal(Pg), Temperature.FromDegreesCelsius(Tg));
        Fluid fluid2 = new(FluidList.Methane);
        fluid2.UpdatePT(Pressure.FromMegapascal(Pl), Temperature.FromDegreesCelsius(Tl));
        densG = fluid.Density.KilogramPerCubicMeter;
        densL = fluid2.Density.KilogramPerCubicMeter;
        Fluid fluid5 = new(FluidList.Methane);
        fluid5.UpdatePT(Pressure.FromMegapascal(Pl), Temperature.FromDegreesCelsius(Tg));
        I1 = fluid5.Enthalpy.KilojoulePerKilogram;
        Fluid fluid3 = new Fluid(FluidList.Methane);
        fluid3.UpdatePT(Pressure.FromMegapascal(Pl), Temperature.FromDegreesCelsius(Tg));
        satT = fluid3.GetSatTemperature(Pressure.FromMegapascal(Pl)).DegreeCelsius;
        Fluid fluid6 = new(FluidList.Methane);
        fluid6.UpdatePT(Pressure.FromMegapascal(Pl), Temperature.FromDegreesCelsius(satT));
        r = fluid6.Enthalpy.KilojoulePerKilogram;

When the above line is running, the last line of code gives an error prompt:“System.NullReferenceException:“Object reference not set to an instance of an object.”
Please help me to answer it, thank you very much

WetBulbTemperature MoistAir bug

Hello,

Moist Air returned value for the Wet Bulb Tempetature is wrong, this is the Dew Point Temperature that is returned,

How correct it?

Thank you

Using SharpFluids in a .Net 4.6.1 Class Library, getting 'Coolprop.dll not found' error after rebuilds

I've been getting an inconsistent issue with SharpFluids since changing a project to a library to add to another, larger project. The first time my project tries to create a fluid with 'Fluid f = new Fluid(FluidList.Water);' I get an exception. It appears that the code is not finding the CoolProp.dll when it tries to convert the FluidList object to a Fluid object. I've confirmed that the CoolProp.dll is present in the Debug folder, and that I'm properly calling 'using SharpFluids;' at the start and all.

Mystifyingly, the workaround I've found so far is to comment out that first 'Fluid f =' line, let my code run, and after it crashes because Fluid f is a null reference object, I un-comment out that code and it runs perfectly fine.

I suspect it's either an issue with the loading order for my project, or maybe it's an issue with the .Net framework I'm using. Any insights at all would be appreciated.

Additional Information:
SharpFluids being used is version 3.0.270 but has been observed on multiple versions
The full error is this: System.TypeInitializationException: The type initializer for 'CoolPropPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'CoolProp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Updating Phase

Hello Community,
I am trying to simulate an originary heatpump with sharpfluids. The pressure of evaporator and compressor is known. Starting with Point 1 (after Evaporator, before Compressor), I have saturated gas. If I check the temperature table it must be the value for Vapor, but SharpFluids always returns the value for Liquid. How can I update the fluid to gas, and later to superheated vapor after the compressor?

The difference with water and IF97::water?

According to the coolprop document , "Water is the only fluid name that can be specified, as IF97::Water". In SharpFluid, only water can be specified in fluidlist. I solved the water property with the pressure and temperature the same as coolprop property, and the result has a little difference. I don't know the reason. Is there any difference with water and IF97::water? Should we define a IF97::water so that we can invoke a IF97water?
image

Thread Unsafe XUnit Testing

Hi MadsKirkFoged,

As promised, here is a bug report demonstrating thread unsafe-ness of coolprop using sharpfluids.

I made an xunit test:

dotnet new xunit --output threadSafetyTestSharpFluids

and i made two identical unit tests and placed them under two files:
UnitTest1.cs
UnitTest2.cs

Here are the codes for each unit test respectively.

using EngineeringUnits;
using EngineeringUnits.Units;
using SharpFluids;
using Xunit;
using System;
using Xunit.Abstractions;


namespace therminolPipeTest;

public class UnitTest1 
{

	[Theory]
	[InlineData(20,1064)]
	[InlineData(30,1056)]
	[InlineData(40,1048)]
	[InlineData(50,1040)]
	[InlineData(60,1032)]
	[InlineData(70,1024)]
	[InlineData(80,1015)]
	[InlineData(90,1007)]
	[InlineData(100,999)]
	[InlineData(110,991)]
	[InlineData(120,982)]
	[InlineData(130,974)]
	[InlineData(140,965)]
	[InlineData(150,957)]
	[InlineData(160,948)]
	[InlineData(180,931)]
	public void WhenTherminolObjectTestedExpectVendorDensityValue(
			double temperatureC, double densityValueKgPerM3){

		//Setup


		// set temperature and pressure for dowtherm and Therminol
		Pressure referencePressure = new Pressure(1.1013e5, PressureUnit.Pascal);
		EngineeringUnits.Temperature testTemperature 
			= new EngineeringUnits.Temperature(temperatureC, 
					TemperatureUnit.DegreeCelsius);

		// get therminol VP-1 fluid object
		Fluid therminol = new Fluid(FluidList.InCompTherminolVP1);

		// Act
		therminol.UpdatePT(referencePressure, testTemperature);

		Density resultDensity = therminol.Density;

		// Assert 
		//
		// Check if densities are equal to within 0.2% of vendor data
	
		double errorMax = 0.2/100;
		double resultDensityValueKgPerM3 = resultDensity.
			As(DensityUnit.KilogramPerCubicMeter);
		double error = Math.Abs(resultDensityValueKgPerM3 - 
				densityValueKgPerM3)/densityValueKgPerM3;

		if (error < errorMax){
			return;
		}
		if (error > errorMax){

		Assert.Equal(densityValueKgPerM3, 
				resultDensity.As(DensityUnit.KilogramPerCubicMeter),
				0);
		}
		
	}


}

And,

using EngineeringUnits;
using EngineeringUnits.Units;
using SharpFluids;
using Xunit;
using System;
using Xunit.Abstractions;


namespace therminolPipeTest;

public class UnitTest2 
{

	[Theory]
	[InlineData(20,1064)]
	[InlineData(30,1056)]
	[InlineData(40,1048)]
	[InlineData(50,1040)]
	[InlineData(60,1032)]
	[InlineData(70,1024)]
	[InlineData(80,1015)]
	[InlineData(90,1007)]
	[InlineData(100,999)]
	[InlineData(110,991)]
	[InlineData(120,982)]
	[InlineData(130,974)]
	[InlineData(140,965)]
	[InlineData(150,957)]
	[InlineData(160,948)]
	[InlineData(180,931)]
	public void WhenTherminolObjectTestedExpectVendorDensityValue(
			double temperatureC, double densityValueKgPerM3){

		//Setup


		// set temperature and pressure for dowtherm and Therminol
		Pressure referencePressure = new Pressure(1.1013e5, PressureUnit.Pascal);
		EngineeringUnits.Temperature testTemperature 
			= new EngineeringUnits.Temperature(temperatureC, 
					TemperatureUnit.DegreeCelsius);

		// get therminol VP-1 fluid object
		Fluid therminol = new Fluid(FluidList.InCompTherminolVP1);

		// Act
		therminol.UpdatePT(referencePressure, testTemperature);

		Density resultDensity = therminol.Density;

		// Assert 
		//
		// Check if densities are equal to within 0.2% of vendor data
	
		double errorMax = 0.2/100;
		double resultDensityValueKgPerM3 = resultDensity.
			As(DensityUnit.KilogramPerCubicMeter);
		double error = Math.Abs(resultDensityValueKgPerM3 - 
				densityValueKgPerM3)/densityValueKgPerM3;

		if (error < errorMax){
			return;
		}
		if (error > errorMax){

		Assert.Equal(densityValueKgPerM3, 
				resultDensity.As(DensityUnit.KilogramPerCubicMeter),
				0);
		}
		
	}


}

Now running both of these using dotnet watch test yields:

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.ApplicationException: FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (System.ApplicationException: This backend does not implement calc_phase function)
 ---> System.ApplicationException: calc_compressibility_factor is not implemented for this backend
   --- End of inner exception stack trace ---
   at CoolPropPINVOKE64.SWIGPendingException.Set(Exception e)
   at CoolPropPINVOKE64.SWIGExceptionHelper.SetPendingApplicationException(String message)


Test Run Aborted with error System.Exception: One or more errors occurred.
 ---> System.Exception: Unable to read beyond the end of the stream.
   at System.IO.BinaryReader.ReadByte()
   at System.IO.BinaryReader.Read7BitEncodedInt()
   at System.IO.BinaryReader.ReadString()
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable()
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---.
watch : Exited with error code 1
watch : Waiting for a file to change before restarting dotnet...

This happens with almost absolute certainty.

If you put the same classes in the same unit test, it will also throw some sort of race condition like error.

In fat i've gotten

Test host process crashed: malloc(): unaligned tcache chunk detected

So this can show that coolprop is definitely not thread safe.

How to solve it? I haven't quite thought of it lol... It's just quite the headache now.

Fluid.UpdateHT not supported?

When I call methods for updating thermophysical properties of the fluid, the only one method that does not work properly throwing me an exception is UpdateHT:
System.ApplicationException: 'This pair of inputs [HmassT_INPUTS] is not yet supported'
This exception is due to an effective non-implemented method or there’s some bug inside?

Thank you

Freezing point

Hello!

Do you consider Tmin as a freezing point as well? I cannot find a property of Tfreeze.

EDIT: never mind. I found the property called melting line. That was the property I was looking for.

  • Atte

R454B Run An Exception

Hello
When I try get the properties of R454B, the following exception is shown and other properties such as critical temperatures and pressures are very high.

solver_rho_Tp was unable to find a solution for T= 448.369, p=6.31699e+07, with guess value 12028.2 with error: The molar density of -44003.133110 mol/m3 is below the minimum of 0.000000 mol/m3

Here is my code where above exception is raised

var fluid = FluidList.R454B_mix; Fluid test = new Fluid(fluid);

Problème

exemple :

    {
        Fluid r134a = new Fluid(FluidList.R134a);
        r134a.UpdatePT(Pressure.FromBars(2), Temperature.FromDegreesCelsius(13));
        string densité = toString(r134a.Entropy);
    }

comment récuperer la valeur pour pouvoir calculer avec après et la convertir en string ?

CO2 input limitations or inproper table link?

Hi MadsKirkFoged,

I've stumbled across some weird results during my mixtures calculations. Upon further examinations it turns out that CO2 part wasn't updating it's status at all. It happens at low pressures and low temperatures (relatively). I was wondering if this has something to do with input limits or is there some error in CO2 table, because CoolProp Online ans NIST Database seems to have proper results in this range. Below is a simple code I wrote for this test. (Enthalpy passed as an input in last line is proper enthalpy at 1 bar and 273 K according to CoolProp Online).

using SharpFluids;
using EngineeringUnits;
using EngineeringUnits.Units;


double press = 101000;
double temp = 273;
Fluid CO2 = new Fluid(FluidList.CO2);

CO2.UpdatePT(Pressure.FromPascals(press), Temperature.FromKelvins(temp));
Console.WriteLine(CO2.Density.As(DensityUnit.KilogramPerCubicMeter));
CO2.UpdatePT(Pressure.FromBars(5), Temperature.FromDegreesCelsius(150));
Console.WriteLine(CO2.Density.As(DensityUnit.KilogramPerCubicMeter));
CO2.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(300));
Console.WriteLine(CO2.Density.As(DensityUnit.KilogramPerCubicMeter));
CO2.UpdatePH(Pressure.FromBars(1), Enthalpy.FromKilojoulePerKilogram(484.749));
Console.WriteLine(CO2.Density.As(DensityUnit.KilogramPerCubicMeter));

And here are the results:

0
0
9,26798114913052
9,26798114913052

I'm not sure what to do with this. Thank you for any help :)

Best Regards

R513A

Hello,
I am trying to use the NuGet pack and I am interested in some R513A properties. Following my code:

  •         MediaType MediaFluid = new MediaType("HEOS", "R513A.MIX");
    
  •         Fluid my_fluid = new Fluid(MediaFluid);
    
  •         my_fluid.UpdatePX(Pressure.FromBars(9), 0.0);
    

Is it the right way to initialize R513A? Is R513A in the FluidList?

From the call my_fluid.UpdatePX(Pressure.FromBars(9), 0.0) I don’t obtain any exceptions however all the properties are equal to zero. I am particular interested to obtain the saturation temperature at a given pressure. Are there any ways to obtain this value?

Thanks in advanced.

Andrea

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.