From cd819d5a9a5d65c1c20e40e592b53e4c0cbaf71b Mon Sep 17 00:00:00 2001 From: Muximize Date: Sun, 7 Jan 2024 00:31:08 +0100 Subject: [PATCH 1/5] Remove all division relations, add some multiplications to replace missing ones --- Common/UnitRelations.json | 113 +++++--------------------------------- 1 file changed, 14 insertions(+), 99 deletions(-) diff --git a/Common/UnitRelations.json b/Common/UnitRelations.json index 622b3a21e8..519ea946d4 100644 --- a/Common/UnitRelations.json +++ b/Common/UnitRelations.json @@ -1,164 +1,79 @@ [ - "Acceleration.MeterPerSecondSquared = Force.Newton / Mass.Kilogram", - "Acceleration.MeterPerSecondSquared = SpecificWeight.NewtonPerCubicMeter / Density.KilogramPerCubicMeter", - "Acceleration.MeterPerSecondSquared = Speed.MeterPerSecond / Duration.Second", + "1 = Area.SquareMeter * ReciprocalArea.InverseSquareMeter", + "1 = ElectricResistivity.OhmMeter * ElectricConductivity.SiemensPerMeter", + "1 = Length.Meter * ReciprocalLength.InverseMeter", + "Acceleration.MeterPerSecondSquared = Jerk.MeterPerSecondCubed * Duration.Second", "AmountOfSubstance.Kilomole = MolarFlow.KilomolePerSecond * Duration.Second", - "AmountOfSubstance.Mole = Mass.Kilogram / MolarMass.KilogramPerMole", + "AmountOfSubstance.Mole = Molarity.MolePerCubicMeter * Volume.CubicMeter", "Angle.Radian = RotationalSpeed.RadianPerSecond * Duration.Second", - "Angle.Radian = Torque.NewtonMeter / RotationalStiffness.NewtonMeterPerRadian", "Area.SquareMeter = KinematicViscosity.SquareMeterPerSecond * Duration.Second", "Area.SquareMeter = Length.Meter * Length.Meter", - "Area.SquareMeter = LinearDensity.KilogramPerMeter / Density.KilogramPerCubicMeter", - "Area.SquareMeter = LuminousIntensity.Candela / Luminance.CandelaPerSquareMeter", - "Area.SquareMeter = Mass.Kilogram / AreaDensity.KilogramPerSquareMeter", - "Area.SquareMeter = MassFlow.KilogramPerSecond / MassFlux.KilogramPerSecondPerSquareMeter", - "Area.SquareMeter = Power.Watt / HeatFlux.WattPerSquareMeter", - "Area.SquareMeter = Volume.CubicMeter / Length.Meter", - "Area.SquareMeter = VolumeFlow.CubicMeterPerSecond / Speed.MeterPerSecond", - "AreaDensity.KilogramPerSquareMeter = Mass.Kilogram / Area.SquareMeter", - "BrakeSpecificFuelConsumption.KilogramPerJoule = double / SpecificEnergy.JoulePerKilogram", - "BrakeSpecificFuelConsumption.KilogramPerJoule = MassFlow.KilogramPerSecond / Power.Watt", - "Density.KilogramPerCubicMeter = double / SpecificVolume.CubicMeterPerKilogram", - "Density.KilogramPerCubicMeter = LinearDensity.KilogramPerMeter / Area.SquareMeter", - "Density.KilogramPerCubicMeter = Mass.Kilogram / Volume.CubicMeter", - "Density.KilogramPerCubicMeter = MassFlow.KilogramPerSecond / VolumeFlow.CubicMeterPerSecond", - "Density.KilogramPerCubicMeter = MassFlux.KilogramPerSecondPerSquareMeter / Speed.MeterPerSecond", - "Density.KilogramPerCubicMeter = SpecificWeight.NewtonPerCubicMeter / Acceleration.MeterPerSecondSquared", + "AreaMomentOfInertia.MeterToTheFourth = Volume.CubicMeter * Length.Meter", + "double = Density.KilogramPerCubicMeter * SpecificVolume.CubicMeterPerKilogram", "double = SpecificEnergy.JoulePerKilogram * BrakeSpecificFuelConsumption.KilogramPerJoule", "double = TemperatureDelta.Kelvin * CoefficientOfThermalExpansion.PerKelvin", - "Duration.Hour = ElectricCharge.AmpereHour / ElectricCurrent.Ampere", - "Duration.Second = Energy.Joule / Power.Watt", - "Duration.Second = Force.Newton / ForceChangeRate.NewtonPerSecond", - "Duration.Second = Length.Meter / Speed.MeterPerSecond", - "Duration.Second = Speed.MeterPerSecond / Acceleration.MeterPerSecondSquared", "DynamicViscosity.NewtonSecondPerMeterSquared = Density.KilogramPerCubicMeter * KinematicViscosity.SquareMeterPerSecond", "ElectricCharge.AmpereHour = ElectricCurrent.Ampere * Duration.Hour", - "ElectricCharge.Coulomb = Energy.Joule / ElectricPotential.Volt", - "ElectricConductivity.SiemensPerMeter = 1 / ElectricResistivity.OhmMeter", - "ElectricCurrent.Ampere = ElectricCharge.AmpereHour / Duration.Hour", "ElectricCurrent.Ampere = ElectricCurrentGradient.AmperePerSecond * Duration.Second", - "ElectricCurrent.Ampere = ElectricPotential.Volt / ElectricResistance.Ohm", - "ElectricCurrent.Ampere = Power.Watt / ElectricPotential.Volt", - "ElectricCurrentGradient.AmperePerSecond = ElectricCurrent.Ampere / Duration.Second", "ElectricPotential.Volt = ElectricCurrent.Ampere * ElectricResistance.Ohm", - "ElectricPotential.Volt = Energy.Joule / ElectricCharge.Coulomb", - "ElectricPotential.Volt = Power.Watt / ElectricCurrent.Ampere", - "ElectricResistance.Ohm = ElectricPotential.Volt / ElectricCurrent.Ampere", "Energy.Joule = ElectricPotential.Volt * ElectricCharge.Coulomb", "Energy.Joule = EnergyDensity.JoulePerCubicMeter * Volume.CubicMeter", "Energy.Joule = Power.Watt * Duration.Second", "Energy.Joule = SpecificEnergy.JoulePerKilogram * Mass.Kilogram", "Energy.Joule = TemperatureDelta.Kelvin * Entropy.JoulePerKelvin", - "Entropy.JoulePerKelvin = Energy.Joule / TemperatureDelta.Kelvin", "Entropy.JoulePerKelvin = SpecificEntropy.JoulePerKilogramKelvin * Mass.Kilogram", "Force.Newton = ForceChangeRate.NewtonPerSecond * Duration.Second", "Force.Newton = ForcePerLength.NewtonPerMeter * Length.Meter", - "Force.Newton = ForcePerLength.NewtonPerMeter / ReciprocalLength.InverseMeter", "Force.Newton = Mass.Kilogram * Acceleration.MeterPerSecondSquared", - "Force.Newton = Power.Watt / Speed.MeterPerSecond", "Force.Newton = Pressure.Pascal * Area.SquareMeter", - "Force.Newton = Pressure.Pascal / ReciprocalArea.InverseSquareMeter", - "Force.Newton = Torque.NewtonMeter / Length.Meter", "ForcePerLength.NewtonPerMeter = Force.Newton * ReciprocalLength.InverseMeter", - "ForcePerLength.NewtonPerMeter = Force.Newton / Length.Meter", - "ForcePerLength.NewtonPerMeter = Pressure.Pascal / ReciprocalLength.InverseMeter", + "ForcePerLength.NewtonPerMeter = Pressure.NewtonPerSquareMeter * Length.Meter", "ForcePerLength.NewtonPerMeter = SpecificWeight.NewtonPerCubicMeter * Area.SquareMeter", - "HeatFlux.WattPerSquareMeter = Power.Watt / Area.SquareMeter", - "Jerk.MeterPerSecondCubed = Acceleration.MeterPerSecondSquared / Duration.Second", - "KinematicViscosity.SquareMeterPerSecond = DynamicViscosity.NewtonSecondPerMeterSquared / Density.KilogramPerCubicMeter", "KinematicViscosity.SquareMeterPerSecond = Length.Meter * Speed.MeterPerSecond", - "Length.Kilometer = TemperatureDelta.Kelvin / TemperatureGradient.DegreeCelsiusPerKilometer", - "Length.Meter = Area.SquareMeter / Length.Meter", - "Length.Meter = Force.Newton / ForcePerLength.NewtonPerMeter", - "Length.Meter = Mass.Kilogram / LinearDensity.KilogramPerMeter", - "Length.Meter = Pressure.Pascal / SpecificWeight.NewtonPerCubicMeter", - "Length.Meter = ReciprocalLength.InverseMeter / ReciprocalArea.InverseSquareMeter", - "Length.Meter = RotationalStiffness.NewtonMeterPerRadian / RotationalStiffnessPerLength.NewtonMeterPerRadianPerMeter", "Length.Meter = Speed.MeterPerSecond * Duration.Second", - "Length.Meter = Torque.NewtonMeter / Force.Newton", - "Length.Meter = Volume.CubicMeter / Area.SquareMeter", "LinearDensity.KilogramPerMeter = Area.SquareMeter * Density.KilogramPerCubicMeter", - "LinearDensity.KilogramPerMeter = Mass.Kilogram / Length.Meter", - "Luminance.CandelaPerSquareMeter = LuminousIntensity.Candela / Area.SquareMeter", "LuminousIntensity.Candela = Luminance.CandelaPerSquareMeter * Area.SquareMeter", "Mass.Gram = AmountOfSubstance.Mole * MolarMass.GramPerMole", "Mass.Kilogram = AreaDensity.KilogramPerSquareMeter * Area.SquareMeter", "Mass.Kilogram = Density.KilogramPerCubicMeter * Volume.CubicMeter", - "Mass.Kilogram = Energy.Joule / SpecificEnergy.JoulePerKilogram", - "Mass.Kilogram = Force.Newton / Acceleration.MeterPerSecondSquared", "Mass.Kilogram = LinearDensity.KilogramPerMeter * Length.Meter", - "Mass.Kilogram = Mass.Kilogram / MassFraction.DecimalFraction", "Mass.Kilogram = MassConcentration.KilogramPerCubicMeter * Volume.CubicMeter", "Mass.Kilogram = MassFlow.KilogramPerSecond * Duration.Second", "Mass.Kilogram = MassFraction.DecimalFraction * Mass.Kilogram", - "MassConcentration.GramPerCubicMeter = Molarity.MolePerCubicMeter * MolarMass.GramPerMole", + "MassConcentration.KilogramPerCubicMeter = Molarity.MolePerCubicMeter * MolarMass.KilogramPerMole", "MassConcentration.KilogramPerCubicMeter = VolumeConcentration.DecimalFraction * Density.KilogramPerCubicMeter", - "MassFlow.GramPerSecond = Area.SquareMeter * MassFlux.GramPerSecondPerSquareMeter", - "MassFlow.KilogramPerSecond = Mass.Kilogram / Duration.Second", + "MassFlow.KilogramPerSecond = Area.SquareMeter * MassFlux.KilogramPerSecondPerSquareMeter", "MassFlow.KilogramPerSecond = MolarFlow.KilomolePerSecond * MolarMass.KilogramPerKilomole", "MassFlow.KilogramPerSecond = Power.Watt * BrakeSpecificFuelConsumption.KilogramPerJoule", - "MassFlow.KilogramPerSecond = Power.Watt / SpecificEnergy.JoulePerKilogram", "MassFlow.KilogramPerSecond = VolumeFlow.CubicMeterPerSecond * Density.KilogramPerCubicMeter", - "MassFlux.KilogramPerSecondPerSquareMeter = MassFlow.KilogramPerSecond / Area.SquareMeter", "MassFlux.KilogramPerSecondPerSquareMeter = Speed.MeterPerSecond * Density.KilogramPerCubicMeter", - "Molarity.MolePerCubicMeter = AmountOfSubstance.Mole / Volume.CubicMeter", - "Molarity.MolePerCubicMeter = MassConcentration.GramPerCubicMeter / MolarMass.GramPerMole", + "MolarFlow.MolePerSecond = VolumeFlow.CubicMeterPerSecond * Molarity.MolePerCubicMeter", "Molarity.MolePerCubicMeter = Molarity.MolePerCubicMeter * VolumeConcentration.DecimalFraction", "Power.Watt = ElectricPotential.Volt * ElectricCurrent.Ampere", "Power.Watt = Energy.Joule * Frequency.PerSecond", - "Power.Watt = Energy.Joule / Duration.Second", "Power.Watt = Force.Newton * Speed.MeterPerSecond", "Power.Watt = HeatFlux.WattPerSquareMeter * Area.SquareMeter", - "Power.Watt = MassFlow.KilogramPerSecond / BrakeSpecificFuelConsumption.KilogramPerJoule", "Power.Watt = SpecificEnergy.JoulePerKilogram * MassFlow.KilogramPerSecond", + "Power.Watt = Torque.NewtonMeter * RotationalSpeed.RadianPerSecond", "Pressure.NewtonPerSquareMeter = Force.Newton * ReciprocalArea.InverseSquareMeter", "Pressure.NewtonPerSquareMeter = ForcePerLength.NewtonPerMeter * ReciprocalLength.InverseMeter", - "Pressure.NewtonPerSquareMeter = ForcePerLength.NewtonPerMeter / Length.Meter", - "Pressure.Pascal = Force.Newton / Area.SquareMeter", "Pressure.Pascal = PressureChangeRate.PascalPerSecond * Duration.Second", "Pressure.Pascal = SpecificWeight.NewtonPerCubicMeter * Length.Meter", - "PressureChangeRate.PascalPerSecond = Pressure.Pascal / Duration.Second", "Ratio.DecimalFraction = Area.SquareMeter * ReciprocalArea.InverseSquareMeter", - "ReciprocalArea.InverseSquareMeter = 1 / Area.SquareMeter", "ReciprocalArea.InverseSquareMeter = ReciprocalLength.InverseMeter * ReciprocalLength.InverseMeter", - "ReciprocalLength.InverseMeter = 1 / Length.Meter", - "ReciprocalLength.InverseMeter = ReciprocalArea.InverseSquareMeter / ReciprocalLength.InverseMeter", - "RotationalSpeed.RadianPerSecond = Angle.Radian / Duration.Second", - "RotationalSpeed.RadianPerSecond = Power.Watt / Torque.NewtonMeter", + "ReciprocalLength.InverseMeter = Length.Meter * ReciprocalArea.InverseSquareMeter", "RotationalStiffness.NewtonMeterPerRadian = RotationalStiffnessPerLength.NewtonMeterPerRadianPerMeter * Length.Meter", - "RotationalStiffness.NewtonMeterPerRadian = Torque.NewtonMeter / Angle.Radian", - "RotationalStiffnessPerLength.NewtonMeterPerRadianPerMeter = RotationalStiffness.NewtonMeterPerRadian / Length.Meter", - "SpecificEnergy.JoulePerKilogram = double / BrakeSpecificFuelConsumption.KilogramPerJoule", - "SpecificEnergy.JoulePerKilogram = Energy.Joule / Mass.Kilogram", - "SpecificEnergy.JoulePerKilogram = Power.Watt / MassFlow.KilogramPerSecond", "SpecificEnergy.JoulePerKilogram = SpecificEntropy.JoulePerKilogramKelvin * TemperatureDelta.Kelvin", "SpecificEnergy.JoulePerKilogram = Speed.MeterPerSecond * Speed.MeterPerSecond", - "SpecificEntropy.JoulePerKilogramKelvin = Entropy.JoulePerKelvin / Mass.Kilogram", - "SpecificEntropy.JoulePerKilogramKelvin = SpecificEnergy.JoulePerKilogram / TemperatureDelta.Kelvin", "SpecificWeight.NewtonPerCubicMeter = Acceleration.MeterPerSecondSquared * Density.KilogramPerCubicMeter", - "SpecificWeight.NewtonPerCubicMeter = Pressure.Pascal / Length.Meter", "Speed.MeterPerSecond = Acceleration.MeterPerSecondSquared * Duration.Second", - "Speed.MeterPerSecond = KinematicViscosity.SquareMeterPerSecond / Length.Meter", - "Speed.MeterPerSecond = Length.Meter / Duration.Second", - "Speed.MeterPerSecond = MassFlux.KilogramPerSecondPerSquareMeter / Density.KilogramPerCubicMeter", - "Speed.MeterPerSecond = VolumeFlow.CubicMeterPerSecond / Area.SquareMeter", "TemperatureDelta.DegreeCelsius = TemperatureChangeRate.DegreeCelsiusPerSecond * Duration.Second", "TemperatureDelta.DegreeCelsius = TemperatureGradient.DegreeCelsiusPerKilometer * Length.Kilometer", - "TemperatureDelta.Kelvin = Energy.Joule / Entropy.JoulePerKelvin", - "TemperatureGradient.KelvinPerMeter = TemperatureDelta.Kelvin / Length.Meter", "Torque.NewtonMeter = ForcePerLength.NewtonPerMeter * Area.SquareMeter", "Torque.NewtonMeter = Length.Meter * Force.Newton", - "Torque.NewtonMeter = Power.Watt / RotationalSpeed.RadianPerSecond", "Torque.NewtonMeter = RotationalStiffness.NewtonMeterPerRadian * Angle.Radian", - "Volume.CubicMeter = AmountOfSubstance.Mole / Molarity.MolePerCubicMeter", - "Volume.CubicMeter = AreaMomentOfInertia.MeterToTheFourth / Length.Meter", "Volume.CubicMeter = Length.Meter * Area.SquareMeter", - "Volume.CubicMeter = Mass.Kilogram / Density.KilogramPerCubicMeter", "Volume.CubicMeter = SpecificVolume.CubicMeterPerKilogram * Mass.Kilogram", "Volume.CubicMeter = VolumeFlow.CubicMeterPerSecond * Duration.Second", - "VolumeConcentration.DecimalFraction = MassConcentration.KilogramPerCubicMeter / Density.KilogramPerCubicMeter", - "VolumeFlow.CubicMeterPerSecond = Area.SquareMeter * Speed.MeterPerSecond", - "VolumeFlow.CubicMeterPerSecond = MassFlow.KilogramPerSecond / Density.KilogramPerCubicMeter", - "VolumeFlow.CubicMeterPerSecond = MolarFlow.MolePerSecond / Molarity.MolePerCubicMeter", - "VolumeFlow.CubicMeterPerSecond = Volume.CubicMeter / Duration.Second" + "VolumeFlow.CubicMeterPerSecond = Area.SquareMeter * Speed.MeterPerSecond" ] \ No newline at end of file From a44d76a9bf6ed95c71cc68046b6cd245a6c194ec Mon Sep 17 00:00:00 2001 From: Muximize Date: Sun, 7 Jan 2024 00:35:57 +0100 Subject: [PATCH 2/5] Add inferred division to CodeGen --- CodeGen/Generators/QuantityRelationsParser.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/CodeGen/Generators/QuantityRelationsParser.cs b/CodeGen/Generators/QuantityRelationsParser.cs index 9c28695af3..fcf709cc1e 100644 --- a/CodeGen/Generators/QuantityRelationsParser.cs +++ b/CodeGen/Generators/QuantityRelationsParser.cs @@ -58,10 +58,28 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities) RightUnit = r.LeftUnit, }) .ToList()); + + // We can infer division relations from multiplication relations. + relations.AddRange(relations + .Where(r => r.Operator is "*") + .Select(r => r with + { + Operator = "/", + LeftQuantity = r.ResultQuantity, + LeftUnit = r.ResultUnit, + ResultQuantity = r.LeftQuantity, + ResultUnit = r.LeftUnit, + }) + // Skip division between equal quantities because the ratio is already generated as part of the Arithmetic Operators. + .Where(r => r.LeftQuantity != r.RightQuantity) + .ToList()); + + // Remove inferred relation "MassConcentration = Mass / Volume" because it duplicates "Density = Mass / Volume" + relations.RemoveAll(r => r is { Operator: "/", ResultQuantity.Name: "MassConcentration", LeftQuantity.Name: "Mass", RightQuantity.Name: "Volume" }); // Sort all relations to keep generated operators in a consistent order. relations.Sort(); - + var duplicates = relations .GroupBy(r => r.SortString) .Where(g => g.Count() > 1) @@ -122,7 +140,7 @@ private static QuantityRelation ParseRelation(string relationString, IReadOnlyDi { var segments = relationString.Split(' '); - if (segments is not [_, "=", _, "*" or "/", _]) + if (segments is not [_, "=", _, "*", _]) { throw new Exception($"Invalid relation string: {relationString}"); } @@ -140,11 +158,9 @@ private static QuantityRelation ParseRelation(string relationString, IReadOnlyDi var rightUnit = GetUnit(rightQuantity, right.ElementAtOrDefault(1)); var resultUnit = GetUnit(resultQuantity, result.ElementAtOrDefault(1)); - if (leftQuantity.Name == "1") + if (resultQuantity.Name == "1") { @operator = "inverse"; - leftQuantity = resultQuantity; - leftUnit = resultUnit; } return new QuantityRelation From 0fe25aaf37f5139349f763821d5416ed56967162 Mon Sep 17 00:00:00 2001 From: Muximize Date: Sun, 7 Jan 2024 00:40:01 +0100 Subject: [PATCH 3/5] Replace TimeSpan with Duration as return type --- UnitsNet.Tests/CustomCode/VolumeTests.cs | 4 ++-- UnitsNet/CustomCode/Quantities/Volume.extra.cs | 16 ---------------- 2 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 UnitsNet/CustomCode/Quantities/Volume.extra.cs diff --git a/UnitsNet.Tests/CustomCode/VolumeTests.cs b/UnitsNet.Tests/CustomCode/VolumeTests.cs index 17cb52f922..44d7e4e3e4 100644 --- a/UnitsNet.Tests/CustomCode/VolumeTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeTests.cs @@ -151,8 +151,8 @@ public void VolumeDividedByDurationEqualsVolumeFlow() [Fact] public void VolumeDividedByVolumeFlowEqualsTimeSpan() { - TimeSpan timeSpan = Volume.FromCubicMeters(20) / VolumeFlow.FromCubicMetersPerSecond(2); - Assert.Equal(TimeSpan.FromSeconds(10), timeSpan); + Duration duration = Volume.FromCubicMeters(20) / VolumeFlow.FromCubicMetersPerSecond(2); + Assert.Equal(Duration.FromSeconds(10), duration); } } } diff --git a/UnitsNet/CustomCode/Quantities/Volume.extra.cs b/UnitsNet/CustomCode/Quantities/Volume.extra.cs deleted file mode 100644 index 88d6bf2a51..0000000000 --- a/UnitsNet/CustomCode/Quantities/Volume.extra.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; - -namespace UnitsNet -{ - public partial struct Volume - { - /// Get from divided by . - public static TimeSpan operator /(Volume volume, VolumeFlow volumeFlow) - { - return TimeSpan.FromSeconds(volume.CubicMeters / volumeFlow.CubicMetersPerSecond); - } - } -} From c4ebb8c8da18a6f2e6fc40376920d955adc2d5e3 Mon Sep 17 00:00:00 2001 From: Muximize Date: Mon, 19 Feb 2024 22:58:25 +0100 Subject: [PATCH 4/5] Add NoInferredDivision option --- CodeGen/Generators/QuantityRelationsParser.cs | 31 +++++++++++++------ CodeGen/JsonTypes/QuantityRelation.cs | 1 + Common/UnitRelations.json | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CodeGen/Generators/QuantityRelationsParser.cs b/CodeGen/Generators/QuantityRelationsParser.cs index fcf709cc1e..401c7e7b10 100644 --- a/CodeGen/Generators/QuantityRelationsParser.cs +++ b/CodeGen/Generators/QuantityRelationsParser.cs @@ -25,13 +25,16 @@ internal static class QuantityRelationsParser /// /// The format of a relation definition is "Quantity.Unit operator Quantity.Unit = Quantity.Unit" (See examples below). /// "double" can be used as a unitless operand. - /// "1" can be used as the left operand to define inverse relations. + /// "1" can be used as the result operand to define inverse relations. + /// + /// Division relations are inferred from multiplication relations, + /// but this can be skipped if the string ends with "NoInferredDivision". /// /// /// [ - /// "Power.Watt = ElectricPotential.Volt * ElectricCurrent.Ampere", - /// "Speed.MeterPerSecond = Length.Meter / Duration.Second", - /// "ReciprocalLength.InverseMeter = 1 / Length.Meter" + /// "1 = Length.Meter * ReciprocalLength.InverseMeter" + /// "Power.Watt = ElectricPotential.Volt * ElectricCurrent.Ampere", + /// "Mass.Kilogram = MassConcentration.KilogramPerCubicMeter * Volume.CubicMeter -- NoInferredDivision", /// ] /// /// Repository root directory. @@ -61,7 +64,7 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities) // We can infer division relations from multiplication relations. relations.AddRange(relations - .Where(r => r.Operator is "*") + .Where(r => r is { Operator: "*", NoInferredDivision: false }) .Select(r => r with { Operator = "/", @@ -73,9 +76,6 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities) // Skip division between equal quantities because the ratio is already generated as part of the Arithmetic Operators. .Where(r => r.LeftQuantity != r.RightQuantity) .ToList()); - - // Remove inferred relation "MassConcentration = Mass / Volume" because it duplicates "Density = Mass / Volume" - relations.RemoveAll(r => r is { Operator: "/", ResultQuantity.Name: "MassConcentration", LeftQuantity.Name: "Mass", RightQuantity.Name: "Volume" }); // Sort all relations to keep generated operators in a consistent order. relations.Sort(); @@ -91,6 +91,18 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities) var list = string.Join("\n ", duplicates); throw new UnitsNetCodeGenException($"Duplicate inferred relations:\n {list}"); } + + var ambiguous = relations + .GroupBy(r => $"{r.LeftQuantity.Name} {r.Operator} {r.RightQuantity.Name}") + .Where(g => g.Count() > 1) + .Select(g => g.Key) + .ToList(); + + if (ambiguous.Any()) + { + var list = string.Join("\n ", ambiguous); + throw new UnitsNetCodeGenException($"Ambiguous inferred relations:\n {list}\n\nHint: you could use NoInferredDivision in the definition file."); + } foreach (var quantity in quantities) { @@ -140,7 +152,7 @@ private static QuantityRelation ParseRelation(string relationString, IReadOnlyDi { var segments = relationString.Split(' '); - if (segments is not [_, "=", _, "*", _]) + if (segments is not [_, "=", _, "*", _, ..]) { throw new Exception($"Invalid relation string: {relationString}"); } @@ -165,6 +177,7 @@ private static QuantityRelation ParseRelation(string relationString, IReadOnlyDi return new QuantityRelation { + NoInferredDivision = segments.Contains("NoInferredDivision"), Operator = @operator, LeftQuantity = leftQuantity, LeftUnit = leftUnit, diff --git a/CodeGen/JsonTypes/QuantityRelation.cs b/CodeGen/JsonTypes/QuantityRelation.cs index 9aec29c2a9..35e97a6bc0 100644 --- a/CodeGen/JsonTypes/QuantityRelation.cs +++ b/CodeGen/JsonTypes/QuantityRelation.cs @@ -7,6 +7,7 @@ namespace CodeGen.JsonTypes { internal record QuantityRelation : IComparable { + public bool NoInferredDivision = false; public string Operator = null!; public Quantity LeftQuantity = null!; diff --git a/Common/UnitRelations.json b/Common/UnitRelations.json index 519ea946d4..b6e6cc2ad3 100644 --- a/Common/UnitRelations.json +++ b/Common/UnitRelations.json @@ -37,7 +37,7 @@ "Mass.Kilogram = AreaDensity.KilogramPerSquareMeter * Area.SquareMeter", "Mass.Kilogram = Density.KilogramPerCubicMeter * Volume.CubicMeter", "Mass.Kilogram = LinearDensity.KilogramPerMeter * Length.Meter", - "Mass.Kilogram = MassConcentration.KilogramPerCubicMeter * Volume.CubicMeter", + "Mass.Kilogram = MassConcentration.KilogramPerCubicMeter * Volume.CubicMeter -- NoInferredDivision", "Mass.Kilogram = MassFlow.KilogramPerSecond * Duration.Second", "Mass.Kilogram = MassFraction.DecimalFraction * Mass.Kilogram", "MassConcentration.KilogramPerCubicMeter = Molarity.MolePerCubicMeter * MolarMass.KilogramPerMole", From 6a5ad04ab2ccb0aba06f5c5a1cbee8b775373ce9 Mon Sep 17 00:00:00 2001 From: Muximize Date: Mon, 19 Feb 2024 22:59:40 +0100 Subject: [PATCH 5/5] Generate code --- .../Quantities/Acceleration.g.cs | 7 ++++ .../Quantities/AmountOfSubstance.g.cs | 14 +++++++ UnitsNet/GeneratedCode/Quantities/Angle.g.cs | 7 ++++ UnitsNet/GeneratedCode/Quantities/Area.g.cs | 30 +++++++++++---- .../Quantities/AreaMomentOfInertia.g.cs | 7 ++++ .../CoefficientOfThermalExpansion.g.cs | 6 +++ .../GeneratedCode/Quantities/Density.g.cs | 13 +++++++ .../GeneratedCode/Quantities/Duration.g.cs | 7 ++++ .../Quantities/DynamicViscosity.g.cs | 7 ++++ .../Quantities/ElectricCurrent.g.cs | 7 ++++ UnitsNet/GeneratedCode/Quantities/Energy.g.cs | 14 +++++++ .../GeneratedCode/Quantities/Entropy.g.cs | 7 ++++ UnitsNet/GeneratedCode/Quantities/Force.g.cs | 14 +++++++ .../Quantities/ForcePerLength.g.cs | 28 ++++++++++++++ UnitsNet/GeneratedCode/Quantities/Jerk.g.cs | 16 ++++++++ .../Quantities/KinematicViscosity.g.cs | 7 ++++ UnitsNet/GeneratedCode/Quantities/Length.g.cs | 29 ++++++++++++-- UnitsNet/GeneratedCode/Quantities/Mass.g.cs | 16 +++++++- .../Quantities/MassConcentration.g.cs | 16 +++++++- .../GeneratedCode/Quantities/MassFlow.g.cs | 14 +++++++ .../GeneratedCode/Quantities/MassFlux.g.cs | 2 +- .../GeneratedCode/Quantities/MolarFlow.g.cs | 7 ++++ .../GeneratedCode/Quantities/MolarMass.g.cs | 2 +- .../GeneratedCode/Quantities/Molarity.g.cs | 23 ++++++++++- UnitsNet/GeneratedCode/Quantities/Power.g.cs | 21 ++++++++++ .../GeneratedCode/Quantities/Pressure.g.cs | 38 ++++++++++++++++--- UnitsNet/GeneratedCode/Quantities/Ratio.g.cs | 23 +++++++++++ .../Quantities/ReciprocalArea.g.cs | 15 ++++++-- .../Quantities/ReciprocalLength.g.cs | 15 ++++++-- .../Quantities/RotationalSpeed.g.cs | 7 ++++ .../Quantities/SpecificEnergy.g.cs | 14 +++++++ .../Quantities/SpecificVolume.g.cs | 7 ++++ .../Quantities/TemperatureDelta.g.cs | 24 +++++++++++- UnitsNet/GeneratedCode/Quantities/Torque.g.cs | 21 ++++++++++ UnitsNet/GeneratedCode/Quantities/Volume.g.cs | 35 +++++++++++++++++ .../GeneratedCode/Quantities/VolumeFlow.g.cs | 7 ++++ 36 files changed, 495 insertions(+), 32 deletions(-) diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 2dd67625dd..89724a7161 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -42,6 +42,7 @@ namespace UnitsNet public readonly partial struct Acceleration : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, @@ -646,6 +647,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Accel #region Relational Operators + /// Get from / . + public static Duration operator /(Acceleration acceleration, Jerk jerk) + { + return Duration.FromSeconds(acceleration.MetersPerSecondSquared / jerk.MetersPerSecondCubed); + } + /// Get from * . public static Force operator *(Acceleration acceleration, Mass mass) { diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs index c76c9b5b8a..58975e193f 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs @@ -42,7 +42,9 @@ namespace UnitsNet public readonly partial struct AmountOfSubstance : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, IDivisionOperators, #endif @@ -693,12 +695,24 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Amoun #region Relational Operators + /// Get from / . + public static Duration operator /(AmountOfSubstance amountOfSubstance, MolarFlow molarFlow) + { + return Duration.FromSeconds(amountOfSubstance.Kilomoles / molarFlow.KilomolesPerSecond); + } + /// Get from * . public static Mass operator *(AmountOfSubstance amountOfSubstance, MolarMass molarMass) { return Mass.FromGrams(amountOfSubstance.Moles * molarMass.GramsPerMole); } + /// Get from / . + public static MolarFlow operator /(AmountOfSubstance amountOfSubstance, Duration duration) + { + return MolarFlow.FromKilomolesPerSecond(amountOfSubstance.Kilomoles / duration.Seconds); + } + /// Get from / . public static Molarity operator /(AmountOfSubstance amountOfSubstance, Volume volume) { diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index 30e9c87f47..4779c595ef 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -42,6 +42,7 @@ namespace UnitsNet public readonly partial struct Angle : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IDivisionOperators, IMultiplyOperators, #endif @@ -676,6 +677,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Angle #region Relational Operators + /// Get from / . + public static Duration operator /(Angle angle, RotationalSpeed rotationalSpeed) + { + return Duration.FromSeconds(angle.Radians / rotationalSpeed.RadiansPerSecond); + } + /// Get from / . public static RotationalSpeed operator /(Angle angle, Duration duration) { diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index 23fc12cd84..4dbb6648d8 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -42,8 +42,10 @@ namespace UnitsNet public readonly partial struct Area : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, @@ -654,6 +656,19 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU #region Relational Operators + /// Calculates the inverse of this quantity. + /// The corresponding inverse quantity, . + public ReciprocalArea Inverse() + { + return SquareMeters == 0.0 ? ReciprocalArea.Zero : ReciprocalArea.FromInverseSquareMeters(1 / SquareMeters); + } + + /// Get from / . + public static Duration operator /(Area area, KinematicViscosity kinematicViscosity) + { + return Duration.FromSeconds(area.SquareMeters / kinematicViscosity.SquareMetersPerSecond); + } + /// Get from * . public static Force operator *(Area area, Pressure pressure) { @@ -666,6 +681,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU return ForcePerLength.FromNewtonsPerMeter(area.SquareMeters * specificWeight.NewtonsPerCubicMeter); } + /// Get from / . + public static KinematicViscosity operator /(Area area, Duration duration) + { + return KinematicViscosity.FromSquareMetersPerSecond(area.SquareMeters / duration.Seconds); + } + /// Get from / . public static Length operator /(Area area, Length length) { @@ -693,7 +714,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU /// Get from * . public static MassFlow operator *(Area area, MassFlux massFlux) { - return MassFlow.FromGramsPerSecond(area.SquareMeters * massFlux.GramsPerSecondPerSquareMeter); + return MassFlow.FromKilogramsPerSecond(area.SquareMeters * massFlux.KilogramsPerSecondPerSquareMeter); } /// Get from * . @@ -708,13 +729,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU return Ratio.FromDecimalFractions(area.SquareMeters * reciprocalArea.InverseSquareMeters); } - /// Calculates the inverse of this quantity. - /// The corresponding inverse quantity, . - public ReciprocalArea Inverse() - { - return SquareMeters == 0.0 ? ReciprocalArea.Zero : ReciprocalArea.FromInverseSquareMeters(1 / SquareMeters); - } - /// Get from * . public static Torque operator *(Area area, ForcePerLength forcePerLength) { diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs index 25e70f94d7..840e9b6d03 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs @@ -42,6 +42,7 @@ namespace UnitsNet public readonly partial struct AreaMomentOfInertia : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -515,6 +516,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaM #region Relational Operators + /// Get from / . + public static Length operator /(AreaMomentOfInertia areaMomentOfInertia, Volume volume) + { + return Length.FromMeters(areaMomentOfInertia.MetersToTheFourth / volume.CubicMeters); + } + /// Get from / . public static Volume operator /(AreaMomentOfInertia areaMomentOfInertia, Length length) { diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs index ab35f654f4..b931c4e7fe 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs @@ -569,6 +569,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Coeff #region Relational Operators + /// Get from / . + public static TemperatureDelta operator /(double value, CoefficientOfThermalExpansion coefficientOfThermalExpansion) + { + return TemperatureDelta.FromKelvins(value / coefficientOfThermalExpansion.PerKelvin); + } + /// Get from * . public static double operator *(CoefficientOfThermalExpansion coefficientOfThermalExpansion, TemperatureDelta temperatureDelta) { diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs index 331e969778..54634fe5d0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs @@ -52,6 +52,7 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, + IMultiplyOperators, #endif IComparable, IComparable, @@ -1360,12 +1361,24 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Densi return MassFlux.FromKilogramsPerSecondPerSquareMeter(density.KilogramsPerCubicMeter * speed.MetersPerSecond); } + /// Get from / . + public static SpecificVolume operator /(double value, Density density) + { + return SpecificVolume.FromCubicMetersPerKilogram(value / density.KilogramsPerCubicMeter); + } + /// Get from * . public static SpecificWeight operator *(Density density, Acceleration acceleration) { return SpecificWeight.FromNewtonsPerCubicMeter(density.KilogramsPerCubicMeter * acceleration.MetersPerSecondSquared); } + /// Get from * . + public static double operator *(Density density, SpecificVolume specificVolume) + { + return density.KilogramsPerCubicMeter * specificVolume.CubicMetersPerKilogram; + } + #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs index e7d4c4c012..188f396f88 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs @@ -42,6 +42,7 @@ namespace UnitsNet public readonly partial struct Duration : IArithmeticQuantity, #if NET7_0_OR_GREATER + IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, @@ -607,6 +608,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Durat #region Relational Operators + /// Get from * . + public static Acceleration operator *(Duration duration, Jerk jerk) + { + return Acceleration.FromMetersPerSecondSquared(duration.Seconds * jerk.MetersPerSecondCubed); + } + /// Get from * . public static AmountOfSubstance operator *(Duration duration, MolarFlow molarFlow) { diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs index 19a6692710..b38c05ab62 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs @@ -45,6 +45,7 @@ namespace UnitsNet public readonly partial struct DynamicViscosity : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -582,6 +583,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Dynam #region Relational Operators + /// Get from / . + public static Density operator /(DynamicViscosity dynamicViscosity, KinematicViscosity kinematicViscosity) + { + return Density.FromKilogramsPerCubicMeter(dynamicViscosity.NewtonSecondsPerMeterSquared / kinematicViscosity.SquareMetersPerSecond); + } + /// Get from / . public static KinematicViscosity operator /(DynamicViscosity dynamicViscosity, Density density) { diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 9a5d304d76..d0ea9143fa 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -42,6 +42,7 @@ namespace UnitsNet public readonly partial struct ElectricCurrent : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, @@ -566,6 +567,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #region Relational Operators + /// Get from / . + public static Duration operator /(ElectricCurrent electricCurrent, ElectricCurrentGradient electricCurrentGradient) + { + return Duration.FromSeconds(electricCurrent.Amperes / electricCurrentGradient.AmperesPerSecond); + } + /// Get from * . public static ElectricCharge operator *(ElectricCurrent electricCurrent, Duration duration) { diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index 3710d9f452..bf03909e6e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -45,12 +45,14 @@ namespace UnitsNet IDivisionOperators, IDivisionOperators, IDivisionOperators, + IDivisionOperators, IDivisionOperators, IDivisionOperators, IMultiplyOperators, IDivisionOperators, IDivisionOperators, IDivisionOperators, + IDivisionOperators, #endif IComparable, IComparable, @@ -1085,6 +1087,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ return ElectricPotential.FromVolts(energy.Joules / electricCharge.Coulombs); } + /// Get from / . + public static EnergyDensity operator /(Energy energy, Volume volume) + { + return EnergyDensity.FromJoulesPerCubicMeter(energy.Joules / volume.CubicMeters); + } + /// Get from / . public static Entropy operator /(Energy energy, TemperatureDelta temperatureDelta) { @@ -1121,6 +1129,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ return TemperatureDelta.FromKelvins(energy.Joules / entropy.JoulesPerKelvin); } + /// Get from / . + public static Volume operator /(Energy energy, EnergyDensity energyDensity) + { + return Volume.FromCubicMeters(energy.Joules / energyDensity.JoulesPerCubicMeter); + } + #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs index a63179ab80..44ae5ecd7a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs @@ -43,6 +43,7 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -538,6 +539,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Entro return Energy.FromJoules(entropy.JoulesPerKelvin * temperatureDelta.Kelvins); } + /// Get from / . + public static Mass operator /(Entropy entropy, SpecificEntropy specificEntropy) + { + return Mass.FromKilograms(entropy.JoulesPerKelvin / specificEntropy.JoulesPerKilogramKelvin); + } + /// Get from / . public static SpecificEntropy operator /(Entropy entropy, Mass mass) { diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs index f0495ec4e3..a1274c9d42 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs @@ -43,7 +43,9 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IDivisionOperators, + IDivisionOperators, IDivisionOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IDivisionOperators, @@ -674,12 +676,24 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return Acceleration.FromMetersPerSecondSquared(force.Newtons / mass.Kilograms); } + /// Get from / . + public static Area operator /(Force force, Pressure pressure) + { + return Area.FromSquareMeters(force.Newtons / pressure.Pascals); + } + /// Get from / . public static Duration operator /(Force force, ForceChangeRate forceChangeRate) { return Duration.FromSeconds(force.Newtons / forceChangeRate.NewtonsPerSecond); } + /// Get from / . + public static ForceChangeRate operator /(Force force, Duration duration) + { + return ForceChangeRate.FromNewtonsPerSecond(force.Newtons / duration.Seconds); + } + /// Get from * . public static ForcePerLength operator *(Force force, ReciprocalLength reciprocalLength) { diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs index 5388adea49..b33a84b513 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs @@ -42,10 +42,14 @@ namespace UnitsNet public readonly partial struct ForcePerLength : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, IDivisionOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, + IDivisionOperators, + IDivisionOperators, IMultiplyOperators, #endif IComparable, @@ -1031,6 +1035,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force #region Relational Operators + /// Get from / . + public static Area operator /(ForcePerLength forcePerLength, SpecificWeight specificWeight) + { + return Area.FromSquareMeters(forcePerLength.NewtonsPerMeter / specificWeight.NewtonsPerCubicMeter); + } + /// Get from * . public static Force operator *(ForcePerLength forcePerLength, Length length) { @@ -1043,6 +1053,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return Force.FromNewtons(forcePerLength.NewtonsPerMeter / reciprocalLength.InverseMeters); } + /// Get from / . + public static Length operator /(ForcePerLength forcePerLength, Pressure pressure) + { + return Length.FromMeters(forcePerLength.NewtonsPerMeter / pressure.NewtonsPerSquareMeter); + } + /// Get from * . public static Pressure operator *(ForcePerLength forcePerLength, ReciprocalLength reciprocalLength) { @@ -1055,6 +1071,18 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return Pressure.FromNewtonsPerSquareMeter(forcePerLength.NewtonsPerMeter / length.Meters); } + /// Get from / . + public static ReciprocalLength operator /(ForcePerLength forcePerLength, Force force) + { + return ReciprocalLength.FromInverseMeters(forcePerLength.NewtonsPerMeter / force.Newtons); + } + + /// Get from / . + public static SpecificWeight operator /(ForcePerLength forcePerLength, Area area) + { + return SpecificWeight.FromNewtonsPerCubicMeter(forcePerLength.NewtonsPerMeter / area.SquareMeters); + } + /// Get from * . public static Torque operator *(ForcePerLength forcePerLength, Area area) { diff --git a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs index f3766501e4..657f51c33d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs @@ -21,6 +21,9 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; +#if NET7_0_OR_GREATER +using System.Numerics; +#endif using System.Runtime.Serialization; using UnitsNet.InternalHelpers; using UnitsNet.Units; @@ -38,6 +41,9 @@ namespace UnitsNet [DataContract] public readonly partial struct Jerk : IArithmeticQuantity, +#if NET7_0_OR_GREATER + IMultiplyOperators, +#endif IComparable, IComparable, IConvertible, @@ -587,6 +593,16 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out JerkU #endregion + #region Relational Operators + + /// Get from * . + public static Acceleration operator *(Jerk jerk, Duration duration) + { + return Acceleration.FromMetersPerSecondSquared(jerk.MetersPerSecondCubed * duration.Seconds); + } + + #endregion + #region Equality / IComparable /// Returns true if less or equal to. diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index e8fe56ad67..19dc50df99 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -47,6 +47,7 @@ namespace UnitsNet #if NET7_0_OR_GREATER IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -580,6 +581,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Kinem return DynamicViscosity.FromNewtonSecondsPerMeterSquared(kinematicViscosity.SquareMetersPerSecond * density.KilogramsPerCubicMeter); } + /// Get from / . + public static Length operator /(KinematicViscosity kinematicViscosity, Speed speed) + { + return Length.FromMeters(kinematicViscosity.SquareMetersPerSecond / speed.MetersPerSecond); + } + /// Get from / . public static Speed operator /(KinematicViscosity kinematicViscosity, Length length) { diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index e6695b1d5b..6e4ae98f80 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -43,11 +43,14 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, IMultiplyOperators, + IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, + IMultiplyOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, @@ -1101,12 +1104,25 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lengt #region Relational Operators + /// Calculates the inverse of this quantity. + /// The corresponding inverse quantity, . + public ReciprocalLength Inverse() + { + return Meters == 0.0 ? ReciprocalLength.Zero : ReciprocalLength.FromInverseMeters(1 / Meters); + } + /// Get from * . public static Area operator *(Length left, Length right) { return Area.FromSquareMeters(left.Meters * right.Meters); } + /// Get from * . + public static AreaMomentOfInertia operator *(Length length, Volume volume) + { + return AreaMomentOfInertia.FromMetersToTheFourth(length.Meters * volume.CubicMeters); + } + /// Get from / . public static Duration operator /(Length length, Speed speed) { @@ -1119,6 +1135,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lengt return Force.FromNewtons(length.Meters * forcePerLength.NewtonsPerMeter); } + /// Get from * . + public static ForcePerLength operator *(Length length, Pressure pressure) + { + return ForcePerLength.FromNewtonsPerMeter(length.Meters * pressure.NewtonsPerSquareMeter); + } + /// Get from * . public static KinematicViscosity operator *(Length length, Speed speed) { @@ -1137,11 +1159,10 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lengt return Pressure.FromPascals(length.Meters * specificWeight.NewtonsPerCubicMeter); } - /// Calculates the inverse of this quantity. - /// The corresponding inverse quantity, . - public ReciprocalLength Inverse() + /// Get from * . + public static ReciprocalLength operator *(Length length, ReciprocalArea reciprocalArea) { - return Meters == 0.0 ? ReciprocalLength.Zero : ReciprocalLength.FromInverseMeters(1 / Meters); + return ReciprocalLength.FromInverseMeters(length.Meters * reciprocalArea.InverseSquareMeters); } /// Get from * . diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index fbb52246e6..6c8463810c 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -46,6 +46,7 @@ namespace UnitsNet IDivisionOperators, IDivisionOperators, IDivisionOperators, + IDivisionOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, @@ -54,6 +55,7 @@ namespace UnitsNet IMultiplyOperators, IDivisionOperators, IDivisionOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, #endif @@ -867,7 +869,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU /// Get from / . public static AmountOfSubstance operator /(Mass mass, MolarMass molarMass) { - return AmountOfSubstance.FromMoles(mass.Kilograms / molarMass.KilogramsPerMole); + return AmountOfSubstance.FromMoles(mass.Grams / molarMass.GramsPerMole); } /// Get from / . @@ -888,6 +890,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU return Density.FromKilogramsPerCubicMeter(mass.Kilograms / volume.CubicMeters); } + /// Get from / . + public static Duration operator /(Mass mass, MassFlow massFlow) + { + return Duration.FromSeconds(mass.Kilograms / massFlow.KilogramsPerSecond); + } + /// Get from * . public static Energy operator *(Mass mass, SpecificEnergy specificEnergy) { @@ -936,6 +944,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU return MassFlow.FromKilogramsPerSecond(mass.Kilograms / duration.Seconds); } + /// Get from / . + public static MolarMass operator /(Mass mass, AmountOfSubstance amountOfSubstance) + { + return MolarMass.FromGramsPerMole(mass.Grams / amountOfSubstance.Moles); + } + /// Get from * . public static Volume operator *(Mass mass, SpecificVolume specificVolume) { diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs index ab3824391e..b3bd701696 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs @@ -45,7 +45,9 @@ namespace UnitsNet public readonly partial struct MassConcentration : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, IDivisionOperators, #endif @@ -1208,16 +1210,28 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassC #region Relational Operators + /// Get from / . + public static Density operator /(MassConcentration massConcentration, VolumeConcentration volumeConcentration) + { + return Density.FromKilogramsPerCubicMeter(massConcentration.KilogramsPerCubicMeter / volumeConcentration.DecimalFractions); + } + /// Get from * . public static Mass operator *(MassConcentration massConcentration, Volume volume) { return Mass.FromKilograms(massConcentration.KilogramsPerCubicMeter * volume.CubicMeters); } + /// Get from / . + public static MolarMass operator /(MassConcentration massConcentration, Molarity molarity) + { + return MolarMass.FromKilogramsPerMole(massConcentration.KilogramsPerCubicMeter / molarity.MolesPerCubicMeter); + } + /// Get from / . public static Molarity operator /(MassConcentration massConcentration, MolarMass molarMass) { - return Molarity.FromMolesPerCubicMeter(massConcentration.GramsPerCubicMeter / molarMass.GramsPerMole); + return Molarity.FromMolesPerCubicMeter(massConcentration.KilogramsPerCubicMeter / molarMass.KilogramsPerMole); } /// Get from / . diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index 2dc2d81e6c..5c62f5b89c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -47,6 +47,8 @@ namespace UnitsNet IDivisionOperators, IMultiplyOperators, IDivisionOperators, + IDivisionOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IDivisionOperators, @@ -984,6 +986,18 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF return MassFlux.FromKilogramsPerSecondPerSquareMeter(massFlow.KilogramsPerSecond / area.SquareMeters); } + /// Get from / . + public static MolarFlow operator /(MassFlow massFlow, MolarMass molarMass) + { + return MolarFlow.FromKilomolesPerSecond(massFlow.KilogramsPerSecond / molarMass.KilogramsPerKilomole); + } + + /// Get from / . + public static MolarMass operator /(MassFlow massFlow, MolarFlow molarFlow) + { + return MolarMass.FromKilogramsPerKilomole(massFlow.KilogramsPerSecond / molarFlow.KilomolesPerSecond); + } + /// Get from * . public static Power operator *(MassFlow massFlow, SpecificEnergy specificEnergy) { diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index 5b22a0347c..51e34f5505 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -622,7 +622,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF /// Get from * . public static MassFlow operator *(MassFlux massFlux, Area area) { - return MassFlow.FromGramsPerSecond(massFlux.GramsPerSecondPerSquareMeter * area.SquareMeters); + return MassFlow.FromKilogramsPerSecond(massFlux.KilogramsPerSecondPerSquareMeter * area.SquareMeters); } /// Get from / . diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs index fdd3530417..0ee93f35f4 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -44,6 +44,7 @@ namespace UnitsNet #if NET7_0_OR_GREATER IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -577,6 +578,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return MassFlow.FromKilogramsPerSecond(molarFlow.KilomolesPerSecond * molarMass.KilogramsPerKilomole); } + /// Get from / . + public static Molarity operator /(MolarFlow molarFlow, VolumeFlow volumeFlow) + { + return Molarity.FromMolesPerCubicMeter(molarFlow.MolesPerSecond / volumeFlow.CubicMetersPerSecond); + } + /// Get from / . public static VolumeFlow operator /(MolarFlow molarFlow, Molarity molarity) { diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index 1857133cc9..37114c0762 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -638,7 +638,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// Get from * . public static MassConcentration operator *(MolarMass molarMass, Molarity molarity) { - return MassConcentration.FromGramsPerCubicMeter(molarMass.GramsPerMole * molarity.MolesPerCubicMeter); + return MassConcentration.FromKilogramsPerCubicMeter(molarMass.KilogramsPerMole * molarity.MolesPerCubicMeter); } /// Get from * . diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index 20d292ea00..edc4201ad7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -45,8 +45,11 @@ namespace UnitsNet public readonly partial struct Molarity : IArithmeticQuantity, #if NET7_0_OR_GREATER + IMultiplyOperators, IMultiplyOperators, + IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, #endif IComparable, IComparable, @@ -599,10 +602,22 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar #region Relational Operators + /// Get from * . + public static AmountOfSubstance operator *(Molarity molarity, Volume volume) + { + return AmountOfSubstance.FromMoles(molarity.MolesPerCubicMeter * volume.CubicMeters); + } + /// Get from * . public static MassConcentration operator *(Molarity molarity, MolarMass molarMass) { - return MassConcentration.FromGramsPerCubicMeter(molarity.MolesPerCubicMeter * molarMass.GramsPerMole); + return MassConcentration.FromKilogramsPerCubicMeter(molarity.MolesPerCubicMeter * molarMass.KilogramsPerMole); + } + + /// Get from * . + public static MolarFlow operator *(Molarity molarity, VolumeFlow volumeFlow) + { + return MolarFlow.FromMolesPerSecond(molarity.MolesPerCubicMeter * volumeFlow.CubicMetersPerSecond); } /// Get from * . @@ -611,6 +626,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return Molarity.FromMolesPerCubicMeter(molarity.MolesPerCubicMeter * volumeConcentration.DecimalFractions); } + /// Get from / . + public static Molarity operator /(Molarity molarity, VolumeConcentration volumeConcentration) + { + return Molarity.FromMolesPerCubicMeter(molarity.MolesPerCubicMeter / volumeConcentration.DecimalFractions); + } + #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index 3514c7be25..20edecda3d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -46,12 +46,15 @@ namespace UnitsNet IDivisionOperators, IDivisionOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, + IDivisionOperators, IDivisionOperators, IMultiplyOperators, IDivisionOperators, IDivisionOperators, IDivisionOperators, + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -869,12 +872,24 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power return Energy.FromJoules(power.Watts * duration.Seconds); } + /// Get from / . + public static Energy operator /(Power power, Frequency frequency) + { + return Energy.FromJoules(power.Watts / frequency.PerSecond); + } + /// Get from / . public static Force operator /(Power power, Speed speed) { return Force.FromNewtons(power.Watts / speed.MetersPerSecond); } + /// Get from / . + public static Frequency operator /(Power power, Energy energy) + { + return Frequency.FromPerSecond(power.Watts / energy.Joules); + } + /// Get from / . public static HeatFlux operator /(Power power, Area area) { @@ -905,6 +920,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power return SpecificEnergy.FromJoulesPerKilogram(power.Watts / massFlow.KilogramsPerSecond); } + /// Get from / . + public static Speed operator /(Power power, Force force) + { + return Speed.FromMetersPerSecond(power.Watts / force.Newtons); + } + /// Get from / . public static Torque operator /(Power power, RotationalSpeed rotationalSpeed) { diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index 461320f9ba..2b9b0ac0c2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -42,11 +42,15 @@ namespace UnitsNet public readonly partial struct Pressure : IArithmeticQuantity, #if NET7_0_OR_GREATER - IMultiplyOperators, + IDivisionOperators, IDivisionOperators, + IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, IDivisionOperators, IDivisionOperators, + IDivisionOperators, + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -1208,22 +1212,34 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press #region Relational Operators + /// Get from / . + public static Duration operator /(Pressure pressure, PressureChangeRate pressureChangeRate) + { + return Duration.FromSeconds(pressure.Pascals / pressureChangeRate.PascalsPerSecond); + } + + /// Get from / . + public static Force operator /(Pressure pressure, ReciprocalArea reciprocalArea) + { + return Force.FromNewtons(pressure.NewtonsPerSquareMeter / reciprocalArea.InverseSquareMeters); + } + /// Get from * . public static Force operator *(Pressure pressure, Area area) { return Force.FromNewtons(pressure.Pascals * area.SquareMeters); } - /// Get from / . - public static Force operator /(Pressure pressure, ReciprocalArea reciprocalArea) + /// Get from * . + public static ForcePerLength operator *(Pressure pressure, Length length) { - return Force.FromNewtons(pressure.Pascals / reciprocalArea.InverseSquareMeters); + return ForcePerLength.FromNewtonsPerMeter(pressure.NewtonsPerSquareMeter * length.Meters); } /// Get from / . public static ForcePerLength operator /(Pressure pressure, ReciprocalLength reciprocalLength) { - return ForcePerLength.FromNewtonsPerMeter(pressure.Pascals / reciprocalLength.InverseMeters); + return ForcePerLength.FromNewtonsPerMeter(pressure.NewtonsPerSquareMeter / reciprocalLength.InverseMeters); } /// Get from / . @@ -1238,6 +1254,18 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press return PressureChangeRate.FromPascalsPerSecond(pressure.Pascals / duration.Seconds); } + /// Get from / . + public static ReciprocalArea operator /(Pressure pressure, Force force) + { + return ReciprocalArea.FromInverseSquareMeters(pressure.NewtonsPerSquareMeter / force.Newtons); + } + + /// Get from / . + public static ReciprocalLength operator /(Pressure pressure, ForcePerLength forcePerLength) + { + return ReciprocalLength.FromInverseMeters(pressure.NewtonsPerSquareMeter / forcePerLength.NewtonsPerMeter); + } + /// Get from / . public static SpecificWeight operator /(Pressure pressure, Length length) { diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs index 93351cfc49..b796ef11fa 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs @@ -21,6 +21,9 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; +#if NET7_0_OR_GREATER +using System.Numerics; +#endif using System.Runtime.Serialization; using UnitsNet.InternalHelpers; using UnitsNet.Units; @@ -38,6 +41,10 @@ namespace UnitsNet [DataContract] public readonly partial struct Ratio : IArithmeticQuantity, +#if NET7_0_OR_GREATER + IDivisionOperators, + IDivisionOperators, +#endif IComparable, IComparable, IConvertible, @@ -507,6 +514,22 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio #endregion + #region Relational Operators + + /// Get from / . + public static Area operator /(Ratio ratio, ReciprocalArea reciprocalArea) + { + return Area.FromSquareMeters(ratio.DecimalFractions / reciprocalArea.InverseSquareMeters); + } + + /// Get from / . + public static ReciprocalArea operator /(Ratio ratio, Area area) + { + return ReciprocalArea.FromInverseSquareMeters(ratio.DecimalFractions / area.SquareMeters); + } + + #endregion + #region Equality / IComparable /// Returns true if less or equal to. diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs index 74b4bfab09..8bf4af8a24 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs @@ -47,6 +47,7 @@ namespace UnitsNet #if NET7_0_OR_GREATER IMultiplyOperators, IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, #endif IComparable, @@ -600,6 +601,13 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip #region Relational Operators + /// Calculates the inverse of this quantity. + /// The corresponding inverse quantity, . + public Area Inverse() + { + return InverseSquareMeters == 0.0 ? Area.Zero : Area.FromSquareMeters(1 / InverseSquareMeters); + } + /// Get from * . public static Pressure operator *(ReciprocalArea reciprocalArea, Force force) { @@ -612,11 +620,10 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip return Ratio.FromDecimalFractions(reciprocalArea.InverseSquareMeters * area.SquareMeters); } - /// Calculates the inverse of this quantity. - /// The corresponding inverse quantity, . - public Area Inverse() + /// Get from * . + public static ReciprocalLength operator *(ReciprocalArea reciprocalArea, Length length) { - return InverseSquareMeters == 0.0 ? Area.Zero : Area.FromSquareMeters(1 / InverseSquareMeters); + return ReciprocalLength.FromInverseMeters(reciprocalArea.InverseSquareMeters * length.Meters); } /// Get from / . diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index 5bc05e0eec..8fa5f8bcd3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -49,6 +49,7 @@ namespace UnitsNet IDivisionOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, #endif IComparable, IComparable, @@ -585,6 +586,13 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip #region Relational Operators + /// Calculates the inverse of this quantity. + /// The corresponding inverse quantity, . + public Length Inverse() + { + return InverseMeters == 0.0 ? Length.Zero : Length.FromMeters(1 / InverseMeters); + } + /// Get from * . public static ForcePerLength operator *(ReciprocalLength reciprocalLength, Force force) { @@ -609,11 +617,10 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip return ReciprocalArea.FromInverseSquareMeters(left.InverseMeters * right.InverseMeters); } - /// Calculates the inverse of this quantity. - /// The corresponding inverse quantity, . - public Length Inverse() + /// Get from / . + public static ReciprocalArea operator /(ReciprocalLength reciprocalLength, Length length) { - return InverseMeters == 0.0 ? Length.Zero : Length.FromMeters(1 / InverseMeters); + return ReciprocalArea.FromInverseSquareMeters(reciprocalLength.InverseMeters / length.Meters); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index 72a953fa87..2f917223fa 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -43,6 +43,7 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, + IMultiplyOperators, #endif IComparable, IComparable, @@ -633,6 +634,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat return Angle.FromRadians(rotationalSpeed.RadiansPerSecond * duration.Seconds); } + /// Get from * . + public static Power operator *(RotationalSpeed rotationalSpeed, Torque torque) + { + return Power.FromWatts(rotationalSpeed.RadiansPerSecond * torque.NewtonMeters); + } + #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs index 311617efc7..90133848e1 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs @@ -48,6 +48,8 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IDivisionOperators, + IDivisionOperators, + IDivisionOperators, IMultiplyOperators, #endif IComparable, @@ -929,6 +931,18 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return SpecificEntropy.FromJoulesPerKilogramKelvin(specificEnergy.JoulesPerKilogram / temperatureDelta.Kelvins); } + /// Get from / . + public static Speed operator /(SpecificEnergy specificEnergy, Speed speed) + { + return Speed.FromMetersPerSecond(specificEnergy.JoulesPerKilogram / speed.MetersPerSecond); + } + + /// Get from / . + public static TemperatureDelta operator /(SpecificEnergy specificEnergy, SpecificEntropy specificEntropy) + { + return TemperatureDelta.FromKelvins(specificEnergy.JoulesPerKilogram / specificEntropy.JoulesPerKilogramKelvin); + } + /// Get from * . public static double operator *(SpecificEnergy specificEnergy, BrakeSpecificFuelConsumption brakeSpecificFuelConsumption) { diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs index fcc1ed7e0e..c65602c990 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs @@ -43,6 +43,7 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, + IMultiplyOperators, #endif IComparable, IComparable, @@ -479,6 +480,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return Volume.FromCubicMeters(specificVolume.CubicMetersPerKilogram * mass.Kilograms); } + /// Get from * . + public static double operator *(SpecificVolume specificVolume, Density density) + { + return specificVolume.CubicMetersPerKilogram * density.KilogramsPerCubicMeter; + } + #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs index 6d567d20d2..a3001d3e02 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs @@ -42,9 +42,11 @@ namespace UnitsNet public readonly partial struct TemperatureDelta : IArithmeticQuantity, #if NET7_0_OR_GREATER + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, + IDivisionOperators, IDivisionOperators, IMultiplyOperators, #endif @@ -567,6 +569,18 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe #region Relational Operators + /// Get from / . + public static CoefficientOfThermalExpansion operator /(double value, TemperatureDelta temperatureDelta) + { + return CoefficientOfThermalExpansion.FromPerKelvin(value / temperatureDelta.Kelvins); + } + + /// Get from / . + public static Duration operator /(TemperatureDelta temperatureDelta, TemperatureChangeRate temperatureChangeRate) + { + return Duration.FromSeconds(temperatureDelta.DegreesCelsius / temperatureChangeRate.DegreesCelsiusPerSecond); + } + /// Get from * . public static Energy operator *(TemperatureDelta temperatureDelta, Entropy entropy) { @@ -576,7 +590,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe /// Get from / . public static Length operator /(TemperatureDelta temperatureDelta, TemperatureGradient temperatureGradient) { - return Length.FromKilometers(temperatureDelta.Kelvins / temperatureGradient.DegreesCelsiusPerKilometer); + return Length.FromKilometers(temperatureDelta.DegreesCelsius / temperatureGradient.DegreesCelsiusPerKilometer); } /// Get from * . @@ -585,10 +599,16 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe return SpecificEnergy.FromJoulesPerKilogram(temperatureDelta.Kelvins * specificEntropy.JoulesPerKilogramKelvin); } + /// Get from / . + public static TemperatureChangeRate operator /(TemperatureDelta temperatureDelta, Duration duration) + { + return TemperatureChangeRate.FromDegreesCelsiusPerSecond(temperatureDelta.DegreesCelsius / duration.Seconds); + } + /// Get from / . public static TemperatureGradient operator /(TemperatureDelta temperatureDelta, Length length) { - return TemperatureGradient.FromKelvinsPerMeter(temperatureDelta.Kelvins / length.Meters); + return TemperatureGradient.FromDegreesCelsiusPerKilometer(temperatureDelta.DegreesCelsius / length.Kilometers); } /// Get from * . diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs index 694ad7a955..0f02672f0e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs @@ -43,8 +43,11 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IDivisionOperators, + IDivisionOperators, IDivisionOperators, + IDivisionOperators, IDivisionOperators, + IMultiplyOperators, IDivisionOperators, #endif IComparable, @@ -828,18 +831,36 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu return Angle.FromRadians(torque.NewtonMeters / rotationalStiffness.NewtonMetersPerRadian); } + /// Get from / . + public static Area operator /(Torque torque, ForcePerLength forcePerLength) + { + return Area.FromSquareMeters(torque.NewtonMeters / forcePerLength.NewtonsPerMeter); + } + /// Get from / . public static Force operator /(Torque torque, Length length) { return Force.FromNewtons(torque.NewtonMeters / length.Meters); } + /// Get from / . + public static ForcePerLength operator /(Torque torque, Area area) + { + return ForcePerLength.FromNewtonsPerMeter(torque.NewtonMeters / area.SquareMeters); + } + /// Get from / . public static Length operator /(Torque torque, Force force) { return Length.FromMeters(torque.NewtonMeters / force.Newtons); } + /// Get from * . + public static Power operator *(Torque torque, RotationalSpeed rotationalSpeed) + { + return Power.FromWatts(torque.NewtonMeters * rotationalSpeed.RadiansPerSecond); + } + /// Get from / . public static RotationalStiffness operator /(Torque torque, Angle angle) { diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index 1f7613d346..880acbe456 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -42,11 +42,16 @@ namespace UnitsNet public readonly partial struct Volume : IArithmeticQuantity, #if NET7_0_OR_GREATER + IMultiplyOperators, IDivisionOperators, + IMultiplyOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, + IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -1288,12 +1293,30 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #region Relational Operators + /// Get from * . + public static AmountOfSubstance operator *(Volume volume, Molarity molarity) + { + return AmountOfSubstance.FromMoles(volume.CubicMeters * molarity.MolesPerCubicMeter); + } + /// Get from / . public static Area operator /(Volume volume, Length length) { return Area.FromSquareMeters(volume.CubicMeters / length.Meters); } + /// Get from * . + public static AreaMomentOfInertia operator *(Volume volume, Length length) + { + return AreaMomentOfInertia.FromMetersToTheFourth(volume.CubicMeters * length.Meters); + } + + /// Get from / . + public static Duration operator /(Volume volume, VolumeFlow volumeFlow) + { + return Duration.FromSeconds(volume.CubicMeters / volumeFlow.CubicMetersPerSecond); + } + /// Get from * . public static Energy operator *(Volume volume, EnergyDensity energyDensity) { @@ -1318,6 +1341,18 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return Mass.FromKilograms(volume.CubicMeters * massConcentration.KilogramsPerCubicMeter); } + /// Get from / . + public static Mass operator /(Volume volume, SpecificVolume specificVolume) + { + return Mass.FromKilograms(volume.CubicMeters / specificVolume.CubicMetersPerKilogram); + } + + /// Get from / . + public static SpecificVolume operator /(Volume volume, Mass mass) + { + return SpecificVolume.FromCubicMetersPerKilogram(volume.CubicMeters / mass.Kilograms); + } + /// Get from / . public static VolumeFlow operator /(Volume volume, Duration duration) { diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index bf86afcf8b..3c6413452c 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -44,6 +44,7 @@ namespace UnitsNet #if NET7_0_OR_GREATER IDivisionOperators, IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, IMultiplyOperators, #endif @@ -1506,6 +1507,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return MassFlow.FromKilogramsPerSecond(volumeFlow.CubicMetersPerSecond * density.KilogramsPerCubicMeter); } + /// Get from * . + public static MolarFlow operator *(VolumeFlow volumeFlow, Molarity molarity) + { + return MolarFlow.FromMolesPerSecond(volumeFlow.CubicMetersPerSecond * molarity.MolesPerCubicMeter); + } + /// Get from / . public static Speed operator /(VolumeFlow volumeFlow, Area area) {