waLBerla 7.3
Loading...
Searching...
No Matches
walberla::math::Vector3< Type > Class Template Reference

Detailed Description

template<typename Type>
class walberla::math::Vector3< Type >

Efficient, generic implementation of a 3-dimensional vector.

The Vector3 class is the representation of a 3D vector with a total of 3 statically allocated elements of arbitrary type. The naming convention of the elements is as follows:

                         \f[\left(\begin{array}{*{3}{c}}
                         x & y & z \\
                         \end{array}\right)\f]

These elements can be accessed directly with the subscript operator. The numbering of the vector elements is

                         \f[\left(\begin{array}{*{3}{c}}
                         0 & 1 & 2 \\
                         \end{array}\right)\f]

#include <Vector3.h>

Public Types

using Length = typename SqrtTrait<Type>::Type
 Vector length return type.
using value_type = Type

Public Member Functions

WALBERLA_HOST_DEVICE constexpr Vector3 ()=default
WALBERLA_HOST_DEVICE constexpr Vector3 (Type init)
 Constructor for a homogenous initialization of all elements.
template<typename Other>
WALBERLA_HOST_DEVICE constexpr Vector3 (Other init)
WALBERLA_HOST_DEVICE constexpr Vector3 (Type x, Type y, Type z)
 Constructor for a direct initialization of all vector elements.
WALBERLA_HOST_DEVICE constexpr Vector3 (const Type *init)
 Constructor for an array initializer.
WALBERLA_HOST_DEVICE constexpr Vector3 (const Vector3 &v)=default
template<typename Other>
WALBERLA_HOST_DEVICE constexpr Vector3 (const Vector3< Other > &v)
 Conversion constructor from different Vector3 instances.
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & operator= (const Vector3< Other > &v)
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & operator%= (const Vector3< Other > &rhs)
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & operator+= (const Vector3< Other > &rhs)
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & operator-= (const Vector3< Other > &rhs)
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & operator*= (Other rhs)
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & operator/= (Other rhs)
Operators
WALBERLA_HOST_DEVICE Vector3operator= (const Vector3 &v)=default
template<typename Other>
WALBERLA_HOST_DEVICE Vector3operator= (const Vector3< Other > &v)
 Assignment operator for different Vector3 instances.
template<typename Other>
WALBERLA_HOST_DEVICE bool operator== (Other rhs) const
 Equality operator for the comparison of a vector and a scalar value.
template<typename Other>
WALBERLA_HOST_DEVICE bool operator== (const Vector3< Other > &rhs) const
 Equality operator for the comparison of two vectors.
template<typename Other>
WALBERLA_HOST_DEVICE bool operator!= (Other rhs) const
 Inequality operator for the comparison of a vector and a scalar value.
template<typename Other>
WALBERLA_HOST_DEVICE bool operator!= (const Vector3< Other > &rhs) const
 Inequality operator for the comparison of two vectors.
WALBERLA_HOST_DEVICE Type & operator[] (uint_t index)
 Subscript operator for the direct access to the vector elements.
WALBERLA_HOST_DEVICE const Type & operator[] (uint_t index) const
 Subscript operator for the direct access to the vector elements.
Arithmetic operators

The return type of the arithmetic operators depends on the involved data types of

the vectors. HIGH denotes the more significant data type of the arithmetic operation

(for further detail see the MathTrait class description).

WALBERLA_HOST_DEVICE Vector3 operator- () const
 Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)).
template<typename Other>
WALBERLA_HOST_DEVICE Vector3operator%= (const Vector3< Other > &rhs)
 Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).
template<typename Other>
WALBERLA_HOST_DEVICE Vector3operator+= (const Vector3< Other > &rhs)
 Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)).
template<typename Other>
WALBERLA_HOST_DEVICE Vector3operator-= (const Vector3< Other > &rhs)
 Subtraction assignment operator for the subtraction of two vectors.
template<typename Other>
WALBERLA_HOST_DEVICE Vector3operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a vector and.
template<typename Other>
WALBERLA_HOST_DEVICE Vector3operator/= (Other rhs)
 Division assignment operator for the division of a vector by a scalar value.
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > operator% (const Vector3< Other > &rhs) const
 Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > operator+ (const Vector3< Other > &rhs) const
 Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)).
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > operator- (const Vector3< Other > &rhs) const
 Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)).
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > operator* (Other rhs) const
 Multiplication operator for the multiplication of a vector and a scalar value.
