Quantity#
- class ansys.units.quantity.Quantity(value: ValT, units: Unit | Literal['kg', 'g', 'lb', 'lbm', 'slug', 'm', 'cm', 'ft', 'inch', 'in', 's', 'A', 'mol', 'slugmol', 'cd', 'sr', 'radian', 'degree', 'K', 'C', 'F', 'R', 'delta_K', 'delta_C', 'delta_F', 'delta_R', 'N', 'Pa', 'W', 'J', 'V', 'farad', 'H', 'S', 'Wb', 'T', 'dyne', 'erg', 'h', 'pdl', 'psi', 'lbf', 'psf', 'ohm', 'Hz', 'l', 'gal', 'BTU', 'cal', 'coulomb'] | str | None = None)#
- class ansys.units.quantity.Quantity(value: ValT, *, dimensions: Dimensions)
- class ansys.units.quantity.Quantity(value: ValT, *, quantity_table: Mapping[Literal['Mass', 'Length', 'Time', 'Temperature', 'Current', 'SubstanceAmount', 'Light', 'Angle', 'SolidAngle', 'Acceleration', 'AngularAcceleration', 'AngularVelocity', 'Area', 'Compressibility', 'Concentration', 'DecayConstant', 'Density', 'DynamicViscosity', 'ElectricCharge', 'ElectricChargeDensity', 'ElectricCurrentDensity', 'ElectricCurrentSource', 'ElectricFluxDensity', 'Enthalpy', 'Force', 'ForceDensity', 'Frequency', 'HeatFlux', 'HeatGeneration', 'HeatTransferCoefficient', 'Impulse', 'MagneticFieldIntensity', 'MassFlowRate', 'MassFlux', 'MolarConcentration', 'MolarEnergy', 'MolarEnthalpy', 'MolarEntropy', 'MolarMass', 'MolarVolume', 'Moment', 'MomentOfInertiaOfArea', 'MomentOfInertiaOfMass', 'Momentum', 'Pressure', 'ShearStrain', 'ShearStrainRate', 'SpecificConcentration', 'SpecificEnergy', 'SpecificEnthalpy', 'SpecificEntropy', 'SpecificFlameSurfaceDensity', 'SpecificHeatCapacity', 'SpecificVolume', 'Stiffness', 'Strain', 'SurfaceChargeDensity', 'SurfaceForceDensity', 'SurfacePowerDensity', 'SurfaceTension', 'TemperatureGradient', 'ThermalCapacitance', 'ThermalConductance', 'ThermalConductivity', 'ThermalContactResistance', 'ThermalExpansionCoefficient', 'Torque', 'Velocity', 'Volume', 'VolumetricFlowRate'], float])
- class ansys.units.quantity.Quantity(*, copy_from: Quantity[ValT])
- class ansys.units.quantity.Quantity(value: ValT, *, copy_from: Quantity)
Bases:
Generic[ValT]A class representing a physical quantity’s value and associated units.
A Quantity object can be instantiated from a NumPy array or list only if the
NumPypackage is installed.The value argument is not required when using
copy_from. A value can be given to override the value from the copy.Implicit conversion from Quantity to float is only allowed if the operand is of quantity type angle or dimensionless.
- Parameters:
- value
int,float,list,np.array Real value of the quantity.
- units
str,Unit,optional Initializes the quantity’s units using a string or
Unitinstance.- quantity_table
dict[str,int],optional Initializes the quantity’s units using the quantity table.
- dimensions
Dimensions,optional Initializes the quantity’s units in SI using a
Dimensionsinstance.- copy_from
Quantity,optional An existing
Quantityinstance.
- value
- Attributes:
valueValue in contained units.
unitsThe quantity’s units.
dimensionsThe quantity’s dimensions.
is_dimensionlessTrue if the quantity is dimensionless.
- compatible_units() set[str]#
Get all units with the same dimensions.
- Returns:
setA set of unit objects.
- convert(system: UnitSystem) Quantity#
Convert a quantity into the unit system.
- Parameters:
- system
UnitSystem Unit system to convert to.
- system
- Returns:
QuantityQuantity object converted into the unit system.
Examples
>>> ur = UnitRegistry() >>> speed_si = Quantity(value=5, units= ur.m / ur.s) >>> bt = UnitSystem(system="BT") >>> speed_bt = speed_si.convert(bt)
- property dimensions: Dimensions#
The quantity’s dimensions.
- classmethod preferred_units(units: Sequence[Unit | Literal['kg', 'g', 'lb', 'lbm', 'slug', 'm', 'cm', 'ft', 'inch', 'in', 's', 'A', 'mol', 'slugmol', 'cd', 'sr', 'radian', 'degree', 'K', 'C', 'F', 'R', 'delta_K', 'delta_C', 'delta_F', 'delta_R', 'N', 'Pa', 'W', 'J', 'V', 'farad', 'H', 'S', 'Wb', 'T', 'dyne', 'erg', 'h', 'pdl', 'psi', 'lbf', 'psf', 'ohm', 'Hz', 'l', 'gal', 'BTU', 'cal', 'coulomb']], remove: bool = False) None#
Add or remove preferred units.
Quantities are automatically converted to preferred units when the quantity is initialized. Conversion is always carried out if the base units are consistent with the preferred units.
Each preferred unit must have unique dimensions. To override units with the same dimensions, the original must first be removed.
- to(to_units: Unit | str) Quantity#
Perform quantity conversions.
- Parameters:
- to_units
Unitorstr Desired unit to convert to.
- to_units
- Returns:
QuantityQuantity instance in the desired units.
Examples
>>> speed_si = Quantity(value=5, units="m s^-1") >>> speed_bt = speed_si.to("ft s^-1")
- validate_matching_dimensions(other)#
Validates dimensions of quantities.
- property value: ValT#
Value in contained units.
- ansys.units.quantity.get_si_value(quantity: Quantity[ValT]) ValT#
Returns a quantity’s value in SI units.
- exception ansys.units.quantity.ExcessiveParameters#
Bases:
ValueErrorRaised when excessive parameters are provided.
- exception ansys.units.quantity.IncompatibleDimensions(from_unit, to_unit)#
Bases:
ValueErrorRaised when dimensions are incompatible.
- exception ansys.units.quantity.IncompatibleQuantities(q1, q2)#
Bases:
ValueErrorRaised when quantities are incompatible.
- exception ansys.units.quantity.IncompatibleValue(value)#
Bases:
ValueErrorRaised when an incompatible value is provided.
- exception ansys.units.quantity.InsufficientArguments#
Bases:
ValueErrorRaised when insufficient arguments are provided.
- exception ansys.units.quantity.InvalidFloatUsage#
Bases:
FloatingPointErrorRaised when float is unsupported for given type of quantity.
- exception ansys.units.quantity.NumPyRequired#
Bases:
ModuleNotFoundErrorRaised when NumPy is unavailable.
- exception ansys.units.quantity.RequiresUniqueDimensions(unit, other_unit)#
Bases:
ValueErrorRaised when two units with the same dimensions are added to the chosen units.