Skip to content

Commit

Permalink
Merge pull request #74 from ESSS/fb-ASIM-4452-force-per-square-veloci…
Browse files Browse the repository at this point in the history
…ty-to-barril

Add "force per velocity squared"
  • Loading branch information
prusse-martin authored Nov 30, 2021
2 parents 1f54263 + 43c64b4 commit 11502e2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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)
-------------------

Expand Down
19 changes: 12 additions & 7 deletions src/barril/units/_tests/test_legacy_unit.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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:
Expand Down Expand Up @@ -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]


Expand Down
43 changes: 41 additions & 2 deletions src/barril/units/posc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/barril/units/unit_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 11502e2

Please sign in to comment.