www.mooseframework.org
Public Member Functions | Protected Attributes | Friends | List of all members
ColumnMajorMatrixTempl< T > Class Template Reference

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

#include <PiecewiseBilinear.h>

Public Member Functions

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

Friends

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

Detailed Description

template<typename T>
class ColumnMajorMatrixTempl< T >

This class defines a Tensor that can change its shape.

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

Definition at line 15 of file PiecewiseBilinear.h.

Constructor & Destructor Documentation

◆ ColumnMajorMatrixTempl() [1/6]

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

Constructor that sets an initial number of entries and shape.

Defaults to creating the same size tensor as TensorValue

Definition at line 22 of file ColumnMajorMatrix.C.

23  : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
24 {
25  _values.resize(rows * cols);
26 }
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 29 of file ColumnMajorMatrix.C.

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

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

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

◆ ColumnMajorMatrixTempl() [4/6]

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

Definition at line 48 of file ColumnMajorMatrix.C.

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

◆ ColumnMajorMatrixTempl() [5/6]

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

Definition at line 55 of file ColumnMajorMatrix.C.

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

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

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

Member Function Documentation

◆ abs()

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

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

Definition at line 312 of file ColumnMajorMatrix.C.

313 {
314  ColumnMajorMatrixTempl<T> & s = (*this);
315 
317 
318  for (unsigned int j = 0; j < _n_cols; j++)
319  for (unsigned int i = 0; i < _n_rows; i++)
320  ret_matrix(i, j) = std::abs(s(i, j));
321 
322  return ret_matrix;
323 }
This class defines a Tensor that can change its shape.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)

◆ addDiag()

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

Add to each of the diagonals the passsed in value.

Definition at line 497 of file ColumnMajorMatrix.h.

498 {
499  this->checkSquareness();
500 
501  for (unsigned int i = 0; i < _n_rows; i++)
502  (*this)(i, i) += value;
503 }
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 296 of file ColumnMajorMatrix.C.

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

◆ checkSquareness()

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

Check if matrix is square.

Definition at line 288 of file ColumnMajorMatrix.C.

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

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

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

471 {
472  ColumnMajorMatrixTempl<T> & s = (*this);
473 
475 
476  I.identity();
477 
478  for (unsigned int i = 0; i < _n_rows; i++)
479  for (unsigned int j = 0; j < _n_cols; j++)
480  ret_matrix(i, j) = s(i, j) - I(i, j) * (s.tr() / 3.0);
481 
482  return ret_matrix;
483 }
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 541 of file ColumnMajorMatrix.h.

542 {
543  this->checkShapeEquality(rhs);
544 
545  T value = 0;
546 
547  for (unsigned int j = 0; j < _n_cols; j++)
548  for (unsigned int i = 0; i < _n_rows; i++)
549  value += (*this)(i, j) * rhs(i, j);
550 
551  return value;
552 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.

◆ eigen() [1/2]

Definition at line 168 of file ColumnMajorMatrix.C.

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

◆ eigen() [2/2]

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

Returns eigen system solve for a symmetric real matrix.

Definition at line 137 of file ColumnMajorMatrix.C.

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

◆ eigenNonsym() [1/2]

template<typename T>
void ColumnMajorMatrixTempl< T >::eigenNonsym ( ColumnMajorMatrixTempl< T > &  eval_real,
ColumnMajorMatrixTempl< T > &  eval_img,
ColumnMajorMatrixTempl< T > &  evec_right,
ColumnMajorMatrixTempl< T > &  eve_left 
) const

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

Definition at line 176 of file ColumnMajorMatrix.C.

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

180 {
181  this->checkSquareness();
182 
183  ColumnMajorMatrixTempl<T> a(*this);
184 
185  char jobvl = 'V';
186  char jobvr = 'V';
187  PetscBLASInt n = _n_rows;
188  PetscBLASInt return_value = 0;
189 
190  eval_real._n_rows = _n_rows;
191  eval_real._n_cols = 1;
192  eval_real._n_entries = _n_rows;
193  eval_real._values.resize(_n_rows);
194 
195  eval_img._n_rows = _n_rows;
196  eval_img._n_cols = 1;
197  eval_img._n_entries = _n_rows;
198  eval_img._values.resize(_n_rows);
199 
200  T * a_data = a.rawData();
201  T * eval_r = eval_real.rawData();
202  T * eval_i = eval_img.rawData();
203  T * evec_ri = evec_right.rawData();
204  T * evec_le = evec_left.rawData();
205 
206  PetscBLASInt buffer_size = n * 64;
207  std::vector<T> buffer(buffer_size);
208 
209  LAPACKgeev_(&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 
224  if (return_value)
225  mooseError("error in lapack eigen solve");
226 }
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:284
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
std::vector< T > _values
unsigned int n() const
Returns the number of rows.

◆ eigenNonsym() [2/2]

Definition at line 230 of file ColumnMajorMatrix.C.

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

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

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

◆ fill() [1/3]

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

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

Definition at line 418 of file ColumnMajorMatrix.h.

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

◆ fill() [2/3]

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

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

Definition at line 431 of file ColumnMajorMatrix.h.

432 {
433  if (rhs.n() * rhs.m() != _n_entries)
434  mooseError(
435  "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
436 
437  for (unsigned int j = 0, index = 0; j < rhs.m(); ++j)
438  for (unsigned int i = 0; i < rhs.n(); ++i, ++index)
439  rhs(i, j) = _values[index];
440 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
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 444 of file ColumnMajorMatrix.h.

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

◆ identity()

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

Turn the matrix into an identity matrix.

Definition at line 529 of file ColumnMajorMatrix.h.

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

530 {
531  this->checkSquareness();
532 
533  zero();
534 
535  for (unsigned int i = 0; i < _n_rows; i++)
536  (*this)(i, i) = 1;
537 }
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 262 of file ColumnMajorMatrix.C.

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

◆ inverse() [2/2]

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

Definition at line 305 of file ColumnMajorMatrix.C.

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

◆ kronecker()

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

Kronecker Product.

Definition at line 83 of file ColumnMajorMatrix.C.

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

◆ m()

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

◆ n()

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

◆ norm()

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

The Euclidean norm of the matrix.

Definition at line 327 of file ColumnMajorMatrix.C.

328 {
329  return std::sqrt(doubleContraction(*this));
330 }
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
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 341 of file ColumnMajorMatrix.h.

342 {
343  return _n_entries;
344 }

◆ operator!=()

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

Definition at line 801 of file ColumnMajorMatrix.h.

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

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

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

378 {
379  if ((i * j) >= _n_entries)
380  mooseError("Reference outside of ColumnMajorMatrix bounds!");
381 
382  // Row major indexing!
383  return _values[(j * _n_rows) + i];
384 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
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 622 of file ColumnMajorMatrix.h.

623 {
625 
626  for (unsigned int i = 0; i < _n_entries; i++)
627  ret_matrix._values[i] = _values[i] * scalar;
628 
629  return ret_matrix;
630 }
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 634 of file ColumnMajorMatrix.h.

635 {
636  if (_n_cols != Moose::dim)
637  mooseError("Cannot perform matvec operation! The column dimension of "
638  "the ColumnMajorMatrix does not match the TypeVector!");
639 
640  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, 1);
641 
642  for (unsigned int i = 0; i < _n_rows; ++i)
643  for (unsigned int j = 0; j < _n_cols; ++j)
644  ret_matrix._values[i] += (*this)(i, j) * rhs(j);
645 
646  return ret_matrix;
647 }
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:284
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:148

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

669 {
670  if (_n_cols != rhs._n_rows)
671  mooseError(
672  "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
673 
674  ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, rhs._n_cols);
675 
676  for (unsigned int i = 0; i < ret_matrix._n_rows; ++i)
677  for (unsigned int j = 0; j < ret_matrix._n_cols; ++j)
678  for (unsigned int k = 0; k < _n_cols; ++k)
679  ret_matrix(i, j) += (*this)(i, k) * rhs(k, j);
680 
681  return ret_matrix;
682 }
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:284

◆ operator*=()

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

Scalar Multiplication plus assignment.

Definition at line 765 of file ColumnMajorMatrix.h.

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

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

754 {
756 
757  for (unsigned int i = 0; i < _n_entries; i++)
758  ret_matrix._values[i] = _values[i] + scalar;
759 
760  return ret_matrix;
761 }
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 714 of file ColumnMajorMatrix.h.

715 {
716  this->checkShapeEquality(rhs);
717 
718  for (unsigned int i = 0; i < _n_entries; i++)
719  _values[i] += rhs._values[i];
720 
721  return *this;
722 }
void checkShapeEquality(const 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 726 of file ColumnMajorMatrix.h.

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

◆ operator+=() [3/3]

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

Scalar Addition plus assignment.

Definition at line 783 of file ColumnMajorMatrix.h.

784 {
785  for (unsigned int i = 0; i < _n_entries; i++)
786  _values[i] += scalar;
787  return *this;
788 }
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 700 of file ColumnMajorMatrix.h.

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

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

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

◆ operator=() [1/5]

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

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

Will also reshape this tensor if necessary.

Definition at line 584 of file ColumnMajorMatrix.h.

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

◆ operator=() [2/5]

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

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

Will also reshape this tensor if necessary.

Definition at line 100 of file ColumnMajorMatrix.C.

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

◆ operator=() [3/5]

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

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

Will also reshape this tensor if necessary.

Definition at line 119 of file ColumnMajorMatrix.C.

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

◆ operator=() [4/5]

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

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

Definition at line 609 of file ColumnMajorMatrix.h.

610 {
611  this->reshape(rhs.m(), rhs.n());
612 
613  for (MooseIndex(rhs.m()) i = 0; i < rhs.m(); ++i)
614  for (MooseIndex(rhs.n()) j = 0; j < rhs.n(); ++j)
615  (*this)(i, j) = rhs(i, j);
616 
617  return *this;
618 }
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.
unsigned int m() const
Returns the number of columns.
unsigned int n() const
Returns the number of rows.

◆ operator=() [5/5]

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

defaulted operator=

◆ operator==()

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

Equality operators.

Definition at line 792 of file ColumnMajorMatrix.h.

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

◆ print()

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

Print the tensor.

Definition at line 388 of file ColumnMajorMatrix.h.

389 {
390  ColumnMajorMatrixTempl<T> & s = (*this);
391 
392  for (unsigned int i = 0; i < _n_rows; i++)
393  {
394  for (unsigned int j = 0; j < _n_cols; j++)
395  Moose::out << std::setw(15) << s(i, j) << " ";
396 
397  Moose::out << std::endl;
398  }
399 }
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 403 of file ColumnMajorMatrix.h.

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

◆ rawData() [1/2]

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

Returns a reference to the raw data pointer.

Definition at line 570 of file ColumnMajorMatrix.h.

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

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

◆ rawData() [2/2]

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

Definition at line 577 of file ColumnMajorMatrix.h.

578 {
579  return &_values[0];
580 }
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 348 of file ColumnMajorMatrix.h.

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

349 {
350  if (cols * rows == _n_entries)
351  {
352  _n_rows = rows;
353  _n_cols = cols;
354  }
355  else
356  {
357  _n_rows = rows;
358  _n_cols = cols;
360  _values.resize(_n_entries);
361  }
362 }
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 487 of file ColumnMajorMatrix.h.

488 {
489  this->checkSquareness();
490 
491  for (unsigned int i = 0; i < _n_rows; i++)
492  (*this)(i, i) = value;
493 }
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 507 of file ColumnMajorMatrix.h.

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

508 {
509  this->checkSquareness();
510 
511  T trace = 0;
512 
513  for (unsigned int i = 0; i < _n_rows; i++)
514  trace += (*this)(i, i);
515 
516  return trace;
517 }
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 455 of file ColumnMajorMatrix.h.

456 {
457  const ColumnMajorMatrixTempl<T> & s = (*this);
458 
460 
461  for (unsigned int i = 0; i < _n_rows; i++)
462  for (unsigned int j = 0; j < _n_cols; j++)
463  ret_matrix(j, i) = s(i, j);
464 
465  return ret_matrix;
466 }
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 521 of file ColumnMajorMatrix.h.

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

Friends And Related Function Documentation

◆ dataLoad

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

◆ dataStore

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

Member Data Documentation

◆ _n_cols

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

◆ _n_entries

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

◆ _n_rows

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

◆ _values

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

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