https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | Friends | List of all members
ColumnMajorMatrixTempl< T > Class Template Reference

This class defines a Tensor that can change its shape. More...

#include <PiecewiseBilinear.h>

Public Member Functions

 ColumnMajorMatrixTempl (const unsigned int rows=Moose::dim, const unsigned int cols=Moose::dim)
 Constructor that sets an initial number of entries and shape. More...
 
 ColumnMajorMatrixTempl (const ColumnMajorMatrixTempl< T > &rhs)
 Copy Constructor defined in terms of operator=() More...
 
 ColumnMajorMatrixTempl (const TypeTensor< T > &tensor)
 Constructor that fills in the ColumnMajorMatrixTempl with values from a libMesh TypeTensor. More...
 
 ColumnMajorMatrixTempl (const DenseMatrix< T > &rhs)
 
 ColumnMajorMatrixTempl (const DenseVector< T > &rhs)
 
 ColumnMajorMatrixTempl (const TypeVector< T > &col1, const TypeVector< T > &col2, const TypeVector< T > &col3)
 Constructor that takes in 3 vectors and uses them to create columns. More...
 
unsigned int numEntries () const
 The total number of entries in the Tensor. More...
 
void reshape (const unsigned int rows, const unsigned int cols)
 Change the shape of the tensor. More...
 
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. More...
 
operator() (const unsigned int i, const unsigned int j=0) const
 Get the i,j entry. More...
 
void print ()
 Print the tensor. More...
 
void print_scientific (std::ostream &os)
 Prints to file. More...
 
void fill (TypeTensor< T > &tensor)
 Fills the passed in tensor with the values from this tensor. More...
 
void fill (DenseMatrix< T > &rhs)
 Fills the passed in dense matrix with the values from this tensor. More...
 
void fill (DenseVector< T > &rhs)
 Fills the passed in dense vector with the values from this tensor. More...
 
ColumnMajorMatrixTempl< T > transpose () const
 Returns a matrix that is the transpose of the matrix this was called on. More...
 
ColumnMajorMatrixTempl< T > deviatoric ()
 Returns a matrix that is the deviatoric of the matrix this was called on. More...
 
ColumnMajorMatrixTempl< T > abs ()
 Returns a matrix that is the absolute value of the matrix this was called on. More...
 
void setDiag (T value)
 Set the value of each of the diagonals to the passed in value. More...
 
void addDiag (T value)
 Add to each of the diagonals the passsed in value. More...
 
tr () const
 The trace of the CMM. More...
 
void zero ()
 Zero the matrix. More...
 
void identity ()
 Turn the matrix into an identity matrix. More...
 
doubleContraction (const ColumnMajorMatrixTempl< T > &rhs) const
 Double contraction of two matrices ie A : B = Sum(A_ab * B_ba) More...
 
norm ()
 The Euclidean norm of the matrix. More...
 
unsigned int n () const
 Returns the number of rows. More...
 
unsigned int m () const
 Returns the number of columns. More...
 
void eigen (ColumnMajorMatrixTempl< T > &eval, ColumnMajorMatrixTempl< T > &evec) const
 Returns eigen system solve for a symmetric real matrix. More...
 
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. More...
 
void exp (ColumnMajorMatrixTempl< T > &z) const
 Returns matrix that is the exponential of the matrix this was called on. More...
 
void inverse (ColumnMajorMatrixTempl< T > &invA) const
 Returns inverse of a general matrix. More...
 
T * rawData ()
 Returns a reference to the raw data pointer. More...
 
const T * rawData () const
 
ColumnMajorMatrixTempl< T > kronecker (const ColumnMajorMatrixTempl< T > &rhs) const
 Kronecker Product. More...
 
ColumnMajorMatrixTempl< T > & operator= (const TypeTensor< T > &rhs)
 Sets the values in this tensor to the values on the RHS. More...
 
ColumnMajorMatrixTempl< T > & operator= (const DenseMatrix< T > &rhs)
 Sets the values in this dense matrix to the values on the RHS. More...
 
ColumnMajorMatrixTempl< T > & operator= (const DenseVector< T > &rhs)
 Sets the values in this dense vector to the values on the RHS. More...
 
template<typename T2 >
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. More...
 
ColumnMajorMatrixTempl< T > & operator= (const ColumnMajorMatrixTempl< T > &rhs)=default
 defaulted operator= More...
 
ColumnMajorMatrixTempl< T > operator* (T scalar) const
 Scalar multiplication of the ColumnMajorMatrixTempl. More...
 
ColumnMajorMatrixTempl< T > operator* (const TypeVector< T > &rhs) const
 Matrix Vector Multiplication of the libMesh TypeVector Type. More...
 
ColumnMajorMatrixTempl< T > operator* (const ColumnMajorMatrixTempl< T > &rhs) const
 Matrix Vector Multiplication of the TypeTensor Product. More...
 
ColumnMajorMatrixTempl< T > operator+ (const ColumnMajorMatrixTempl< T > &rhs) const
 Matrix Matrix Addition. More...
 
ColumnMajorMatrixTempl< T > operator- (const ColumnMajorMatrixTempl< T > &rhs) const
 Matrix Matrix Subtraction. More...
 
ColumnMajorMatrixTempl< T > & operator+= (const ColumnMajorMatrixTempl< T > &rhs)
 Matrix Matrix Addition plus assignment. More...
 
ColumnMajorMatrixTempl< T > & operator+= (const TypeTensor< T > &rhs)
 Matrix Tensor Addition Plus Assignment. More...
 
ColumnMajorMatrixTempl< T > & operator-= (const ColumnMajorMatrixTempl< T > &rhs)
 Matrix Matrix Subtraction plus assignment. More...
 
ColumnMajorMatrixTempl< T > operator+ (T scalar) const
 Scalar addition. More...
 
ColumnMajorMatrixTempl< T > & operator*= (T scalar)
 Scalar Multiplication plus assignment. More...
 
ColumnMajorMatrixTempl< T > & operator/= (T scalar)
 Scalar Division plus assignment. More...
 
ColumnMajorMatrixTempl< T > & operator+= (T scalar)
 Scalar Addition plus assignment. More...
 
void checkSquareness () const
 Check if matrix is square. More...
 
void checkShapeEquality (const ColumnMajorMatrixTempl< T > &rhs) const
 Check if matrices are of same shape. More...
 
bool operator== (const ColumnMajorMatrixTempl< T > &rhs) const
 Equality operators. More...
 
bool operator!= (const ColumnMajorMatrixTempl< T > &rhs) const
 
template<>
void eigen (ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &) const
 
template<>
void eigenNonsym (ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &) const
 
template<>
void inverse (ColumnMajorMatrixTempl< ADReal > &) const
 

Protected Attributes

unsigned int _n_rows
 
unsigned int _n_cols
 
unsigned int _n_entries
 
std::vector< T > _values
 

Friends

template<typename T2 >
void dataStore (std::ostream &, ColumnMajorMatrixTempl< T2 > &, void *)
 
template<typename T2 >
void dataLoad (std::istream &, ColumnMajorMatrixTempl< T2 > &, void *)
 

Detailed Description

template<typename T>
class ColumnMajorMatrixTempl< T >

This class defines a Tensor that can change its shape.

This means a 3x3x3x3 Tensor can be represented as a 9x9 or an 81x1. Further, the values of this tensor are COLUMN major ordered!

Definition at line 15 of file PiecewiseBilinear.h.

Constructor & Destructor Documentation

◆ ColumnMajorMatrixTempl() [1/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const unsigned int  rows = Moose::dim,
const unsigned int  cols = Moose::dim 
)
explicit

Constructor that sets an initial number of entries and shape.

Defaults to creating the same size tensor as TensorValue

Definition at line 20 of file ColumnMajorMatrix.C.

21  : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
22 {
23  _values.resize(rows * cols);
24 }
std::vector< T > _values

◆ ColumnMajorMatrixTempl() [2/6]

template<typename T>
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const ColumnMajorMatrixTempl< T > &  rhs)

Copy Constructor defined in terms of operator=()

Definition at line 27 of file ColumnMajorMatrix.C.

28  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
29 {
30  *this = rhs;
31 }

◆ ColumnMajorMatrixTempl() [3/6]

template<typename T>
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const TypeTensor< T > &  tensor)
explicit

Constructor that fills in the ColumnMajorMatrixTempl with values from a libMesh TypeTensor.

Definition at line 34 of file ColumnMajorMatrix.C.

35  : _n_rows(LIBMESH_DIM),
36  _n_cols(LIBMESH_DIM),
37  _n_entries(LIBMESH_DIM * LIBMESH_DIM),
38  _values(LIBMESH_DIM * LIBMESH_DIM)
39 {
40  for (const auto j : make_range(Moose::dim))
41  for (const auto i : make_range(Moose::dim))
42  (*this)(i, j) = rhs(i, j);
43 }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
std::vector< T > _values
IntRange< T > make_range(T beg, T end)

◆ ColumnMajorMatrixTempl() [4/6]

template<typename T>
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const DenseMatrix< T > &  rhs)
explicit

Definition at line 46 of file ColumnMajorMatrix.C.

47  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
48 {
49  *this = rhs;
50 }

◆ ColumnMajorMatrixTempl() [5/6]

template<typename T>
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const DenseVector< T > &  rhs)
explicit

Definition at line 53 of file ColumnMajorMatrix.C.

54  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
55 {
56  *this = rhs;
57 }

◆ ColumnMajorMatrixTempl() [6/6]

template<typename T>
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const TypeVector< T > &  col1,
const TypeVector< T > &  col2,
const TypeVector< T > &  col3 
)

