17#include "libmesh/type_tensor.h"
18#include "libmesh/dense_vector.h"
20#include "metaphysicl/raw_type.h"
59 const TypeVector<T> & col2,
60 const TypeVector<T> & col3);
72 void reshape(
const unsigned int rows,
const unsigned int cols);
78 T &
operator()(
const unsigned int i,
const unsigned int j = 0);
86 T
operator()(
const unsigned int i,
const unsigned int j = 0)
const;
101 void fill(TypeTensor<T> & tensor);
106 void fill(DenseMatrix<T> & rhs);
111 void fill(DenseVector<T> & rhs);
169 unsigned int n()
const;
174 unsigned int m()
const;
232 template <
typename T2>
332 template <
typename T2>
334 template <
typename T2>
349 if (cols * rows == _n_entries)
358 _n_entries = _n_rows * _n_cols;
359 _values.resize(_n_entries);
367 if ((i * j) >= _n_entries)
368 mooseError(
"Reference outside of ColumnMajorMatrix bounds!");
371 return _values[(j * _n_rows) + i];
378 if ((i * j) >= _n_entries)
379 mooseError(
"Reference outside of ColumnMajorMatrix bounds!");
382 return _values[(j * _n_rows) + i];
391 for (
unsigned int i = 0; i < _n_rows; i++)
393 for (
unsigned int j = 0; j < _n_cols; j++)
394 Moose::out << std::setw(15) << s(i, j) <<
" ";
396 Moose::out << std::endl;
406 for (
unsigned int i = 0; i < _n_rows; i++)
408 for (
unsigned int j = 0; j < _n_cols; j++)
409 os << std::setw(15) << std::scientific << std::setprecision(8) << s(i, j) <<
" ";
421 "Cannot fill tensor! The ColumnMajorMatrix doesn't have the same number of entries!");
432 if (rhs.n() * rhs.m() != _n_entries)
434 "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
436 for (
unsigned int j = 0, index = 0; j < rhs.m(); ++j)
437 for (
unsigned int i = 0; i < rhs.n(); ++i, ++index)
438 rhs(i, j) = _values[index];
445 if (_n_rows != rhs.size() || _n_cols != 1)
446 mooseError(
"ColumnMajorMatrix and DenseVector must be the same shape for a fill!");
448 for (
unsigned int i = 0; i < _n_rows; ++i)
460 for (
unsigned int i = 0; i < _n_rows; i++)
461 for (
unsigned int j = 0; j < _n_cols; j++)
462 ret_matrix(j, i) = s(i, j);
477 for (
unsigned int i = 0; i < _n_rows; i++)
478 for (
unsigned int j = 0; j < _n_cols; j++)
479 ret_matrix(i, j) = s(i, j) - I(i, j) * (s.
tr() / 3.0);
488 this->checkSquareness();
490 for (
unsigned int i = 0; i < _n_rows; i++)
491 (*
this)(i, i) = value;
498 this->checkSquareness();
500 for (
unsigned int i = 0; i < _n_rows; i++)
501 (*
this)(i, i) += value;
508 this->checkSquareness();
512 for (
unsigned int i = 0; i < _n_rows; i++)
513 trace += (*
this)(i, i);
522 for (
unsigned int i = 0; i < _n_entries; i++)
530 this->checkSquareness();
534 for (
unsigned int i = 0; i < _n_rows; i++)
542 this->checkShapeEquality(rhs);
546 for (
unsigned int j = 0; j < _n_cols; j++)
547 for (
unsigned int i = 0; i < _n_rows; i++)
548 value += (*
this)(i, j) * rhs(i, j);
589 _values.resize(_n_entries);
598 for (
unsigned int j = 0; j < _n_cols; j++)
599 for (
unsigned int i = 0; i < _n_cols; i++)
606template <
typename T2>
610 this->reshape(rhs.
m(), rhs.
n());
612 for (MooseIndex(rhs.
m()) i = 0; i < rhs.
m(); ++i)
613 for (MooseIndex(rhs.
n()) j = 0; j < rhs.
n(); ++j)
614 (*
this)(i, j) = rhs(i, j);
625 for (
unsigned int i = 0; i < _n_entries; i++)
626 ret_matrix.
_values[i] = _values[i] * scalar;
636 mooseError(
"Cannot perform matvec operation! The column dimension of "
637 "the ColumnMajorMatrix does not match the TypeVector!");
641 for (
unsigned int i = 0; i < _n_rows; ++i)
642 for (
unsigned int j = 0; j < _n_cols; ++j)
643 ret_matrix.
_values[i] += (*
this)(i, j) * rhs(j);
671 "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
675 for (
unsigned int i = 0; i < ret_matrix.
_n_rows; ++i)
676 for (
unsigned int j = 0; j < ret_matrix.
_n_cols; ++j)
677 for (
unsigned int k = 0; k < _n_cols; ++k)
678 ret_matrix(i, j) += (*this)(i, k) * rhs(k, j);
687 this->checkShapeEquality(rhs);
691 for (
unsigned int i = 0; i < _n_entries; i++)
701 this->checkShapeEquality(rhs);
705 for (
unsigned int i = 0; i < _n_entries; i++)
715 this->checkShapeEquality(rhs);
717 for (
unsigned int i = 0; i < _n_entries; i++)
728 mooseError(
"Cannot perform matrix addition and assignment! The shapes of the two operands are "
733 (*
this)(i, j) += rhs(i, j);
742 this->checkShapeEquality(rhs);
744 for (
unsigned int i = 0; i < _n_entries; i++)
756 for (
unsigned int i = 0; i < _n_entries; i++)
757 ret_matrix.
_values[i] = _values[i] + scalar;
766 for (
unsigned int i = 0; i < _n_entries; i++)
767 _values[i] *= scalar;
775 for (
unsigned int i = 0; i < _n_entries; i++)
776 _values[i] /= scalar;
784 for (
unsigned int i = 0; i < _n_entries; i++)
785 _values[i] += scalar;
795 return std::equal(_values.begin(), _values.end(), rhs.
_values.begin());
802 return !(*
this == rhs);
817 for (MooseIndex(in.
m()) i = 0; i < in.
m(); ++i)
818 for (MooseIndex(in.
n()) j = 0; j < in.
n(); ++j)
ColumnMajorMatrixTempl< Real > ColumnMajorMatrix
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
This class defines a Tensor that can change its shape.
void eigenNonsym(ColumnMajorMatrixTempl< T > &eval_real, ColumnMajorMatrixTempl< T > &eval_img, ColumnMajorMatrixTempl< T > &evec_right, ColumnMajorMatrixTempl< T > &eve_left) const
Returns eigen system solve for a non-symmetric real matrix.
ColumnMajorMatrixTempl< T > & operator/=(T scalar)
Scalar Division plus assignment.
const T * rawData() const
unsigned int numEntries() const
The total number of entries in the Tensor.
void fill(DenseVector< T > &rhs)
Fills the passed in dense vector with the values from this tensor.
void exp(ColumnMajorMatrixTempl< T > &z) const
Returns matrix that is the exponential of the matrix this was called on.
T tr() const
The trace of the CMM.
ColumnMajorMatrixTempl< T > transpose() const
Returns a matrix that is the transpose of the matrix this was called on.
void fill(TypeTensor< T > &tensor)
Fills the passed in tensor with the values from this tensor.
void print_scientific(std::ostream &os)
Prints to file.
bool operator!=(const ColumnMajorMatrixTempl< T > &rhs) const
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.
friend void dataLoad(std::istream &, ColumnMajorMatrixTempl< T2 > &, void *)
ColumnMajorMatrixTempl< T > & operator=(const TypeTensor< T > &rhs)
Sets the values in this tensor to the values on the RHS.
ColumnMajorMatrixTempl< T > & operator*=(T scalar)
Scalar Multiplication plus assignment.
bool operator==(const ColumnMajorMatrixTempl< T > &rhs) const
Equality operators.
T & operator()(const unsigned int i, const unsigned int j=0)
Get the i,j entry j defaults to zero so you can use it as a column vector.
void addDiag(T value)
Add to each of the diagonals the passsed in value.
ColumnMajorMatrixTempl< T > & operator-=(const ColumnMajorMatrixTempl< T > &rhs)
Matrix Matrix Subtraction plus assignment.
void setDiag(T value)
Set the value of each of the diagonals to the passed in value.
void identity()
Turn the matrix into an identity matrix.
ColumnMajorMatrixTempl< T > & operator=(const ColumnMajorMatrixTempl< T2 > &rhs)
Sets the values in this tensor to the values on the RHS Will also reshape this tensor if necessary.
friend void dataStore(std::ostream &, ColumnMajorMatrixTempl< T2 > &, void *)
void inverse(ColumnMajorMatrixTempl< T > &invA) const
Returns inverse of a general matrix.
ColumnMajorMatrixTempl< T > & operator+=(const TypeTensor< T > &rhs)
Matrix Tensor Addition Plus Assignment.
T norm()
The Euclidean norm of the matrix.
void print()
Print the tensor.
ColumnMajorMatrixTempl< T > deviatoric()
Returns a matrix that is the deviatoric of the matrix this was called on.
unsigned int n() const
Returns the number of rows.
void eigen(ColumnMajorMatrixTempl< T > &eval, ColumnMajorMatrixTempl< T > &evec) const
Returns eigen system solve for a symmetric real matrix.
void checkSquareness() const
Check if matrix is square.
ColumnMajorMatrixTempl< T > operator*(const TypeVector< T > &rhs) const
Matrix Vector Multiplication of the libMesh TypeVector Type.
ColumnMajorMatrixTempl< T > abs()
Returns a matrix that is the absolute value of the matrix this was called on.
ColumnMajorMatrixTempl< T > kronecker(const ColumnMajorMatrixTempl< T > &rhs) const
Kronecker Product.
ColumnMajorMatrixTempl< T > & operator+=(T scalar)
Scalar Addition plus assignment.
T * rawData()
Returns a reference to the raw data pointer.
ColumnMajorMatrixTempl< T > & operator+=(const ColumnMajorMatrixTempl< T > &rhs)
Matrix Matrix Addition plus assignment.
T doubleContraction(const ColumnMajorMatrixTempl< T > &rhs) const
Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)
unsigned int m() const
Returns the number of columns.
ColumnMajorMatrixTempl< T > operator*(const ColumnMajorMatrixTempl< T > &rhs) const
Matrix Matrix Multiplication.
ColumnMajorMatrixTempl< T > operator+(const ColumnMajorMatrixTempl< T > &rhs) const
Matrix Matrix Addition.
void fill(DenseMatrix< T > &rhs)
Fills the passed in dense matrix with the values from this tensor.
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
ColumnMajorMatrixTempl< T > operator*(T scalar) const
Scalar multiplication of the ColumnMajorMatrixTempl.
ColumnMajorMatrixTempl< T > & operator=(const ColumnMajorMatrixTempl< T > &rhs)=default
defaulted operator=
ColumnMajorMatrixTempl< T > operator+(T scalar) const
Scalar addition.
ColumnMajorMatrixTempl< T > operator-(const ColumnMajorMatrixTempl< T > &rhs) const
Matrix Matrix Subtraction.
void zero()
Zero the matrix.
T operator()(const unsigned int i, const unsigned int j=0) const
Get the i,j entry.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
IntRange< T > make_range(T beg, T end)