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

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

#include <kokkos_linalg_base.h>

Public Types

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

Public Member Functions

LIBMESH_DEVICE_INLINE tensor_ref (ViewType view, const unsigned int index)
 Constructs a reference to entry index of view.
 
LIBMESH_DEVICE_INLINE decltype(auto) operator() (const unsigned int row, const unsigned int col) const
 
LIBMESH_DEVICE_INLINE decltype(auto) operator() (const unsigned int row, const unsigned int col)
 
template<typename RightTensor >
LIBMESH_DEVICE_INLINE void assign (const RightTensor &right)
 Assigns right 's components to the referenced entry.
 
template<typename RightTensor >
LIBMESH_DEVICE_INLINE void add (const RightTensor &right)
 Adds right to the referenced entry, in place.
 
template<typename RightTensor >
LIBMESH_DEVICE_INLINE void add_scaled (const RightTensor &right, const value_type &factor)
 Adds factor times right to the referenced entry, in place.
 
template<typename RightTensor >
LIBMESH_DEVICE_INLINE void subtract (const RightTensor &right)
 Subtracts right from the referenced entry, in place.
 
template<typename RightTensor >
LIBMESH_DEVICE_INLINE void subtract_scaled (const RightTensor &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 RightTensor >
LIBMESH_DEVICE_INLINE auto contract (const RightTensor &right) const
 
LIBMESH_DEVICE_INLINE auto norm () const
 
LIBMESH_DEVICE_INLINE auto norm_sq () const
 
LIBMESH_DEVICE_INLINE bool is_zero () const
 
LIBMESH_DEVICE_INLINE auto transpose () const
 
LIBMESH_DEVICE_INLINE auto det (const unsigned int dim=LIBMESH_DIM) const
 
LIBMESH_DEVICE_INLINE auto tr () const
 
LIBMESH_DEVICE_INLINE auto inverse (const unsigned int dim=LIBMESH_DIM) const
 
template<typename VectorLike , typename ResultVector >
LIBMESH_DEVICE_INLINE void solve (const VectorLike &b, ResultVector &x) const
 Solves the linear system (*this)x = b for x, via the explicit inverse.
 
LIBMESH_DEVICE_INLINE auto row (const unsigned int i) const
 
LIBMESH_DEVICE_INLINE auto column (const unsigned int i) const
 
template<typename VectorLike >
LIBMESH_DEVICE_INLINE auto left_multiply (const VectorLike &v) const
 
LIBMESH_DEVICE_INLINE unsigned int index () const
 

Private Attributes

ViewType _view
 
unsigned int _index
 

Detailed Description

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

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

The tensor analogue of vector_ref: it pairs a view with an entry index, exposes the entry's components through operator()(row,col), and provides the TypeTensor-like arithmetic methods below (defined out-of-line in kokkos_tensor_ops.h). Component writes go directly to the underlying view.

Definition at line 340 of file kokkos_linalg_base.h.

Member Typedef Documentation

◆ value_type

template<typename ViewType >
using libMesh::Kokkos::tensor_ref< ViewType >::value_type = detail::tensor_view_value_t<ViewType>

Definition at line 345 of file kokkos_linalg_base.h.

◆ view_type

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

Definition at line 344 of file kokkos_linalg_base.h.

Constructor & Destructor Documentation

◆ tensor_ref()

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

Constructs a reference to entry index of view.

Definition at line 351 of file kokkos_linalg_base.h.

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

Member Function Documentation

◆ add()

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

Adds right to the referenced entry, in place.

Definition at line 623 of file kokkos_tensor_ops.h.

624{
625 libMesh::Kokkos::operator+=(*this, right);
626}
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 RightTensor >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::tensor_ref< ViewType >::add_scaled ( const RightTensor &  right,
const value_type &  factor 
)

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

Definition at line 631 of file kokkos_tensor_ops.h.

632{
633 detail::update_tensor_components(*this, right, factor);
634}
LIBMESH_DEVICE_INLINE void update_tensor_components(LeftTensor &left, const RightTensor &right, const Scalar &factor)
Componentwise axpy-style update: left += factor * right.

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

◆ assign()

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

Assigns right 's components to the referenced entry.

Definition at line 615 of file kokkos_tensor_ops.h.

616{
618}
LIBMESH_DEVICE_INLINE void assign_tensor_components(LeftTensor &left, const RightTensor &right)
Componentwise copy: left = right.

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

◆ column()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::column ( const unsigned int  i) const
Returns
Column i of the referenced entry, as an owning vector.

Definition at line 750 of file kokkos_tensor_ops.h.

751{
752 return libMesh::Kokkos::column(*this, i);
753}
LIBMESH_DEVICE_INLINE auto column(const TensorLike &T_in, const unsigned int i) -> std::enable_if_t< is_tensor_like_v< TensorLike >, std::conditional_t< std::is_void< ResultVector >::value, libMesh::TypeVector< typename TensorLike::value_type >, ResultVector > >

References libMesh::Kokkos::column().

◆ contract()

template<typename ViewType >
template<typename RightTensor >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::contract ( const RightTensor &  right) const
Returns
The full contraction (sum of componentwise products) of the referenced entry with right.

Definition at line 662 of file kokkos_tensor_ops.h.

663{
664 return libMesh::Kokkos::contract(*this, right);
665}
LIBMESH_DEVICE_INLINE auto contract(const LeftTensor &left, const RightTensor &right)

References libMesh::Kokkos::contract().

◆ det()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::det ( const unsigned int  dim = LIBMESH_DIM) const
Returns
The determinant of the leading dim x dim block of the referenced entry.

Definition at line 711 of file kokkos_tensor_ops.h.

712{
713 return detail::leading_determinant(*this, dim);
714}
unsigned int dim
LIBMESH_DEVICE_INLINE TensorLike::value_type leading_determinant(const TensorLike &T_in, const unsigned int dim=LIBMESH_DIM)

References dim, and libMesh::Kokkos::detail::leading_determinant().

◆ index()

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

Definition at line 499 of file kokkos_linalg_base.h.

500 {
501 return _index;
502 }

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

◆ inverse()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::inverse ( const unsigned int  dim = LIBMESH_DIM) const
Returns
The inverse of the leading dim x dim block of the referenced entry, as an owning tensor.

Definition at line 725 of file kokkos_tensor_ops.h.

726{
727 return libMesh::Kokkos::inverse(*this, dim);
728}
LIBMESH_DEVICE_INLINE auto inverse(const TensorLike &T_in, const unsigned int dim=LIBMESH_DIM) -> std::enable_if_t< is_tensor_like_v< TensorLike >, std::conditional_t< std::is_void< ResultTensor >::value, tensor_semantic_type_t< TensorLike >, ResultTensor > >

References dim, and libMesh::Kokkos::inverse().

◆ is_zero()

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

Definition at line 692 of file kokkos_tensor_ops.h.

693{
694 for (unsigned int row = 0; row < LIBMESH_DIM; ++row)
695 for (unsigned int col = 0; col < LIBMESH_DIM; ++col)
696 if ((*this)(row, col) != value_type(0))
697 return false;
698
699 return true;
700}
LIBMESH_DEVICE_INLINE auto row(const unsigned int i) const
detail::tensor_view_value_t< ViewType > value_type

References libMesh::Kokkos::row().

◆ left_multiply()

template<typename ViewType >
template<typename VectorLike >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::left_multiply ( const VectorLike &  v) const
Returns
The vector-tensor product v * (*this), as an owning vector.

Definition at line 758 of file kokkos_tensor_ops.h.

759{
760 return v * *this;
761}

◆ norm()

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

Definition at line 669 of file kokkos_tensor_ops.h.

670{
671 using std::sqrt;
672 return sqrt(this->norm_sq());
673}
LIBMESH_DEVICE_INLINE auto norm_sq() const

◆ norm_sq()

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

Definition at line 677 of file kokkos_tensor_ops.h.

678{
679 // TensorTools::norm_sq handles complex-valued components correctly.
680 using norm_type = detail::remove_cvref_t<decltype(libMesh::TensorTools::norm_sq((*this)(0, 0)))>;
681
682 norm_type sum = norm_type(0);
683 for (unsigned int row = 0; row < LIBMESH_DIM; ++row)
684 for (unsigned int col = 0; col < LIBMESH_DIM; ++col)
685 sum += libMesh::TensorTools::norm_sq((*this)(row, col));
686
687 return sum;
688}
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.
LIBMESH_DEVICE_INLINE auto norm_sq(const T &a)

References libMesh::TensorTools::norm_sq(), and libMesh::Kokkos::row().

◆ operator()() [1/2]

template<typename ViewType >
LIBMESH_DEVICE_INLINE decltype(auto) libMesh::Kokkos::tensor_ref< ViewType >::operator() ( const unsigned int  row,
const unsigned int  col 
)
inline

◆ operator()() [2/2]

template<typename ViewType >
LIBMESH_DEVICE_INLINE decltype(auto) libMesh::Kokkos::tensor_ref< ViewType >::operator() ( const unsigned int  row,
const unsigned int  col 
) const
inline
Returns
A reference to the (row, col) component of the referenced entry, writable under the same shallow-constness rules as vector_ref::operator().

Definition at line 359 of file kokkos_linalg_base.h.

360 {
361 return _view(_index, row, col);
362 }

References libMesh::Kokkos::tensor_ref< ViewType >::_index, libMesh::Kokkos::tensor_ref< ViewType >::_view, and libMesh::Kokkos::tensor_ref< ViewType >::row().

◆ row()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::row ( const unsigned int  i) const
Returns
Row i of the referenced entry, as an owning vector.

Definition at line 743 of file kokkos_tensor_ops.h.

744{
745 return libMesh::Kokkos::row(*this, i);
746}
LIBMESH_DEVICE_INLINE auto row(const TensorLike &T_in, const unsigned int i) -> std::enable_if_t< is_tensor_like_v< TensorLike >, std::conditional_t< std::is_void< ResultVector >::value, libMesh::TypeVector< typename TensorLike::value_type >, ResultVector > >

References libMesh::Kokkos::row().

Referenced by libMesh::Kokkos::tensor_ref< ViewType >::operator()(), and libMesh::Kokkos::tensor_ref< ViewType >::operator()().

◆ solve()

template<typename ViewType >
template<typename VectorLike , typename ResultVector >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::tensor_ref< ViewType >::solve ( const VectorLike &  b,
ResultVector &  x 
) const

Solves the linear system (*this)x = b for x, via the explicit inverse.

Definition at line 733 of file kokkos_tensor_ops.h.

734{
735 const auto solution =
736 detail::multiply_tensor_vector<vector_semantic_type_t<ResultVector>>(this->inverse(), b);
737 for (unsigned int component = 0; component < LIBMESH_DIM; ++component)
738 x(component) = solution(component);
739}
LIBMESH_DEVICE_INLINE auto inverse(const unsigned int dim=LIBMESH_DIM) const
static const Real b

References b, and libMesh::Kokkos::inverse().

◆ subtract()

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

Subtracts right from the referenced entry, in place.

Definition at line 639 of file kokkos_tensor_ops.h.

640{
641 libMesh::Kokkos::operator-=(*this, right);
642}
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 RightTensor >
LIBMESH_DEVICE_INLINE void libMesh::Kokkos::tensor_ref< ViewType >::subtract_scaled ( const RightTensor &  right,
const value_type &  factor 
)

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

Definition at line 647 of file kokkos_tensor_ops.h.

648{
649 detail::update_tensor_components(*this, right, -factor);
650}

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

◆ tr()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::tr ( ) const
Returns
The trace of the referenced entry.

Definition at line 718 of file kokkos_tensor_ops.h.

719{
720 return detail::tensor_trace(*this);
721}
LIBMESH_DEVICE_INLINE auto tensor_trace(const TensorLike &T_in)

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

◆ transpose()

template<typename ViewType >
LIBMESH_DEVICE_INLINE auto libMesh::Kokkos::tensor_ref< ViewType >::transpose ( ) const
Returns
The transpose of the referenced entry, as an owning tensor.

Definition at line 704 of file kokkos_tensor_ops.h.

705{
706 return libMesh::Kokkos::transpose(*this);
707}
LIBMESH_DEVICE_INLINE auto transpose(const TensorLike &T_in) -> std::enable_if_t< is_tensor_like_v< TensorLike >, std::conditional_t< std::is_void< ResultTensor >::value, tensor_semantic_type_t< TensorLike >, ResultTensor > >

References libMesh::Kokkos::transpose().

◆ zero()

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

Sets every component of the referenced entry to zero.

Definition at line 654 of file kokkos_tensor_ops.h.

655{
657}
LIBMESH_DEVICE_INLINE void fill_tensor_components(TensorLike &T_in, const Scalar &value)
Sets every component of T_in to value.

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

Member Data Documentation

◆ _index

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

◆ _view

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

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