www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
ColumnMajorMatrix Class Reference

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

#include <ColumnMajorMatrix.h>

Public Member Functions

 ColumnMajorMatrix (const unsigned int rows=LIBMESH_DIM, const unsigned int cols=LIBMESH_DIM)
 Constructor that sets an initial number of entries and shape. More...
 
 ColumnMajorMatrix (const ColumnMajorMatrix &rhs)
 Copy Constructor defined in terms of operator=() More...
 
 ColumnMajorMatrix (const TypeTensor< Real > &tensor)
 Constructor that fills in the ColumnMajorMatrix with values from a libMesh TypeTensor. More...
 
 ColumnMajorMatrix (const DenseMatrix< Real > &rhs)
 
 ColumnMajorMatrix (const DenseVector< Real > &rhs)
 
 ColumnMajorMatrix (const TypeVector< Real > &col1, const TypeVector< Real > &col2, const TypeVector< Real > &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...
 
Real & 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...
 
Real 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< Real > &tensor)
 Fills the passed in tensor with the values from this tensor. More...
 
void fill (DenseMatrix< Real > &rhs)
 Fills the passed in dense matrix with the values from this tensor. More...
 
void fill (DenseVector< Real > &rhs)
 Fills the passed in dense vector with the values from this tensor. More...
 
ColumnMajorMatrix transpose () const
 Returns a matrix that is the transpose of the matrix this was called on. More...
 
ColumnMajorMatrix deviatoric ()
 Returns a matrix that is the deviatoric of the matrix this was called on. More...
 
ColumnMajorMatrix abs ()
 Returns a matrix that is the absolute value of the matrix this was called on. More...
 
void setDiag (Real value)
 Set the value of each of the diagonals to the passed in value. More...
 
void addDiag (Real value)
 Add to each of the diagonals the passsed in value. More...
 
Real tr () const
 The trace of the CMM. More...
 
void zero ()
 Zero the matrix. More...
 
void identity ()
 Turn the matrix into an identity matrix. More...
 
Real doubleContraction (const ColumnMajorMatrix &rhs) const
 Double contraction of two matrices ie A : B = Sum(A_ab * B_ba) More...
 
Real 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 (ColumnMajorMatrix &eval, ColumnMajorMatrix &evec) const
 Returns eigen system solve for a symmetric real matrix. More...
 
void eigenNonsym (ColumnMajorMatrix &eval_real, ColumnMajorMatrix &eval_img, ColumnMajorMatrix &evec_right, ColumnMajorMatrix &eve_left) const
 Returns eigen system solve for a non-symmetric real matrix. More...
 
void exp (ColumnMajorMatrix &z) const
 Returns matrix that is the exponential of the matrix this was called on. More...
 
void inverse (ColumnMajorMatrix &invA) const
 Returns inverse of a general matrix. More...
 
Real * rawData ()
 Returns a reference to the raw data pointer. More...
 
const Real * rawData () const
 
ColumnMajorMatrix kronecker (const ColumnMajorMatrix &rhs) const
 Kronecker Product. More...
 
ColumnMajorMatrixoperator= (const TypeTensor< Real > &rhs)
 Sets the values in this tensor to the values on the RHS. More...
 
ColumnMajorMatrixoperator= (const DenseMatrix< Real > &rhs)
 
Sets the values in this dense matrix to the values on the RHS. More...
 
ColumnMajorMatrixoperator= (const DenseVector< Real > &rhs)
 
Sets the values in this dense vector to the values on the RHS. More...
 
ColumnMajorMatrixoperator= (const ColumnMajorMatrix &rhs)
 Sets the values in this tensor to the values on the RHS Will also reshape this tensor if necessary. More...
 
ColumnMajorMatrix operator* (Real scalar) const
 Scalar multiplication of the ColumnMajorMatrix. More...
 
ColumnMajorMatrix operator* (const TypeVector< Real > &rhs) const
 Matrix Vector Multiplication of the libMesh TypeVector Type. More...
 
