Skip to content

Commit

Permalink
Add si method to defined units
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxcode123 committed Feb 19, 2024
1 parent 6c2aa67 commit d5287fa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/property_utils/units/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ class NonDimensionalUnit(MeasurementUnit):

NON_DIMENSIONAL = ""

@classmethod
def si(cls) -> "NonDimensionalUnit":
return cls.NON_DIMENSIONAL


class TemperatureUnit(MeasurementUnit):
CELCIUS = "°C"
KELVIN = "K"
FAHRENHEIT = "°F"
RANKINE = "°R"

@classmethod
def si(cls) -> "TemperatureUnit":
return cls.KELVIN


class LengthUnit(MeasurementUnit):
MILLI_METER = "mm"
Expand All @@ -30,6 +38,10 @@ class LengthUnit(MeasurementUnit):
INCH = "in"
FOOT = "ft"

@classmethod
def si(cls) -> "LengthUnit":
return cls.METER


class MassUnit(MeasurementUnit):
MILLI_GRAM = "mg"
Expand All @@ -38,11 +50,19 @@ class MassUnit(MeasurementUnit):
METRIC_TONNE = "MT"
POUND = "lb"

@classmethod
def si(cls) -> "MassUnit":
return cls.KILO_GRAM


class AmountUnit(MeasurementUnit):
MOL = "mol"
KILO_MOL = "kmol"

@classmethod
def si(cls) -> "AmountUnit":
return cls.MOL


class TimeUnit(MeasurementUnit):
MILLI_SECOND = "ms"
Expand All @@ -51,6 +71,10 @@ class TimeUnit(MeasurementUnit):
HOUR = "hr"
DAY = "d"

@classmethod
def si(cls) -> "TimeUnit":
return cls.SECOND


class PressureUnit(AliasMeasurementUnit):
MILLI_BAR = "mbar"
Expand All @@ -63,6 +87,10 @@ class PressureUnit(AliasMeasurementUnit):
def aliased_generic_descriptor(cls) -> GenericCompositeDimension:
return MassUnit / LengthUnit / (TimeUnit**2)

@classmethod
def si(cls) -> "PressureUnit":
return cls.PASCAL


class EnergyUnit(AliasMeasurementUnit):
JOULE = "J"
Expand All @@ -76,3 +104,7 @@ class EnergyUnit(AliasMeasurementUnit):
@classmethod
def aliased_generic_descriptor(cls) -> GenericCompositeDimension:
return MassUnit * (LengthUnit**2) / (TimeUnit**2)

@classmethod
def si(cls) -> "EnergyUnit":
return cls.JOULE

0 comments on commit d5287fa

Please sign in to comment.