AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::utilities Namespace Reference

Namespaces

 annotations
 
 filesystem
 
 raii
 
 string
 

Classes

struct  BitTraits
 
struct  BitTraits< std::uint64_t >
 
struct  BitTraits< std::uint32_t >
 
struct  BitTraits< std::uint16_t >
 
struct  BitTraits< std::uint8_t >
 
class  Timer
 A simple Timer class to measure execution time. More...
 
class  LexiComparator
 Compares std::vector< T > in lexicographic order. More...
 

Functions

AXOM_HOST_DEVICE int countr_zero (std::uint64_t word) noexcept
 Counts the number of trailing zeros in word. More...
 
AXOM_HOST_DEVICE int popcount (std::uint64_t word) noexcept
 Counts the number of set bits in word. More...
 
AXOM_HOST_DEVICE std::int32_t countl_zero (std::int32_t word) noexcept
 Counts the number of leading zeros in word. More...
 
std::string getHostName ()
 Returns the name of the machine. More...
 
std::string getUserName ()
 Returns the name of the current user. More...
 
std::locale locale (const std::string &name="en_US.UTF-8")
 Returns a valid locale for the current system. More...
 
void processAbort ()
 Gracefully aborts the application. More...
 
template<typename T >
AXOM_HOST_DEVICEabs (const T &x)
 Returns the absolute value of x. More...
 
template<typename T >
AXOM_HOST_DEVICEfloor (const T &x)
 Returns the largest integer less than or equal to x. More...
 
template<typename T >
AXOM_HOST_DEVICEceil (const T &x)
 Returns the smallest integer greater than or equal to x. More...
 
template<typename T >
AXOM_HOST_DEVICE const T & max (const T &x, const T &y)
 Returns the max value of x and y. More...
 
template<typename T >
AXOM_HOST_DEVICE const T & min (const T &x, const T &y)
 Returns the min value of x and y. More...
 
template<typename T >
AXOM_HOST_DEVICE void swap (T &a, T &b)
 Swaps the values of a, b. More...
 
template<typename T >
AXOM_HOST_DEVICElerp (T A, T B, T t)
 returns the linear interpolation of A and B at t. i.e. (1-t)A+tB More...
 
template<typename T >
log2 (T val)
 Returns the base 2 logarithm of the input. More...
 
template<typename T >
AXOM_HOST_DEVICEclampVal (T val, T lower, T upper)
 Clamps an input value to a given range. More...
 
template<typename T >
AXOM_HOST_DEVICEclampUpper (T val, T upper)
 Clamps the upper range on an input value. More...
 
template<typename T >
AXOM_HOST_DEVICEclampLower (T val, T lower)
 Clamps the lower range on an input value. More...
 
int binomialCoefficient (int n, int k)
 Computes the binomial coefficient n choose k More...
 
template<typename T >
random_real (const T &a, const T &b)
 Returns a random real number within the specified interval. More...
 
template<typename T >
random_real (const T &a, const T &b, unsigned int seed)
 Returns a random real number within the specified interval given the bounds of the interval and a seed value for the underlying random number generator. More...
 
bool isLittleEndian ()
 Tests the endianness of the system. More...
 
template<typename T >
constexpr T byteswap (T val) noexcept
 Reverses the bytes of the input value. More...
 
template<typename RealType >
AXOM_HOST_DEVICE bool isNearlyEqual (RealType a, RealType b, RealType thresh=1.0e-8)
 Fuzzy comparison of two real valued quantities. More...
 
template<typename RealType >
AXOM_HOST_DEVICE bool isNearlyEqualRelative (RealType a, RealType b, RealType relThresh=1.0e-6, RealType absThresh=1.0e-8)
 Fuzzy comparison of two real valued quantities. More...
 
template<typename DataType , typename Predicate = std::less<DataType>>
AXOM_HOST_DEVICE void insertionSort (DataType *array, IndexType n, Predicate cmp={})
 Insertion sort of an array. More...
 

Function Documentation

◆ countr_zero()

AXOM_HOST_DEVICE int axom::utilities::countr_zero ( std::uint64_t  word)
inlinenoexcept

Counts the number of trailing zeros in word.

Returns
The number of zeros to the right of the first set bit in \word, starting with the least significant bit, or 64 if word == 0.

◆ popcount()

AXOM_HOST_DEVICE int axom::utilities::popcount ( std::uint64_t  word)
inlinenoexcept

Counts the number of set bits in word.

Returns
number of bits in word that are set to 1

References axom::slic::inherit::masks.

◆ countl_zero()

AXOM_HOST_DEVICE std::int32_t axom::utilities::countl_zero ( std::int32_t  word)
inlinenoexcept

Counts the number of leading zeros in word.

Returns
The number of zeros to the left of the first set bit in \word, starting with the least significant bit.

◆ getHostName()

std::string axom::utilities::getHostName ( )

Returns the name of the machine.

Returns
The name of the current machine, empty string on failure

◆ getUserName()

std::string axom::utilities::getUserName ( )

Returns the name of the current user.

Returns
The name of the current user, empty string on failure

◆ locale()

std::locale axom::utilities::locale ( const std::string &  name = "en_US.UTF-8")

Returns a valid locale for the current system.

Parameters
nameThe name of the desired locale

◆ processAbort()

void axom::utilities::processAbort ( )

Gracefully aborts the application.

◆ abs()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::abs ( const T &  x)
inline

Returns the absolute value of x.

Parameters
[in]xvalue whose absolute value is computed.
Returns
abs(x) the absolute value of x.

◆ floor()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::floor ( const T &  x)
inline

Returns the largest integer less than or equal to x.

Parameters
[in]xvalue whose floor value is computed.
Returns
floor(x) the largest integer less than or equal to x.

◆ ceil()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::ceil ( const T &  x)
inline

Returns the smallest integer greater than or equal to x.

Parameters
[in]xvalue whose ceil value is computed.
Returns
ceil(x) the smallest integer greater than or equal to x.

◆ max()

template<typename T >
AXOM_HOST_DEVICE const T& axom::utilities::max ( const T &  x,
const T &  y 
)
inline

Returns the max value of x and y.

Parameters
[in]xthe first value to check.
[in]ythe second value to check.
Returns
max(x, y) the max value of x and y.

◆ min()

template<typename T >
AXOM_HOST_DEVICE const T& axom::utilities::min ( const T &  x,
const T &  y 
)
inline

Returns the min value of x and y.

Parameters
[in]xthe first value to check.
[in]ythe second value to check.
Returns
min(x, y) the min value of x and y.

◆ swap()

template<typename T >
AXOM_HOST_DEVICE void axom::utilities::swap ( T &  a,
T &  b 
)
inline

Swaps the values of a, b.

Parameters
[in,out]a1st object to swap.
[in,out]b2nd object to swap.

◆ lerp()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::lerp ( A,
B,
t 
)
inline

returns the linear interpolation of A and B at t. i.e. (1-t)A+tB

◆ log2()

template<typename T >
T axom::utilities::log2 ( val)
inline

Returns the base 2 logarithm of the input.

Parameters
[in]valThe input value

◆ clampVal()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::clampVal ( val,
lower,
upper 
)
inline

Clamps an input value to a given range.

Parameters
[in]valThe value to clamp.
[in]lowerThe lower range.
[in]upperThe upper range.
Returns
The clamped value.
Precondition
lower <= upper
Postcondition
lower <= returned value <= upper.

◆ clampUpper()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::clampUpper ( val,
upper 
)
inline

Clamps the upper range on an input value.

Parameters
[in]valThe value to clamp
[in]upperThe upper range
Returns
upper if val > upper, else val
Postcondition
returned value is less than or equal to upper

◆ clampLower()

template<typename T >
AXOM_HOST_DEVICE T axom::utilities::clampLower ( val,
lower 
)
inline

Clamps the lower range on an input value.

Parameters
[in]valThe value to clamp
[in]lowerThe lower range
Returns
lower if val < lower, else val
Postcondition
returned value is greater than or equal to lower

