version 0.4.1
Tensor Utilities

Collection of several utilities for dealing with Eigen tensors. More...

Collaboration diagram for Tensor Utilities:

Functions

template<typename Derived , typename T , auto rank>
Eigen::Tensor< typename Derived::Scalar, rank > Ikarus::tensorView (const Eigen::EigenBase< Derived > &matrix, const std::array< T, rank > &dims)
 View an Eigen matrix as an Eigen Tensor with specified dimensions. More...
 
auto Ikarus::dyadic (const auto &A_ij, const auto &B_kl)
 Computes the dyadic product of two Eigen tensors. More...
 
template<typename ScalarType = double, int dim = 3>
auto Ikarus::symmetricIdentityFourthOrder ()
 Generates a symmetric identity fourth-order tensor. More...
 
template<typename ScalarType = double, int dim = 3>
auto Ikarus::symmetricFourthOrder (const auto &A, const auto &B)
 Generates a symmetric fourth-order tensor based on two second-order input tensors. More...
 
template<typename ScalarType = double, int dim = 3>
auto Ikarus::identityFourthOrder ()
 Generates an identity fourth-order tensor. More...
 
template<typename AType , typename BType >
auto Ikarus::fourthOrderIKJL (const Eigen::MatrixBase< AType > &A, const Eigen::MatrixBase< BType > &B)
 Computes the IKJL product of two matrices. More...
 
template<typename ScalarType , long int dim>
auto Ikarus::symTwoSlots (const Eigen::TensorFixedSize< ScalarType, Eigen::Sizes< dim, dim, dim, dim > > &t, const std::array< size_t, 2 > &slots)
 Creates a symmetric fourth-order tensor in the two specified slots of the input tensor. More...
 
constexpr Eigen::Index Ikarus::toVoigt (Eigen::Index i, Eigen::Index j) noexcept
 Converts 2D indices to Voigt notation index. More...
 
template<typename ScalarType = double>
Eigen::Matrix< ScalarType, 6, 6 > Ikarus::toVoigt (const Eigen::TensorFixedSize< ScalarType, Eigen::Sizes< 3, 3, 3, 3 > > &ft)
 Converts a fourth-order tensor of fixed size 3x3x3x3 to a Voigt notation matrix of size 6x6. More...
 
template<typename ST , int size, int Options>
requires (size > 0 and size <= 3)
auto Ikarus::toVoigt (const Eigen::Matrix< ST, size, size, Options, size, size > &E, bool isStrain=true)
 Converts a square 2x2 or 3x3 matrix to a Voigt notation vector. More...
 
template<typename ST , int size>
requires (size == 1 or size == 3 or size == 6)
auto Ikarus::fromVoigt (const Eigen::Vector< ST, size > &EVoigt, bool isStrain=true)
 Converts a vector given in Voigt notation to a matrix. More...
 
constexpr std::array< size_t, 2 > Ikarus::fromVoigt (size_t i)
 Converts a Voigt notation index to matrix indices. More...
 
template<typename ScalarType >
auto Ikarus::fromVoigt (const Eigen::Matrix< ScalarType, 6, 6 > &CVoigt)
 Converts a matrix in Voigt notation to a Fourth-order tensor. More...
 

Detailed Description

Function Documentation

◆ dyadic()

auto Ikarus::dyadic ( const auto &  A_ij,
const auto &  B_kl 
)

The components of the result read

\[ \CI_{ijkl} = A_{ij}B_{kl}. \]

Parameters
A_ijFirst tensor.
B_klSecond tensor.
Returns
Resulting tensor after the dyadic product.
Here is the caller graph for this function:

◆ fourthOrderIKJL()

template<typename AType , typename BType >
auto Ikarus::fourthOrderIKJL ( const Eigen::MatrixBase< AType > &  A,
const Eigen::MatrixBase< BType > &  B 
)

The components of the result read

\[ \CI_{ijkl} = A_{ik}B_{jl}, \]

which simply swaps the inner slots jand k

Template Parameters
ATypeType of the first matrix.
BTypeType of the second matrix.
Parameters
AFirst matrix.
BSecond matrix.
Returns
Resulting tensor of the IKJL product.
Here is the caller graph for this function:

◆ fromVoigt() [1/3]

template<typename ScalarType >
auto Ikarus::fromVoigt ( const Eigen::Matrix< ScalarType, 6, 6 > &  CVoigt)
Template Parameters
ScalarTypeScalar type of the matrix elements.
Parameters
CVoigtVoigt notation matrix.
Returns
Fourth-order tensor corresponding to the matrix in Voigt notation.

This function converts a Voigt notation matrix to the corresponding 4th-order tensor. The function uses the fromVoigt function to map matrix indices to tensor indices. The resulting tensor is symmetric due to symmetry considerations.

◆ fromVoigt() [2/3]

template<typename ST , int size>
requires (size == 1 or size == 3 or size == 6)
auto Ikarus::fromVoigt ( const Eigen::Vector< ST, size > &  EVoigt,
bool  isStrain = true 
)
Template Parameters
STScalar type of the vector elements.
sizeSize of the Voigt notation vector.
Parameters
EVoigtVoigt notation vector.
isStrainFlag indicating whether the vector represents a strain (default is true).
Returns
Matrix corresponding to the vector in Voigt notation.

This function converts a vector given in Voigt notation to the corresponding matrix. The conversion depends on the size The parameter isStrain is used to determine the conversion factor for off-diagonal components, which need to be divided by 2 in the matrix representation if the quantity is a strain tensor.

The function requires that the size of the Voigt notation vector is valid (1, 3, or 6).

Here is the caller graph for this function:

◆ fromVoigt() [3/3]

constexpr std::array< size_t, 2 > Ikarus::fromVoigt ( size_t  i)
constexpr
Parameters
iVoigt notation index.
Returns
Matrix indices corresponding to the Voigt notation index.

This function converts a Voigt notation index to the corresponding matrix indices. The mapping is based on the assumption that the Voigt notation indices 0, 1, and 2 represent the diagonal components 00, 11, and 22, respectively. The remaining Voigt notation indices (3, 4, and 5) correspond to the off-diagonal components (12 and 21, 02 and 20, 01 and 10).

The function asserts that the input index is within the valid range for Voigt notation (0 to 5).

◆ identityFourthOrder()

template<typename ScalarType = double, int dim = 3>
auto Ikarus::identityFourthOrder ( )

The components of the result read

\[ \CI_{ijkl} = \de_{ij}\de_{kl}. \]

Template Parameters
ScalarTypeType of the elements in the tensor.
dimDimension of the tensor.
Returns
Identity fourth-order tensor.
Here is the caller graph for this function:

◆ symmetricFourthOrder()

template<typename ScalarType = double, int dim = 3>
auto Ikarus::symmetricFourthOrder ( const auto &  A,
const auto &  B 
)

The components of the result read

\[ \CI_{ijkl} = \frac{1}{2} \left(A_{ik}B_{jl}+A_{il}B_{jk} \right) . \]

Template Parameters
ScalarTypeType of the elements in the tensors.
dimDimension of the tensors.
Parameters
AFirst tensor.
BSecond tensor.
Returns
Symmetric fourth-order tensor.

◆ symmetricIdentityFourthOrder()

template<typename ScalarType = double, int dim = 3>
auto Ikarus::symmetricIdentityFourthOrder ( )
Template Parameters
ScalarTypeType of the elements in the tensor.
dimDimension of the tensor.
Returns
Symmetric identity fourth-order tensor.
Here is the caller graph for this function:

◆ symTwoSlots()

template<typename ScalarType , long int dim>
auto Ikarus::symTwoSlots ( const Eigen::TensorFixedSize< ScalarType, Eigen::Sizes< dim, dim, dim, dim > > &  t,
const std::array< size_t, 2 > &  slots 
)
Template Parameters
ScalarTypeType of the elements in the tensor.
Parameters
tInput tensor.
slotsIndices of the slots to be swapped.
Returns
Fourth-order Tensor which is symmetric in the given slots.
Here is the caller graph for this function:

◆ tensorView()

template<typename Derived , typename T , auto rank>
Eigen::Tensor< typename Derived::Scalar, rank > Ikarus::tensorView ( const Eigen::EigenBase< Derived > &  matrix,
const std::array< T, rank > &  dims 
)
Template Parameters
DerivedType of the input Eigen matrix.
TType of the elements in the matrix.
rankRank of the resulting Tensor.
Parameters
matrixInput Eigen matrix to be cast.
dimsDimensions of the resulting Tensor.
Returns
Eigen::Tensor<typename Derived::Scalar, rank> The casted Eigen Tensor.
Here is the caller graph for this function:

◆ toVoigt() [1/3]

template<typename ST , int size, int Options>
requires (size > 0 and size <= 3)
auto Ikarus::toVoigt ( const Eigen::Matrix< ST, size, size, Options, size, size > &  E,
bool  isStrain = true 
)
Template Parameters
STData type of the matrix elements.
sizeNumber of rows and columns of the square matrix.
OptionsEigen matrix options.
Parameters
EInput matrix of size (size x size).
isStrainFlag indicating whether the conversion is for strain (true) or not (false).
Returns
Vector with components in Voigt notation vector.

This function converts a square matrix to a Voigt notation vector, which contains the unique components of the input matrix. The mapping from the matrix indices to the Voigt notation indices is performed by the toVoigt function.

The optional isStrain parameter allows the user to specify whether the conversion is intended for strain calculations. If isStrain is true, the off-diagonal components are multiplied by 2, providing the correct Voigt notation for symmetric strain tensors.

◆ toVoigt() [2/3]

template<typename ScalarType = double>
Eigen::Matrix< ScalarType, 6, 6 > Ikarus::toVoigt ( const Eigen::TensorFixedSize< ScalarType, Eigen::Sizes< 3, 3, 3, 3 > > &  ft)
Template Parameters
ScalarTypeData type of the tensor elements.
Parameters
ftFourth-order tensor .
Returns
Voigt notation matrix.

This function converts a fourth-order tensor to a Voigt notation matrix, which is a symmetric 6x6 matrix containing the unique components of the input tensor. The mapping from the tensor indices to the Voigt notation indices is performed by the toVoigt function.

Remarks
The current implementation does not take advantage of this symmetry.

◆ toVoigt() [3/3]

constexpr Eigen::Index Ikarus::toVoigt ( Eigen::Index  i,
Eigen::Index  j 
)
constexprnoexcept
Parameters
iRow index.
jColumn index.
Returns
Eigen::Index Voigt notation index.

This function converts 2D indices (i, j) to a Voigt notation index. The Voigt notation is used to represent the six unique components of a symmetric 3x3 matrix in a one-dimensional array.

If the input indices are not within the valid range (0, 1, 2), an assertion failure is triggered.

Here is the caller graph for this function: