MadsKirkFoged / SharpFluids

Lightweight CoolProp C# Wrapper - for easy fluid properties lookups
MIT License
30 stars 9 forks source link

R513A #15

Open AndreaVIC opened 3 years ago

AndreaVIC commented 3 years ago

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

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

MadsFoged commented 3 years ago

Hi AndreaVIC,

R513A is not yet in SharpFluids's official List however it is in CoolProp's list, thats why it kinda works for you. For some reason coolprop cant return R513A's Critical Pressure which is used inside 'UpdatePX' -thats way it doesnt work for you.

I have created a new release that should work for you. Can you try to download the newest NuGet and test it out?

AndreaVIC commented 3 years ago

Thank you MadsFoged! It works perfectly!

Andrea

AndreaVIC commented 3 years ago

Probably there is the same problem also here:

my_fluid.UpdatePS(Pressure.FromBars(9), UnitsNet.Entropy.FromJoulesPerKelvin(1699.7));

Could you fix the issue? Thanks again

Andrea

MadsFoged commented 3 years ago

Coolprop gives me this error when I try: phase envelope must be built to carry out HSU_P_flash for mixture

It looks like it is a CoolProp problem: https://github.com/CoolProp/CoolProp/issues/2000

ibell commented on 14 Feb For mixtures, you will probably need REFPROP. The mixture routines in CoolProp are not very stable, and those of REFPROP are much better.

This is the reason I haven't yet been supporting mixtures, it is simply not stable enough.

MadsFoged commented 3 years ago

However if you want you could build a binary search to search for the entropy you need.

If you use my_fluid.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(x)); You can read out the entropy and guess the next temperature to lookup

Does that make sense?

AndreaVIC commented 3 years ago

Thanks for the suggestion. It is probably more time-consuming procedure but it could work. Before moving to Refprop I am going to follow this approach and if you are interested I can share the algorithm.

Thanks again

Andrea

MadsFoged commented 3 years ago

It could be as simple as this:

            MediaType MediaFluid = new MediaType("HEOS", "R513A.MIX");
            Fluid my_fluid = new Fluid(MediaFluid);

            //This is want we are aiming for
            Entropy Aim = Entropy.FromJoulesPerKelvin(1699.7);

            Temperature Max = my_fluid.LimitTemperatureMax;
            Temperature Min = my_fluid.LimitTemperatureMin;
            Temperature Mid = Temperature.Zero;   

            for (int i = 0; i < 20; i++)
            {

                Mid = Temperature.FromKelvins((Max.Kelvins + Min.Kelvins) / 2);

                my_fluid.UpdatePT(Pressure.FromBars(10), Mid);

                if (my_fluid.Entropy > Aim) 
                    Max = Mid;
                else
                    Min = Mid;

            }
MadsFoged commented 3 years ago

With the neweste verion you can get the fluid using:

Fluid my_fluid = new Fluid(FluidList.R513A_mix);

AndreaVIC commented 3 years ago

Thanks, the new string for R513A works for me. Following my custom UpdatePS function:

private void My_UpdatePS(ref Fluid my_fluid,double my_Entropy, double ref_Pressure)
{

    // my_Entropy:   J/(kg*K)
    // ref_Pressure: Pa

    double error = my_Entropy;                  // Function error
    double stop_error = my_Entropy * 1e-3/100;  // Stop error

    //This is want we are aiming for:
    Entropy Aim = Entropy.FromJoulesPerKelvin(my_Entropy);

    //Interval:
    Temperature Max = my_fluid.LimitTemperatureMax;
    Temperature Min = my_fluid.LimitTemperatureMin;
    Temperature Mid = Temperature.Zero;

    int iter = 0;
    while(error > stop_error & iter < 20)
    {

        Mid = Temperature.FromKelvins((Max.Kelvins + Min.Kelvins) / 2);

        my_fluid.UpdatePT(Pressure.FromPascals(ref_Pressure), Mid);

        if (my_fluid.Entropy > Aim)
            Max = Mid;
        else
            Min = Mid;

        iter++;
        error = Math.Abs(my_fluid.Entropy.JoulesPerDegreeCelsius - Aim.JoulesPerDegreeCelsius);
    }
}