AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::primal::Vector< T, NDIMS > Class Template Reference

Represents a vector, \( v \in \mathcal{R}^d \). It provides access methods for setting and querying the vector components as well as vector math operators, e.g., adding, subtracting, dot_product and cross_product. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.5.0/src/axom/primal/geometry/Vector.hpp>

Inheritance diagram for axom::primal::Vector< T, NDIMS >:

Public Types

typedef Point< T, NDIMS > PointType
 

Public Member Functions

AXOM_HOST_DEVICE Vector (T val=T(), int sz=NDIMS)
 Fill vector with single value. Acts as default constructor Sets first sz components of the vector to val (default 0). More...
 
AXOM_HOST_DEVICE Vector (const NumericArray< T, NDIMS > &arr)
 Constructor from a numeric array. More...
 
AXOM_HOST_DEVICE Vector (const T *vals, int sz=NDIMS)
 Creates a vector from the first sz values of the input array. More...
 
AXOM_HOST_DEVICE Vector (const Point< T, NDIMS > &pt)
 Constructor to create vector from a Point. More...
 
AXOM_HOST_DEVICE Vector (const Vector< T, NDIMS > &other)
 Copy constructor. More...
 
AXOM_HOST_DEVICE Vectoroperator= (const Vector< T, NDIMS > &other)
 Copy assignment operator. More...
 
AXOM_HOST_DEVICE Vector (const Point< T, NDIMS > &A, const Point< T, NDIMS > &B)
 Constructs a vector from point A to point B. More...
 
 Vector (std::initializer_list< T > values)
 Creates a vector from an initializer list. More...
 
AXOM_HOST_DEVICE ~Vector ()
 Destructor. More...
 
AXOM_HOST_DEVICE int dimension () const
 Returns the dimension of this vector instance. More...
 
AXOM_HOST_DEVICE const T & operator[] (int i) const
 Access operator for individual components. More...
 
AXOM_HOST_DEVICE T & operator[] (int i)
 
AXOM_HOST_DEVICE const NumericArray< T, NDIMS > & array () const
 Returns a reference to the underlying NumericArray. More...
 
AXOM_HOST_DEVICE NumericArray< T, NDIMS > & array ()
 
AXOM_HOST_DEVICE const T * data () const
 Returns a pointer to the underlying data. More...
 
AXOM_HOST_DEVICE T * data ()
 
Vector< T, NDIMS > & operator+= (const Vector< T, NDIMS > &v)
 Adds the vector to the Vector instance \(\vec{u} +=\vec{v}\). More...
 
Vector< T, NDIMS > & operator-= (const Vector< T, NDIMS > &v)
 Adds the vector ot the Vector instance \(\vec{u} -=\vec{v}\). More...
 
Vector< T, NDIMS > & operator*= (T scalar)
 Scalar multiplication on the Vector instance. More...
 
AXOM_HOST_DEVICE Vector< T, NDIMS > & operator/= (T scalar)
 Scalar division on the Vector instance. More...
 
AXOM_HOST_DEVICEdot (const Vector< T, NDIMS > &v) const
 Dot product of the Vector instance with another vector v. More...
 
AXOM_HOST_DEVICE double squared_norm () const
 Computes the squared \( l^2\) norm of this vector instance. More...
 
AXOM_HOST_DEVICE double norm () const
 Computes the \( l^2 \) norm of this vector instance. More...
 
void negate ()
 Component-wise negation of the vector. More...
 
AXOM_HOST_DEVICE Vector unitVector () const
 Creates a new unit vector in the direction of the vector instance. More...
 
std::ostream & print (std::ostream &os) const
 Simple formatted print of a Vector instance. More...
 

Static Public Member Functions

static AXOM_HOST_DEVICEdot_product (const Vector< T, NDIMS > &u, const Vector< T, NDIMS > &v)
 Computes the dot product of two vectors u, v. More...
 
