コード例 #1
0
        public void Powerequation()
        {
            //Q = m * Cp * dT

            //obs - UnitsNet cant do this eq..


            EngineeringUnits.SpecificEntropy P1 = new EngineeringUnits.SpecificEntropy(1, EngineeringUnits.SpecificEntropyUnit.JoulePerKilogramKelvin);
            EngineeringUnits.MassFlow        M1 = new EngineeringUnits.MassFlow(1, EngineeringUnits.MassFlowUnit.KilogramPerSecond);
            EngineeringUnits.Temperature     T2 = new EngineeringUnits.Temperature(10, EngineeringUnits.TemperatureUnit.DegreeCelsius);
            EngineeringUnits.Temperature     T1 = new EngineeringUnits.Temperature(5, EngineeringUnits.TemperatureUnit.DegreeCelsius);

            EngineeringUnits.Power Q1 = M1 * P1 * (T2 - T1);



            UnitsNet.SpecificEntropy p1 = new UnitsNet.SpecificEntropy(1, UnitsNet.Units.SpecificEntropyUnit.JoulePerKilogramKelvin);
            UnitsNet.MassFlow        m1 = new UnitsNet.MassFlow(1, UnitsNet.Units.MassFlowUnit.KilogramPerSecond);
            UnitsNet.Temperature     t2 = new UnitsNet.Temperature(10, UnitsNet.Units.TemperatureUnit.DegreeCelsius);
            UnitsNet.Temperature     t1 = new UnitsNet.Temperature(5, UnitsNet.Units.TemperatureUnit.DegreeCelsius);

            UnitsNet.Power q1 = UnitsNet.Power.FromWatts(p1.JoulesPerKilogramKelvin * m1.KilogramsPerSecond * (t2.Kelvins - t1.Kelvins));



            Assert.AreEqual(0, Q1.As(EngineeringUnits.PowerUnit.BritishThermalUnitPerHour) - q1.As(UnitsNet.Units.PowerUnit.BritishThermalUnitPerHour), 7.2E-05);
            Assert.AreEqual(0, Q1.As(EngineeringUnits.PowerUnit.Kilowatt) - q1.As(UnitsNet.Units.PowerUnit.Kilowatt), 0);
            Assert.AreEqual(0, Q1.As(EngineeringUnits.PowerUnit.Watt) - q1.As(UnitsNet.Units.PowerUnit.Watt), 0);
        }
