示例#1
0
 /// <inheritdoc cref="ElectricPotentialDc.FromKilovoltsDc(double?)"/>
 public static ElectricPotentialDc?KilovoltsDc(this decimal?value) => ElectricPotentialDc.FromKilovoltsDc(value == null ? (double?)null : Convert.ToDouble(value.Value));
示例#2
0
        public void CompareToThrowsOnTypeMismatch()
        {
            ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1);

            Assert.Throws <ArgumentException>(() => voltdc.CompareTo(new object()));
        }
示例#3
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1);

            Assert.False(voltdc.Equals(new object()));
        }
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(ElectricPotentialDc.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
        public void GetHashCode_Equals()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(new { ElectricPotentialDc.Info.Name, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricPotentialDcUnit)));
        }
 public void FromVoltsDc_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => ElectricPotentialDc.FromVoltsDc(double.NaN));
 }
        public void ToUnit_WithNullUnitSystem_ThrowsNullException()
        {
            var voltdc = ElectricPotentialDc.FromVoltsDc(1);

            Assert.Throws <ArgumentNullException>(() => voltdc.ToUnit(null));
        }
 /// <inheritdoc cref="ElectricPotentialDc.FromVoltsDc(UnitsNet.QuantityValue)" />
 public static ElectricPotentialDc VoltsDc <T>(this T value) =>
 ElectricPotentialDc.FromVoltsDc(Convert.ToDouble(value));
 public void FromVoltsDc_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => ElectricPotentialDc.FromVoltsDc(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => ElectricPotentialDc.FromVoltsDc(double.NegativeInfinity));
 }
示例#12
0
        static void Main(string[] args)
        {
            // nema17 - 24v datasheet
            var MOTOR_TYPE    = "nema17";
            var MOTOR_VOLTAGE = ElectricPotentialDc.FromVoltsDc(24);
            var SPEED_MAX     = RotationalSpeed.FromRevolutionsPerMinute(200);
            var TORQUE_MAX    = Torque.FromNewtonMeters(0.4);
            // problem data
            var MASS           = Mass.FromKilograms(2);
            var LEVER_ARM_LEN  = Length.FromCentimeters(1);
            var ROUND_CNT      = Angle.FromRevolutions(1d);
            var EXECUTION_TIME = Duration.FromSeconds(2);
            // config
            var TIME_STEP = Duration.FromMilliseconds(1);

            // speed required to achieve given ROUND_CNT in EXECUTION_TIME without cruise
            var minTargetSpeed = 2 * ROUND_CNT / EXECUTION_TIME;

            if (minTargetSpeed > SPEED_MAX)
            {
                System.Console.WriteLine($"W: given position {ROUND_CNT} round cannot established due to speed_max:{SPEED_MAX.RevolutionsPerSecond} rps vs actual required target speed:{minTargetSpeed.RevolutionsPerSecond} rps");
                return;
            }

            // s:target speed
            var s = minTargetSpeed;

            // d:duration
            var d = EXECUTION_TIME;

            var minHoldingTorque = Torque.FromKilogramForceCentimeters(MASS.Kilograms * LEVER_ARM_LEN.Centimeters);

            if (minHoldingTorque > TORQUE_MAX)
            {
                System.Console.WriteLine($"W: given mass {MASS} at lever arm distance {LEVER_ARM_LEN} generate {minHoldingTorque.KilogramForceCentimeters} kgfcm torque versus max {TORQUE_MAX.KilogramForceCentimeters} kgfcm");
                return;
            }

            var minDynAccel = RotationalAcceleration.FromRevolutionsPerSecondSquared(4 * s.RevolutionsPerSecond / d.Seconds);
            var I           = MassMomentOfInertia.FromKilogramSquareCentimeters(MASS.Kilograms * Pow(LEVER_ARM_LEN.Centimeters, 2));
            // torque            = inertia * angularaccel
            // F:[M*L*T-2]*r:[L] = I:[M*L2]*a:[T-2]
            // [M*L2*T-2]        = [M*L2*T-2]
            var minDynTorque = Torque.FromKilogramForceMeters(I.KilogramSquareMeters * minDynAccel.RadiansPerSecondSquared);

            if (minDynTorque > TORQUE_MAX)
            {
                System.Console.WriteLine($"W: accelerating given mass {MASS} at angaccel {minDynAccel} generates torque {minDynTorque.NewtonCentimeters} Ncm great than max {TORQUE_MAX.NewtonCentimeters} Ncm");
                return;
            }

            var srcPathfilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "template.xlsx");
            var dstPathfilename = "output.xlsx";

            File.Copy(srcPathfilename, dstPathfilename, true);
            using (var wb = new ClosedXML.Excel.XLWorkbook(dstPathfilename))
            {
                var ws = wb.Worksheets.First();

                IXLCell cell = null;

                Action <int, int, object> setCell = (r, c, val) =>
                {
                    cell       = ws.Cell(r, c);
                    cell.Value = val;
                };

                Action <int, int, object> setCellBold = (r, c, val) =>
                {
                    cell       = ws.Cell(r, c);
                    cell.Value = val;
                    cell.Style.Font.SetBold();
                };

                var row       = 1;
                int col       = 1;
                var colTime   = col++;
                var colAccel  = col++;
                var colSpeed  = col++;
                var colPosRot = col++;

                setCellBold(row, colTime, "TIME (s)");
                setCellBold(row, colAccel, "ACCEL (rps2)");
                setCellBold(row, colSpeed, "SPEED (rps)");
                setCellBold(row, colPosRot, "POS (rot)");
                ++row;

                var t    = Duration.FromSeconds(0);
                var tMax = t + EXECUTION_TIME;

                var halfTMax = tMax / 2;

                ws.Cell("MotorType").Value                 = MOTOR_TYPE;
                ws.Cell("MotorSpeedMax").Value             = SPEED_MAX;
                ws.Cell("MotorTorqueMaxAtSpeedMax").Value  = TORQUE_MAX;
                ws.Cell("MotorVoltage").Value              = MOTOR_VOLTAGE;
                ws.Cell("ProblemDuration").Value           = EXECUTION_TIME;
                ws.Cell("ProblemLoadLeverArmLength").Value = LEVER_ARM_LEN;
                ws.Cell("ProblemLoadMass").Value           = MASS;
                ws.Cell("ProblemRevolutions").Value        = ROUND_CNT;
                ws.Cell("ResultingTorque").Value           = minDynTorque.ToUnit(TorqueUnit.NewtonMeter);
                ws.Cell("ResultingAccel").Value            = minDynAccel;
                ws.Cell("ResultingSpeedMax").Value         = minTargetSpeed.ToUnit(RotationalSpeedUnit.RevolutionPerMinute);

                var tEps = Duration.FromNanoseconds(1);
                while (t.LessThanOrEqualsTol(tEps, tMax))
                {
                    setCell(row, colTime, t.Seconds);

                    var accel = RotationalAcceleration.FromRevolutionsPerSecondSquared(0);
                    var speed = RotationalSpeed.FromRevolutionsPerSecond(0);
                    var pos   = Angle.FromRevolutions(0);

                    if (t.LessThanOrEqualsTol(tEps, halfTMax))
                    {
                        accel = RotationalAcceleration.FromRevolutionsPerSecondSquared(
                            2 * s.RevolutionsPerSecond / d.Seconds * (1 - Cos(4 * PI * t / d)));

                        speed = RotationalSpeed.FromRevolutionsPerSecond(
                            2 * s.RevolutionsPerSecond / d.Seconds * (t - d * Sin(4 * PI * t / d) / (4 * PI)).Seconds);

                        pos = s * d * (Cos(4 * PI * t / d) - 1) / (8 * Pow(PI, 2)) + (s * t) * (t / d);
                    }

                    if (t.GreatThanOrEqualsTol(tEps, halfTMax))
                    {
                        var th = t - d / 2;

                        accel = RotationalAcceleration.FromRevolutionsPerSecondSquared(
                            2 * s.RevolutionsPerSecond / d.Seconds * (Cos(4 * PI * th / d) - 1));

                        speed = RotationalSpeed.FromRevolutionsPerSecond(
                            2 * s.RevolutionsPerSecond * Sin(4 * PI * th / d) / (4 * PI)
                            - (2 * s * th / d - s).RevolutionsPerSecond);

                        pos = s * d * (1 - Cos(4 * PI * th / d)) / (8 * Pow(PI, 2)) - (s * th) * (th / d) + s * th + s * d / 4;
                    }

                    setCell(row, colAccel, accel.RevolutionsPerSecondSquared);
                    setCell(row, colSpeed, speed.RevolutionsPerSecond);
                    setCell(row, colPosRot, pos.Revolutions);

                    ++row;
                    t += TIME_STEP;
                }

                wb.Save();
            }
        }
示例#13
0
 /// <inheritdoc cref="ElectricPotentialDc.FromMegavoltsDc(double?)"/>
 public static ElectricPotentialDc?MegavoltsDc(this double?value) => ElectricPotentialDc.FromMegavoltsDc(value);
示例#14
0
 /// <inheritdoc cref="ElectricPotentialDc.FromMegavoltsDc(double)"/>
 public static ElectricPotentialDc MegavoltsDc(this long value) => ElectricPotentialDc.FromMegavoltsDc(value);
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
        public void ToBaseUnit_ReturnsQuantityWithBaseUnit()
        {
            var quantityInBaseUnit = ElectricPotentialDc.FromVoltsDc(1).ToBaseUnit();

            Assert.Equal(ElectricPotentialDc.BaseUnit, quantityInBaseUnit.Unit);
        }
        public void Convert_ToString_EqualsToString()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = ElectricPotentialDc.FromVoltsDc(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(ElectricPotentialDc.FromVoltsDc(1), -1, ComparisonType.Relative));
        }
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricPotentialDc)));
        }
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
        public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(ElectricPotentialDc.Info, Convert.ChangeType(quantity, typeof(QuantityInfo)));
        }
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(value);

            Assert.Equal(ElectricPotentialDc.FromVoltsDc(-value), -quantity);
        }
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }
示例#27
0
        public void CompareToThrowsOnNull()
        {
            ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1);

            Assert.Throws <ArgumentNullException>(() => voltdc.CompareTo(null));
        }
        public void Convert_ToInt32_EqualsValueAsSameType()
        {
            var quantity = ElectricPotentialDc.FromVoltsDc(1.0);

            Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity));
        }
示例#29
0
        public void EqualsReturnsFalseOnNull()
        {
            ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1);

            Assert.False(voltdc.Equals(null));
        }
示例#30
0
 /// <inheritdoc cref="ElectricPotentialDc.FromKilovoltsDc(double)"/>
 public static ElectricPotentialDc KilovoltsDc(this decimal value) => ElectricPotentialDc.FromKilovoltsDc(Convert.ToDouble(value));