template<typename Other>
WALBERLA_HOST_DEVICE MathTrait< Type, Other >::High operator* (const Vector3< Other > &rhs) const
 Multiplication operator for the scalar product (inner product) of two vectors.
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > operator/ (Other rhs) const
 Division operator for the division of a vector by a scalar value.
Utility functions
WALBERLA_HOST_DEVICE uint_t indexOfMax () const
 Returns index of absolute maximum value.
WALBERLA_HOST_DEVICE uint_t indexOfMin () const
 Returns index of absolute minimum value.
WALBERLA_HOST_DEVICE Type max () const
 Returns maximum value.
WALBERLA_HOST_DEVICE Type min () const
 Returns minimum value.
WALBERLA_HOST_DEVICE void set (Type x, Type y, Type z)
 Set function for a direct assignment of all vector elements.
WALBERLA_HOST_DEVICE Length length () const
 Calculation of the vector length \(|\vec{a}|\).
WALBERLA_HOST_DEVICE Type sqrLength () const
 Calculation of the vector square length \(|\vec{a}|^2\).
WALBERLA_HOST_DEVICE Vector3< LengthgetNormalized () const
 Calculation of the normalized vector ( \(|\vec{a}|=1\)).
WALBERLA_HOST_DEVICE Vector3< LengthgetNormalizedOrZero () const
 Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition.
WALBERLA_HOST_DEVICE Vector3< LengthgetNormalizedIfNotZero () const
 Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition.
WALBERLA_HOST_DEVICE void reset ()
 Sets all components of the vector to 0.
WALBERLA_HOST_DEVICE Type * data ()
WALBERLA_HOST_DEVICE Type const * data () const

Private Attributes

Member variables
stdlib::array< Type, 3 > v_ = { Type(), Type(), Type() }
 The three statically allocated vector elements.

Member Typedef Documentation

◆ Length

template<typename Type>
using walberla::math::Vector3< Type >::Length = typename SqrtTrait<Type>::Type

Vector length return type.

Return type of the Vector3<Type>::length function.

◆ value_type

template<typename Type>
using walberla::math::Vector3< Type >::value_type = Type

Constructor & Destructor Documentation

◆ Vector3() [1/7]

template<typename Type>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( )
explicitconstexprdefault

◆ Vector3() [2/7]

template<typename Type>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( Type init)
inlineexplicitconstexpr

Constructor for a homogenous initialization of all elements.

Parameters
initInitial value for all vector elements.

◆ Vector3() [3/7]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( Other init)
inlineexplicitconstexpr

◆ Vector3() [4/7]

template<typename Type>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( Type x,
Type y,
Type z )
inlineexplicitconstexpr

Constructor for a direct initialization of all vector elements.

Parameters
xThe initial value for the x-component.
yThe initial value for the y-component.
zThe initial value for the z-component.

◆ Vector3() [5/7]

template<typename Type>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( const Type * init)
inlineexplicitconstexpr

Constructor for an array initializer.

Parameters
initPointer to the initialization array.

The array is assumed to have at least three valid elements.

◆ Vector3() [6/7]

template<typename Type>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( const Vector3< Type > & v)
constexprdefault

◆ Vector3() [7/7]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE constexpr walberla::math::Vector3< Type >::Vector3 ( const Vector3< Other > & v)
inlineconstexpr

Conversion constructor from different Vector3 instances.

Parameters
vVector to be copied.

Member Function Documentation

◆ data() [1/2]

template<typename Type>
WALBERLA_HOST_DEVICE Type * walberla::math::Vector3< Type >::data ( )
inline

◆ data() [2/2]

template<typename Type>
WALBERLA_HOST_DEVICE Type const * walberla::math::Vector3< Type >::data ( ) const
inline

◆ getNormalized()

template<typename Type>
WALBERLA_HOST_DEVICE Vector3< typename Vector3< Type >::Length > walberla::math::Vector3< Type >::getNormalized ( ) const

Calculation of the normalized vector ( \(|\vec{a}|=1\)).

Precondition
\(|\vec{a}|\neq0\)
Returns
The normalized vector.

The function returns the normalized vector.

◆ getNormalizedIfNotZero()

template<typename Type>
WALBERLA_HOST_DEVICE Vector3< typename Vector3< Type >::Length > walberla::math::Vector3< Type >::getNormalizedIfNotZero ( ) const

Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition.

Returns
The normalized vector or the original vector if vector is too small.

◆ getNormalizedOrZero()