コード例 #2
0
        public void Powerequation2()
        {
            //Q = m * Cp * dT

            //obs - UnitsNet cant do this eq..


            EngineeringUnits.SpecificEntropy P1 = new EngineeringUnits.SpecificEntropy(35345, EngineeringUnits.SpecificEntropyUnit.BtuPerPoundRankine);
            EngineeringUnits.MassFlow        M1 = new EngineeringUnits.MassFlow(4356, EngineeringUnits.MassFlowUnit.PoundPerMinute);
            EngineeringUnits.Temperature     T2 = new EngineeringUnits.Temperature(342, EngineeringUnits.TemperatureUnit.DegreeRankine);
            EngineeringUnits.Temperature     T1 = new EngineeringUnits.Temperature(43, EngineeringUnits.TemperatureUnit.DegreeRankine);

            EngineeringUnits.Power Q1 = M1 * P1 * (T2 - T1);



            UnitsNet.SpecificEntropy p1 = new UnitsNet.SpecificEntropy(35345, UnitsNet.Units.SpecificEntropyUnit.BtuPerPoundFahrenheit);
            UnitsNet.MassFlow        m1 = new UnitsNet.MassFlow(4356, UnitsNet.Units.MassFlowUnit.PoundPerMinute);
            UnitsNet.Temperature     t2 = new UnitsNet.Temperature(342, UnitsNet.Units.TemperatureUnit.DegreeRankine);
            UnitsNet.Temperature     t1 = new UnitsNet.Temperature(43, UnitsNet.Units.TemperatureUnit.DegreeRankine);

            UnitsNet.Power q1 = UnitsNet.Power.FromWatts(p1.JoulesPerKilogramKelvin * m1.KilogramsPerSecond * (t2.Kelvins - t1.Kelvins));



            //BtuPerPoundFahrenheit-- > JoulePerKilogramKelvin
            //UnitsNet: 4186,8
            //EngineeringUnits: 4186,816458133984
            //UnitsNet dont not use a high precision for this conversion which gives a off result

            //Difference in procent
            Assert.AreEqual(0, HelperClass.Percent(P1.As(EngineeringUnits.SpecificEntropyUnit.JoulePerKilogramKelvin),
                                                   p1.As(UnitsNet.Units.SpecificEntropyUnit.JoulePerKilogramKelvin)), 0.0004);

            Assert.AreEqual(0, HelperClass.Percent(P1.As(EngineeringUnits.SpecificEntropyUnit.BtuPerPoundRankine),
                                                   p1.As(UnitsNet.Units.SpecificEntropyUnit.BtuPerPoundFahrenheit)), 0);

            Assert.AreEqual(0, HelperClass.Percent(M1.As(EngineeringUnits.MassFlowUnit.KilogramPerSecond),
                                                   m1.As(UnitsNet.Units.MassFlowUnit.KilogramPerSecond)), 0.0003);



            //Assert.AreEqual(0, Q1.As(EngineeringUnits.PowerUnit.BritishThermalUnitPerHour) - q1.As(UnitsNet.Units.PowerUnit.BritishThermalUnitPerHour), 0);
            //Assert.AreEqual(0, Q1.As(EngineeringUnits.PowerUnit.Kilowatt) - q1.As(UnitsNet.Units.PowerUnit.Kilowatt), 0);
            //Assert.AreEqual(0, Q1.As(EngineeringUnits.PowerUnit.Watt) - q1.As(UnitsNet.Units.PowerUnit.Watt), 0);

            //Difference in procent
            Assert.AreEqual(0, HelperClass.Percent(Q1.As(EngineeringUnits.PowerUnit.BritishThermalUnitPerHour),
                                                   q1.As(UnitsNet.Units.PowerUnit.BritishThermalUnitPerHour)), 0.0003);

            Assert.AreEqual(0, HelperClass.Percent(Q1.As(EngineeringUnits.PowerUnit.Kilowatt),
                                                   q1.As(UnitsNet.Units.PowerUnit.Kilowatt)), 0.00013);

            Assert.AreEqual(0, HelperClass.Percent(Q1.As(EngineeringUnits.PowerUnit.Watt),
                                                   q1.As(UnitsNet.Units.PowerUnit.Watt)), 0.00013);
        }
コード例 #3
0
        /// <summary>
        ///     <para>
        ///     Compare equality to another Power within the given absolute or relative tolerance.
        ///     </para>
        ///     <para>
        ///     Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
        ///     <paramref name="other"/> as a percentage of this quantity's value. <paramref name="other"/> will be converted into
        ///     this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
        ///     this quantity's value to be considered equal.
        ///     <example>
        ///     In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
        ///     <code>
        ///     var a = Length.FromMeters(2.0);
        ///     var b = Length.FromInches(50.0);
        ///     a.Equals(b, 0.01, ComparisonType.Relative);
        ///     </code>
        ///     </example>
        ///     </para>
        ///     <para>
        ///     Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
        ///     <paramref name="other"/> as a fixed number in this quantity's unit. <paramref name="other"/> will be converted into
        ///     this quantity's unit for comparison.
        ///     <example>
        ///     In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
        ///     <code>
        ///     var a = Length.FromMeters(2.0);
        ///     var b = Length.FromInches(50.0);
        ///     a.Equals(b, 0.01, ComparisonType.Absolute);
        ///     </code>
        ///     </example>
        ///     </para>
        ///     <para>
        ///     Note that it is advised against specifying zero difference, due to the nature
        ///     of floating point operations and using System.Double internally.
        ///     </para>
        /// </summary>
        /// <param name="other">The other quantity to compare to.</param>
        /// <param name="tolerance">The absolute or relative tolerance value. Must be greater than or equal to 0.</param>
        /// <param name="comparisonType">The comparison type: either relative or absolute.</param>
        /// <returns>True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.</returns>
        public bool Equals(Power other, double tolerance, ComparisonType comparisonType)
        {
            if (tolerance < 0)
            {
                throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
            }

            double thisValue             = (double)this.Value;
            double otherValueInThisUnits = other.As(this.Unit);

            return(UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType));
        }