diff --git a/CaliperSharp/MeasurementSystem.cs b/CaliperSharp/MeasurementSystem.cs index b734c0f..2bc79d5 100644 --- a/CaliperSharp/MeasurementSystem.cs +++ b/CaliperSharp/MeasurementSystem.cs @@ -968,7 +968,9 @@ private UnitOfMeasure CreateCustomaryUnit(Unit unit) // inches of Mercury uom = CreateScalarUOM(UnitType.PRESSURE, Unit.IN_HG, UnitsManager.GetString("inhg.name"), UnitsManager.GetString("inhg.symbol"), UnitsManager.GetString("inhg.desc")); - uom.SetConversion(0.4911531047, GetUOM(Unit.PSI)); + UnitOfMeasure u1 = CreateProductUOM(GetUOM(Unit.FOOT), GetUOM(Unit.SQUARE_SECOND)); + UnitOfMeasure u2 = CreateQuotientUOM(GetUOM(Unit.POUND_MASS), u1); + uom.SetConversion(2275.520677, u2); break; case Unit.SQUARE_INCH: diff --git a/CaliperSharp/bin/Release/CaliperSharp.dll b/CaliperSharp/bin/Release/CaliperSharp.dll index e9bd604..cc8802c 100644 Binary files a/CaliperSharp/bin/Release/CaliperSharp.dll and b/CaliperSharp/bin/Release/CaliperSharp.dll differ diff --git a/CaliperSharpTests/TestPartial.cs b/CaliperSharpTests/TestPartial.cs index ca8ce13..cc030c8 100644 --- a/CaliperSharpTests/TestPartial.cs +++ b/CaliperSharpTests/TestPartial.cs @@ -10,6 +10,16 @@ public class TestPartial : BaseTest [TestMethod] public void TestSnippet() { + UnitOfMeasure gUOM = sys.GetUOM(Unit.NEWTON_METRE).Multiply(sys.GetUOM(Unit.METRE)).Divide(sys.CreatePowerUOM(sys.GetUOM(Unit.KILOGRAM), 2)); + Quantity G = new Quantity(6.743015E-11, gUOM); + Quantity mEarth = new Quantity(5.96E24, sys.GetUOM(Unit.KILOGRAM)); + Quantity mMoon = new Quantity(7.33E22, sys.GetUOM(Unit.KILOGRAM)); + Quantity distance = new Quantity(3.84E08, sys.GetUOM(Unit.METRE)); + Quantity force = G.Multiply(mEarth).Multiply(mMoon).Divide(distance.Multiply(distance)); + + Console.WriteLine("Done"); + + } } } diff --git a/CaliperSharpTests/TestUnits.cs b/CaliperSharpTests/TestUnits.cs index 622306e..496b100 100644 --- a/CaliperSharpTests/TestUnits.cs +++ b/CaliperSharpTests/TestUnits.cs @@ -1768,5 +1768,56 @@ public void TestMeasurementTypes() Assert.IsTrue(a.GetMeasurementType().Equals(UnitOfMeasure.MeasurementType.POWER)); } + [TestMethod] + public void TestPerm() + { + UnitOfMeasure inHg = sys.GetUOM(Unit.IN_HG); + UnitOfMeasure hr = sys.GetUOM(Unit.HOUR); + UnitOfMeasure ft2 = sys.GetUOM(Unit.SQUARE_FOOT); + UnitOfMeasure s = sys.GetUOM(Unit.SECOND); + UnitOfMeasure day = sys.GetUOM(Unit.DAY); + UnitOfMeasure msq = sys.GetUOM(Unit.SQUARE_METRE); + UnitOfMeasure Pa = sys.GetUOM(Unit.PASCAL); + UnitOfMeasure ng = sys.GetUOM(Prefix.NANO, Unit.GRAM); + UnitOfMeasure g = sys.GetUOM(Unit.GRAM); + UnitOfMeasure grain = sys.GetUOM(Unit.GRAIN); + + // mm of Mercury pressure + UnitOfMeasure mmHg = sys.CreateScalarUOM(UnitType.PRESSURE, "mmHg", "mmHg", "mmHg"); + mmHg.SetConversion(133.3223684d, Pa); + + // US perm + UnitOfMeasure us1 = sys.CreateQuotientUOM(grain, inHg); + UnitOfMeasure us2 = sys.CreateQuotientUOM(us1, ft2); + UnitOfMeasure perm = sys.CreateQuotientUOM(UnitType.UNCLASSIFIED, "perm", "perm", "gn/hr/ft2/inHg", us2, hr); + + // metric perm + UnitOfMeasure m1 = sys.CreateQuotientUOM(g, day); + UnitOfMeasure m2 = sys.CreateQuotientUOM(m1, msq); + UnitOfMeasure mperm = sys.CreateQuotientUOM(UnitType.UNCLASSIFIED, "mperm", "mperm", "g/day/m2/mmHg", m2, mmHg); + + // Equivalent SI unit + UnitOfMeasure si1 = sys.CreateQuotientUOM(ng, s); + UnitOfMeasure si2 = sys.CreateQuotientUOM(si1, msq); + UnitOfMeasure eqSI = sys.CreateQuotientUOM(si2, Pa); + + // US perm to equivalent SI + double f = perm.GetConversionFactor(eqSI); + Assert.IsTrue(IsCloseTo(f, 57.214184d, DELTA6)); + f = eqSI.GetConversionFactor(perm); + Assert.IsTrue(IsCloseTo(f, 0.0174781d, DELTA6)); + + // metric perm to US perm + f = perm.GetConversionFactor(mperm); + Assert.IsTrue(IsCloseTo(f, 0.659053d, DELTA6)); + f = mperm.GetConversionFactor(perm); + Assert.IsTrue(IsCloseTo(f, 1.517328d, DELTA6)); + + // metric perm to equivalent SI + f = mperm.GetConversionFactor(eqSI); + Assert.IsTrue(IsCloseTo(f, 86.812694d, DELTA6)); + f = eqSI.GetConversionFactor(mperm); + Assert.IsTrue(IsCloseTo(f, 0.0115190d, DELTA6)); + } } // end TestUnits } // end namespace