AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
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.6.0/src/axom/primal/geometry/Vector.hpp>
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... | |
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_DEVICE T | dot (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_DEVICE T | dot_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 | |
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... | |
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.
T | the coordinate type, e.g., double, float, etc. |
NDIMS | the number of dimensions |
using axom::primal::Vector< T, NDIMS >::PointType = Point<T, NDIMS> |
using axom::primal::Vector< T, NDIMS >::CoordType = T |
|
inlineexplicit |
Fill vector with single value. Acts as default constructor Sets first sz components of the vector to val (default 0).
[in] | val | The value to set the coordinates to. Defaults to zero |
[in] | sz | The 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().
|
inlineexplicit |
Constructor from a numeric array.
[in] | arr | The numeric array to copy from |
|
inlineexplicit |
Creates a vector from the first sz values of the input array.
[in] | vals | An array containing at least sz values |
[in] | sz | The number of coordinates to take from the array. Defaults to NDIMS. If sz is greater than NDIMS, we only take the first NDIMS values. |
|
inlineexplicit |
Constructor to create vector from a Point.
[in] | pt | The point containing the vector's coordinates. |
|
inline |
Constructs a vector from point A to point B.
[in] | A | origin point of the vector. |
[in] | B | destination point of the vector. |
|
inline |
Creates a vector from an initializer list.
[in] | values | an 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. |
|
inline |
Returns the dimension of this vector instance.
Referenced by axom::primal::Vector< SpaceCoordType, NDIMS >::dot_product().
|
inline |
Access operator for individual components.
[in] | i | the component index to access |
|
inline |
|
inline |
Returns a reference to the underlying NumericArray.
Referenced by axom::primal::OrientedBoundingBox< T, NDIMS >::bisect(), axom::primal::OrientedBoundingBox< T, NDIMS >::furthestPoint(), axom::primal::OrientedBoundingBox< T, NDIMS >::getPoints(), axom::primal::Vector< SpaceCoordType, NDIMS >::operator+=(), axom::primal::Vector< SpaceCoordType, NDIMS >::operator-=(), axom::primal::BoundingBox< double, DIM >::scale(), and axom::primal::BoundingBox< double, DIM >::shift().
|
inline |
|
inline |
Returns a pointer to the underlying data.
Referenced by axom::primal::Vector< SpaceCoordType, NDIMS >::cross_product(), and axom::primal::Vector< SpaceCoordType, NDIMS >::dot_product().
|
inline |
|
inline |
|
inline |
|
inline |
Scalar multiplication on the Vector instance.
[in] | scalar | the scalar value to multiply with this vector. |
|
inline |
Scalar division on the Vector instance.
[in] | scalar | the scalar value to divide with this vector. |
|
inline |
Check if this is a zero vector.
Referenced by axom::primal::make_plane(), and axom::primal::Plane< T, NDIMS >::Plane().
|
inline |
Dot product of the Vector instance with another vector v.
[in] | v | the other vector in the dot product |
Referenced by axom::quest::SignedDistance< NDIMS, ExecSpace >::computeDistances(), axom::primal::Plane< T, NDIMS >::signedDistance(), axom::primal::Vector< SpaceCoordType, NDIMS >::squared_norm(), axom::primal::OrientedBoundingBox< T, NDIMS >::toLocal(), and axom::primal::Polyhedron< T, NDIMS >::volume().
|
inline |
Computes the squared \( l^2\) norm of this vector instance.
Referenced by axom::primal::Vector< SpaceCoordType, NDIMS >::norm(), axom::primal::Ray< T, NDIMS >::Ray(), axom::primal::squared_distance(), and axom::primal::Vector< SpaceCoordType, NDIMS >::unitVector().
|
inline |
Computes the \( l^2 \) norm of this vector instance.
Referenced by axom::primal::Triangle< double, NDIMS >::angle(), and axom::spin::ImplicitGrid< NDIMS, TheIndexType >::initialize().
|
inline |
Component-wise negation of the vector.
Referenced by axom::primal::operator-().
|
inline |
Creates a new unit vector in the direction of the vector instance.
Referenced by axom::quest::SignedDistance< NDIMS, ExecSpace >::computeDistances(), and axom::primal::Plane< T, NDIMS >::print().
std::ostream & axom::primal::Vector< T, NDIMS >::print | ( | std::ostream & | os | ) | const |
Simple formatted print of a Vector instance.
os | The output stream to write to |
Referenced by axom::primal::operator<<().
|
inlinestatic |
Computes the dot product of two vectors u, v.
[in] | u | the vector on the right-hand side. |
[in] | v | the vector on the left-hand side. |
Referenced by axom::primal::closest_point(), axom::primal::Vector< SpaceCoordType, NDIMS >::dot(), and axom::primal::squared_distance().
|
inlinestatic |
Computes the cross product of vector u and v, treating them as 3D.
[in] | u | the vector on the right-hand side. |
[in] | v | the vector on the left-hand side. |
Referenced by axom::primal::Triangle< double, NDIMS >::area(), axom::primal::make_plane(), axom::primal::Triangle< double, NDIMS >::normal(), and axom::primal::Triangle< double, NDIMS >::physToBarycentric().
|
inlinestatic |
Computes the 3-D cross product of vector u and v.
[in] | u | the vector on the right-hand side. |
[in] | v | the vector on the left-hand side. |
|
inlinestatic |
|
friend |
Equality comparison operator for vectors.
|
friend |
Inequality operator for points.