libMesh
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
libMesh::Kokkos::vector_ref< ViewType > Class Template Reference

Non-owning handle to one vector entry of a Kokkos storage view. More...

#include <kokkos_linalg_base.h>

Public Types

using view_type = ViewType
 
using value_type = detail::vector_view_value_t< ViewType >
 

Public Member Functions

LIBMESH_DEVICE_INLINE vector_ref (ViewType view, const unsigned int index)
 Constructs a reference to entry index of view.
 
LIBMESH_DEVICE_INLINE decltype(auto) operator() (const unsigned int component) const
 
LIBMESH_DEVICE_INLINE decltype(auto) operator() (const unsigned int component)
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE void assign (const RightVector &right)
 Assigns right 's components to the referenced entry.
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE void add (const RightVector &right)
 Adds right to the referenced entry, in place.
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE void add_scaled (const RightVector &right, const value_type &factor)
 Adds factor times right to the referenced entry, in place.
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE void subtract (const RightVector &right)
 Subtracts right from the referenced entry, in place.
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE void subtract_scaled (const RightVector &right, const value_type &factor)
 Subtracts factor times right from the referenced entry, in place.
 
LIBMESH_DEVICE_INLINE void zero ()
 Sets every component of the referenced entry to zero.
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE auto contract (const RightVector &right) const
 
LIBMESH_DEVICE_INLINE auto norm () const
 
LIBMESH_DEVICE_INLINE auto norm_sq () const
 
LIBMESH_DEVICE_INLINE auto l1_norm () const
 
LIBMESH_DEVICE_INLINE bool is_zero () const
 
LIBMESH_DEVICE_INLINE auto unit () const
 
template<typename RightVector >
LIBMESH_DEVICE_INLINE auto cross (const RightVector &right) const
 
LIBMESH_DEVICE_INLINE unsigned int index () const
 

Private Attributes

ViewType _view
 
unsigned int _index
 

Detailed Description

template<typename ViewType>
class libMesh::Kokkos::vector_ref< ViewType >

Non-owning handle to one vector entry of a Kokkos storage view.

A vector_ref pairs a view with an entry index and exposes the entry's components through operator(), so it can be used wherever a vector-like object is expected. Component writes go directly to the underlying view; the arithmetic methods below (defined out-of-line in kokkos_vector_ops.h) either update the view in place or return owning results, mirroring the TypeVector interface.

Refs are cheap to construct and copy (a view handle plus an index) and are intended to be created on the fly inside kernels via make_vector_ref().

Definition at line 193 of file kokkos_linalg_base.h.

Member Typedef Documentation

◆ value_type

template<typename ViewType >
using libMesh::Kokkos::vector_ref< ViewType >::value_type = detail::vector_view_value_t<ViewType>

Definition at line 198 of file kokkos_linalg_base.h.

◆ view_type

template<typename ViewType >
using libMesh::Kokkos::vector_ref< ViewType >::view_type = ViewType

Definition at line 197 of file kokkos_linalg_base.h.

Constructor & Destructor Documentation

◆ vector_ref()

template<typename ViewType >
LIBMESH_DEVICE_INLINE libMesh::Kokkos::vector_ref< ViewType >::vector_ref ( ViewType  view,
const unsigned int  index 
)
inline

Constructs a reference to entry index of view.

Definition at line 204 of file kokkos_linalg_base.h.

204: _view(view), _index(index) {}
LIBMESH_DEVICE_INLINE unsigned int index() const

Member Function Documentation

◆ add()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::vector_ref< ViewType >::add ( const RightVector &  right)

Adds right to the referenced entry, in place.

Definition at line 409 of file kokkos_vector_ops.h.

410{
411 libMesh::Kokkos::operator+=(*this, right);
412}
LIBMESH_DEVICE_INLINE auto operator+=(LeftTensor &left, const RightTensor &right) -> std::enable_if_t< is_tensor_like_v< LeftTensor > &&is_tensor_like_v< RightTensor > &&(is_tensor_ref_v< LeftTensor >||is_tensor_ref_v< RightTensor >), LeftTensor & >
Adds right to left in place; when left is a ref, the update writes through to the underlying storage.

