svMultiPhysics
Loading...
Searching...
No Matches
mat_fun Namespace Reference

The classes defined here duplicate the data structures in the Fortran MATFUN module defined in MATFUN.f. More...

Typedefs

template<int nsd>
using Matrix = Eigen::Matrix<double, nsd, nsd>
 A 2nd order tensor, nsd x nsd, fixed size and stack allocated. Used for the deformation gradient, stresses and similar quantities that have a known size at compile time.
template<int nsd>
using Tensor = Eigen::TensorFixedSize<double, Eigen::Sizes<nsd, nsd, nsd, nsd>>
 A 4th order tensor, nsd x nsd x nsd x nsd, fixed size and stack allocated. Used for the material elasticity tensor and other 4th order tensors that have a known size at compile time.
template<int nsd>
using NodalMatrix = Eigen::Matrix<double, nsd, Eigen::Dynamic, 0, nsd, consts::maxNoN>
 One nsd-vector per element node, so nsd x eNoN. Row count is fixed at compile time while column count is the element's node count, known only at run time, so it is bounded by consts::maxNoN to stay stack allocated. Used for shape function gradients and other per-node vector quantities.
using NodalVector = Eigen::Matrix<double, Eigen::Dynamic, 1, 0, consts::maxNoN, 1>
 One scalar per element node, so eNoN entries. Dynamic length bounded by consts::maxNoN to stay stack allocated, as for NodalMatrix. Used for shape function values and other per-node scalar quantities.

Functions

double mat_ddot (const Array< double > &A, const Array< double > &B, const int nd)
 Double dot product of 2 square matrices.
double mat_det (const Array< double > &A, const int nd)
Array< double > mat_dev (const Array< double > &A, const int nd)
Array< double > mat_dyad_prod (const Vector< double > &u, const Vector< double > &v, const int nd)
 Create a matrix from outer product of two vectors.
Array< double > mat_id (const int nd)
Array< double > mat_inv (const Array< double > &A, const int nd, bool debug)
 This function computes inverse of a square matrix.
Array< double > mat_inv_ge (const Array< double > &Ain, const int n, bool debug)
 This function computes inverse of a square matrix using Gauss Elimination method.
Array< double > mat_inv_ge_orig (const Array< double > &A, const int nd, bool debug)
 This function computes inverse of a square matrix using Gauss Elimination method.
Array< double > mat_inv_lp (const Array< double > &A, const int nd)
 This function computes inverse of a square matrix using Lapack functions (DGETRF + DGETRI).
Vector< double > mat_mul (const Array< double > &A, const Vector< double > &v)
 Multiply a matrix by a vector.
Array< double > mat_mul (const Array< double > &A, const Array< double > &B)
 Multiply a matrix by a matrix.
void mat_mul (const Array< double > &A, const Array< double > &B, Array< double > &result)
 Multiply a matrix by a matrix.
Array< double > mat_symm (const Array< double > &A, const int nd)
 Symmetric part of a matrix, S = (A + A.T)/2.
Array< double > mat_symm_prod (const Vector< double > &u, const Vector< double > &v, const int nd)
 Create a matrix from symmetric product of two vectors.
double mat_trace (const Array< double > &A, const int nd)
 Trace of second order matrix of rank nd.
Tensor4< double > ten_asym_prod12 (const Array< double > &A, const Array< double > &B, const int nd)
 Create a 4th order tensor from antisymmetric outer product of two matrices.
Tensor4< double > ten_ddot (const Tensor4< double > &A, const Tensor4< double > &B, const int nd)
 Double dot product of 2 4th order tensors T_ijkl = A_ijmn * B_klmn.
Tensor4< double > ten_ddot_2412 (const Tensor4< double > &A, const Tensor4< double > &B, const int nd)
 T_ijkl = A_imjn * B_mnkl.
Tensor4< double > ten_ddot_3424 (const Tensor4< double > &A, const Tensor4< double > &B, const int nd)
void ten_init (const int nd)
 Initialize tensor index pointer.
Tensor4< double > ten_dyad_prod (const Array< double > &A, const Array< double > &B, const int nd)
 Create a 4th order tensor from outer product of two matrices.
Tensor4< double > ten_ids (const int nd)
 Create a 4th order order symmetric identity tensor.
Array< double > ten_mddot (const Tensor4< double > &A, const Array< double > &B, const int nd)
 Double dot product of a 4th order tensor and a 2nd order tensor.
Tensor4< double > ten_symm_prod (const Array< double > &A, const Array< double > &B, const int nd)
 Create a 4th order tensor from symmetric outer product of two matrices.
Tensor4< double > ten_transpose (const Tensor4< double > &A, const int nd)
Array< double > transpose (const Array< double > &A)
 Reproduces Fortran TRANSPOSE.
template<int rows>
Eigen::Map< const Eigen::Matrix< double, rows, Eigen::Dynamic > > eigen_view (const Array< double > &A)
 Read-only Eigen view of an Array, sharing its storage.
Eigen::Map< const Eigen::MatrixXd > eigen_view (const Array< double > &A)
 Read-only Eigen view of a whole Array, sharing its storage.
template<int rows>
Eigen::Map< const Eigen::Matrix< double, rows, Eigen::Dynamic >, 0, Eigen::OuterStride<> > eigen_view_rows (const Array< double > &A, const int first)
 Read-only Eigen view of a band of rows of an Array, sharing its storage.
Eigen::Map< Eigen::MatrixXd > eigen_view_mutable (Array< double > &A)
 Writable Eigen view of a whole Array, sharing its storage.
Eigen::Map< const Eigen::VectorXd > eigen_view (const Vector< double > &v)
 Read-only Eigen view of a whole Vector, sharing its storage.
template<int rows>
Eigen::Map< const Eigen::Matrix< double, rows, 1 > > eigen_view (const Vector< double > &v)
 Read-only Eigen view of a Vector, sharing its storage.
template<typename MatrixType>
MatrixType convert_to_eigen_matrix (const Array< double > &src)
template<typename MatrixType>
void convert_to_array (const MatrixType &mat, Array< double > &dest)
template<typename MatrixType>
void copy_Dm (const MatrixType &mat, Array< double > &dest)
template<int nsd>
Eigen::Matrix< double, nsd, 1 > cross_product (const Eigen::Matrix< double, nsd, 1 > &u, const Eigen::Matrix< double, nsd, 1 > &v)
template<int nsd>
double double_dot_product (const Matrix< nsd > &A, const Matrix< nsd > &B)
template<int M, int K, int N>
void mat_mul (const Array< double > &A, const Array< double > &B, Array< double > &C)
 Matrix product with the operand shape supplied at compile time.
template<int M, int K>
void mat_mul (const Array< double > &A, const Array< double > &B, Array< double > &C)
 As above, but with the column count known only at run time.
template<int nsd>
Tensor< nsd > double_dot_product (const Tensor< nsd > &A, const std::array< int, 2 > &dimsA, const Tensor< nsd > &B, const std::array< int, 2 > &dimsB)
 Contracts two 4th order tensors A and B over two dimensions.
template<int nsd>
Tensor< nsd > dyadic_product (const Matrix< nsd > &A, const Matrix< nsd > &B)
 Compute the dyadic product of two 2nd order tensors A and B, C_ijkl = A_ij * B_kl.
template<int nsd>
Tensor< nsd > fourth_order_identity ()
 Create a 4th order identity tensor: I_ijkl = 0.5 * (δ_ik * δ_jl + δ_il * δ_jk).
template<int nsd>
Tensor< nsd > symmetric_dyadic_product (const Matrix< nsd > &A, const Matrix< nsd > &B)
 Create a 4th order tensor from symmetric outer product of two matrices: C_ijkl = 0.5 * (A_ik * B_jl + A_il * B_jk).
template<int nsd>
Tensor< nsd > transpose (const Tensor< nsd > &A)
 Performs a tensor transpose operation on a 4th order tensor A, B_ijkl = A_klij.

Variables

Array< int > t_ind

Detailed Description

The classes defined here duplicate the data structures in the Fortran MATFUN module defined in MATFUN.f.

This module defines data structures for generally performed matrix and tensor operations.

Todo
[TODO:DaveP] this should just be a namespace?

Typedef Documentation

◆ Matrix

template<int nsd>
using mat_fun::Matrix = Eigen::Matrix<double, nsd, nsd>