ColumnMajorMatrix operator* (const ColumnMajorMatrix &rhs) const
 Matrix Vector Multiplication of the TypeTensor Product. More...
 
ColumnMajorMatrix operator+ (const ColumnMajorMatrix &rhs) const
 Matrix Matrix Addition. More...
 
ColumnMajorMatrix operator- (const ColumnMajorMatrix &rhs) const
 Matrix Matrix Subtraction. More...
 
ColumnMajorMatrixoperator+= (const ColumnMajorMatrix &rhs)
 Matrix Matrix Addition plus assignment. More...
 
ColumnMajorMatrixoperator+= (const TypeTensor< Real > &rhs)
 Matrix Tensor Addition Plus Assignment. More...
 
ColumnMajorMatrixoperator-= (const ColumnMajorMatrix &rhs)
 Matrix Matrix Subtraction plus assignment. More...
 
ColumnMajorMatrix operator+ (Real scalar) const
 Scalar addition. More...
 
ColumnMajorMatrixoperator*= (Real scalar)
 Scalar Multiplication plus assignment. More...
 
ColumnMajorMatrixoperator/= (Real scalar)
 Scalar Division plus assignment. More...
 
ColumnMajorMatrixoperator+= (Real scalar)
 Scalar Addition plus assignment. More...
 
void checkSquareness () const
 Check if matrix is square. More...
 
void checkShapeEquality (const ColumnMajorMatrix &rhs) const
 Check if matrices are of same shape. More...
 
bool operator== (const ColumnMajorMatrix &rhs) const
 Equality operators. More...
 
bool operator!= (const ColumnMajorMatrix &rhs) const
 

Protected Attributes

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

Detailed Description

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 29 of file ColumnMajorMatrix.h.

Constructor & Destructor Documentation

◆ ColumnMajorMatrix() [1/6]

ColumnMajorMatrix::ColumnMajorMatrix ( const unsigned int  rows = LIBMESH_DIM,
const unsigned int  cols = LIBMESH_DIM 
)
explicit

Constructor that sets an initial number of entries and shape.

Defaults to creating the same size tensor as TensorValue

Definition at line 28 of file ColumnMajorMatrix.C.

29  : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
30 {
31  _values.resize(rows * cols);
32 }
unsigned int _n_entries
std::vector< Real > _values

◆ ColumnMajorMatrix() [2/6]

ColumnMajorMatrix::ColumnMajorMatrix ( const ColumnMajorMatrix rhs)

Copy Constructor defined in terms of operator=()

Definition at line 34 of file ColumnMajorMatrix.C.

35  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
36 {
37  *this = rhs;
38 }
unsigned int _n_entries

◆ ColumnMajorMatrix() [3/6]

ColumnMajorMatrix::ColumnMajorMatrix ( const TypeTensor< Real > &  tensor)
explicit

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

Definition at line 40 of file ColumnMajorMatrix.C.

41  : _n_rows(LIBMESH_DIM),
42  _n_cols(LIBMESH_DIM),
43  _n_entries(LIBMESH_DIM * LIBMESH_DIM),
44  _values(LIBMESH_DIM * LIBMESH_DIM)
45 {
46  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
47  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
48  (*this)(i, j) = rhs(i, j);
49 }
unsigned int _n_entries
std::vector< Real > _values

◆ ColumnMajorMatrix() [4/6]

ColumnMajorMatrix::ColumnMajorMatrix ( const DenseMatrix< Real > &  rhs)
explicit

Definition at line 51 of file ColumnMajorMatrix.C.

52  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
53 {
54  *this = rhs;
55 }
unsigned int _n_entries

◆ ColumnMajorMatrix() [5/6]

ColumnMajorMatrix::ColumnMajorMatrix ( const DenseVector< Real > &  rhs)
explicit

Definition at line 57 of file ColumnMajorMatrix.C.

58  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
59 {
60  *this = rhs;
61 }
unsigned int _n_entries

◆ ColumnMajorMatrix() [6/6]

ColumnMajorMatrix::ColumnMajorMatrix ( const TypeVector< Real > &  col1,
const TypeVector< Real > &  col2,
const TypeVector< Real > &  col3 
)

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

Definition at line 63 of file ColumnMajorMatrix.C.

66  : _n_rows(LIBMESH_DIM),
67  _n_cols(LIBMESH_DIM),
68  _n_entries(LIBMESH_DIM * LIBMESH_DIM),
69  _values(LIBMESH_DIM * LIBMESH_DIM)
70 {
71  unsigned int entry = 0;
72  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
73  _values[entry++] = col1(i);
74 
75  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
76  _values[entry++] = col2(i);
77 
78  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
79  _values[entry++] = col3(i);
80 }
unsigned int _n_entries
std::vector< Real > _values

Member Function Documentation

◆ abs()

ColumnMajorMatrix ColumnMajorMatrix::abs ( )
inline

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

Definition at line 461 of file ColumnMajorMatrix.h.

462 {
463  ColumnMajorMatrix & s = (*this);
464 
465  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
466 
467  for (unsigned int j = 0; j < _n_cols; j++)
468  for (unsigned int i = 0; i < _n_rows; i++)
469  ret_matrix(i, j) = std::abs(s(i, j));
470 
471  return ret_matrix;
472 }
This class defines a Tensor that can change its shape.

◆ addDiag()

void ColumnMajorMatrix::addDiag ( Real  value)
inline

Add to each of the diagonals the passsed in value.

Definition at line 484 of file ColumnMajorMatrix.h.

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

◆ checkShapeEquality()

void ColumnMajorMatrix::checkShapeEquality ( const ColumnMajorMatrix rhs) const

Check if matrices are of same shape.

Definition at line 299 of file ColumnMajorMatrix.C.

Referenced by doubleContraction(), inverse(), operator+(), operator+=(), operator-(), and operator-=().

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

◆ checkSquareness()

void ColumnMajorMatrix::checkSquareness ( ) const

Check if matrix is square.

Definition at line 292 of file ColumnMajorMatrix.C.

Referenced by addDiag(), eigen(), eigenNonsym(), exp(), identity(), inverse(), kronecker(), setDiag(), and tr().

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

◆ deviatoric()

ColumnMajorMatrix ColumnMajorMatrix::deviatoric ( )
inline

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

Definition at line 445 of file ColumnMajorMatrix.h.

446 {
447  ColumnMajorMatrix & s = (*this);
448 
449  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols), I(_n_rows, _n_cols);
450 
451  I.identity();
452 
453  for (unsigned int i = 0; i < _n_rows; i++)
454  for (unsigned int j = 0; j < _n_cols; j++)
455  ret_matrix(i, j) = s(i, j) - I(i, j) * (s.tr() / 3.0);
456 
457  return ret_matrix;
458 }
Real tr() const
The trace of the CMM.
This class defines a Tensor that can change its shape.

◆ doubleContraction()

Real ColumnMajorMatrix::doubleContraction ( const ColumnMajorMatrix rhs) const
inline

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

Definition at line 524 of file ColumnMajorMatrix.h.

Referenced by norm().

525 {
526  this->checkShapeEquality(rhs);
527 
528  Real value = 0;
529 
530  for (unsigned int j = 0; j < _n_cols; j++)
531  for (unsigned int i = 0; i < _n_rows; i++)
532  value += (*this)(i, j) * rhs(i, j);
533 
534  return value;
535 }
void checkShapeEquality(const ColumnMajorMatrix &rhs) const
Check if matrices are of same shape.

◆ eigen()

void ColumnMajorMatrix::eigen ( ColumnMajorMatrix eval,
ColumnMajorMatrix evec 
) const

Returns eigen system solve for a symmetric real matrix.

Definition at line 134 of file ColumnMajorMatrix.C.

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

◆ eigenNonsym()

void ColumnMajorMatrix::eigenNonsym ( ColumnMajorMatrix eval_real,
ColumnMajorMatrix eval_img,
ColumnMajorMatrix evec_right,
ColumnMajorMatrix eve_left 
) const

Returns eigen system solve for a non-symmetric real matrix.