Constructor that takes in 3 vectors and uses them to create columns.

Definition at line 60 of file ColumnMajorMatrix.C.

63  : _n_rows(LIBMESH_DIM),
64  _n_cols(LIBMESH_DIM),
65  _n_entries(LIBMESH_DIM * LIBMESH_DIM),
66  _values(LIBMESH_DIM * LIBMESH_DIM)
67 {
68  unsigned int entry = 0;
69  for (const auto i : make_range(Moose::dim))
70  _values[entry++] = col1(i);
71 
72  for (const auto i : make_range(Moose::dim))
73  _values[entry++] = col2(i);
74 
75  for (const auto i : make_range(Moose::dim))
76  _values[entry++] = col3(i);
77 }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
std::vector< T > _values
IntRange< T > make_range(T beg, T end)

Member Function Documentation

◆ abs()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::abs ( )
inline

Returns a matrix that is the absolute value of the matrix this was called on.

Definition at line 310 of file ColumnMajorMatrix.C.

311 {
312  ColumnMajorMatrixTempl<T> & s = (*this);
313 
315 
316  for (unsigned int j = 0; j < _n_cols; j++)
317  for (unsigned int i = 0; i < _n_rows; i++)
318  ret_matrix(i, j) = std::abs(s(i, j));
319 
320  return ret_matrix;
321 }
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
This class defines a Tensor that can change its shape.

◆ addDiag()

template<typename T>
void ColumnMajorMatrixTempl< T >::addDiag ( value)
inline

Add to each of the diagonals the passsed in value.

Definition at line 496 of file ColumnMajorMatrix.h.

497 {
498  this->checkSquareness();
499 
500  for (unsigned int i = 0; i < _n_rows; i++)
501  (*this)(i, i) += value;
502 }
void checkSquareness() const
Check if matrix is square.

◆ checkShapeEquality()

template<typename T>
void ColumnMajorMatrixTempl< T >::checkShapeEquality ( const ColumnMajorMatrixTempl< T > &  rhs) const

Check if matrices are of same shape.

Definition at line 294 of file ColumnMajorMatrix.C.

295 {
296  if (_n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
297  mooseError("ColumnMajorMatrix error: Unable to perform the operation on matrices of different "
298  "shapes.");
299 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ checkSquareness()

template<typename T >
void ColumnMajorMatrixTempl< T >::checkSquareness ( ) const

Check if matrix is square.

Definition at line 286 of file ColumnMajorMatrix.C.

Referenced by ColumnMajorMatrixTempl< Real >::kronecker().

287 {
288  if (_n_rows != _n_cols)
289  mooseError("ColumnMajorMatrix error: Unable to perform the operation on a non-square matrix.");
290 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ deviatoric()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::deviatoric ( )
inline

Returns a matrix that is the deviatoric of the matrix this was called on.

Definition at line 469 of file ColumnMajorMatrix.h.

470 {
471  ColumnMajorMatrixTempl<T> & s = (*this);
472 
474 
475  I.identity();
476 
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);
480 
481  return ret_matrix;
482 }
T tr() const
The trace of the CMM.
This class defines a Tensor that can change its shape.

◆ doubleContraction()

template<typename T>
T ColumnMajorMatrixTempl< T >::doubleContraction ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)

Definition at line 540 of file ColumnMajorMatrix.h.

541 {
542  this->checkShapeEquality(rhs);
543 
544  T value = 0;
545 
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);
549 
550  return value;
551 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.

◆ eigen() [1/2]

Definition at line 166 of file ColumnMajorMatrix.C.

168 {
169  mooseError("Eigen solves with AD types is not supported.");
170 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ eigen() [2/2]

template<typename T>
void ColumnMajorMatrixTempl< T >::eigen ( ColumnMajorMatrixTempl< T > &  eval,
ColumnMajorMatrixTempl< T > &  evec 
) const

Returns eigen system solve for a symmetric real matrix.

Definition at line 135 of file ColumnMajorMatrix.C.

137 {
138  this->checkSquareness();
139 
140  char jobz = 'V';
141  char uplo = 'U';
142  PetscBLASInt n = _n_rows;
143  PetscBLASInt return_value = 0;
144 
145  eval._n_rows = _n_rows;
146  eval._n_cols = 1;
147  eval._n_entries = _n_rows;
148  eval._values.resize(_n_rows);
149 
150  evec = *this;
151 
152  T * eval_data = eval.rawData();
153  T * evec_data = evec.rawData();
154 
155  PetscBLASInt buffer_size = n * 64;
156  std::vector<T> buffer(buffer_size);
157 
158  LAPACKsyev_(&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
159 
160  if (return_value)
161  mooseError("error in lapack eigen solve");
162 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
std::vector< T > _values
unsigned int n() const
Returns the number of rows.

◆ eigenNonsym() [1/2]

template<typename T>
void ColumnMajorMatrixTempl< T >::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.

Definition at line 174 of file ColumnMajorMatrix.C.

Referenced by ColumnMajorMatrixTempl< Real >::exp().

178 {
179  this->checkSquareness();
180 
181  ColumnMajorMatrixTempl<T> a(*this);
182 
183  char jobvl = 'V';
184  char jobvr = 'V';
185  PetscBLASInt n = _n_rows;
186  PetscBLASInt return_value = 0;
187 
188  eval_real._n_rows = _n_rows;
189  eval_real._n_cols = 1;
190  eval_real._n_entries = _n_rows;
191  eval_real._values.resize(_n_rows);
192 
193  eval_img._n_rows = _n_rows;
194  eval_img._n_cols = 1;
195  eval_img._n_entries = _n_rows;
196  eval_img._values.resize(_n_rows);
197 
198  T * a_data = a.rawData();
199  T * eval_r = eval_real.rawData();
200  T * eval_i = eval_img.rawData();
201  T * evec_ri = evec_right.rawData();
202  T * evec_le = evec_left.rawData();
203 
204  PetscBLASInt buffer_size = n * 64;
205  std::vector<T> buffer(buffer_size);
206 
207  LAPACKgeev_(&jobvl,
208  &jobvr,
209  &n,
210  a_data,
211  &n,
212  eval_r,
213  eval_i,
214  evec_le,
215  &n,
216  evec_ri,
217  &n,
218  &buffer[0],
219  &buffer_size,
220  &return_value);
221 
222  if (return_value)
223  mooseError("error in lapack eigen solve");
224 }
This class defines a Tensor that can change its shape.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
std::vector< T > _values
unsigned int n() const
Returns the number of rows.

◆ eigenNonsym() [2/2]

Definition at line 228 of file ColumnMajorMatrix.C.

232 {
233  mooseError("Eigen solves with AD types is not supported.");
234 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ exp()

template<typename T>
void ColumnMajorMatrixTempl< T >::exp ( ColumnMajorMatrixTempl< T > &  z) const

Returns matrix that is the exponential of the matrix this was called on.

Definition at line 238 of file ColumnMajorMatrix.C.

239 {
240  this->checkSquareness();
241 
242  ColumnMajorMatrixTempl<T> a(*this);
243  ColumnMajorMatrixTempl<T> evals_real(_n_rows, 1), evals_img(_n_rows, 1),
244  evals_real2(_n_rows, _n_cols);
245  ColumnMajorMatrixTempl<T> evec_right(_n_rows, _n_cols), evec_left(_n_rows, _n_cols);
246  ColumnMajorMatrixTempl<T> evec_right_inverse(_n_rows, _n_cols);
247 
248  a.eigenNonsym(evals_real, evals_img, evec_right, evec_left);
249 
250  for (unsigned int i = 0; i < _n_rows; i++)
251  evals_real2(i, i) = std::exp(evals_real(i, 0));
252 
253  evec_right.inverse(evec_right_inverse);
254 
255  z = evec_right * evals_real2 * evec_right_inverse;
256 }
This class defines a Tensor that can change its shape.
auto exp(const T &)
void checkSquareness() const
Check if matrix is square.

◆ fill() [1/3]

template<typename T>
void ColumnMajorMatrixTempl< T >::fill ( TypeTensor< T > &  tensor)
inline

Fills the passed in tensor with the values from this tensor.

Definition at line 417 of file ColumnMajorMatrix.h.

418 {
420  mooseError(
421  "Cannot fill tensor! The ColumnMajorMatrix doesn't have the same number of entries!");
422 
423  for (const auto j : libMesh::make_range(Moose::dim))
424  for (const auto i : libMesh::make_range(Moose::dim))
425  tensor(i, j) = _values[j * Moose::dim + i];
426 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
std::vector< T > _values
IntRange< T > make_range(T beg, T end)

◆ fill() [2/3]

template<typename T>
void ColumnMajorMatrixTempl< T >::fill ( DenseMatrix< T > &  rhs)
inline

Fills the passed in dense matrix with the values from this tensor.

Definition at line 430 of file ColumnMajorMatrix.h.

431 {
432  if (rhs.n() * rhs.m() != _n_entries)
433  mooseError(
434  "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
435 
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];
439 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::vector< T > _values

◆ fill() [3/3]

template<typename T>
void ColumnMajorMatrixTempl< T >::fill ( DenseVector< T > &  rhs)
inline

Fills the passed in dense vector with the values from this tensor.

Definition at line 443 of file ColumnMajorMatrix.h.

444 {
445  if (_n_rows != rhs.size() || _n_cols != 1)
446  mooseError("ColumnMajorMatrix and DenseVector must be the same shape for a fill!");
447 
448  for (unsigned int i = 0; i < _n_rows; ++i)
449  rhs(i) = (*this)(i);
450 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ identity()

template<typename T >
void ColumnMajorMatrixTempl< T >::identity ( )
inline

Turn the matrix into an identity matrix.

Definition at line 528 of file ColumnMajorMatrix.h.

Referenced by ColumnMajorMatrixTempl< Real >::deviatoric().

529 {
530  this->checkSquareness();
531 
532  zero();
533 
534  for (unsigned int i = 0; i < _n_rows; i++)
535  (*this)(i, i) = 1;
536 }
void checkSquareness() const
Check if matrix is square.
void zero()
Zero the matrix.

◆ inverse() [1/2]

template<typename T>
void ColumnMajorMatrixTempl< T >::inverse ( ColumnMajorMatrixTempl< T > &  invA) const

Returns inverse of a general matrix.

Definition at line 260 of file ColumnMajorMatrix.C.

261 {
262  this->checkSquareness();
263  this->checkShapeEquality(invA);
264 
265  PetscBLASInt n = _n_rows;
266  PetscBLASInt return_value = 0;
267 
268  invA = *this;
269 
270  std::vector<PetscBLASInt> ipiv(n);
271  T * invA_data = invA.rawData();
272 
273  PetscBLASInt buffer_size = n * 64;
274  std::vector<T> buffer(buffer_size);
275 
276  LAPACKgetrf_(&n, &n, invA_data, &n, &ipiv[0], &return_value);
277 
278  LAPACKgetri_(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
279 
280  if (return_value)
281  mooseException("Error in LAPACK matrix-inverse calculation");
282 }
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
unsigned int n() const
Returns the number of rows.

◆ inverse() [2/2]

template<>
void ColumnMajorMatrixTempl< ADReal >::inverse ( ColumnMajorMatrixTempl< ADReal > &  ) const

Definition at line 303 of file ColumnMajorMatrix.C.

304 {
305  mooseError("Inverse solves with AD types is not supported for the ColumnMajorMatrix class.");
306 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ kronecker()

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::kronecker ( const ColumnMajorMatrixTempl< T > &  rhs) const

Kronecker Product.

Definition at line 81 of file ColumnMajorMatrix.C.

82 {
83  rhs.checkSquareness();
84 
85  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows * rhs._n_rows, _n_cols * rhs._n_cols);
86 
87  for (unsigned int i = 0; i < _n_rows; i++)
88  for (unsigned int j = 0; j < _n_cols; j++)
89  for (unsigned int k = 0; k < rhs._n_rows; k++)
90  for (unsigned int l = 0; l < rhs._n_cols; l++)
91  ret_matrix(((i * _n_rows) + k), ((j * _n_cols) + l)) = (*this)(i, j) * rhs(k, l);
92 
93  return ret_matrix;
94 }
This class defines a Tensor that can change its shape.
void checkSquareness() const
Check if matrix is square.

◆ m()

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::m ( ) const
inline

◆ n()

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::n ( ) const
inline

◆ norm()

template<typename T >
T ColumnMajorMatrixTempl< T >::norm ( )
inline

The Euclidean norm of the matrix.

Definition at line 325 of file ColumnMajorMatrix.C.

326 {
327  return std::sqrt(doubleContraction(*this));
328 }
T doubleContraction(const ColumnMajorMatrixTempl< T > &rhs) const
Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh

◆ numEntries()

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::numEntries ( ) const
inline

The total number of entries in the Tensor.

i.e. cols * rows

Definition at line 340 of file ColumnMajorMatrix.h.

341 {
342  return _n_entries;
343 }

◆ operator!=()

template<typename T>
bool ColumnMajorMatrixTempl< T >::operator!= ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Definition at line 800 of file ColumnMajorMatrix.h.

801 {
802  return !(*this == rhs);
803 }

◆ operator()() [1/2]

template<typename T >
T & ColumnMajorMatrixTempl< T >::operator() ( const unsigned int  i,
const unsigned int  j = 0 
)
inline

Get the i,j entry j defaults to zero so you can use it as a column vector.

Definition at line 365 of file ColumnMajorMatrix.h.

366 {
367  if ((i * j) >= _n_entries)
368  mooseError("Reference outside of ColumnMajorMatrix bounds!");
369 
370  // Row major indexing!
371  return _values[(j * _n_rows) + i];
372 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::vector< T > _values

◆ operator()() [2/2]

template<typename T >
T ColumnMajorMatrixTempl< T >::operator() ( const unsigned int  i,
const unsigned int  j = 0 
) const
inline

Get the i,j entry.

j defaults to zero so you can use it as a column vector. This is the version used for a const ColumnMajorMatrixTempl.

Definition at line 376 of file ColumnMajorMatrix.h.

377 {
378  if ((i * j) >= _n_entries)
379  mooseError("Reference outside of ColumnMajorMatrix bounds!");
380 
381  // Row major indexing!
382  return _values[(j * _n_rows) + i];
383 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::vector< T > _values

◆ operator*() [1/3]

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator* ( scalar) const
inline

Scalar multiplication of the ColumnMajorMatrixTempl.

Definition at line 621 of file ColumnMajorMatrix.h.

622 {
624 
625  for (unsigned int i = 0; i < _n_entries; i++)
626  ret_matrix._values[i] = _values[i] * scalar;
627 
628  return ret_matrix;
629 }
This class defines a Tensor that can change its shape.
std::vector< T > _values

◆ operator*() [2/3]

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator* ( const TypeVector< T > &  rhs) const
inline

Matrix Vector Multiplication of the libMesh TypeVector Type.

Definition at line 633 of file ColumnMajorMatrix.h.

634 {
635  if (_n_cols != Moose::dim)
636  mooseError("Cannot perform matvec operation! The column dimension of "
637  "the ColumnMajorMatrix does not match the TypeVector!");
638 
639  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, 1);
640 
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);
644 
645  return ret_matrix;
646 }
This class defines a Tensor that can change its shape.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154

◆ operator*() [3/3]

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator* ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Matrix Vector Multiplication of the TypeTensor Product.

Note that the Tensor type is treated as a single dimension Vector for this operation Matrix Matrix Multiplication

Definition at line 667 of file ColumnMajorMatrix.h.

668 {
669  if (_n_cols != rhs._n_rows)
670  mooseError(
671  "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
672 
673  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, rhs._n_cols);
674 
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);
679 
680  return ret_matrix;
681 }
This class defines a Tensor that can change its shape.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ operator*=()

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator*= ( scalar)
inline

Scalar Multiplication plus assignment.

Definition at line 764 of file ColumnMajorMatrix.h.

765 {
766  for (unsigned int i = 0; i < _n_entries; i++)
767  _values[i] *= scalar;
768  return *this;
769 }
std::vector< T > _values

◆ operator+() [1/2]

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator+ ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Matrix Matrix Addition.

Definition at line 685 of file ColumnMajorMatrix.h.

686 {
687  this->checkShapeEquality(rhs);
688 
690 
691  for (unsigned int i = 0; i < _n_entries; i++)
692  ret_matrix._values[i] = _values[i] + rhs._values[i];
693 
694  return ret_matrix;
695 }
This class defines a Tensor that can change its shape.
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
std::vector< T > _values

◆ operator+() [2/2]

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator+ ( scalar) const
inline

Scalar addition.

Definition at line 752 of file ColumnMajorMatrix.h.

753 {
755 
756  for (unsigned int i = 0; i < _n_entries; i++)
757  ret_matrix._values[i] = _values[i] + scalar;
758 
759  return ret_matrix;
760 }
This class defines a Tensor that can change its shape.
std::vector< T > _values

◆ operator+=() [1/3]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator+= ( const ColumnMajorMatrixTempl< T > &  rhs)
inline

Matrix Matrix Addition plus assignment.

Note that this is faster than regular addition because the result doesn't have to get copied out

Definition at line 713 of file ColumnMajorMatrix.h.

714 {
715  this->checkShapeEquality(rhs);
716 
717  for (unsigned int i = 0; i < _n_entries; i++)
718  _values[i] += rhs._values[i];
719 
720  return *this;
721 }
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
std::vector< T > _values

◆ operator+=() [2/3]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator+= ( const TypeTensor< T > &  rhs)
inline

Matrix Tensor Addition Plus Assignment.

Definition at line 725 of file ColumnMajorMatrix.h.

726 {
727  if ((_n_rows != Moose::dim) || (_n_cols != Moose::dim))
728  mooseError("Cannot perform matrix addition and assignment! The shapes of the two operands are "
729  "not compatible!");
730 
731  for (const auto j : libMesh::make_range(Moose::dim))
732  for (const auto i : libMesh::make_range(Moose::dim))
733  (*this)(i, j) += rhs(i, j);
734 
735  return *this;
736 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
IntRange< T > make_range(T beg, T end)

◆ operator+=() [3/3]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator+= ( scalar)
inline

Scalar Addition plus assignment.

Definition at line 782 of file ColumnMajorMatrix.h.

783 {
784  for (unsigned int i = 0; i < _n_entries; i++)
785  _values[i] += scalar;
786  return *this;
787 }
std::vector< T > _values

◆ operator-()

template<typename T>
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator- ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Matrix Matrix Subtraction.

Definition at line 699 of file ColumnMajorMatrix.h.

700 {
701  this->checkShapeEquality(rhs);
702 
704 
705  for (unsigned int i = 0; i < _n_entries; i++)
706  ret_matrix._values[i] = _values[i] - rhs._values[i];
707 
708  return ret_matrix;
709 }
This class defines a Tensor that can change its shape.
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
std::vector< T > _values

◆ operator-=()

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator-= ( const ColumnMajorMatrixTempl< T > &  rhs)
inline

Matrix Matrix Subtraction plus assignment.

Note that this is faster than regular subtraction because the result doesn't have to get copied out

Definition at line 740 of file ColumnMajorMatrix.h.

741 {
742  this->checkShapeEquality(rhs);
743 
744  for (unsigned int i = 0; i < _n_entries; i++)
745  _values[i] -= rhs._values[i];
746 
747  return *this;
748 }
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
std::vector< T > _values

◆ operator/=()

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator/= ( scalar)
inline

Scalar Division plus assignment.

Definition at line 773 of file ColumnMajorMatrix.h.

774 {
775  for (unsigned int i = 0; i < _n_entries; i++)
776  _values[i] /= scalar;
777  return *this;
778 }
std::vector< T > _values

◆ operator=() [1/5]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const TypeTensor< T > &  rhs)
inline

Sets the values in this tensor to the values on the RHS.

Will also reshape this tensor if necessary.

Definition at line 583 of file ColumnMajorMatrix.h.

584 {
585  // Resize the tensor if necessary
586  if ((Moose::dim * Moose::dim) != _n_entries)
587  {
589  _values.resize(_n_entries);
590  }
591 
592  // Make sure the shape is correct
594 
595  ColumnMajorMatrixTempl<T> & s = (*this);
596 
597  // Copy the values
598  for (unsigned int j = 0; j < _n_cols; j++)
599  for (unsigned int i = 0; i < _n_cols; i++)
600  s(i, j) = rhs(i, j);
601 
602  return *this;
603 }
This class defines a Tensor that can change its shape.
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
std::vector< T > _values

◆ operator=() [2/5]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const DenseMatrix< T > &  rhs)

Sets the values in this dense matrix to the values on the RHS.

Will also reshape this tensor if necessary.

Definition at line 98 of file ColumnMajorMatrix.C.

99 {
100  if (_n_rows != rhs.m() || _n_cols != rhs.n())
101  mooseError("ColumnMajorMatrix and DenseMatrix should be of the same shape.");
102 
103  _n_rows = rhs.m();
104  _n_cols = rhs.n();
105  _n_entries = rhs.m() * rhs.n();
106  _values.resize(rhs.m() * rhs.n());
107 
108  for (unsigned int j = 0; j < _n_cols; ++j)
109  for (unsigned int i = 0; i < _n_rows; ++i)
110  (*this)(i, j) = rhs(i, j);
111 
112  return *this;
113 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::vector< T > _values

◆ operator=() [3/5]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const DenseVector< T > &  rhs)

Sets the values in this dense vector to the values on the RHS.

Will also reshape this tensor if necessary.

Definition at line 117 of file ColumnMajorMatrix.C.

118 {
119  if (_n_rows != rhs.size() || _n_cols != 1)
120  mooseError("ColumnMajorMatrix and DenseVector should be of the same shape.");
121 
122  _n_rows = rhs.size();
123  _n_cols = 1;
124  _n_entries = rhs.size();
125  _values.resize(rhs.size());
126 
127  for (unsigned int i = 0; i < _n_rows; ++i)
128  (*this)(i) = rhs(i);
129 
130  return *this;
131 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::vector< T > _values

◆ operator=() [4/5]

template<typename T >
template<typename T2 >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const ColumnMajorMatrixTempl< T2 > &  rhs)
inline

Sets the values in this tensor to the values on the RHS Will also reshape this tensor if necessary.

Definition at line 608 of file ColumnMajorMatrix.h.

609 {
610  this->reshape(rhs.m(), rhs.n());
611 
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);
615 
616  return *this;
617 }
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.
unsigned int m() const
Returns the number of columns.
unsigned int n() const
Returns the number of rows.

◆ operator=() [5/5]

template<typename T>
ColumnMajorMatrixTempl<T>& ColumnMajorMatrixTempl< T >::operator= ( const ColumnMajorMatrixTempl< T > &  rhs)
default

defaulted operator=

◆ operator==()

template<typename T>
bool ColumnMajorMatrixTempl< T >::operator== ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Equality operators.

Definition at line 791 of file ColumnMajorMatrix.h.

792 {
793  if (_n_entries != rhs._n_entries || _n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
794  return false;
795  return std::equal(_values.begin(), _values.end(), rhs._values.begin());
796 }
std::vector< T > _values

◆ print()

template<typename T >
void ColumnMajorMatrixTempl< T >::print ( )
inline

Print the tensor.

Definition at line 387 of file ColumnMajorMatrix.h.

388 {
389  ColumnMajorMatrixTempl<T> & s = (*this);
390 
391  for (unsigned int i = 0; i < _n_rows; i++)
392  {
393  for (unsigned int j = 0; j < _n_cols; j++)
394  Moose::out << std::setw(15) << s(i, j) << " ";
395 
396  Moose::out << std::endl;
397  }
398 }
This class defines a Tensor that can change its shape.

◆ print_scientific()

template<typename T >
void ColumnMajorMatrixTempl< T >::print_scientific ( std::ostream &  os)
inline

Prints to file.

Definition at line 402 of file ColumnMajorMatrix.h.

403 {
404  ColumnMajorMatrixTempl<T> & s = (*this);
405 
406  for (unsigned int i = 0; i < _n_rows; i++)
407  {
408  for (unsigned int j = 0; j < _n_cols; j++)
409  os << std::setw(15) << std::scientific << std::setprecision(8) << s(i, j) << " ";
410 
411  os << std::endl;
412  }
413 }
This class defines a Tensor that can change its shape.
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:33

◆ rawData() [1/2]

template<typename T >
T * ColumnMajorMatrixTempl< T >::rawData ( )
inline

Returns a reference to the raw data pointer.

Definition at line 569 of file ColumnMajorMatrix.h.

Referenced by ColumnMajorMatrixTempl< Real >::eigen(), ColumnMajorMatrixTempl< Real >::eigenNonsym(), ColumnMajorMatrixTempl< Real >::inverse(), and RankTwoTensorTempl< Real >::operator=().

570 {
571  return &_values[0];
572 }
std::vector< T > _values

◆ rawData() [2/2]

template<typename T >
const T * ColumnMajorMatrixTempl< T >::rawData ( ) const
inline

Definition at line 576 of file ColumnMajorMatrix.h.

577 {
578  return &_values[0];
579 }
std::vector< T > _values

◆ reshape()

template<typename T >
void ColumnMajorMatrixTempl< T >::reshape ( const unsigned int  rows,
const unsigned int  cols 
)
inline

Change the shape of the tensor.

Note that cols * rows should be equal to numEntries()!

Definition at line 347 of file ColumnMajorMatrix.h.

Referenced by PiecewiseBilinear::parse(), and PiecewiseBilinear::PiecewiseBilinear().

348 {
349  if (cols * rows == _n_entries)
350  {
351  _n_rows = rows;
352  _n_cols = cols;
353  }
354  else
355  {
356  _n_rows = rows;
357  _n_cols = cols;
359  _values.resize(_n_entries);
360  }
361 }
std::vector< T > _values

◆ setDiag()

template<typename T>
void ColumnMajorMatrixTempl< T >::setDiag ( value)
inline

Set the value of each of the diagonals to the passed in value.

Definition at line 486 of file ColumnMajorMatrix.h.

487 {
488  this->checkSquareness();
489 
490  for (unsigned int i = 0; i < _n_rows; i++)
491  (*this)(i, i) = value;
492 }
void checkSquareness() const
Check if matrix is square.

◆ tr()

template<typename T >
T ColumnMajorMatrixTempl< T >::tr ( ) const
inline

The trace of the CMM.

Definition at line 506 of file ColumnMajorMatrix.h.

Referenced by ColumnMajorMatrixTempl< Real >::deviatoric().

507 {
508  this->checkSquareness();
509 
510  T trace = 0;
511 
512  for (unsigned int i = 0; i < _n_rows; i++)
513  trace += (*this)(i, i);
514 
515  return trace;
516 }
void checkSquareness() const
Check if matrix is square.

◆ transpose()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::transpose ( ) const
inline

Returns a matrix that is the transpose of the matrix this was called on.

Definition at line 454 of file ColumnMajorMatrix.h.

455 {
456  const ColumnMajorMatrixTempl<T> & s = (*this);
457 
459 
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);
463 
464  return ret_matrix;
465 }
This class defines a Tensor that can change its shape.

◆ zero()

template<typename T >
void ColumnMajorMatrixTempl< T >::zero ( )
inline

Zero the matrix.

Definition at line 520 of file ColumnMajorMatrix.h.

521 {
522  for (unsigned int i = 0; i < _n_entries; i++)
523  _values[i] = 0;
524 }
std::vector< T > _values

Friends And Related Function Documentation

◆ dataLoad

template<typename T>
template<typename T2 >
void dataLoad ( std::istream &  ,
ColumnMajorMatrixTempl< T2 > &  ,
void  
)
friend

◆ dataStore

template<typename T>
template<typename T2 >
void dataStore ( std::ostream &  ,
ColumnMajorMatrixTempl< T2 > &  ,
void  
)
friend

Member Data Documentation

◆ _n_cols

template<typename T>
unsigned int ColumnMajorMatrixTempl< T >::_n_cols
protected

◆ _n_entries

template<typename T>
unsigned int ColumnMajorMatrixTempl< T >::_n_entries
protected

◆ _n_rows

template<typename T>
unsigned int ColumnMajorMatrixTempl< T >::_n_rows
protected

◆ _values

template<typename T>
std::vector<T> ColumnMajorMatrixTempl< T >::_values
protected

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