MadsKirkFoged / SharpFluids

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

some problem in getsattemperature #54

Open johnhe001 opened 2 months ago

johnhe001 commented 2 months ago

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

MadsKirkFoged commented 2 months ago

Could you create a working stand-alone working example with hardcoded values? That way it is easier for me to test it out

johnhe001 commented 2 months ago

Thank you for your response! below is an independent working example with hardcoded values. I want to calculate the saturation temperature of methane based on pressure, then update the temperature and pressure of the methane to ultimately determine its enthalpy value. However, when the program runs, the code throws an error, specifically on this line: double I1 = fluid2.Enthalpy.KilojoulePerKilogram;. The error is: System.NullReferenceException: 'Object reference not set to an instance of an object.' SharpFluids.Fluid.Enthalpy.get returns null.

using EngineeringUnits; using SharpFluids; namespace nitrogen { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Fluid fluid = new Fluid(FluidList.Methane); double satT = fluid.GetSatTemperature(Pressure.FromMegapascal(0.7)).DegreeCelsius; Fluid fluid2 = new Fluid(FluidList.Methane); fluid2.UpdatePT(Pressure.FromMegapascal(0.7), Temperature.FromDegreesCelsius(satT)); double I1 = fluid2.Enthalpy.KilojoulePerKilogram; } } }

------------------ 原始邮件 ------------------ 发件人: "MadsKirkFoged/SharpFluids" @.>; 发送时间: 2024年6月26日(星期三) 下午4:08 @.>; 抄送: "何毅 储运1901班 @.**@.>; 主题: Re: [MadsKirkFoged/SharpFluids] some problem in getsattemperature (Issue #54)

Could you create a working stand-alone working example with hardcoded values? That way it is easier for me to test it out

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>