Celeritas  0.5.0-86+4a8eea4
Classes | Functions
Quantity.hh File Reference
#include <type_traits>
#include "corecel/Macros.hh"
#include "corecel/Types.hh"
#include "detail/QuantityImpl.hh"
This graph shows which files directly or indirectly include this file:

Classes

class  celeritas::Quantity< UnitT, ValueT >
 A numerical value tagged with a unit. More...
 

Macros

#define CELER_DEFINE_QACCESS(FUNC, QUAL)
 

Functions

CELER_CONSTEXPR_FUNCTION auto celeritas::zero_quantity () noexcept
 Get a zero quantity (analogous to nullptr).
 
CELER_CONSTEXPR_FUNCTION auto celeritas::max_quantity () noexcept
 Get a quantitity greater than any other numeric quantity.
 
CELER_CONSTEXPR_FUNCTION auto celeritas::neg_max_quantity () noexcept
 Get a quantitity less than any other numeric quantity.
 
template<class U , class V >
CELER_CONSTEXPR_FUNCTION void celeritas::swap (Quantity< U, V > &a, Quantity< U, V > &b) noexcept
 Swap two Quantities.
 
template<class UnitT , class ValueT >
CELER_CONSTEXPR_FUNCTION auto celeritas::native_value_from (Quantity< UnitT, ValueT > quant) noexcept
 Convert the given quantity into the native Celeritas unit system. More...
 
template<class Q >
CELER_CONSTEXPR_FUNCTIONceleritas::native_value_to (typename Q::value_type value) noexcept
 Create a quantity from a value in the Celeritas unit system. More...
 
template<class Q , class SrcUnitT , class ValueT >
CELER_CONSTEXPR_FUNCTION auto celeritas::value_as (Quantity< SrcUnitT, ValueT > quant) noexcept -> ValueT
 Use the value of a Quantity. More...
 
template<class T >
char const * celeritas::accessor_unit_label ()
 Get the label for a unit returned from a class accessor. More...
 

Macro Definition Documentation

◆ CELER_DEFINE_QACCESS

#define CELER_DEFINE_QACCESS (   FUNC,
  QUAL 
)
Value:
CELER_CONSTEXPR_FUNCTION value_type QUAL FUNC() QUAL noexcept \
{ \
return value_; \
}
#define CELER_CONSTEXPR_FUNCTION
Decorate a function that works on both host and device, with and without NVCC, can be evaluated at co...
Definition: Macros.hh:81

Access the underlying numeric value, discarding units

Function Documentation

◆ accessor_unit_label()

template<class T >
char const* celeritas::accessor_unit_label ( )
inline

Get the label for a unit returned from a class accessor.

Example:

cout << accessor_unit_label<decltype(&ParticleView::mass)>() << endl;

◆ native_value_from()

template<class UnitT , class ValueT >
CELER_CONSTEXPR_FUNCTION auto celeritas::native_value_from ( Quantity< UnitT, ValueT >  quant)
noexcept

Convert the given quantity into the native Celeritas unit system.

assert(native_value_from(Quantity<CLight>{1}) == 2.998e10 *
double native_value_from(UnitSystem sys, ImportUnits q)
Get the native value from a quantity of this type.
Definition: ImportUnits.cc:96
constexpr real_type centimeter
Length.
Definition: Units.hh:68
constexpr real_type second
Time.
Definition: Units.hh:70

◆ native_value_to()

template<class Q >
CELER_CONSTEXPR_FUNCTION Q celeritas::native_value_to ( typename Q::value_type  value)
noexcept

Create a quantity from a value in the Celeritas unit system.

This function can be used for defining a constant for use in another unit system (typically a "natural" unit system for use in physics kernels).

constexpr LightSpeed c = native_value_to<LightSpeed>(constants::c_light);
assert(c.value() == 1);

◆ value_as()

template<class Q , class SrcUnitT , class ValueT >
CELER_CONSTEXPR_FUNCTION auto celeritas::value_as ( Quantity< SrcUnitT, ValueT >  quant) -> ValueT
noexcept

Use the value of a Quantity.

The redundant unit type in the function signature is to make coupling safer across different parts of the code and to make the user code more readable.

assert(value_as<LightSpeed>(LightSpeed{1}) == 1);