MooseUnits

MooseUnits is a physical units parsing and conversion helper class. A unit object can be constructed form a string (e.g. N*m, eV/at, kg*(m/s)^2, 1/s, m^-3). The unit parser supports the *,/, and ^ operators as well as parenthesis (, ). The argument of the ^ operator is expected to be a positive or negative integer.

Upon parsing all units are resolved to a combination of the seven base SI units (m, g, s, A, K, mol, cd) with their respective exponents and a prefactor. A canonical form is generated that permits unit comparisons to determine conformity (i.e. whether two units can be converted between).

MooseUnits supports prefixing all units with a metric prefix ranging from Y (yotta) to y (yocto).

Supported derived units

The following units are currently supported

SymbolBase unitsNameDescription
OhmOhmresistance, impedance, reactance
atmStandard atmospherepressure
eVelectron Voltenergy
ergErgenergy
degCCelsiustemperature - As long as this unit stands alone the additive shift in the scale is taken into account. In all other cases this unit behaves like Kelvin
degFFahrenheittemperature - As long as this unit stands alone the additive shift in the scale is taken into account. In all other cases this unit behaves like Rankine
degRRankinetemperature
AngAngstromlength
mmeterlength
ggrammass
ssecondtime
AAmpereelectric current
KKelvintemperature
molmoleamount of substance
cdcandelaluminous intensity
NNewtonforce, weight
PaPascalpressure, stress
JJouleenergy, work, heat
calCalorieenergy, work, heat
WWattpower, radiant flux
CCoulombelectric charge
VVoltvoltage (electrical potential), emf
FFaradcapacitance
SSiemenselectrical conductance
WbWebermagnetic flux
TTeslamagnetic flux density
HHenryinductance
BabaryePressure
dyndyneforce, weight
ftFootlength
inInchlength
lbpoundmass
lbfpound-forceforce
psipound-force per square inchpressure, stress
BTUISO 31-4 British thermal unitheat
barBarpressure, stress
hhourtime
daydaytime (d would create an ambiguity between centi-day and candela)
yearannumtime (Julian calendar year, a would create an ambiguity between Peta-annum and Pascal)
llitervolume
uunified atomic mass unitmass
atatomsingle count of substance

Operators

Unit objects support the * and / operators to multiply and divide units respectively. An overload of std::pow is provided to exponentiate units.

The == equal operator is implemented for comparison of two units and a unit and a real number. It returns true if the two units are exactly identical including the prefactor. A comparison that omits the prefactor is provided by the conformsTo method.

A unit is considered equal to a real number if all its base unit exponents are zero and the prefactor matches the real number.

Dimension check

In addition to the conformsTo check a few bool member functions are provided to check if the unit represents a given physical dimension.

  • isLength()

  • isTime()

  • isMass()

  • isCurrent()

  • isTemperature()

Output

MooseUnits objects can be output to streams using the << operator. The output consists of the prefactor and the SI base units with their respective exponents. Two stream manipulators are provided to toggle between plain text and LaTeX formatted output of the units.

See also

Unit conversion using MooseUnits is available in input files through the ${units ...} Brace Expression.