static AXOM_HOST_DEVICE Vector< T, 3 > cross_product (const Vector< T, 2 > &u, const Vector< T, 2 > &v)
 Computes the cross product of vector u and v, treating them as 3D. More...
 
static AXOM_HOST_DEVICE Vector< T, 3 > cross_product (const Vector< T, 3 > &u, const Vector< T, 3 > &v)
 Computes the 3-D cross product of vector u and v. More...
 
static Vector make_vector (const T &x, const T &y, const T &z=0.0)
 Utility function to constructs a Vector with the given coordinates. More...
 

Friends

bool operator== (const Vector &lhs, const Vector &rhs)
 Equality comparison operator for vectors. More...
 
bool operator!= (const Vector &lhs, const Vector &rhs)
 Inequality operator for points. More...
 

Detailed Description

template<typename T, int NDIMS>
class axom::primal::Vector< T, NDIMS >

Represents a vector, \( v \in \mathcal{R}^d \). It provides access methods for setting and querying the vector components as well as vector math operators, e.g., adding, subtracting, dot_product and cross_product.

Template Parameters
Tthe coordinate type, e.g., double, float, etc.
NDIMSthe number of dimensions
See also
NumericArray
Point

Member Typedef Documentation

◆ PointType

template<typename T, int NDIMS>
typedef Point<T, NDIMS> axom::primal::Vector< T, NDIMS >::PointType

Constructor & Destructor Documentation

◆ Vector() [1/7]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::Vector ( val = T(),
int  sz = NDIMS 
)
inlineexplicit

Fill vector with single value. Acts as default constructor Sets first sz components of the vector to val (default 0).

Parameters
[in]valThe value to set the coordinates to. Defaults to zero
[in]szThe number of coordinates to set to val. The rest will be set to zero. Defaults is NDIMS.

Referenced by axom::primal::Vector< SpaceCoordType, NDIMS >::make_vector(), and axom::primal::Vector< SpaceCoordType, NDIMS >::unitVector().

◆ Vector() [2/7]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::Vector ( const NumericArray< T, NDIMS > &  arr)
inline

Constructor from a numeric array.

Parameters
[in]arrThe numeric array to copy from

◆ Vector() [3/7]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::Vector ( const T *  vals,
int  sz = NDIMS 
)
inline

Creates a vector from the first sz values of the input array.

Parameters
[in]valsAn array containing at least sz values
[in]szThe number of coordinates to take from the array. Defaults to NDIMS. If sz is greater than NDIMS, we only take the first NDIMS values.

◆ Vector() [4/7]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::Vector ( const Point< T, NDIMS > &  pt)
inline

Constructor to create vector from a Point.

Parameters
[in]ptThe point containing the vector's coordinates.
Note
Equivalent to Vector( Point::zero(), pt)

◆ Vector() [5/7]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::Vector ( const Vector< T, NDIMS > &  other)
inline

Copy constructor.

Parameters
[in]otherThe vector to copy

◆ Vector() [6/7]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::Vector ( const Point< T, NDIMS > &  A,
const Point< T, NDIMS > &  B 
)
inline

Constructs a vector from point A to point B.

Parameters
[in]Aorigin point of the vector.
[in]Bdestination point of the vector.
Precondition
A.dimension() == B.dimension()
A.dimension() == ndims

◆ Vector() [7/7]

template<typename T, int NDIMS>
axom::primal::Vector< T, NDIMS >::Vector ( std::initializer_list< T >  values)
inline

Creates a vector from an initializer list.

Parameters
[in]valuesan initializer list containing the values of the vector. If the size is not the same as the size of this vector, this behaves the same way as the constructor which takes a pointer and size.

◆ ~Vector()

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Vector< T, NDIMS >::~Vector ( )
inline

Destructor.

Member Function Documentation

◆ operator=()

