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

Constructor & Destructor Documentation

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 33 of file ColumnMajorMatrix.C.

34  : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
35 {
36  _values.resize(rows * cols);
37 }
unsigned int _n_entries
std::vector< Real > _values
ColumnMajorMatrix::ColumnMajorMatrix ( const ColumnMajorMatrix rhs)

Copy Constructor defined in terms of operator=()

Definition at line 39 of file ColumnMajorMatrix.C.

40  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
41 {
42  *this = rhs;
43 }
unsigned int _n_entries
ColumnMajorMatrix::ColumnMajorMatrix ( const TypeTensor< Real > &  tensor)
explicit

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

Definition at line 45 of file ColumnMajorMatrix.C.

46  : _n_rows(LIBMESH_DIM),
47  _n_cols(LIBMESH_DIM),
48  _n_entries(LIBMESH_DIM * LIBMESH_DIM),
49  _values(LIBMESH_DIM * LIBMESH_DIM)
50 {
51  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
52  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
53  (*this)(i, j) = rhs(i, j);
54 }
unsigned int _n_entries
std::vector< Real > _values
ColumnMajorMatrix::ColumnMajorMatrix ( const DenseMatrix< Real > &  rhs)
explicit

Definition at line 56 of file ColumnMajorMatrix.C.

57  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
58 {
59  *this = rhs;
60 }
unsigned int _n_entries
ColumnMajorMatrix::ColumnMajorMatrix ( const DenseVector< Real > &  rhs)
explicit

Definition at line 62 of file ColumnMajorMatrix.C.

63  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
64 {
65  *this = rhs;
66 }
unsigned int _n_entries
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 68 of file ColumnMajorMatrix.C.

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

Member Function Documentation

ColumnMajorMatrix ColumnMajorMatrix::abs ( )
inline

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

Definition at line 453 of file ColumnMajorMatrix.h.

454 {
455  ColumnMajorMatrix & s = (*this);
456 
457  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
458 
459  for (unsigned int j = 0; j < _n_cols; j++)
460  for (unsigned int i = 0; i < _n_rows; i++)
461  ret_matrix(i, j) = std::abs(s(i, j));
462 
463  return ret_matrix;
464 }
This class defines a Tensor that can change its shape.
void ColumnMajorMatrix::addDiag ( Real  value)
inline

Add to each of the diagonals the passsed in value.

Definition at line 476 of file ColumnMajorMatrix.h.

477 {
478  mooseAssert(_n_rows == _n_cols, "Cannot add to the diagonal of a non-square matrix!");
479 
480  for (unsigned int i = 0; i < _n_rows; i++)
481  (*this)(i, i) += value;
482 }
ColumnMajorMatrix ColumnMajorMatrix::deviatoric ( )
inline

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

Definition at line 437 of file ColumnMajorMatrix.h.

438 {
439  ColumnMajorMatrix & s = (*this);
440 
441  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols), I(_n_rows, _n_cols);
442 
443  I.identity();
444 
445  for (unsigned int i = 0; i < _n_rows; i++)
446  for (unsigned int j = 0; j < _n_cols; j++)
447  ret_matrix(i, j) = s(i, j) - I(i, j) * (s.tr() / 3.0);
448 
449  return ret_matrix;
450 }
Real tr() const
The trace of the CMM.
This class defines a Tensor that can change its shape.
Real ColumnMajorMatrix::doubleContraction ( const ColumnMajorMatrix rhs) const
inline

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

Definition at line 516 of file ColumnMajorMatrix.h.

Referenced by norm().

517 {
518  mooseAssert(_n_rows == rhs._n_cols && _n_cols == rhs._n_rows,
519  "Matrices must be the same shape for a double contraction!");
520 
521  Real value = 0;
522 
523  for (unsigned int j = 0; j < _n_cols; j++)
524  for (unsigned int i = 0; i < _n_rows; i++)
525  value += (*this)(i, j) * rhs(i, j);
526 
527  return value;
528 }
void ColumnMajorMatrix::eigen ( ColumnMajorMatrix eval,
ColumnMajorMatrix evec 
) const