template<typename Type>
WALBERLA_HOST_DEVICE Vector3< typename Vector3< Type >::Length > walberla::math::Vector3< Type >::getNormalizedOrZero ( ) const

Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition.

Returns
The normalized vector or a vector with all components equal to zero if vector is too small.

◆ indexOfMax()

template<typename Type>
WALBERLA_HOST_DEVICE uint_t walberla::math::Vector3< Type >::indexOfMax ( ) const
inline

Returns index of absolute maximum value.

◆ indexOfMin()

template<typename Type>
WALBERLA_HOST_DEVICE uint_t walberla::math::Vector3< Type >::indexOfMin ( ) const
inline

Returns index of absolute minimum value.

◆ length()

template<typename Type>
WALBERLA_HOST_DEVICE SqrtTrait< Type >::Type walberla::math::Vector3< Type >::length ( ) const
inline

Calculation of the vector length \(|\vec{a}|\).

Returns
The length of the vector.

The return type of the length function depends on the actual type of the vector instance:

Type Length
floatfloat
integral data types and doubledouble
long doublelong double

◆ max()

template<typename Type>
WALBERLA_HOST_DEVICE Type walberla::math::Vector3< Type >::max ( ) const
inline

Returns maximum value.

◆ min()

template<typename Type>
WALBERLA_HOST_DEVICE Type walberla::math::Vector3< Type >::min ( ) const
inline

Returns minimum value.

◆ operator!=() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE bool walberla::math::Vector3< Type >::operator!= ( const Vector3< Other > & rhs) const
inline

Inequality operator for the comparison of two vectors.

Parameters
rhsThe right-hand-side vector for the comparison.
Returns
bool

◆ operator!=() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE bool walberla::math::Vector3< Type >::operator!= ( Other rhs) const
inline

Inequality operator for the comparison of a vector and a scalar value.

Parameters
rhsThe right-hand-side scalar value for the comparison.
Returns
bool

If one value of the vector is inequal to the scalar value, the inequality test returns true, otherwise false.

◆ operator%()

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator% ( const Vector3< Other > & rhs) const
inline

Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).

Parameters
rhsThe right-hand-side vector for the cross product.
Returns
The cross product.

◆ operator%=() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & walberla::math::Vector3< Type >::operator%= ( const Vector3< Other > & rhs)
inline

◆ operator%=() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator%= ( const Vector3< Other > & rhs)

Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).

Parameters
rhsThe right-hand-side vector for the cross product.
Returns
The cross product.

◆ operator*() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE MathTrait< Type, Other >::High walberla::math::Vector3< Type >::operator* ( const Vector3< Other > & rhs) const
inline

Multiplication operator for the scalar product (inner product) of two vectors.

( \( s=\vec{a}*\vec{b} \)).

Parameters
rhsThe right-hand-side vector for the inner product.
Returns
The scalar product.

The operator returns a scalar value of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).

◆ operator*() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator* ( Other rhs) const
inline

Multiplication operator for the multiplication of a vector and a scalar value.

( \( \vec{a}=\vec{b}*s \)).

Parameters
rhsThe right-hand-side scalar value for the multiplication.
Returns
The scaled result vector.

The operator returns a vector of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).

◆ operator*=() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & walberla::math::Vector3< Type >::operator*= ( Other rhs)
inline

◆ operator*=() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator*= ( Other rhs)

Multiplication assignment operator for the multiplication between a vector and.

a scalar value ( \( \vec{a}*=s \)).

Parameters
rhsThe right-hand-side scalar value for the multiplication.
Returns
Reference to the vector.

◆ operator+()

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator+ ( const Vector3< Other > & rhs) const
inline

Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)).

Parameters
rhsThe right-hand-side vector to be added to the vector.
Returns
The sum of the two vectors.

The operator returns a vector of the higher-order data type of the two involved vector data types (in fact the two template arguments Type and Other ).

◆ operator+=() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & walberla::math::Vector3< Type >::operator+= ( const Vector3< Other > & rhs)
inline

◆ operator+=() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator+= ( const Vector3< Other > & rhs)

Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)).

Parameters
rhsThe right-hand-side vector to be added to the vector.
Returns
Reference to the vector.

◆ operator-() [1/2]

template<typename Type>
WALBERLA_HOST_DEVICE Vector3< Type > walberla::math::Vector3< Type >::operator- ( ) const
inline

Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)).

Returns
The inverse of the vector.

◆ operator-() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator- ( const Vector3< Other > & rhs) const
inline

Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)).

Parameters
rhsThe right-hand-side vector to be subtracted from the vector.
Returns
The difference of the two vectors.