◆ binomialCoefficient()

int axom::utilities::binomialCoefficient ( int  n,
int  k 
)

Computes the binomial coefficient n choose k

Returns
\( {n\choose k} = n! / (k! * (n-k)!)\) when \( n \ge k \ge 0 \), 0 otherwise.

◆ random_real() [1/2]

template<typename T >
T axom::utilities::random_real ( const T &  a,
const T &  b 
)
inline

Returns a random real number within the specified interval.

Parameters
[in]athe interval's lower bound
[in]bthe interval's upper bound
Returns
r the random real number within the specified interval.
Template Parameters
Ta built-in floating point type, e.g., double, float, long double.
Note
Consecutive calls to this method will generate a non-deterministic sequence of numbers.
Precondition
a < b
Postcondition
a <= r < b

References AXOM_STATIC_ASSERT.

◆ random_real() [2/2]

template<typename T >
T axom::utilities::random_real ( const T &  a,
const T &  b,
unsigned int  seed 
)
inline

Returns a random real number within the specified interval given the bounds of the interval and a seed value for the underlying random number generator.

Parameters
[in]athe interval's lower bound
[in]bthe interval's upper bound
[in]seeduser-supplied seed for the random number generator
Returns
r the random real number within the specified interval.
Template Parameters
Ta built-in floating type, e.g., double, float, long double.
Note
Consecutive calls to this method will generate a deterministic sequence of numbers.
Precondition
a < b
Postcondition
a <= r < b

References AXOM_STATIC_ASSERT.

◆ isLittleEndian()

bool axom::utilities::isLittleEndian ( )
inline

Tests the endianness of the system.

Returns
True, if the system is little endian, false otherwise.

◆ byteswap()

template<typename T >
constexpr T axom::utilities::byteswap ( val)
constexprnoexcept

Reverses the bytes of the input value.

Parameters
[in]valThe input value
Returns
The value with swapped bytes
Note
Assumes endianness is either little or big (not PDP).
Precondition
T is a native arithmetic type (i.e. integral or floating point).
sizeof(T) must be 1, 2, 4, or 8 bytes.

References AXOM_STATIC_ASSERT_MSG.

◆ isNearlyEqual()

template<typename RealType >
AXOM_HOST_DEVICE bool axom::utilities::isNearlyEqual ( RealType  a,
RealType  b,
RealType  thresh = 1.0e-8 
)
inline

Fuzzy comparison of two real valued quantities.

Parameters
[in]aThe first real valued quantities we are comparing.
[in]bThe second real valued quantities we are comparing.
[in]threshThe threshold of the fuzzy comparison. Default is 1.0e-8.
Returns
True if the absolute value of the difference is less than thresh and false otherwise.

References abs().

◆ isNearlyEqualRelative()

template<typename RealType >
AXOM_HOST_DEVICE bool axom::utilities::isNearlyEqualRelative ( RealType  a,
RealType  b,
RealType  relThresh = 1.0e-6,
RealType  absThresh = 1.0e-8 
)
inline

Fuzzy comparison of two real valued quantities.

Parameters
[in]aThe first real valued quantities we are comparing.
[in]bThe second real valued quantities we are comparing.
[in]relThreshThe relative threshold of the fuzzy comparison. Default is 1.0e-6.
[in]absThreshThe absolute threshold of the fuzzy comparison. Default is 1.0e-8.
Returns
True if the absolute value of the difference is less than the sum of absThresh and the relative difference (relThresh times the absolute max of a and b).

References abs(), and max().

◆ insertionSort()

template<typename DataType , typename Predicate = std::less<DataType>>
AXOM_HOST_DEVICE void axom::utilities::insertionSort ( DataType *  array,
IndexType  n,
Predicate  cmp = {} 
)
inline

Insertion sort of an array.

Parameters
[in]arrayThe array to sort.
[in]nThe number of entries in the array.
[in]cmpThe comparator to use for comparing elements; "less than" by default.