References libMesh::Kokkos::operator+=().

◆ add_scaled()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::vector_ref< ViewType >::add_scaled ( const RightVector &  right,
const value_type &  factor 
)

Adds factor times right to the referenced entry, in place.

Definition at line 417 of file kokkos_vector_ops.h.

418{
419 detail::update_vector_components(*this, right, factor);
420}
LIBMESH_DEVICE_INLINE void update_vector_components(LeftVector &left, const RightVector &right, const Scalar &factor)
Componentwise axpy-style update: left += factor * right.

References libMesh::Kokkos::detail::update_vector_components().

◆ assign()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::vector_ref< ViewType >::assign ( const RightVector &  right)

Assigns right 's components to the referenced entry.

Definition at line 401 of file kokkos_vector_ops.h.

402{
404}
LIBMESH_DEVICE_INLINE void assign_vector_components(LeftVector &left, const RightVector &right)
Componentwise copy: left = right.

References libMesh::Kokkos::detail::assign_vector_components().

◆ contract()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::vector_ref< ViewType >::contract ( const RightVector &  right) const
Returns
The dot product of the referenced entry with right.

Definition at line 448 of file kokkos_vector_ops.h.

449{
450 return libMesh::Kokkos::contract(*this, right);
451}
LIBMESH_DEVICE_INLINE auto contract(const LeftTensor &left, const RightTensor &right)

References libMesh::Kokkos::contract().

◆ cross()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::vector_ref< ViewType >::cross ( const RightVector &  right) const
Returns
The cross product of the referenced entry with right, as an owning vector.

Definition at line 510 of file kokkos_vector_ops.h.

511{
512 return vector_cross(*this, right);
513}
LIBMESH_DEVICE_INLINE auto vector_cross(const LeftVector &left, const RightVector &right) -> std::conditional_t< std::is_void< ResultVector >::value, vector_semantic_type_t< LeftVector >, ResultVector >

References libMesh::Kokkos::vector_cross().

◆ index()

template<typename ViewType >
LIBMESH_DEVICE_INLINE unsigned int libMesh::Kokkos::vector_ref< ViewType >::index ( ) const
inline
Returns
The index of the entry this ref addresses within its view.

Definition at line 320 of file kokkos_linalg_base.h.

321 {
322 return _index;
323 }

References libMesh::Kokkos::vector_ref< ViewType >::_index.

◆ is_zero()

template<typename ViewType >
LIBMESH_DEVICE_INLINE bool libMesh::Kokkos::vector_ref< ViewType >::is_zero ( ) const
Returns
true if every component of the referenced entry is exactly zero, false otherwise.

Definition at line 491 of file kokkos_vector_ops.h.

492{
493 for (unsigned int component = 0; component < LIBMESH_DIM; ++component)
494 if ((*this)(component) != value_type(0))
495 return false;
496
497 return true;
498}
detail::vector_view_value_t< ViewType > value_type

◆ l1_norm()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::vector_ref< ViewType >::l1_norm ( ) const
Returns
The l1-norm of the referenced entry, i.e. the sum of the absolute values of the components.

Definition at line 477 of file kokkos_vector_ops.h.

478{
479 using std::abs;
480 using norm_type = detail::remove_cvref_t<decltype(abs((*this)(0)))>;
481
482 norm_type sum = norm_type(0);
483 for (unsigned int component = 0; component < LIBMESH_DIM; ++component)
484 sum += abs((*this)(component));
485
486 return sum;
487}
typename std::remove_cv< typename std::remove_reference< T >::type >::type remove_cvref_t
Strips reference and const/volatile qualifiers from T, turning e.g.

◆ norm()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::vector_ref< ViewType >::norm ( ) const
Returns
The magnitude of the referenced entry, i.e. the square-root of the sum of the elements squared.

Definition at line 455 of file kokkos_vector_ops.h.

456{
457 using std::sqrt;
458 return sqrt(this->norm_sq());
459}
LIBMESH_DEVICE_INLINE auto norm_sq() const

◆ norm_sq()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::vector_ref< ViewType >::norm_sq ( ) const
Returns
The magnitude squared of the referenced entry.

