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/latest/src/axom/primal/geometry/Vector.hpp>

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

Public Types

using PointType = Point< T, NDIMS >
 
using CoordType = T
 

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 Point< T, NDIMS > &A, const Point< T, NDIMS > &B)
 Constructs a vector from point A to point B. More...
 
AXOM_HOST_DEVICE Vector (std::initializer_list< T > values)
 Creates a vector from an initializer list. 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 ()
 
AXOM_HOST_DEVICE Vector< T, NDIMS > & operator+= (const Vector< T, NDIMS > &v)
 Adds the vector to the Vector instance \(\vec{u} +=\vec{v}\). More...
 
AXOM_HOST_DEVICE Vector< T, NDIMS > & operator-= (const Vector< T, NDIMS > &v)
 Adds the vector ot the Vector instance \(\vec{u} -=\vec{v}\). More...
 
AXOM_HOST_DEVICE 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_DEVICE bool is_zero () const
 Check if this is a zero vector. 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...
 
AXOM_HOST_DEVICE 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 AXOM_HOST_DEVICEscalar_triple_product (const Vector< T, 3 > &u, const Vector< T, 3 > &v, const Vector< T, 3 > &w)
 Computes the 3-D scalar triple product of vectors u, v and w. 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

AXOM_HOST_DEVICE friend 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>
using axom::primal::Vector< T, NDIMS >::PointType = Point<T, NDIMS>

◆ CoordType

template<typename T , int NDIMS>
using axom::primal::Vector< T, NDIMS >::CoordType = T

Constructor & Destructor Documentation

◆ Vector() [1/6]

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.

◆ Vector() [2/6]

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

Constructor from a numeric array.

Parameters
[in]arrThe numeric array to copy from

◆ Vector() [3/6]

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

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/6]

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

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/6]

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() [6/6]

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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.

Member Function Documentation

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

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

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

Returns a reference to the underlying NumericArray.

◆ 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

Returns a pointer to the underlying data.

References axom::primal::NumericArray< T, SIZE >::data().

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

References axom::primal::Vector< T, NDIMS >::array().

◆ operator-=()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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.

References axom::primal::Vector< T, NDIMS >::array().

◆ operator*=()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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>
AXOM_HOST_DEVICE 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.

◆ is_zero()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE bool axom::primal::Vector< T, NDIMS >::is_zero
inline

Check if this is a zero vector.

Returns
whether this vector consists of all zeros

References axom::utilities::isNearlyEqual().

◆ dot()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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.

References axom::numerics::dot_product().

◆ squared_norm()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE double axom::primal::Vector< T, NDIMS >::squared_norm
inline

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

Returns
n the squared norm.
See also
Vector::norm()

◆ norm()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE double axom::primal::Vector< T, NDIMS >::norm
inline

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

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

◆ negate()

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

Component-wise negation of the vector.

◆ unitVector()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE Vector< T, NDIMS > axom::primal::Vector< T, NDIMS >::unitVector
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

◆ 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

◆ dot_product()

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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().

◆ cross_product() [1/2]

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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.

References axom::numerics::determinant().

◆ cross_product() [2/2]

template<typename T , int NDIMS>
AXOM_HOST_DEVICE 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.

References axom::numerics::determinant().

◆ scalar_triple_product()

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

Computes the 3-D scalar triple product of vectors u, v and w.

Parameters
[in]uthe first vector
[in]vthe second vector
[in]wthe third vector
Returns
The scalar triple product of u, v and w

The scalar triple product dot(u, v x w) is the signed volume of the parallelepiped defined by the three 3D vectors

References axom::numerics::determinant().

◆ 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>
AXOM_HOST_DEVICE friend 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: