From fc160cc892e9e33d0632420b1e6e7d56f668ea74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pr=C3=BCsse?= Date: Wed, 24 Nov 2021 17:38:31 -0300 Subject: [PATCH 1/3] Add "force per velocity squared" Also update the base unit of "force per velocity" to make it consistent with the other units of the category. Did add input support to the legacy unit writing. ASIM-4452 --- src/barril/units/posc.py | 43 +++++++++++++++++++++++++++++-- src/barril/units/unit_database.py | 5 ++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/barril/units/posc.py b/src/barril/units/posc.py index 5865985..cfc328a 100644 --- a/src/barril/units/posc.py +++ b/src/barril/units/posc.py @@ -290,13 +290,16 @@ def FillUnitDatabaseWithPosc( db.AddUnitBase("computer binary memory", "Byte", "Byte") db.AddUnitBase("flow coefficient", "flow rate per pressure power of 0.5 ", "(m3/s)/(Pa^0.5)") db.AddUnitBase("temperature per area", "degrees Celsius per square meter", "degC/m2") - db.AddUnitBase("force per velocity", "Newton second per meter", "Ns/m") + db.AddUnitBase("force per velocity", "Newton second per meter", "N.s/m") db.AddUnitBase("force per angle", "Newton per angle", "N/rad") db.AddUnitBase("force per angular velocity", "Newton second per angle", "Ns/rad") db.AddUnitBase("moment per angle", "Newton meter per angle", "Nm/rad") db.AddUnitBase("moment per angular velocity", "newton meter per angular velocity", "Nms/rad") db.AddUnitBase("mass temperature per mol", "kg.K/mol", "kg.K/mol") db.AddUnitBase("joule-thomson coefficient", "delta kelvin per pascal", "K/Pa") + db.AddUnitBase( + "force per velocity squared", "Newton second squared per meter squared", "N.s2/m2" + ) f_unit_to_base = MakeCustomaryToBase(0.0, 6.283185307, 1.0, 0.0) f_base_to_unit = MakeBaseToCustomary(0.0, 6.283185307, 1.0, 0.0) db.AddUnit("frequency", "hertz", "Hz", f_base_to_unit, f_unit_to_base, default_category=None) @@ -12265,6 +12268,36 @@ def FillUnitDatabaseWithPosc( f_unit_to_base, default_category=None, ) + f_unit_to_base = MakeCustomaryToBase(0.0, 47.8802631216, 1.0, 0.0) + f_base_to_unit = MakeBaseToCustomary(0.0, 47.8802631216, 1.0, 0.0) + db.AddUnit( + "force per velocity squared", + "Pound force second squared per foot squared", + "lbf.s2/ft2", + f_base_to_unit, + f_unit_to_base, + default_category=None, + ) + f_unit_to_base = MakeCustomaryToBase(0.0, 6894.75788952, 1.0, 0.0) + f_base_to_unit = MakeBaseToCustomary(0.0, 6894.75788952, 1.0, 0.0) + db.AddUnit( + "force per velocity squared", + "Pound force second squared per inch squared", + "lbf.s2/in2", + f_base_to_unit, + f_unit_to_base, + default_category=None, + ) + f_unit_to_base = MakeCustomaryToBase(0.0, 9.80665, 1.0, 0.0) + f_base_to_unit = MakeBaseToCustomary(0.0, 9.80665, 1.0, 0.0) + db.AddUnit( + "force per velocity squared", + "Kilogram force second squared per meter squared", + "kgf.s2/m2", + f_base_to_unit, + f_unit_to_base, + default_category=None, + ) if fill_categories: db.AddCategory( "reluctance", "reluctance", override=override_categories, valid_units=["1/H"] @@ -15605,7 +15638,7 @@ def FillUnitDatabaseWithPosc( "force per velocity", "force per velocity", override=override_categories, - valid_units=["Ns/m", "lbf.s/ft", "lbf.s/in", "kgf.s/m"], + valid_units=["N.s/m", "lbf.s/ft", "lbf.s/in", "kgf.s/m"], ) db.AddCategory( "force per angle", @@ -15684,6 +15717,12 @@ def FillUnitDatabaseWithPosc( "degR/MPa", ], ) + db.AddCategory( + "force per velocity squared", + "force per velocity squared", + valid_units=["N.s2/m2", "lbf.s2/ft2", "lbf.s2/in2", "kgf.s2/m2"], + override=True, + ) return db diff --git a/src/barril/units/unit_database.py b/src/barril/units/unit_database.py index 1c8bb0d..320589f 100644 --- a/src/barril/units/unit_database.py +++ b/src/barril/units/unit_database.py @@ -39,13 +39,14 @@ ] -_LEGACY_TO_CURRENT = { +_LEGACY_TO_CURRENT: List[Tuple[str, str]] = [ ("1000ft3", "Mcf"), ("1000m3", "Mm3"), ("M(ft3)", "MMcf"), ("M(m3)", "MMm3"), ("k(ft3)", "Mcf"), -} + ("Ns/m", "N.s/m"), +] def FixUnitIfIsLegacy(unit: str) -> Tuple[bool, str]: From bc89d96fe598c951e8bf4af0351fbe5242faa56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pr=C3=BCsse?= Date: Thu, 25 Nov 2021 09:16:07 -0300 Subject: [PATCH 2/3] Split legacy units test into 2 Execute the "test all legacy units" in a tests of its own. --- src/barril/units/_tests/test_legacy_unit.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/barril/units/_tests/test_legacy_unit.py b/src/barril/units/_tests/test_legacy_unit.py index 7ddfcd4..6e1bbc8 100644 --- a/src/barril/units/_tests/test_legacy_unit.py +++ b/src/barril/units/_tests/test_legacy_unit.py @@ -1,12 +1,12 @@ +import pytest from pytest import approx from pytest import raises from barril.units import Scalar +from barril.units.unit_database import _LEGACY_TO_CURRENT -def testConvertLegacyUnit() -> None: - from barril.units.unit_database import _LEGACY_TO_CURRENT - +def testCubicFeetPerDayLegacyUnits() -> None: # test creating scalar using legacy representation and default category q = Scalar(1.0, "1000ft3/d") assert q.GetUnit() == "Mcf/d" @@ -23,9 +23,14 @@ def testConvertLegacyUnit() -> None: assert approx(q.GetValue("M(ft3)/d")) == q.GetValue("MMcf/d") assert q.GetUnitName() == "million cubic feet per day" - # Test all possible legacy formats - for legacy, current in _LEGACY_TO_CURRENT: - assert Scalar(1.0, legacy).GetUnit() == current + +@pytest.mark.parametrize("legacy, current", _LEGACY_TO_CURRENT) +@pytest.mark.parametrize("value", [1.0, 3.1415, 123.567]) +def testAllLegacyUnits(legacy: str, current: str, value: float) -> None: + test_scalar = Scalar(value, legacy) + assert test_scalar.GetUnit() == current + assert approx(test_scalar.GetValue(legacy)) == value + assert approx(test_scalar.GetValue(current)) == value def testCreateScalarUnitsError() -> None: @@ -53,7 +58,7 @@ class SomeNonExpectedObject: unknown = SomeNonExpectedObject() is_legacy, unit = FixUnitIfIsLegacy(unknown) # type:ignore[arg-type] - assert is_legacy == False + assert not is_legacy assert unit is unknown # type:ignore[comparison-overlap] From 43c64b4f8c686c6e5f2f6cadb9bf9a35dda4ad71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pr=C3=BCsse?= Date: Thu, 25 Nov 2021 09:22:28 -0300 Subject: [PATCH 3/3] Update change log --- CHANGELOG.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b53c3c5..239d665 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +1.13.0 (unreleased) +------------------- + +* Update ``Newton second per meter`` unit from ``Ns/m`` to ``N.s/m`` to get unit display consistent with other units in the same category (support for the old unit input added). +* Add ``force per velocity squared`` quantity (``N.s2/m2``, ``lbf.s2/ft2``, ``lbf.s2/in2``, ``kgf.s2/m2``). + 1.12.0 (2021-11-08) -------------------