www.mooseframework.org
Public Member Functions | Protected Attributes | 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=LIBMESH_DIM, const unsigned int cols=LIBMESH_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...
 
ColumnMajorMatrixTempl< T > & operator= (const ColumnMajorMatrixTempl< T > &rhs)
 Sets the values in this tensor to the values on the RHS Will also reshape this tensor if necessary. 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< DualReal > &, ColumnMajorMatrixTempl< DualReal > &) const
 
template<>
void eigenNonsym (ColumnMajorMatrixTempl< DualReal > &, ColumnMajorMatrixTempl< DualReal > &, ColumnMajorMatrixTempl< DualReal > &, ColumnMajorMatrixTempl< DualReal > &) const
 
template<>
void inverse (ColumnMajorMatrixTempl< DualReal > &) const
 

Protected Attributes

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

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 16 of file PiecewiseBilinear.h.

Constructor & Destructor Documentation

◆ ColumnMajorMatrixTempl() [1/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( 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 32 of file ColumnMajorMatrix.C.

33  : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
34 {
35  _values.resize(rows * cols);
36 }
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 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 }

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

47  : _n_rows(LIBMESH_DIM),
48  _n_cols(LIBMESH_DIM),
49  _n_entries(LIBMESH_DIM * LIBMESH_DIM),
50  _values(LIBMESH_DIM * LIBMESH_DIM)
51 {
52  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
53  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
54  (*this)(i, j) = rhs(i, j);
55 }
std::vector< T > _values

◆ ColumnMajorMatrixTempl() [4/6]

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

Definition at line 58 of file ColumnMajorMatrix.C.

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

◆ ColumnMajorMatrixTempl() [5/6]

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

Definition at line 65 of file ColumnMajorMatrix.C.

66  : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
67 {
68  *this = rhs;
69 }

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

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

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

354 {
355  ColumnMajorMatrixTempl<T> & s = (*this);
356 
358 
359  for (unsigned int j = 0; j < _n_cols; j++)
360  for (unsigned int i = 0; i < _n_rows; i++)
361  ret_matrix(i, j) = std::abs(s(i, j));
362 
363  return ret_matrix;
364 }
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
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 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()

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

Check if matrices are of same shape.

Definition at line 337 of file ColumnMajorMatrix.C.

338 {
339  if (_n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
340  mooseError("ColumnMajorMatrix error: Unable to perform the operation on matrices of different "
341  "shapes.");
342 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207

◆ checkSquareness()

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

Check if matrix is square.

Definition at line 329 of file ColumnMajorMatrix.C.

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

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

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

458 {
459  ColumnMajorMatrixTempl<T> & s = (*this);
460 
462 
463  I.identity();
464 
465  for (unsigned int i = 0; i < _n_rows; i++)
466  for (unsigned int j = 0; j < _n_cols; j++)
467  ret_matrix(i, j) = s(i, j) - I(i, j) * (s.tr() / 3.0);
468 
469  return ret_matrix;
470 }
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 528 of file ColumnMajorMatrix.h.

529 {
530  this->checkShapeEquality(rhs);
531 
532  T value = 0;
533 
534  for (unsigned int j = 0; j < _n_cols; j++)
535  for (unsigned int i = 0; i < _n_rows; i++)
536  value += (*this)(i, j) * rhs(i, j);
537 
538  return value;
539 }
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.

◆ eigen() [1/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 147 of file ColumnMajorMatrix.C.

149 {
150  this->checkSquareness();
151 
152  char jobz = 'V';
153  char uplo = 'U';
154  int n = _n_rows;
155  int return_value = 0;
156 
157  eval._n_rows = _n_rows;
158  eval._n_cols = 1;
159  eval._n_entries = _n_rows;
160  eval._values.resize(_n_rows);
161 
162  evec = *this;
163 
164  T * eval_data = eval.rawData();
165  T * evec_data = evec.rawData();
166 
167  int buffer_size = n * 64;
168  std::vector<T> buffer(buffer_size);
169 
170 #if !defined(LIBMESH_HAVE_PETSC)
171  FORTRAN_CALL(dsyev)
172  (&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
173 #else
174  LAPACKsyev_(&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
175 #endif
176 
177  if (return_value)
178  mooseError("error in lapack eigen solve");
179 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
std::vector< T > _values
void FORTRAN_CALL() dsyev(...)
unsigned int n() const
Returns the number of rows.

◆ eigen() [2/2]

template<>
void ColumnMajorMatrixTempl< DualReal >::eigen ( ColumnMajorMatrixTempl< DualReal > &  ,
ColumnMajorMatrixTempl< DualReal > &   
) const

Definition at line 183 of file ColumnMajorMatrix.C.

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

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

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

195 {
196  this->checkSquareness();
197 
198  ColumnMajorMatrixTempl<T> a(*this);
199 
200  char jobvl = 'V';
201  char jobvr = 'V';
202  int n = _n_rows;
203  int return_value = 0;
204 
205  eval_real._n_rows = _n_rows;
206  eval_real._n_cols = 1;
207  eval_real._n_entries = _n_rows;
208  eval_real._values.resize(_n_rows);
209 
210  eval_img._n_rows = _n_rows;
211  eval_img._n_cols = 1;
212  eval_img._n_entries = _n_rows;
213  eval_img._values.resize(_n_rows);
214 
215  T * a_data = a.rawData();
216  T * eval_r = eval_real.rawData();
217  T * eval_i = eval_img.rawData();
218  T * evec_ri = evec_right.rawData();
219  T * evec_le = evec_left.rawData();
220 
221  int buffer_size = n * 64;
222  std::vector<T> buffer(buffer_size);
223 
224 #if !defined(LIBMESH_HAVE_PETSC)
225  FORTRAN_CALL(dgeev)
226  (&jobvl,
227  &jobvr,
228  &n,
229  a_data,
230  &n,
231  eval_r,
232  eval_i,
233  evec_le,
234  &n,
235  evec_ri,
236  &n,
237  &buffer[0],
238  &buffer_size,
239  &return_value);
240 #else
241  LAPACKgeev_(&jobvl,
242  &jobvr,
243  &n,
244  a_data,
245  &n,
246  eval_r,
247  eval_i,
248  evec_le,
249  &n,
250  evec_ri,
251  &n,
252  &buffer[0],
253  &buffer_size,
254  &return_value);
255 #endif
256 
257  if (return_value)
258  mooseError("error in lapack eigen solve");
259 }
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:207
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.
void FORTRAN_CALL() dgeev(...)

◆ eigenNonsym() [2/2]

Definition at line 263 of file ColumnMajorMatrix.C.

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

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

274 {
275  this->checkSquareness();
276 
277  ColumnMajorMatrixTempl<T> a(*this);
278  ColumnMajorMatrixTempl<T> evals_real(_n_rows, 1), evals_img(_n_rows, 1),
279  evals_real2(_n_rows, _n_cols);
280  ColumnMajorMatrixTempl<T> evec_right(_n_rows, _n_cols), evec_left(_n_rows, _n_cols);
281  ColumnMajorMatrixTempl<T> evec_right_inverse(_n_rows, _n_cols);
282 
283  a.eigenNonsym(evals_real, evals_img, evec_right, evec_left);
284 
285  for (unsigned int i = 0; i < _n_rows; i++)
286  evals_real2(i, i) = std::exp(evals_real(i, 0));
287 
288  evec_right.inverse(evec_right_inverse);
289 
290  z = evec_right * evals_real2 * evec_right_inverse;
291 }
This class defines a Tensor that can change its shape.
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 405 of file ColumnMajorMatrix.h.

406 {
407  if (LIBMESH_DIM * LIBMESH_DIM != _n_entries)
408  mooseError(
409  "Cannot fill tensor! The ColumnMajorMatrix doesn't have the same number of entries!");
410 
411  for (unsigned int j = 0, index = 0; j < LIBMESH_DIM; ++j)
412  for (unsigned int i = 0; i < LIBMESH_DIM; ++i, ++index)
413  tensor(i, j) = _values[index];
414 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
std::vector< T > _values

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

419 {
420  if (rhs.n() * rhs.m() != _n_entries)
421  mooseError(
422  "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
423 
424  for (unsigned int j = 0, index = 0; j < rhs.m(); ++j)
425  for (unsigned int i = 0; i < rhs.n(); ++i, ++index)
426  rhs(i, j) = _values[index];
427 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
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 431 of file ColumnMajorMatrix.h.

432 {
433  if (_n_rows != rhs.size() || _n_cols != 1)
434  mooseError("ColumnMajorMatrix and DenseVector must be the same shape for a fill!");
435 
436  for (unsigned int i = 0; i < _n_rows; ++i)
437  rhs(i) = (*this)(i);
438 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207

◆ identity()

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

Turn the matrix into an identity matrix.

Definition at line 516 of file ColumnMajorMatrix.h.

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

517 {
518  this->checkSquareness();
519 
520  zero();
521 
522  for (unsigned int i = 0; i < _n_rows; i++)
523  (*this)(i, i) = 1;
524 }
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 295 of file ColumnMajorMatrix.C.

296 {
297  this->checkSquareness();
298  this->checkShapeEquality(invA);
299 
300  int n = _n_rows;
301  int return_value = 0;
302 
303  invA = *this;
304 
305  std::vector<PetscBLASInt> ipiv(n);
306  T * invA_data = invA.rawData();
307 
308  int buffer_size = n * 64;
309  std::vector<T> buffer(buffer_size);
310 
311 #if !defined(LIBMESH_HAVE_PETSC)
312  FORTRAN_CALL(dgetrf)(&n, &n, invA_data, &n, &ipiv[0], &return_value);
313 #else
314  LAPACKgetrf_(&n, &n, invA_data, &n, &ipiv[0], &return_value);
315 #endif
316 
317 #if !defined(LIBMESH_HAVE_PETSC) || PETSC_VERSION_LESS_THAN(3, 5, 0)
318  FORTRAN_CALL(dgetri)(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
319 #else
320  LAPACKgetri_(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
321 #endif
322 
323  if (return_value)
324  mooseException("Error in LAPACK matrix-inverse calculation");
325 }
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
void FORTRAN_CALL() dgetri(...)
void FORTRAN_CALL() dgetrf(...)
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< DualReal >::inverse ( ColumnMajorMatrixTempl< DualReal > &  ) const

Definition at line 346 of file ColumnMajorMatrix.C.

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

◆ kronecker()

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

Kronecker Product.

Definition at line 93 of file ColumnMajorMatrix.C.

94 {
95  rhs.checkSquareness();
96 
97  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows * rhs._n_rows, _n_cols * rhs._n_cols);
98 
99  for (unsigned int i = 0; i < _n_rows; i++)
100  for (unsigned int j = 0; j < _n_cols; j++)
101  for (unsigned int k = 0; k < rhs._n_rows; k++)
102  for (unsigned int l = 0; l < rhs._n_cols; l++)
103  ret_matrix(((i * _n_rows) + k), ((j * _n_cols) + l)) = (*this)(i, j) * rhs(k, l);
104 
105  return ret_matrix;
106 }
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

Returns the number of columns.

Definition at line 550 of file ColumnMajorMatrix.h.

Referenced by dataLoad(), dataStore(), and RankTwoTensorTempl< Real >::operator=().

551 {
552  return _n_cols;
553 }

◆ n()

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

Returns the number of rows.

Definition at line 543 of file ColumnMajorMatrix.h.

Referenced by dataLoad(), dataStore(), and RankTwoTensorTempl< Real >::operator=().

544 {
545  return _n_rows;
546 }

◆ norm()

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

The Euclidean norm of the matrix.

Definition at line 368 of file ColumnMajorMatrix.C.

369 {
370  return std::sqrt(doubleContraction(*this));
371 }
T doubleContraction(const ColumnMajorMatrixTempl< T > &rhs) const
Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)

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

329 {
330  return _n_entries;
331 }

◆ operator!=()

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

Definition at line 789 of file ColumnMajorMatrix.h.

790 {
791  return !(*this == rhs);
792 }

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

354 {
355  if ((i * j) >= _n_entries)
356  mooseError("Reference outside of ColumnMajorMatrix bounds!");
357 
358  // Row major indexing!
359  return _values[(j * _n_rows) + i];
360 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
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 364 of file ColumnMajorMatrix.h.

365 {
366  if ((i * j) >= _n_entries)
367  mooseError("Reference outside of ColumnMajorMatrix bounds!");
368 
369  // Row major indexing!
370  return _values[(j * _n_rows) + i];
371 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
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 610 of file ColumnMajorMatrix.h.

611 {
613 
614  for (unsigned int i = 0; i < _n_entries; i++)
615  ret_matrix._values[i] = _values[i] * scalar;
616 
617  return ret_matrix;
618 }
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 622 of file ColumnMajorMatrix.h.

623 {
624  if (_n_cols != LIBMESH_DIM)
625  mooseError("Cannot perform matvec operation! The column dimension of "
626  "the ColumnMajorMatrix does not match the TypeVector!");
627 
628  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, 1);
629 
630  for (unsigned int i = 0; i < _n_rows; ++i)
631  for (unsigned int j = 0; j < _n_cols; ++j)
632  ret_matrix._values[i] += (*this)(i, j) * rhs(j);
633 
634  return ret_matrix;
635 }
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:207

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

657 {
658  if (_n_cols != rhs._n_rows)
659  mooseError(
660  "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
661 
662  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, rhs._n_cols);
663 
664  for (unsigned int i = 0; i < ret_matrix._n_rows; ++i)
665  for (unsigned int j = 0; j < ret_matrix._n_cols; ++j)
666  for (unsigned int k = 0; k < _n_cols; ++k)
667  ret_matrix(i, j) += (*this)(i, k) * rhs(k, j);
668 
669  return ret_matrix;
670 }
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:207

◆ operator*=()

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

Scalar Multiplication 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 }
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 674 of file ColumnMajorMatrix.h.

675 {
676  this->checkShapeEquality(rhs);
677 
679 
680  for (unsigned int i = 0; i < _n_entries; i++)
681  ret_matrix._values[i] = _values[i] + rhs._values[i];
682 
683  return ret_matrix;
684 }
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 741 of file ColumnMajorMatrix.h.

742 {
744 
745  for (unsigned int i = 0; i < _n_entries; i++)
746  ret_matrix._values[i] = _values[i] + scalar;
747 
748  return ret_matrix;
749 }
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 702 of file ColumnMajorMatrix.h.

703 {
704  this->checkShapeEquality(rhs);
705 
706  for (unsigned int i = 0; i < _n_entries; i++)
707  _values[i] += rhs._values[i];
708 
709  return *this;
710 }
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 714 of file ColumnMajorMatrix.h.

715 {
716  if ((_n_rows != LIBMESH_DIM) || (_n_cols != LIBMESH_DIM))
717  mooseError("Cannot perform matrix addition and assignment! The shapes of the two operands are "
718  "not compatible!");
719 
720  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
721  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
722  (*this)(i, j) += rhs(i, j);
723 
724  return *this;
725 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207

◆ operator+=() [3/3]

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

Scalar Addition plus assignment.

Definition at line 771 of file ColumnMajorMatrix.h.

772 {
773  for (unsigned int i = 0; i < _n_entries; i++)
774  _values[i] += scalar;
775  return *this;
776 }
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 688 of file ColumnMajorMatrix.h.

689 {
690  this->checkShapeEquality(rhs);
691 
693 
694  for (unsigned int i = 0; i < _n_entries; i++)
695  ret_matrix._values[i] = _values[i] - rhs._values[i];
696 
697  return ret_matrix;
698 }
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 729 of file ColumnMajorMatrix.h.

730 {
731  this->checkShapeEquality(rhs);
732 
733  for (unsigned int i = 0; i < _n_entries; i++)
734  _values[i] -= rhs._values[i];
735 
736  return *this;
737 }
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 762 of file ColumnMajorMatrix.h.

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

◆ operator=() [1/4]

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

572 {
573  // Resize the tensor if necessary
574  if ((LIBMESH_DIM * LIBMESH_DIM) != _n_entries)
575  {
576  _n_entries = LIBMESH_DIM * LIBMESH_DIM;
577  _values.resize(_n_entries);
578  }
579 
580  // Make sure the shape is correct
581  reshape(LIBMESH_DIM, LIBMESH_DIM);
582 
583  ColumnMajorMatrixTempl<T> & s = (*this);
584 
585  // Copy the values
586  for (unsigned int j = 0; j < _n_cols; j++)
587  for (unsigned int i = 0; i < _n_cols; i++)
588  s(i, j) = rhs(i, j);
589 
590  return *this;
591 }
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.
std::vector< T > _values

◆ operator=() [2/4]

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

111 {
112  if (_n_rows != rhs.m() || _n_cols != rhs.n())
113  mooseError("ColumnMajorMatrix and DenseMatrix should be of the same shape.");
114 
115  _n_rows = rhs.m();
116  _n_cols = rhs.n();
117  _n_entries = rhs.m() * rhs.n();
118  _values.resize(rhs.m() * rhs.n());
119 
120  for (unsigned int j = 0; j < _n_cols; ++j)
121  for (unsigned int i = 0; i < _n_rows; ++i)
122  (*this)(i, j) = rhs(i, j);
123 
124  return *this;
125 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
std::vector< T > _values

◆ operator=() [3/4]

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

130 {
131  if (_n_rows != rhs.size() || _n_cols != 1)
132  mooseError("ColumnMajorMatrix and DenseVector should be of the same shape.");
133 
134  _n_rows = rhs.size();
135  _n_cols = 1;
136  _n_entries = rhs.size();
137  _values.resize(rhs.size());
138 
139  for (unsigned int i = 0; i < _n_rows; ++i)
140  (*this)(i) = rhs(i);
141 
142  return *this;
143 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
std::vector< T > _values

◆ operator=() [4/4]

template<typename T>
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const ColumnMajorMatrixTempl< 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 595 of file ColumnMajorMatrix.h.

596 {
597  _n_rows = rhs._n_rows;
598  _n_cols = rhs._n_cols;
599  _n_entries = rhs._n_entries;
600 
601  _values.resize(_n_entries);
602 
603  for (unsigned int i = 0; i < _n_entries; i++)
604  _values[i] = rhs._values[i];
605 
606  return *this;
607 }
std::vector< T > _values

◆ operator==()

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

Equality operators.

Definition at line 780 of file ColumnMajorMatrix.h.

781 {
782  if (_n_entries != rhs._n_entries || _n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
783  return false;
784  return std::equal(_values.begin(), _values.end(), rhs._values.begin());
785 }
std::vector< T > _values

◆ print()

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

Print the tensor.

Definition at line 375 of file ColumnMajorMatrix.h.

376 {
377  ColumnMajorMatrixTempl<T> & s = (*this);
378 
379  for (unsigned int i = 0; i < _n_rows; i++)
380  {
381  for (unsigned int j = 0; j < _n_cols; j++)
382  Moose::out << std::setw(15) << s(i, j) << " ";
383 
384  Moose::out << std::endl;
385  }
386 }
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 390 of file ColumnMajorMatrix.h.

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

◆ rawData() [1/2]

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

Returns a reference to the raw data pointer.

Definition at line 557 of file ColumnMajorMatrix.h.

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

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

◆ rawData() [2/2]

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

Definition at line 564 of file ColumnMajorMatrix.h.

565 {
566  return &_values[0];
567 }
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 335 of file ColumnMajorMatrix.h.

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

336 {
337  if (cols * rows == _n_entries)
338  {
339  _n_rows = rows;
340  _n_cols = cols;
341  }
342  else
343  {
344  _n_rows = rows;
345  _n_cols = cols;
347  _values.resize(_n_entries);
348  }
349 }
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 474 of file ColumnMajorMatrix.h.

475 {
476  this->checkSquareness();
477 
478  for (unsigned int i = 0; i < _n_rows; i++)
479  (*this)(i, i) = value;
480 }
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 494 of file ColumnMajorMatrix.h.

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

495 {
496  this->checkSquareness();
497 
498  T trace = 0;
499 
500  for (unsigned int i = 0; i < _n_rows; i++)
501  trace += (*this)(i, i);
502 
503  return trace;
504 }
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 442 of file ColumnMajorMatrix.h.

443 {
444  const ColumnMajorMatrixTempl<T> & s = (*this);
445 
447 
448  for (unsigned int i = 0; i < _n_rows; i++)
449  for (unsigned int j = 0; j < _n_cols; j++)
450  ret_matrix(j, i) = s(i, j);
451 
452  return ret_matrix;
453 }
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 508 of file ColumnMajorMatrix.h.

509 {
510  for (unsigned int i = 0; i < _n_entries; i++)
511  _values[i] = 0;
512 }
std::vector< T > _values

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: