Celeritas 0.6.0-dev.116+3fbab5e0
Loading...
Searching...
No Matches
Classes | Typedefs | 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...
 

Typedefs

template<class UnitT >
using celeritas::RealQuantity = Quantity< UnitT, real_type >
 Type alias for a quantity that uses compile-time precision.
 

Functions

CELER_CONSTEXPR_FUNCTION auto celeritas::zero_quantity () noexcept
 Get a typeless zero quantity.
 
CELER_CONSTEXPR_FUNCTION auto celeritas::max_quantity () noexcept
 Get a typeless 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.
 
template<class Q , class T >
CELER_CONSTEXPR_FUNCTION Q celeritas::native_value_to (T value) noexcept
 Create a quantity from a value in the Celeritas unit system.
 
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.
 
template<class T >
char constceleritas::accessor_unit_label ()
 Get the label for a unit returned from a class accessor.
 

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 *
centimeter/second);

◆ native_value_to()

template<class Q , class T >
CELER_CONSTEXPR_FUNCTION Q celeritas::native_value_to ( T  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).

An extra cast may be needed when mixing float, double, and celeritas::Constant.

◆ 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);

◆ zero_quantity()

CELER_CONSTEXPR_FUNCTION auto celeritas::zero_quantity ( )
noexcept

Get a typeless zero quantity.

The zero quantity can be compared against any Quantity.