Example #1
0
        public Substance(Pressure pressure, Enthalpy enthalpy)
        {
            Pressure = pressure;

            //Checking what region the Substanse belong to:

            //1. check if it is region 1
            try
            {
                Temperature = new Temperature(Region1BackwardEquation_Tph.CalculateTemperature(pressure.Value, enthalpy.Value));
                CalculateProperties(Temperature, Pressure);
            }
            catch (CantDetermineRegionException)
            { }
            if (SpecificEnthalpy != null && Math.Round(SpecificEnthalpy.Value) == Math.Round(enthalpy.Value))
            {
                //it is region 1
                return;
            }

            //2. check if it is region 2

            if (pressure.Value <= 4)
            {
                Temperature = new Temperature(Region2aBackwardEquation_Tph.CalculateTemperature(pressure.Value, enthalpy.Value));
                CalculateProperties(Temperature, Pressure);
                if (Math.Round(SpecificEnthalpy.Value, 1) == Math.Round(enthalpy.Value, 1))
                {
                    //it is region 2a
                    return;
                }
            }
            else if (Region2B2bcEquation.is2cSubregion(pressure.Value, enthalpy.Value) == false)
            {
                Temperature = new Temperature(Region2bBackwardEquation_Tph.CalculateTemperature(pressure.Value, enthalpy.Value));
                CalculateProperties(Temperature, Pressure);
                if (Math.Round(SpecificEnthalpy.Value, 1) == Math.Round(enthalpy.Value, 1))
                {
                    //it is region 2b
                    return;
                }
            }
            else if (Region2B2bcEquation.is2cSubregion(pressure.Value, enthalpy.Value))
            {
                Temperature = new Temperature(Region2cBackwardEquation_Tph.CalculateTemperature(pressure.Value, enthalpy.Value));
                CalculateProperties(Temperature, Pressure);
                if (Math.Round(SpecificEnthalpy.Value, 1) == Math.Round(enthalpy.Value, 1))
                {
                    //it is region 2c
                    return;
                }
            }
            else
            {
                throw new CantDetermineRegionException("It seems no region fits to these values pressure and enthalpy");
            }
        }
Example #2
0
 private void Region5Calculations(Temperature temperature, Pressure pressure)
 {
     Temperature                   = temperature;
     Pressure                      = pressure;
     SpecificVolume                = Region5.CalculateSpecificVolume(temperature.Value, pressure.Value);
     SpecificEnthalpy              = new Enthalpy(Region5.CalculateSpecificEnthalpy(temperature.Value, pressure.Value));
     SpecificInternalEnergy        = Region5.CalculateSpecificInternalEnergy(temperature.Value, pressure.Value);
     SpecificEntropy               = new Entropy(Region5.CalculateSpecificEntropy(temperature.Value, pressure.Value));
     SpecificIsobaricHeatCapacity  = Region5.SpecificIsobaricHeatCapacity(temperature.Value, pressure.Value);
     SpeedOfSound                  = Region5.SpeedOfSound(temperature.Value, pressure.Value);
     SpecificIsochoricHeatCapacity = Region5.SpecificIsochoricHeatCapacity(temperature.Value, pressure.Value);
 }
Example #3
0
        public override int GetHashCode()
        {
            var hashCode = 570931003;

            hashCode = hashCode * -1521134295 + Region.GetHashCode();
            hashCode = hashCode * -1521134295 + VaporMassFraction.GetHashCode();
            hashCode = hashCode * -1521134295 + LiquidMassFraction.GetHashCode();
            hashCode = hashCode * -1521134295 + SolidMassFraction.GetHashCode();
            hashCode = hashCode * -1521134295 + Temperature.GetHashCode();
            hashCode = hashCode * -1521134295 + Pressure.GetHashCode();
            hashCode = hashCode * -1521134295 + SpecificVolume.GetHashCode();
            hashCode = hashCode * -1521134295 + InternalEnergy.GetHashCode();
            hashCode = hashCode * -1521134295 + Enthalpy.GetHashCode();
            hashCode = hashCode * -1521134295 + Entropy.GetHashCode();
            hashCode = hashCode * -1521134295 + IsochoricHeatCapacity.GetHashCode();
            hashCode = hashCode * -1521134295 + IsobaricHeatCapacity.GetHashCode();
            hashCode = hashCode * -1521134295 + SpeedOfSound.GetHashCode();
            hashCode = hashCode * -1521134295 + Density.GetHashCode();
            return(hashCode);
        }
