sfepy.mechanics.units module¶
Some utilities for work with units of physical quantities.
-
class
sfepy.mechanics.units.
Quantity
(name, unit_set)[source]¶ A physical quantity in a given set of basic units.
Examples
Construct the stress quantity:
>>> from sfepy.mechanics.units import Unit, Quantity >>> units = ['m', 's', 'kg', 'C'] >>> unit_set = [Unit(key) for key in units] >>> q1 = Quantity('stress', unit_set) >>> q1() '1.0 Pa'
Show its unit using various prefixes:
>>> q1('m') '1000.0 mPa' >>> q1('') '1.0 Pa' >>> q1('k') '0.001 kPa' >>> q1('M') '1e-06 MPa'
Construct the stress quantity in another unit set:
>>> units = ['mm', 's', 'kg', 'C'] >>> unit_set = [Unit(key) for key in units] >>> q2 = Quantity('stress', unit_set) >>> q2() '1.0 kPa'
Show its unit using various prefixes:
>>> q2('m') '1000000.0 mPa' >>> q2('') '1000.0 Pa' >>> q2('k') '1.0 kPa' >>> q2('M') '0.001 MPa'
-
class
sfepy.mechanics.units.
Unit
(name)[source]¶ A unit of a physical quantity. The prefix and coefficient of the unit are determined from to its name.
Examples
Construct some units:
>>> from sfepy.mechanics.units import Unit >>> unit = Unit('mm') >>> print unit Unit:mm coef: 0.001 name: mm prefix: m prefix_length: 1 unit: m >>> unit = Unit('kg') >>> print unit Unit:kg coef: 1000.0 name: kg prefix: k prefix_length: 1 unit: g
Get prefixes for a coefficient:
>>> Unit.get_prefix(100.0) ('d', 10.0) >>> Unit.get_prefix(100.0, omit=('d',)) ('k', 0.10000000000000001)