Celeritas  0.5.0-86+4a8eea4
Public Member Functions | List of all members
celeritas::ArraySoftUnit< T > Class Template Reference

Test for being approximately a unit vector. More...

#include <ArraySoftUnit.hh>

Public Types

Type aliases
using value_type = T
 

Public Member Functions

CELER_FUNCTION ArraySoftUnit (value_type tol)
 Construct with explicit tolereance.
 
CELER_CONSTEXPR_FUNCTION ArraySoftUnit ()
 Construct with default tolereance.
 
template<::celeritas::size_type N>
CELER_CONSTEXPR_FUNCTION bool operator() (Array< T, N > const &arr) const
 Calculate whether the array is nearly a unit vector. More...
 

Detailed Description

template<class T = ::celeritas::real_type>
class celeritas::ArraySoftUnit< T >

Test for being approximately a unit vector.

Consider a unit vector v with a small perturbation along a unit vector e :

\[ \vec v + \epsilon \vec e \]

The magnitude squared is

\[ m^2 = (v + \epsilon e) \cdot (v + \epsilon e) = v \cdot v + 2 \epsilon v \cdot e + \epsilon^2 e \cdot e = 1 + 2 \epsilon v \cdot e + \epsilon^2 \]

Since

\[ |v \cdot e| <= |v||e| = 1 \]

by the triangle inequality, then the magnitude squared of a perturbed unit vector is bounded

\[ m^2 = 1 \pm 2 \epsilon + \epsilon^2 \]

Instead of calculating the square of the tolerance we loosely bound with another epsilon.

Member Function Documentation

◆ operator()()

template<class T >
template<::celeritas::size_type N>
CELER_CONSTEXPR_FUNCTION bool celeritas::ArraySoftUnit< T >::operator() ( Array< T, N > const &  arr) const

Calculate whether the array is nearly a unit vector.

The calculation below is equivalent to

return SoftEqual{tol, tol}(1, dot_product(arr, arr));
CELER_FUNCTION T dot_product(Array< T, N > const &x, Array< T, N > const &y)
Dot product of two vectors.
Definition: ArrayUtils.hh:98

.


The documentation for this class was generated from the following file: