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

Namespaces

 filesystem
 
 string
 

Classes

struct  BitTraits
 
struct  BitTraits< axom::uint16 >
 
struct  BitTraits< axom::uint32 >
 
struct  BitTraits< axom::uint64 >
 
struct  BitTraits< axom::uint8 >
 
class  LexiComparator
 Compares std::vector< T > in lexicographic order. More...
 
class  Timer
 A simple Timer class to measure execution time. More...
 

Functions

AXOM_HOST_DEVICE int trailingZeros (axom::uint64 word)
 Counts the number of trailing zeros in word. More...
 
AXOM_HOST_DEVICE int popCount (axom::uint64 word)
 Counts the number of set bits in word. More...
 
AXOM_HOST_DEVICE axom::int32 leadingZeros (axom::int32 word)
 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...
 
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 >
swapEndian (T val)
 Swaps the endianness 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...
 

Function Documentation

◆ trailingZeros()

AXOM_HOST_DEVICE int axom::utilities::trailingZeros ( axom::uint64  word)
inline

Counts the number of trailing zeros in word.

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

◆ popCount()

AXOM_HOST_DEVICE int axom::utilities::popCount ( axom::uint64  word)
inline

Counts the number of set bits in word.

Returns
number of bits in word that are set to 1

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

◆ leadingZeros()

AXOM_HOST_DEVICE axom::int32 axom::utilities::leadingZeros ( axom::int32  word)
inline

Counts the number of leading zeros in word.

Returns
The number of zeros to the left of the first set bit in , 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

◆ 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

References binomialCoefficient().

◆ 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.

◆ swapEndian()

template<typename T >
T axom::utilities::swapEndian ( val)

Swaps the endianness of the input value.

Parameters
[in]valThe input value.
Returns
The value with endianness swapped.
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 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().