#include <symtensor/SymmetricTensor.h>
template<typename S, std::size_t D, std::size_t R, typename I = Index<D>>
SymmetricTensor class
Generic symmetric tensor type.
Template parameters | |
---|---|
S | scalar type |
D | number of dimensions (2d, 3d, etc.) |
R | rank |
I | index type, defaults to the appropriate symtensor:: |
Base classes
-
template<class Implementation, typename S, std::size_t D, std::size_t R, typename I = Index<D>>class SymmetricTensorBase<SymmetricTensor<S, D, R, Index<D>>, S, D, R, Index<D>>
- Symmetric tensor base-type for use with CRTP implementations.
Public types
- using Self = SymmetricTensorBase<SymmetricTensor<S, D, R, Index<D>>, S, D, R, Index<D>>
- using Scalar = S
- using Index = Index<D>
Public static variables
- static std::size_t Dimensions constexpr
- static std::size_t Rank constexpr
- static std::size_t NumValues constexpr
- static std::size_t NumUniqueValues constexpr
Public variables
- std::array<S, NumUniqueValues> _data
Other Tensor-tensor operations
- requires requires
Constructors
- static auto Identity() -> SymmetricTensor<S, D, R, Index<D>> consteval
- Identity matrix constructor.
- static auto Ones() -> SymmetricTensor<S, D, R, Index<D>> consteval
- Unit matrix constructor.
- static auto Zeros() -> SymmetricTensor<S, D, R, Index<D>> consteval
- Zero matrix constructor.
- static auto NullaryExpression(F function = {}) -> ALWAYS_INLINE SymmetricTensor<S, D, R, Index<D>> constexpr
- Generic constructor from an expression.
- static auto CartesianPower(const Vector& vector) -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Constructor by repeated cartesian product.
- static auto Diagonal(const Vector& vector) -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Constructor with a set vector as the diagonal.
- static auto ConstantDiagonal(const T& value) -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Constructor with a set constant value along the diagonal.
Member access
- auto operator[](const std::array<Index, R>& indices) const -> const Scalar& constexpr
- Indexed member access.
- auto at() const -> const Scalar& constexpr
- Compile-time indexed member access.
- auto at() -> Scalar& constexpr
- Compile-time indexed member access.
- auto flat() const -> const auto& constexpr
- Direct access to underlying data structure.
- auto flat() -> auto& constexpr
- Direct access to underlying data structure.
Tensor properties
Tensor-scalar operators
- auto operator+=(const Scalar& scalar) -> SymmetricTensor<S, D, R, Index<D>>& constexpr
- Element-wise addition of a scalar.
- auto operator-=(const Scalar& scalar) -> SymmetricTensor<S, D, R, Index<D>>& constexpr
- Element-wise subtraction of a scalar.
- auto operator*=(const Scalar& scalar) -> SymmetricTensor<S, D, R, Index<D>>& constexpr
- Element-wise multiplication by a scalar.
- auto operator/=(const Scalar& scalar) -> SymmetricTensor<S, D, R, Index<D>>& constexpr
- Element-wise division by a scalar.
- auto operator+(const Scalar& scalar) const -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Element-wise addition of a scalar.
- auto operator-(const Scalar& scalar) const -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Element-wise subtraction of a scalar.
- auto operator*(const Scalar& scalar) const -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Element-wise multiplication by a scalar.
- auto operator/(const Scalar& scalar) const -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Element-wise division by a scalar.
Tensor-tensor element-wise operations
- auto operator+=(const SymmetricTensor<S, D, R, Index<D>>& other) -> SymmetricTensor<S, D, R, Index<D>>& constexpr
- Element-wise addition with another tensor.
- auto operator-=(const SymmetricTensor<S, D, R, Index<D>>& other) -> SymmetricTensor<S, D, R, Index<D>>& constexpr
- Element-wise subtraction by another tensor.
- auto operator+(const SymmetricTensor<S, D, R, Index<D>>& other) const -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Element-wise addition with another tensor.
- auto operator-(const SymmetricTensor<S, D, R, Index<D>>& other) const -> SymmetricTensor<S, D, R, Index<D>> constexpr
- Element-wise subtraction by another tensor.
Comparison operations
- auto operator==(const Self& other) const -> bool defaulted constexpr
- Comparison with another symmetric tensor.
Typedef documentation
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
using symtensor:: SymmetricTensor<S, D, R, I>:: Self = SymmetricTensorBase<SymmetricTensor<S, D, R, Index<D>>, S, D, R, Index<D>>
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
using symtensor:: SymmetricTensor<S, D, R, I>:: Scalar = S
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
using symtensor:: SymmetricTensor<S, D, R, I>:: Index = Index<D>
Function documentation
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: Identity() consteval
Identity matrix constructor.
Returns | a symmetric tensor with a value of 1 along the diagonal, 0 elsewhere. |
---|
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: Ones() consteval
Unit matrix constructor.
Returns | a symmetric tensor with a value of 1 at every index. |
---|
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: Zeros() consteval
Zero matrix constructor.
Returns | a symmetric tensor with a value of 0 at every index. |
---|
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static ALWAYS_INLINE SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: NullaryExpression(F function = {}) constexpr
Generic constructor from an expression.
Parameters | |
---|---|
function | a functor which returns a scalar type given an index |
Returns | a symmetric tensor with each value set by evaluating the function. |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: CartesianPower(const Vector& vector) constexpr
Constructor by repeated cartesian product.
Parameters | |
---|---|
vector | vector which will be multiplied with itself |
Returns | a symmetric tensor produced by the repeated outer product of vector. |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: Diagonal(const Vector& vector) constexpr
Constructor with a set vector as the diagonal.
Parameters | |
---|---|
vector | vector which will define the diagonal of the tensor |
Returns | a symmetric tensor with diagonal equal to vector, zero elsewhere. |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
static SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: ConstantDiagonal(const T& value) constexpr
Constructor with a set constant value along the diagonal.
Parameters | |
---|---|
value | the value to be placed along the diagonal of the tensor |
Returns | a symmetric tensor with elements of the diagonal diagonal equal to value, zero elsewhere. |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
const Scalar& symtensor:: SymmetricTensor<S, D, R, I>:: operator[](const std::array<Index, R>& indices) const constexpr
Indexed member access.
Parameters | |
---|---|
indices | Array of R Index values which specify an element of the tensor. Indices may be in arbitrary order, because the tensor is symmetric. |
Returns | the scalar element at the requested index |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
const Scalar& symtensor:: SymmetricTensor<S, D, R, I>:: at() const constexpr
Compile-time indexed member access.
Returns | the scalar element at the requested index |
---|
The index sequence is converted to a flat index at compile-time, allowing for performance equivalent to hand-written member access. mytensor.at<X, X, X>()
should be equivalent to mytensor.flat()[0]
.
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
Scalar& symtensor:: SymmetricTensor<S, D, R, I>:: at() constexpr
Compile-time indexed member access.
Returns | the scalar element at the requested index |
---|
The index sequence is converted to a flat index at compile-time, allowing for performance equivalent to hand-written member access. mytensor.at<X, X, X>()
should be equivalent to mytensor.flat()[0]
.
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
const auto& symtensor:: SymmetricTensor<S, D, R, I>:: flat() const constexpr
Direct access to underlying data structure.
Returns | a reference to the underlying flat storage. |
---|
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
auto& symtensor:: SymmetricTensor<S, D, R, I>:: flat() constexpr
Direct access to underlying data structure.
Returns | a reference to the underlying flat storage. |
---|
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
Scalar symtensor:: SymmetricTensor<S, D, R, I>:: trace() const constexpr
Computes the trace of the tensor.
Returns | the sum of the scalar values at the diagonal positions of the tensor |
---|
This is equivalent to the sum of the diagonal elements.
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
auto symtensor:: SymmetricTensor<S, D, R, I>:: diagonal() const constexpr
Produces the diagonal of the tensor.
Returns | A vector containing the elements along the diagonal of the tensor. |
---|
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
auto symtensor:: SymmetricTensor<S, D, R, I>:: norm2() const constexpr
Returns | Norm2 of the tensor, with the same type as the tensor's elements. |
---|
The squared Frobenius norm of the tensor.
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
auto symtensor:: SymmetricTensor<S, D, R, I>:: norm() const constexpr
Returns | Norm of the tensor, with the same type as the tensor's elements. |
---|
The Frobenius norm of the tensor.
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>>& symtensor:: SymmetricTensor<S, D, R, I>:: operator+=(const Scalar& scalar) constexpr
Element-wise addition of a scalar.
Parameters | |
---|---|
scalar | value to add to each element of the tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>>& symtensor:: SymmetricTensor<S, D, R, I>:: operator-=(const Scalar& scalar) constexpr
Element-wise subtraction of a scalar.
Parameters | |
---|---|
scalar | value to subtract from each element of the tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>>& symtensor:: SymmetricTensor<S, D, R, I>:: operator*=(const Scalar& scalar) constexpr
Element-wise multiplication by a scalar.
Parameters | |
---|---|
scalar | value to multiply each element of the tensor by. |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>>& symtensor:: SymmetricTensor<S, D, R, I>:: operator/=(const Scalar& scalar) constexpr
Element-wise division by a scalar.
Parameters | |
---|---|
scalar | value to divide each element of the tensor by. |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: operator+(const Scalar& scalar) const constexpr
Element-wise addition of a scalar.
Parameters | |
---|---|
scalar | value to add to each element of the tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: operator-(const Scalar& scalar) const constexpr
Element-wise subtraction of a scalar.
Parameters | |
---|---|
scalar | value to subtract from each element of the tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: operator*(const Scalar& scalar) const constexpr
Element-wise multiplication by a scalar.
Parameters | |
---|---|
scalar | value to multiply each element of the tensor by. |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: operator/(const Scalar& scalar) const constexpr
Element-wise division by a scalar.
Parameters | |
---|---|
scalar | value to divide each element of the tensor by. |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>>& symtensor:: SymmetricTensor<S, D, R, I>:: operator+=(const SymmetricTensor<S, D, R, Index<D>>& other) constexpr
Element-wise addition with another tensor.
Parameters | |
---|---|
other | tensor to add with this tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>>& symtensor:: SymmetricTensor<S, D, R, I>:: operator-=(const SymmetricTensor<S, D, R, Index<D>>& other) constexpr
Element-wise subtraction by another tensor.
Parameters | |
---|---|
other | tensor to subtract from this tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: operator+(const SymmetricTensor<S, D, R, Index<D>>& other) const constexpr
Element-wise addition with another tensor.
Parameters | |
---|---|
other | tensor to add with this tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
SymmetricTensor<S, D, R, Index<D>> symtensor:: SymmetricTensor<S, D, R, I>:: operator-(const SymmetricTensor<S, D, R, Index<D>>& other) const constexpr
Element-wise subtraction by another tensor.
Parameters | |
---|---|
other | tensor to subtract from this tensor |
Returns | the modified tensor |
#include <symtensor/SymmetricTensorBase.h>
template<typename S, std::size_t D, std::size_t R, typename I>
bool symtensor:: SymmetricTensor<S, D, R, I>:: operator==(const Self& other) const defaulted constexpr
Comparison with another symmetric tensor.
Parameters | |
---|---|
other | symmetric tensor to compare with |
Returns | true if all elements of the tensors are equivalent, false otherwise |