# sfepy.mechanics.units module

Some utilities for work with units of physical quantities.

class sfepy.mechanics.units.Quantity(name, unit_set)

  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)

  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)

  static get_prefix(coef, bias=0.1, omit=None)

    Get the prefix and numerical multiplier corresponding to a numerical coefficient, omitting prefixes in omit tuple.

sfepy.mechanics.units.apply_unit_multipliers(values, unit_kinds, unit_multipliers)

  Apply time, length and mass unit multipliers to given values with units corresponding to unit kinds.

  Returns:
    new_values list

      The new values with applied unit multipliers

sfepy.mechanics.units.apply_units_to_pars(pars, pars_kinds, unit_multipliers)

  Apply units in unit_multipliers to pars according to their kinds.

  Parameters:
    pars dict

      The input parameters given as name : value items.

    pars_kinds dict

      The kinds of the parameters given as name : kind items, with kinds defined in `apply_unit_multipliers()`.

    unit_multipliers tuple

      The time, length and mass unit multipliers.

  Returns:
    new_pars dict

      The output parameters.

sfepy.mechanics.units.get_consistent_unit_set(length=None, time=None, mass=None, temperature=None)

  Given a set of basic units, return a consistent set of derived units for quantities listed in the units_of_quantities dictionary.