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

486 {
487  this->checkSquareness();
488 
489  for (unsigned int i = 0; i < _n_rows; i++)
490  (*this)(i, i) += value;
491 }
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:208

◆ 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:208

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

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

530 {
531  this->checkShapeEquality(rhs);
532 
533  T value = 0;
534 
535  for (unsigned int j = 0; j < _n_cols; j++)
536  for (unsigned int i = 0; i < _n_rows; i++)
537  value += (*this)(i, j) * rhs(i, j);
538 
539  return value;
540 }
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:208
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:208

◆ 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:208
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:208

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

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

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

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

◆ identity()

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

Turn the matrix into an identity matrix.

Definition at line 517 of file ColumnMajorMatrix.h.

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

518 {
519  this->checkSquareness();
520 
521  zero();
522 
523  for (unsigned int i = 0; i < _n_rows; i++)
524  (*this)(i, i) = 1;
525 }
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:208

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

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

552 {
553  return _n_cols;
554 }

◆ n()

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

Returns the number of rows.

Definition at line 544 of file ColumnMajorMatrix.h.

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

545 {
546  return _n_rows;
547 }

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

330 {
331  return _n_entries;
332 }

◆ operator!=()

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

Definition at line 790 of file ColumnMajorMatrix.h.

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

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

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

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

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

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

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

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

◆ operator*=()

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

Scalar Multiplication plus assignment.

Definition at line 754 of file ColumnMajorMatrix.h.

755 {
756  for (unsigned int i = 0; i < _n_entries; i++)
757  _values[i] *= scalar;
758  return *this;
759 }
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 675 of file ColumnMajorMatrix.h.

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

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

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

716 {
717  if ((_n_rows != LIBMESH_DIM) || (_n_cols != LIBMESH_DIM))
718  mooseError("Cannot perform matrix addition and assignment! The shapes of the two operands are "
719  "not compatible!");
720 
721  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
722  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
723  (*this)(i, j) += rhs(i, j);
724 
725  return *this;
726 }
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]

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

Scalar Addition plus assignment.

Definition at line 772 of file ColumnMajorMatrix.h.

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

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

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

764 {
765  for (unsigned int i = 0; i < _n_entries; i++)
766  _values[i] /= scalar;
767  return *this;
768 }
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 572 of file ColumnMajorMatrix.h.

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

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

◆ operator==()

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

Equality operators.

Definition at line 781 of file ColumnMajorMatrix.h.

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

◆ print()

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

Print the tensor.

Definition at line 376 of file ColumnMajorMatrix.h.

377 {
378  ColumnMajorMatrixTempl<T> & 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  Moose::out << std::setw(15) << s(i, j) << " ";
384 
385  Moose::out << std::endl;
386  }
387 }
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 391 of file ColumnMajorMatrix.h.

392 {
393  ColumnMajorMatrixTempl<T> & s = (*this);
394 
395  for (unsigned int i = 0; i < _n_rows; i++)
396  {
397  for (unsigned int j = 0; j < _n_cols; j++)
398  os << std::setw(15) << std::scientific << std::setprecision(8) << s(i, j) << " ";
399 
400  os << std::endl;
401  }
402 }
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 558 of file ColumnMajorMatrix.h.

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

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

◆ rawData() [2/2]

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

Definition at line 565 of file ColumnMajorMatrix.h.

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

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

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

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

The trace of the CMM.

Definition at line 495 of file ColumnMajorMatrix.h.

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

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

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

510 {
511  for (unsigned int i = 0; i < _n_entries; i++)
512  _values[i] = 0;
513 }
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: