Physical unit management class with runtime unit string parsing, unit checking, unit conversion, and output. More...
#include <Units.h>
Public Member Functions | |
MooseUnits (const std::string &unit_string) | |
MooseUnits (Real f) | |
MooseUnits (Real f, Real s, std::vector< std::pair< MooseUnits::BaseUnit, int >> b) | |
bool | conformsTo (const MooseUnits &) const |
checks if the units are dimensionally conforming (i.e. the describe the same physical quanitity) More... | |
Real | convert (Real from_value, const MooseUnits &from_unit) const |
Converts from_value in units of from_units to value this units. More... | |
void | parse (const std::string &unit_string) |
parse a unit string into a MooseUnits object More... | |
void | simplify () |
simplify into the canonical form that permits comparisons More... | |
MooseUnits | operator* (const Real f) const |
Unit prefactor scaling. More... | |
bool | operator== (const MooseUnits &rhs) const |
bool | operator== (const Real rhs) const |
operator Real () const | |
cast of units representing pure numbers More... | |
bool | isLength () const |
query the nature of the unit More... | |
bool | isTime () const |
bool | isMass () const |
bool | isCurrent () const |
bool | isTemperature () const |
MooseUnits | operator* (const MooseUnits &rhs) const |
Unit combination operators for unit pairs zero out the shift. More... | |
MooseUnits | operator/ (const MooseUnits &rhs) const |
Static Public Member Functions | |
static std::ostream & | latex (std::ostream &os) |
iostream manipulators More... | |
static std::ostream & | text (std::ostream &os) |
Static Public Attributes | |
static const std::map< std::string, Real > | _si_prefix |
data tables with SI prefixes and known units More... | |
static const std::vector< std::pair< std::string, MooseUnits > > | _unit_table |
Protected Member Functions | |
template<typename... Args> | |
void | parseError (const std::string &unit_string, std::string::const_iterator it, Args... args) |
helper function to generate a pretty mooseError More... | |
bool | isBase (const MooseUnits::BaseUnit) const |
check if the unit has a pure base More... | |
Static Protected Member Functions | |
static int | geti () |
iosteam manipulator helper to toggle latex / text output More... | |
Protected Attributes | |
Real | _factor |
conversion factor w.r.t. the base SI units More... | |
Real | _shift |
additive shift (for Celsius and Fahrenheit) More... | |
std::vector< std::pair< BaseUnit, int > > | _base |
base SI units and their exponents More... | |
Private Types | |
enum | BaseUnit { BaseUnit::METER, BaseUnit::KILOGRAM, BaseUnit::SECOND, BaseUnit::AMPERE, BaseUnit::KELVIN, BaseUnit::COUNT, BaseUnit::CANDELA } |
Friends | |
std::ostream & | operator<< (std::ostream &os, const MooseUnits &dt) |
MooseUnits | std::pow (const MooseUnits &, int) |
Physical unit management class with runtime unit string parsing, unit checking, unit conversion, and output.
|
strongprivate |
MooseUnits::MooseUnits | ( | const std::string & | unit_string | ) |
Definition at line 207 of file Units.C.
Referenced by parse().
|
inline |
Definition at line 47 of file Units.h.
|
inline |
Definition at line 48 of file Units.h.
bool MooseUnits::conformsTo | ( | const MooseUnits & | u | ) | const |
checks if the units are dimensionally conforming (i.e. the describe the same physical quanitity)
Definition at line 214 of file Units.C.
Referenced by convert(), and operator==().
Real MooseUnits::convert | ( | Real | from_value, |
const MooseUnits & | from_unit | ||
) | const |
Converts from_value
in units of from_units
to value this units.
Definition at line 226 of file Units.C.
|
staticprotected |
iosteam manipulator helper to toggle latex / text output
Definition at line 562 of file Units.C.
Referenced by latex(), operator<<(), and text().
|
protected |
check if the unit has a pure base
Definition at line 520 of file Units.C.
Referenced by isCurrent(), isLength(), isMass(), isTemperature(), and isTime().
|
inline |
Definition at line 74 of file Units.h.
|
inline |
query the nature of the unit
Definition at line 71 of file Units.h.
|
inline |
Definition at line 73 of file Units.h.
|
inline |
Definition at line 75 of file Units.h.
|
inline |
Definition at line 72 of file Units.h.
|
static |
iostream manipulators
Definition at line 549 of file Units.C.
|
explicit |
cast of units representing pure numbers
Definition at line 492 of file Units.C.
MooseUnits MooseUnits::operator* | ( | const Real | f | ) | const |
Unit prefactor scaling.
Definition at line 446 of file Units.C.
MooseUnits MooseUnits::operator* | ( | const MooseUnits & | rhs | ) | const |
Unit combination operators for unit pairs zero out the shift.
e.g. temperatures are interpreted as temperature differentials
Definition at line 455 of file Units.C.
MooseUnits MooseUnits::operator/ | ( | const MooseUnits & | rhs | ) | const |
Definition at line 466 of file Units.C.
bool MooseUnits::operator== | ( | const MooseUnits & | rhs | ) | const |
Definition at line 479 of file Units.C.
bool MooseUnits::operator== | ( | const Real | rhs | ) | const |
Definition at line 487 of file Units.C.
void MooseUnits::parse | ( | const std::string & | unit_string | ) |
parse a unit string into a MooseUnits object
Definition at line 234 of file Units.C.
Referenced by MooseUnits().
|
protected |
helper function to generate a pretty mooseError
Definition at line 126 of file Units.h.
Referenced by parse().
void MooseUnits::simplify | ( | ) |
simplify into the canonical form that permits comparisons
Definition at line 500 of file Units.C.
Referenced by operator*(), operator/(), and parse().
|
static |
Definition at line 555 of file Units.C.
|
friend |
Definition at line 569 of file Units.C.
|
friend |
base SI units and their exponents
Definition at line 118 of file Units.h.
Referenced by conformsTo(), isBase(), operator*(), operator/(), operator<<(), operator==(), std::pow(), and simplify().
|
protected |
conversion factor w.r.t. the base SI units
Definition at line 109 of file Units.h.
Referenced by convert(), operator*(), operator/(), operator<<(), operator==(), and std::pow().
|
protected |
additive shift (for Celsius and Fahrenheit)
Definition at line 112 of file Units.h.
Referenced by convert(), operator*(), operator/(), operator==(), and std::pow().
|
static |
data tables with SI prefixes and known units
Definition at line 66 of file Units.h.
Referenced by parse().
|
static |