Unit#
- class ansys.units.unit.Unit(units: str | None = None, config: dict | None = None, dimensions: Dimensions | None = None, system: UnitSystem | str | None = None, table: dict | None = None, copy_from: Unit | None = None)#
Bases:
objectA class containing the string name and dimensions of a unit.
- Parameters:
- units: str, optional
Name of the unit or string chain of combined units
- config: dict, optional
dictionary of unit properties
- dimensions: Dimensions, optional
An instance of the Dimensions class.
- system: str, optional
Define the unit system for base units of dimension, default is SI.
- table: dict, optional
A dictionary of api table keys from the cfg.yaml and exponent values.
- copy_from: Unit, optional
A previous instance of Unit.
- Attributes:
nameThe unit string.
si_unitsThe unit string in SI units.
si_scaling_factorThe scaling factor used to convert to SI units.
si_offsetThe offset used to convert to SI units.
dimensionsThen units base dimensions.
Examples
>>> from ansys.units import Unit, Quantity >>> fps = Unit("ft s^-1") >>> fps.name 'ft s^-1' >>> fps.dimensions {'LENGTH': 1.0, 'TIME': -1.0} >>> speed = Quantity(value=5, units=fps) >>> speed Quantity (5.0, "ft s^-1")
- compatible_units() set[str]#
Get all units with the same dimensions.
- Returns:
setA set of unit objects.
- convert(system: UnitSystem) Unit#
Convert a unit into the unit system.
- Parameters:
- system
UnitSystem Unit system to convert to.
- system
- Returns:
UnitUnit object converted into the unit system.
Examples
>>> ur = UnitRegistry() >>> speed_si = Unit(units= ur.m / ur.s) >>> bt = UnitSystem(system="BT") >>> speed_bt = speed_si.convert(bt)
- property dimensions: Dimensions#
Then units base dimensions.
- exception ansys.units.unit.ProhibitedTemperatureOperation#
Bases:
TypeErrorRaised when two absolute temperatures are added.
- exception ansys.units.unit.IncorrectUnits(unit1, unit2)#
Bases:
ValueErrorRaised when the specified units are incorrect.
- exception ansys.units.unit.InconsistentDimensions#
Bases:
ValueErrorRaised when units have inconsistent base dimensions.
- exception ansys.units.unit.UnconfiguredUnit(unit)#
Bases:
ValueErrorRaised when the specified unit is unconfigured.
- exception ansys.units.unit.UnknownTableItem(item)#
Bases:
ValueErrorRaised when a quantity table item is undefined.