Returns eigen system solve for a symmetric real matrix.

Definition at line 140 of file ColumnMajorMatrix.C.

141 {
142  mooseAssert(_n_rows == _n_cols, "Cannot solve eigen system of a non-square matrix!");
143 
144  char jobz = 'V';
145  char uplo = 'U';
146  int n = _n_rows;
147  int return_value = 0;
148 
149  eval._n_rows = _n_rows;
150  eval._n_cols = 1;
151  eval._n_entries = _n_rows;
152  eval._values.resize(_n_rows);
153 
154  evec = *this;
155 
156  Real * eval_data = eval.rawData();
157  Real * evec_data = evec.rawData();
158 
159  int buffer_size = n * 64;
160  std::vector<Real> buffer(buffer_size);
161 
162 #if !defined(LIBMESH_HAVE_PETSC)
163  FORTRAN_CALL(dsyev)
164  (&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
165 #else
166  LAPACKsyev_(&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
167 #endif
168 
169  if (return_value)
170  mooseError("error in lapack eigen solve");
171 }
unsigned int n() const
Returns the number of rows.
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:182
unsigned int _n_entries
std::vector< Real > _values
void FORTRAN_CALL() dsyev(...)
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 174 of file ColumnMajorMatrix.C.

Referenced by exp().

178 {
179  mooseAssert(_n_rows == _n_cols, "Cannot solve eigen system of a non-square matrix!");
180 
181  ColumnMajorMatrix a(*this);
182 
183  char jobvl = 'V';
184  char jobvr = 'V';
185  int n = _n_rows;
186  int 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  Real * a_data = a.rawData();
199  Real * eval_r = eval_real.rawData();
200  Real * eval_i = eval_img.rawData();
201  Real * evec_ri = evec_right.rawData();
202  Real * evec_le = evec_left.rawData();
203 
204  int buffer_size = n * 64;
205  std::vector<Real> buffer(buffer_size);
206 
207 #if !defined(LIBMESH_HAVE_PETSC)
208  FORTRAN_CALL(dgeev)
209  (&jobvl,
210  &jobvr,
211  &n,
212  a_data,
213  &n,
214  eval_r,
215  eval_i,
216  evec_le,
217  &n,
218  evec_ri,
219  &n,
220  &buffer[0],
221  &buffer_size,
222  &return_value);
223 #else
224  LAPACKgeev_(&jobvl,
225  &jobvr,
226  &n,
227  a_data,
228  &n,
229  eval_r,
230  eval_i,
231  evec_le,
232  &n,
233  evec_ri,
234  &n,
235  &buffer[0],
236  &buffer_size,
237  &return_value);
238 #endif
239 
240  if (return_value)
241  mooseError("error in lapack eigen solve");
242 }
unsigned int n() const
Returns the number of rows.
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:182
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values
void FORTRAN_CALL() dgeev(...)
void ColumnMajorMatrix::exp ( ColumnMajorMatrix z) const

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

Definition at line 245 of file ColumnMajorMatrix.C.

246 {
247  mooseAssert(_n_rows == _n_cols, "The Matrix being exponentiated is not square");
248  ColumnMajorMatrix a(*this);
249  ColumnMajorMatrix evals_real(_n_rows, 1), evals_img(_n_rows, 1), evals_real2(_n_rows, _n_cols);
250  ColumnMajorMatrix evec_right(_n_rows, _n_cols), evec_left(_n_rows, _n_cols);
251  ColumnMajorMatrix evec_right_inverse(_n_rows, _n_cols);
252 
253  a.eigenNonsym(evals_real, evals_img, evec_right, evec_left);
254 
255  for (unsigned int i = 0; i < _n_rows; i++)
256  evals_real2(i, i) = std::exp(evals_real(i, 0));
257 
258  evec_right.inverse(evec_right_inverse);
259 
260  z = evec_right * evals_real2 * evec_right_inverse;
261 }
This class defines a Tensor that can change its shape.
void ColumnMajorMatrix::fill ( TypeTensor< Real > &  tensor)
inline

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

Definition at line 390 of file ColumnMajorMatrix.h.

391 {
392  mooseAssert(
393  LIBMESH_DIM * LIBMESH_DIM == _n_entries,
394  "Cannot fill tensor! The ColumnMajorMatrix doesn't have the same number of entries!");
395 
396  for (unsigned int j = 0, index = 0; j < LIBMESH_DIM; ++j)
397  for (unsigned int i = 0; i < LIBMESH_DIM; ++i, ++index)
398  tensor(i, j) = _values[index];
399 }
unsigned int _n_entries
std::vector< Real > _values
void ColumnMajorMatrix::fill ( DenseMatrix< Real > &  rhs)
inline

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

Definition at line 402 of file ColumnMajorMatrix.h.

403 {
404  mooseAssert(
405  rhs.n() * rhs.m() == _n_entries,
406  "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
407 
408  for (unsigned int j = 0, index = 0; j < rhs.m(); ++j)
409  for (unsigned int i = 0; i < rhs.n(); ++i, ++index)
410  rhs(i, j) = _values[index];
411 }
unsigned int _n_entries
std::vector< Real > _values
void ColumnMajorMatrix::fill ( DenseVector< Real > &  rhs)
inline

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

Definition at line 414 of file ColumnMajorMatrix.h.

415 {
416  mooseAssert(_n_rows == rhs.size(), "Vectors must be the same shape for a fill!");
417 
418  for (unsigned int i = 0; i < _n_rows; ++i)
419  rhs(i) = (*this)(i);
420 }
void ColumnMajorMatrix::identity ( )
inline

Turn the matrix into an identity matrix.

Definition at line 505 of file ColumnMajorMatrix.h.

Referenced by deviatoric().

506 {
507  mooseAssert(_n_rows == _n_cols, "Cannot set the diagonal of a non-square matrix!");
508 
509  zero();
510 
511  for (unsigned int i = 0; i < _n_rows; i++)
512  (*this)(i, i) = 1;
513 }
void zero()
Zero the matrix.
void ColumnMajorMatrix::inverse ( ColumnMajorMatrix invA) const

Returns inverse of a general matrix.

Definition at line 264 of file ColumnMajorMatrix.C.

265 {
266  mooseAssert(_n_rows == _n_cols, "Cannot solve for inverse of a non-square matrix!");
267  mooseAssert(_n_rows == invA._n_cols && _n_cols == invA._n_rows,
268  "Matrices must be the same size for matrix inverse!");
269 
270  int n = _n_rows;
271  int return_value = 0;
272 
273  invA = *this;
274 
275  std::vector<PetscBLASInt> ipiv(n);
276  Real * invA_data = invA.rawData();
277 
278  int buffer_size = n * 64;
279  std::vector<Real> buffer(buffer_size);
280 
281 #if !defined(LIBMESH_HAVE_PETSC)
282  FORTRAN_CALL(dgetrf)(&n, &n, invA_data, &n, &ipiv[0], &return_value);
283 #else
284  LAPACKgetrf_(&n, &n, invA_data, &n, &ipiv[0], &return_value);
285 #endif
286 
287 #if !defined(LIBMESH_HAVE_PETSC) || PETSC_VERSION_LESS_THAN(3, 5, 0)
288  FORTRAN_CALL(dgetri)(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
289 #else
290  LAPACKgetri_(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
291 #endif
292 
293  if (return_value)
294  mooseException("Error in LAPACK matrix-inverse calculation");
295 }
unsigned int n() const
Returns the number of rows.
Real * rawData()
Returns a reference to the raw data pointer.
void FORTRAN_CALL() dgetri(...)
void FORTRAN_CALL() dgetrf(...)
ColumnMajorMatrix ColumnMajorMatrix::kronecker ( const ColumnMajorMatrix rhs) const

Kronecker Product.

Definition at line 88 of file ColumnMajorMatrix.C.

89 {
90  mooseAssert(_n_rows == rhs._n_cols && _n_cols == rhs._n_rows,
91  "Matrices must be the same shape for a kronecker product!");
92 
93  ColumnMajorMatrix ret_matrix(_n_rows * _n_rows, rhs._n_cols * rhs._n_cols);
94 
95  for (unsigned int i = 0; i < _n_rows; i++)
96  for (unsigned int j = 0; j < _n_cols; j++)
97  for (unsigned int k = 0; k < rhs._n_rows; k++)
98  for (unsigned int l = 0; l < rhs._n_cols; l++)
99  ret_matrix(((i * _n_rows) + k), ((j * _n_cols) + l)) = (*this)(i, j) * rhs(k, l);
100 
101  return ret_matrix;
102 }
This class defines a Tensor that can change its shape.
unsigned int ColumnMajorMatrix::m ( ) const
inline

Returns the number of columns.

Definition at line 543 of file ColumnMajorMatrix.h.

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

544 {
545  return _n_cols;
546 }
unsigned int ColumnMajorMatrix::n ( ) const
inline

Returns the number of rows.

Definition at line 537 of file ColumnMajorMatrix.h.

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

538 {
539  return _n_rows;
540 }
Real ColumnMajorMatrix::norm ( )
inline

The Euclidean norm of the matrix.

Definition at line 531 of file ColumnMajorMatrix.h.

532 {
533  return std::sqrt(doubleContraction(*this));
534 }
Real doubleContraction(const ColumnMajorMatrix &rhs) const
Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)
unsigned int ColumnMajorMatrix::numEntries ( ) const
inline

The total number of entries in the Tensor.

i.e. cols * rows

Definition at line 321 of file ColumnMajorMatrix.h.

322 {
323  return _n_entries;
324 }
unsigned int _n_entries
bool ColumnMajorMatrix::operator!= ( const ColumnMajorMatrix rhs) const
inline

Definition at line 769 of file ColumnMajorMatrix.h.

770 {
771  return !(*this == rhs);
772 }
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 344 of file ColumnMajorMatrix.h.

345 {
346  mooseAssert((i * j) < _n_entries, "Reference outside of ColumnMajorMatrix bounds!");
347 
348  // Row major indexing!
349  return _values[(j * _n_rows) + i];
350 }
unsigned int _n_entries
std::vector< Real > _values
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 353 of file ColumnMajorMatrix.h.

354 {
355  mooseAssert((i * j) < _n_entries, "Reference outside of ColumnMajorMatrix bounds!");
356 
357  // Row major indexing!
358  return _values[(j * _n_rows) + i];
359 }
unsigned int _n_entries
std::vector< Real > _values
ColumnMajorMatrix ColumnMajorMatrix::operator* ( Real  scalar) const
inline

Scalar multiplication of the ColumnMajorMatrix.

Definition at line 598 of file ColumnMajorMatrix.h.

599 {
600  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
601 
602  for (unsigned int i = 0; i < _n_entries; i++)
603  ret_matrix._values[i] = _values[i] * scalar;
604 
605  return ret_matrix;
606 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values
ColumnMajorMatrix ColumnMajorMatrix::operator* ( const TypeVector< Real > &  rhs) const
inline

Matrix Vector Multiplication of the libMesh TypeVector Type.

Definition at line 608 of file ColumnMajorMatrix.h.

609 {
610  mooseAssert(_n_cols == LIBMESH_DIM,
611  "Cannot perform matvec operation! The column dimension of "
612  "the ColumnMajorMatrix does not match the TypeVector!");
613 
614  ColumnMajorMatrix ret_matrix(_n_rows, 1);
615 
616  for (unsigned int i = 0; i < _n_rows; ++i)
617  for (unsigned int j = 0; j < _n_cols; ++j)
618  ret_matrix._values[i] += (*this)(i, j) * rhs(j);
619 
620  return ret_matrix;
621 }
This class defines a Tensor that can change its shape.
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 639 of file ColumnMajorMatrix.h.

640 {
641  mooseAssert(
642  _n_cols == rhs._n_rows,
643  "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
644 
645  ColumnMajorMatrix ret_matrix(_n_rows, rhs._n_cols);
646 
647  for (unsigned int i = 0; i < ret_matrix._n_rows; ++i)
648  for (unsigned int j = 0; j < ret_matrix._n_cols; ++j)
649  for (unsigned int k = 0; k < _n_cols; ++k)
650  ret_matrix(i, j) += (*this)(i, k) * rhs(k, j);
651 
652  return ret_matrix;
653 }
This class defines a Tensor that can change its shape.
ColumnMajorMatrix & ColumnMajorMatrix::operator*= ( Real  scalar)
inline

Scalar Multiplication plus assignment.

Definition at line 737 of file ColumnMajorMatrix.h.

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

Matrix Matrix Addition.

Definition at line 656 of file ColumnMajorMatrix.h.

657 {
658  mooseAssert(
659  (_n_rows == rhs._n_rows) && (_n_cols == rhs._n_cols),
660  "Cannot perform matrix addition! The shapes of the two operands are not compatible!");
661 
662  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
663 
664  for (unsigned int i = 0; i < _n_entries; i++)
665  ret_matrix._values[i] = _values[i] + rhs._values[i];
666 
667  return ret_matrix;
668 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values
ColumnMajorMatrix ColumnMajorMatrix::operator+ ( Real  scalar) const
inline

Scalar addition.

Definition at line 726 of file ColumnMajorMatrix.h.

727 {
728  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
729 
730  for (unsigned int i = 0; i < _n_entries; i++)
731  ret_matrix._values[i] = _values[i] + scalar;
732 
733  return ret_matrix;
734 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values
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 686 of file ColumnMajorMatrix.h.

687 {
688  mooseAssert((_n_rows == rhs._n_rows) && (_n_cols == rhs._n_cols),
689  "Cannot perform matrix addition and assignment! The shapes of the two operands are "
690  "not compatible!");
691 
692  for (unsigned int i = 0; i < _n_entries; i++)
693  _values[i] += rhs._values[i];
694 
695  return *this;
696 }
unsigned int _n_entries
std::vector< Real > _values
ColumnMajorMatrix & ColumnMajorMatrix::operator+= ( const TypeTensor< Real > &  rhs)
inline

Matrix Tensor Addition Plus Assignment.

Definition at line 699 of file ColumnMajorMatrix.h.

700 {
701  mooseAssert((_n_rows == LIBMESH_DIM) && (_n_cols == LIBMESH_DIM),
702  "Cannot perform matrix addition and assignment! The shapes of the two operands are "
703  "not compatible!");
704 
705  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
706  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
707  (*this)(i, j) += rhs(i, j);
708 
709  return *this;
710 }
ColumnMajorMatrix & ColumnMajorMatrix::operator+= ( Real  scalar)
inline

Scalar Addition plus assignment.

Definition at line 753 of file ColumnMajorMatrix.h.

754 {
755  for (unsigned int i = 0; i < _n_entries; i++)
756  _values[i] += scalar;
757  return *this;
758 }
unsigned int _n_entries
std::vector< Real > _values
ColumnMajorMatrix ColumnMajorMatrix::operator- ( const ColumnMajorMatrix rhs) const
inline

Matrix Matrix Subtraction.

Definition at line 671 of file ColumnMajorMatrix.h.

672 {
673  mooseAssert(
674  (_n_rows == rhs._n_rows) && (_n_cols == rhs._n_cols),
675  "Cannot perform matrix addition! The shapes of the two operands are not compatible!");
676 
677  ColumnMajorMatrix ret_matrix(_n_rows, _n_cols);
678 
679  for (unsigned int i = 0; i < _n_entries; i++)
680  ret_matrix._values[i] = _values[i] - rhs._values[i];
681 
682  return ret_matrix;
683 }
unsigned int _n_entries
This class defines a Tensor that can change its shape.
std::vector< Real > _values
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 713 of file ColumnMajorMatrix.h.

714 {
715  mooseAssert((_n_rows == rhs._n_rows) && (_n_cols == rhs._n_cols),
716  "Cannot perform matrix subtraction and assignment! The shapes of the two operands "
717  "are not compatible!");
718 
719  for (unsigned int i = 0; i < _n_entries; i++)
720  _values[i] -= rhs._values[i];
721 
722  return *this;
723 }
unsigned int _n_entries
std::vector< Real > _values
ColumnMajorMatrix & ColumnMajorMatrix::operator/= ( Real  scalar)
inline

Scalar Division plus assignment.

Definition at line 745 of file ColumnMajorMatrix.h.

746 {
747  for (unsigned int i = 0; i < _n_entries; i++)
748  _values[i] /= scalar;
749  return *this;
750 }
unsigned int _n_entries
std::vector< Real > _values
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 561 of file ColumnMajorMatrix.h.

562 {
563  // Resize the tensor if necessary
564  if ((LIBMESH_DIM * LIBMESH_DIM) != _n_entries)
565  {
566  _n_entries = LIBMESH_DIM * LIBMESH_DIM;
567  _values.resize(_n_entries);
568  }
569 
570  // Make sure the shape is correct
571  reshape(LIBMESH_DIM, LIBMESH_DIM);
572 
573  ColumnMajorMatrix & s = (*this);
574 
575  // Copy the values
576  for (unsigned int j = 0; j < _n_cols; j++)
577  for (unsigned int i = 0; i < _n_cols; i++)
578  s(i, j) = rhs(i, j);
579 
580  return *this;
581 }
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.
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 105 of file ColumnMajorMatrix.C.

106 {
107  mooseAssert(_n_rows == rhs.m(), "different number of rows");
108  mooseAssert(_n_cols == rhs.n(), "different number of cols");
109 
110  _n_rows = rhs.m();
111  _n_cols = rhs.n();
112  _n_entries = rhs.m() * rhs.n();
113  _values.resize(rhs.m() * rhs.n());
114 
115  for (unsigned int j = 0; j < _n_cols; ++j)
116  for (unsigned int i = 0; i < _n_rows; ++i)
117  (*this)(i, j) = rhs(i, j);
118 
119  return *this;
120 }
unsigned int _n_entries
std::vector< Real > _values
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 123 of file ColumnMajorMatrix.C.

124 {
125  mooseAssert(_n_rows == rhs.size(), "different number of rows");
126  mooseAssert(_n_cols == 1, "different number of cols");
127 
128  _n_rows = rhs.size();
129  _n_cols = 1;
130  _n_entries = rhs.size();
131  _values.resize(rhs.size());
132 
133  for (unsigned int i = 0; i < _n_rows; ++i)
134  (*this)(i) = rhs(i);
135 
136  return *this;
137 }
unsigned int _n_entries
std::vector< Real > _values
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 584 of file ColumnMajorMatrix.h.

585 {
586  _n_rows = rhs._n_rows;
587  _n_cols = rhs._n_cols;
588  _n_entries = rhs._n_entries;
589 
590  _values.resize(_n_entries);
591 
592  for (unsigned int i = 0; i < _n_entries; i++)
593  _values[i] = rhs._values[i];
594 
595  return *this;
596 }
unsigned int _n_entries
std::vector< Real > _values
bool ColumnMajorMatrix::operator== ( const ColumnMajorMatrix rhs) const
inline

Equality operators.

Definition at line 761 of file ColumnMajorMatrix.h.

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

Print the tensor.

Definition at line 362 of file ColumnMajorMatrix.h.

363 {
364  ColumnMajorMatrix & s = (*this);
365 
366  for (unsigned int i = 0; i < _n_rows; i++)
367  {
368  for (unsigned int j = 0; j < _n_cols; j++)
369  Moose::out << std::setw(15) << s(i, j) << " ";
370 
371  Moose::out << std::endl;
372  }
373 }
This class defines a Tensor that can change its shape.
void ColumnMajorMatrix::print_scientific ( std::ostream &  os)
inline

Prints to file.

Definition at line 376 of file ColumnMajorMatrix.h.

377 {
378  ColumnMajorMatrix & s = (*this);
379 
380  for (unsigned int i = 0; i < _n_rows; i++)
381  {
382  for (unsigned int j = 0; j < _n_cols; j++)
383  os << std::setw(15) << std::scientific << std::setprecision(8) << s(i, j) << " ";
384 
385  os << std::endl;
386  }
387 }
This class defines a Tensor that can change its shape.
Real * ColumnMajorMatrix::rawData ( )
inline

Returns a reference to the raw data pointer.

Definition at line 549 of file ColumnMajorMatrix.h.

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

550 {
551  return &_values[0];
552 }
std::vector< Real > _values
const Real * ColumnMajorMatrix::rawData ( ) const
inline

Definition at line 555 of file ColumnMajorMatrix.h.

556 {
557  return &_values[0];
558 }
std::vector< Real > _values
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 327 of file ColumnMajorMatrix.h.

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

328 {
329  if (cols * rows == _n_entries)
330  {
331  _n_rows = rows;
332  _n_cols = cols;
333  }
334  else
335  {
336  _n_rows = rows;
337  _n_cols = cols;
339  _values.resize(_n_entries);
340  }
341 }
unsigned int _n_entries
std::vector< Real > _values
void ColumnMajorMatrix::setDiag ( Real  value)
inline

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

Definition at line 467 of file ColumnMajorMatrix.h.

468 {
469  mooseAssert(_n_rows == _n_cols, "Cannot set the diagonal of a non-square matrix!");
470 
471  for (unsigned int i = 0; i < _n_rows; i++)
472  (*this)(i, i) = value;
473 }
Real ColumnMajorMatrix::tr ( ) const
inline

The trace of the CMM.

Definition at line 485 of file ColumnMajorMatrix.h.

Referenced by deviatoric().

486 {
487  mooseAssert(_n_rows == _n_cols, "Cannot find the trace of a non-square matrix!");
488 
489  Real trace = 0;
490 
491  for (unsigned int i = 0; i < _n_rows; i++)
492  trace += (*this)(i, i);
493 
494  return trace;
495 }
ColumnMajorMatrix ColumnMajorMatrix::transpose ( ) const
inline

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

Definition at line 423 of file ColumnMajorMatrix.h.

424 {
425  const ColumnMajorMatrix & s = (*this);
426 
427  ColumnMajorMatrix ret_matrix(_n_cols, _n_rows);
428 
429  for (unsigned int i = 0; i < _n_rows; i++)
430  for (unsigned int j = 0; j < _n_cols; j++)
431  ret_matrix(j, i) = s(i, j);
432 
433  return ret_matrix;
434 }
This class defines a Tensor that can change its shape.
void ColumnMajorMatrix::zero ( )
inline

Zero the matrix.

Definition at line 498 of file ColumnMajorMatrix.h.

Referenced by identity().

499 {
500  for (unsigned int i = 0; i < _n_entries; i++)
501  _values[i] = 0;
502 }
unsigned int _n_entries
std::vector< Real > _values

Member Data Documentation

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

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