Provides a class for storing units. More...
#include <Units.h>
Public Types | |
| using | SI_type = std::array< int8_t, 9 > |
| using | unit_type = std::array< char, 31 > |
Public Member Functions | |
| constexpr bool | compatible (const Units &unit) noexcept |
| Check if two units are compatible. | |
| constexpr double | convert (const Units &unit) const |
| Convert the unit to a new type. | |
| constexpr UnitType | getType () const noexcept |
| Get the unit type. | |
| constexpr bool | isNull () const |
| Check if unit is null. | |
| constexpr bool | operator!= (const Units &rhs) const noexcept |
| Operator !=. | |
| constexpr void | operator*= (const Units &rhs) noexcept |
| Operator *=. | |
| constexpr void | operator*= (double x) noexcept |
| Operator *=. | |
| constexpr void | operator/= (const Units &rhs) noexcept |
| Operator /=. | |
| constexpr bool | operator== (const Units &rhs) const noexcept |
| Operator ==. | |
| constexpr Units | pow (int p) const noexcept |
| Raise the unit to the given power. | |
| std::string | printFull () const |
| Get the full unit and conversion string. | |
| std::string | printSI () const |
| Get a string representation of the units in SI units (with scaling factor) | |
| std::string | printUnit () const |
| Get a string representation of the units in SI units (with scaling factor) | |
| std::string | str () const |
| Get a string representation of the units. | |
| constexpr | Units ()=default |
| Empty constructor. | |
| constexpr | Units (const char *unit) |
| Construct the units from a const char array. | |
| constexpr | Units (const SI_type &unit, double scale=1.0) |
| Construct the units. | |
| constexpr | Units (const std::string_view &unit) |
| Construct the units from a const char array. | |
| constexpr | Units (const std::string_view &unit, double value) |
| Construct the units from a const char array. | |
| constexpr | Units (const UnitType &unit, double scale=1.0) |
| Construct the units. | |
Static Public Member Functions | |
| static constexpr int | atoi (std::string_view, bool=true) |
| static constexpr double | convert (UnitPrefix x) noexcept |
| Convert the prefix to a double. | |
| static std::vector< std::string > | getAllPrefixes () |
| Get all supported unit prefixes. | |
| static std::vector< std::string > | getAllUnits () |
| Get all supported units. | |
| static constexpr std::string_view | getPrefixStr (UnitPrefix) noexcept |
| Get a string representation for the prefix. | |
| static constexpr UnitPrefix | getUnitPrefix (const std::string_view &str) noexcept |
| Get the prefix from a string. | |
| static constexpr double | strtod (std::string_view) |
Protected Member Functions | |
| std::string | printSIBase () const |
Static Protected Member Functions | |
| static constexpr SI_type | combine (const SI_type &a, const SI_type &b) |
| static constexpr size_t | findPar (const std::string_view &, size_t) |
| static constexpr std::pair< size_t, char > | findToken (const std::string_view &, size_t) |
| static constexpr SI_type | getSI (UnitType) |
| static constexpr Units | read (std::string_view str) |
| static constexpr Units | read2 (std::string_view str) |
| static constexpr Units | readUnit (const std::string_view &str, bool throwErr=true) |
Protected Attributes | |
| double | d_scale = { 0.0 } |
| SI_type | d_SI = { 0 } |
| unit_type | d_unit = { 0 } |
Friends | |
| constexpr Units | pow (Units base, int exponent) |
Provides a class for storing units.
This class provides routines for creating and storing units.
A user can specify a unit and get the scaling factor to a compatible unit.
All user-provided units are converted to SI base units with a scaling factor.
Currently we support all major SI units and some additional units with prefixes.
Note: currently the majority of the routines are constexpr so that the creation
of a unit can be done at compile-time.
Note: To prevent ambiguity some unit abbreviations are not supported:
min (minute) - ambiguous with min (milli-inch)
Note: To prevent ambiguity some units are not supported:
year: could be 365 days, 365.25 days, 365.2425 days
horsepower:
Mechanical horsepower - 745.6998715822702 W
Metric horsepower - 735.49875 W
Electric horsepower - 746 W
Boiler horsepower - 9,812.5 W
Hydraulic horsepower - 745.69987 W
Air horsepower - 745.69987 W
| using AMP::Units::SI_type = std::array<int8_t, 9> |
| using AMP::Units::unit_type = std::array<char, 31> |
|
constexprdefault |
Empty constructor.
|
constexpr |
Construct the units from a const char array.
This is the default constructor for a string view. It can create a unit from a string of the format "W/(m^2)"
| unit | Input string |
|
constexpr |
Construct the units from a const char array.
This is the default constructor for a string view. It can create a unit from a string of the format "W/(m^2)"
| unit | Input string |
|
constexpr |
Construct the units from a const char array.
This is the default constructor for a string view. It can create a unit from a string of the format "W/(m^2)"
| unit | Input string |
| value | Value of constant scalar |
|
explicitconstexpr |
Construct the units.
Construct units directly by specifying the SI units and scale
| unit | Input string |
| scale | Value of constant scalar |
|
explicitconstexpr |
Construct the units.
Construct units directly by specifying the SI units and scale
| unit | Input string |
| scale | Value of constant scalar |
|
staticconstexpr |
|
staticconstexprprotected |
|
constexprnoexcept |
Check if two units are compatible.
Check if two units are compatible with each other. I.e. if convert will succeed.
| unit | Unit to compare |
|
constexpr |
Convert the unit to a new type.
This function returns the scaling factor to convert between two different units. For example, converting "J" to "ergs" returns 1e7. If the two units are not compatible an exception will be thrown.
| unit | Desired unit |
Referenced by AMP::Materials::Property::set_default().
|
staticconstexprnoexcept |
Convert the prefix to a double.
This returns the value of the given prefix
| x | Enum for the prefix |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
inlinestatic |
Get all supported unit prefixes.
|
inlinestatic |
Get all supported units.
|
staticconstexprnoexcept |
Get a string representation for the prefix.
|
constexprnoexcept |
Get the unit type.
This returns the type of unit (if it is reducible). e.g. time, length, energy, power, etc.
|
staticconstexprnoexcept |
Get the prefix from a string.
This returns an enum representing the given input string
| str | Input string |
|
inlineconstexpr |
Check if unit is null.
Definition at line 208 of file Units.h.
References d_scale.
Referenced by AMP::Materials::Property::set_default().
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
constexprnoexcept |
Operator ==.
Referenced by operator!=().
|
constexprnoexcept |
Raise the unit to the given power.
| std::string AMP::Units::printFull | ( | ) | const |
Get the full unit and conversion string.
| std::string AMP::Units::printSI | ( | ) | const |
Get a string representation of the units in SI units (with scaling factor)
|
protected |
| std::string AMP::Units::printUnit | ( | ) | const |
Get a string representation of the units in SI units (with scaling factor)
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
| std::string AMP::Units::str | ( | ) | const |
Get a string representation of the units.
Referenced by AMP::operator<<().
|
staticconstexpr |
|
protected |
Definition at line 245 of file Units.h.
Referenced by isNull(), and operator*=().
|
Advanced Multi-Physics (AMP) Oak Ridge National Laboratory Idaho National Laboratory Los Alamos National Laboratory |
This page automatically produced from the source code by Last updated: Tue Mar 10 2026 13:06:42. Comments on this page |