2.1. Unit Converters

The unit converts are embeded in objects with units. Each instance of the class stores a base unit, and the ratio between that unit and other possible units. The base UnitConverter class is referenced below. Specific UnitConverter classes exist that inherit from the base class. This includes for most common units used in structural analysis, for example, length, force, and stress.

class UnitConverter[source]

Bases: ABC

The base unit converter class, contains interfaces all unit converter classes use.

convert(inputUnit: str, outputUnit: str, value: float)[source]

Converts the value of one unit to another unit.

Parameters
  • inputUnit (str) – A string representing the input unit. Must be one of the units in the the unit converter ‘unitDict’ attribute.

  • outputUnit (str) – A string representing the output unit. Must be one of the units in the the unit converter ‘unitDict’ attribute.

  • value (float) – The current value to be converted.

Returns

The “value” converted from the input unit to the output unit.

Return type

float

getConversionFactor(inputUnit: str, outputUnit: str) float[source]

Finds the conversion factor between two units.

Parameters
  • inputUnit (str) – A string representing the input unit. Must be one of the units in the the unit converter ‘unitDict’ attribute.

  • outputUnit (str) – A string representing the output unit. Must be one of the units in the the unit converter ‘unitDict’ attribute.

Returns

cfactor – The conversion factor between units.

Return type

float

getFactorUnit(unit: str)[source]

Returns the conversion factor for a given unit.

Parameters

outputUnit (str) – The input unit type, must be unit from the unit dictionary.

Returns

The output conversion factor.

Return type

float

unitDict = {}
class ConverterLength[source]

Bases: UnitConverter

A converter for length units. Supports: ‘m’, ‘mm’, ‘in’, ‘ft’

type = 'length'
unitDict = {'ft': 0.30479999999999996, 'in': 0.0254, 'm': 1, 'mm': 0.001}
class ConverterForce[source]

Bases: UnitConverter

A converter for length units. Supports: ‘N’, ‘kN’, ‘lbf’.

type = 'force'
unitDict = {'N': 1, 'kN': 1000, 'lbf': 4.44822162}
class ConverterStress[source]

Bases: UnitConverter

type = 'stress'
unitDict = {'GPa': 1000000000.0, 'MPa': 1000000.0, 'Pa': 1, 'kPa': 1000, 'ksi': 6894757.2932, 'psf': 47.880258888889, 'psi': 6894.7572932}
class ConverterDensity[source]

Bases: UnitConverter

type = 'mass'
unitDict = {'N/m3': 9.8066500286389, 'kN/m3': 0.0098066500286389, 'kg/m3': 1, 'lbm/ft3': 0.062427960576145}