Celeritas
0.5.0-56+6b053cd
|
A numerical value tagged with a unit. More...
#include <Quantity.hh>
Public Types | |
Type aliases | |
using | value_type = ValueT |
using | unit_type = UnitT |
Public Member Functions | |
constexpr | Quantity ()=default |
Construct with default (zero) | |
CELER_CONSTEXPR_FUNCTION | Quantity (value_type value) noexcept |
Construct with value in celeritas native units. | |
template<detail::QConstant QC> | |
CELER_CONSTEXPR_FUNCTION | Quantity (detail::UnitlessQuantity< QC >) noexcept |
Construct implicitly from a unitless quantity. | |
CELER_CONSTEXPR_FUNCTION value_type const * | data () const |
Access the underlying data for more efficient loading from memory. | |
CELER_CONSTEXPR_FUNCTION value_type & | value () &noexcept |
CELER_CONSTEXPR_FUNCTION value_type const & | value () const &noexcept |
A numerical value tagged with a unit.
UnitT | unit tag class |
ValueT | value type |
A quantity is a value expressed in terms of the given unit. Storing values in a different unit system can help with some calculations (e.g. operating in natural unit systems) by avoiding numerical multiplications and divisions by large constants. It can also make debugging easier (numeric values are obvious).
Example usage by physics class, where charge is in units of q_e+, and mass and momentum are expressed in atomic natural units (where m_e = 1 and c = 1).
A relativistic equation that operates on these quantities can do so without unnecessary floating point operations involving the speed of light:
The resulting quantity can be converted to the native Celeritas unit system with native_value_from
, which multiplies in the constant value of ElMomentumUnit:
When using a Quantity from another part of the code, e.g. an imported unit system, use the quantity
free function rather than .value() in order to guarantee consistency of units between source and destination.
An example unit class would be:
The label is used solely for outputting to JSON.
value_as
(to operate within the Quantity's unit system) or native_value_from
(to operate in the Celeritas native unit system), use the resulting numeric values in your mathematical expressions, then return a new Quantity class with the resulting value and correct type.