template<typename T, int NDIMS>
Vector< T, NDIMS > & axom::primal::Vector< T, NDIMS >::operator= ( const Vector< T, NDIMS > &  other)
inline

Copy assignment operator.

Parameters
[in]otherThe vector to copy

Referenced by axom::primal::Vector< SpaceCoordType, NDIMS >::Vector().

◆ dimension()

template<typename T, int NDIMS>
AXOM_HOST_DEVICE int axom::primal::Vector< T, NDIMS >::dimension ( ) const
inline

Returns the dimension of this vector instance.

Returns
d the dimension (size) of the vector
Postcondition
d >= 1.

Referenced by axom::primal::Vector< SpaceCoordType, NDIMS >::dot_product().

◆ operator[]() [1/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE const T& axom::primal::Vector< T, NDIMS >::operator[] ( int  i) const
inline

Access operator for individual components.

Parameters
[in]ithe component index to access
Returns
p[i] the value at the given component index.
Precondition
(i >= 0) && (i < ndims)

◆ operator[]() [2/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE T& axom::primal::Vector< T, NDIMS >::operator[] ( int  i)
inline

◆ array() [1/2]

◆ array() [2/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE NumericArray<T, NDIMS>& axom::primal::Vector< T, NDIMS >::array ( )
inline

◆ data() [1/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE const T* axom::primal::Vector< T, NDIMS >::data ( ) const
inline

◆ data() [2/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE T* axom::primal::Vector< T, NDIMS >::data ( )
inline

◆ operator+=()

template<typename T, int NDIMS>
Vector< T, NDIMS > & axom::primal::Vector< T, NDIMS >::operator+= ( const Vector< T, NDIMS > &  v)
inline

Adds the vector to the Vector instance \(\vec{u} +=\vec{v}\).

Parameters
[in]vthe vector to add.
Returns
A reference to the Vector instance after vector addition.

◆ operator-=()

template<typename T, int NDIMS>
Vector< T, NDIMS > & axom::primal::Vector< T, NDIMS >::operator-= ( const Vector< T, NDIMS > &  v)
inline

Adds the vector ot the Vector instance \(\vec{u} -=\vec{v}\).

Parameters
[in]vthe vector to subtract.
Returns
A reference to the Vector instance after vector subtraction.

◆ operator*=()

template<typename T, int NDIMS>
Vector< T, NDIMS > & axom::primal::Vector< T, NDIMS >::operator*= ( scalar)
inline

Scalar multiplication on the Vector instance.

Parameters
[in]scalarthe scalar value to multiply with this vector.
Returns
A reference to the vector instance after scalar multiplication.

◆ operator/=()

template<typename T, int NDIMS>
Vector< T, NDIMS > & axom::primal::Vector< T, NDIMS >::operator/= ( scalar)
inline

Scalar division on the Vector instance.

Parameters
[in]scalarthe scalar value to divide with this vector.
Precondition
scalar != 0
Returns
A reference to the vector instance after scalar division.

◆ dot()

template<typename T, int NDIMS>
T axom::primal::Vector< T, NDIMS >::dot ( const Vector< T, NDIMS > &  v) const
inline

Dot product of the Vector instance with another vector v.

Parameters
[in]vthe other vector in the dot product
Returns
The dot product of the two vectors.

Referenced by axom::quest::SignedDistance< NDIMS >::computeDistance(), axom::primal::Vector< SpaceCoordType, NDIMS >::squared_norm(), and axom::primal::OrientedBoundingBox< T, NDIMS >::toLocal().

◆ squared_norm()

template<typename T , int NDIMS>
double axom::primal::Vector< T, NDIMS >::squared_norm ( ) const
inline

◆ norm()

template<typename T , int NDIMS>
double axom::primal::Vector< T, NDIMS >::norm ( ) const
inline

Computes the \( l^2 \) norm of this vector instance.

Returns
n the norm of the vector, a.k.a., magnitude or length.

Referenced by axom::primal::Triangle< T, NDIMS >::angle(), axom::spin::ImplicitGrid< NDIMS, TheIndexType >::initialize(), and axom::primal::Segment< T, NDIMS >::length().

◆ negate()

template<typename T , int NDIMS>
void axom::primal::Vector< T, NDIMS >::negate ( )
inline

Component-wise negation of the vector.

Referenced by axom::primal::operator-().

◆ unitVector()

template<typename T , int NDIMS>
Vector< T, NDIMS > axom::primal::Vector< T, NDIMS >::unitVector ( ) const
inline

Creates a new unit vector in the direction of the vector instance.

Note
The unit vector of the zero vector is (1,0,0,...) when normalized.
Postcondition
this->norm() == 1.0f

Referenced by axom::primal::Ray< T, NDIMS >::Ray().

◆ print()

template<typename T , int NDIMS>
std::ostream & axom::primal::Vector< T, NDIMS >::print ( std::ostream &  os) const

Simple formatted print of a Vector instance.

Parameters
osThe output stream to write to
Returns
A reference to the modified ostream

Referenced by axom::primal::operator<<().

◆ dot_product()

template<typename T, int NDIMS>
T axom::primal::Vector< T, NDIMS >::dot_product ( const Vector< T, NDIMS > &  u,
const Vector< T, NDIMS > &  v 
)
inlinestatic

Computes the dot product of two vectors u, v.

Parameters
[in]uthe vector on the right-hand side.
[in]vthe vector on the left-hand side.
Returns
dotprod the computed dot product.
Precondition
u.dimension() == v.dimension().

Referenced by axom::primal::Triangle< T, NDIMS >::angle(), axom::primal::closest_point(), axom::primal::Vector< SpaceCoordType, NDIMS >::dot(), and axom::primal::squared_distance().

◆ cross_product() [1/2]

template<typename T, int NDIMS>
Vector< T, 3 > axom::primal::Vector< T, NDIMS >::cross_product ( const Vector< T, 2 > &  u,
const Vector< T, 2 > &  v 
)
inlinestatic

Computes the cross product of vector u and v, treating them as 3D.

Parameters
[in]uthe vector on the right-hand side.
[in]vthe vector on the left-hand side.
Returns
C the resulting vector from A x B.

Referenced by axom::primal::Triangle< T, NDIMS >::area(), axom::primal::Triangle< T, NDIMS >::normal(), and axom::primal::Triangle< T, NDIMS >::physToBarycentric().

◆ cross_product() [2/2]

template<typename T, int NDIMS>
Vector< T, 3 > axom::primal::Vector< T, NDIMS >::cross_product ( const Vector< T, 3 > &  u,
const Vector< T, 3 > &  v 
)
inlinestatic

Computes the 3-D cross product of vector u and v.

Parameters
[in]uthe vector on the right-hand side.
[in]vthe vector on the left-hand side.
Returns
C the resulting vector from A x B.

◆ make_vector()

template<typename T, int NDIMS>
Vector< T, NDIMS > axom::primal::Vector< T, NDIMS >::make_vector ( const T &  x,
const T &  y,
const T &  z = 0.0 
)
inlinestatic

Utility function to constructs a Vector with the given coordinates.

Parameters
[in]xthe x–coordinate of the vector.
[in]ythe y–coordinate of the vector.
[in]zthe z–coordinate of the vector. Default is 0.0.
Returns
v a Vector instance with the given coordinates.

Friends And Related Function Documentation

◆ operator==

template<typename T, int NDIMS>
bool operator== ( const Vector< T, NDIMS > &  lhs,
const Vector< T, NDIMS > &  rhs 
)
friend

Equality comparison operator for vectors.

◆ operator!=

template<typename T, int NDIMS>
bool operator!= ( const Vector< T, NDIMS > &  lhs,
const Vector< T, NDIMS > &  rhs 
)
friend

Inequality operator for points.


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