Definition at line 463 of file kokkos_vector_ops.h.

464{
465 // TensorTools::norm_sq handles complex-valued components correctly.
466 using norm_type = detail::remove_cvref_t<decltype(libMesh::TensorTools::norm_sq((*this)(0)))>;
467
468 norm_type sum = norm_type(0);
469 for (unsigned int component = 0; component < LIBMESH_DIM; ++component)
470 sum += libMesh::TensorTools::norm_sq((*this)(component));
471
472 return sum;
473}
LIBMESH_DEVICE_INLINE auto norm_sq(const T &a)

References libMesh::TensorTools::norm_sq().

◆ operator()() [1/2]

template<typename ViewType >
LIBMESH_DEVICE_INLINE decltype(auto) libMesh::Kokkos::vector_ref< ViewType >::operator() ( const unsigned int  component)
inline

Definition at line 220 of file kokkos_linalg_base.h.

221 {
222 return _view(_index, component);
223 }

References libMesh::Kokkos::vector_ref< ViewType >::_index, and libMesh::Kokkos::vector_ref< ViewType >::_view.

◆ operator()() [2/2]

template<typename ViewType >
LIBMESH_DEVICE_INLINE decltype(auto) libMesh::Kokkos::vector_ref< ViewType >::operator() ( const unsigned int  component) const
inline
Returns
A reference to component component of the referenced entry. Writes through it land directly in the underlying view; since Kokkos view constness is shallow, even the const overload yields a writable reference when the view's data type is non-const.

Definition at line 214 of file kokkos_linalg_base.h.

215 {
216 return _view(_index, component);
217 }

References libMesh::Kokkos::vector_ref< ViewType >::_index, and libMesh::Kokkos::vector_ref< ViewType >::_view.

◆ subtract()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::vector_ref< ViewType >::subtract ( const RightVector &  right)

Subtracts right from the referenced entry, in place.

Definition at line 425 of file kokkos_vector_ops.h.

426{
427 libMesh::Kokkos::operator-=(*this, right);
428}
LIBMESH_DEVICE_INLINE auto operator-=(LeftTensor &left, const RightTensor &right) -> std::enable_if_t< is_tensor_like_v< LeftTensor > &&is_tensor_like_v< RightTensor > &&(is_tensor_ref_v< LeftTensor >||is_tensor_ref_v< RightTensor >), LeftTensor & >
Subtracts right from left in place.

References libMesh::Kokkos::operator-=().

◆ subtract_scaled()

template<typename ViewType >
template<typename RightVector >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::vector_ref< ViewType >::subtract_scaled ( const RightVector &  right,
const value_type &  factor 
)

Subtracts factor times right from the referenced entry, in place.

Definition at line 433 of file kokkos_vector_ops.h.

434{
435 detail::update_vector_components(*this, right, -factor);
436}

References libMesh::Kokkos::detail::update_vector_components().

◆ unit()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::vector_ref< ViewType >::unit ( ) const
Returns
An owning unit vector in the direction of the referenced entry.

Definition at line 502 of file kokkos_vector_ops.h.

503{
504 return vector_unit(*this);
505}
LIBMESH_DEVICE_INLINE auto vector_unit(const VectorLike &v) -> std::conditional_t< std::is_void< ResultVector >::value, vector_semantic_type_t< VectorLike >, ResultVector >

References libMesh::Kokkos::vector_unit().

◆ zero()

template<typename ViewType >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::vector_ref< ViewType >::zero ( )

Sets every component of the referenced entry to zero.

Definition at line 440 of file kokkos_vector_ops.h.

441{
443}
LIBMESH_DEVICE_INLINE void fill_vector_components(VectorLike &v, const Scalar &value)
Sets every component of v to value.

References libMesh::Kokkos::detail::fill_vector_components().

Member Data Documentation

◆ _index

template<typename ViewType >
unsigned int libMesh::Kokkos::vector_ref< ViewType >::_index
private

◆ _view

template<typename ViewType >
ViewType libMesh::Kokkos::vector_ref< ViewType >::_view
private

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