Example #4
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Debug()
                         .CreateLogger();

            Log.Information("Hello, world!");



            MoistAir Air = new MoistAir();

            Air.UpdateAir(Pressure.FromBars(1),
                          DryBulbTemperature: Temperature.FromDegreesCelsius(20),
                          RelativeHumidity: 0.7

                          );

            Air.UpdateAir(Pressure.FromBars(1), HumidityRatio: 0.010397090640274141, RelativeHumidity: 0.7);
            //Air.UpdateAir(Pressure.FromSI(101325), HumidityRatio: 0.011, RelativeHumidity: 0.8);



            Fluid R407C = new Fluid(FluidList.R407C);

            R407C.UpdatePX(Pressure.FromMegapascals(4.022736), 0);



            Fluid Ammonia = new Fluid(FluidList.Ammonia);


            var test11 = Ammonia.GetEnvelopePhase();


            Ammonia.UpdatePX(Pressure.FromBars(25), 0.5);

            Ammonia.UpdateDH(Ammonia.Density, Ammonia.Enthalpy);


            Ammonia.UpdatePT(Pressure.FromSI(2293443.57087332), Temperature.FromSI(405.55873230045091));

            Ammonia.UpdatePT(Pressure.FromSI(2493443), Temperature.FromSI(410));


            Fluid r134a = new Fluid(FluidList.R134a);

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



            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²

            Console.WriteLine(area.GetHashCode());

            Fluid R717 = new Fluid(FluidList.Ammonia);

            R717.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(100));

            Fluid R717Clone = R717.Clone();

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

            //Fluid test12 = new Fluid(FluidList.Custom_SHC226E);



            //test12.updateAir("H","T",298.15,"P",101325,"R",0.5);


            Air.UpdateAir(Pressure.FromBars(1),
                          DryBulbTemperature: Temperature.FromKelvins(298.15),
                          RelativeHumidity: 0.5

                          );

            Debug.Print($"WetBulbTemperature: {Air.WetBulbTemperature}");
            Debug.Print($"DewPointTemperature: {Air.DewPointTemperature}");
            Debug.Print($"DryBulbTemperature: {Air.Temperature}");

            Debug.Print($"RelativeHumidity: {Air.RelativeHumidity * 100} % ");
            Debug.Print($"HumidityRatio: {Air.HumidityRatio} kg/kg");



            Enthalpy H = Air.Enthalpy;


            int totalcount = 10000;
            var watch      = System.Diagnostics.Stopwatch.StartNew();


            for (int i = 0; i < totalcount; i++)
            {
                Air.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(10));
                Air.UpdatePT(Pressure.FromBars(2), Temperature.FromDegreesCelsius(300));
            }


            watch.Stop();
            Log.Information($"Time: {watch.ElapsedTicks / totalcount}");



            string jsonString1 = JsonConvert.SerializeObject(Air);
            Fluid  testJSON    = JsonConvert.DeserializeObject <Fluid>(jsonString1);
            string jsonString2 = JsonConvert.SerializeObject(testJSON);

            Debug.Print($"{jsonString1 == jsonString2}");

            testJSON.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(10));



            var howManyBytes = jsonString1.Length * sizeof(Char);


            Debug.Print($"Size is: {howManyBytes}");



            //................................................

            Fluid test = new Fluid(FluidList.Water);

            test.UpdatePT(Pressure.FromBars(3), Temperature.FromDegreesCelsius(20));
            test.MassFlow = MassFlow.FromKilogramsPerSecond(1);


            //for (int i = 0; i < 100000; i++)
            //{
            //    test.AddPower(Power.FromWatts(1));
            //}

            Debug.Print("");



            ////Arrange
            //foreach (FluidList suit in (FluidList[])Enum.GetValues(typeof(FluidList)))
            //{
            //    //Arrange
            //    Fluid TestFluid = new Fluid(suit);


            //    using (var loggerFactory = LoggerFactory.Create(builder =>
            //    { builder.AddConsole(); }))

            //    {
            //        ILogger logger = loggerFactory.CreateLogger<Program>();
            //        //logger.LogInformation("Logging has stared");
            //        TestFluid.Log = logger;

            //    }


            //    Debug.Print(TestFluid.Media.InternalName);
            //    TestFluid.Log.LogInformation(TestFluid.Media.InternalName);

            //    TestFluid.GetEnvelopePhase();



            //}



            ////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;

            //}



            //my_fluid.UpdatePX(Pressure.FromBars(9), 0.0);

            // Fluid test = new Fluid(FluidList.Water);
            test.UpdatePT(Pressure.FromBars(-10), Temperature.FromDegreesCelsius(300));
            test.UpdatePT(Pressure.FromBars(100000), Temperature.FromDegreesCelsius(300));
            test.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(30000));

            test.UpdatePH(Pressure.FromBars(2), SpecificEnergy.FromKilojoulesPerKilogram(10740.5));

            test.MassFlow = MassFlow.FromKilogramsPerSecond(-0.0054);
            test.AddPower(Power.FromWatts(-86982.42));



            //Fluid r134a = new Fluid(FluidList.R134a);
            r134a.UpdatePT(Pressure.FromBars(2), Temperature.FromDegreesCelsius(13));
            string densité = r134a.Density.MilligramsPerCubicMeter.ToString();

            Density Result = r134a.Density;



            //Arrange
            //Fluid R717 = new Fluid(FluidList.Ammonia);
            Density        setDensity  = Density.FromKilogramsPerCubicMeter(15.36622602626586);
            SpecificEnergy setEnthalpy = SpecificEnergy.FromJoulesPerKilogram(1043420.2106074861);
            Mass           setMass     = Mass.FromKilograms(43);

            setMass = setMass.ToUnit(MassUnit.Decagram);



            //Act
            R717.UpdateDH(setDensity, setEnthalpy);
            R717.Mass = setMass;

            //Save as JSON
            string json = R717.SaveAsJSON();


            //Start new fluid and load as json
            Fluid R717JSON = R717.LoadFromJSON(json);

            Temperature test1 = R717JSON.Tsat;



            //Find the Density of water at 13°C
            Fluid Water = new Fluid(FluidList.Water);

            Water.UpdatePT(Pressure.FromBars(1.013), Temperature.FromDegreesCelsius(13));
            Console.WriteLine("Density of water at 13°C: " + Water.Density);



            Water.UpdateHS(SpecificEnergy.FromJoulesPerKilogram(54697.59), SpecificEntropy.FromJoulesPerKilogramKelvin(195.27));

            Debug.Print("Density of water is: " + Water.Density);

            //Giving water a Massflow
            Water.MassFlow = MassFlow.FromKilogramsPerHour(100);

            //What is the volumeFlow for this water?
            Console.WriteLine("VolumeFlow of the water: " + Water.VolumeFlow);

            //What is the boiling point of the water?
            Water.UpdatePX(Pressure.FromBars(1.013), 0);             //X=0 it is 100% liquid and 0% gas but at it boiling point
            Console.WriteLine("Boiling point of this water is: " + Water.Temperature);

            //..and if you want to display it in another unit
            Console.WriteLine("Boiling point of this water is: " + Water.Temperature.ToUnit(TemperatureUnit.DegreeCelsius));

            //Display Dynamic Viscosity of the water
            Console.WriteLine("Dynamic Viscosity of this water is: " + Water.DynamicViscosity);



            //Create a CO2 fluid
            Fluid ref1 = new Fluid(FluidList.CO2);

            //Update it with 25bar and X=1
            ref1.UpdatePX(Pressure.FromBars(25), 1);

            Console.WriteLine(ref1.Cp);
            Console.WriteLine(ref1.Temperature);
            Console.WriteLine("Prandtl is : " + ref1.Prandtl);
            Console.WriteLine("Cp is : " + ref1.Cp);
            Console.WriteLine("Cv is : " + ref1.Cv);
            Console.WriteLine("Surface Tension is : " + ref1.SurfaceTension);
            Console.WriteLine("Density is : " + ref1.Density);


            //A Fluid that is a mix of Ammonia and water
            Fluid ref2 = new Fluid(FluidList.MixAmmoniaAQ);


            //Set the fraction between ammonia(80%) and water(20%)
            ref2.SetFraction(0.3);

            //Update it with 10bars and 10°C
            ref2.UpdatePT(Pressure.FromBars(10), Temperature.FromDegreesCelsius(10));


            //Copy fluid type
            Fluid ref3 = new Fluid();

            ref3.CopyType(ref1);
            ref3.UpdatePX(Pressure.FromBars(25), 1);

            Console.WriteLine(ref3.Cp);
            Console.WriteLine(ref3.Temperature);
            Console.WriteLine("Prandtl is : " + ref3.Prandtl);
            Console.WriteLine("Cp is : " + ref3.Cp);
            Console.WriteLine("Cv is : " + ref3.Cv);
            Console.WriteLine("Surface Tension is : " + ref3.SurfaceTension);

            //Saving and loading to JSON
            Fluid  ref4 = new Fluid();
            string JSON = ref3.SaveAsJSON();

            ref4 = ref4.LoadFromJSON(JSON);

            Console.WriteLine(ref4.Cp);
            Console.WriteLine(ref4.Temperature);
            Console.WriteLine("Prandtl is : " + ref4.Prandtl);
            Console.WriteLine("Cp is : " + ref4.Cp);
            Console.WriteLine("Cv is : " + ref4.Cv);
            Console.WriteLine("Surface Tension is : " + ref4.SurfaceTension);

            ref4.UpdatePX(Pressure.FromBars(45), 1);

            Console.WriteLine(ref4.Cp);
            Console.WriteLine(ref4.Temperature);
            Console.WriteLine("Prandtl is : " + ref4.Prandtl);
            Console.WriteLine("Cp is : " + ref4.Cp);
            Console.WriteLine("Cv is : " + ref4.Cv);
            Console.WriteLine("Surface Tension is : " + ref4.SurfaceTension);

            ref4.UpdatePX(Pressure.FromBars(25), 1);

            Console.WriteLine(ref4.Cp);
            Console.WriteLine(ref4.Temperature);
            Console.WriteLine("Prandtl is : " + ref4.Prandtl);
            Console.WriteLine("Cp is : " + ref4.Cp);
            Console.WriteLine("Cv is : " + ref4.Cv);
            Console.WriteLine("Surface Tension is : " + ref4.SurfaceTension);

            Console.WriteLine(ref2.Density);

            Fluid ref5 = new Fluid();

            ref5.Copy(ref4);

            Console.ReadKey();
        }