The operator returns a vector of the higher-order data type of the two involved vector data types (in fact the two template arguments Type and Other ).

◆ operator-=() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & walberla::math::Vector3< Type >::operator-= ( const Vector3< Other > & rhs)
inline

◆ operator-=() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator-= ( const Vector3< Other > & rhs)

Subtraction assignment operator for the subtraction of two vectors.

( \( \vec{a}-=\vec{b} \)).

Parameters
rhsThe right-hand-side vector to be subtracted from the vector.
Returns
Reference to the vector.

◆ operator/()

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator/ ( Other rhs) const
inline

Division operator for the division of a vector by a scalar value.

( \( \vec{a}=\vec{b}/s \)).

Parameters
rhsThe right-hand-side scalar value for the division.
Returns
The scaled result vector.

The operator returns a vector of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
Note: No check for 0 is applied.

◆ operator/=() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & walberla::math::Vector3< Type >::operator/= ( Other rhs)
inline

◆ operator/=() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator/= ( Other rhs)

Division assignment operator for the division of a vector by a scalar value.

( \( \vec{a}/=s \)).

Parameters
rhsThe right-hand-side scalar value for the division.
Returns
Reference to the vector.

Note: No check for 0 is applied.

◆ operator=() [1/3]

template<typename Type>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator= ( const Vector3< Type > & v)
default

◆ operator=() [2/3]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3< Type > & walberla::math::Vector3< Type >::operator= ( const Vector3< Other > & v)
inline

◆ operator=() [3/3]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE Vector3 & walberla::math::Vector3< Type >::operator= ( const Vector3< Other > & v)

Assignment operator for different Vector3 instances.

Parameters
vVector to be copied.
Returns
Reference to the assigned vector.

◆ operator==() [1/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE bool walberla::math::Vector3< Type >::operator== ( const Vector3< Other > & rhs) const
inline

Equality operator for the comparison of two vectors.

Parameters
rhsThe right-hand-side vector for the comparison.
Returns
bool

◆ operator==() [2/2]

template<typename Type>
template<typename Other>
WALBERLA_HOST_DEVICE bool walberla::math::Vector3< Type >::operator== ( Other rhs) const
inline

Equality operator for the comparison of a vector and a scalar value.

Parameters
rhsThe right-hand-side scalar value for the comparison.
Returns
bool

If all values of the vector are equal to the scalar value, the equality test returns true, otherwise false.

◆ operator[]() [1/2]

template<typename Type>
WALBERLA_HOST_DEVICE Type & walberla::math::Vector3< Type >::operator[] ( uint_t index)
inline

Subscript operator for the direct access to the vector elements.

Parameters
indexAccess index. The index has to be in the range \([0..2]\).
Returns
Reference to the accessed value.

◆ operator[]() [2/2]

template<typename Type>
WALBERLA_HOST_DEVICE const Type & walberla::math::Vector3< Type >::operator[] ( uint_t index) const
inline

Subscript operator for the direct access to the vector elements.

Parameters
indexAccess index. The index has to be in the range \([0..2]\).
Returns
Reference-to-const to the accessed value.

◆ reset()

template<typename Type>
WALBERLA_HOST_DEVICE void walberla::math::Vector3< Type >::reset ( )

Sets all components of the vector to 0.

◆ set()

template<typename Type>
WALBERLA_HOST_DEVICE void walberla::math::Vector3< Type >::set ( Type x,
Type y,
Type z )
inline

Set function for a direct assignment of all vector elements.

Parameters
xThe initial value for the x-component.
yThe initial value for the y-component.
zThe initial value for the z-component.

◆ sqrLength()

template<typename Type>
WALBERLA_HOST_DEVICE Type walberla::math::Vector3< Type >::sqrLength ( ) const
inline

Calculation of the vector square length \(|\vec{a}|^2\).

Returns
The square length of the vector.

Member Data Documentation

◆ v_

template<typename Type>
stdlib::array< Type, 3 > walberla::math::Vector3< Type >::v_ = { Type(), Type(), Type() }
private

The three statically allocated vector elements.

Access to the vector values is gained via the subscript operator. The order of the elements is

\[\left(\begin{array}{*{3}{c}} 0 & 1 & 2 \\ \end{array}\right)\]


The documentation for this class was generated from the following files:
  • /builds/administration/walberla-website/walberla/src/core/math/Quaternion.h
  • /builds/administration/walberla-website/walberla/src/core/math/Vector3.h