Definition at line 168 of file ColumnMajorMatrix.C.

Referenced by exp().

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

◆ exp()

void ColumnMajorMatrix::exp ( ColumnMajorMatrix z) const

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

Definition at line 239 of file ColumnMajorMatrix.C.

240 {
241  this->checkSquareness();
242 
243  ColumnMajorMatrix a(*this);
244  ColumnMajorMatrix evals_real(_n_rows, 1), evals_img(_n_rows, 1), evals_real2(_n_rows, _n_cols);
245  ColumnMajorMatrix evec_right(_n_rows, _n_cols), evec_left(_n_rows, _n_cols);
246  ColumnMajorMatrix 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 }
void checkSquareness() const
Check if matrix is square.
This class defines a Tensor that can change its shape.

◆ fill() [1/3]

void ColumnMajorMatrix::fill ( TypeTensor< Real > &  tensor)
inline

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

Definition at line 397 of file ColumnMajorMatrix.h.

398 {
399  if (LIBMESH_DIM * LIBMESH_DIM != _n_entries)
400  mooseError(
401  "Cannot fill tensor! The ColumnMajorMatrix doesn't have the same number of entries!");
402 
403  for (unsigned int j = 0, index = 0; j < LIBMESH_DIM; ++j)
404  for (unsigned int i = 0; i < LIBMESH_DIM; ++i, ++index)
405  tensor(i, j) = _values[index];
406 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
unsigned int _n_entries
std::vector< Real > _values

◆ fill() [2/3]

void ColumnMajorMatrix::fill ( DenseMatrix< Real > &  rhs)
inline

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

Definition at line 409 of file ColumnMajorMatrix.h.

410 {
411  if (rhs.n() * rhs.m() != _n_entries)
412  mooseError(
413  "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
414 
415  for (unsigned int j = 0, index = 0; j < rhs.m(); ++j)
416  for (unsigned int i = 0; i < rhs.n(); ++i, ++index)
417  rhs(i, j) = _values[index];
418 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
unsigned int _n_entries
std::vector< Real > _values

◆ fill() [3/3]

void ColumnMajorMatrix::fill ( DenseVector< Real > &  rhs)
inline

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

Definition at line 421 of file ColumnMajorMatrix.h.

422 {
423  if (_n_rows != rhs.size() || _n_cols != 1)
424  mooseError("ColumnMajorMatrix and DenseVector must be the same shape for a fill!");
425 
426  for (unsigned int i = 0; i < _n_rows; ++i)
427  rhs(i) = (*this)(i);
428 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ identity()

void ColumnMajorMatrix::identity ( )
inline

Turn the matrix into an identity matrix.

Definition at line 513 of file ColumnMajorMatrix.h.

Referenced by deviatoric().

514 {
515  this->checkSquareness();
516 
517  zero();
518 
519  for (unsigned int i = 0; i < _n_rows; i++)
520  (*this)(i, i) = 1;
521 }
void zero()
Zero the matrix.
void checkSquareness() const
Check if matrix is square.

◆ inverse()

void ColumnMajorMatrix::inverse ( ColumnMajorMatrix invA) const

Returns inverse of a general matrix.

Definition at line 259 of file ColumnMajorMatrix.C.

260 {
261  this->checkSquareness();
262  this->checkShapeEquality(invA);
263 
264  int n = _n_rows;
265  int return_value = 0;
266 
267  invA = *this;
268 
269  std::vector<PetscBLASInt> ipiv(n);
270  Real * invA_data = invA.rawData();
271 
272  int buffer_size = n * 64;
273  std::vector<Real> buffer(buffer_size);
274 
275 #if !defined(LIBMESH_HAVE_PETSC)
276  FORTRAN_CALL(dgetrf)(&n, &n, invA_data, &n, &ipiv[0], &return_value);
277 #else
278  LAPACKgetrf_(&n, &n, invA_data, &n, &ipiv[0], &return_value);
279 #endif
280 
281 #if !defined(LIBMESH_HAVE_PETSC) || PETSC_VERSION_LESS_THAN(3, 5, 0)
282  FORTRAN_CALL(dgetri)(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
283 #else
284  LAPACKgetri_(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
285 #endif
286 
287  if (return_value)
288  mooseException("Error in LAPACK matrix-inverse calculation");
289 }
Real * rawData()
Returns a reference to the raw data pointer.
void checkShapeEquality(const ColumnMajorMatrix &rhs) const
Check if matrices are of same shape.
void checkSquareness() const
Check if matrix is square.
unsigned int n() const
Returns the number of rows.
void FORTRAN_CALL() dgetri(...)
void FORTRAN_CALL() dgetrf(...)

◆ kronecker()

ColumnMajorMatrix ColumnMajorMatrix::kronecker ( const ColumnMajorMatrix rhs) const

Kronecker Product.

Definition at line 83 of file ColumnMajorMatrix.C.

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

◆ m()

unsigned int ColumnMajorMatrix::m ( ) const
inline

Returns the number of columns.

Definition at line 550 of file ColumnMajorMatrix.h.

Referenced by dataLoad(), dataStore(), and RankTwoTensor::operator=().

551 {
552  return _n_cols;
553 }

◆ n()

unsigned int ColumnMajorMatrix::n ( ) const
inline

Returns the number of rows.

Definition at line 544 of file ColumnMajorMatrix.h.

Referenced by dataLoad(), dataStore(), eigen(), eigenNonsym(), inverse(), and RankTwoTensor::operator=().

545 {
546  return _n_rows;
547 }

◆ norm()

Real ColumnMajorMatrix::norm ( )
inline

The Euclidean norm of the matrix.

Definition at line 538 of file ColumnMajorMatrix.h.

539 {
540  return std::sqrt(doubleContraction(*this));
541 }
Real doubleContraction(const ColumnMajorMatrix &rhs) const
Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)

◆ numEntries()

unsigned int ColumnMajorMatrix::numEntries ( ) const
inline

The total number of entries in the Tensor.

i.e. cols * rows

Definition at line 326 of file ColumnMajorMatrix.h.

327 {
328  return _n_entries;
329 }
unsigned int _n_entries

◆ operator!=()

bool ColumnMajorMatrix::operator!= ( const ColumnMajorMatrix rhs) const
inline

Definition at line 768 of file ColumnMajorMatrix.h.

769 {
770  return !(*this == rhs);
771 }

◆ operator()() [1/2]

Real & ColumnMajorMatrix::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 349 of file ColumnMajorMatrix.h.

350 {
351  if ((i * j) >= _n_entries)
352  mooseError("Reference outside of ColumnMajorMatrix bounds!");
353 
354  // Row major indexing!
355  return _values[(j * _n_rows) + i];
356 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
unsigned int _n_entries
std::vector< Real > _values

◆ operator()() [2/2]

Real ColumnMajorMatrix::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 ColumnMajorMatrix.

Definition at line 359 of file ColumnMajorMatrix.h.

360 {
361  if ((i * j) >= _n_entries)
362  mooseError("Reference outside of ColumnMajorMatrix bounds!");
363 
364  // Row major indexing!
365  return _values[(j * _n_rows) + i];
366 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
unsigned int _n_entries
std::vector< Real > _values

◆ operator*() [1/3]

ColumnMajorMatrix ColumnMajorMatrix::operator* ( Real  scalar) const
inline

Scalar multiplication of the ColumnMajorMatrix.

Definition at line 605 of file ColumnMajorMatrix.h.

606 {
607  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
608 
609  for (unsigned int i = 0; i < _n_entries; i++)
610  ret_matrix._values[i] = _values[i] * scalar;
611 
612  return ret_matrix;
613 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values

◆ operator*() [2/3]

ColumnMajorMatrix ColumnMajorMatrix::operator* ( const TypeVector< Real > &  rhs) const
inline

Matrix Vector Multiplication of the libMesh TypeVector Type.

Definition at line 615 of file ColumnMajorMatrix.h.

616 {
617  if (_n_cols != LIBMESH_DIM)
618  mooseError("Cannot perform matvec operation! The column dimension of "
619  "the ColumnMajorMatrix does not match the TypeVector!");
620 
621  ColumnMajorMatrix ret_matrix(_n_rows, 1);
622 
623  for (unsigned int i = 0; i < _n_rows; ++i)
624  for (unsigned int j = 0; j < _n_cols; ++j)
625  ret_matrix._values[i] += (*this)(i, j) * rhs(j);
626 
627  return ret_matrix;
628 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
This class defines a Tensor that can change its shape.

◆ operator*() [3/3]

ColumnMajorMatrix ColumnMajorMatrix::operator* ( const ColumnMajorMatrix 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 646 of file ColumnMajorMatrix.h.

647 {
648  if (_n_cols != rhs._n_rows)
649  mooseError(
650  "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
651 
652  ColumnMajorMatrix ret_matrix(_n_rows, rhs._n_cols);
653 
654  for (unsigned int i = 0; i < ret_matrix._n_rows; ++i)
655  for (unsigned int j = 0; j < ret_matrix._n_cols; ++j)
656  for (unsigned int k = 0; k < _n_cols; ++k)
657  ret_matrix(i, j) += (*this)(i, k) * rhs(k, j);
658 
659  return ret_matrix;
660 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
This class defines a Tensor that can change its shape.

◆ operator*=()

ColumnMajorMatrix & ColumnMajorMatrix::operator*= ( Real  scalar)
inline

Scalar Multiplication plus assignment.

Definition at line 736 of file ColumnMajorMatrix.h.

737 {
738  for (unsigned int i = 0; i < _n_entries; i++)
739  _values[i] *= scalar;
740  return *this;
741 }
unsigned int _n_entries
std::vector< Real > _values

◆ operator+() [1/2]

ColumnMajorMatrix ColumnMajorMatrix::operator+ ( const ColumnMajorMatrix rhs) const
inline

Matrix Matrix Addition.

Definition at line 663 of file ColumnMajorMatrix.h.

664 {
665  this->checkShapeEquality(rhs);
666 
667  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
668 
669  for (unsigned int i = 0; i < _n_entries; i++)
670  ret_matrix._values[i] = _values[i] + rhs._values[i];
671 
672  return ret_matrix;
673 }
void checkShapeEquality(const ColumnMajorMatrix &rhs) const
Check if matrices are of same shape.
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values

◆ operator+() [2/2]

ColumnMajorMatrix ColumnMajorMatrix::operator+ ( Real  scalar) const
inline

Scalar addition.

Definition at line 725 of file ColumnMajorMatrix.h.

726 {
727  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
728 
729  for (unsigned int i = 0; i < _n_entries; i++)
730  ret_matrix._values[i] = _values[i] + scalar;
731 
732  return ret_matrix;
733 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values

◆ operator+=() [1/3]

ColumnMajorMatrix & ColumnMajorMatrix::operator+= ( const ColumnMajorMatrix 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 689 of file ColumnMajorMatrix.h.

690 {
691  this->checkShapeEquality(rhs);
692 
693  for (unsigned int i = 0; i < _n_entries; i++)
694  _values[i] += rhs._values[i];
695 
696  return *this;
697 }
void checkShapeEquality(const ColumnMajorMatrix &rhs) const
Check if matrices are of same shape.
unsigned int _n_entries
std::vector< Real > _values

◆ operator+=() [2/3]

ColumnMajorMatrix & ColumnMajorMatrix::operator+= ( const TypeTensor< Real > &  rhs)
inline

Matrix Tensor Addition Plus Assignment.

Definition at line 700 of file ColumnMajorMatrix.h.

701 {
702  if ((_n_rows != LIBMESH_DIM) || (_n_cols != LIBMESH_DIM))
703  mooseError("Cannot perform matrix addition and assignment! The shapes of the two operands are "
704  "not compatible!");
705 
706  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
707  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
708  (*this)(i, j) += rhs(i, j);
709 
710  return *this;
711 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ operator+=() [3/3]

ColumnMajorMatrix & ColumnMajorMatrix::operator+= ( Real  scalar)
inline

Scalar Addition plus assignment.

Definition at line 752 of file ColumnMajorMatrix.h.

753 {
754  for (unsigned int i = 0; i < _n_entries; i++)
755  _values[i] += scalar;
756  return *this;
757 }
unsigned int _n_entries
std::vector< Real > _values

◆ operator-()

ColumnMajorMatrix ColumnMajorMatrix::operator- ( const ColumnMajorMatrix rhs) const
inline

Matrix Matrix Subtraction.

Definition at line 676 of file ColumnMajorMatrix.h.

677 {
678  this->checkShapeEquality(rhs);
679 
680  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
681 
682  for (unsigned int i = 0; i < _n_entries; i++)
683  ret_matrix._values[i] = _values[i] - rhs._values[i];
684 
685  return ret_matrix;
686 }
void checkShapeEquality(const ColumnMajorMatrix &rhs) const
Check if matrices are of same shape.
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values

◆ operator-=()

ColumnMajorMatrix & ColumnMajorMatrix::operator-= ( const ColumnMajorMatrix 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 714 of file ColumnMajorMatrix.h.

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

◆ operator/=()

ColumnMajorMatrix & ColumnMajorMatrix::operator/= ( Real  scalar)
inline

Scalar Division plus assignment.

Definition at line 744 of file ColumnMajorMatrix.h.

745 {
746  for (unsigned int i = 0; i < _n_entries; i++)
747  _values[i] /= scalar;
748  return *this;
749 }
unsigned int _n_entries
std::vector< Real > _values

◆ operator=() [1/4]

ColumnMajorMatrix & ColumnMajorMatrix::operator= ( const TypeTensor< Real > &  rhs)
inline

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

Will also reshape this tensor if necessary.

Definition at line 568 of file ColumnMajorMatrix.h.

569 {
570  // Resize the tensor if necessary
571  if ((LIBMESH_DIM * LIBMESH_DIM) != _n_entries)
572  {
573  _n_entries = LIBMESH_DIM * LIBMESH_DIM;
574  _values.resize(_n_entries);
575  }
576 
577  // Make sure the shape is correct
578  reshape(LIBMESH_DIM, LIBMESH_DIM);
579 
580  ColumnMajorMatrix & s = (*this);
581 
582  // Copy the values
583  for (unsigned int j = 0; j < _n_cols; j++)
584  for (unsigned int i = 0; i < _n_cols; i++)
585  s(i, j) = rhs(i, j);
586 
587  return *this;
588 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.

◆ operator=() [2/4]

ColumnMajorMatrix & ColumnMajorMatrix::operator= ( const DenseMatrix< Real > &  rhs)


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

Will also reshape this tensor if necessary.

Definition at line 99 of file ColumnMajorMatrix.C.

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

◆ operator=() [3/4]

ColumnMajorMatrix & ColumnMajorMatrix::operator= ( const DenseVector< Real > &  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:208
unsigned int _n_entries
std::vector< Real > _values

◆ operator=() [4/4]

ColumnMajorMatrix & ColumnMajorMatrix::operator= ( const ColumnMajorMatrix rhs)
inline

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

Definition at line 591 of file ColumnMajorMatrix.h.

592 {
593  _n_rows = rhs._n_rows;
594  _n_cols = rhs._n_cols;
595  _n_entries = rhs._n_entries;
596 
597  _values.resize(_n_entries);
598 
599  for (unsigned int i = 0; i < _n_entries; i++)
600  _values[i] = rhs._values[i];
601 
602  return *this;
603 }
unsigned int _n_entries
std::vector< Real > _values

◆ operator==()

bool ColumnMajorMatrix::operator== ( const ColumnMajorMatrix rhs) const
inline

Equality operators.

Definition at line 760 of file ColumnMajorMatrix.h.

761 {
762  if (_n_entries != rhs._n_entries || _n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
763  return false;
764  return std::equal(_values.begin(), _values.end(), rhs._values.begin());
765 }
unsigned int _n_entries
std::vector< Real > _values

◆ print()

void ColumnMajorMatrix::print ( )
inline

Print the tensor.

Definition at line 369 of file ColumnMajorMatrix.h.

370 {
371  ColumnMajorMatrix & s = (*this);
372 
373  for (unsigned int i = 0; i < _n_rows; i++)
374  {
375  for (unsigned int j = 0; j < _n_cols; j++)
376  Moose::out << std::setw(15) << s(i, j) << " ";
377 
378  Moose::out << std::endl;
379  }
380 }
This class defines a Tensor that can change its shape.

◆ print_scientific()

void ColumnMajorMatrix::print_scientific ( std::ostream &  os)
inline

Prints to file.

Definition at line 383 of file ColumnMajorMatrix.h.

384 {
385  ColumnMajorMatrix & s = (*this);
386 
387  for (unsigned int i = 0; i < _n_rows; i++)
388  {
389  for (unsigned int j = 0; j < _n_cols; j++)
390  os << std::setw(15) << std::scientific << std::setprecision(8) << s(i, j) << " ";
391 
392  os << std::endl;
393  }
394 }
This class defines a Tensor that can change its shape.

◆ rawData() [1/2]

Real * ColumnMajorMatrix::rawData ( )
inline

Returns a reference to the raw data pointer.

Definition at line 556 of file ColumnMajorMatrix.h.

Referenced by eigen(), eigenNonsym(), inverse(), and RankTwoTensor::operator=().

557 {
558  return &_values[0];
559 }
std::vector< Real > _values

◆ rawData() [2/2]

const Real * ColumnMajorMatrix::rawData ( ) const
inline

Definition at line 562 of file ColumnMajorMatrix.h.

563 {
564  return &_values[0];
565 }
std::vector< Real > _values

◆ reshape()

void ColumnMajorMatrix::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 332 of file ColumnMajorMatrix.h.

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

333 {
334  if (cols * rows == _n_entries)
335  {
336  _n_rows = rows;
337  _n_cols = cols;
338  }
339  else
340  {
341  _n_rows = rows;
342  _n_cols = cols;
344  _values.resize(_n_entries);
345  }
346 }
unsigned int _n_entries
std::vector< Real > _values

◆ setDiag()

void ColumnMajorMatrix::setDiag ( Real  value)
inline

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

Definition at line 475 of file ColumnMajorMatrix.h.

476 {
477  this->checkSquareness();
478 
479  for (unsigned int i = 0; i < _n_rows; i++)
480  (*this)(i, i) = value;
481 }
void checkSquareness() const
Check if matrix is square.

◆ tr()

Real ColumnMajorMatrix::tr ( ) const
inline

The trace of the CMM.

Definition at line 493 of file ColumnMajorMatrix.h.

Referenced by deviatoric().

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

◆ transpose()

ColumnMajorMatrix ColumnMajorMatrix::transpose ( ) const
inline

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

Definition at line 431 of file ColumnMajorMatrix.h.

432 {
433  const ColumnMajorMatrix & s = (*this);
434 
435  ColumnMajorMatrix ret_matrix(_n_cols, _n_rows);
436 
437  for (unsigned int i = 0; i < _n_rows; i++)
438  for (unsigned int j = 0; j < _n_cols; j++)
439  ret_matrix(j, i) = s(i, j);
440 
441  return ret_matrix;
442 }
This class defines a Tensor that can change its shape.

◆ zero()

void ColumnMajorMatrix::zero ( )
inline

Zero the matrix.

Definition at line 506 of file ColumnMajorMatrix.h.

Referenced by identity().

507 {
508  for (unsigned int i = 0; i < _n_entries; i++)
509  _values[i] = 0;
510 }
unsigned int _n_entries
std::vector< Real > _values

Member Data Documentation

◆ _n_cols

unsigned int ColumnMajorMatrix::_n_cols
protected

◆ _n_entries

unsigned int ColumnMajorMatrix::_n_entries
protected

◆ _n_rows

unsigned int ColumnMajorMatrix::_n_rows
protected

◆ _values

std::vector<Real> ColumnMajorMatrix::_values
protected

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