A 2nd order tensor, nsd x nsd, fixed size and stack allocated. Used for the deformation gradient, stresses and similar quantities that have a known size at compile time.

◆ NodalMatrix

template<int nsd>
using mat_fun::NodalMatrix = Eigen::Matrix<double, nsd, Eigen::Dynamic, 0, nsd, consts::maxNoN>

One nsd-vector per element node, so nsd x eNoN. Row count is fixed at compile time while column count is the element's node count, known only at run time, so it is bounded by consts::maxNoN to stay stack allocated. Used for shape function gradients and other per-node vector quantities.

◆ NodalVector

using mat_fun::NodalVector = Eigen::Matrix<double, Eigen::Dynamic, 1, 0, consts::maxNoN, 1>

One scalar per element node, so eNoN entries. Dynamic length bounded by consts::maxNoN to stay stack allocated, as for NodalMatrix. Used for shape function values and other per-node scalar quantities.

◆ Tensor

template<int nsd>
using mat_fun::Tensor = Eigen::TensorFixedSize<double, Eigen::Sizes<nsd, nsd, nsd, nsd>>

A 4th order tensor, nsd x nsd x nsd x nsd, fixed size and stack allocated. Used for the material elasticity tensor and other 4th order tensors that have a known size at compile time.

Function Documentation

◆ double_dot_product()

template<int nsd>
Tensor< nsd > mat_fun::double_dot_product ( const Tensor< nsd > & A,
const std::array< int, 2 > & dimsA,
const Tensor< nsd > & B,
const std::array< int, 2 > & dimsB )

Contracts two 4th order tensors A and B over two dimensions.

For example, if dimsA = {0, 1} and dimsB = {2, 3} this is C_klmn = A_ijkl B_mnij (sum over i, j)

Template Parameters
nsdNumber of spatial dimensions; each tensor is nsd^4.
Parameters
[in]A,BFourth order tensors to contract.
[in]dimsA,dimsBIndices of the contracted dimensions of A and B.
Returns
The contracted tensor.

◆ dyadic_product()

template<int nsd>
Tensor< nsd > mat_fun::dyadic_product ( const Matrix< nsd > & A,
const Matrix< nsd > & B )

Compute the dyadic product of two 2nd order tensors A and B, C_ijkl = A_ij * B_kl.

Template Parameters
nsd,thenumber of spatial dimensions
Parameters
A,thefirst 2nd order tensor
B,thesecond 2nd order tensor
Returns
Tensor<nsd>

◆ eigen_view() [1/4]

Eigen::Map< const Eigen::MatrixXd > mat_fun::eigen_view ( const Array< double > & A)
inline

Read-only Eigen view of a whole Array, sharing its storage.

◆ eigen_view() [2/4]

template<int rows>
Eigen::Map< const Eigen::Matrix< double, rows, Eigen::Dynamic > > mat_fun::eigen_view ( const Array< double > & A)

Read-only Eigen view of an Array, sharing its storage.

Template Parameters
rowsRow count, fixed at compile time; the columns are taken from the Array.

◆ eigen_view() [3/4]

template<int rows>
Eigen::Map< const Eigen::Matrix< double, rows, 1 > > mat_fun::eigen_view ( const Vector< double > & v)

Read-only Eigen view of a Vector, sharing its storage.

Template Parameters
rowsEntry count, fixed at compile time.

◆ eigen_view() [4/4]

Eigen::Map< const Eigen::VectorXd > mat_fun::eigen_view ( const Vector< double > & v)
inline

Read-only Eigen view of a whole Vector, sharing its storage.

◆ eigen_view_mutable()

Eigen::Map< Eigen::MatrixXd > mat_fun::eigen_view_mutable ( Array< double > & A)
inline

Writable Eigen view of a whole Array, sharing its storage.

◆ eigen_view_rows()

template<int rows>
Eigen::Map< const Eigen::Matrix< double, rows, Eigen::Dynamic >, 0, Eigen::OuterStride<> > mat_fun::eigen_view_rows ( const Array< double > & A,
const int first )

Read-only Eigen view of a band of rows of an Array, sharing its storage.

Used where an Array contains several fields and only a contiguous band is viewed. For example,

A = [ A00, A01, A02 ;         eigen_view_rows<2>(A, 1) = [ A10, A11, A12 ;
      A10, A11, A12 ;                                      A20, A21, A22 ]
      A20, A21, A22 ;
      A30, A31, A32 ]
Parameters
AThe Array to view.
firstIndex of the band's first row within the Array.
Template Parameters
rowsNumber of rows, fixed at compile time, typically nsd.

◆ fourth_order_identity()

template<int nsd>
Tensor< nsd > mat_fun::fourth_order_identity ( )

Create a 4th order identity tensor: I_ijkl = 0.5 * (δ_ik * δ_jl + δ_il * δ_jk).

Template Parameters
nsd,thenumber of spatial dimensions
Returns
Tensor<nsd>

◆ mat_ddot()

double mat_fun::mat_ddot ( const Array< double > & A,
const Array< double > & B,
const int nd )

Double dot product of 2 square matrices.

◆ mat_dyad_prod()

Array< double > mat_fun::mat_dyad_prod ( const Vector< double > & u,
const Vector< double > & v,
const int nd )

Create a matrix from outer product of two vectors.

◆ mat_inv()

Array< double > mat_fun::mat_inv ( const Array< double > & A,
const int nd,
bool debug )

This function computes inverse of a square matrix.

◆ mat_inv_ge()

Array< double > mat_fun::mat_inv_ge ( const Array< double > & Ain,
const int n,
bool debug )

This function computes inverse of a square matrix using Gauss Elimination method.

◆ mat_inv_ge_orig()

Array< double > mat_fun::mat_inv_ge_orig ( const Array< double > & A,
const int nd,
bool debug )

This function computes inverse of a square matrix using Gauss Elimination method.

Todo
[TODO:DaveP] The original version sometimes produced NaNs.

◆ mat_inv_lp()

Array< double > mat_fun::mat_inv_lp ( const Array< double > & A,
const int nd )

This function computes inverse of a square matrix using Lapack functions (DGETRF + DGETRI).

Replaces 'FUNCTION MAT_INV_LP(A, nd) RESULT(Ainv)' defined in MATFUN.f.

◆ mat_mul() [1/5]

Array< double > mat_fun::mat_mul ( const Array< double > & A,
const Array< double > & B )

Multiply a matrix by a matrix.

Multiply two matrices, returning A*B.

Allocates the result and hands it to the in-place overload, so the two share one implementation and both reach the fixed-shape paths.

Parameters
[in]Aleft operand.
[in]Bright operand, with as many rows as A has columns.
Returns
the product, of size rows(A) by cols(B).

Throws InvalidArgumentException if the sizes are incompatible. The result is freshly allocated, so the operands may alias it, as in A = mat_mul(A, B).

◆ mat_mul() [2/5]

template<int M, int K>
void mat_fun::mat_mul ( const Array< double > & A,
const Array< double > & B,
Array< double > & C )

As above, but with the column count known only at run time.

For operands with one column per element node, where the width depends on the element type. The row counts are still compile-time, which is where most of the benefit comes from.

◆ mat_mul() [3/5]

template<int M, int K, int N>
void mat_fun::mat_mul ( const Array< double > & A,
const Array< double > & B,
Array< double > & C )

Matrix product with the operand shape supplied at compile time.

Overloads of mat_mul rather than differently named helpers, so a call site states the shape and otherwise reads exactly as before:

mat_mul(Dm, Bm.rslice(b), DBm); // runtime shape check
mat_mul<6, 6, 3>(Dm, Bm.rslice(b), DBm); // no check, same arguments
Vector< double > mat_mul(const Array< double > &A, const Vector< double > &v)
Multiply a matrix by a vector.
Definition mat_fun.cpp:433

The generic mat_mul overload above will dispatch to this overload when the shapes are known at compile time.

Template Parameters
Mrows of A and of the result
Kcolumns of A and rows of B, the contracted dimension
Ncolumns of B and of the result

◆ mat_mul() [4/5]

void mat_fun::mat_mul ( const Array< double > & A,
const Array< double > & B,
Array< double > & result )

Multiply a matrix by a matrix.

Multiply two matrices, writing A*B into an existing result.

Dispatches the shapes that dominate the element loops to fixed-size Eigen products, and falls back to a general triple loop otherwise.

Parameters
[in]Aleft operand.
[in]Bright operand, with as many rows as A has columns.
[out]resultthe product. The caller sizes it rows(A) by cols(B).

Throws InvalidArgumentException if the sizes are incompatible. Preferred in loops, where it reuses the caller's storage instead of allocating a result on every call. The result must not alias A or B.

◆ mat_mul() [5/5]

Vector< double > mat_fun::mat_mul ( const Array< double > & A,
const Vector< double > & v )

Multiply a matrix by a vector.

Multiply a matrix by a vector, returning A*v.

Parameters
[in]Amatrix with as many columns as v has entries.
[in]vvector.
Returns
the product, of size rows(A).

Throws InvalidArgumentException if the sizes are incompatible.

◆ mat_symm()

Array< double > mat_fun::mat_symm ( const Array< double > & A,
const int nd )

Symmetric part of a matrix, S = (A + A.T)/2.

◆ mat_symm_prod()

Array< double > mat_fun::mat_symm_prod ( const Vector< double > & u,
const Vector< double > & v,
const int nd )

Create a matrix from symmetric product of two vectors.

◆ mat_trace()

double mat_fun::mat_trace ( const Array< double > & A,
const int nd )

Trace of second order matrix of rank nd.

◆ symmetric_dyadic_product()

template<int nsd>
Tensor< nsd > mat_fun::symmetric_dyadic_product ( const Matrix< nsd > & A,
const Matrix< nsd > & B )

Create a 4th order tensor from symmetric outer product of two matrices: C_ijkl = 0.5 * (A_ik * B_jl + A_il * B_jk).

Template Parameters
nsdNumber of spatial dimensions.
Parameters
[in]A,BSecond order tensors.
Returns
The resulting 4th order tensor.

◆ ten_asym_prod12()

Tensor4< double > mat_fun::ten_asym_prod12 ( const Array< double > & A,
const Array< double > & B,
const int nd )

Create a 4th order tensor from antisymmetric outer product of two matrices.

Cijkl = Aij*Bkl-Ail*Bjk

◆ ten_ddot()

Tensor4< double > mat_fun::ten_ddot ( const Tensor4< double > & A,
const Tensor4< double > & B,
const int nd )

Double dot product of 2 4th order tensors T_ijkl = A_ijmn * B_klmn.

Reproduces 'FUNCTION TEN_DDOT_3434(A, B, nd) RESULT(C)'.

◆ ten_ddot_2412()

Tensor4< double > mat_fun::ten_ddot_2412 ( const Tensor4< double > & A,
const Tensor4< double > & B,
const int nd )

T_ijkl = A_imjn * B_mnkl.

◆ ten_dyad_prod()

Tensor4< double > mat_fun::ten_dyad_prod ( const Array< double > & A,
const Array< double > & B,
const int nd )

Create a 4th order tensor from outer product of two matrices.

◆ ten_ids()

Tensor4< double > mat_fun::ten_ids ( const int nd)

Create a 4th order order symmetric identity tensor.

◆ ten_init()

void mat_fun::ten_init ( const int nd)

Initialize tensor index pointer.

◆ ten_mddot()

Array< double > mat_fun::ten_mddot ( const Tensor4< double > & A,
const Array< double > & B,
const int nd )

Double dot product of a 4th order tensor and a 2nd order tensor.

C_ij = (A_ijkl * B_kl)

◆ ten_symm_prod()

Tensor4< double > mat_fun::ten_symm_prod ( const Array< double > & A,
const Array< double > & B,
const int nd )

Create a 4th order tensor from symmetric outer product of two matrices.

Reproduces 'FUNCTION TEN_SYMMPROD(A, B, nd) RESULT(C)'.

◆ transpose() [1/2]

Array< double > mat_fun::transpose ( const Array< double > & A)

Reproduces Fortran TRANSPOSE.

◆ transpose() [2/2]

template<int nsd>
Tensor< nsd > mat_fun::transpose ( const Tensor< nsd > & A)

Performs a tensor transpose operation on a 4th order tensor A, B_ijkl = A_klij.

Template Parameters
nsd,thenumber of spatial dimensions
Parameters
A,theinput 4th order tensor
Returns
Tensor<nsd>